Get all site 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!
MirkoPinna
Posts: 16
Joined: 04 Sep 2017, 12:35

Get all site products

Post by MirkoPinna » 27 Nov 2017, 08:37

Hi is there a way to get all products from a site?
I know i can use https://aimeos.org/docs/Developers/Libr ... s#Get_item but id doesn't gives me enough informations, i need to take price, name, image and status.

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

Re: Get all site products

Post by aimeos » 27 Nov 2017, 12:36

You can use the searchItem() method of the product manager to get all products:
https://aimeos.org/docs/Developers/Libr ... arch_items

To retrieve associated items like texts, prices, attributes, etc. pass the list of domain names you need as second parameter. This does also work for getItem():

Code: Select all

$manager->searchItems( $criteria, ['text', 'price', 'media', 'attribute', 'product'] );
You can limit the returned products by conditions:
https://aimeos.org/docs/Developers/Cond ... _searching

And you need to do that efficiently and not thousands of products at once:
https://aimeos.org/docs/Developers/Fetc ... in_bunches
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MirkoPinna
Posts: 16
Joined: 04 Sep 2017, 12:35

Re: Get all site products

Post by MirkoPinna » 27 Nov 2017, 14:07

Thank you, i did try the following code but returns me an empty array.

Code: Select all

//First get the context
      $context = App::make('\Aimeos\Shop\Base\Context')->get(TRUE);

      //Obtain the manager for products
      $this->orderManager = \Aimeos\MShop\Factory::createManager($context, 'product');

      //Create the search for retrieve the orders
      $search = $this->orderManager->createSearch();
      $search->setConditions( $search->compare('==', 'product.siteid', $siteID));
      $products = $this->orderManager->searchItems($search, ['text', 'price', 'media', 'attribute', 'product'] );

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

Re: Get all site products

Post by aimeos » 27 Nov 2017, 22:04

You must not use the "siteid" key for searching because it's already added from the locale object!
In your example, this leads to SQL queries like "siteid=1 AND siteid=2" if your siteid value is different from the locale site ID and therefore to empty results.

If you implement a Laravel command, you have to add a locale item yourself using the bootstrap() method of the locale manager: https://aimeos.org/docs/Laravel/Extend_Aimeos
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MirkoPinna
Posts: 16
Joined: 04 Sep 2017, 12:35

Re: Get all site products

Post by MirkoPinna » 28 Nov 2017, 09:33

Thank you now it works, but i cannot get media and price anyway.
this is what i get:

Code: Select all

[13] => 
 Aimeos\MShop\Product\Item\Standard Object ( 
 	[values:Aimeos\MShop\Product\Item\Standard:private] => Array ( 
 		[product.id] => 13 
 		[product.siteid] => 8 
 		[product.typeid] => 1 
 		[product.code] => test1 
 		[product.label] => Product VENDOR 1 
 		[product.config] => Array ( ) 
 		[product.datestart] => 
 		[product.dateend] => 
 		[product.status] => 1 
 		[product.ctime] => 2017-10-20 07:56:33 
 		[product.mtime] => 2017-11-24 10:01:24 
 		[product.editor] => super@botteega.com 
 		[product.target] => 
 		[product.type] => default 
 		[product.typename] => Article ) 
 	[propItems:Aimeos\MShop\Product\Item\Standard:private] => Array ( ) 
 	[refItems:Aimeos\MShop\Common\Item\ListRef\Base:private] => Array ( ) 
 	[listItems:Aimeos\MShop\Common\Item\ListRef\Base:private] => Array ( ) 
 	[sortedLists:Aimeos\MShop\Common\Item\ListRef\Base:private] => 
 	[bdata:Aimeos\MShop\Common\Item\Base:private] => Array ( 
 		[product.id] => 13 
 		[product.siteid] => 8 
 		[product.typeid] => 1 
 		[product.code] => test1 
 		[product.label] => Product VENDOR 1 
 		[product.config] => Array ( ) 
 		[product.datestart] => 
 		[product.dateend] => 
 		[product.status] => 1 
 		[product.ctime] => 2017-10-20 07:56:33 
 		[product.mtime] => 2017-11-24 10:01:24 
 		[product.editor] => super@botteega.com 
 		[product.target] => 
 		[product.type] => default 
 		[product.typename] => Article ) 
 	[prefix:Aimeos\MShop\Common\Item\Base:private] => product. 
 	[modified:Aimeos\MShop\Common\Item\Base:private] => )

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

Re: Get all site products

Post by aimeos » 28 Nov 2017, 22:26

Does the items have media and prices in the site you are using in the locale item?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply