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

Page 2 of 9
Add multiple products to cart - example
 
vman
Jr. Member
 
Total Posts:  3
Joined:  2009-01-23
 

does this work in 1.2.03 of Magento ?

I really need this functionaliy for my shop

 
Magento Community Magento Community
Magento Community
Magento Community
 
rtgr
Jr. Member
 
Total Posts:  12
Joined:  2008-11-19
 

I can confirm it works for 1.2.1, my guess is it will also work for 1.2.03

 
Magento Community Magento Community
Magento Community
Magento Community
 
ethan schaefer
Jr. Member
 
Total Posts:  12
Joined:  2009-01-14
 
uni-man - 09 June 2008 12:44 AM

Hi all

Create a new file Company/Module/controllers/Checkout/CartController.php

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

class 
Company_Module_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()
    
{
        $productIds 
$this->getRequest()->getParam('products');
        if (!
is_array($productIds)) {
            $this
->_goBack();
            return;
        
}

        
foreach( $productIds as $productId{
            
try {
                $qty 
$this->getRequest()->getParam('qty' $productId0);
                if (
$qty <= 0) continue; // nothing to add
                
                
$cart $this->_getCart();
                
$product Mage::getModel('catalog/product')
                    ->
setStoreId(Mage::app()->getStore()->getId())
                    ->
load($productId)
                    ->
setConfiguredAttributes($this->getRequest()->getParam('super_attribute'))
                    ->
setGroupedProducts($this->getRequest()->getParam('super_group', array()));
                
$eventArgs = array(
                    
'product' => $product,
                    
'qty' => $qty,
                    
'additional_ids' => array(),
                    
'request' => $this->getRequest(),
                    
'response' => $this->getResponse(),
                );
    
                
Mage::dispatchEvent('checkout_cart_before_add'$eventArgs);
    
                
$cart->addProduct($product$qty);
    
                
Mage::dispatchEvent('checkout_cart_after_add'$eventArgs);
    
                
$cart->save();
    
                
Mage::dispatchEvent('checkout_cart_add_product', array('product'=>$product));
    
                
$message $this->__('%s was successfully added to your shopping cart.'$product->getName());    
                
Mage::getSingleton('checkout/session')->addSuccess($message);
            
}
            
catch (Mage_Core_Exception $e{
                
if (Mage::getSingleton('checkout/session')->getUseNotice(true)) {
                    Mage
::getSingleton('checkout/session')->addNotice($product->getName() . ': ' $e->getMessage());
                
}
                
else {
                    Mage
::getSingleton('checkout/session')->addError($product->getName() . ': ' $e->getMessage());
                
}
            }
            
catch (Exception $e{
                Mage
::getSingleton('checkout/session')->addException($e$this->__('Can not add item to shopping cart'));
            
}
        }
        $this
->_goBack();
    
}
}

anyone know where that directory/file is?
I cannot find a company directory anywhere.  My version is 1.2.1

 
Magento Community Magento Community
Magento Community
Magento Community
 
rtgr
Jr. Member
 
Total Posts:  12
Joined:  2008-11-19
 

Company is a name you can choose yourself, it can be your own company name, or the name of the storecompany for example
You create the folder under [magentodirectory]/app/code/local/ and you have to activate your module described over here

http://activecodeline.com/writing-a-custom-module-in-magento-detailed-walktrough/

good luck:)

 
Magento Community Magento Community
Magento Community
Magento Community
 
ethan schaefer
Jr. Member
 
Total Posts:  12
Joined:  2009-01-14
 

Everything went smooth, except i’m getting an error:

Fatal error: Class ‘Mage_Module_Helper_Multiple’ not found in /home/dfstore/public_html/magento/app/code/core/Mage/Core/Model/App.php on line 830

any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
ethan schaefer
Jr. Member
 
Total Posts:  12
Joined:  2009-01-14
 
zero cool - 15 December 2008 07:37 AM

Hi jpluttme,

I’m coding this mod 4 u in SL, smile. Just replace the Company by Mage. When I do it, not fatal error anymore. But the URL I got is not exactly. I do not know how to fix it.

Thanks,

what do you exactly mean by replace company with mage? i’ve renamed the namespace to mage and replaced it everywhere i recall it being, however it doesn’t fix my error.

it keeps telling me:
Fatal error: Class ‘Mage_Module_Helper_Multiple’ not found in /home/dfstore/public_html/magento/app/code/core/Mage/Core/Model/App.php on line 830

 
Magento Community Magento Community
Magento Community
Magento Community
 
Nexus Rex
Sr. Member
 
Avatar
Total Posts:  139
Joined:  2008-07-10
Utah, USA
 

Can anybody post a live example of what this modification functions like?

 
Magento Community Magento Community
Magento Community
Magento Community
 
levy
Jr. Member
 
Total Posts:  2
Joined:  2009-01-03
 

Hi .

I got it work for 1.2. I am sure it will work for 1.3 , but I didn’t try yet.

I am sure here few problems but it is work.

What I did :

1. For Helper change: Company_Module_Helper_Multiple to Mage_Module_Helper_Multiple

2. Function addmultipleAction() ( from CartController.php ) Insert inside class Mage_Checkout_CartController extends Mage_Core_Controller_Front_Action { } in \app\code\core\Mage\Checkout\controllers\CartController.php

I think some problem with url in Mage_Module_Helper_Multiple it looking for addmultipleAction() and can;t find it in checkout/cart/addmultiple

if some one can fix it , welcome smile

in few days I will upload example to http://www.eddiesperfume.com

---------------------------------------------------------------------------------

http://www.sasin.info

 
Magento Community Magento Community
Magento Community
Magento Community
 
Nexus Rex
Sr. Member
 
Avatar
Total Posts:  139
Joined:  2008-07-10
Utah, USA
 

I got it installed and it works great:
http://www.clearprotector.com/phone-protectors/apple.html

 
Magento Community Magento Community
Magento Community
Magento Community
 
levy
Jr. Member
 
Total Posts:  2
Joined:  2009-01-03
 

Nexus Rex , Did you install in my way ? or it work with original code ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Nexus Rex
Sr. Member
 
Avatar
Total Posts:  139
Joined:  2008-07-10
Utah, USA
 

That example uses the original code from uni-man at the beginning of this thread.

 
Magento Community Magento Community
Magento Community
Magento Community
 
5erTag
Member
 
Total Posts:  46
Joined:  2008-04-08
 
Andrewc - 22 September 2008 03:47 AM

Ok I did not tell Magento that I had a new module.

Found help here on how to do this: http://www.getfido.net/blog/magento/simple-custom-module.php

Link doens´t work anymore,

Use this one:
http://www.magentocommerce.com/wiki/how-to/create-payment-method-module

Take care of telling Magento, that there is a new module.
(app/etc/module/your_company_moduleName.xml

Quite don´t know anything about depends on in the your_company_moduleName.xml, but i suggest its the major module of magentos Core in app/code/core/Mage/

UPD: Yes, that works for me,

in the DEPENDS Block you have to put the magento Core Module:

<depends>

<Mage_Checkout />

</depends>

 
Magento Community Magento Community
Magento Community
Magento Community
 
5erTag
Member
 
Total Posts:  46
Joined:  2008-04-08
 
levy - 05 May 2009 09:12 PM

Hi .

I got it work for 1.2. I am sure it will work for 1.3 , but I didn’t try yet.

I am sure here few problems but it is work.

What I did :

1. For Helper change: Company_Module_Helper_Multiple to Mage_Module_Helper_Multiple

2. Function addmultipleAction() ( from CartController.php ) Insert inside class Mage_Checkout_CartController extends Mage_Core_Controller_Front_Action { } in \app\code\core\Mage\Checkout\controllers\CartController.php

I think some problem with url in Mage_Module_Helper_Multiple it looking for addmultipleAction() and can;t find it in checkout/cart/addmultiple

if some one can fix it , welcome smile

in few days I will upload example to http://www.eddiesperfume.com

---------------------------------------------------------------------------------

http://www.sasin.info

I suggest, “.......checkout/cart/addmultiple” is not a real path to a directory, but to the Function addmultipleAction,
instead a Function-Call normally works if you write down the whole name, but somehow (for me) magento synthax is effective and maybe similar to the module-Creation, some things are “filtered” by the core.

Because, if you look to the original CArtController.php, there is a add addAction-Function, and it is (i suggest) called (ijn the orginal Cart.php with that call:
return $this->_getUrl(’checkout/cart/add’, $params);

if you look into the original cartController.php you find DeleteAction, UpdatePostAction

But in the Cart.php there are similar “Pathes”, but without “...Action”

Maybe someone can confirm, if i´m right or wrong.

 
Magento Community Magento Community
Magento Community
Magento Community
 
5erTag
Member
 
Total Posts:  46
Joined:  2008-04-08
 

It´s me again,

its horrible, in the list.phtlm, i get no Form Action- Content, the following line returns nothing, expect it not calling the helper at all, because the source ends with
form action=”

<form action="<?php echo $this->helper('Module/MultipleCart')->getAddToCartUrl() ?>

somebody got an idea?

If i hardcode the form action like this form action ="”

everything is ok (except that nothing happens if i hit the button:-))

So it seems, that he s not raching the Function.........

Greetings

MArc

 
Magento Community Magento Community
Magento Community
Magento Community
 
5erTag
Member
 
Total Posts:  46
Joined:  2008-04-08
 

i think my Problem is located here:

<form action="<?php echo $this->helper('Cartmods/Multicartaction/multiple')->getAddToCartUrl() ?>” method="post" id="product_addtocart_form">

i dont know how it refers to the new helper, normally its located in Mage/core/ModuleName
but in this case its located in community/Cartmods/Multicartaction

Further i don´t know, how the rewriteRule works:

<rewrite>
<Cartmods_Multicartaction_checkout_cart>
<from><![CDATA[#^/checkout/cart/addmultiple/.*$#]]></from>
<to>/Module/checkout/addmultiple/</to>
</Cartmods_Multicartaction_checkout_cart>
</rewrite>

Should i modify it like this? ( tried it already and it did/nt work)

<to>/Multicartaction/checkout/addmultiple/</to>

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 2 of 9