Page 1 of 1

Sorting by attribute type

Posted: 05 Oct 2019, 22:41
by DembeRed
Hello everyone,,
how can I sort a list of products by a specific attribute? E.g. sort list by countries which is a attribute of type country on every product?
I see name, relevace and price.
Can I extend this?

Greetings

Re: Sorting by attribute type

Posted: 07 Oct 2019, 09:02
by aimeos
To extend Aimeos to be able to sort by attribute type/values a few steps must be taken:

1.) Extend the indext attribute manager (https://github.com/aimeos/aimeos-core/b ... rd.php#L62) by

Code: Select all

		'index.attribute:code' => array(
			'code' => 'index.attribute:code()',
			'internalcode' => 'mindat."listtype" = $1 AND mindat."type" = $2 AND mindat."code"',
			'label' => 'Attribute code, parameter(<list type code>,<type code>)',
			'type' => 'string',
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
			'public' => false,
		),
		'sort:index.attribute:code' => array(
			'code' => 'sort:index.attribute:code()',
			'internalcode' => 'mindat."code"',
			'label' => 'Sort by attribute code, parameter(<list type code>,<type code>)',
			'type' => 'string',
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
			'public' => false,
		)
2.) Extend the sort method of the product frontend controller (https://github.com/aimeos/ai-controller ... d.php#L335) by a key e.g. "a_<type>" and add the condition and sorting

3.) Add the new sorting in the pagination template (https://github.com/aimeos/ai-client-htm ... andard.php)

If everything works, a pull request with your changes is very welcome :-)