Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consumer - product alert emails are not translated #35674

Closed
1 of 5 tasks
loic-paquin opened this issue Jun 24, 2022 · 16 comments
Closed
1 of 5 tasks

Consumer - product alert emails are not translated #35674

loic-paquin opened this issue Jun 24, 2022 · 16 comments
Assignees
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.4 Indicates original Magento version for the Issue report.

Comments

@loic-paquin
Copy link

loic-paquin commented Jun 24, 2022

Preconditions and environment

Steps to reproduce

  • Enable product alert stock in BO (Configuration > Catalog >Product Alerts > Allow Alert When Product Comes Back in Stock > Yes)
  • Create a customer on the new store view
  • Select a Product without stock
  • Register to a product stock alert
  • Add stock to that product
  • Launch the cron catalog_product_alert

Expected result

  • The consumer is launched
  • The email is sent to the customer in the correct language

Actual result

The email is sent in english even if the translations are available in the language pack

Additional information

I was able to fix the problem by editing the class Magento\ProductAlert\Model\Email

I added those lines after the call to the startEnvironmentEmulation function ( around L349)

$area = $this->areaList->getArea(\Magento\Framework\App\Area::AREA_FRONTEND);
$area->load(\Magento\Framework\App\Area::PART_TRANSLATE);

( You will need to add Magento\Framework\App\AreaList in the constructor)

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
@m2-assistant
Copy link

m2-assistant bot commented Jun 24, 2022

Hi @loic-paquin. Thank you for your report.
To speed up processing of this issue, make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-assistant
Copy link

m2-assistant bot commented Jun 24, 2022

Hi @engcom-Lima. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Lima
Copy link
Contributor

engcom-Lima commented Jun 28, 2022

Since I am not getting product stock alert emails as this issue is dependent on the issue . This will be tested after issue got fixed. Hence, moving this issue to "On Hold".

@engcom-Lima
Copy link
Contributor

Hi @loic-paquin ,

Thanks for your contribution and collaboration.

As this issue related to this issue #35602 and it is taking time to resolve .
Kindly provide us any other way to reproduce the issue so that we can proceed further.

Thanks

@joseluisi4
Copy link

joseluisi4 commented Jun 1, 2023

Reproduced issue in Magento pce 2.4.5-p2

@dandrikop
Copy link

I have the same problem on Magento 2.4.6-p1.

@dandrikop
Copy link

@loic-paquin I didn't understand your comment that it will be needed to add Magento\Framework\App\AreaList in the constructor. Can you please provide the exact code changes?

@loic-paquin
Copy link
Author

@dandrikop

This is what I did at the time, I used a preference :
https://gist.github.com/loic-paquin/d1511b52b9c7f34f87a58b06e26e5231

It worked well on 2.4.4, I cannot confirm it will works on current Magento version.

You can see I added on L69 AreaList $areaList in the constructor

@dandrikop
Copy link

