I have created extension attributes which i would like to use in my custom plugin.I want to call this plugin when after credit memo item is saved which happens when credit memo is saved(refund) But my plugin is not getting called( var_dump("hello");exit(); ) and I am not getting any errors or warning. I cleaned, cache, flushed compile and upgrade. It would be really helpful if someone can suggest something so that I can learn new concept and continue my learning. I have referred to lot of similar questions and tried to understand the flow and hence I implemented this which seems to be missing a step. app\code\Vendor\Sales\etc\di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Sales\Api\Data\CreditmemoItemRepositoryInterface">
<plugin name="creditmemoitemdetail_plugin" type="Vendor\Sales\Plugin\Order\Creditmemo\CreditmemoItemDetailPlugin" sortOrder="1" disabled="false"/>
</type>
</config>
app\code\Vendor\Sales\etc\extension_attributes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Sales\Api\Data\CreditmemoItemInterface">
<attribute code="creditmemoitemdetail" type="Vendor\Sales\Api\Data\CreditmemoItemDetailInterface">
<join reference_table="sales_creditmemo_item_detail" reference_field="parent_id" join_on_field="entity_id">
<field column="entity_id">entity_id</field>
<field column="parent_id">parent_id</field>
<field column="item_number">item_number</field>
<field column="description">description</field>
<field column="sku">sku</field>
<field column="name">name</field>
</join>
</attribute>
</extension_attributes>
</config>
app\code\Vendor\Sales\Plugin\Order\Creditmemo\CreditmemoItemDetailPlugin.php
<?php
namespace Vendor\Sales\Plugin\Order\Creditmemo;
class CreditmemoItemDetailPlugin {
public function afterSave(
\Magento\Sales\Api\CreditmemoItemRepositoryInterface $subject,
\Magento\Sales\Api\Data\CreditmemoItemInterface $resultOrder
) {
$resultOrder = $this->saveTigrenAttribute($resultOrder);
return $resultOrder;
}
private function saveTigrenAttribute(\Magento\Sales\Api\Data\CreditmemoItemInterface $order)
{
var_dump("hello");exit();
$extensionAttributes = $order->getExtensionAttributes();
if (
null !== $extensionAttributes &&
null !== $extensionAttributes->getTigrenAttribute()
) {
$tigrenAttributeValue = $extensionAttributes->getTigrenAttribute()->getParentId();
$name = $extensionAttributes->getTigrenAttribute()->getName();
$sku = $extensionAttributes->getTigrenAttribute()->getSku();
$description = $extensionAttributes->getTigrenAttribute()->getDescription();
$item_number = $extensionAttributes->getTigrenAttribute()->getItemNumber();
try {
// The actual implementation of the repository is omitted
// but it is where you would save to the database (or any other persistent storage)
$this->tigrenExampleRepository->save($order->getParentId(), $tigrenAttributeValue);
$this->tigrenExampleRepository->save($order->getName(), $name);
$this->tigrenExampleRepository->save($order->getSku(), $sku);
$this->tigrenExampleRepository->save($order->getOrderItemId(), $item_number);
$this->tigrenExampleRepository->save($order->getDescription(), $description);
} catch (\Exception $e) {
throw new CouldNotSaveException(
__('Could not add attribute to order: "%1"', $e->getMessage()),
$e
);
}
}
return $order;
}
}