1

I have tried to get the category id to store in my custom table with some values like cat_id, custom_value.

here i googled and get "catalog_category_prepare_save" to get category object when saving the existing category but when adding new order how will i get category id?

please suggest any events is there in magento2 for "catalog_category_prepare_save"? or suggest to some other method?

here by add my codes:

events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="catalog_category_prepare_save">
        <observer name="categoryattributes" instance="Namespace\Module\Observer\Categoryattributes"/>
    </event>
</config>

Categoryattributes.php

<?php
namespace Namespace\Module\Observer;

class Categoryattributes implements \Magento\Framework\Event\ObserverInterface
{
    private $category = null;
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
         $this->category = $observer->getEvent()->getCategory();
    }
}

1 Answer 1

6

You can use catalog_category_save_after event.

event.xml

 <?xml version="1.0"?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="catalog_category_save_after">
        <observer name="categoryattributes" instance="Namespace\Module\Observer\Categoryattributes"/>
    </event>
 </config>

Categoryattributes.php

<?php
namespace Namespace\Module\Observer;

class Categoryattributes implements \Magento\Framework\Event\ObserverInterface
{
    private $category = null;
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
         $this->category = $observer->getEvent()->getCategory();
    }
}
1
  • thanks, i found this event by yesterday. i forgot to update here.
    – Sathish
    Feb 15, 2017 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.