I'm having this problem and getting pretty annoyed by it.
here's the situation.
I was running a website on the codeigniter framework, and our customer wanted to add a shop to sell a couple of products. I decided to try to use magento, since its widely used and the documentation seemed ok.
My test setup on my local machine looks like this.
"localhost/project/" is the website root, where the codeigniter installation files are.
I added a new folder "store" to the root and installed magendo 184.108.40.206 into it. The magento installation runs as baseurl 127.0.0.1
Now i tried to add products from a codeigniter library to a magento cart via the following code:
require_once 'store/app/Mage.php'; umask(0); Mage::init('default'); Mage::getSingleton('core/session', array('name' => 'frontend')); // Get customer session $session = Mage::getSingleton('customer/session'); // Get cart instance $cart = Mage::getSingleton('checkout/cart'); $cart->init(); // Add a product with custom options $productInstance = Mage::getModel('catalog/product')->load($productId); $param = array( 'product' => $productInstance->getId(), 'qty' => 1, ); $request = new Varien_Object(); $request->setData($param); $cart->addProduct($productInstance, $param); // update session $session->setCartWasUpdated(true); // save the cart $cart->save();
Seemed pretty straigforward. no errors or anything. I can verify that the adding works by
It shows the right amount of items.
But whenever I try to switch to the cart in the store itself using
It is empty.
The interesting part is, I can get all the info I need from magento, but I cant seem to add anything to a cart.
Im guessing it has something to do with sessions getting mixed up.
delivers something like
where as 5068c0335528f0713360cc3d6b302f8481ebb732 is the codeigniter session id. so im guessing the code never creates a magento session at all and links to a cart that with the CI session and not a magento session?
i think im getting closer to the root of the problem. after printing the data for the magento session with
im getting the following
Array ( [_session_validator_data] => Array ( [remote_addr] => ::1 [http_via] => [http_x_forwarded_for] => [http_user_agent] => Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36 ) [cart_was_updated] => 1 [id] => ) 1
the curious part for me is that the 'id' is empty. so i think the session is just not created correctly.