How to configure and adapt Aimeos based shops as developer
Forum rules: Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
#3564 by Pejka
24 Oct 2016, 11:20
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,
#3566 by aimeos
24 Oct 2016, 11:30
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.