Get data from another template

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
aloniwe
Posts: 10
Joined: 21 Nov 2019, 12:45

Get data from another template

Post by aloniwe » 06 Dec 2019, 15:22

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 377 times
i'm passing some params into view:
Screenshot_3.png
Screenshot_3.png (7.33 KiB) Viewed 377 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?

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

Re: Get data from another template

Post by aimeos » 07 Dec 2019, 10:21

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
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

aloniwe
Posts: 10
Joined: 21 Nov 2019, 12:45

Re: Get data from another template

Post by aloniwe » 10 Dec 2019, 15:24

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.

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

Re: Get data from another template

Post by aimeos » 11 Dec 2019, 12:36

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();
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

aloniwe
Posts: 10
Joined: 21 Nov 2019, 12:45

Re: Get data from another template

Post by aloniwe » 11 Dec 2019, 16:35

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?

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

Re: Get data from another template

Post by aimeos » 12 Dec 2019, 14:52

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;
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply