0

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.

2

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.

  • Thanks Shashank, It is working fine but i want dynamic qty of related product so how to get it.? – Sarfaraj Sipai Oct 10 '18 at 6:04
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.