diff --git a/api/v2/get/catalog.php b/api/v2/get/catalog.php index 98ccdc2..c9d6649 100644 --- a/api/v2/get/catalog.php +++ b/api/v2/get/catalog.php @@ -128,10 +128,15 @@ foreach ($pricelist as $price) { $keys_to_remove = ['status','item_status','group_status','version','config','sn','build','softwareversion','healthindex','salesflag','configurable','updatedby','createdby','updated','created']; removeKeysRecursive($catalog,$keys_to_remove); +//------------------------------------------ +//Catalog processor to split versions as new product +//------------------------------------------ +$messages = processProductCollection($catalog); + //------------------------------------------ //JSON_ENCODE //------------------------------------------ -$messages = json_encode($catalog, JSON_UNESCAPED_UNICODE); +$messages = json_encode($messages, JSON_UNESCAPED_UNICODE); //------------------------------------------ //Send results diff --git a/api/v2/get/categories.php b/api/v2/get/categories.php new file mode 100644 index 0000000..a2438e5 --- /dev/null +++ b/api/v2/get/categories.php @@ -0,0 +1,118 @@ +soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';} + +//default whereclause +$whereclause = ''; + +switch ($permission) { + case '4': + $whereclause = ''; + break; + case '3': + $whereclause = ''; + break; + default: + $condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search; + $whereclause = 'WHERE accounthierarchy like "'.$condition.'"'; + break; +} + +//NEW ARRAY +$criterias = []; +$clause = ''; + +//Check for $_GET variables and build up clause +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] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='list' || $v[0] =='history'|| $v[0] =='success_msg'){ + //do nothing + } + elseif ($v[0] == 'search') { + //build up search + $clause .= ' AND name like :'.$v[0]; + } + else {//create clause + $clause .= ' AND '.$v[0].' = :'.$v[0]; + } + } + if ($whereclause == '' && $clause !=''){ + $whereclause = 'WHERE '.substr($clause, 4); + } else { + $whereclause .= $clause; + } +} +//Define Query +if(isset($criterias['totals']) && $criterias['totals'] ==''){ +//Request for total rows + $sql = 'SELECT count(*) as count FROM categories '.$whereclause.''; +} +else { + //SQL for Paging + $sql = 'SELECT * FROM categories '.$whereclause.' LIMIT :page,:num_products'; +} + +$stmt = $pdo->prepare($sql); + +//Bind to query +if (str_contains($whereclause, ':condition')){ + $stmt->bindValue('condition', $condition, PDO::PARAM_STR); +} + +if (!empty($criterias)){ + foreach ($criterias as $key => $value){ + $key_condition = ':'.$key; + if (str_contains($whereclause, $key_condition)){ + if ($key == 'search'){ + $search_value = '%'.$value.'%'; + $stmt->bindValue($key, $search_value, PDO::PARAM_STR); + } + else { + $stmt->bindValue($key, $value, PDO::PARAM_STR); + } + } + } +} + +//Add paging details +if(isset($criterias['totals']) && $criterias['totals']==''){ + $stmt->execute(); + $messages = $stmt->fetch(); + $messages = $messages[0]; +} +else { + $current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1; + $stmt->bindValue('page', ($current_page - 1) * $page_rows_categories, PDO::PARAM_INT); + $stmt->bindValue('num_products', $page_rows_categories, PDO::PARAM_INT); + + //Excute Query + $stmt->execute(); + //Get results + $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); +} + +//------------------------------------------ +//JSON_ENCODE +//------------------------------------------ +$messages = json_encode($messages, JSON_UNESCAPED_UNICODE); + +//Send results +echo $messages; + +?> \ No newline at end of file diff --git a/api/v2/get/products.php b/api/v2/get/products.php index b66e52e..8813172 100644 --- a/api/v2/get/products.php +++ b/api/v2/get/products.php @@ -46,15 +46,10 @@ if(isset($get_content) && $get_content!=''){ } elseif ($v[0] == 'search') { //build up search - $clause .= ' AND productcode like :'.$v[0]; - } - elseif ($v[0] == 'list' && $v[1] == 'price') { - //Add default selection criteria for LIST - $clause .= ' AND salesflag = 1'; - $clause .= ' AND item_status = 1'; + $clause .= ' AND p.productcode like :'.$v[0]; } else {//create clause - $clause .= ' AND '.$v[0].' = :'.$v[0]; + $clause .= ' AND p.'.$v[0].' = :'.$v[0]; } } if ($whereclause == '' && $clause !=''){ @@ -66,43 +61,43 @@ if(isset($get_content) && $get_content!=''){ //Define Query if(isset($criterias['totals']) && $criterias['totals'] ==''){ //Request for total rows - $sql = 'SELECT count(*) as count FROM products '.$whereclause.''; + $sql = 'SELECT count(*) as count FROM products p '.$whereclause.''; } elseif (isset($criterias['list']) && $criterias['list'] =='') { //SQL for Paging - $sql = 'SELECT * FROM products '.$whereclause.''; + $sql = 'SELECT * FROM products p '.$whereclause.''; } elseif (isset($criterias['list']) && $criterias['list'] =='price'){ //SET SPECIFIC WHERECLAUSE if ($whereclause == ''){ - $whereclause_1 = 'WHERE salesflag = 1'; - $whereclause_2 = 'WHERE item_status = 1'; + $whereclause_1 = 'WHERE p.salesflag = 1'; + $whereclause_2 = 'WHERE pat.item_status = 1'; } else { - $whereclause_1 = $whereclause .' AND salesflag = 1 AND status = 1 '; - $whereclause_2 = $whereclause .' AND item_status = 1'; + $whereclause_1 = $whereclause .' AND p.salesflag = 1 AND p.status = 1 '; + $whereclause_2 = $whereclause .' AND pat.item_status = 1'; } //GET ALL PRODUCTS AND PRODUCT ATTRIBUTES FOR PRICING - $sql = '(SELECT rowID as product_id, productname as product_name FROM products '.$whereclause_1.' ) UNION (SELECT attribute_id as product_id, item_name as product_name FROM `products_attributes_items` '.$whereclause_2.' )'; + $sql = '(SELECT p.rowID as product_id, p.productname as product_name FROM products p '.$whereclause_1.' ) UNION (SELECT pat.attribute_id as product_id, pat.item_name as product_name FROM products_attributes_items pat '.$whereclause_2.' )'; } elseif (isset($criterias['list']) && $criterias['list'] =='config'){ //SET SPECIFIC WHERECLAUSE if ($whereclause == ''){ - $whereclause_1 = 'WHERE salesflag = 1 AND status = 1 AND configurable = 0 '; - $whereclause_2 = 'WHERE group_status = 1'; + $whereclause_1 = 'WHERE p.salesflag = 1 AND p.status = 1 AND p.configurable = 0 '; + $whereclause_2 = 'WHERE pag.group_status = 1'; } else { - $whereclause_1 = $whereclause .' AND salesflag = 1 AND status = 1 AND configurable = 0 '; - $whereclause_2 = $whereclause .' AND group_status = 1'; + $whereclause_1 = $whereclause .' AND p.salesflag = 1 AND p.status = 1 AND p.configurable = 0 '; + $whereclause_2 = $whereclause .' AND pag.group_status = 1'; } //GET ALL PRODUCTS AND PRODUCT ATTRIBUTES FOR PRICING - $sql = '(SELECT rowID as product_id, productname as product_name FROM products '.$whereclause_1.' ) UNION (SELECT group_id as product_id, group_name as product_name FROM `products_attributes_groups` '.$whereclause_2.' )'; + $sql = '(SELECT p.rowID as product_id, p.productname as product_name FROM products p '.$whereclause_1.' ) UNION (SELECT pag.group_id as product_id, pag.group_name as product_name FROM products_attributes_groups pag '.$whereclause_2.' )'; } else { //SQL for Paging - $sql = 'SELECT * FROM products '.$whereclause.' LIMIT :page,:num_products'; + $sql = 'SELECT p.*, m.full_path FROM products p LEFT JOIN media m ON p.product_media = m.rowID '.$whereclause.' LIMIT :page,:num_products'; } $stmt = $pdo->prepare($sql); diff --git a/api/v2/get/products_attributes_items.php b/api/v2/get/products_attributes_items.php index 94ca0e4..9043616 100644 --- a/api/v2/get/products_attributes_items.php +++ b/api/v2/get/products_attributes_items.php @@ -23,7 +23,7 @@ switch ($permission) { break; default: $condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search; - $whereclause = 'WHERE accounthierarchy like "'.$condition.'"'; + $whereclause = 'WHERE pat.accounthierarchy like "'.$condition.'"'; break; } @@ -62,15 +62,15 @@ if(isset($get_content) && $get_content!=''){ //Define Query if(isset($criterias['totals']) && $criterias['totals'] ==''){ //Request for total rows - $sql = 'SELECT count(*) as count FROM products_attributes_items '.$whereclause.''; + $sql = 'SELECT count(*) as count FROM products_attributes_items pat '.$whereclause.''; } elseif ($criterias['media'] && $criterias['media'] =='all'){ //GET ALL MEDIA ITEMS RELATED TO ATTRIBUTES - $sql = 'SELECT pat.*, m.full_path FROM products_attributes_items pat LEFT JOIN media m ON pat.item_media = m.rowID '.$whereclause; + $sql = 'SELECT pat.*, m.full_path, ma.full_path as alternative_media_full_path FROM products_attributes_items pat LEFT JOIN media m ON pat.item_media = m.rowID LEFT JOIN media ma ON pat.alternative_media = ma.rowID '.$whereclause; } elseif ($criterias['list'] && $criterias['list'] =='catalog'){ //GET ALL ATTRIBUTE DATA FOR CATALOG GROUPS,ITEMS,MEDIA - $sql = 'SELECT pag.*, pat.*, m.title, m.full_path FROM products_attributes_groups pag JOIN products_attributes_items pat ON pag.rowID = pat.group_id LEFT JOIN media m ON pat.item_media = m.rowID '.$whereclause; + $sql = 'SELECT pag.*, pat.*, m.title, m.full_path, ma.title as alternative_media_title, ma.full_path as alternative_media_full_path FROM products_attributes_groups pag JOIN products_attributes_items pat ON pag.rowID = pat.group_id LEFT JOIN media m ON pat.item_media = m.rowID LEFT JOIN media ma ON pat.alternative_media = ma.rowID '.$whereclause; } else { //SQL for Paging diff --git a/assets/functions.php b/assets/functions.php index 62ec1e8..58e1215 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -2983,4 +2983,55 @@ function removeKeysRecursive(array &$array, array $keysToRemove): void { } } } +} +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// Catalogprocessor ++++++++++++++ +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ +function processProductCollection($products) { + $processedProducts = []; + + foreach ($products as $key => $product) { + // Check if product has versions + if (isset($product['versions']) && !empty($product['versions'])) { + // Check if there's only one version + $singleVersion = count($product['versions']) === 1; + + // For each version, create a new product entry + foreach ($product['versions'] as $version) { + // Create a copy of the base product + $versionProduct = $product; + + // Remove the versions array + unset($versionProduct['versions']); + + // Add version specific data + $versionProduct['version_id'] = $version['version_id']; + $versionProduct['config_setting'] = $version['config_setting']; + $versionProduct['configurations'] = $version['configurations']; + + // Only modify identifiers if there's more than one version + if (!$singleVersion) { + // Create a unique rowID for the new product + $versionProduct['rowID'] = $versionProduct['rowID'] . '_v' . $version['version_id']; + + // Add version suffix to productcode and url_slug + $versionProduct['productcode'] = $versionProduct['productcode'] . '_v' . $version['version_id']; + if (!empty($versionProduct['url_slug'])) { + $versionProduct['url_slug'] = $versionProduct['url_slug'] . '_v' . $version['version_id']; + } + + // Add version to product name if needed + $versionProduct['productname'] = $versionProduct['productname'] . ' (v' . $version['version_id'] . ')'; + } + + // Add to processed products + $processedProducts[] = $versionProduct; + } + } else { + // If no versions, add product as is + $processedProducts[] = $product; + } + } + + return $processedProducts; } \ No newline at end of file diff --git a/product.php b/product.php index 9b14e3c..3c43581 100644 --- a/product.php +++ b/product.php @@ -63,7 +63,7 @@ $product_software = ioServer($api_url,''); if (!empty($product_software)){$product_software = decode_payload($product_software);}else{$product_software = null;} //CALL TO API FOR Product_configuration -$api_url = '/v2/products_configurations/productrowid='.$_GET['rowID']; +$api_url = '/v2/products_configurations/version_status=1&productrowid='.$_GET['rowID']; $products_configurations = ioServer($api_url,''); //Decode Payload if (!empty($products_configurations)){$products_configurations = json_decode($products_configurations,true);}else{$products_configurations = null;} @@ -142,6 +142,10 @@ $view .= '
'.(${$responses->url_slug} ?? $responses->url_slug).'
+'.(${$responses->quantity} ?? $responses->quantity).'