Ejemplo n.º 1
0
 public function testConvertFromModel()
 {
     $converterMock = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\Attribute')->disableOriginalConstructor()->setMethods(['getId', 'getData', 'getLabel', '__sleep', '__wakeup', 'getProductAttribute'])->getMock();
     $productAttribute = $this->getMockBuilder('Magento\\Catalog\\Model\\Resource\\Eav\\Attribute')->disableOriginalConstructor()->setMethods(['getFrontend', '__wakeup'])->getMock();
     $frontend = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\DefaultFrontend')->disableOriginalConstructor()->setMethods(['getInputType'])->getMock();
     $productAttribute->expects($this->any())->method('getFrontend')->will($this->returnValue($frontend));
     $frontend->expects($this->once())->method('getInputType')->will($this->returnValue('select'));
     $prices = ['value_index' => 1, 'pricing_value' => 12, 'is_percent' => true];
     $converterMock->expects($this->at(0))->method('getData')->with('prices')->will($this->returnValue([$prices]));
     $converterMock->expects($this->once())->method('getId')->will($this->returnValue(1));
     $converterMock->expects($this->at(2))->method('getData')->with('attribute_id')->will($this->returnValue(2));
     $converterMock->expects($this->once())->method('getLabel')->will($this->returnValue('Test Label'));
     $converterMock->expects($this->any())->method('getProductAttribute')->will($this->returnValue($productAttribute));
     $converterMock->expects($this->at(5))->method('getData')->with('position')->will($this->returnValue(3));
     $converterMock->expects($this->at(6))->method('getData')->with('use_default')->will($this->returnValue(true));
     /** @var \Magento\ConfigurableProduct\Service\V1\Data\Option $option */
     $option = $this->converter->convertFromModel($converterMock);
     $this->assertEquals(1, $option->getId());
     $this->assertEquals(2, $option->getAttributeId());
     $this->assertEquals('Test Label', $option->getLabel());
     $this->assertEquals(3, $option->getPosition());
     /** @var \Magento\ConfigurableProduct\Service\V1\Data\Option\Value $value */
     $value = \current($option->getValues());
     $this->assertEquals(1, $value->getIndex());
     $this->assertEquals(12, $value->getPrice());
     $this->assertEquals(true, $value->isPercent());
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function getList($productSku)
 {
     $options = [];
     $product = $this->getProduct($productSku);
     foreach ($this->getConfigurableAttributesCollection($product) as $option) {
         $options[] = $this->optionConverter->convertFromModel($option);
     }
     return $options;
 }