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

HOW I ADD A PRODUCT to THE CART
 
lakikeanu
Jr. Member
 
Total Posts:  24
Joined:  2008-06-16
 

How i add a Product to the Cart using API ?
it seemes no api defines for that..

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vofka
Jr. Member
 
Avatar
Total Posts:  30
Joined:  2008-06-19
 

try this

$cart Mage::getModel('checkout/cart');
$cart->addProduct($product$qty);
$cart->save();
 
Magento Community Magento Community
Magento Community
Magento Community
 
yshahin
Jr. Member
 
Avatar
Total Posts:  30
Joined:  2008-05-14
 

I think u should do

Mage::getSingleton('checkout/cart')
because you want the already existing cart for this session
 
Magento Community Magento Community
Magento Community
Magento Community
 
collinssolutions
Sr. Member
 
Total Posts:  79
Joined:  2008-07-09
USA Arkansas
 

did you ever get this to work?

 
Magento Community Magento Community
Magento Community
Magento Community
 
edlitmus
Jr. Member
 
Total Posts:  25
Joined:  2008-07-21
 

I have been able to get this working using the getSinglton method:

$cart Mage::getSingleton('checkout/cart');
    
$product_id Mage::getModel('catalog/product')
        ->
setStoreId(Mage::app()->getStore()->getId())
        ->
getIdBySku($sku);

    if (
$product_id{
        $product 
Mage::getModel('catalog/product')
            ->
setStoreId(Mage::app()->getStore()->getId())
            ->
load($product_id);

        if (
$product{
            $cart
->addProduct($product, array($cart->getItemsCount() + $qty));
            
$cart->save();
        
}
        
else {
            error_log
("can't find product id: $product_id");
        
}
    }
    
else {
        error_log
("can't find product sku: $sku");
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
collinssolutions
Sr. Member
 
Total Posts:  79
Joined:  2008-07-09
USA Arkansas
 

this works to an extent. if i click my cart it says the cart is empty. if i click home or checkout it says 1 item in cart. If i go to the cart it says its empty and the number 1 disappears from the my cart link.

 
Magento Community Magento Community
Magento Community
Magento Community
 
collinssolutions
Sr. Member
 
Total Posts:  79
Joined:  2008-07-09
USA Arkansas
 

figured out the problem. the product needs more info in the attributes. I need to figure out how to set the inventory information to use default settings like products added through admin.

 
Magento Community Magento Community
Magento Community
Magento Community
 
collinssolutions
Sr. Member
 
Total Posts:  79
Joined:  2008-07-09
USA Arkansas
 

all done thanks for the help

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

nice! ajax cart, here I come!

can we see your final solution with the necessary attributes, etc?

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