public function testValidateSetEntityAttributeValuesWithoutResource()
 {
     $product = $this->getMock('Magento\\Framework\\Model\\AbstractModel', ['someMethod', 'getResource', 'load'], [], '', false);
     $this->_condition->setAttribute('someAttribute');
     $product->setAtribute('attribute');
     $product->setId(12);
     $this->_configProperty->setValue($this->_condition, $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false));
     $this->_entityAttributeValuesProperty->setValue($this->_condition, $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false));
     $attribute = new \Magento\Framework\DataObject();
     $attribute->setBackendType('multiselect');
     $newResource = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product', ['getAttribute'], [], '', false);
     $newResource->expects($this->any())->method('getAttribute')->with('someAttribute')->will($this->returnValue($attribute));
     $newResource->_config = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
     $product->expects($this->atLeastOnce())->method('getResource')->willReturn($newResource);
     $this->_entityAttributeValuesProperty->setValue($this->_condition, [1 => [''], 2 => ['option1,option2,option3'], 3 => ['option1,option2,option3']]);
     $this->assertFalse($this->_condition->validate($product));
     $attribute = new \Magento\Framework\DataObject();
     $attribute->setBackendType(null);
     $attribute->setFrontendInput('multiselect');
     $newResource = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product', ['getAttribute'], [], '', false);
     $newResource->expects($this->any())->method('getAttribute')->with('someAttribute')->will($this->returnValue($attribute));
     $newResource->_config = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
     $product->setResource($newResource);
     $product->setId(1);
     $product->setData('someAttribute', 'value');
     $this->assertFalse($this->_condition->validate($product));
 }
Example #2
0
 /**
  * Validate Product Rule Condition
  *
  * @param \Magento\Framework\Model\AbstractModel $model
  * @return bool
  */
 public function validate(\Magento\Framework\Model\AbstractModel $model)
 {
     //@todo reimplement this method when is fixed MAGETWO-5713
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $model->getProduct();
     if (!$product instanceof \Magento\Catalog\Model\Product) {
         $product = $this->productRepository->getById($model->getProductId());
     }
     $product->setQuoteItemQty($model->getQty())->setQuoteItemPrice($model->getPrice())->setQuoteItemRowTotal($model->getBaseRowTotal());
     return parent::validate($product);
 }
Example #3
0
 /**
  * Validate Product Rule Condition
  *
  * @param \Magento\Framework\Object $object
  * @return bool
  */
 public function validate(\Magento\Framework\Object $object)
 {
     //@todo reimplement this method when is fixed MAGETWO-5713
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $object->getProduct();
     if (!$product instanceof \Magento\Catalog\Model\Product) {
         $product = $this->_productFactory->create()->load($object->getProductId());
     }
     $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal());
     return parent::validate($product);
 }