Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Add Multiple To Cart failing after 1.3.0 upgrade
 
circa1977
Member
 
Total Posts:  65
Joined:  2008-03-01
 

We had the following custom action working prior to our 1.3.0 upgrade utilizing LKC Modular Routers. 1.3.0 has broken Modular Routers, but with Lee’s tips, we’ve gotten the custom action working again. It works in that it can be accessed, but fails on the addProduct() method.

This worked before and took us quite a while to build. Anyone see why it would stop working in 1.3.0?

We’ve begun receiving “Stock item for Product is not valid” which we’ve traced to app/code/core/Mage/CatalogInventory/Model/Observer.php. Adding products to the cart via the site works fine, no changes have been made to inventory.

require_once 'Mage/Checkout/controllers/CartController.php';

class 
SlimKiwi_Checkout_CartController extends Mage_Checkout_CartController
{
  
/**
   * Adding multiple products to shopping cart action
   * based on Mage_Checkout_CartController::addAction()
   * see also http://www.magentocommerce.com/boards/viewthread/8610/
   * and http://www.magentocommerce.com/wiki/how_to_overload_a_controller
   */
  
public function addmultipleAction()
  
{
    $dbg 
true;
    if(
$dbg)  echo $this->getRequest()->getRequestUri() . "\n";
    
$product_infos = array();
    
$oversized_products = array();
    if(
$this->getRequest()->getParam('order_list')) //Thule
      
$order_list split(','$this->getRequest()->getParam('order_list'));
      foreach(
$order_list as $order{
        $product_infos[] 
split('_'$order);
      
}
    } 
else {                                          //Assuming Yakima
      
$params $this->getRequest()->getParams();
      foreach(
$params as $param => $value{
        
if(preg_match('/^p[0-9]+$/'$param)) {
          $product_infos[] 
array_slice(split(','$value), 02false);
        
}
      }
    }
    
if($dbgvar_dump($product_infos);
    
$catalog_product Mage::getModel('catalog/product');
    foreach(
$product_infos as $product_info{
      try{
        
if($dbg)  echo "\n..............\nProduct:\n";
        if(
$dbg)  var_dump($product_info);
        if(
$dbg)  echo "\n";

        
$products $catalog_product->getCollection();
        
$products->addAttributeToFilter('sku'$product_info[0]);
        
$products->addAttributeToSelect('*');
        
$products->load();

        
$cart $this->_getCart();
        foreach(
$products as $product{
          
if($dbg)  echo "Product Instance: " $product->getName() . "\n";
          if(!
$product->getOversized()) {
            
if($dbg)  echo "Not Oversized\n";
            if(
$dbg)  echo "Starting Count: " $cart->getItemsCount() . "\n";
            if(
$dbg)  echo "Product Status: " $product->getStatus() . "\n";

            
$eventArgs = array(
                    
'product' => $product,
                    
'qty' => intval($product_info[1]),
                    
'additional_ids' => array(),
                    
'request' => $this->getRequest(),
                    
'response' => $this->getResponse(),
                );
            
Mage::dispatchEvent('checkout_cart_before_add'$eventArgs);
            if(
$dbg)  echo "\n-->Line before addProduct<--\n";
            
/*echo "\nCart (valid :\n";
            var_dump($cart);
            echo "\n\n";*/
            
$cart->addProduct($productintval($product_info[1]));
            
/* DOES NOT REACH THIS POINT */
            
Mage::dispatchEvent('checkout_cart_after_add'$eventArgs);

            
$cart->save();
            
$this->_getSession()->setCartWasUpdated(true);
            
Mage::dispatchEvent('checkout_cart_add_product', array('product'=>$product));

            if(
$dbg)  echo "Ending Count: " $cart->getItemsCount() . "\n";
            if(
$dbg)  echo "Quote Id: " $cart->getQuote()->getId() . "\n";

            
$message $this->__('%s was successfully added to your shopping cart.'$product->getName());
            
Mage::getSingleton('checkout/session')->addSuccess($message);
          
else {
            
if($dbg) echo "Oversized\n";
            
$oversized_products[] = array($productintval($product_info[1]));
            
$err_message $product->getName() . ': ' 'Unable to add to cart. Please select shipping option';
            
Mage::getSingleton('checkout/session')->addNotice($err_message);
          
}
        }
      }
      
catch (Mage_Core_Exception $e{
        
if($dbg) echo "Mage Core Exception Thrown\n";
        if(
$dbg) echo $e->getMessage()."\n";
        
$name "Adding Product";
        if(isset(
$product)) {
          $name 
$product->getName();
        
}

        
if (Mage::getSingleton('checkout/session')->getUseNotice(true)) {
          Mage
::getSingleton('checkout/session')->addNotice($name ': ' $e->getMessage());
        
else {
          Mage
::getSingleton('checkout/session')->addError($name ': ' $e->getMessage());
        
}
      }
      
catch (Exception $e{
        
if($dbg) echo "General Exception Thrown\n";
        if(
$dbg) echo $e->getMessage()."\n";
        
Mage::getSingleton('checkout/session')->addException($e$this->__('Can not add item to shopping cart'));
      
}
    }
    
if($dbg) exit();
    if(
count($oversized_products) != 0{
      $this
->_redirectUrl($oversized_products[0][0]->getProductUrl());
    
else {
      $this
->_redirect('checkout/cart');
    
}
  }
 
Magento Community Magento Community
Magento Community
Magento Community
 
l781
Sr. Member
 
Total Posts:  109
Joined:  2008-11-09
 

any news on this topic? i neet multiple add to cart feature…

 
Magento Community Magento Community
Magento Community
Magento Community
 
l781
Sr. Member
 
Total Posts:  109
Joined:  2008-11-09
 

bump! any news...?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top