On a custom page I want to show only the swatches of a configurable product and automatically update the product price based on the chosen swatches.
I managed to get the swatches and price to show up on the page, but I can't get the price to update automatically.
My custom page layout:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="empty" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Magento_Swatches::css/swatches.css"/>
</head>
<body>
<referenceContainer name="content">
<block class="Company\Module\Block\FormBlock" name="iframe.form" template="Company_Module::form.phtml" cacheable="false">
<block class="Magento\Catalog\Block\Product\View" name="product.info.options.wrapper" as="product_options_wrapper" template="Magento_Catalog::product/view/options/wrapper.phtml">
<block class="Magento\Swatches\Block\Product\Renderer\Configurable" name="product.info.options.swatches" as="swatch_options" before="-" />
<container name="product.info.price" label="Product info auxiliary container" htmlTag="div" htmlClass="product-info-price">
<block class="Magento\Catalog\Pricing\Render" name="product.price.final">
<arguments>
<argument name="price_render" xsi:type="string">product.price.render.default</argument>
<argument name="price_type_code" xsi:type="string">final_price</argument>
<argument name="zone" xsi:type="string">item_view</argument>
</arguments>
</block>
</container>
</block>
</block>
</referenceContainer>
</body>
</page>
The FormBlock extends Magento\Catalog\Block\Product\View
, in the controller I set the 'product' registry to the product being viewed with $this->registry->register('product', $product);
.
The form.phtml
file simply calls <?= $block->getChildHtml() ?>
.