di.xml
< ?xml version="1.0"?>
extension_attributes.xml
< ?xml version="1.0"?>
Save.php
< ?php
namespace CCreditMemoItemDetailsModelPlugin;
use MagentoFrameworkExceptionCouldNotSaveException;
class Save
{
public function beforeSave(
MagentoSalesApiCreditMemoItemRepositoryInterface $subject,
MagentoSalesApiDataCreditMemoItemInterface $entity
)
{
echo("hello");exit();
}
public function afterSave(
MagentoSalesApiCreditMemoItemRepositoryInterface $subject,
MagentoSalesApiDataCreditMemoItemInterface $result
) {
echo("hello");exit();
$result = $this->savecreditmemoitemdetailsAttribute($result);
return $result;
}
private function savecreditmemoitemdetailsAttribute(MagentoSalesApiDataCreditMemoItemInterface $creditmemoitemdetails)
{
$extensionAttributes = $creditmemoitemdetails->getExtensionAttributes();
if (
null !== $extensionAttributes &&
null !== $extensionAttributes->getcreditememoitemdetailsAttribute()
) {
$request = $this->getRequest();
$data = $request->getPost('creditmemo');
$data['creditmemo']['refund_creditlof_refund_credit'] = 1;
$data['do_offline'] = true;
$request->setPostValue('creditmemo', $data);
$creditememoitemdetailsAttributeValue = $extensionAttributes->getcreditememoitemdetailsAttribute()->getValue();
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->CreditMemoItemDetailsRepository->save($creditmemoitemdetails->getEntityId(), $creditememoitemdetailsAttributeValue);
foreach($data['item_Number'] as $selected){
echo $selected;
$this->creditmemoitemdetails->setItemNumber($selected);
}exit();
$creditememoitemdetailsAttributeValue->save();
} catch (Exception $e) {
throw new CouldNotSaveException(
__('Could not add attribute to order: "%1"', $e->getMessage()),
$e
);
}
}
return $creditmemoitemdetails;
}
}
Basically I am trying to extend Save.php by creating this plugin and save custom data in my newly created table in backend. But when I am saving creditmemo it is not passing any of those exists nor it gives any warnings or error. What should I do at this point? Am I doing it in right manner I am referring to How to extend creditmemo save action in magento 2 and https://store.fooman.co.nz/blog/an-introduction-to-extension-attributes.html