magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.47k stars 9.28k forks source link

Template file retrieving should be store scoped #33519

Open alexmtch opened 3 years ago

alexmtch commented 3 years ago

Preconditions (*)

  1. Magento 2.3.6 or lower (maybe greater)

Steps to reproduce (*)

Setup Multiple Stores/websites in Magento Create 2 different Stock Alert Email Templates for each store (Marketing - Communications - Email Templates - Add New Template) Enable Product Alerts and Apply the newly created templates for each Store Stores - Configuration - Catalog - Catalog - Product Alerts - Stock Alert Email Template - Set the new template created for new Store view scope , "Allow Alert When Product Comes Back in Stock" - Yes Default Scope: Product Alerts Run Settings - Give the Start time and Save Configuration Change the Scope of Store View to another Store view and apply other newly created template and save the configuration Reindex and clear cache Admin - Add a new Product - Set the Product to Out Of Stock and Save Front-end - New Store website (for ex: France website) - Sign in as customer - Product Details page - Click on "Notify me when this product is in stock" Open the same Product in different Store (for ex: Germany website) - Sign in as same customer - Product Details page - Click on "Notify me when this product is in stock" Admin - Edit the same product and Set the stock status to "In Stock" and Save Run the Cron > php bin/magento cron:run Verify emails of both the Stores

Expected result (*)

  1. Each email should have the right template

Actual result (*)

  1. Only the first processed store template is serving

Workaround

I found out that it's caused by \Magento\Framework\View\Element\Template\File\Resolver::getTemplateFileName In this case, the $key to store the template and avoid multiple times the same process to run is the concatenation of the template identifier with params given by \Magento\Framework\View\Element\Template.

In this case i recommend in \Magento\Framework\View\Element\Template::getTemplateFile to add in parameters the store id in parameters by this way :

$params = ['module' => $this->getModuleName()]; could be

$params = [
            'module' => $this->getModuleName(),
            'store_id' => $this->_storeManager->getStore()->getId()
        ];

or

$store = $this->_storeManager->getStore();
        $params = [
            'module' => $this->getModuleName(),
            'store_id' => $store ? $store->getId() : \Magento\Store\Model\Store::DEFAULT_STORE_ID
        ];

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

m2-assistant[bot] commented 3 years ago

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

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.4-develop instance - upcoming 2.4.x release

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

Please, add a comment to assign the issue: @magento I am working on this


:clock10: You can find the schedule on the Magento Community Calendar page.

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

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

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

m2-assistant[bot] commented 3 years ago

Hi @engcom-Delta. 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:

engcom-Delta commented 3 years ago

Hi @alexmtch,

Please provide more clarity on the step# 'Run the catalog_product_alert CRON'. How to run the alert CRON? Hence added the label 'Needs Update'

Thanks

alexmtch commented 3 years ago

Hi @engcom-Delta You could run cron job from magento by following this documentation

This cron job is provided by the module Magento_ProductAlert. You could use tools like bin/magento or magerun to help you to run the cron individually.

m2-assistant[bot] commented 3 years ago

Hi @engcom-November. 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:

engcom-November commented 3 years ago

Verified the issue on Magento 2.4-develop branch and the issue is not reproducible: Steps performed:

  1. Setup Multiple Stores/websites Ref link
  2. Create 2 different templates for each store for the template (Marketing - Communications - Email Templates - Add New Template)
  3. Enable Product Alerts and Apply the newly created templates for each Store Stores - Configuration - Catalog - Catalog - Product Alerts - Stock Alert Email Template - Set the new template created for new Store view scope , "Allow Alert When Product Comes Back in Stock" - Yes
  4. Default Scope: Product Alerts Run Settings - Give the Start time and Save Configuration
  5. Change the Scope of Store View to another Store view and apply other newly created template and save the configuration
  6. Reindex and clear cache
  7. Admin - Add a new Product - Set the Product to Out Of Stock and Save
  8. Front-end - New Store website (for ex: France website) - Sign in as customer - Product Details page - Click on "Notify me when this product is in stock"
  9. Open the same Product in different Store (for ex: Germany website) - Sign in as same customer - Product Details page - Click on "Notify me when this product is in stock"
  10. Admin - Edit the same product and Set the stock status to "In Stock" and Save
  11. Run the Cron > php bin/magento cron:run
  12. Verify emails of both the Stores - No issue: Different templates are applied to both the stores in the emails image

image

image

@alexmtch , kindly recheck the issue on Magento 2.4-develop branch and provide missing steps if any if the issue is still reproducible. Thank you.

alexmtch commented 3 years ago

Hello @engcom-November

Ah you could see in \Magento\Framework\View\Element\Template\File\Resolver::getTemplateFileName the template path is stored and no process could define the difference between 2 store template file path.

The process you made seems to be good to reproduce the bug.

engcom-November commented 3 years ago

Verified the issue again on Magento 2.4-develop branch and the issue is reproducible: Steps to reproduce:

  1. Setup Multiple Stores/websites in Magento
  2. Create 2 different Stock Alert Email Templates for each store (Marketing - Communications - Email Templates - Add New Template)
  3. Enable Product Alerts and Apply the newly created templates for each Store Stores - Configuration - Catalog - Catalog - Product Alerts - Stock Alert Email Template - Set the new template created for new Store view scope , "Allow Alert When Product Comes Back in Stock" - Yes
  4. Default Scope: Product Alerts Run Settings - Give the Start time and Save Configuration
  5. Change the Scope of Store View to another Store view and apply other newly created template and save the configuration
  6. Reindex and clear cache
  7. Admin - Add a new Product - Set the Product to Out Of Stock and Save
  8. Front-end - New Store website (for ex: France website) - Sign in as customer - Product Details page - Click on "Notify me when this product is in stock"
  9. Open the same Product in different Store (for ex: Germany website) - Sign in as same customer - Product Details page - Click on "Notify me when this product is in stock"
  10. Admin - Edit the same product and Set the stock status to "In Stock" and Save
  11. Run the Cron > php bin/magento cron:run
  12. Verify emails of both the Stores Issue: Only one Stock Alert email is getting triggered for particular Store (first processed store template) Note: There is no issue with Price Alert emails - 2 Emails are triggered for both the Stores. image
github-jira-sync-bot commented 3 years ago

:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-1099 is successfully created for this GitHub issue.

m2-assistant[bot] commented 3 years ago

:white_check_mark: Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

github-jira-sync-bot commented 3 years ago

:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.magento.com/browse/AC-1099

LexKoomen commented 2 years ago

Any update on this?

topanok commented 2 years ago

@magento I am working on this