Create a $manager to get products details of a stored order!

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!
jahidkhan
Posts: 1
Joined: 26 May 2019, 12:18

Create a $manager to get products details of a stored order!

Post by jahidkhan » 26 May 2019, 12:19

I think it is a simple question. Everything is in the title : I'm still beginning with Aimeos and I would like to access all products details of a given stored order using my own controller.

I was hoping that retrieving the order details adding ['product'] domain in the criteria then access it with getProducts() was the correct way to do that but it wasn't.

Here is the code I used:

CODE: SELECT ALL
$obid = 1;
$context = app()->make('\Aimeos\Shop\Base\Context')->get();
$manager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' );
$search = $manager->createSearch();
$search->setConditions( $search->compare( '==', 'order.base.id', $obid ) );
$order = $manager->searchItems($search,['text', 'price', 'attribute', 'product']);
$order_products = $order[$obid]->getProducts();


$order is well set but $order_products is an empty array.
Using ->getProducts() is probably naïve :)

I probably misunderstood something, I couldn't find anything in the documentation and on this forum to help me.

I suppose too that using :
Last edited by jahidkhan on 26 May 2019, 18:08, edited 1 time in total.

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

Re: Create a $manager to get products details of a stored or

Post by aimeos » 26 May 2019, 16:16

Almost :-)

If you want an order for a specific ID, easiest way is:

Code: Select all

$manager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' );
$products = $manager->load($oid)->getProducts();
If you need to search for several orders:

Code: Select all

$manager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' );
$orders = $manager->searchItems($manager->createSearch(),['order/base/product']);
foreach($orders as $order) {
    $products = $order->getProducts();
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply