Basket Controller addProduct doesn't work

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)
Spam and unrelated posts will be removed immediately!
Pejka
Posts: 17
Joined: 24 Oct 2016, 11:04

Basket Controller addProduct doesn't work

Post by Pejka » 24 Oct 2016, 11:20

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é

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Basket Controller addProduct doesn't work

Post 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.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Pejka
Posts: 17
Joined: 24 Oct 2016, 11:04

Re: Basket Controller addProduct doesn't work

Post by Pejka » 24 Oct 2016, 12:46

Thanks! That solved that problem, though now I have like 99 other ones :D

Post Reply