CMXX - Added categories filter for commerce
This commit is contained in:
@@ -10,12 +10,42 @@ defined($security_key) or exit;
|
|||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
$catalog = []; // Main catalog array
|
$catalog = []; // Main catalog array
|
||||||
|
|
||||||
|
//NEW ARRAY
|
||||||
|
$criterias = [];
|
||||||
|
$filter = '';
|
||||||
|
|
||||||
|
//Check for $_GET variables and build $_GET
|
||||||
|
if(isset($get_content) && $get_content!=''){
|
||||||
|
//GET VARIABLES FROM URL
|
||||||
|
$requests = explode("&", $get_content);
|
||||||
|
//Check for keys and values
|
||||||
|
foreach ($requests as $y){
|
||||||
|
$v = explode("=", $y);
|
||||||
|
//INCLUDE VARIABLES IN ARRAY
|
||||||
|
$criterias[$v[0]] = $v[1];
|
||||||
|
|
||||||
|
if ($v[0] == 'category'){
|
||||||
|
//------------------------------------------
|
||||||
|
//IF CATEGORY IS RECEIVED ONLY GET RELATED PRODUCTS
|
||||||
|
//------------------------------------------
|
||||||
|
$url_input = '';
|
||||||
|
//Get all the related products from the database
|
||||||
|
$cat_products = ioAPIv2('/v2/products_categories/list=filter&category_id='.$v[1],'',$clientsecret);
|
||||||
|
$cat_products = json_decode($cat_products,true);
|
||||||
|
|
||||||
|
foreach($cat_products as $cat_product_id){
|
||||||
|
$url_input .= $cat_product_id['product_id'].',';
|
||||||
|
}
|
||||||
|
$filter .= '&product_id='.substr($url_input,0,-1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
//GET ACTIVE AND SALES RELATED PRODUCTS
|
//GET ACTIVE AND SALES RELATED PRODUCTS
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
|
|
||||||
$filter = (isset($get_content) && $get_content !='') ? '&'.$get_content : '';
|
|
||||||
|
|
||||||
//GET PRODUCTS
|
//GET PRODUCTS
|
||||||
$api_url = '/v2/products/salesflag=1&status=1'.$filter;
|
$api_url = '/v2/products/salesflag=1&status=1'.$filter;
|
||||||
$products = ioApi($api_url,'',$clientsecret);
|
$products = ioApi($api_url,'',$clientsecret);
|
||||||
|
|||||||
@@ -48,6 +48,32 @@ if(isset($get_content) && $get_content!=''){
|
|||||||
//build up search
|
//build up search
|
||||||
$clause .= ' AND p.productcode like :'.$v[0];
|
$clause .= ' AND p.productcode like :'.$v[0];
|
||||||
}
|
}
|
||||||
|
elseif ($v[0] == 'product_id') {
|
||||||
|
//build up product_id = rowID
|
||||||
|
//check if multiple product_ids are provided
|
||||||
|
if (str_contains($v[1], ',')){
|
||||||
|
$inputs = explode(",",$v[1]);
|
||||||
|
$new_querystring = ''; //empty querystring
|
||||||
|
$x=0;
|
||||||
|
foreach($inputs as $input){
|
||||||
|
//create key
|
||||||
|
$new_key = $v[0].'_'.$x;
|
||||||
|
//inject new key/value to array
|
||||||
|
$criterias[$new_key] = $input;
|
||||||
|
$new_querystring .= ':'.$new_key.',';
|
||||||
|
$x++;
|
||||||
|
}
|
||||||
|
//remove obsolete last character from new_querystring
|
||||||
|
$new_querystring = substr($new_querystring,0, -1);
|
||||||
|
//add new_querystring to clause
|
||||||
|
$clause .= ' AND p.rowID IN ('.$new_querystring.')';
|
||||||
|
//remove original key/value from array
|
||||||
|
unset($criterias[$v[0]]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$clause .= ' AND p.rowID IN (:'.$v[0].')';
|
||||||
|
}
|
||||||
|
}
|
||||||
else {//create clause
|
else {//create clause
|
||||||
$clause .= ' AND p.'.$v[0].' = :'.$v[0];
|
$clause .= ' AND p.'.$v[0].' = :'.$v[0];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,11 +43,67 @@ if(isset($get_content) && $get_content!=''){
|
|||||||
|
|
||||||
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='list' || $v[0] =='history'|| $v[0] =='success_msg'){
|
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='list' || $v[0] =='history'|| $v[0] =='success_msg'){
|
||||||
//do nothing
|
//do nothing
|
||||||
|
}
|
||||||
|
elseif ($v[0] == 'product_id') {
|
||||||
|
//check if multiple product_ids are provided
|
||||||
|
if (str_contains($v[1], ',')){
|
||||||
|
$inputs = explode(",",$v[1]);
|
||||||
|
$new_querystring = ''; //empty querystring
|
||||||
|
$x=0;
|
||||||
|
foreach($inputs as $input){
|
||||||
|
//create key
|
||||||
|
$new_key = $v[0].'_'.$x;
|
||||||
|
//inject new key/value to array
|
||||||
|
$criterias[$new_key] = $input;
|
||||||
|
$new_querystring .= ':'.$new_key.',';
|
||||||
|
$x++;
|
||||||
|
}
|
||||||
|
//remove obsolete last character from new_querystring
|
||||||
|
$new_querystring = substr($new_querystring,0, -1);
|
||||||
|
//add new_querystring to clause
|
||||||
|
$clause .= ' AND pc.product_id IN ('.$new_querystring.')';
|
||||||
|
//remove original key/value from array
|
||||||
|
unset($criterias[$v[0]]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$clause .= ' AND pc.product_id IN (:'.$v[0].')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif ($v[0] == 'category_id') {
|
||||||
|
//check if multiple category_ids are provided
|
||||||
|
if (str_contains($v[1], ',')){
|
||||||
|
$inputs = explode(",",$v[1]);
|
||||||
|
$new_querystring = ''; //empty querystring
|
||||||
|
$x=0;
|
||||||
|
foreach($inputs as $input){
|
||||||
|
//create key
|
||||||
|
$new_key = $v[0].'_'.$x;
|
||||||
|
//inject new key/value to array
|
||||||
|
$criterias[$new_key] = $input;
|
||||||
|
$new_querystring .= ':'.$new_key.',';
|
||||||
|
$x++;
|
||||||
|
}
|
||||||
|
//remove obsolete last character from new_querystring
|
||||||
|
$new_querystring = substr($new_querystring,0, -1);
|
||||||
|
$categoryCount = count($inputs);
|
||||||
|
//add new_querystring to clause
|
||||||
|
$clause .= ' AND pc.category_id IN ('.$new_querystring.')';
|
||||||
|
//remove original key/value from array
|
||||||
|
unset($criterias[$v[0]]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$clause .= ' AND pc.category_id IN (:'.$v[0].')';
|
||||||
|
$categoryCount = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elseif ($v[0] == 'search') {
|
elseif ($v[0] == 'search') {
|
||||||
//build up search
|
//build up search
|
||||||
$clause .= ' AND c.name like :'.$v[0];
|
$clause .= ' AND c.name like :'.$v[0];
|
||||||
}
|
}
|
||||||
|
elseif ($v[0] == 'filter') {
|
||||||
|
//build up filter
|
||||||
|
$clause .= ' AND c.filter = :'.$v[0];
|
||||||
|
}
|
||||||
else {//create clause
|
else {//create clause
|
||||||
$clause .= ' AND pc.'.$v[0].' = :'.$v[0];
|
$clause .= ' AND pc.'.$v[0].' = :'.$v[0];
|
||||||
}
|
}
|
||||||
@@ -63,9 +119,17 @@ if(isset($criterias['totals']) && $criterias['totals'] ==''){
|
|||||||
//Request for total rows
|
//Request for total rows
|
||||||
$sql = 'SELECT count(*) as count FROM products_categories '.$whereclause.'';
|
$sql = 'SELECT count(*) as count FROM products_categories '.$whereclause.'';
|
||||||
}
|
}
|
||||||
|
elseif(isset($criterias['list']) && $criterias['list'] =='filter'){
|
||||||
|
|
||||||
|
$sql = 'SELECT pc.product_id
|
||||||
|
FROM products_categories pc
|
||||||
|
'.$whereclause.'
|
||||||
|
GROUP BY pc.product_id
|
||||||
|
HAVING COUNT(DISTINCT pc.category_id) = '.$categoryCount;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
//SQL for Paging
|
//SQL for Paging
|
||||||
$sql = 'SELECT c.name, c.rowID FROM products_categories pc JOIN categories c ON c.rowID = pc.category_id '.$whereclause.'';
|
$sql = 'SELECT c.* , pc.product_id FROM products_categories pc JOIN categories c ON c.rowID = pc.category_id '.$whereclause.'';
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
@@ -96,7 +160,7 @@ if(isset($criterias['totals']) && $criterias['totals']==''){
|
|||||||
$messages = $stmt->fetch();
|
$messages = $stmt->fetch();
|
||||||
$messages = $messages[0];
|
$messages = $messages[0];
|
||||||
}
|
}
|
||||||
elseif(isset($criterias['list']) && $criterias['list']==''){
|
elseif(isset($criterias['list']) && $criterias['list']=='filter'){
|
||||||
//Excute Query
|
//Excute Query
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
//Get results
|
//Get results
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ function admin_populate_categories($categories, $parent_id = 0, $n = 0) {
|
|||||||
$html .= '
|
$html .= '
|
||||||
<tr>
|
<tr>
|
||||||
<td><span style="padding-right:8px;color:#bbbec0;border-left:1px solid #bbbec0;padding-bottom:2px;">-' . str_repeat('----', $n) . '</span>' . $category['name'] . '</td>
|
<td><span style="padding-right:8px;color:#bbbec0;border-left:1px solid #bbbec0;padding-bottom:2px;">-' . str_repeat('----', $n) . '</span>' . $category['name'] . '</td>
|
||||||
|
<td>'.(($category['filter'] == 1) ? 'V' : '').'</td>
|
||||||
<td><a href="index.php?page=category&rowID=' . $category['rowID'] . '" class="link1">Edit</a> (ID =' . $category['rowID'] . ') </td>
|
<td><a href="index.php?page=category&rowID=' . $category['rowID'] . '" class="link1">Edit</a> (ID =' . $category['rowID'] . ') </td>
|
||||||
</tr>
|
</tr>
|
||||||
';
|
';
|
||||||
@@ -100,6 +101,7 @@ $view .= '
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td>'.($categories_name ?? 'Name').'</td>
|
<td>'.($categories_name ?? 'Name').'</td>
|
||||||
|
<td>'.($categories_filter ?? 'Filter').'</td>
|
||||||
<td>'.$general_actions.'</td>
|
<td>'.$general_actions.'</td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ define('superuser_profile','dashboard,profile,assets,equipments,equipment,equipm
|
|||||||
/*Admin*/
|
/*Admin*/
|
||||||
define('admin_profile','dashboard,profile,buildtool,sales,accounts,account,contracts,contract,contract_manage,cartests,cartest,cartest_manage,assets,equipments,equipment,equipment_healthindex,equipment_data,equipment_manage,equipment_manage_edit,equipments_mass_update,histories,history,history_manage,firmwaretool,rmas,rma,rma_manage,rma_history,rma_history_manage,buildtool,products,products_versions,products_software,product,product_manage,servicereports,servicereport,admin,partners,partner,users,user,user_manage,communications,communication,communication_send,marketing,reporting,report_build,report_contracts_billing,report_healthindex,changelog,application');
|
define('admin_profile','dashboard,profile,buildtool,sales,accounts,account,contracts,contract,contract_manage,cartests,cartest,cartest_manage,assets,equipments,equipment,equipment_healthindex,equipment_data,equipment_manage,equipment_manage_edit,equipments_mass_update,histories,history,history_manage,firmwaretool,rmas,rma,rma_manage,rma_history,rma_history_manage,buildtool,products,products_versions,products_software,product,product_manage,servicereports,servicereport,admin,partners,partner,users,user,user_manage,communications,communication,communication_send,marketing,reporting,report_build,report_contracts_billing,report_healthindex,changelog,application');
|
||||||
/*AdminPlus*/
|
/*AdminPlus*/
|
||||||
define('adminplus_profile','dashboard,profile,buildtool,sales,accounts,account,contracts,contract,contract_manage,billing,cartests,cartest,cartest_manage,assets,equipments,equipment,equipment_healthindex,equipment_data,equipment_manage,equipment_manage_edit,equipments_mass_update,histories,history,history_manage,firmwaretool,rmas,rma,rma_manage,rma_history,rma_history_manage,buildtool,products,products_versions,products_software,products_attributes,products_attributes_items,products_attributes_manage,products_configurations,product,product_manage,pricelists,pricelists_items,pricelists_manage,catalog,categories,category,servicereports,servicereport,admin,partners,partner,users,user,user_manage,communications,communication,communication_send,marketing,reporting,report_build,report_contracts_billing,report_healthindex,report_usage,config,settings,logfile,changelog,language,translations,translations_details,translation_manage,media,media_manage,application,maintenance,profiles,vin');
|
define('adminplus_profile','dashboard,profile,buildtool,sales,accounts,account,contracts,contract,contract_manage,billing,cartests,cartest,cartest_manage,assets,equipments,equipment,equipment_healthindex,equipment_data,equipment_manage,equipment_manage_edit,equipments_mass_update,histories,history,history_manage,firmwaretool,rmas,rma,rma_manage,rma_history,rma_history_manage,buildtool,products,products_versions,products_software,products_attributes,products_attributes_items,products_attributes_manage,products_configurations,products_categories,product,product_manage,pricelists,pricelists_items,pricelists_manage,catalog,categories,category,servicereports,servicereport,admin,partners,partner,users,user,user_manage,communications,communication,communication_send,marketing,reporting,report_build,report_contracts_billing,report_healthindex,report_usage,config,settings,logfile,changelog,language,translations,translations_details,translation_manage,media,media_manage,application,maintenance,profiles,vin');
|
||||||
/*Build*/
|
/*Build*/
|
||||||
define('build','dashboard,profile,buildtool,firmwaretool,buildtool,products_software,application');
|
define('build','dashboard,profile,buildtool,firmwaretool,buildtool,products_software,application');
|
||||||
/*Distribution*/
|
/*Distribution*/
|
||||||
|
|||||||
Reference in New Issue
Block a user