listing categories

Help for integrating the Laravel package
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!
User avatar
mahammadareef
Posts: 36
Joined: 14 Oct 2022, 11:54

listing categories

Post by mahammadareef » 24 Nov 2022, 13:09

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

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

Re: listing categories

Post by aimeos » 25 Nov 2022, 14:30

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

User avatar
mahammadareef
Posts: 36
Joined: 14 Oct 2022, 11:54

Re: listing categories

Post by mahammadareef » 30 Nov 2022, 12:01

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 );
	}

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

Re: listing categories

Post by aimeos » 01 Dec 2022, 15:07

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

Post Reply