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 Answers
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.? Commented Oct 10, 2018 at 6:04
As per your requirement you have go through below link to achieve your all things.
I hope it will help to you.