Created
August 20, 2012 08:46
-
-
Save nobuhiko/3402401 to your computer and use it in GitHub Desktop.
おすすめ商品にカテゴリーを追加
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* おすすめ商品検索. | |
* | |
* @return array $arrBestProducts 検索結果配列 | |
*/ | |
function lfGetRanking() { | |
$objQuery =& SC_Query_Ex::getSingletonInstance(); | |
$objProduct = new SC_Product_Ex(); | |
// おすすめ商品取得 | |
$col = 'T1.best_id, T1.category_id, T1.rank, T1.product_id, T1.title, T1.comment, T1.create_date, T1.update_date'; | |
$table = 'dtb_best_products as T1 INNER JOIN dtb_products as T2 ON T1.product_id = T2.product_id'; | |
$where = 'T1.del_flg = 0 and T2.status = 1'; | |
$objQuery->setOrder('T1.rank'); | |
$objQuery->setLimit(RECOMMEND_NUM); | |
$arrBestProducts = $objQuery->select($col, $table, $where); | |
$objQuery =& SC_Query_Ex::getSingletonInstance(); | |
if (count($arrBestProducts) > 0) { | |
// 商品一覧を取得 | |
// where条件生成&セット | |
$arrProductId = array(); | |
$where = 'product_id IN ('; | |
foreach ($arrBestProducts as $key => $val) { | |
$arrProductId[] = $val['product_id']; | |
} | |
// 取得 | |
$arrProductList = $objProduct->getListByProductIds($objQuery, $arrProductId); | |
// おすすめ商品情報にマージ | |
foreach (array_keys($arrBestProducts) as $key) { | |
$arrRow =& $arrBestProducts[$key]; | |
if (isset($arrProductList[$arrRow['product_id']])) { | |
$arrRow = array_merge($arrRow, $arrProductList[$arrRow['product_id']]); | |
} else { | |
// 削除済み商品は除外 | |
unset($arrBestProducts[$key]); | |
} | |
} | |
} | |
// 追加 | |
// 各商品ごとのカテゴリIDを取得 | |
if (count($arrBestProducts) > 0) { | |
foreach ($arrBestProducts as $key => $val) { | |
$arrBestProducts[$key]['categories'] = SC_Helper_DB_Ex::sfGetCategoryId($val['product_id'], 0, true); | |
} | |
} | |
// ここまで | |
return $arrBestProducts; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment