微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将可配置产品选项添加到Magento 2中的类别列表页面

如何解决将可配置产品选项添加到Magento 2中的类别列表页面

我正在尝试将可配置选项添加到Magento 2的类别列表中,我能够添加下拉列表,但它不会更新价格,也不会直接将产品添加到购物车中。该代码添加到Catalog-> templates-> product-> list.phtml中,如何将下拉列表或整个可配置块正确添加到类别列表页面。

<?PHP
$_objectManager= \Magento\Framework\App\ObjectManager::getInstance();
$productTypeInstance = $_objectManager->get('Magento\ConfigurableProduct\Model\Product\Type\Configurable');
$productAttributeOptions = $productTypeInstance->getConfigurableAttributesAsArray($_product);
if (!empty($productAttributeOptions)) { //check if product has custom options. If it doesn't go to the next product
    foreach($productAttributeOptions as $productAttributeOption){
        ?>
        <p><span><?PHP echo $productAttributeOption['label']; ?></span></p>
        <select name="super_attribute[<?PHP echo $productAttributeOption['attribute_id'] ?>]" data-selector="super_attribute[151]" data-validate="{required:true}" id="attribute151" class="super-attribute-select" aria-required="true">
            <?PHP
            foreach($productAttributeOption['values'] as $configure_option)
            {
                ?>
                <option value="<?PHP echo $configure_option['value_index']; ?>"><?PHP echo $configure_option['label'] ?></option>
                <?PHP
            }
            ?>

        </select>
        <?PHP
    }
}
?>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。