Page 1 of 1

listing categories

Posted: 24 Nov 2022, 13:09
by mahammadareef
I want to list out 20 categories on the home page (in the shop by category section) - based on the option value given in categories - how to achieve this -explain to me with steps

and what is the exact use of option + value options available in the catalog adding part

Re: listing categories

Posted: 25 Nov 2022, 14:30
by aimeos
The option/value pairs are just configuration values which can be stored in each category and which can be used e.g. in the template to enable the CSS based megamenu. But you can't filter for those values as they are stored as JSON encoded string in the "config" column of the mshop_catalog table.

If you you explicitly want to filter the categories in the database by a custom value, you could add a manager decorator adding a new column to the mshop_catalog table:
https://aimeos.org/docs/latest/models/extend-managers/

Re: listing categories

Posted: 30 Nov 2022, 12:01
by mahammadareef
okay assume i added one coloumn is_branded_category , how to write filter option , if posssible please show it in this data() function of my component (here it retrives all the category tree )

Code: Select all

  public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\Base\View\Iface
	{
        $tree = \Aimeos\Controller\Frontend::create( $this->context(), 'catalog' )->uses( $this->domains() )
			->getTree( \Aimeos\Controller\Frontend\Catalog\Iface::LIST );
		

		$products = \Aimeos\Controller\Frontend::create( $this->context(), 'product' )->uses( $this->domains() )
			->category( $tree->getChildren()->getId()->all(), 'promotion' )->search();

		$this->addMetaItemCatalog( $tree, $expire, $tags );
		$this->addMetaItems( $products, $expire, $tags, ['product'] );

		$view->homeTree = $tree;
		// $view->homeStockUrl = $this->stockUrl( $products );

		return parent::data( $view, $tags, $expire );
	}

Re: listing categories

Posted: 01 Dec 2022, 15:07
by aimeos
The catalog controller has a compare() method where you can add custom conditions:
https://github.com/aimeos/ai-controller ... hp#L26-L35

In your example:

Code: Select all

$cntl = \Aimeos\Controller\Frontend::create( $this->context(), 'catalog' );
$categories = $cntl->compare( '==', 'is_branded_category', 1 )->slice( 0, 20 )->search();