Page 1 of 1

Get data from another template

Posted: 06 Dec 2019, 15:22
by aloniwe
Hey! I'm trying to create filter by price (range slider).
I'm passing range values (min and max) by url.
After extending list standard class and retrieving products that matchs range:
Screenshot_2.png
Screenshot_2.png (40.26 KiB) Viewed 1760 times
i'm passing some params into view:
Screenshot_3.png
Screenshot_3.png (7.33 KiB) Viewed 1760 times
The question is: how can i get them in another template like attribute-body-standard?
If it's not possible, what should i do to get min and max values in attribute template?

Re: Get data from another template

Posted: 07 Dec 2019, 10:21
by aimeos
You can implement your code in a decorator which you can configure for all clients where you need the values in their templates: https://aimeos.org/docs/Developers/Html ... components

Re: Get data from another template

Posted: 10 Dec 2019, 15:24
by aloniwe
I created my own decorator. Now i need to compare each product price with min and max values. I'm trying to do smth like that in my decorator:

Code: Select all

$products = \Aimeos\Controller\Frontend::create( $context, 'product' )->uses( $domains );
$items = $products->compare('>', 'product.price.value', 20)->search();
What is wrong with my query? Or how can i access each product price and compare it value with my min and max.
Sorry, cann't find any information about this in docs.

Re: Get data from another template

Posted: 11 Dec 2019, 12:36
by aimeos
What you are looking for is "index.price:value":
https://github.com/aimeos/aimeos-core/b ... rd.php#L35

Code: Select all

$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' )->uses( $domains );
$items = $cntl->compare('>=', 'index.price:value', 20)->compare('<', 'index.price:value', 40)->search();

Re: Get data from another template

Posted: 11 Dec 2019, 16:35
by aloniwe
Thank you very match!
For it works i also added currency:

Code: Select all

$cntl = \Aimeos\Controller\Frontend::create( $context, 'product' )->uses( $domains );
$items = $cntl->compare('>=', 'index.price:value("'.$currencyid.'")', 20)->search();
Is it good idea to fetch all products again in my decorator if price sorting is required or better configure new standard class?

Re: Get data from another template

Posted: 12 Dec 2019, 14:52
by aimeos
If the HTML client already adds the products to the view, you only have to wait until its method has been called, e.g.

Code: Select all

public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], &$expire = null )
{
	$view = $this->client->addData( $view, $tags, $expire );
	// now use $view->listProductItems
	return $view;
}