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

  • yes need to add store .. On your code add this Mage::app("StoreCOde",'Storetype'); instead of Mage::app(); – Amit Bera Sep 9 '15 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. – jfrubio Sep 9 '15 at 12:01
  • add ..please check.. – Amit Bera Sep 9 '15 at 12:06
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()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.