diff --git a/.gitignore b/.gitignore index e69de29..45c2d7f 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +productold.php diff --git a/admin/index.php b/admin/index.php index 41c703b..fd9664d 100644 --- a/admin/index.php +++ b/admin/index.php @@ -10,7 +10,7 @@ $base_url .= '/' . ltrim(substr(str_replace('\\', '/', realpath(__DIR__)), strle define('base_url', rtrim($base_url, '/') . '/'); session_start(); // Include the configuration file, this contains settings you can change. -include '../config.php'; +include '../custom/settings/config.php'; // Include functions and connect to the database using PDO MySQL include '../functions.php'; // Connect to MySQL database diff --git a/admin/settings.php b/admin/settings.php index 800ecfc..06d3aee 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -1,7 +1,7 @@ \ No newline at end of file diff --git a/functions.php b/functions.php index 66d8561..b06dd0c 100644 --- a/functions.php +++ b/functions.php @@ -556,10 +556,12 @@ function freeShipment($price, $type){ $delivery_status = ($price >= free_shipment_price) ? $free_delivery : $non_free_delivery.currency_code.free_shipment_price.',-'; $style = ($delivery_status == $free_delivery) ? 'style="color:green;font-weight: bold;"' : 'style="color:gray;font-weight: lighter;"'; - echo ' + $shipment = ' <'.$type.' class="delivery">

'.$delivery_status.'

'; + + return $shipment; } function consent() @@ -781,4 +783,72 @@ function debuglog($error){ $filelocation = './log/log_'.date('m').'.txt'; error_log($test, 3, $filelocation); } -?> \ No newline at end of file + +//------------------------------------------ +// Retrieve all $_GET from URL +//------------------------------------------ +function urlGETdetails($input){ + //GET Details from URL + if(isset($input) && !empty($input)){ + $GET_VALUES = ''; + foreach ($input as $KEY => $VALUE){ + $GET_VALUES .= $KEY.'='.$VALUE; + $GET_VALUES .= '&'; + } + return $GET_VALUES = rtrim($GET_VALUES, "&"); + } + else { + return $GET_VALUES = ''; + } + +} + +//------------------------------------------ +// API TO API version 2 +//------------------------------------------ +function ioAPIv2($api_call, $data, $token){ + + $url = api_url.$api_call; + + $curl = curl_init($url); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + + //SEND BEARER CODE WHEN TOKEN PROVIDED + if ($token != ''){ + $headers = array( + "Authorization: Bearer $token", + "Content-Type: application/json", + ); + } else { + $headers = array( + "Content-Type: application/json", + ); + } + + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + + //IF DATA PROVIDED CONSIDER POST + if (!empty($data)){ + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); + } + + $resp = curl_exec($curl); + $http_status = curl_getinfo($curl) ?? '200'; + curl_close($curl); + + //Check If errorcode is returned + if($http_status['http_code'] == '403' || $http_status['http_code'] == '400') {$resp = json_encode('NOK');} + + if (debug){ + $message = date('Y-m-d H:i:s').';'.$api_call; + debuglog($message); + } + + //Response + return $resp; +} + + +?> diff --git a/index.php b/index.php index 72f8598..8aef612 100644 --- a/index.php +++ b/index.php @@ -42,8 +42,8 @@ if (isset($_POST['banner_move'])){ // Define all the routes for all pages $url = routes([ '/' => 'home.php', - '/about' => '/custom/pages/about.php', - '/about_morval' => '/custom/pages/about_morval.php', + '/about' => 'custom/pages/about.php', + '/about_morval' => 'custom/pages/about_morval.php', '/product/{id}' => 'product.php', '/product/{id}/{option_id}' => 'product.php', '/products' => 'products.php', @@ -60,14 +60,14 @@ $url = routes([ '/placeorder/{order_id}' => 'placeorder.php', '/search/{query}' => 'search.php', '/logout' => 'logout.php', - '/termsandconditions'=> '/custom/pages/termsandconditions.php', - '/termsandconditions/{download}'=> '/custom/pages/termsandconditions.php', - '/faq'=> '/custom/pages/faq.php', - '/privacy'=> '/custom/pages/privacy.php', - '/privacy/{download}'=> '/custom/pages/privacy.php', - '/instructions-for-use' => '/custom/pages/faq.php', - '/test' => 'test.php' + '/termsandconditions'=> 'custom/pages/termsandconditions.php', + '/termsandconditions/{download}'=> 'custom/pages/termsandconditions.php', + '/faq'=> 'custom/pages/faq.php', + '/privacy'=> 'custom/pages/privacy.php', + '/privacy/{download}'=> 'custom/pages/privacy.php', + '/instructions-for-use' => 'custom/pages/faq.php' ]); + // Check if route exists if ($url) { include $url; diff --git a/products.php b/products.php index a6840d0..69a01c0 100644 --- a/products.php +++ b/products.php @@ -1,254 +1,274 @@ query('SELECT * FROM categories'); -$stmt->execute(); -$categories = $stmt->fetchAll(PDO::FETCH_ASSOC); -// Get the current category from the GET request, if none exists set the default selected category to: all -$category = isset($_GET['category']) ? $_GET['category'] : $main_category; -$category_sql = ''; -if ($category != $main_category) { - $category_sql = 'JOIN products_categories pc ON pc.category_id = :category_id AND pc.product_id = p.id JOIN categories c ON c.id = pc.category_id'; -} -// Get the sort from GET request, will occur if the user changes an item in the select box -$default_product_sort = default_product_sort; -$sort = isset($_GET['sort']) ? $_GET['sort'] : $default_product_sort; -// The amounts of products to show on each page -$num_products_on_each_page = 25; -// The current page, in the URL this will appear as index.php?page=products&p=1, index.php?page=products&p=2, etc... +//===================================== +// MOVE TO INDEX +//===================================== + +//LOGIN TO API +$data = json_encode(array("username" => "paul@veliti.nl", "password" => "test1234"), JSON_UNESCAPED_UNICODE); +$responses = ioAPIv2('/v2/authorization', $data,''); +//Decode Payload +if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = '400';} +$clientsecret = $responses['token']; + +$img_url = substr(api_url, 0, -8); +//===================================== +//end move to index +//===================================== +//Pagination $current_page = isset($_GET['p']) && is_numeric($_GET['p']) ? (int)$_GET['p'] : 1; -// Select products ordered by the date added -if ($sort == 'sort1') { - // sort1 = Alphabetical A-Z - $stmt = $pdo->prepare('SELECT p.*, (SELECT m.full_path FROM products_media pm JOIN media m ON m.id = pm.media_id WHERE pm.product_id = p.id ORDER BY pm.position ASC LIMIT 1) AS img FROM products p ' . $category_sql . ' WHERE p.status = 1 ORDER BY p.name ASC LIMIT :page,:num_products'); -} elseif ($sort == 'sort2') { - // sort2 = Alphabetical Z-A - $stmt = $pdo->prepare('SELECT p.*, (SELECT m.full_path FROM products_media pm JOIN media m ON m.id = pm.media_id WHERE pm.product_id = p.id ORDER BY pm.position ASC LIMIT 1) AS img FROM products p ' . $category_sql . ' WHERE p.status = 1 ORDER BY p.name DESC LIMIT :page,:num_products'); -} elseif ($sort == 'sort3') { - // sort3 = Newest - $stmt = $pdo->prepare('SELECT p.*, (SELECT m.full_path FROM products_media pm JOIN media m ON m.id = pm.media_id WHERE pm.product_id = p.id ORDER BY pm.position ASC LIMIT 1) AS img FROM products p ' . $category_sql . ' WHERE p.status = 1 ORDER BY p.date_added DESC LIMIT :page,:num_products'); -} elseif ($sort == 'sort4') { - // sort4 = Oldest - $stmt = $pdo->prepare('SELECT p.*, (SELECT m.full_path FROM products_media pm JOIN media m ON m.id = pm.media_id WHERE pm.product_id = p.id ORDER BY pm.position ASC LIMIT 1) AS img FROM products p ' . $category_sql . ' WHERE p.status = 1 ORDER BY p.date_added ASC LIMIT :page,:num_products'); -} elseif ($sort == 'sort5') { - // sort5 = Highest Price - $stmt = $pdo->prepare('SELECT p.*, (SELECT m.full_path FROM products_media pm JOIN media m ON m.id = pm.media_id WHERE pm.product_id = p.id ORDER BY pm.position ASC LIMIT 1) AS img FROM products p ' . $category_sql . ' WHERE p.status = 1 ORDER BY p.price DESC LIMIT :page,:num_products'); -} elseif ($sort == 'sort6') { - // sort6 = Lowest Price - $stmt = $pdo->prepare('SELECT p.*, (SELECT m.full_path FROM products_media pm JOIN media m ON m.id = pm.media_id WHERE pm.product_id = p.id ORDER BY pm.position ASC LIMIT 1) AS img FROM products p ' . $category_sql . ' WHERE p.status = 1 ORDER BY p.price ASC LIMIT :page,:num_products'); -} else { - // No sort was specified, get the products with no sorting - $stmt = $pdo->prepare('SELECT p.*, (SELECT m.full_path FROM products_media pm JOIN media m ON m.id = pm.media_id WHERE pm.product_id = p.id ORDER BY pm.position ASC LIMIT 1) AS img FROM products p ' . $category_sql . ' WHERE p.status = 1 LIMIT :page,:num_products'); -} -// bindValue will allow us to use integer in the SQL statement, we need to use for LIMIT -if ($category != $main_category) { - $stmt->bindValue(':category_id', $category, PDO::PARAM_INT); -} -$stmt->bindValue(':page', ($current_page - 1) * $num_products_on_each_page, PDO::PARAM_INT); -$stmt->bindValue(':num_products', $num_products_on_each_page, PDO::PARAM_INT); -$stmt->execute(); -// Fetch the products from the database and return the result as an Array -$products = $stmt->fetchAll(PDO::FETCH_ASSOC); -// Get the total number of products -$stmt = $pdo->prepare('SELECT COUNT(*) FROM products p ' . $category_sql . ' WHERE p.status = 1'); -if ($category != $main_category) { - $stmt->bindValue(':category_id', $category, PDO::PARAM_INT); +$num_products_on_each_page = 25; + +//GET Details from URL +$GET_VALUES = urlGETdetails($_GET) ?? ''; + +//Get all the categories from the database +$categories = ioAPIv2('/v2/categories/','',$clientsecret); +$categories = json_decode($categories,true); + +//IF CATEGORY IS RECEIVED ONLY GET RELATED PRODUCTS +$url_input = ''; +if(isset($_GET['category'])){ + $url_input = 'category='.$_GET['category']; } -$stmt->execute(); -$total_products = $stmt->fetchColumn(); +if (isset($_POST['category'])){ + + $filter_input = ''; -//get all media -$stmt = $pdo->query('SELECT id, full_path FROM media'); -$stmt->execute(); -$media = $stmt->fetchAll(PDO::FETCH_ASSOC); - -?> - - - - -

'.show_offer_product_text.'

- - '; + foreach (array_keys($_POST['category']) as $cat_filter){ + $filter_input .= $cat_filter.','; } - ?> -
- + + if ($url_input != ''){ + $url_input = $url_input.','.substr($filter_input,0, -1); + + } else { + $url_input = 'category='.substr($filter_input,0, -1); + } +} + +//GET CATALOG DATA +$products = ioAPIv2('/v2/catalog/'.$url_input,'',$clientsecret); +$products = json_decode($products,true); + +//Return QueryTotal from API +$total_products = ioAPIv2('/v2/products/'.$GET_VALUES.'&totals=&salesflag=1&status=1','',$clientsecret); +$total_products = json_decode($total_products,true); + +//INCLUDE THE HEADER +template_header_top($products_text); + +$view = ' + '; + +//SHOW OFFER +if(show_offer_product_page){ +$view .= ' +
+

'.show_offer_product_text.'

+
+ '; +} + + +$view .= ' +
+ + +
+
+

'.($products_filters_h2 ?? 'Filter Products').'

'; + + if (count($categories) > 0){ + //BUILD UP FILTERS BASED ON CATEGORY ASSIGNMENTS + foreach ($categories as $filters){ + + if ($filters['parent_id'] == '0' && $filters['status'] == 1 && $filters['filter'] == 1){ + $view .= '
+ '; + //Iterate through categories for subfilters + foreach ($categories as $subfilter){ + if ($filters['rowID'] == $subfilter['parent_id'] && $subfilter['status'] == 1 && $subfilter['filter'] == 1){ + $view .= '
+ + +
'; + } + } + $view .= '
'; + } + } + $view .= ''; + } +$view .= '
+
+ +
'; + +//ADD CATEGORIES +$view .= '
'; foreach ($categories as $categorie){ - if ($categorie['parent_id'] == '0' && $categorie['status'] == 1){ - $weburl = url("index.php?page=products&category=".$categorie['id']."&sort=".$sort.""); - echo ''.$categorie['name'].''; + if ($categorie['parent_id'] == '0' && $categorie['status'] == 1 && $categorie['filter'] != 1){ + $weburl = url('index.php?page=test&category='.$categorie['rowID'].''); + $view .= ''.$categorie['name'].''; } } - echo ' + $view .= '
'; if (isset($_GET['category'])){ - echo'
'; + $view .= '
'; foreach ($categories as $categorie){ - if ($categorie['parent_id'] == $_GET['category'] && $categorie['status'] == 1){ - $weburl = url("index.php?page=products&category=".$categorie['id']."&sort=".$sort.""); - echo ''.$categorie['name'].''; + if ($categorie['parent_id'] == $_GET['category'] && $categorie['status'] == 1 && $categorie['filter'] != 1){ + $weburl = url('index.php?page=productsnew&category='.$categorie['rowID'].''); + $view .= ''.$categorie['name'].''; } } - echo '
'; + $view .= '
'; } - echo' + $view .= '
'; - ?> -
-

-
- - - -
-
- -
- -
- '; - } - else{//ADD related optionID when configuration is found - $option_id = getPictureID($pdo,$product['id'],$product['product_config']); - echo ''; - } - ?> - - - <?=$product['name']?> - - -
-
- -
-
- - - <?=$product['name']?> - -
- IMG_small_id){ - $IMG_small_id = $media_item['full_path']; - } - if ($media_item['id'] == $option->IMG_large_id){ - $IMG_large_id = $media_item['full_path']; - } - } - $option_id = ($option->option_id != '') ? $option->option_id : ''; - $option_price = $option->option_price ?? 0; - $option_price = currency_code.number_format($product['price']+$option_price,2); + +$view .= '
'; + + foreach ($products as $product){ + + // Ensure product price is a numeric value + $product_price = isset($product['price']) && $product['price'] > 0 ? floatval($product['price']) : 0.00; + + //SHOW LARGE PICTURE + $view .= ' +
+ + '.$product['productname'].' + '; + + //CHECK IF CONFIGURATION SETTING IS FOUND AND NOT EMPTY => USE GROUP TO DISPLAY IMAGES + if (isset($product['configurations']) && isset($product['config_setting']) && $product['config_setting'] != ''){ + + + //GET THE CONFIG_SETTING GROuP AND DISPLAY + foreach ($product['configurations'] as $config){ + + //MATCH ASSIGNMENT WITH CONFIG SETTING + if($config['assignment'] == $product['config_setting']){ + + $view .= '
'; - echo' + //GET ALL RELATED ATTRIBUTES + foreach ($config['attributes'] as $attribute){ + $option_id = $attribute['alternative_media']; // ID of the LARGE IMAGE + $IMG_small_id = $img_url.$attribute['full_path']; //URL TO SMALL IMAGE + $IMG_large_id = $img_url.$attribute['alternative_media_full_path']; //URL TO LARGE IMAGE + + // Ensure attribute price is a numeric value + $attribute_price = isset($attribute['price']) ? floatval($attribute['price']) : 0.00; + + //$option_price = (isset($attribute['price'])) ? (currency_code.((isset($attribute['price_modifier']) && $attribute['price_modifier'] == 1) ? number_format(floatval($product_price+$attribute_price),2) : number_format(($product_price-$attribute_price),2))) : (($product_price != 0.00) ? currency_code.number_format($product_price,2) : ''); + + $option_price = isset($attribute['price']) + // If price modifier is 1, add prices; otherwise, subtract + ? ((isset($attribute['price_modifier']) && $attribute['price_modifier'] == 1) ? currency_code . number_format(floatval($product_price + $attribute_price), 2) : currency_code . number_format(floatval($product_price - $attribute_price), 2)) + // If product price is not zero, format it + : (($product_price != 0.00) ? currency_code . number_format(floatval($product_price), 2) : ''); + + $view .= '
- + +
'; + } + + $view .= '
'; + + } + } + + } else { + //SHOW SMALL IMAGE + $view .= '
+
+
- '; - - } - ?> -
- - - +
'; + } + + //Stock status + $stock_status = (isset($product['quantity']) && $product['quantity'] != 0) ? $product_on_stock : $out_of_stock; + $style = ($stock_status == $product_on_stock) ? 'style="background-color: green;"' : 'style="background-color:gray;font-weight: lighter;"'; + + $view .= ' -

