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();
    }
}
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();
    }
}
  • thanks, i found this event by yesterday. i forgot to update here. – Sathish Feb 15 '17 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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