Created
June 8, 2015 08:47
-
-
Save alpharder/6b4a3d62346033188d1b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff --git a/app/functions/fn.catalog.php b/app/functions/fn.catalog.php | |
index cd7b966..9a85478 100644 | |
--- a/app/functions/fn.catalog.php | |
+++ b/app/functions/fn.catalog.php | |
@@ -5894,7 +5894,12 @@ function fn_get_products($params, $items_per_page = 0, $lang_code = CART_LANGUAG | |
$params = array_merge($default_params, $params); | |
- if ((empty($params['pname']) || $params['pname'] != 'Y') && (empty($params['pshort']) || $params['pshort'] != 'Y') && (empty($params['pfull']) || $params['pfull'] != 'Y') && (empty($params['pkeywords']) || $params['pkeywords'] != 'Y') && !empty($params['q'])) { | |
+ if ((empty($params['pname']) || $params['pname'] != 'Y') | |
+ && (empty($params['pshort']) || $params['pshort'] != 'Y') | |
+ && (empty($params['pfull']) || $params['pfull'] != 'Y') | |
+ && (empty($params['pkeywords']) || $params['pkeywords'] != 'Y') | |
+ && !empty($params['q']) | |
+ ) { | |
$params['pname'] = 'Y'; | |
} | |
@@ -5948,22 +5953,18 @@ function fn_get_products($params, $items_per_page = 0, $lang_code = CART_LANGUAG | |
$params['q'] = trim($params['q']); | |
if ($params['match'] == 'any') { | |
- $pieces = fn_explode(' ', $params['q']); | |
+ $query_pieces = fn_explode(' ', $params['q']); | |
$search_type = ' OR '; | |
} elseif ($params['match'] == 'all') { | |
- $pieces = fn_explode(' ', $params['q']); | |
+ $query_pieces = fn_explode(' ', $params['q']); | |
$search_type = ' AND '; | |
} else { | |
- $pieces = array($params['q']); | |
+ $query_pieces = array($params['q']); | |
$search_type = ''; | |
} | |
- if (!empty($params['pcode_from_q'])) { | |
- $params['pcode'] = $params['q']; | |
- } | |
- | |
- $_condition = array(); | |
- foreach ($pieces as $piece) { | |
+ $search_conditions = array(); | |
+ foreach ($query_pieces as $piece) { | |
if (strlen($piece) == 0) { | |
continue; | |
} | |
@@ -5989,20 +5990,21 @@ function fn_get_products($params, $items_per_page = 0, $lang_code = CART_LANGUAG | |
$params['extend'][] = 'feature_values'; | |
} | |
- if (isset($params['pcode']) && fn_string_not_empty($params['pcode'])) { | |
- $pcode = trim($params['pcode']); | |
+ if (isset($params['pcode_from_q']) && $params['pcode_from_q'] == 'Y') { | |
+ $tmp .= db_quote(" OR inventory.product_code LIKE ?l OR products.product_code LIKE ?l", | |
+ "%{$piece}%", "%{$piece}%" | |
+ ); | |
$fields['combination'] = 'inventory.combination'; | |
- $tmp .= db_quote(" OR inventory.product_code LIKE ?l OR products.product_code LIKE ?l", "%$pcode%", "%$pcode%"); | |
} | |
fn_set_hook('additional_fields_in_search', $params, $fields, $sortings, $condition, $join, $sorting, $group_by, $tmp, $piece, $having); | |
- $_condition[] = '(' . $tmp . ')'; | |
+ $search_conditions[] = '(' . $tmp . ')'; | |
} | |
- $_cond = implode($search_type, $_condition); | |
+ $_cond = implode($search_type, $search_conditions); | |
- if (!empty($_condition)) { | |
+ if (!empty($search_conditions)) { | |
$condition .= ' AND (' . $_cond . ') '; | |
} | |
@@ -6015,7 +6017,7 @@ function fn_get_products($params, $items_per_page = 0, $lang_code = CART_LANGUAG | |
$params['extend'][] = 'description'; | |
} | |
- unset($_condition); | |
+ unset($search_conditions); | |
} | |
// | |
@@ -6036,6 +6038,14 @@ function fn_get_products($params, $items_per_page = 0, $lang_code = CART_LANGUAG | |
$params['pid'] = $pids; | |
} | |
+ if (!empty($params['pcode'])) { | |
+ $pcode = trim($params['pcode']); | |
+ $condition .= db_quote(" AND (inventory.product_code LIKE ?l OR products.product_code LIKE ?l)", | |
+ "%{$pcode}%", "%{$pcode}%" | |
+ ); | |
+ $fields['combination'] = 'inventory.combination'; | |
+ } | |
+ | |
// Feature code | |
if (!empty($params['feature_code'])) { | |
$condition .= db_quote(" AND ?:product_features.feature_code = ?s", $params['feature_code']); | |
@@ -6238,7 +6248,18 @@ function fn_get_products($params, $items_per_page = 0, $lang_code = CART_LANGUAG | |
$condition .= db_quote(' AND products.is_edp = ?s', $params['downloadable']); | |
} | |
- if ((isset($params['amount_to']) && fn_is_numeric($params['amount_to'])) || (isset($params['amount_from']) && fn_is_numeric($params['amount_from'])) || !empty($params['pcode']) || (Registry::get('settings.General.inventory_tracking') == 'Y' && Registry::get('settings.General.show_out_of_stock_products') == 'N' && $params['area'] == 'C')) { | |
+ // Join inventory table | |
+ if ( | |
+ (isset($params['amount_to']) && fn_is_numeric($params['amount_to'])) | |
+ || (isset($params['amount_from']) && fn_is_numeric($params['amount_from'])) | |
+ || !empty($params['pcode']) | |
+ || (isset($params['pcode_from_q']) && $params['pcode_from_q'] == 'Y') | |
+ || ( | |
+ Registry::get('settings.General.inventory_tracking') == 'Y' | |
+ && Registry::get('settings.General.show_out_of_stock_products') == 'N' | |
+ && $params['area'] == 'C' | |
+ ) | |
+ ) { | |
$join .= " LEFT JOIN ?:product_options_inventory as inventory ON inventory.product_id = products.product_id $inventory_join_cond"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment