How to get products of specific category.

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!
awaidqureshi
Posts: 86
Joined: 12 Jan 2019, 15:17

How to get products of specific category.

Post by awaidqureshi » 08 Mar 2019, 16:09

Please tell me method so that i can get the products of specific category.
and please tell me the function that i can get

name
Media URL
Description
Attributes
Price

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

Re: How to get products of specific category.

Post by aimeos » 08 Mar 2019, 17:21

In 2018.10:

Code: Select all

$cntl = \Aimeos\Controller\Frontend\Factory::createController( $context, 'product' );
$filter = $cntl->createFilter( 'relevance', '+', 0, 48 );
$filter = $cntl->addFilterCategory( $filter, '<catid>' );
$products = $cntl->searchItems( $filter, ['attribute', 'media', 'price', 'text] );

foreach( $products as $product )
{
    $name = $product->getName();
    $url = current( $product->getRefItems( 'media', 'default', 'default' ) )->getPreview(); // or ->getUrl()
    $desc = current( $product->getRefItems( 'text', 'default', 'long' ) )->getContent();
    $attributes = $product->getRefItems( 'attribute', null, 'default' );
    $price = current( $product->getRefItems( 'price', 'default', 'default' ) )->getValue();
}
In upcoming 2019.04:

Code: Select all

$products = \Aimeos\Controller\Frontend::create( $context, 'product' )
    ->uses( ['attribute', 'media', 'price', 'text] )->category( '<catid>' )
    ->sort( 'relevance' )->slice( 0, 48 )->search();

// rest same as above
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply