Last active
May 25, 2018 14:36
-
-
Save paliarush/23a5e8dff4b5bb42f6d207435c61810d to your computer and use it in GitHub Desktop.
No more boilerplate code for extension attributes object instantiation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Before Magento 2.3 | |
$extensionAttributes = $product->getExtensionAttributes(); | |
if (null === $extensionAttributes) { | |
/** @var \Magento\Catalog\Api\Data\ProductExtensionInterface $extensionAttributes */ | |
$extensionAttributes = $this->extensionAttributesFactory->create(ProductInterface::class); | |
$product->setExtensionAttributes($extensionAttributes); | |
} | |
$myExtensionAttribute = $extensionAttributes->getMyExtensionAttribute(); | |
// After Magento 2.3 | |
$myExtensionAttribute = $product->getExtensionAttributes()->getMyExtensionAttribute(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment