Question

I have a related product list in product detail page. Default there is not qty box available to edit qty i want to add qty box and also it's qty add to checkout/cart page while add specific qty.

Was it helpful?

Solution

You need to first add qty field in related_product.phtml file then rewrite function public function addAction() in file app/code/core/Mage/Checkout/controllers/CartController.php

in this method related products are added just by their ids as shown below-

$related = $this->getRequest()->getParam('related_product');
/**
 * Check product availability
 */
 if (!$product) {
     $this->_goBack();
     return;
 }

 $cart->addProduct($product, $params);
 if (!empty($related)) {
          $cart->addProductsByIds(explode(',', $related));
 }

and here you need to do something like this- Using Fix Quantity :

if (!empty($related)) {
           foreach (explode(',', $related) as $productId) {
              $rp = Mage::getModel('catalog/product')->load($productId);
              $rparams['qty'] = 2; // desired quantity got from frontend
              $cart->addProduct($rp, $rparams);
           }

               // $cart->addProductsByIds(explode(',', $related));
  }

and here you need to do something like this- Using User Entered Quantity :

if (!empty($related)) {
            foreach (explode(',', $related) as $productId) {                    
                $rp = Mage::getModel('catalog/product')->load($productId);                  
                $rparams['qty'] = $this->getRequest()->getParam('related_qty_'.$productId); // desired quantity got from frontend
                $cart->addProduct($rp, $rparams);
            }
            //$cart->addProductsByIds(explode(',', $related));
        }       

and here 'related_qty_'.$productId is quantity textbox name.

above is a basic idea to achieve goal.

please comment if it does not work.

OTHER TIPS

As per your requirement you have go through below link to achieve your all things.

  1. Quantity Field on Related Products Listing
  2. Quantity Field on Related Products Cart

I hope it will help to you.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top