How to filter only promotion 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!
kdim95
Advanced
Posts: 204
Joined: 26 Aug 2022, 12:17

How to filter only promotion products?

Post by kdim95 » 24 Nov 2022, 14:24

Laravel framework version: 9.41.0
Aimeos Laravel version: * 2022.07.2
PHP Version: 8.1.12
Environment: Linux

I want to show only products that have categories added their promotion categories list.
The file I'm redacting is a customized version of ai-client-html/src/Client/Html/Catalog/Lists/Standard.
I'm changing the filtering inside data() function.

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

Re: How to filter only promotion products?

Post by aimeos » 25 Nov 2022, 14:38

You can filter products by category types for the frontend using:

Code: Select all

\Aimeos\Client\Html\Catalog\Lists\Standard::macro( 'conditions', function( \Aimeos\Controller\Frontend\Product\Iface $cntl, \Aimeos\Base\View\Iface $view ) {
	if( $view->config( 'client/html/catalog/instock', false ) ) {
		$cntl->compare( '>', 'product.instock', 0 );
	}

	$cntl->compare( '!=', $cntl->function( 'product:has', ['catalog', 'promotion'] ), null );
} );
This is a macro overwriting the conditions() method in the \Aimeos\Client\Html\Catalog\Lists\Standard class and adds an additional condition that checks if the product has a list item referencing a category and the list type "promotion".
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

kdim95
Advanced
Posts: 204
Joined: 26 Aug 2022, 12:17

Re: How to filter only promotion products?

Post by kdim95 » 25 Nov 2022, 14:52

aimeos wrote: 25 Nov 2022, 14:38

Code: Select all

$cntl->compare( '!=', $cntl->function( 'product:has', ['catalog', 'promotion'] ), null );
Thank you, this was exactly what I needed for my filtering.

Post Reply