/** * {@inheritdoc} */ public function update($productSku, $optionId, Option $option) { $product = $this->getProduct($productSku); $configurableAttribute = $this->configurableAttributeFactory->create(); $configurableAttribute->load($optionId); if (!$configurableAttribute->getId() || $configurableAttribute->getProductId() != $product->getId()) { throw new NoSuchEntityException('Option with id "%1" not found', [$optionId]); } $configurableAttribute = $this->optionConverter->getModelFromData($option, $configurableAttribute); try { $configurableAttribute->save(); } catch (\Exception $e) { throw new CouldNotSaveException('Could not update option with id "%1"', [$optionId]); } return true; }
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); }