3

I have the following file

Vendor/Catalog/view/templates/product/view/type/options/configurable.phtml

Content of that file as follows

<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>

<?php
/** @var $block \Vendor\Catalog\Block\Product\Renderer\Configurable*/
$_product    = $block->getProduct();
$_attributes = $block->decorateArray($block->getAllowAttributes());
?>
<?php //var_dump($block->getJsonConfig())?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
    <?php foreach ($_attributes as $_attribute): ?>
        <div class="field configurable required">
            <label class="label" for="attribute<?php /* @escapeNotVerified */ echo $_attribute->getAttributeId() ?>">
                <span><?php echo $block->escapeHtml($_attribute->getProductAttribute()->getStoreLabel()) ?></span>
            </label>
            <div class="control">
                <select name="super_attribute[<?php /* @escapeNotVerified */ echo $_attribute->getAttributeId() ?>]"
                        data-selector="super_attribute[<?php /* @escapeNotVerified */ echo $_attribute->getAttributeId() ?>]"
                        data-validate="{required:true}"
                        id="attribute<?php /* @escapeNotVerified */ echo $_attribute->getAttributeId() ?>"
                        class="super-attribute-select">
                    <option value=""><?php /* @escapeNotVerified */ echo __('Choose an Option...') ?></option>
                </select>
            </div>
        </div>
    <?php endforeach; ?>
    <script id="configurable_attribute_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'; ?>"
                }
            }
        }
    </script> 
<?php endif;?>

I'm trying to call a function of following js file

vendor/magento/module-configurable-product/view/frontend/web/js/configurable.js

I added following code in above phtml file

<script>
 define('configurable_attribute_change',['jquery','configurableJs'],function($,configurable){
 configurable._initializeOptions();
 });
 require(['configurable_attribute_change']);
</script>

I'm just trying to call a function to see if its possible to make a call. I even added a following require.js file

app/code/Vendor/Catalog/view/frontend/requirejs-config.js

with following content

var config = {
    map: {
        '*': {
            configurableJs: 'Magento_ConfigurableProduct/js/configurable'
        }
    }
};

But I'm getting this error in console. enter image description here

Is there a way to call configurable.js functions?

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.