/** * @param string $entityType * @param ProductInterface $entity * @return ProductInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute($entityType, $entity) { 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; }
/** * @covers \Magento\ConfigurableProduct\Helper\Product\Options\Loader::load */ public function testLoad() { $option = ['value_index' => 23]; $this->product->expects(static::once())->method('getTypeInstance')->willReturn($this->configurable); $attribute = $this->getMockBuilder(Attribute::class)->disableOriginalConstructor()->setMethods(['getOptions', 'setValues'])->getMock(); $attributes = [$attribute]; $iterator = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $iterator->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator($attributes)); $this->configurable->expects(static::once())->method('getConfigurableAttributeCollection')->with($this->product)->willReturn($iterator); $attribute->expects(static::once())->method('getOptions')->willReturn([$option]); $optionValue = $this->getMockForAbstractClass(OptionValueInterface::class); $this->optionValueFactory->expects(static::once())->method('create')->willReturn($optionValue); $optionValue->expects(static::once())->method('setValueIndex')->with($option['value_index']); $attribute->expects(static::once())->method('setValues')->with([$optionValue]); $options = $this->loader->load($this->product); static::assertSame([$attribute], $options); }
/** * {@inheritdoc} */ public function getList($sku) { $product = $this->getProduct($sku); return (array) $this->optionLoader->load($product); }