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!
sixbynine
Posts: 93
Joined: 10 Jan 2018, 11:22

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

Post by sixbynine » 29 Jul 2018, 11:18

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 :

Code: Select all

$manager = \Aimeos\MShop\Factory::createManager( $context, 'product' );
is to reach the product info from the products catalog, not the ordered products.

So, what is the correct way to get each product details for a given order?

Thank you a lot in advance for your help and your patience,

sbn

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

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

Post by aimeos » 29 Jul 2018, 13:39

You have two options offered by the order base manager:
https://aimeos.org/api/latest/class-Aim ... Iface.html

1.) $orderBaseManager->getItem( $id, ['order/base/product'] );
2.) $orderBaseManager->load( $id, \Aimeos\MShop\Order\Item\Base\Base::PARTS_PRODUCT );

The first one should be used if you don't want to modify anything. Using the section option allows you to save the order base object (= basket) afterwards via the store() method.

The rule for the second parameter of findItem(), getItem() and searchItems() is:
- Items referenced by the list tables require the domain only (e.g. ['attribute', 'media', 'price', 'product', 'text'])
- Items stored in the same domain need the full sub-domain (e.g. ['product/property'] or ['order/base/product'])
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply