Rebate filter implementation

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!
vision
Posts: 23
Joined: 01 Dec 2022, 05:35

Rebate filter implementation

Post by vision » 20 Apr 2023, 05:26

2022.10 branch.
Triyng to create rebate filter for catalog:

I extended "mshop_index_price table" with the new column 'rebate', overwrited the index price manager to store that values and added a 'index.price:rebate' search function to the "Aimeos\Client\Html\Catalog\Filter\Price\Standard.php":

'index.price:rebate' => array(
'code' => 'index.price:rebate()',
'internalcode' => ':site AND mindpr."currencyid" = $1 AND mindpr."rebate"',
'label' => 'Product price rebate, parameter(<currency id="">)',
'type' => 'float',
'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR,
'public' => false,
),


added to "Aimeos\Controller\Frontend\Product\Standard.php":

public function rebate( ) : Iface
{
$func = $this->filter->make( 'index.price:rebate', [$this->context()->locale()->getCurrencyId()] );

$this->addExpression( $this->filter->compare( '>', $func, 0 ) );
}

return $this;
}


I tried to use it via "Aimeos\Client\Html\Catalog\Filter\Price\Standard.php" class:

...
$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' )
->text( $view->param( 'f_search' ) )
->category( $this->categories( $view ), 'default', $this->level() )
->radius( $view->param( 'f_point', [] ), $view->param( 'f_dist' ) )
->supplier( $this->suppliers( $view ) )
->allOf( $this->attributes() )
->allOf( $view->param( 'f_attrid', [] ) )
->oneOf( $view->param( 'f_optid', [] ) )
->oneOf( $view->param( 'f_oneid', [] ) )
->rebate( );
...


added to "templates\client\html\catalog\filter\price-body,php":

input type="checkbox" for checking if rebate filter is needed


Example URI I got:
.../shop/hot-deals~63?f_search=&f_rebate=f_rebate&f_price%5B0%5D=0&f_price%5B1%5D=2001&f_price%5B1%5D=2001

But my filter does not apply. How can I fix that?

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

Re: Rebate filter implementation

Post by aimeos » 21 Apr 2023, 14:54

vision wrote: 20 Apr 2023, 05:26 added to "Aimeos\Controller\Frontend\Product\Standard.php":

Code: Select all

public function rebate( ) : Iface
{
	$func = $this->filter->make( 'index.price:rebate', [$this->context()->locale()->getCurrencyId()] );

	$this->addExpression( $this->filter->compare( '>', $func, 0 ) );

	return $this;
}
You don't necessarily need to overwrite the product frontend controller because you can use the filter directly in the "Aimeos\Client\Html\Catalog\Filter\Price\MyProject.php" class. That's less code to care about.
vision wrote: 20 Apr 2023, 05:26 But my filter does not apply. How can I fix that?
Two things you take care about:
- Give your new classes a new name, e.g. the name of the project (like "MyProject" above)
- Configure the name of the new class, e.g. for the index price manager in your ./config/shop.php:

Code: Select all

	'mshop' => [
		'index' => [
			'manager' => [
				'price' => [
					'name' => 'MyProject',
				],
			],
		],
	],
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

vision
Posts: 23
Joined: 01 Dec 2022, 05:35

Re: Rebate filter implementation

Post by vision » 24 Apr 2023, 07:42

aimeos wrote: 21 Apr 2023, 14:54
Two things you take care about:
- Give your new classes a new name, e.g. the name of the project (like "MyProject" above)
- Configure the name of the new class, e.g. for the index price manager in your ./config/shop.php:

Code: Select all

	'mshop' => [
		'index' => [
			'manager' => [
				'price' => [
					'name' => 'MyProject',
				],
			],
		],
	],
I did my filter implementation via "Aimeos extansions".
Also I tried to do as you said above - created "MyProject" class, etc. My filter still doesn't apply.
Furthermore, I echoed sql statement that I receive by implementing
You don't necessarily need to overwrite the product frontend controller because you can use the filter directly in the "Aimeos\Client\Html\Catalog\Filter\Price\MyProject.php" class. That's less code to care about.
:

Code: Select all

SELECT "product.status", max("val") AS "value"
FROM (
	SELECT mpro."status" AS "product.status", mindpr."value" AS "val"
	FROM "mshop_product" mpro
	LEFT JOIN "mshop_index_catalog" AS mindca USE INDEX ("idx_msindca_s_ca_lt_po", "unq_msindca_p_s_cid_lt_po") ON mindca."prodid" = mpro."id"
	LEFT JOIN "mshop_index_price" AS mindpr USE INDEX ("unq_msindpr_pid_sid_cid", "idx_msindpr_sid_cid_val", "idx_msindpr_sid_cid_reb") ON mindpr."prodid" = mpro."id"
	WHERE (
		( mpro."siteid" IN ('','1.') ) AND  (
			( mindpr."value" IS NOT NULL ) AND ( 
				( mpro."status" IS NOT NULL ) AND ( 
					mindca."catid" IS NOT NULL AND ( mindpr."siteid" IN ('','1.') ) AND 
					mindpr."currencyid" = 'RUB' AND 
					mindpr."value" IS NOT NULL AND 
					( mindpr."siteid" IN ('','1.') ) AND 
					mindpr."currencyid" = 'RUB' AND 
					mindpr."rebate" > '0' 
				) 
			) 
		) 
	)
	GROUP BY mpro."status", mindpr."value", mpro."id"
	ORDER BY mpro."id" ASC
	LIMIT 100 OFFSET 0
) AS list
GROUP BY "product.status"
It contains "."rebate" > '0'", but doesn't affect on my filtering results somehow. I think I’m missing something, but it unclear for me. I wrote the steps I did in my first message.

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

Re: Rebate filter implementation

Post by aimeos » 26 Apr 2023, 06:37

The rebate condition has been added and the query you've posted is an aggregation query for counting the products in the filter. This also matches your changes in the catalog filter component.

When you want to filter products by rebates in the list view, you have to use a GET parameter like "f_rebate" and adapt the catalog/lists component where the products are passed to the list view.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

vision
Posts: 23
Joined: 01 Dec 2022, 05:35

Re: Rebate filter implementation

Post by vision » 26 Apr 2023, 08:46

Thanks! It works)

Post Reply