I have a configurable product with 4 configurable attribute, and this configurable product has 1000 of values in each configurable attribute. So my simple products of above configurable product ranges from 50k to 100k. The problem is when product view page loads, it loads all the values of the 4 configurable attributes dropdown which slows down the page load. Following code gets all the data.

<script type="text/x-magento-init">
                "#product_addtocart_form": {
                    "configurable": {
                        "spConfig": <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>,
                        "gallerySwitchStrategy": "<?php /* @escapeNotVerified */ echo $block->getVar('gallery_switch_strategy',
                            'Magento_ConfigurableProduct') ?: 'replace'; ?>"

I have created another function getJsonConfigCustom($attributeId, $attributeValue) to get values of configurable attributes which works perfectly fine. Based on the value selected from the first drop-down I want to query above code with new values. The function getJsonConfigCustom is passed with two parameters. On page load $attributeId will be the first configurable attribute Id and $attributeValue will be null indicating to get all the value of $attributeId related to the product. When first configurable attribute is selected from the dropdown, the function will be passed with attributeId of the selected dropdown and with the value in second parameter and the output will contain details of first and second attributes value and product options. I have written the above code and works perfectly on manual calls. But I want to automate this on dropdown selections which I think will be achievable when I try to run above code again and again with new sets of value for spConfig.

Is it possible to run above script tag again and again?

  • So i have managed to run the script tag again and again, but I have encountered a new problem which is, it refreshed the form values, so it doesn't matter what I select in first dropdown, the form input select fields resets. Any idea how to retain the selected dropdown? @marius could you please help me out? – Nausif Oct 30 '17 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.