epynic
epynic

Reputation: 1164

Product List page get the currently added QTY , besides the product name - Magento

In product list page how can I get the quantity currently added in the cart.

Product list page

Just in case if i have 'ottoman' 10 qty in the cart, how can i show the added QTY besides the product name.

Upvotes: 1

Views: 213

Answers (1)

Amit Bera
Amit Bera

Reputation: 7611

add below code start of list.phtml

<?php 
$currentCart=array();
//$currentCartItemDetails=array();
$quote = Mage::getSingleton('checkout/session')->getQuote();
 foreach ($quote->getAllItems() as $item) {
            if ($item->getProductId()) {
            $currentCart[$item->getProductId()]=$item->getQty();
            }
        }?>

after that add below code after isSaleable()): ?>

 <?php 
                    if (isset($currentCart) and array_key_exists($_product->getId(), $currentCart)) { 
                    ?>
                    <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $currentCart[$_product->getId()] ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
                    <?php }?>

Upvotes: 1

Related Questions