/**
  * Remove catalog attribute condition by attribute code from rule conditions
  *
  * @param \Magento\Rule\Model\Condition\Combine $combine
  * @param string $attributeCode
  * @return void
  */
 protected function _removeAttributeFromConditions($combine, $attributeCode)
 {
     $conditions = $combine->getConditions();
     foreach ($conditions as $conditionId => $condition) {
         if ($condition instanceof \Magento\Rule\Model\Condition\Combine) {
             $this->_removeAttributeFromConditions($condition, $attributeCode);
         }
         if ($condition instanceof \Magento\SalesRule\Model\Rule\Condition\Product) {
             if ($condition->getAttribute() == $attributeCode) {
                 unset($conditions[$conditionId]);
             }
         }
     }
     $combine->setConditions($conditions);
 }
示例#2
0
 /**
  * @param Combine $combine
  * @param string $value
  * @return string
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _getMappedSqlCombination(Combine $combine, $value = '')
 {
     $out = !empty($value) ? $value : '';
     $value = $combine->getValue() ? '' : ' NOT ';
     $getAggregator = $combine->getAggregator();
     $conditions = $combine->getConditions();
     foreach ($conditions as $key => $condition) {
         /** @var $condition AbstractCondition|Combine */
         $con = $getAggregator == 'any' ? \Zend_Db_Select::SQL_OR : \Zend_Db_Select::SQL_AND;
         $con = isset($conditions[$key + 1]) ? $con : '';
         if ($condition instanceof Combine) {
             $out .= $this->_getMappedSqlCombination($condition, $value);
         } else {
             $out .= $this->_getMappedSqlCondition($condition, $value);
         }
         $out .= $out ? ' ' . $con : '';
     }
     return $this->_expressionFactory->create(['expression' => $out]);
 }