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.55k stars 9.32k forks source link

mageSwatchRenderer is undefined on PDP #36937

Open Mugentoki opened 1 year ago

Mugentoki commented 1 year ago

Preconditions and environment

Steps to reproduce

After setting up the fresh M2 instance with demo data

  1. Go to any product with swatches (size, color)
  2. In developer console, try to access the swatch renderer with jQuery('[data-role=swatch-options]').data('mageSwatchRenderer')

Expected result

Swatch renderer should be initialized and data be accessible image

Actual result

Swatch renderer is undefined image

Additional information

I still had a clean installed M2 version 2.3.4 around, and there it's working just fine.

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 year ago

Hi @Hoargarth. Thank you for your report. To speed up processing of this issue, 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:

Mugentoki commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @Hoargarth. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @Hoargarth, here is your Magento Instance: https://d9d1a9d5bfe4d0486845cb818bc2ce33.instances.magento-community.engineering Admin access: https://d9d1a9d5bfe4d0486845cb818bc2ce33.instances.magento-community.engineering/admin_2da3 Login: 2844ce62 Password: 9bf9e8dce4ed

m2-assistant[bot] commented 1 year ago

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: :point_down:


Mugentoki commented 1 year ago

Checked on the radiant-tee /radiant-tee.html And can reproduce the issue

image

Mugentoki commented 1 year ago

There's this file in vendor vendor/magento/module-swatches/view/frontend/web/js/configurable-customer-data.js which is referencing mageSwatchRenderer

    var selectors = {
            formSelector: '#product_addtocart_form',
            swatchSelector: '.swatch-opt'
        },
        swatchWidgetName = 'mageSwatchRenderer',
        widgetInitEvent = 'swatch.initialized',



However, further inspecting the jQuery object in browser I can see it's actually attached with mage-SwatchRenderer and can be accessed like that jQuery('[data-role=swatch-options]').data('mage-SwatchRenderer')

image


So the question now arises, which one is correct? mageSwatchRenderer or mage-SwatchRenderer

engcom-Dash commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Dash. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Dash, here is your Magento Instance: https://d9d1a9d5bfe4d0486845cb818bc2ce33.instances.magento-community.engineering Admin access: https://d9d1a9d5bfe4d0486845cb818bc2ce33.instances.magento-community.engineering/admin_6216 Login: b05b0c3a Password: 105d382344ce

engcom-Dash commented 1 year ago

Hi @Hoargarth ,

Thanks for Raising this issue,

Could you please provide the exact steps which you followed for this issue.Because it will helps to proceed further in this case.

Thanks.

Mugentoki commented 1 year ago

Hi @engcom-Dash

First of all, I've lowered the severity to S3 as it's not affecting the store user, but us developers.

Detailed steps below:

  1. In frontend, go to the product page of any product, which has a size and/or color
  2. Open your browsers developer toolbar and go to the developer console
  3. Input following JavaScript into the console jQuery('[data-role=swatch-options]').data('mageSwatchRenderer')

The problem is not limited to the developer toolbar, but also happens when trying to access the 'mageSwatchRenderer' module by code in any .phtml or .js file. For example if you want to extract the selected product ID like it's being described in this article and was working at least until Magento 2.4.0

Also as I mentioned in my previous comment, I could already debug it a bit.

engcom-Dash commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Dash. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Dash, here is your Magento Instance: https://d9d1a9d5bfe4d0486845cb818bc2ce33.instances.magento-community.engineering Admin access: https://d9d1a9d5bfe4d0486845cb818bc2ce33.instances.magento-community.engineering/admin_ee2d Login: bb45d853 Password: efb072fb3195

engcom-Dash commented 1 year ago

Hi @Hoargarth ,

Verified the issue is 2.4-develop instance and the issue is reproducible.

Description: mageSwatchRenderer is undefined on PDP

Prerequisite:

Magento Version 2.4-develop PHP Version 8.1

Actual result: Swatch renderer should be initialized and data be accessible

Expected Result: Swatch renderer is undefined

Steps to reproduce: 1.In frontend, go to the product page of any product, which has a size and/or color 2.Open your browsers developer toolbar and go to the developer console 3.Input following JavaScript into the console jQuery('[data-role=swatch-options]').data('mageSwatchRenderer')

Screenshots for your reference:

unde1

We are getting Actual result which is Swatch renderer is undefined ,Hence we are confirming the issue in 2.4-develop instance.

Let us know if we are missing anything

Thanks,

m2-assistant[bot] commented 1 year 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:

github-jira-sync-bot commented 1 year ago

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

m2-assistant[bot] commented 1 year 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.

engcom-November commented 1 year ago

Hi @Hoargarth , Thank you for the response. I re-checked the issue on latest Magento 2.4-develop instance and verified the code in /Swatches/view/frontend/web/js/configurable-customer-data.js and is mentioned as swatchWidgetName = 'mage-SwatchRenderer' but not mageSwatchRenderer also data is displayed in console on verifying with mage-SwatchRenderer image Kindly recheck the code on Magento 2.4-develop instance as it is having latest code base and upcoming 2.4.x release and let us know if you are still facing any issues. https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Swatches/view/frontend/web/js/configurable-customer-data.js Thank you.

Mugentoki commented 1 year ago

Hi @engcom-November since https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Swatches/view/frontend/web/js/configurable-customer-data.js is now also using mage-SwatchRenderer, I assume the change from mageSwatchRenderer was intended?

If so, then this issue can be closed. But I highly recommend to add a documentation about the change somewhere in the docs. Many blog articles are referencing mageSwatchRenderer

mrtuvn commented 1 year ago

mage-SwatchRenderer is correct widget name -> you should use that name

mrtuvn commented 1 year ago

https://github.com/magento/magento2/blob/2.4.6/app/code/Magento/Swatches/view/frontend/web/js/configurable-customer-data.js version 2.4.6

mrtuvn commented 1 year ago

@dobooth Is there any docs official related with this area ? mageSwatchRenderer In my opinion other blog also should update code snippets to latest version. I don't sure current docs mention this somewhere

engcom-November commented 1 year ago

Hi @Hoargarth , There is no official Magento documentation referring this topic in devdocs & docs to raise an issue report in https://github.com/magento/devdocs or https://github.com/magento/merchdocs repositories to update the changes. Please share the official articles that are are referencing mageSwatchRenderer if any. Thank you.

mrtuvn commented 1 year ago

https://docs.swissuplabs.com/m2/argento/customization/adding-prices-to-magento-swatches/ https://argentotheme.com/knowledgebase/faq/adding-price-to-magento-2-swatches-with-argento-possibilities/ Here is some refer i got after search @engcom-November still refer to old name. But can't find official docs for this