Get refItems by condition

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

Get refItems by condition

Post by MikaelNazarenko » 09 Sep 2019, 06:59

As we now entities in aimeos may have referenced children entities. For example product may have several prices in array. Child objects associated to parent by list table. So when we getRefItems for some entity script firstly getListItems and populates the array of $item->getRegItem()

So tell me please if it possible to get refItemsBy condition ? If not possible which way I need to make it, filter them on DB level, or still retrive all and filter them on array point ?

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

Re: Get refItems by condition

Post by aimeos » 09 Sep 2019, 08:10

Can you post some example code you would like to do? We don't understand what you want to achieve based on your explanation.
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: Get refItems by condition

Post by MikaelNazarenko » 09 Sep 2019, 08:24

Ok, sorry for unclear explanation(

I have a product item \Aimeos\MShop\Product\Item\Standard object,

Then I get product prices

Code: Select all

$product->getRefItems('price')

It will return me an array of the objects from mshop_price table. But I don't want to get all prices, I need to get prices by specific condition, for example where quantity = 4 or another condition.

Thank you a lot for the fast answer and help!

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

Re: Get refItems by condition

Post by aimeos » 09 Sep 2019, 08:36

You can only limit the referenced items by type and their list type, e.g.

Code: Select all

$prices = $item->getRefItems( 'price', '<type>', '<list type>' );
The price items are fetched nevertheless but only the prices with the matching type and list type are returned.

In searchItems() you can limit fetching items by list type:

Code: Select all

$manager->searchItems( $filter, ['price' => ['default']] );
The currently matching price is determined by getLowestPrice() of the price manager:

Code: Select all

$priceManager->getLowestPrice( $prices, $quantity );
See https://github.com/aimeos/aimeos-core/b ... ce.php#L31
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply