So, I’m becoming very desperate with this problem. It just won’t work. No error message, nothing. But let me start from the beginning:
A client want’s a special basket layer enabling customers to put items into the basket without leaving or reloading the page. So, for this, I will need AJAX, obviously. I’ve already created the controller for this (I removed every kind of error handling to make sure nothing interferes with the functionality):
class TheModule_AjaxRecipient extends oxView {
public function addToBasket() {
ob_start();
$orderedArticles = json_decode(oxRegistry::getConfig()->getRequestParameter('data', true), true);
$basket = $this->getSession()->getBasket();
foreach($orderedArticles as $articleId) {
$basket->addToBasket($articleId, 1, array(0), null, false, false);
}
ob_flush();
echo json_encode(array('status' => 1);
}
}
The request-data (POST) looks like this:
cl=TheModule_AjaxRecipient&fnc=addToBasket&data={"0":"someRandomOxId","1":"anotherRandomOxId"}&stoken=theSessionToken
The controller fetches the data, foreaches through the containing IDs and tries to add them to the basket via ‘addToBasket()’. And this does work. When I dump the basket object after the foreach loop, all these articles are actually there, and when I dump the result of addToBasket(), it always returns the articleObject it just added. However, all of these articles are not saved, they are not persisted. They are in the object, but disappear right after, like the basket is not saved or … I really don’t know actually. It should work, but it doesn’t. But I also didn’t find another function in the oxbasket.php that would give me the opportunity to add articles into the basket.
This is oxid 4.10.8, running on PHP 5.6 by the way.
Any help is greatly appreciated, because I’m extremely clueless on this one.