public function testInsertProductData() { $productId = 100; $productMock = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId'], [], '', false); $productMock->expects($this->once())->method('getId')->willReturn($productId); $this->connectionMock->expects($this->once())->method('insert')->with('table_name', ['entity_id' => $productId]); $this->assertEquals($this->model, $this->model->insertProductData($productMock, [])); }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function afterSave($object) { $orig = $object->getOrigData($this->getAttribute()->getName()); $current = $object->getData($this->getAttribute()->getName()); if ($orig == $current) { return $this; } $this->_attributeTax->deleteProductData($object, $this->getAttribute()); $taxes = $object->getData($this->getAttribute()->getName()); if (!is_array($taxes)) { return $this; } foreach ($taxes as $tax) { if (empty($tax['price']) && empty($tax['value']) || empty($tax['country']) || !empty($tax['delete'])) { continue; } $state = isset($tax['state']) ? $tax['state'] : '0'; $data = []; $data['website_id'] = $tax['website_id']; $data['country'] = $tax['country']; $data['state'] = $state; $data['value'] = !empty($tax['price']) ? $tax['price'] : $tax['value']; $data['attribute_id'] = $this->getAttribute()->getId(); $this->_attributeTax->insertProductData($object, $data); } return $this; }