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

Commit eff234c

Browse files
authored
Merge pull request #8246 from chiranjeevi-cj/7786-aftersave-functionality-correctly-described
7786-Changed the code for afterSave function in adding-attributes.md file
2 parents bb3fce8 + c857ebf commit eff234c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/guides/v2.3/extension-dev-guide/extension_attributes/adding-attributes.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,19 @@ Likewise, the `afterSave` plugin should manipulate the entity data before return
107107
public function afterSave
108108
(
109109
\Magento\Catalog\Api\ProductRepositoryInterface $subject,
110-
\Magento\Catalog\Api\Data\ProductInterface $entity
110+
\Magento\Catalog\Api\Data\ProductInterface $result, /** result from the save call **/
111+
\Magento\Catalog\Api\Data\ProductInterface $entity /** original parameter to the call **/
112+
/** other parameter not required **/
111113
) {
112-
$extensionAttributes = $entity->getExtensionAttributes(); /** get current extension attributes from entity **/
114+
$extensionAttributes = $entity->getExtensionAttributes(); /** get original extension attributes from entity **/
113115
$ourCustomData = $extensionAttributes->getOurCustomData();
114116
$this->customDataRepository->save($ourCustomData);
115117

116-
return $entity;
118+
$resultAttributes = $result->getExtentionAttributes(); /** get extension attributes as they exist after save **/
119+
$resultAttributes->setOurCustomData($ourCustomData); /** update the extension attributes with correct data **/
120+
$result->setExtensionAttributes($resultAttributes);
121+
122+
return $result;
117123
}
118124
```
119125

0 commit comments

Comments
 (0)