How to get orders with their products

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
awaidqureshi
Posts: 86
Joined: 12 Jan 2019, 15:17

How to get orders with their products

Post by awaidqureshi » 21 Feb 2019, 08:38

I want to get order with their products and their attribute that customer select .
Please tell me step by step guide to get those details.

Secondly Ordered Product with attributes are not saving that what can be the issue that the customer select some attribute while ordering something my system not showing those attributes in the order details.maybe i have done some thing

Please Guide me for those issue that how i can solve that my system show ordered product with their attribute selected .

Thanks

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

Re: How to get orders with their products

Post by aimeos » 22 Feb 2019, 09:13

To get the orders of the current customer:

Code: Select all

$context = app('\Aimeos\Shop\Base\Context')->get();
$manager = \Aimeos\MShop\Factory::createManager($context, 'order/base');

$search = $manager->createSearch();
$search->setConditions($search->compare('==', 'order.base.customerid', $context->getUserId()));
// add 'order/base/address', 'order/base/coupon' and/or 'order/base/service' as well if necessary
$orders = $manager->searchItems($search, ['order/base/product']);

foreach($orders as $order) {
    foreach($order->getProducts() as $orderProducts) {
        foreach($orderProducts->getAttributeItems() as $orderProductAttribute) {
            // ...
        }
   }
}
The API docs describe what you can do with the objects: https://aimeos.org/api/latest/class-Aim ... Iface.html

For adding attributes to the ordered products, they must be either of type "variant", "configurable", "custom" or "hidden". Standard attributes won't be added to ordered products.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

awaidqureshi
Posts: 86
Joined: 12 Jan 2019, 15:17

Re: How to get orders with their products

Post by awaidqureshi » 01 Mar 2019, 14:04

i have used these types for attributes that i attach with the product
but when user buy product and select some options .butt when order created order did not save those attributes (Options that user select like size or color) are not saving with the order

for reference :
http://prntscr.com/mrusw9

right now i m getting only name of product

http://prntscr.com/mruuge

And kindly tell me from where i can get the order id right after the order process complete so that i can use it for getting those products details.

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

Re: How to get orders with their products

Post by aimeos » 03 Mar 2019, 12:15

Did you add variant attributes of the right type? Please show by screenshot
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

awaidqureshi
Posts: 86
Joined: 12 Jan 2019, 15:17

Re: How to get orders with their products

Post by awaidqureshi » 04 Mar 2019, 07:14

we are adding Article type products right now.

For options( the way we are attaching them with the product) reference:
https://prnt.sc/msvlz5

maitrishah3
Posts: 2
Joined: 04 Mar 2019, 12:50

Re: How to get orders with their products

Post by maitrishah3 » 04 Mar 2019, 12:57

awesome this post. cool post

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

Re: How to get orders with their products

Post by aimeos » 05 Mar 2019, 10:49

Your configurable products look OK. What Aimeos version are you using?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

awaidqureshi
Posts: 86
Joined: 12 Jan 2019, 15:17

Re: How to get orders with their products

Post by awaidqureshi » 06 Mar 2019, 06:34

aimeos wrote:Your configurable products look OK. What Aimeos version are you using?
Thanks for your reply sir. Problem was from my side.

Dhara1510
Posts: 15
Joined: 27 Apr 2019, 05:36

Re: How to get orders with their products

Post by Dhara1510 » 09 May 2019, 07:23

Hello sir,

This post helps me to get order products.

Code: Select all

$context     = App::make('\Aimeos\Shop\Base\Context')->get();
        $baseManager = \Aimeos\MShop::create($context, 'order/base');
        $search      = $baseManager->createSearch();
        $items       = $baseManager->searchItems($search, ['order/base/product']);
        $basket      = reset($items);
        
        foreach ($basket->getProducts() as $orderProduct)
        {
            foreach($orderProduct->getAttributeItems() as $orderProductAttribute) {
                dd($orderProductAttribute->getParentId());
            }
        }
See my above code. I have added this code in my overridden confirmAction function. It gives me all order details. i need order detail which logged in user created latest order?

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

Re: How to get orders with their products

Post by aimeos » 09 May 2019, 09:35

Please do not use this code as is because it returns a more or less random order regardless of who placed it!
Which Aimeos version do you use?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply