Example #1
0
 /**
  * Prepare rewrites for condition
  *
  * @param int $storeId
  * @param int|array $categoryIds
  * @param int|array $productIds
  * @return array
  */
 public function prepareRewrites($storeId, $categoryIds = null, $productIds = null)
 {
     $rewrites = array();
     $adapter = $this->_getWriteAdapter();
     $select = $adapter->select()->from($this->getMainTable())->where('store_id = :store_id')->where('is_system = ?', 1);
     $bind = array('store_id' => $storeId);
     if ($categoryIds === null) {
         $select->where('category_id IS NULL');
     } elseif ($categoryIds) {
         $catIds = is_array($categoryIds) ? $categoryIds : array($categoryIds);
         // Check maybe we request products and root category id is within categoryIds,
         // it's a separate case because root category products are stored with NULL categoryId
         if ($productIds) {
             $addNullCategory = in_array($this->getStores($storeId)->getRootCategoryId(), $catIds);
         } else {
             $addNullCategory = false;
         }
         // Compose optimal condition
         if ($addNullCategory) {
             $select->where('category_id IN(?) OR category_id IS NULL', $catIds);
         } else {
             $select->where('category_id IN(?)', $catIds);
         }
     }
     if ($productIds === null) {
         $select->where('product_id IS NULL');
     } elseif ($productIds) {
         $select->where('product_id IN(?)', $productIds);
     }
     $rowSet = $adapter->fetchAll($select, $bind);
     foreach ($rowSet as $row) {
         $rewrite = new Varien_Object($row);
         $rewrite->setIdFieldName($this->getIdFieldName());
         $rewrites[$rewrite->getIdPath()] = $rewrite;
     }
     return $rewrites;
 }
Example #2
0
 public function prepareRewrites($storeId, $categoryIds = null, $productIds = null)
 {
     $rewrites = array();
     $select = $this->_getWriteAdapter()->select()->from($this->getMainTable())->where('store_id=?', $storeId)->where('is_system=?', 1);
     if (is_null($categoryIds)) {
         $select->where('category_id IS NULL');
     } elseif ($categoryIds) {
         $select->where('category_id IN(?)', $categoryIds);
     }
     if (is_null($productIds)) {
         $select->where('product_id IS NULL');
     } elseif ($productIds) {
         $select->where('product_id IN(?)', $productIds);
     }
     $query = $this->_getWriteAdapter()->query((string) $select);
     while ($row = $query->fetch()) {
         $rewrite = new Varien_Object($row);
         $rewrite->setIdFieldName($this->getIdFieldName());
         $rewrites[$rewrite->getIdPath()] = $rewrite;
     }
     unset($query);
     return $rewrites;
 }