Create a $manager to get products details of a stored order
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!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Create a $manager to get products details of a stored order
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:
$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 :
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
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();
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' );
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
Re: Create a $manager to get products details of a stored or
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'])
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, give us a star
If you like Aimeos, give us a star