예제 #1
0
    /**
     * カテゴリ数の登録を行う.
     *
     *
     * @param  SC_Query $objQuery           SC_Query インスタンス
     * @param  boolean  $is_force_all_count 全カテゴリの集計を強制する場合 true
     * @return void
     */
    public function sfCountCategory($objQuery = NULL, $is_force_all_count = false)
    {
        $objProduct = new SC_Product_Ex();
        if ($objQuery == NULL) {
            $objQuery =& SC_Query_Ex::getSingletonInstance();
        }
        $is_out_trans = false;
        if (!$objQuery->inTransaction()) {
            $objQuery->begin();
            $is_out_trans = true;
        }
        //共通のfrom/where文の構築
        $sql_where = SC_Product_Ex::getProductDispConditions('alldtl');
        // 在庫無し商品の非表示
        if (NOSTOCK_HIDDEN) {
            $where_products_class = '(stock >= 1 OR stock_unlimited = 1)';
            $from = $objProduct->alldtlSQL($where_products_class);
        } else {
            $from = 'dtb_products as alldtl';
        }
        //dtb_category_countの構成
        // 各カテゴリに所属する商品の数を集計。集計対象には子カテゴリを含まない。
        //まずテーブル内容の元を取得
        if (!$is_force_all_count) {
            $arrCategoryCountOld = $objQuery->select('category_id,product_count', 'dtb_category_count');
        } else {
            $arrCategoryCountOld = array();
        }
        //各カテゴリ内の商品数を数えて取得
        $sql = <<<__EOS__
            SELECT T1.category_id, count(T2.category_id) as product_count
            FROM dtb_category AS T1
                LEFT JOIN dtb_product_categories AS T2
                    ON T1.category_id = T2.category_id
                LEFT JOIN {$from}
                    ON T2.product_id = alldtl.product_id
            WHERE {$sql_where}
            GROUP BY T1.category_id, T2.category_id
__EOS__;
        $arrCategoryCountNew = $objQuery->getAll($sql);
        // 各カテゴリに所属する商品の数を集計。集計対象には子カテゴリを「含む」。
        //差分を取得して、更新対象カテゴリだけを確認する。
        //各カテゴリ毎のデータ値において以前との差を見る
        //古いデータの構造入れ替え
        $arrOld = array();
        foreach ($arrCategoryCountOld as $item) {
            $arrOld[$item['category_id']] = $item['product_count'];
        }
        //新しいデータの構造入れ替え
        $arrNew = array();
        foreach ($arrCategoryCountNew as $item) {
            $arrNew[$item['category_id']] = $item['product_count'];
        }
        unset($arrCategoryCountOld);
        unset($arrCategoryCountNew);
        $arrDiffCategory_id = array();
        //新しいカテゴリ一覧から見て商品数が異なるデータが無いか確認
        foreach ($arrNew as $cid => $count) {
            if ($arrOld[$cid] != $count) {
                $arrDiffCategory_id[] = $cid;
            }
        }
        //削除カテゴリを想定して、古いカテゴリ一覧から見て商品数が異なるデータが無いか確認。
        foreach ($arrOld as $cid => $count) {
            if ($arrNew[$cid] != $count && $count > 0) {
                $arrDiffCategory_id[] = $cid;
            }
        }
        //対象IDが無ければ終了
        if (count($arrDiffCategory_id) == 0) {
            if ($is_out_trans) {
                $objQuery->commit();
            }
            return;
        }
        //差分対象カテゴリIDの重複を除去
        $arrDiffCategory_id = array_unique($arrDiffCategory_id);
        //dtb_category_countの更新 差分のあったカテゴリだけ更新する。
        foreach ($arrDiffCategory_id as $cid) {
            $sqlval = array();
            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
            $sqlval['product_count'] = (string) $arrNew[$cid];
            if ($sqlval['product_count'] == '') {
                $sqlval['product_count'] = (string) '0';
            }
            if (isset($arrOld[$cid])) {
                $objQuery->update('dtb_category_count', $sqlval, 'category_id = ?', array($cid));
            } else {
                if ($is_force_all_count) {
                    $ret = $objQuery->update('dtb_category_count', $sqlval, 'category_id = ?', array($cid));
                    if ($ret > 0) {
                        continue;
                    }
                }
                $sqlval['category_id'] = $cid;
                $objQuery->insert('dtb_category_count', $sqlval);
            }
        }
        unset($arrOld);
        unset($arrNew);
        //差分があったIDとその親カテゴリIDのリストを取得する
        $arrTgtCategory_id = array();
        foreach ($arrDiffCategory_id as $parent_category_id) {
            $arrTgtCategory_id[] = $parent_category_id;
            $arrParentID = $this->sfGetParents('dtb_category', 'parent_category_id', 'category_id', $parent_category_id);
            $arrTgtCategory_id = array_unique(array_merge($arrTgtCategory_id, $arrParentID));
        }
        unset($arrDiffCategory_id);
        //dtb_category_total_count 集計処理開始
        //更新対象カテゴリIDだけ集計しなおす。
        $arrUpdateData = array();
        $where_products_class = '';
        if (NOSTOCK_HIDDEN) {
            $where_products_class .= '(stock >= 1 OR stock_unlimited = 1)';
        }
        $from = $objProduct->alldtlSQL($where_products_class);
        foreach ($arrTgtCategory_id as $category_id) {
            $arrWhereVal = array();
            list($tmp_where, $arrTmpVal) = $this->sfGetCatWhere($category_id);
            if ($tmp_where != '') {
                $sql_where_product_ids = 'product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')';
                $arrWhereVal = $arrTmpVal;
            } else {
                $sql_where_product_ids = '0<>0';
                // 一致させない
            }
            $where = "({$sql_where}) AND ({$sql_where_product_ids})";
            $arrUpdateData[$category_id] = $objQuery->count($from, $where, $arrWhereVal);
        }
        unset($arrTgtCategory_id);
        // 更新対象だけを更新。
        foreach ($arrUpdateData as $cid => $count) {
            $sqlval = array();
            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
            $sqlval['product_count'] = $count;
            if ($sqlval['product_count'] == '') {
                $sqlval['product_count'] = (string) '0';
            }
            $ret = $objQuery->update('dtb_category_total_count', $sqlval, 'category_id = ?', array($cid));
            if (!$ret) {
                $sqlval['category_id'] = $cid;
                $objQuery->insert('dtb_category_total_count', $sqlval);
            }
        }
        // トランザクション終了処理
        if ($is_out_trans) {
            $objQuery->commit();
        }
    }
 /**
  * 全ての商品詳細ページを取得する.
  *
  * @return array 検索エンジンからアクセス可能な商品詳細ページの情報
  */
 public function getAllDetail()
 {
     $objQuery = SC_Query_Ex::getSingletonInstance();
     $sql = 'SELECT product_id, update_date FROM dtb_products WHERE ' . SC_Product_Ex::getProductDispConditions();
     $objQuery->setOrder("product_id");
     $result = $objQuery->getAll($sql);
     $arrRet = array();
     foreach ($result as $row) {
         $arrPage = $row;
         $arrPage['update_date'] = $row['update_date'];
         $arrPage['url'] = HTTP_URL . substr(P_DETAIL_URLPATH, strlen(ROOT_URLPATH)) . $row['product_id'];
         $arrRet[] = $arrPage;
     }
     return $arrRet;
 }
예제 #3
0
 /**
  * 商品名を取得
  *
  * @param  integer $product_id 商品ID
  * @return string  $product_name 商品名
  */
 public function lfGetProductName($product_id)
 {
     $objQuery =& SC_Query_Ex::getSingletonInstance();
     return $objQuery->get('name', 'dtb_products', 'product_id = ? AND ' . SC_Product_Ex::getProductDispConditions(), array($product_id));
 }
예제 #4
0
 /**
  * 検索条件のwhere文とかを取得
  *
  * @return array
  */
 public function lfGetSearchCondition($arrSearchData)
 {
     $searchCondition = array('where' => '', 'arrval' => array(), 'where_category' => '', 'arrvalCategory' => array());
     // カテゴリからのWHERE文字列取得
     if ($arrSearchData['category_id'] != 0) {
         list($searchCondition['where_category'], $searchCondition['arrvalCategory']) = SC_Helper_DB_Ex::sfGetCatWhere($arrSearchData['category_id']);
     }
     // ▼対象商品IDの抽出
     // 商品検索条件の作成(未削除、表示)
     $searchCondition['where'] = SC_Product_Ex::getProductDispConditions('alldtl');
     if (strlen($searchCondition['where_category']) >= 1) {
         $searchCondition['where'] .= ' AND EXISTS (SELECT * FROM dtb_product_categories WHERE ' . $searchCondition['where_category'] . ' AND product_id = alldtl.product_id)';
         $searchCondition['arrval'] = array_merge($searchCondition['arrval'], $searchCondition['arrvalCategory']);
     }
     // 商品名をwhere文に
     $name = $arrSearchData['name'];
     $name = str_replace(',', '', $name);
     // 全角スペースを半角スペースに変換
     $name = str_replace(' ', ' ', $name);
     // スペースでキーワードを分割
     $names = preg_split('/ +/', $name);
     // 分割したキーワードを一つずつwhere文に追加
     foreach ($names as $val) {
         if (strlen($val) > 0) {
             $searchCondition['where'] .= ' AND ( alldtl.name ILIKE ? OR alldtl.comment3 ILIKE ?) ';
             $searchCondition['arrval'][] = "%{$val}%";
             $searchCondition['arrval'][] = "%{$val}%";
         }
     }
     // メーカーらのWHERE文字列取得
     if ($arrSearchData['maker_id']) {
         $searchCondition['where'] .= ' AND alldtl.maker_id = ? ';
         $searchCondition['arrval'][] = $arrSearchData['maker_id'];
     }
     // 在庫無し商品の非表示
     if (NOSTOCK_HIDDEN) {
         $searchCondition['where'] .= ' AND EXISTS(SELECT * FROM dtb_products_class WHERE product_id = alldtl.product_id AND del_flg = 0 AND (stock >= 1 OR stock_unlimited = 1))';
     }
     // XXX 一時期内容が異なっていたことがあるので別要素にも格納している。
     $searchCondition['where_for_count'] = $searchCondition['where'];
     return $searchCondition;
 }
예제 #5
0
 /**
  * 商品情報を取得する(vw_products_allclass使用)
  *
  * @param  SC_Query $objQuery DB操作クラス
  * @return array    $arrProduct 取得結果を配列で返す
  */
 public function lfGetProductsAllclass(&$objQuery)
 {
     // --- 商品一覧の取得
     $objProduct = new SC_Product_Ex();
     $objQuery->setWhere($objProduct->getProductDispConditions());
     $objQuery->setOrder('product_id');
     $arrProductLsit = $objProduct->lists($objQuery);
     // 各商品のカテゴリIDとランクの取得
     $arrProducts = array();
     foreach ($arrProductLsit as $key => $val) {
         $sql = '';
         $sql .= ' SELECT';
         $sql .= '   T1.category_id,';
         $sql .= '   T1.rank AS product_rank,';
         $sql .= '   T2.rank AS category_rank';
         $sql .= ' FROM';
         $sql .= '   dtb_product_categories AS T1';
         $sql .= ' LEFT JOIN';
         $sql .= '   dtb_category AS T2';
         $sql .= ' ON';
         $sql .= '   T1.category_id = T2.category_id';
         $sql .= ' WHERE';
         $sql .= '   product_id = ?';
         $arrCategory = $objQuery->getAll($sql, array($val['product_id']));
         if (!empty($arrCategory)) {
             $arrProducts[$key] = array_merge($val, $arrCategory[0]);
         }
     }
     // 税込金額を設定する
     SC_Product_Ex::setIncTaxToProducts($arrProducts);
     return $arrProducts;
 }