Help with Customizing Catalog Functionality in Aimeos Admin

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
Paulus-Ragnarr
Posts: 25
Joined: 15 Oct 2024, 07:02

Help with Customizing Catalog Functionality in Aimeos Admin

Post by Paulus-Ragnarr » 15 Oct 2024, 07:14

Hi everyone,

I'm new to Aimeos and am looking for guidance on how to modify the code within the Aimeos admin, specifically in the catalog section. I have a particular requirement:
  • When creating a new catalog, I need it to automatically link all existing products to the newly created catalog.
Is there a specific section in the documentation or any guide that covers this kind of customization? Any help or pointers would be greatly appreciated!

Thanks in advance!

User avatar
Paulus-Ragnarr
Posts: 25
Joined: 15 Oct 2024, 07:02

Re: Help with Customizing Catalog Functionality in Aimeos Admin

Post by Paulus-Ragnarr » 15 Oct 2024, 14:10

Hi again,

Following up on my earlier question about customizing the catalog panel in Aimeos admin, I came across the documentation that suggests using decorators for extending functionality.

Here’s an update on my goal:
There will be a created main category under Home called Promotions, and within it, subcategories for Monthly Discounts and Sales will be linked to Price Rules. When these promotion subcategories are created, they should automatically link to all existing products.

Would using a decorator be the best approach to achieve this? If so, could you please share tips or examples on implementing it? Any insights would be appreciated!

https://aimeos.org/docs/2024.x/admin/jq ... nd-panels/

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

Re: Help with Customizing Catalog Functionality in Aimeos Admin

Post by aimeos » 16 Oct 2024, 12:10

First thing is that adding all existing products to new categories only works if you have a low number of products. If that is the case, a decorator should be the best option to implement the code you need. After saving the category is done, you have to fetch all products with their categories and add the new category ID like this:

Code: Select all

    public function save() : ?string
    {
        $result = $this->getClient()->save();
        $catitem = $this->view()->item;

        $manager = \Aimeos\MShop::create( $this->context(), 'product' );
        $items = $manager->search( $manager->filter() ); // fetches only 100 products
        
        foreach( $items as $item ) {
            $item->addListItem( 'catalog', $manager->createListItem(), $catItem );
        }
        
        $manager->save( $items );
        return $result;
    }
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
Paulus-Ragnarr
Posts: 25
Joined: 15 Oct 2024, 07:02

Re: Help with Customizing Catalog Functionality in Aimeos Admin

Post by Paulus-Ragnarr » 17 Oct 2024, 00:10

Hello Aimeos, thank you for your reply! :D

I’ll explore using decorators as suggested. Currently, the shop has around 2,000 products, but in the future, this number could increase to around 10,000. Given the potential growth, are there other options I could consider for efficiently linking products to categories, especially in a large shop?

Additionally, would it be feasible to override the save() function directly inside:

Code: Select all

vendor/aimeos/ai-admin-jqadm/src/Admin/JQAdm/Catalog/Standard.php
to link all products to the saved category?

Thank you for your insights!

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

Re: Help with Customizing Catalog Functionality in Aimeos Admin

Post by aimeos » 17 Oct 2024, 15:29

The first question is: Why do you want to link all products to new categories? This doesn't make sense because categories are meant to split products for customers so they can find them more easily. Can you describe your motivation behind?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
Paulus-Ragnarr
Posts: 25
Joined: 15 Oct 2024, 07:02

Re: Help with Customizing Catalog Functionality in Aimeos Admin

Post by Paulus-Ragnarr » 17 Oct 2024, 22:32

Hi,

Our goal in linking all products to a specific category is to streamline the application of a Price Rule. We want to automatically include products in a discount category upon creation, instead of manually adding them individually.

For example:
  • Main Category: "Promotion" (A main category under "HOME" dedicated to discounts)
    • Subcategory: "November 10% Discount" (A subcategory that should be automatically linked to the relevant products and a price rule)

However, we made exceptions for certain products, meaning not all products will be linked. The total number of linked products could still be more than 1000. Additionally, we’ve implemented a condition to ensure that only subcategories created under the "Promotion" category will automatically link products. Other categories will not be affected by this process.

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

Re: Help with Customizing Catalog Functionality in Aimeos Admin

Post by aimeos » 18 Oct 2024, 06:56

In that case, we would suggest to implement the decorator for the Catalog panel:

Code: Select all

    public function save() : ?string
    {
        $view = $this->view();
        $catid = $view->param( 'item/catalog.id' );
        $result = $this->getClient()->save();
        
        if( !$catid ) // check if it's a new category so you don't do that whenever a category is saved
        {
            $catitem = $view->item;
        
            // check if the category item is one of the categories you want to link the products to

            $manager = \Aimeos\MShop::create( $this->context(), 'product' );
            $filter = $manager->filter( true ); // add more conditions here
            $cursor = $manager->cursor( $filter );
            $items = $manager->search( $manager->filter() ); // fetches only 100 products
        
            while( $items = $manager->iterate( $cursor ) ) {
                foreach( $items as $item ) {
                    $item->addListItem( 'catalog', $manager->createListItem(), $catItem );
                }
                $manager->save( $items );
            }
        }
        
        return $result;
    }
See: https://aimeos.org/docs/2024.x/models/m ... rate-items

If you only want to add new products to be automatically added to categories, you can use datasets to add the categories automatically in the product panel if the dataset was selected:
https://aimeos.org/docs/2024.x/config/a ... m/dataset/

This allows you to create one or more dataset configurations with default categories for that datasets, e.g.:

Code: Select all

 [
   'November 10% Discount' => [
     'catalog/default' => [['catalog.id' => 123]],
   ],
 ]
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
Paulus-Ragnarr
Posts: 25
Joined: 15 Oct 2024, 07:02

Re: Help with Customizing Catalog Functionality in Aimeos Admin

Post by Paulus-Ragnarr » 19 Oct 2024, 08:21

Hi aimeos.

We recently tried the decorator and code you suggested, and it worked well in our shop—thank you! :D

However, we have some questions about optimization. Given the large number of products we need to link to categories, even with filtering in place, the save process still takes a significant amount of time, leading to longer load times after clicking "Save."

Are there any steps or recommendations you could suggest to improve performance? For example, is it possible to run the save process in the background to reduce the loading time for users? I was considering using Laravel's queue jobs to handle the product-category linking in the background, but I'm unsure if this approach is compatible with Aimeos or if it's the best solution.

Thanks!

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

Re: Help with Customizing Catalog Functionality in Aimeos Admin

Post by aimeos » 21 Oct 2024, 09:00

Yes, you can use Laravel queues without problems because you have access to the Aimeos context object everywhere.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply