Rebate filter implementation
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!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Rebate filter implementation
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?
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?
Re: Rebate filter implementation
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 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; }
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, give us a star
If you like Aimeos, give us a star
Re: Rebate filter implementation
I did my filter implementation via "Aimeos extansions".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', ], ], ], ],
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"
Re: Rebate filter implementation
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.
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, give us a star
If you like Aimeos, give us a star