Search Orders For Products: My_Changes 4.x

The following adds a “Product” field to “Orders / Advanced Search” in CS-Cart 4.x. This uses the my_changes addon and is based on Shikhar's blog post (v. 3.x). I'm mainly posting this for my own documentation of my_changes.



[attachment=8665:Screen Shot 2014-11-11 at 11.38.11 AM.png][list=1]

[]Make sure you have the “My Changes” addon installed and activated.

[
]Create app/addons/my_changes/init.php with the following code:

if (!defined('AREA')) { die('Access denied'); }
fn_register_hooks(
'get_orders'

);


[]Create app/addons/my_changes/func.php with the following code:

function fn_my_changes_get_orders($params, $fields, $sortings, $condition, $join, $group)
{
//debugbreak();
if (isset($params['compact']) && $params['compact'] == 'Y') {
$union_condition = ' OR ';
} else {
$union_condition = ' AND ';
}

if (isset($params['o_product_name']) && fn_string_not_empty($params['o_product_name'])) {

// extend join only if not already done
if( empty($params['p_ids']) && empty($params['product_view_id']) ){

$join .= " LEFT JOIN ?:order_details ON ?:order_details.order_id = ?:orders.order_id";
$group .= " GROUP BY ?:orders.order_id ";

}

$condition .= db_quote(" $union_condition ?:order_details.extra LIKE ?l", "%" . trim($params['o_product_name']) . "%");
}

}


[
]Create design/backend/templates/addons/my_changes/hooks/orders/advanced_search.pre.tpl with the following code:








[*]Clear your site cache

[/list]

You will need to create the directory structure for each of these files. Make sure that you set permissions correctly.



-Glen

Screen Shot 2014-11-11 at 11.38.11 AM.png