2

I have a magento store with two websites for Italian and Spanish market. I perform a php page to add items to cart programatically, but it works in Spain but not in Italy.

See sample code that works on ES but not in IT.

umask(0);
Mage::app();
$session = Mage::getSingleton('core/session', array('name' =>> 'frontend')); 
$cart = Mage::getSingleton('checkout/cart');
$cart->init();
$cart->addProduct(140616, 3);
$session->setCartWasUpdated(true);
$cart->save(); 

In var_dump afther $cart->init(); I see that the cart in IT dont load customer data.

Var_Dump in ES

object(Mage_Checkout_Model_Cart)[80]
 protected '_summaryQty' => null
 protected '_productIds' => null
 protected '_data' => 
 array (size=1)
 'quote' => 
 object(Mage_Sales_Model_Quote)[82]
 protected '_eventPrefix' => string 'sales_quote' (length=11)
 protected '_eventObject' => string 'quote' (length=5)
 protected '_customer' =>
 object(Mage_Customer_Model_Customer)[136]
 protected '_eventPrefix' => string 'customer' (length=8)
 protected '_eventObject' => string 'customer' (length=8)
 protected '_errors' => 
 array (size=0)
 empty
 protected '_attributes' => null
 protected '_addresses' => null
 protected '_addressesCollection' => null

Var_Dump in IT

object(Mage_Checkout_Model_Cart)[81]
 protected '_summaryQty' => null
 protected '_productIds' => null
 protected '_data' => 
 array (size=1)
 'quote' => 
 object(Mage_Sales_Model_Quote)[83]
 protected '_eventPrefix' => string 'sales_quote' (length=11)
 protected '_eventObject' => string 'quote' (length=5)
 protected '_customer' => null
 protected '_addresses' => null
 protected '_items' => 
 object(Mage_Sales_Model_Resource_Quote_Item_Collection)[136]
 protected '_quote' => 
 &object(Mage_Sales_Model_Quote)[83]
 protected '_productIds' => 
 array (size=11)
 0 => int 139190
 1 => int 139167
 2 => int 73844

Any sugestion?

Thanks

asked Sep 9, 2015 at 11:08
3
  • yes need to add store .. On your code add this Mage::app("StoreCOde",'Storetype'); instead of Mage::app(); Commented Sep 9, 2015 at 11:29
  • Perfect solution!! Now it works perfect, As you suggest I change <pre>Mage::app();</pre> with <pre>Mage::app('11');</pre>. Thanks for your help! Add an answer if you want to check it as solution. Thanks from Spain. Commented Sep 9, 2015 at 12:01
  • add ..please check.. Commented Sep 9, 2015 at 12:06

1 Answer 1

1

As per as comment. You need to initialize Mage::app() for each store.

SO just need to add store on Mage::app() .

Use: Mage::app("StoreCOde",'Storetype');

instead of Mage::app()

answered Sep 9, 2015 at 12:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.