Esempio n. 1
0
 /**
  * Initialize data for configurable product
  *
  * @param Helper $subject
  * @param ProductInterface $product
  * @return ProductInterface
  * @throws \InvalidArgumentException
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterInitialize(Helper $subject, ProductInterface $product)
 {
     $attributes = $this->request->getParam('attributes');
     $productData = $this->request->getPost('product', []);
     if ($product->getTypeId() !== ConfigurableProduct::TYPE_CODE || empty($attributes)) {
         return $product;
     }
     $setId = $this->request->getPost('new-variations-attribute-set-id');
     if ($setId) {
         $product->setAttributeSetId($setId);
     }
     $extensionAttributes = $product->getExtensionAttributes();
     $product->setNewVariationsAttributeSetId($setId);
     $configurableOptions = [];
     if (!empty($productData['configurable_attributes_data'])) {
         $configurableOptions = $this->optionsFactory->create((array) $productData['configurable_attributes_data']);
     }
     $extensionAttributes->setConfigurableProductOptions($configurableOptions);
     $this->setLinkedProducts($product, $extensionAttributes);
     $product->setCanSaveConfigurableAttributes((bool) $this->request->getPost('affect_configurable_product_attributes'));
     $product->setExtensionAttributes($extensionAttributes);
     return $product;
 }
 /**
  * @covers Configurable::afterInitialize
  */
 public function testAfterInitializeWithAttributesAndWithoutVariations()
 {
     $attributes = [['attribute_id' => 90, 'values' => [['value_index' => 12], ['value_index' => 13]]]];
     $valueMap = [['new-variations-attribute-set-id', null, 24], ['associated_product_ids', [], []], ['product', [], ['configurable_attributes_data' => $attributes]]];
     $paramValueMap = [['variations-matrix', [], []], ['attributes', null, $attributes]];
     $this->product->expects(static::once())->method('getTypeId')->willReturn(ConfigurableProduct::TYPE_CODE);
     $this->request->expects(static::any())->method('getPost')->willReturnMap($valueMap);
     $this->request->expects(static::any())->method('getParam')->willReturnMap($paramValueMap);
     $extensionAttributes = $this->getMockBuilder(ProductExtensionAttributes::class)->disableOriginalConstructor()->setMethods(['setConfigurableProductOptions', 'setConfigurableProductLinks'])->getMockForAbstractClass();
     $this->product->expects(static::once())->method('getExtensionAttributes')->willReturn($extensionAttributes);
     $this->optionFactory->expects(static::once())->method('create')->with($attributes)->willReturn($attributes);
     $extensionAttributes->expects(static::once())->method('setConfigurableProductOptions')->with($attributes);
     $this->variationHandler->expects(static::never())->method('generateSimpleProducts');
     $extensionAttributes->expects(static::once())->method('setConfigurableProductLinks');
     $this->product->expects(static::once())->method('setExtensionAttributes')->with($extensionAttributes);
     $this->plugin->afterInitialize($this->subject, $this->product);
 }
Esempio n. 3
0
 /**
  * @covers \Magento\ConfigurableProduct\Helper\Product\Options\Factory::create
  */
 public function testCreate()
 {
     $attributeId = 90;
     $valueIndex = 12;
     $item = ['attribute_id' => $attributeId, 'values' => [['value_index' => $valueIndex]]];
     $data = [$item];
     $attribute = $this->getMockBuilder(Attribute::class)->disableOriginalConstructor()->setMethods(['setValues', 'setData', '__wakeup'])->getMock();
     $this->attributeFactory->expects(static::once())->method('create')->willReturn($attribute);
     $eavAttribute = $this->getMockBuilder(EavAttribute::class)->disableOriginalConstructor()->getMock();
     $this->productAttributeRepository->expects(static::once())->method('get')->with($attributeId)->willReturn($eavAttribute);
     $this->configurable->expects(static::once())->method('canUseAttribute')->with($eavAttribute)->willReturn(true);
     $option = $this->getMock(OptionValueInterface::class);
     $option->expects(static::once())->method('setValueIndex')->with($valueIndex)->willReturnSelf();
     $this->optionValueFactory->expects(static::once())->method('create')->willReturn($option);
     $attribute->expects(static::once())->method('setData')->with($item);
     $attribute->expects(static::once())->method('setValues')->with([$option]);
     $result = $this->factory->create($data);
     static::assertSame([$attribute], $result);
 }