cancel
Showing results for 
Search instead for 
Did you mean: 

Automate Smart Category Rules

Automate Smart Category Rules

Currently in 2.4+, the process of applying category rules requires a manual save of each category.  This is extremely time consuming for a store that has a lot of categories and also could severely impact the cache if done during business hours.  These rules should be applied automatically or at least on a schedule.  A bonus would be to do this in a cache-preserving way.

5 Comments
johnny16
Senior Member

Yes, I agree 100%. The expected behaviour of this feature should be that it automatically updates the category products dynamically.  There just doesn’t really seem to be much point in having this feature if it requires manually saving each category to update the products.

 

It’s really disappointing that I’m now going to have to abandon this Magento native feature in favor of a 3rd party module. All of these 3rd party options seem to offer the ability to update the category products automatically/dynamically without creating huge server loads.

marketings658a
New Member

Completely agree, We have just created 100's of categories on the advise of our SEO company which has worked amazingly well but we are also due to upload 200 new products to our catalog next week a lot of which will be in several of these categories. I have no idea how we are going to overcome having to waste time going back and  saving 100's of categories.

 

drewbombaradd1
Visitor

@johnny16 ... curious about what 3rd party products you may be using for this?

 

I was about to embark on a task of trying to trigger this Save option on timed Cron each morning so that the need to manually click the button was necessary.  

johnny16
Senior Member

@drewbombaradd1I've been using Mirasvit Dynamic Category for the past 14 months https://mirasvit.com/magento-2-dynamic-category.html .  It's a very well thought out extension, reasonably priced and works exactly like this feature should work.

 

There is a setting in this extension to run dynamic category re-indexing with the native reindex process but I have this setting disabled because I found it adversely affected server performance. I instead opted to run a full re-index daily each morning using the in-built command through CRON. The full re-indexing process takes about 15-20 minutes to complete on our database of 650 catagories and 21,000 products. Most of these products are in a minimum of 4 dynamic categories each.

drewbombaradd1
Visitor

Thanks for the tip!

 

While I was waiting for your reply I started poking at this little snippet of code that I think might do the trick.  We already have a cron that runs at 1:00 am every morning so the scheduling thing had been worked out.  About to put this into some real-world testing later on today / overnight to see how it goes -- initial tests were positive.

 

I'll definitely check out the Mirasvit module you mentioned as well.  Thanks again!

 

Have a great rest of your day.

- Drew

 

public function applyCategoryRules(): void
{
    $catFactory = $this->categoryFactory->create();
    $category = $catFactory->getCollection()
        ->addAttributeToFilter('name', 'New')
        ->getFirstItem();

    if ($category->getId()) {
        $category->save();
    }
}