You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: guides/v2.0/extension-dev-guide/extension_attributes/adding-attributes.md
+56Lines changed: 56 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -105,6 +105,62 @@ Likewise afterSave plugin should take data from entity and do some manipulations
105
105
?>
106
106
{% endhighlight %}
107
107
108
+
But if some entity doesn't have implementation to fetch extension attributes, we will always retrieve `null` and each time when we fetch extension atrributes we need to check if they are `null` - need to create them. To avoid such code duplication, we need to create `afterGet` plugin for our entity with extension attributes.
109
+
110
+
Let's assume the product entity doesn't have any implementation of extension attributes, so our plugin might looks like this:
111
+
112
+
{% highlight php startinline=1 %}
113
+
114
+
use Magento\Catalog\Api\Data\ProductExtensionInterface;
115
+
use Magento\Catalog\Api\Data\ProductInterface;
116
+
use Magento\Catalog\Api\Data\ProductExtensionFactory;
0 commit comments