public function testBeforeSave() { $this->attributeMock->expects($this->any())->method('getName')->willReturn('attribute_name'); $object = new DataObject(['use_config_attribute_name' => true]); $this->model->beforeSave($object); $this->assertEquals(BooleanSource::VALUE_USE_CONFIG, $object->getData('attribute_name')); }
/** * Disable MAP if it's bundle with dynamic price type * * @param \Magento\Catalog\Model\Product $product * @return $this */ public function beforeSave($product) { if (!$product instanceof \Magento\Catalog\Model\Product || $product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE || $product->getPriceType() != \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) { return parent::beforeSave($product); } parent::beforeSave($product); $attributeCode = $this->getAttribute()->getName(); $value = $product->getData($attributeCode); if (empty($value)) { $value = $this->_catalogData->isMsrpApplyToAll(); } if ($value) { $product->setData($attributeCode, 0); } return $this; }