예제 #1
0
 /**
  * Apply price rule price to price index table
  *
  * @param \Magento\Framework\DB\Select $select
  * @param array|string $indexTable
  * @param string $entityId
  * @param string $customerGroupId
  * @param string $websiteId
  * @param array $updateFields       the array of fields for compare with rule price and update
  * @param string $websiteDate
  * @return \Magento\CatalogRule\Model\ResourceModel\Rule\Product\Price
  */
 public function applyPriceRuleToIndexTable(\Magento\Framework\DB\Select $select, $indexTable, $entityId, $customerGroupId, $websiteId, $updateFields, $websiteDate)
 {
     if (empty($updateFields)) {
         return $this;
     }
     if (is_array($indexTable)) {
         foreach ($indexTable as $k => $v) {
             if (is_string($k)) {
                 $indexAlias = $k;
             } else {
                 $indexAlias = $v;
             }
             break;
         }
     } else {
         $indexAlias = $indexTable;
     }
     $select->join(['rp' => $this->getMainTable()], "rp.rule_date = {$websiteDate}", [])->where("rp.product_id = {$entityId} AND rp.website_id = {$websiteId} AND rp.customer_group_id = {$customerGroupId}");
     foreach ($updateFields as $priceField) {
         $priceCond = $this->getConnection()->quoteIdentifier([$indexAlias, $priceField]);
         $priceExpr = $this->getConnection()->getCheckSql("rp.rule_price < {$priceCond}", 'rp.rule_price', $priceCond);
         $select->columns([$priceField => $priceExpr]);
     }
     $query = $select->crossUpdateFromSelect($indexTable);
     $this->getConnection()->query($query);
     return $this;
 }
예제 #2
0
 /**
  * Add attribute to filter
  *
  * @param int $storeId
  * @param string $attributeCode
  * @param mixed $value
  * @param string $type
  * @return \Magento\Framework\DB\Select|bool
  */
 protected function _addFilter($storeId, $attributeCode, $value, $type = '=')
 {
     if (!$this->_select instanceof \Magento\Framework\DB\Select) {
         return false;
     }
     if (!isset($this->_attributesCache[$attributeCode])) {
         $attribute = $this->_categoryResource->getAttribute($attributeCode);
         $this->_attributesCache[$attributeCode] = ['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(['t1_' . $attributeCode => $attribute['table']], 'e.entity_id = t1_' . $attributeCode . '.entity_id AND t1_' . $attributeCode . '.store_id = 0', [])->where('t1_' . $attributeCode . '.attribute_id=?', $attribute['attribute_id']);
         if ($attribute['is_global']) {
             $this->_select->where('t1_' . $attributeCode . '.value' . $conditionRule, $value);
         } else {
             $ifCase = $this->getConnection()->getCheckSql('t2_' . $attributeCode . '.value_id > 0', 't2_' . $attributeCode . '.value', 't1_' . $attributeCode . '.value');
             $this->_select->joinLeft(['t2_' . $attributeCode => $attribute['table']], $this->getConnection()->quoteInto('t1_' . $attributeCode . '.entity_id = t2_' . $attributeCode . '.entity_id AND t1_' . $attributeCode . '.attribute_id = t2_' . $attributeCode . '.attribute_id AND t2_' . $attributeCode . '.store_id=?', $storeId), [])->where('(' . $ifCase . ')' . $conditionRule, $value);
         }
     }
     return $this->_select;
 }
예제 #3
0
 /**
  * Add join for catalog/product_website table
  * Joined table has alias pw
  *
  * @param \Magento\Framework\DB\Select $select the select object
  * @param string|\Zend_Db_Expr $website the limitation of website_id
  * @param string|\Zend_Db_Expr $product the limitation of product_id
  * @return $this
  */
 protected function _addProductWebsiteJoinToSelect($select, $website, $product)
 {
     $select->join(['pw' => $this->getTable('catalog_product_website')], "pw.product_id = {$product} AND pw.website_id = {$website}", []);
     return $this;
 }
예제 #4
0
 /**
  * Add stock status limitation to catalog product price index select object
  *
  * @param \Magento\Framework\DB\Select $select
  * @param string|\Zend_Db_Expr $entityField
  * @param string|\Zend_Db_Expr $websiteField
  * @return $this
  */
 public function prepareCatalogProductIndexSelect(\Magento\Framework\DB\Select $select, $entityField, $websiteField)
 {
     $select->join(array('ciss' => $this->getMainTable()), "ciss.product_id = {$entityField} AND ciss.website_id = {$websiteField}", array());
     $select->where('ciss.stock_status = ?', Stock\Status::STATUS_IN_STOCK);
     return $this;
 }
 protected function applyCondition(Select $select)
 {
     $select->join(['id' => $this->tableName], 'attribute.entity_id = id.entity_id', []);
 }
 public function limitFlatActive(Select $select, $alias = 'main')
 {
     $select->join(['flat' => $this->getTable('entity_flat')], $alias . '.entity_id = flat.entity_id', []);
     $select->where('flat.scope_id = ?', $this->scope->getId($this->scopeCode));
     $select->where('flat.is_active = ?', 1);
     return $this;
 }