optionLoader = $optionLoader; } /** * @param object $entity * @param array $arguments * @return object * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute($entity, $arguments = []) { if ($entity->getTypeId() !== Configurable::TYPE_CODE) { return $entity; } $extensionAttributes = $entity->getExtensionAttributes(); $extensionAttributes->setConfigurableProductLinks($this->getLinkedProducts($entity)); $extensionAttributes->setConfigurableProductOptions($this->optionLoader->load($entity)); $entity->setExtensionAttributes($extensionAttributes); return $entity; } /** * Get linked to configurable simple products * * @param ProductInterface $product * @return int[] */ private function getLinkedProducts(ProductInterface $product) { /** @var Configurable $typeInstance */ $typeInstance = $product->getTypeInstance(); $childrenIds = $typeInstance->getChildrenIds($product->getId()); if (isset($childrenIds[0])) { return $childrenIds[0]; } else { return []; } } }