How to get customer with orders ?

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!
MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

How to get customer with orders ?

Post by MikaelNazarenko » 27 Aug 2020, 18:24

Hi community ) Long time with no questions from me ) I have real problem.


I need to get customer with his orders. Exactly would be great to get several customers with their base orders which are paid.
Now it is very ugly in aimeos, or maybe I don't know the right way....

I try to get ids of orders which have payment status "received", then I search the items with "order/base" manager by those ordersIds and ids of customers which I need.. So crazy ( Is there good way for this ?




This is the components versions:

Code: Select all

aimeos/ai-admin-jqadm                 2019.10.6  Aimeos ai-admin-jqadm extension
aimeos/ai-admin-jsonadm               2019.10.2  Aimeos ai-admin-jsonadm extension
aimeos/ai-client-html                 2019.10.10 Aimeos ai-client-html extension
aimeos/ai-client-jsonapi              2019.10.2  Aimeos JSON API extension
aimeos/ai-controller-frontend         2019.10.3  Aimeos ai-controller-frontend extension
aimeos/ai-controller-jobs             2019.10.4  Aimeos ai-controller-jobs extension
aimeos/ai-gettext                     2019.10.1  Aimeos Gettext extension
aimeos/ai-laravel                     2019.10.2  Laravel adapter for Aimeos web shops and e-commerce solutions
aimeos/ai-payments                    2019.10.1  Payment extension for Aimeos web shops and e-commerce solutions
aimeos/ai-swiftmailer                 2019.10.1  SwiftMailer adapter for Aimeos web shops and e-commerce solutions
aimeos/aimeos-core                    2019.10.7  Full-featured e-commerce components for high performance online shops
aimeos/aimeos-laravel                 2019.10.1  Professional, full-featured and high performance Laravel e-commerce package for online shops and complex B2B projects

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

Re: How to get customer with orders ?

Post by aimeos » 28 Aug 2020, 11:32

Make sure you use the latest 2019.10 release. Then, you can do:

Code: Select all

$manager = \Aimeos\MShop::create( $context, 'order' );
$search = $manager->createSearch();
$search->setConditions( $search->combine( '&&', [
	$search->compare( '==', 'order.statuspayment', 4 ),
	$search->compare( '==', 'order.base.customerid', [1, 2, 3] )
] ) );
$orderItems = $manager->searchItems( $search, ['order/base', 'order/base/address', 'order/base/coupon', 'order/base/product', 'order/base/service'] );

foreach( $orderItems as $orderItem ) {
	$basket = $orderItem->getBaseItem();
	$orderProducts = $baset->getProduct();
}
In 2020.x, this will be even simpler:

Code: Select all

$manager = \Aimeos\MShop::create( $context, 'order' );
$filter = $manager->filter()->add( ['order.statuspayment' => 4, 'order.base.customerid' => [1, 2, 3]] );
$orderItems = $manager->search( $filter, ['order/base', 'order/base/address', 'order/base/coupon', 'order/base/product', 'order/base/service'] );

foreach( $orderItems->getBaseItem() as $basket ) {
	$orderProducts = $baset->getProduct();
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: How to get customer with orders ?

Post by MikaelNazarenko » 28 Aug 2020, 11:57

Great thank you for the fast support!

But can I also set condition to the query to get orders which have statuspayment = 4 ?

And will your first example work for the following versions ?

Code: Select all

aimeos/ai-admin-jqadm                 2019.10.6  Aimeos ai-admin-jqadm extension
aimeos/ai-admin-jsonadm               2019.10.2  Aimeos ai-admin-jsonadm extension
aimeos/ai-client-html                 2019.10.10 Aimeos ai-client-html extension
aimeos/ai-client-jsonapi              2019.10.2  Aimeos JSON API extension
aimeos/ai-controller-frontend         2019.10.3  Aimeos ai-controller-frontend extension
aimeos/ai-controller-jobs             2019.10.4  Aimeos ai-controller-jobs extension
aimeos/ai-gettext                     2019.10.1  Aimeos Gettext extension
aimeos/ai-laravel                     2019.10.2  Laravel adapter for Aimeos web shops and e-commerce solutions
aimeos/ai-payments                    2019.10.1  Payment extension for Aimeos web shops and e-commerce solutions
aimeos/ai-swiftmailer                 2019.10.1  SwiftMailer adapter for Aimeos web shops and e-commerce solutions
aimeos/aimeos-core                    2019.10.7  Full-featured e-commerce components for high performance online shops
aimeos/aimeos-laravel                 2019.10.1  Professional, full-featured and high performance Laravel e-commerce package for online shops and complex B2B projects
And how can I update aimeos components ? Because when I updated it some time I had to change my custom extension's code because behavior of aimeos was changed. This is why I am not harry to update it )

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

Re: How to get customer with orders ?

Post by aimeos » 28 Aug 2020, 12:02

Updated the original code.
2019.10 is an LTS version with bugfixes only and there are no structural changes any more. Only if you want to update to 2020.x, you have to expect breaking changes.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: How to get customer with orders ?

Post by MikaelNazarenko » 28 Aug 2020, 12:09

Excellent! Great solution, your code works!

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: How to get customer with orders ?

Post by MikaelNazarenko » 28 Aug 2020, 12:18

Ahh sorry, however I have error:

Code: Select all

Call to undefined method Aimeos\MShop\Order\Item\Standard::getBaseItem()
Order does not have getBaseItem method.. So I can't get the base order object ((

This is how order looks like in debug:

Code: Select all

Aimeos\MShop\Order\Item\Standard {#816 ▼
  -bdata: array:12 [▼
    "order.id" => "45"
    "order.baseid" => "45"
    "order.siteid" => "1"
    "order.type" => "web"
    "order.datepayment" => "2020-08-27 15:01:22"
    "order.datedelivery" => null
    "order.statuspayment" => "6"
    "order.statusdelivery" => "-1"
    "order.relatedid" => null
    "order.ctime" => "2020-08-27 15:01:22"
    "order.mtime" => "2020-08-27 18:28:32"
    "order.editor" => "email@gmail.com"
  ]
  -prefix: "order."
  -available: true
  -modified: false
}
So it does not seem like order has base object or any child items...


Is the problem because of my old version ?

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

Re: How to get customer with orders ?

Post by aimeos » 28 Aug 2020, 12:29

Like said, you need to update to the latest 2019.10 release. You are using aimeos/aimeos-core 2019.10.7, latest one is 2019.10.31
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: How to get customer with orders ?

Post by MikaelNazarenko » 28 Aug 2020, 13:34

I am sorry, does aimeos have such terminal command to update components ?

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

Re: How to get customer with orders ?

Post by aimeos » 28 Aug 2020, 14:25

Simply use

Code: Select all

composer update
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: How to get customer with orders ?

Post by MikaelNazarenko » 28 Aug 2020, 15:15

composer update I don't want to use because I don't want to update a lot other packages from vendor. I want only update aimeos to version 2019.10.31 like you said)

Post Reply