سؤال

I added my mini cart to the header and now I have a nice popup that shows the list of items inside my cart. I can see how many items I have of each on my cart but I want the user to be able to change that quantity. What is the best way to achieve this?

This is the part that's getting the content of the mini cart:

<?php $_items = $this->getRecentItems() ?>
    <?php if(count($_items)): ?>

            <div id="header-items">
                <!--div class="block-subtitle">
                    <span><?php echo $this->__('Recently added item(s)') ?></span> 
                    <div class="clear"></div>
                </div>-->

                <ol id="cart-sidebar" class="mini-products-list">
                <?php foreach($_items as $_item): ?>
                    <?php echo $this->getItemHtml($_item) ?>
                <?php endforeach; ?>
                </ol>
                <a class="view_all" href="<?php echo $this->getUrl('checkout/cart')?>"><?php echo ($_cartQty > 3) ? $this->__('View All Items'): $this->__('View Cart');?></a>                                             
                <button type="button" title="<?php echo $this->__('Checkout') ?>" class="button checkout" onclick="window.location='<?php echo $this->getUrl('checkout/onepage')?>';"><span><span><?php echo $this->__('Checkout') ?></span></span></button>                                
                <div class="clear"></div>
            </div>
        <script type="text/javascript">decorateList('cart-sidebar', 'none-recursive')</script>

    <?php else: ?>
        <div id="header-items">
            <p class="empty"><?php echo $this->__('You have no items in your shopping cart.') ?></p>
        </div>
    <?php endif ?>

And on the php file I have this (among other functions):

public function getRecentItems($count = null)
    {
        if ($count === null) {
            $count = $this->getItemCount();
        }

        $items = array();
        if (!$this->getSummaryCount()) {
            return $items;
        }

        $i = 0;
        $allItems = array_reverse($this->getItems());
        foreach ($allItems as $item) {
            /* @var $item Mage_Sales_Model_Quote_Item */
            if (!$item->getProduct()->isVisibleInSiteVisibility()) {
                $productId = $item->getProduct()->getId();
                $products  = Mage::getResourceSingleton('catalog/url')
                    ->getRewriteByProductStore(array($productId => $item->getStoreId()));
                if (!isset($products[$productId])) {
                    continue;
                }
                $urlDataObject = new Varien_Object($products[$productId]);
                $item->getProduct()->setUrlDataObject($urlDataObject);
            }

            $items[] = $item;
            if (++$i == $count) {
                break;
            }
        }

        return $items;
    }

Right now this gives me this: item - qty - remove button - edit button And I want to replace the edit button with input to change the quantity of the items

هل كانت مفيدة؟

المحلول

It doesn't matter what cart you are talking about. What you need is the URL which is called to change the qty of a product and these url is:

\Mage_Checkout_CartController::updatePostAction()

so the url is:

$this->getUrl('checkout/cart/updatePost');

And then you just need to add the $qouteIitem->getId() and the new $qty in a form. Send the form in the format array(cart => array($quoteItemId => $qty)) to this URL and the quantities are updated.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top