Retrieving order with products

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!
yeh
Posts: 39
Joined: 27 Jun 2022, 13:26

Retrieving order with products

Post by yeh » 10 Nov 2022, 14:41

I have a parent site with many sub sites using the ai-sites extension. I have a decorator on jqadm/order/decorators/global that needs to be able to access all the products on an order even if they are attached to different sub-sites.

So when an order is saved on a particular sub-site, the decorator should look at all products from all sites and perform some actions.

To get the order with its associated products I am trying this:

Code: Select all

$defaultSiteId = '1.';
$context = $this->context();
$item = $this->view()->item;
$context->locale()->setSiteId($defaultSiteId);
$orderBaseManager = \Aimeos\MShop::create( $context, 'order/base' );
$orderBase = $orderBaseManager->get($item->getId(), ['product']);
Although this does retrieve an $orderBase object, it doesn't load the products. What am I doing wrong?

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

Re: Retrieving order with products

Post by aimeos » 11 Nov 2022, 06:13

The domains to retrieve must be:

Code: Select all

$orderBaseManager->get($item->getId(), ['order/base/product']);
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

yeh
Posts: 39
Joined: 27 Jun 2022, 13:26

Re: Retrieving order with products

Post by yeh » 15 Nov 2022, 11:21

great, thank you.

That works to retrieve the products, however the code is only retrieving products for the currently selected site. I am setting the locale site id earlier in the code, is there anything else I need to do to set the context to the default site rather than the site currently selected?

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

Re: Retrieving order with products

Post by aimeos » 16 Nov 2022, 10:15

If your context locale object is already using the "default" site, it will work as expected but I guess you are in a sub-site and want to get all orders from the "default" site and all it's sub-sites. You have to set a new locale to a cloned context:

Code: Select all

$manager = \Aimeos\MShop::create( $context, 'locale' );
$context->setLocale( $manager->bootstrap( 'default', '', '' ) );
This is documented here:
https://aimeos.org/docs/latest/laravel/ ... os-objects
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

yeh
Posts: 39
Joined: 27 Jun 2022, 13:26

Re: Retrieving order with products

Post by yeh » 16 Nov 2022, 16:21

That is exactly what I need, thank you :)

Post Reply