最終更新: daidaibousi 2012年10月23日(火) 16:46:05履歴
- LC_Page_Products_List#action?
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'] = 'alldtl.del_flg = 0 AND alldtl.status = 1 '; 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']; } $searchCondition['where_for_count'] = $searchCondition['where']; // 在庫無し商品の非表示 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))'; $searchCondition['where_for_count'] .= ' AND EXISTS(SELECT * FROM dtb_products_class WHERE product_id = alldtl.product_id AND del_flg = 0 AND (stock >= 1 OR stock_unlimited = 1))'; } return $searchCondition; }
- SC_Helper_DB#sfGetCatWhere?
このページへのコメント
InWyFW I really liked your blog post. Much obliged.