Page 1 of 1

Get all site products

Posted: 27 Nov 2017, 08:37
by MirkoPinna
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.

Re: Get all site products

Posted: 27 Nov 2017, 12:36
by aimeos
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

Re: Get all site products

Posted: 27 Nov 2017, 14:07
by MirkoPinna
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'] );

Re: Get all site products

Posted: 27 Nov 2017, 22:04
by aimeos
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

Re: Get all site products

Posted: 28 Nov 2017, 09:33
by MirkoPinna
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] => )

Re: Get all site products

Posted: 28 Nov 2017, 22:26
by aimeos
Does the items have media and prices in the site you are using in the locale item?