I have created a custom module in magento2
, and I want to show configurable products options in the drop-down for the configurable product.
I have done using custom code, but problem is that when I change the option for a configurable product the price does not change anything
.
Could you please let me know what we need to do to show the change price on the change that is related to the dropdown?
<form data-product-sku="<?= /* @NoEscape */ $product->getSku() ?>"
action="<?= /* @NoEscape */ $block->getSubmitUrl($product) ?>" method="post"
id="product_addtocart_form"<?php if ($product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $product->getId() ?>" />
<input type="hidden" name="selected_configurable_option" value="" />
<input type="hidden" name="related_product" id="related-products-field" value="" />
<?= $block->getChildHtml('form_top') ?>
<?php if (!$block->hasOptions()):?>
<?= $block->getChildHtml('product_info_form_content') ?>
<?php else:?>
<?php if ($_product->isSaleable() && $block->getOptionsContainer() == 'container1'):?>
<?= $block->getChildChildHtml('options_container') ?>
<?php endif;?>
<?php endif; ?>
<?= $block->getBlockHtml('formkey'); ?>
<div class="product-options-wrapper" id="product-options-wrapper" data-hasrequired="* Verplichte velden">
<?php if($product->getTypeId() === 'configurable') : ?>
<?php foreach($product->getTypeInstance()->getConfigurableAttributes($product) as $attribute) : ?>
<div class="field configurable required">
<label class="label" for="attribute<?php echo $attribute->getAttributeId(); ?>"><span><?php echo $attribute->getLabel() ?></span></label>
<?php $values = $attribute->getOptions(); ?>
<div class="control">
<select id="attribute<?php echo $attribute->getAttributeId() ?>" name="super_attribute[<?php echo $attribute->getAttributeId() ?>]" class="super-attribute-select upsell_options" data-validate="{required:true}">
<option value="">Choose an Option...</option>
<?php foreach($values as $value): ?>
<option value="<?php echo $value['value_index'] ?>" ><?php echo $value['label'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<?php endforeach; ?>
<?php
?>
<?php endif; ?>
</div>
<?= $block->getChildHtml('form_bottom') ?>
</form>
<script>
require([
'jquery',
'priceBox'
], function($){
var dataPriceBoxSelector = '[data-role=priceBox]',
dataProductIdSelector = '[data-product-id=<?= $block->escapeHtml($product->getId()) ?>]',
priceBoxes = $(dataPriceBoxSelector + dataProductIdSelector);
priceBoxes = priceBoxes.filter(function(index, elem){
return !$(elem).find('.price-from').length;
});
priceBoxes.priceBox({'priceConfig': <?= /* @escapeNotVerified */ $block->getJsonConfig() ?>});
});