get an array of products with it's ID and LABEL

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!
User avatar
ahmed31916
Advanced
Posts: 148
Joined: 14 Apr 2022, 12:15

get an array of products with it's ID and LABEL

Post by ahmed31916 » 01 Jun 2022, 10:36

Hello,

How to get an array of products (or any domain) with it's ID and LABEL?
This get the Label, but how to get it's id?

Code: Select all

->getLabel()->toArray()
something like this:
array:3 [
5 => "product1"
7 => "product2"
11 => "product3"
]

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

Re: get an array of products with it's ID and LABEL

Post by aimeos » 02 Jun 2022, 10:12

The product IDs are already used as keys in the array.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ahmed31916
Advanced
Posts: 148
Joined: 14 Apr 2022, 12:15

Re: get an array of products with it's ID and LABEL

Post by ahmed31916 » 02 Jun 2022, 11:22

Thanks for your reply, but maybe you didn't understand my point.
Anyway, is there a function in Aimeos similar to the "where" eloquent function that we use in Laravel?

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

Re: get an array of products with it's ID and LABEL

Post by aimeos » 02 Jun 2022, 11:50

ahmed31916 wrote: 02 Jun 2022, 11:22 Thanks for your reply, but maybe you didn't understand my point.
According to your question, you requested something like:

Code: Select all

array(
    <product ID> => '<product label>',
)
If this is not the case, what do you want instead?
ahmed31916 wrote: 02 Jun 2022, 11:22 Anyway, is there a function in Aimeos similar to the "where" eloquent function that we use in Laravel?
The Map object implemented where() to filter the collection:
https://php-map.org/#where
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ahmed31916
Advanced
Posts: 148
Joined: 14 Apr 2022, 12:15

Re: get an array of products with it's ID and LABEL

Post by ahmed31916 » 02 Jun 2022, 13:00

I wanted array with id and label for sub categories to use it in ajax for main category.
Using getLabel function: " ->getLabel()->toArray()", it get an array with sub categories without id.

When things get tough I used query builder, and it meet the purpose. Thanks.

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

Re: get an array of products with it's ID and LABEL

Post by aimeos » 02 Jun 2022, 13:55

The IDs of the objects are always the keys of the arrays when you get back the collection from the storage.
If you transform data and it's not the case any more, you can always use the "col()" method to rekey the collection, e.g. for a collection of categories:

Code: Select all

$collection->col( null, 'catalog.id' )
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply