lakikeanu
Total Posts: 24
Joined: 2008-06-16
How i add a Product to the Cart using API ?
it seemes no api defines for that..
Posted: July 29 2008
| top
Vofka
Total Posts: 30
Joined: 2008-06-19
try this
$cart = Mage :: getModel ( 'checkout/cart' ); $cart -> addProduct ( $product , $qty ); $cart -> save ();
Posted: July 29 2008
| top
| # 1
yshahin
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
Signature
Regards,
yshahin
Posted: July 29 2008
| top
| # 2
collinssolutions
Total Posts: 79
Joined: 2008-07-09
USA Arkansas
did you ever get this to work?
Posted: August 8 2008
| top
| # 3
edlitmus
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" ); }
Posted: August 8 2008
| top
| # 4
collinssolutions
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.
Posted: August 8 2008
| top
| # 5
collinssolutions
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.
Posted: August 8 2008
| top
| # 6
collinssolutions
Total Posts: 79
Joined: 2008-07-09
USA Arkansas
all done thanks for the help
Posted: August 8 2008
| top
| # 7
nikefido
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?
Signature
@ My Magento Blog
- Handy tutorials on programming and designing Magento. A continual work in progress!
- Now with a new design, new hosting and a new domain! Check it out!
Posted: August 8 2008
| top
| # 8