Page 1 of 1

Basket Controller addProduct doesn't work

Posted: 24 Oct 2016, 11:20
by Pejka
Hello!
I'm having trouble while adding a product to the basket via the built-in basket controller.
The code is as follows:

Code: Select all

$context = app( '\Aimeos\Shop\Base\Context' )->get();
$basket = \Aimeos\Controller\Frontend\Factory::createController( $context, 'basket' )->get();
$basket->addProduct($felsoid, 1);
$felsoid is a product ID in string format, exactly as specified in the docs and the comments preceding the function, yet I'm getting the following error:

ErrorException in Base.php line 163: Argument 1 passed to Aimeos\MShop\Order\Item\Base\Base::addProduct() must be an instance of Aimeos\MShop\Order\Item\Base\Product\Iface, string given, called in MYPATH\Modules\Setgenerator\Http\Controllers\SetgeneratorController.php on line 39 and defined MYPATH\vendor\aimeos\aimeos-core\lib\mshoplib\src\MShop\Order\Item\Base\Base.php

Unless I'm really missing something, it seems somewhere down the line aimeos doesn't request the proper object, but hands down the string ID when trying to create the Order object proper.

Thank you for your reply in advance,
Máté

Re: Basket Controller addProduct doesn't work

Posted: 24 Oct 2016, 11:30
by aimeos
You are using the addProduct() for the \Aimeos\MShop\Order\Item\Base\Iface which requires and object instead of the addProduct() method of the \Aimeos\Controller\Frontend\Basket\Iface due to the "->get()" call.

Re: Basket Controller addProduct doesn't work

Posted: 24 Oct 2016, 12:46
by Pejka
Thanks! That solved that problem, though now I have like 99 other ones :D