>

-
- '.$stock_status.'

+ '; + if (free_shipment_indicator){ - freeShipment($product['price'],'span'); + $shipment = freeShipment($product_price,'span'); + $view .= $shipment; } - - //ADD related optionID when configuration is found - if (empty($product['product_config'])){ - $option_id = ''; - }else { - $option_id = '/'.getPictureID($pdo,$product['id'],$product['product_config']); + $option_id =''; + $view .=' + '.$product['productname'].''; + + if (isset($product_price)){ + + $view .= ''.(($product_price != 0.00) ? currency_code.number_format($product_price,2) : '').''; + + if (isset($product['rrp']) && $product['rrp'] > 0){ + $view .= ''.currency_code.number_format($product['rrp'],2).''; + } + $view .= ''; + } + $view .= ' + +
'; + } + + $view .= ' +
'; + + $view .= ' +
'; + if ($current_page > 1) { + $view .= 'Prev'; + } + if ($total_products > ($current_page * $num_products_on_each_page) - $num_products_on_each_page + count($products)){ + $view .= 'Next'; + } + $view .= '
+
+
'; + +$view .= ''; -
- 1): ?> - Prev - - ($current_page * $num_products_on_each_page) - $num_products_on_each_page + count($products)): ?> - Next - -
+//OUTPUT +echo $view; -
- - \ No newline at end of file +template_footer() +?> \ No newline at end of file