예제 #1
0
 /**
  * Add attribute to filter
  *
  * @param int $storeId
  * @param string $attributeCode
  * @param mixed $value
  * @param string $type
  * @return \Zend_Db_Select|bool
  */
 protected function _addFilter($storeId, $attributeCode, $value, $type = '=')
 {
     if (!$this->_select instanceof \Zend_Db_Select) {
         return false;
     }
     if (!isset($this->_attributesCache[$attributeCode])) {
         $attribute = $this->_categoryResource->getAttribute($attributeCode);
         $this->_attributesCache[$attributeCode] = array('entity_type_id' => $attribute->getEntityTypeId(), 'attribute_id' => $attribute->getId(), 'table' => $attribute->getBackend()->getTable(), 'is_global' => $attribute->getIsGlobal(), 'backend_type' => $attribute->getBackendType());
     }
     $attribute = $this->_attributesCache[$attributeCode];
     switch ($type) {
         case '=':
             $conditionRule = '=?';
             break;
         case 'in':
             $conditionRule = ' IN(?)';
             break;
         default:
             return false;
             break;
     }
     if ($attribute['backend_type'] == 'static') {
         $this->_select->where('e.' . $attributeCode . $conditionRule, $value);
     } else {
         $this->_select->join(array('t1_' . $attributeCode => $attribute['table']), 'e.entity_id = t1_' . $attributeCode . '.entity_id AND t1_' . $attributeCode . '.store_id = 0', array())->where('t1_' . $attributeCode . '.attribute_id=?', $attribute['attribute_id']);
         if ($attribute['is_global']) {
             $this->_select->where('t1_' . $attributeCode . '.value' . $conditionRule, $value);
         } else {
             $ifCase = $this->_select->getAdapter()->getCheckSql('t2_' . $attributeCode . '.value_id > 0', 't2_' . $attributeCode . '.value', 't1_' . $attributeCode . '.value');
             $this->_select->joinLeft(array('t2_' . $attributeCode => $attribute['table']), $this->_getWriteAdapter()->quoteInto('t1_' . $attributeCode . '.entity_id = t2_' . $attributeCode . '.entity_id AND t1_' . $attributeCode . '.attribute_id = t2_' . $attributeCode . '.attribute_id AND t2_' . $attributeCode . '.store_id=?', $storeId), array())->where('(' . $ifCase . ')' . $conditionRule, $value);
         }
     }
     return $this->_select;
 }
 /**
  * Validate category process
  *
  * @param  Category $category
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function validateCategory(Category $category)
 {
     $useConfigFields = [];
     foreach ($this->useConfigFields as $field) {
         if (!$category->getData($field)) {
             $useConfigFields[] = $field;
         }
     }
     $category->setData('use_post_data_config', $useConfigFields);
     $validate = $category->validate();
     if ($validate !== true) {
         foreach ($validate as $code => $error) {
             if ($error === true) {
                 $attribute = $this->categoryResource->getAttribute($code)->getFrontend()->getLabel();
                 throw new \Magento\Framework\Exception\LocalizedException(__('Attribute "%1" is required.', $attribute));
             } else {
                 throw new \Magento\Framework\Exception\LocalizedException(__($error));
             }
         }
     }
     $category->unsetData('use_post_data_config');
 }