Ejemplo n.º 1
0
 /**
  * Prepare attribute info for variation matrix generation
  *
  * @param \Magento\ConfigurableProduct\Service\V1\Data\Option[] $options
  * @return array
  */
 private function getAttributesForMatrix($options)
 {
     $attributes = [];
     foreach ($options as $option) {
         $configurable = $option->__toArray();
         $attribute = $this->attributeReadService->info($option->getAttributeId());
         $configurable['options'] = $attribute->__toArray()['options'];
         $configurable['attribute_code'] = $attribute->getAttributeCode();
         $attributes[$option->getAttributeId()] = $configurable;
     }
     return $attributes;
 }
Ejemplo n.º 2
0
 /**
  * @param array $configurableAttributeData
  * @dataProvider productVariationDataProvider
  */
 public function testGenerateVariation($configurableAttributeData)
 {
     $attributeCode = 'code';
     $attribute = $this->getMockBuilder('Magento\\Catalog\\Service\\V1\\Data\\Eav\\AttributeMetadata')->disableOriginalConstructor()->getMock();
     $attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $this->attributeReadService->expects($this->once())->method('info')->with($configurableAttributeData['attribute_id'])->will($this->returnValue($attribute));
     $options = null;
     $this->variationMatrix->expects($this->any())->method('getVariations')->with([$configurableAttributeData['attribute_id'] => ["attribute_id" => $configurableAttributeData['attribute_id'], "values" => $configurableAttributeData['values'], "options" => $options, "attribute_code" => $attributeCode]])->will($this->returnValue([[$configurableAttributeData['attribute_id'] => ['value' => '14', 'label' => 'dd', 'price' => ['index' => 14, 'price' => 10]]]]));
     $product = $this->getMockBuilder('Magento\\Catalog\\Service\\V1\\Data\\Product')->disableOriginalConstructor()->getMock();
     $product->expects($this->any())->method('getPrice')->will($this->returnValue(100));
     $configurableAttribute = $this->getMockBuilder('Magento\\ConfigurableProduct\\Service\\V1\\Data\\Option')->disableOriginalConstructor()->getMock();
     $configurableAttribute->expects($this->any())->method('__toArray')->will($this->returnValue($configurableAttributeData));
     $configurableAttribute->expects($this->any())->method('getAttributeId')->will($this->returnValue($configurableAttributeData['attribute_id']));
     $this->productBuilder->expects($this->any())->method('populute')->with($product);
     $this->productBuilder->expects($this->once())->method('setCustomAttribute')->with($attributeCode, 14);
     $this->productBuilder->expects($this->once())->method('setPrice')->with(110);
     $this->productBuilder->expects($this->once())->method('create')->will($this->returnValue($product));
     $result = $this->object->generateVariation($product, [$configurableAttribute]);
     $this->assertCount(1, $result);
     $this->assertEquals([$product], $result);
 }