#StackBounty: #magento2 #magento2.2 #mini-cart Custom "add to cart" button not updating minicart

Bounty: 50

I’ve added a custom “add to cart” button by overwriting the configurable.phtml file in my theme.

The button adds the product to the cart, however it doesn’t seem to show up in the minicart –


Looking at the newtwork tab, it doesn’t seem to pick up any actual items –

Network tab

Whereas using the default template it passes stuff over in this –

enter image description here

Am I missing something in passing over this data?

I’m essentially changing the configurables from showing in a drop down menu, to having each simple product have an “add to basket” button on the page.

I’ve tried both adding to cart with AJAX and with refreshing the page, but neither seems to work. Once you go to the actual cart page, you can see what these items are – it’s just the minicart that isn’t displaying the items.

I’m also including the

            "#product_addtocart_form": {
                "configurable": {
                    "spConfig": getJsonConfig() ?>,
                    "gallerySwitchStrategy": "getVar('gallery_switch_strategy',
            'Magento_ConfigurableProduct') ?: 'replace'; ?>"

On the page, which has all the simple product details in JSON.

Here is a code excerpt of how i’m displaying / using the buy now button on my custom template –

        foreach ($_children as $child) :
            $productName = $child->getName();

            if ( strpos($productName, '-UK') !== false ) :

getPrice(); echo $this->helper('MagentoFrameworkPricingHelperData')->currency($price,true,false); $productID = $child->getId(); ?>
getAttributeText('subscription_terms'); ?>
Buy Now getViewFileUrl('images/logos/logo_direct-debit.png'); ?>" />
getAddUrl($child);?>" method="post"> getBlockHtml("formkey");?>
  • MaestrogetViewFileUrl('images/logos/logo_maestro.png'); ?>" />
  • MastercardgetViewFileUrl('images/logos/logo_mastercard.png'); ?>" />
  • Verified by VisagetViewFileUrl('images/logos/logo_verified-by-visa.png'); ?>" />
  • PayPalgetViewFileUrl('images/logos/logo_paypal.png'); ?>" />
</div> <?php endif; endforeach; ?>

I’m doing a FOREACH on each simple assigned to the configurable, doing an IF to make sure the SKU is of a certain type and then outputting a Add to cart button for each one.

enter image description here

To get around another problem with the first item not actually going in the basket, I had to add an empty form –

  <form type="hidden" data-role="tocart-form" action=""  method="post"> <?php echo $block->getBlockHtml("formkey");?>
            <input type="hidden" name="product" value="">
            <input type="hidden" name="selected_configurable_option" value="">

Could this be the cause of it?

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.