/**
  * 商品情報を取得する(vw_products_allclass使用)
  *
  * @param SC_Query $objQuery DB操作クラス
  * @return array $arrProduct 取得結果を配列で返す
  */
 function lfGetProductsAllclass(&$objQuery)
 {
     // --- 商品一覧の取得
     $objQuery->setWhere('del_flg = 0 AND status = 1');
     $objQuery->setOrder('product_id');
     $objProduct = new SC_Product_Ex();
     $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;
 }
 /**
  * 商品IDを指定し、商品一覧を取得する
  *
  * SC_Query::setOrder() や SC_Query::setLimitOffset() を設定して, 商品一覧
  * の配列を取得する.
  * FIXME: 呼び出し元で設定した、SC_Query::setWhere() も有効に扱いたい。
  *
  * @param SC_Query $objQuery SC_Query インスタンス
  * @param array $arrProductId 商品ID
  * @return array 商品一覧の配列 (キー: 商品ID)
  */
 function getListByProductIds(&$objQuery, $arrProductId = array())
 {
     if (empty($arrProductId)) {
         return array();
     }
     $where = 'alldtl.product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($arrProductId)) . ')';
     $where .= ' AND alldtl.del_flg = 0';
     $objQuery->setWhere($where, $arrProductId);
     $arrProducts = $this->lists($objQuery);
     // 配列のキーを商品IDに
     $arrTmp = array();
     foreach ($arrProducts as $arrProduct) {
         $arrTmp[$arrProduct['product_id']] = $arrProduct;
     }
     $arrProducts =& $arrTmp;
     unset($arrTmp);
     // SC_Query::setOrder() の指定がない場合、$arrProductId で指定された商品IDの順に配列要素を並び替え
     if (strlen($objQuery->order) === 0) {
         $arrTmp = array();
         foreach ($arrProductId as $product_id) {
             $arrTmp[$product_id] = $arrProducts[$product_id];
         }
         $arrProducts =& $arrTmp;
         unset($arrTmp);
     }
     // 税込金額を設定する
     SC_Product_Ex::setIncTaxToProducts($arrProducts);
     return $arrProducts;
 }
Beispiel #3
0
    /**
     * SC_Query インスタンスに設定された検索条件を使用して商品規格を取得する.
     *
     * @param SC_Query $objQuery SC_Queryインスタンス
     * @param array $params 検索パラメーターの配列
     * @return array 商品規格の配列
     */
    function getProductsClassByQuery(&$objQuery, $params)
    {
        // 末端の規格を取得
        $col = <<<__EOS__
            T1.product_id,
            T1.stock,
            T1.stock_unlimited,
            T1.sale_limit,
            T1.price01,
            T1.price02,
            T1.point_rate,
            T1.product_code,
            T1.product_class_id,
            T1.del_flg,
            T1.product_type_id,
            T1.down_filename,
            T1.down_realfilename,
            T2.class_combination_id,
            T2.parent_class_combination_id,
            T2.classcategory_id,
            T2.level,
            T3.name AS classcategory_name,
            T3.rank,
            T4.name AS class_name,
            T4.class_id
__EOS__;
        $table = <<<__EOS__
                      dtb_products_class T1
            LEFT JOIN dtb_class_combination T2
                   ON T1.class_combination_id = T2.class_combination_id
            LEFT JOIN dtb_classcategory T3
                   ON T2.classcategory_id = T3.classcategory_id
            LEFT JOIN dtb_class T4
                   ON T3.class_id = T4.class_id
__EOS__;
        $objQuery->setOrder('T3.rank DESC');
        // XXX
        $arrRet = $objQuery->select($col, $table, "", $params);
        $levels = array();
        $parents = array();
        foreach ($arrRet as $rows) {
            $levels[] = $rows['level'];
            $parents[] = $rows['parent_class_combination_id'];
        }
        $level = max($levels);
        $parentsClass = array();
        // 階層分の親を取得
        for ($i = 0; $i < $level - 1; $i++) {
            $objQuery =& SC_Query_Ex::getSingletonInstance();
            $objQuery->setWhere('T1.class_combination_id IN (' . implode(', ', array_pad(array(), count($parents), '?')) . ')');
            $col = <<<__EOS__
                T1.class_combination_id,
                T1.classcategory_id,
                T1.parent_class_combination_id,
                T1.level,
                T2.name AS classcategory_name,
                T2.rank,
                T3.name AS class_name,
                T3.class_id
__EOS__;
            $table = <<<__EOS__
                          dtb_class_combination T1
                LEFT JOIN dtb_classcategory T2
                       ON T1.classcategory_id = T2.classcategory_id
                LEFT JOIN dtb_class T3
                       ON T2.class_id = T3.class_id
__EOS__;
            $objQuery->setOrder('T2.rank DESC');
            // XXX
            $arrParents = $objQuery->select($col, $table, "", $parents);
            foreach ($arrParents as $rows) {
                $parents[] = $rows['parent_class_combination_id'];
                foreach ($arrRet as $child) {
                    if ($child['parent_class_combination_id'] == $rows['class_combination_id']) {
                        $rows['product_id'] = $child['product_id'];
                    }
                }
                $tmpParents[] = $rows;
            }
            $parentsClass = array_merge($parentsClass, $tmpParents);
        }
        // 末端から枝を作成
        $tmpClass = array_merge($arrRet, $parentsClass);
        foreach ($tmpClass as $val) {
            $val['class_id' . $val['level']] = $val['class_id'];
            $val['class_name' . $val['level']] = $val['class_name'];
            $val['classcategory_name' . $val['level']] = $val['classcategory_name'];
            $val['classcategory_id' . $val['level']] = $val['classcategory_id'];
            $arrProductsClass[] = $val;
        }
        return $arrProductsClass;
    }