magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Magento does not translate product alert mail if two stores with different languages are under the same website

Open sezio opened this issue 5 years ago • 13 comments

Summary

With several stores under a same website, if the stores don't have the same language, product alert stock will send product information in the default website language.

Preconditions (*)

  1. Magento 2.2.5

Steps to reproduce (*)

  1. Create a main store, (ie language FR) under main website
  2. Create a secondary store, (ie language EN) under main website
  3. Enable product alert stock
  4. Go to a product and set a different name / description / short_description for the two stores (FR and EN)
  5. Make the product out of stock
  6. Create a customer account on the main storeview (FR here)
  7. Change your storeview to EN and login with the previously created customer account
  8. On the product page on the EN frontend and subscribe to the stock alert
  9. Make the product in stock
  10. Alert mail should be sended

Expected result (*)

  1. In the email, product description, name, etc should be in English as we subscribed to the alert stock on the english storeview.

Actual result (*)

  1. In the email, product description, name, etc is in French as it is the main store of the website because there is only a website_id in the alert stock table structure. By default, in the mail sender, the default store to be used is the store where the customer has been created :

vendor/magento/module-product-alert/Model/Email.php:309

        if ($this->_customer->getStoreId() > 0) {
            $store = $this->_storeManager->getStore($this->_customer->getStoreId());
        } else {
            $store = $this->_website->getDefaultStore();
        }

I assume the behabior is the same on magento 2.3 as the table structure has not changed

Is it the normal behavior ? In my opinion, an alert should be translated at the store level, what do you think ?

Thanks

sezio avatar May 30 '19 13:05 sezio

Hi @sezio. Thank you for your report. To help us process this issue please make sure that you provided the following information:

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

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

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

For more details, please, review the Magento Contributor Assistant documentation.

@sezio do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

m2-assistant[bot] avatar May 30 '19 13:05 m2-assistant[bot]

Hi @AlexWorking. 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: :point_down:

  • [ ] 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.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.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. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar May 30 '19 13:05 m2-assistant[bot]

In 2.2-develop not only the name, and the descriptions are in French but the whole text of the email, while in 2.3-develop the first line of the email (right after customer's name) is in English.

AlexWorking avatar Jun 04 '19 12:06 AlexWorking

:white_check_mark: Confirmed by @AlexWorking Thank you for verifying the issue. Based on the provided information internal tickets MC-17202, MC-17203 were created

Issue Available: @AlexWorking, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

magento-engcom-team avatar Jun 04 '19 12:06 magento-engcom-team

Hi @lavanyadckap. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 2. 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!

  • [ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


m2-assistant[bot] avatar Feb 02 '20 08:02 m2-assistant[bot]

Hi,

just found this issue after debugging a similar issue in M 2.3.1: When using theme specific translations, the Phrase above the product images (view/frontend/templates/email/price.phtml:12) uses the the theme specific translation, the one below (view/frontend/templates/email/price.phtml:45) does not. This is probably due to the fact, that the \Magento\Store\Model\App\Emulation::startEnvironmentEmulation is used in a nested way in \Magento\ProductAlert\Block\Product\ImageProvider::getImage, at least it works if I comment out these parts. Maybe this is the reason also for this Issue. If not, I might open another one.

Best regards, Willi

wilfriedwolf avatar Feb 13 '20 21:02 wilfriedwolf

Does anyone have a solution for that bug? Even a hotfix that could be applied via an override? Thank you!

EDIT: @wilfriedwolf solution seems to work, but I have no idea of the impact of such a modification...

Axel29 avatar Feb 12 '21 14:02 Axel29

Same issue in Magento 2.1.6

wanghsingchuan avatar Mar 29 '21 09:03 wanghsingchuan

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

stale[bot] avatar Jun 13 '21 10:06 stale[bot]

Hi everyone, I'm still facing the same issue on version Magento ver. 2.3.4-p2 Please investigate the issue again.

ngtuan96lc avatar Jun 22 '21 03:06 ngtuan96lc

Hello everyone,

We encountered this issue while we did an upgrade from 2.2 to 2.4.1 (EE version) After some debugging we ended up on:

vendor\magento\module-product-alert\Model\Observer.php

_processStock:351 method (but the same thing applies for _processPrice )

It looks like default store id is used instead or alert store id

 $product = $this->productRepository->getById(
    $alert->getProductId(),
    false,
    $website->getDefaultStore()->getId()
);

Instead of something like:

 $product = $this->productRepository->getById(
    $alert->getProductId(),
    false,
    $alert->getStoreId() ? $alert->getStoreId() : $website->getDefaultStore()->getId()
);

Therefor a custom module that rewrites this observer should resolve the issue.

doubleweb avatar Oct 22 '21 08:10 doubleweb

Hello everyone, have we some updates about this issue ?

Albinoty avatar Sep 15 '22 10:09 Albinoty

I think the easiest way to solve this problem is by adding a store_id column in the stock and price alert tables. I know it modifies a core table but that's the way I fixed it when I faced this problem.

Then, I overrided the \Magento\ProductAlert\Controller\Add\Price and \Magento\ProductAlert\Controller\Add\Stock classes to get the current store_id and set it in the alert.

Once the correct store_id was saved and available, I overrided \BodyAndMoves\ProductAlert\Rewrite\Magento\ProductAlert\Model\Email::send (to include the store_id when the email sending is done) and I also overrided Magento\ProductAlert\Model\Observer::_processPrice and Magento\ProductAlert\Model\Observer::_processStock to include the correct store_id when the alerts are processed.

sezio avatar Sep 20 '22 14:09 sezio

I think the easiest way to solve this problem is by adding a store_id column in the stock and price alert tables. I know it modifies a core table but that's the way I fixed it when I faced this problem.

Then, I overrided the \Magento\ProductAlert\Controller\Add\Price and \Magento\ProductAlert\Controller\Add\Stock classes to get the current store_id and set it in the alert.

Once the correct store_id was saved and available, I overrided \BodyAndMoves\ProductAlert\Rewrite\Magento\ProductAlert\Model\Email::send (to include the store_id when the email sending is done) and I also overrided Magento\ProductAlert\Model\Observer::_processPrice and Magento\ProductAlert\Model\Observer::_processStock to include the correct store_id when the alerts are processed.

Has anyone tried this solution? Looks like stock alert table already contains column with right store_id.

jilvins avatar Jan 03 '23 08:01 jilvins

Hi @engcom-Delta. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

    1. Add/Edit 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!
    1. If the issue is not relevant or is not reproducible any more, feel free to close it.

m2-assistant[bot] avatar May 13 '24 13:05 m2-assistant[bot]