skip to Main Content

I added qty input on product list (list.phtml) is any way to implement solution with update qty like on cart page or minicart? not just add to cart but update qty in product list.

Regards Matt

2

Answers


  1. You can use something like this:

    <?php $postParams = $block->getAddToCartPostParams($_product); ?>
    
    <form data-role="tocart-form" onsubmit="return false;" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
        <?php echo $block->getBlockHtml('formkey')?>
        <input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
        <input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
        <input type="text" name="qty" id="qty" class="qty" value="1"/>
        <button type="submit"
                title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
                class="action tocart primary"
                <span class="label">
                    <?php /* @escapeNotVerified */ echo __('Add to Cart') ?>
                </span>
        </button>                                                
    </form>  
    

    But this will work only with simple products.

    Login or Signup to reply.
  2. Replace below code in mincart.phtml and deply :

    <?php
    /**
     * Copyright © 2016 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    
    // @codingStandardsIgnoreFile
    
    /** @var $block MagentoCheckoutBlockCartSidebar */
    ?>
    
    <div data-block="minicart" class="minicart-wrapper">
        <a class="action showcart" href="<?php /* @escapeNotVerified */ echo $block->getShoppingCartUrl(); ?>"
           data-bind="scope: 'minicart_content'">
            <span class="text"><?php /* @escapeNotVerified */ echo __('Warenkorb'); ?></span>
            <span class="counter qty empty"
                  data-bind="css: { empty: !!getCartParam('summary_count') == false }, blockLoader: isLoading">
                <span class="counter-number"><!-- ko text: getCartParam('summary_count') --><!-- /ko --></span>
                <span class="counter-label">
                <!-- ko if: getCartParam('summary_count') -->
                    <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
                    <!-- ko i18n: 'items' --><!-- /ko -->
                <!-- /ko -->
                </span>
            </span>
        </a>
        <?php if ($block->getIsNeedToDisplaySideBar()): ?>
            <div class="block block-minicart empty"
                 data-role="dropdownDialog"
                 data-mage-init='{"dropdownDialog":{
                    "appendTo":"[data-block=minicart]",
                    "triggerTarget":".showcart",
                    "timeout": "2000",
                    "closeOnMouseLeave": false,
                    "closeOnEscape": true,
                    "triggerClass":"active",
                    "parentClass":"active",
                    "buttons":[]}}'>
                    <div class="menu-main-title-mobile min-cart-mob">
                                <a href="#" class="close-mega-menu"><?php echo __('< Zurück') ?></a>
                                <h4><span><?php echo __('Warenkorb') ?></span></h4>                     
                            </div>
                <div id="minicart-content-wrapper" data-bind="scope: 'minicart_content'">
                <?php   /* <div class="menu-main-title">
                        <h3>Ihr EGLO Warenkorb</h3>
                        <span><a href="#"> Liste hochladen</a></span>
                        <a href="#" class="close-mega-menu">Schliessen   x</a>
                    </div> */ ?>
                    <!-- ko template: getTemplate() --><!-- /ko -->
    
                </div>
                <?php //echo $block->getChildHtml('minicart.addons'); ?>
            </div>
        <?php endif ?>
        <script>
            window.checkout = <?php /* @escapeNotVerified */ echo Zend_Json::encode($block->getConfig()); ?>;
        </script>
        <script type="text/x-magento-init">
        {
            "[data-block='minicart']": {
                "Magento_Ui/js/core/app": <?php /* @escapeNotVerified */ echo $block->getJsLayout();?>
            },
            "*": {
                "Magento_Ui/js/block-loader": "<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('images/loader-1.gif'); ?>"
            }
        }
        </script>
    </div>
    <script>
    
    /* Minicart Plus Minus Script */
    function cartplus(elementId) {
        var qty = document.getElementById('cart-item-'+elementId+'-qty').value; 
        qty = parseInt(qty) + 1;
        document.getElementById('cart-item-'+elementId+'-qty').value = qty;
        document.getElementById('update-cart-item-'+elementId).style.display = "block";
    
        }
    
    function cartminus(elementId){
         var qty = document.getElementById('cart-item-'+elementId+'-qty').value;    
        qty = parseInt(qty) - 1;
        if (qty < 0)
           qty = 0;
        document.getElementById('cart-item-'+elementId+'-qty').value = qty;
        document.getElementById('update-cart-item-'+elementId).style.display = "block";
        }
    
    /* Minicart Plus Minus Script End */
    
    </script>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search