I want to have two add to cart in product view page.

So from somewhere I've found the following code

    $postDataHelper = $this->helper('Magento\Framework\Data\Helper\PostHelper');
    $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_product), ['product' => $_product->getEntityId()])
<button class="action tocart primary"
        data-post='<?php /* @escapeNotVerified */ echo $postData; ?>'
        type="button" title="<?php /* @escapeNotVerified */ echo __('Add to Cart') ?>">
    <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>

Where $_product is my product. well this code is working fine for the simple products but not working for configurable products where I've to choose options(like size,color etc.)..

Even if I select all those attributes the default add to cart button is working fine but that button created by code is giving me error

You need to choose options for your item.

So anyidea how can I solve this issue for configurable products??

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.