public function testGetModelFromData() { $data = ['data']; $id = 33; $this->configurableAttribute->expects($this->any())->method('getData')->will($this->returnValue($data)); $this->configurableAttribute->expects($this->once())->method('setData')->with($this->equalTo($data)); $this->configurableAttribute->expects($this->once())->method('addData')->with($this->equalTo($data)); $this->configurableAttribute->expects($this->any())->method('getId')->will($this->returnValue($id)); $this->configurableAttribute->expects($this->once())->method('setId')->with($this->equalTo($id)); $this->configurableAttribute->expects($this->any())->method('getAttributeId')->will($this->returnValue($id)); $this->configurableAttribute->expects($this->once())->method('setAttributeId')->with($this->equalTo($id)); $this->configurableAttribute->expects($this->any())->method('getValues')->will($this->returnValue($data)); $this->configurableAttribute->expects($this->any())->method('setValues')->with($this->equalTo($data)); $this->option->expects($this->any())->method('getValues')->will($this->returnValue([$this->value])); $this->option->expects($this->any())->method('__toArray')->will($this->returnValue($data)); $this->valueConverter->expects($this->any())->method('convertArrayFromData')->with($this->equalTo($this->value))->will($this->returnValue($data[0])); $result = $this->converter->getModelFromData($this->option, $this->configurableAttribute); $this->assertEquals($this->configurableAttribute, $result); }
/** * @param Option $option * @param Attribute $configurableAttribute * @return Attribute */ public function getModelFromData(Option $option, Attribute $configurableAttribute) { /** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute $returnConfigurableAttribute */ $returnConfigurableAttribute = $this->attributeFactory->create(); $returnConfigurableAttribute->setData($configurableAttribute->getData()); $returnConfigurableAttribute->addData($option->__toArray()); $returnConfigurableAttribute->setId($configurableAttribute->getId()); $returnConfigurableAttribute->setAttributeId($configurableAttribute->getAttributeId()); $returnConfigurableAttribute->setValues($configurableAttribute->getPrices()); $values = $option->getValues(); if (!is_null($values)) { $prices = []; foreach ($values as $value) { $prices[] = $this->valueConverter->convertArrayFromData($value); } $returnConfigurableAttribute->setValues($prices); } return $returnConfigurableAttribute; }