@loic-paquin
It seems that the problem with translating the product alerts has been identified for Magento 2.4.7 (https://github.com/magento/magento2/tree/2.4.7-beta1/app/code/Magento/ProductAlert). At the updated Product Alert module, it seems that only the file app/code/Magento/ProductAlert/Model /Mailing/AlertProcessor.php has changed. I tried the updated ProductAlert module, but the unfortunately the problem with translations persisted. Of course, Magento 2.4.7 is still in beta phase, so maybe the problem is fixed till version 2.4.7 becomes stable.

Anyway, based on your directions, I created and applied the below patch and tested it on Magento 2.4.6-p1 with PHP 8.1.20, and it worked without any errors recorders in the log files. I would like to thank you for that.

`diff --git a/vendor/magento/module-product-alert/Model/Email.php b/vendor/magento/module-product-alert/Model/Email.php
index 379ae29..c6b1c12 100644
--- a/vendor/magento/module-product-alert/Model/Email.php
+++ b/vendor/magento/module-product-alert/Model/Email.php
@@ -31,6 +31,7 @@ use Magento\Store\Model\App\Emulation;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Model\Website;
+use Magento\Framework\App\AreaList;

/**

  • ProductAlert Email processor
    @@ -139,6 +140,11 @@ class Email extends AbstractModel
    */
    protected $_customerHelper;
  • /**
  • * @var View
    
  • */
    
  • protected $areaList;
  • /**
    * @param Context $context
    * @param Registry $registry
    @@ -149,6 +155,7 @@ class Email extends AbstractModel
    * @param View $customerHelper
    * @param Emulation $appEmulation
    * @param TransportBuilder $transportBuilder
  • * @param AreaList $areaList;
    * @param AbstractResource $resource
    * @param AbstractDb $resourceCollection
    * @param array $data
    

@@ -164,6 +171,7 @@ class Email extends AbstractModel
View $customerHelper,
Emulation $appEmulation,
TransportBuilder $transportBuilder,

  •    AreaList $areaList,
       AbstractResource $resource = null,
       AbstractDb $resourceCollection = null,
       array $data = []
    

@@ -175,6 +183,7 @@ class Email extends AbstractModel
$this->_appEmulation = $appEmulation;
$this->_transportBuilder = $transportBuilder;
$this->_customerHelper = $customerHelper;

  •    $this->areaList = $areaList;
       parent::__construct($context, $registry, $resource, $resourceCollection, $data);
    
    }

@@ -346,7 +355,9 @@ class Email extends AbstractModel
$storeId = (int) $this->getStoreId() ?: (int) $this->_customer->getStoreId();
$store = $this->getStore($storeId);

  •    $this->_appEmulation->startEnvironmentEmulation($storeId);
    
  •    $this->_appEmulation->startEnvironmentEmulation($storeId, Area::AREA_FRONTEND, true);
    
  •    $area = $this->areaList->getArea(\Magento\Framework\App\Area::AREA_FRONTEND);
    
  •    $area->load(\Magento\Framework\App\Area::PART_TRANSLATE); 
    
       $block = $this->getBlock();
       $block->setStore($store)->reset();
    

`

@TheBadong
Copy link

Reproduced on 2.4.5-p2
This solution works just fine. Does anyone know if it's been fixed in more recent versions ?

@nurullah
Copy link

nurullah commented Feb 6, 2024

Since I am not getting product stock alert emails as this issue is dependent on the issue . This will be tested after issue got fixed. Hence, moving this issue to "On Hold".

Hello. It looks like dependent issue fixed. Could you please test this issue again? After my translations did not work, I realized that this was the problem.

Copy link

m2-assistant bot commented Feb 7, 2024

Hi @engcom-Dash. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

    1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    1. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
    1. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
    1. Verify that the issue is reproducible on 2.4-develop branch
      Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
      - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
      - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

@hoanxuanmai
Copy link

hoanxuanmai commented Feb 22, 2024

use Magento\Framework\App\Area;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Phrase;
use Magento\Framework\Phrase\Renderer\Composite;
use Magento\Framework\Translate;
use Magento\ProductAlert\Model\Mailing\AlertProcessor;

class AlertProcessorPlugin
{
    function beforeProcess(AlertProcessor $object, string $alertType, array $customerIds, int $websiteId)
    {
        $objectManager = ObjectManager::getInstance();

        $objectManager->get(Translate::class)->loadData(Area::AREA_FRONTEND, true);

        Phrase::setRenderer($objectManager->get(Composite::class));
        return [$alertType, $customerIds, $websiteId];
    }
}

I just added this plugin to fix the product alert translation issue

it is working for me
@loic-paquin

@engcom-Dash
Copy link
Contributor

Hi @loic-paquin

We have reopened the dependent issue - 35602. Will test this issue once the dependent issue is fixed.

Thanks.

@engcom-Dash engcom-Dash added the Issue: needs update Additional information is require, waiting for response label Mar 4, 2024
@engcom-Dash engcom-Dash added Issue: ready for confirmation Issue: On Hold and removed Issue: needs update Additional information is require, waiting for response labels Mar 4, 2024
@engcom-Delta engcom-Delta added the Reported on 2.4.4 Indicates original Magento version for the Issue report. label May 28, 2024
@engcom-Dash
Copy link
Contributor

Hi @loic-paquin

Thanks for reporting and collaboration.

Verified the issue on Magento 2.4 dev instance and the issue is not reproducable.

Product alert emails are being translated

Steps to reproduce

  1. Enable product alert stock in BO (Configuration > Catalog >Product Alerts > Allow Alert When Product Comes Back in Stock > Yes)
  2. Create a customer on the new store view
  3. Select a Product without stock
  4. Register to a product stock alert
  5. Add stock to that product
  6. Launch the cron catalog_product_alert

The consumer is launched
The email is sent to the customer in the correct language

Please refer the attached screenshots and let us know if we missed anything.

Screenshot 2024-06-18 at 5 35 57 PM Screenshot 2024-06-18 at 5 32 55 PM Screenshot 2024-06-18 at 5 14 33 PM

@engcom-Dash engcom-Dash added the Issue: needs update Additional information is require, waiting for response label Jun 18, 2024
@engcom-Dash
Copy link
Contributor

Hi @loic-paquin

As there is no activity on this issue for a long time, we believe the issue has been resolved, hence closing this issue.
Feel free to raise a new issue or reopen this if you need more assistance.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.4 Indicates original Magento version for the Issue report.
Projects
None yet
Development

No branches or pull requests

9 participants