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

7786-Changed the code for afterSave function in adding-attributes.md file #8246

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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