show product sclider based on product code

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
mahammadareef
Posts: 36
Joined: 14 Oct 2022, 11:54

show product sclider based on product code

Post by mahammadareef » 30 Nov 2022, 09:48

I have a requirement I want to show the list of products based on the product_codes list given on the admin side where I want to keep one option in the backend where I have to add product_code ...how to do this? please help me

User avatar
mahammadareef
Posts: 36
Joined: 14 Oct 2022, 11:54

Re: show product sclider based on product code

Post by mahammadareef » 30 Nov 2022, 11:06

Code: Select all

public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\Base\View\Iface
	{
		
		$texts = [];
		$context = $this->context();
		$config = $context->config();
		$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' );

		
		$template = $config->get( 'client/html/additional/productslider/template-header', 'additional/productslider/header' );
		$domains = $config->get( 'client/html/catalog/lists/domains', ['media', 'media/property', 'price', 'text'] );
        
        // $domains = $context->config()->get( 'client/html/account/favorite/domains', ['text', 'price', 'media'] );

        
		if( $view->config( 'client/html/cms/page/basket-add', false ) ) {
            $domains = array_merge_recursive( $domains, ['product' => ['default'], 'attribute' => ['variant', 'custom', 'config']] );
		}      
        
        $products = ( clone $cntl )->uses( $domains )
        ->category( 1, 'default' )
        ->slice( 0,10 )
        ->search();
        
        $this->addMetaItems( $products, $expire, $tags );
        
        $tview = $context->view()->set( 'products', $products );
        
        if( !$products->isEmpty() && (bool) $config->get( 'client/html/catalog/lists/stock/enable', true ) === true ) 
        {
            $tview->itemsStockUrl = $this->getStockUrl( $tview, $products );
        }

        $view->sliderItems = $products; 
		return parent::data( $view, $tags, $expire );
	}

this is the code to fetch products category vise, the same way I need the products list of given product_codes of products !

for example if ` $product.code = "demo-selection-article,demo-article,Demo-variant-article-4"; `
this is the condition i want to list the products details of these 3 articles only


Thankyou

User avatar
mahammadareef
Posts: 36
Joined: 14 Oct 2022, 11:54

Re: show product sclider based on product code

Post by mahammadareef » 30 Nov 2022, 13:13

i tried with this code ,

$products = ( clone $cntl )->uses( $domains )
->filter()->add( ['product.code' => ['demo-selection-article-3','demo-selection-article-4'] ] )->slice( 0,10 )
->slice( 0,10 )
->search();


it giving me this error

/home2
Called unknown macro "filter" on class "Aimeos\Controller\Frontend\Product\Standard"
#0

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

Re: show product sclider based on product code

Post by aimeos » 01 Dec 2022, 15:10

filter() is a method of the mangers but the frontend controllers have a simpler interface. Use compare() instead:

Code: Select all

$products = $cntl->uses( $domains )
	->compare( '==', 'product.code', ['demo-selection-article-3','demo-selection-article-4'] )
	->slice( 0,10 )
	->search();
See: https://github.com/aimeos/ai-controller ... hp#L53-L62
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply