Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8246 from chiranjeevi-cj/7786-aftersave-functiona…
Browse files Browse the repository at this point in the history
…lity-correctly-described

7786-Changed the code for afterSave function in adding-attributes.md file
  • Loading branch information
dobooth authored Nov 24, 2020
2 parents bb3fce8 + c857ebf commit eff234c
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,19 @@ Likewise, the `afterSave` plugin should manipulate the entity data before return
public function afterSave
(
\Magento\Catalog\Api\ProductRepositoryInterface $subject,
\Magento\Catalog\Api\Data\ProductInterface $entity
\Magento\Catalog\Api\Data\ProductInterface $result, /** result from the save call **/
\Magento\Catalog\Api\Data\ProductInterface $entity /** original parameter to the call **/
/** other parameter not required **/
) {
$extensionAttributes = $entity->getExtensionAttributes(); /** get current extension attributes from entity **/
$extensionAttributes = $entity->getExtensionAttributes(); /** get original extension attributes from entity **/
$ourCustomData = $extensionAttributes->getOurCustomData();
$this->customDataRepository->save($ourCustomData);

return $entity;
$resultAttributes = $result->getExtentionAttributes(); /** get extension attributes as they exist after save **/
$resultAttributes->setOurCustomData($ourCustomData); /** update the extension attributes with correct data **/
$result->setExtensionAttributes($resultAttributes);

return $result;
}
```

Expand Down

0 comments on commit eff234c

Please sign in to comment.