/**
  * @param array $setData
  * @param string $attributeObjectFrontendInput
  * @param array $attrObjectSourceAllOptionsValue
  * @param array $attrSetCollectionOptionsArray
  * @param bool $expectedAttrObjSourceAllOptionsParam
  * @param array $expectedValueSelectOptions
  * @param array $expectedValueOption
  * @dataProvider prepareValueOptionsDataProvider
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function testPrepareValueOptions($setData, $attributeObjectFrontendInput, $attrObjectSourceAllOptionsValue, $attrSetCollectionOptionsArray, $expectedAttrObjSourceAllOptionsParam, $expectedValueSelectOptions, $expectedValueOption)
 {
     foreach ($setData as $key => $value) {
         $this->_condition->setData($key, $value);
     }
     $attrObjectSourceMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Source\\AbstractSource')->setMethods(['getAllOptions'])->disableOriginalConstructor()->getMock();
     $attrObjectSourceMock->expects(null === $expectedAttrObjSourceAllOptionsParam ? $this->never() : $this->once())->method('getAllOptions')->with($expectedAttrObjSourceAllOptionsParam)->willReturn($attrObjectSourceAllOptionsValue);
     $attributeObjectMock = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute')->setMethods(['usesSource', 'getFrontendInput', 'getSource', 'getAllOptions'])->disableOriginalConstructor()->getMock();
     $attributeObjectMock->method('usesSource')->willReturn(true);
     $attributeObjectMock->expects(null === $attributeObjectFrontendInput ? $this->never() : $this->once())->method('getFrontendInput')->willReturn($attributeObjectFrontendInput);
     $attributeObjectMock->method('getSource')->willReturn($attrObjectSourceMock);
     $entityTypeMock = $this->getMockBuilder('Magento\\Framework\\Model\\AbstractModel\\Type')->setMethods(['getId'])->disableOriginalConstructor()->getMock();
     $entityTypeMock->method('getId')->willReturn('SomeEntityType');
     $configValueMock = $this->getMock('Magento\\Eav\\Model\\Config', ['getAttribute', 'getEntityType'], [], '', false);
     $configValueMock->method('getAttribute')->willReturn($attributeObjectMock);
     $configValueMock->method('getEntityType')->willReturn($entityTypeMock);
     $configProperty = new ReflectionProperty('Magento\\Rule\\Model\\Condition\\Product\\AbstractProduct', '_config');
     $configProperty->setAccessible(true);
     $configProperty->setValue($this->_condition, $configValueMock);
     $attrSetCollectionValueMock = $this->getMockBuilder('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection')->setMethods(['setEntityTypeFilter', 'load', 'toOptionArray'])->disableOriginalConstructor()->getMock();
     $attrSetCollectionValueMock->method('setEntityTypeFilter')->will($this->returnSelf());
     $attrSetCollectionValueMock->method('load')->will($this->returnSelf());
     $attrSetCollectionValueMock->expects(null === $attrSetCollectionOptionsArray ? $this->never() : $this->once())->method('toOptionArray')->willReturn($attrSetCollectionOptionsArray);
     $attrSetCollectionProperty = new ReflectionProperty('Magento\\Rule\\Model\\Condition\\Product\\AbstractProduct', '_attrSetCollection');
     $attrSetCollectionProperty->setAccessible(true);
     $attrSetCollectionProperty->setValue($this->_condition, $attrSetCollectionValueMock);
     $testedMethod = new ReflectionMethod('Magento\\Rule\\Model\\Condition\\Product\\AbstractProduct', '_prepareValueOptions');
     $testedMethod->setAccessible(true);
     $testedMethod->invoke($this->_condition);
     $this->assertEquals($expectedValueSelectOptions, $this->_condition->getData('value_select_options'));
     $this->assertEquals($expectedValueOption, $this->_condition->getData('value_option'));
 }
Exemple #2
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);
 }
Exemple #3
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);
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function getMappedSqlField()
 {
     $result = '';
     if ($this->getAttribute() == 'category_ids') {
         $result = parent::getMappedSqlField();
     } elseif (isset($this->joinedAttributes[$this->getAttribute()])) {
         $result = $this->joinedAttributes[$this->getAttribute()];
     } elseif ($this->getAttributeObject()->isStatic()) {
         $result = $this->getAttributeObject()->getAttributeCode();
     } elseif ($this->getValueParsed()) {
         $result = 'e.entity_id';
     }
     return $result;
 }
Exemple #5
0
 /**
  * @SuppressWarnings(PHPMD.CamelCaseMethodName)
  * @SuppressWarnings(PHPMD.ElseExpression)
  *
  * {@inheritDoc}
  */
 protected function _prepareValueOptions()
 {
     $selectReady = $this->getData('value_select_options');
     $hashedReady = $this->getData('value_option');
     if (in_array($this->getAttribute(), ['stock.is_in_stock', 'has_image', 'price.is_discount'])) {
         $selectOptions = $this->booleanSource->toOptionArray();
         $this->_setSelectOptions($selectOptions, $selectReady, $hashedReady);
     } else {
         parent::_prepareValueOptions();
     }
 }