CMXX - Updated Products page
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -0,0 +1 @@
|
|||||||
|
productold.php
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ $base_url .= '/' . ltrim(substr(str_replace('\\', '/', realpath(__DIR__)), strle
|
|||||||
define('base_url', rtrim($base_url, '/') . '/');
|
define('base_url', rtrim($base_url, '/') . '/');
|
||||||
session_start();
|
session_start();
|
||||||
// Include the configuration file, this contains settings you can change.
|
// 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 and connect to the database using PDO MySQL
|
||||||
include '../functions.php';
|
include '../functions.php';
|
||||||
// Connect to MySQL database
|
// Connect to MySQL database
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
defined('admin') or exit;
|
defined('admin') or exit;
|
||||||
// Configuration file
|
// Configuration file
|
||||||
$file = '../config.php';
|
$file = '../custom/settings/config.php';
|
||||||
// Open the configuration file for reading
|
// Open the configuration file for reading
|
||||||
$contents = file_get_contents($file);
|
$contents = file_get_contents($file);
|
||||||
// Format key function
|
// Format key function
|
||||||
|
|||||||
@@ -1827,3 +1827,47 @@ input.banner_deny:hover {
|
|||||||
#banner hr {
|
#banner hr {
|
||||||
margin: 15px 0;
|
margin: 15px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Main Container */
|
||||||
|
.filtersection {
|
||||||
|
display: flex;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Filter Section */
|
||||||
|
.filter-section {
|
||||||
|
width: 250px;
|
||||||
|
padding: 20px;
|
||||||
|
border-right: 1px solid #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-section h2 {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-group {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-group label {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-group input[type="checkbox"] {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Responsive Design */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.filtersection {
|
||||||
|
flex-direction: column;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-section {
|
||||||
|
width: 100%;
|
||||||
|
border-right: none;
|
||||||
|
border-bottom: 1px solid #e0e0e0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -110,7 +110,7 @@ if (veliti_analytics){
|
|||||||
// Template Header (related to MENU function)
|
// Template Header (related to MENU function)
|
||||||
function template_header_top($title, $head = '') {
|
function template_header_top($title, $head = '') {
|
||||||
|
|
||||||
include './custom/translations/'.strtoupper(language_code).'.php';
|
include './custom/translations/translations_'.strtoupper(language_code).'.php';
|
||||||
// Get the amount of items in the shopping cart, this will be displayed in the header.
|
// Get the amount of items in the shopping cart, this will be displayed in the header.
|
||||||
$num_items_in_cart = isset($_SESSION['cart']) ? array_sum(array_column($_SESSION['cart'], 'quantity')) : 0;
|
$num_items_in_cart = isset($_SESSION['cart']) ? array_sum(array_column($_SESSION['cart'], 'quantity')) : 0;
|
||||||
$home_link = url('index.php');
|
$home_link = url('index.php');
|
||||||
|
|||||||
@@ -156,6 +156,9 @@ define('db_user','morvalwatches');//morvalwatches_prod
|
|||||||
define('db_pass','4~gv71bM6');
|
define('db_pass','4~gv71bM6');
|
||||||
// Database name
|
// Database name
|
||||||
define('db_name','shoppingcart_advanced'); //morvalwatches
|
define('db_name','shoppingcart_advanced'); //morvalwatches
|
||||||
|
// API BASE URL
|
||||||
|
define('api_url','https://dev.veliti.nl/api.php'); //morvalwatches
|
||||||
|
|
||||||
|
|
||||||
/* Payment options */
|
/* Payment options */
|
||||||
//Pay on Delivery
|
//Pay on Delivery
|
||||||
@@ -176,7 +179,7 @@ define('PAYPAL_CLIENT_SECRET','');
|
|||||||
|
|
||||||
/* Admin modes */
|
/* Admin modes */
|
||||||
//debug
|
//debug
|
||||||
define('debug',false);
|
define('debug',true);
|
||||||
// Default maintenance_mode
|
// Default maintenance_mode
|
||||||
define('maintenanceMode',false);
|
define('maintenanceMode',false);
|
||||||
?>
|
?>
|
||||||
@@ -556,10 +556,12 @@ function freeShipment($price, $type){
|
|||||||
$delivery_status = ($price >= free_shipment_price) ? $free_delivery : $non_free_delivery.currency_code.free_shipment_price.',-';
|
$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;"';
|
$style = ($delivery_status == $free_delivery) ? 'style="color:green;font-weight: bold;"' : 'style="color:gray;font-weight: lighter;"';
|
||||||
|
|
||||||
echo '
|
$shipment = '
|
||||||
<'.$type.' class="delivery">
|
<'.$type.' class="delivery">
|
||||||
<p '.$style.'> '.$delivery_status.'</p>
|
<p '.$style.'> '.$delivery_status.'</p>
|
||||||
</'.$type.'>';
|
</'.$type.'>';
|
||||||
|
|
||||||
|
return $shipment;
|
||||||
}
|
}
|
||||||
|
|
||||||
function consent()
|
function consent()
|
||||||
@@ -781,4 +783,72 @@ function debuglog($error){
|
|||||||
$filelocation = './log/log_'.date('m').'.txt';
|
$filelocation = './log/log_'.date('m').'.txt';
|
||||||
error_log($test, 3, $filelocation);
|
error_log($test, 3, $filelocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
18
index.php
18
index.php
@@ -42,8 +42,8 @@ if (isset($_POST['banner_move'])){
|
|||||||
// Define all the routes for all pages
|
// Define all the routes for all pages
|
||||||
$url = routes([
|
$url = routes([
|
||||||
'/' => 'home.php',
|
'/' => 'home.php',
|
||||||
'/about' => '/custom/pages/about.php',
|
'/about' => 'custom/pages/about.php',
|
||||||
'/about_morval' => '/custom/pages/about_morval.php',
|
'/about_morval' => 'custom/pages/about_morval.php',
|
||||||
'/product/{id}' => 'product.php',
|
'/product/{id}' => 'product.php',
|
||||||
'/product/{id}/{option_id}' => 'product.php',
|
'/product/{id}/{option_id}' => 'product.php',
|
||||||
'/products' => 'products.php',
|
'/products' => 'products.php',
|
||||||
@@ -60,14 +60,14 @@ $url = routes([
|
|||||||
'/placeorder/{order_id}' => 'placeorder.php',
|
'/placeorder/{order_id}' => 'placeorder.php',
|
||||||
'/search/{query}' => 'search.php',
|
'/search/{query}' => 'search.php',
|
||||||
'/logout' => 'logout.php',
|
'/logout' => 'logout.php',
|
||||||
'/termsandconditions'=> '/custom/pages/termsandconditions.php',
|
'/termsandconditions'=> 'custom/pages/termsandconditions.php',
|
||||||
'/termsandconditions/{download}'=> '/custom/pages/termsandconditions.php',
|
'/termsandconditions/{download}'=> 'custom/pages/termsandconditions.php',
|
||||||
'/faq'=> '/custom/pages/faq.php',
|
'/faq'=> 'custom/pages/faq.php',
|
||||||
'/privacy'=> '/custom/pages/privacy.php',
|
'/privacy'=> 'custom/pages/privacy.php',
|
||||||
'/privacy/{download}'=> '/custom/pages/privacy.php',
|
'/privacy/{download}'=> 'custom/pages/privacy.php',
|
||||||
'/instructions-for-use' => '/custom/pages/faq.php',
|
'/instructions-for-use' => 'custom/pages/faq.php'
|
||||||
'/test' => 'test.php'
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Check if route exists
|
// Check if route exists
|
||||||
if ($url) {
|
if ($url) {
|
||||||
include $url;
|
include $url;
|
||||||
|
|||||||
452
products.php
452
products.php
@@ -1,254 +1,274 @@
|
|||||||
<?php
|
<?php
|
||||||
// Prevent direct access to file
|
// Prevent direct access to file
|
||||||
defined(security_key) or exit;
|
defined(security_key) or exit;
|
||||||
// Get all the categories from the database
|
//=====================================
|
||||||
$stmt = $pdo->query('SELECT * FROM categories');
|
// MOVE TO INDEX
|
||||||
$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
|
//LOGIN TO API
|
||||||
$category = isset($_GET['category']) ? $_GET['category'] : $main_category;
|
$data = json_encode(array("username" => "paul@veliti.nl", "password" => "test1234"), JSON_UNESCAPED_UNICODE);
|
||||||
$category_sql = '';
|
$responses = ioAPIv2('/v2/authorization', $data,'');
|
||||||
if ($category != $main_category) {
|
//Decode Payload
|
||||||
$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';
|
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = '400';}
|
||||||
}
|
$clientsecret = $responses['token'];
|
||||||
// Get the sort from GET request, will occur if the user changes an item in the select box
|
|
||||||
$default_product_sort = default_product_sort;
|
$img_url = substr(api_url, 0, -8);
|
||||||
$sort = isset($_GET['sort']) ? $_GET['sort'] : $default_product_sort;
|
//=====================================
|
||||||
// The amounts of products to show on each page
|
//end move to index
|
||||||
$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...
|
//Pagination
|
||||||
$current_page = isset($_GET['p']) && is_numeric($_GET['p']) ? (int)$_GET['p'] : 1;
|
$current_page = isset($_GET['p']) && is_numeric($_GET['p']) ? (int)$_GET['p'] : 1;
|
||||||
// Select products ordered by the date added
|
$num_products_on_each_page = 25;
|
||||||
if ($sort == 'sort1') {
|
|
||||||
// sort1 = Alphabetical A-Z
|
//GET Details from URL
|
||||||
$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');
|
$GET_VALUES = urlGETdetails($_GET) ?? '';
|
||||||
} elseif ($sort == 'sort2') {
|
|
||||||
// sort2 = Alphabetical Z-A
|
//Get all the categories from the database
|
||||||
$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');
|
$categories = ioAPIv2('/v2/categories/','',$clientsecret);
|
||||||
} elseif ($sort == 'sort3') {
|
$categories = json_decode($categories,true);
|
||||||
// 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');
|
//IF CATEGORY IS RECEIVED ONLY GET RELATED PRODUCTS
|
||||||
} elseif ($sort == 'sort4') {
|
$url_input = '';
|
||||||
// sort4 = Oldest
|
if(isset($_GET['category'])){
|
||||||
$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');
|
$url_input = 'category='.$_GET['category'];
|
||||||
} 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt->execute();
|
if (isset($_POST['category'])){
|
||||||
$total_products = $stmt->fetchColumn();
|
|
||||||
|
|
||||||
//get all media
|
$filter_input = '';
|
||||||
$stmt = $pdo->query('SELECT id, full_path FROM media');
|
|
||||||
$stmt->execute();
|
|
||||||
$media = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
?>
|
foreach (array_keys($_POST['category']) as $cat_filter){
|
||||||
<?=template_header_top($products_text)?>
|
$filter_input .= $cat_filter.',';
|
||||||
|
|
||||||
<div class="featured" style="background-image:url(<?= base_url.featured_store_image?>);background-position: center center;">
|
|
||||||
<?=template_menu()?>
|
|
||||||
<h2><?=$h1_content_top?></h2>
|
|
||||||
<h2></h2>
|
|
||||||
<p></p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<?php
|
|
||||||
//SHOW OFFER
|
|
||||||
if(show_offer_product_page){
|
|
||||||
|
|
||||||
echo '
|
|
||||||
<div class="" style="text-align: center;">
|
|
||||||
<p class="p.paragraph.neutral-paragraph-text-1" style="font-family:\'gerb\';font-size: 15px;">'.show_offer_product_text.'</p>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
<div class="products content-wrapper">
|
if ($url_input != ''){
|
||||||
<?php
|
$url_input = $url_input.','.substr($filter_input,0, -1);
|
||||||
echo '
|
|
||||||
<div style="margin-top: 30px;display: flex;align-items: center;align-content: center;flex-wrap: nowrap;flex-direction: column;">
|
} 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 = '
|
||||||
|
<div class="featured" style="background-image:url('.base_url.featured_store_image.');background-position: center center;">';
|
||||||
|
|
||||||
|
//Include the menu
|
||||||
|
template_menu();
|
||||||
|
|
||||||
|
$view .=' <h2>'.$h1_content_top.'</h2>
|
||||||
|
<h2></h2>
|
||||||
|
<p></p>
|
||||||
|
</div>';
|
||||||
|
|
||||||
|
//SHOW OFFER
|
||||||
|
if(show_offer_product_page){
|
||||||
|
$view .= '
|
||||||
|
<div class="" style="text-align: center;">
|
||||||
|
<p class="p.paragraph.neutral-paragraph-text-1" style="font-family:\'gerb\';font-size: 15px;">'.show_offer_product_text.'</p>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$view .= '
|
||||||
|
<div class="filtersection">
|
||||||
|
|
||||||
|
<!-- Filter Section -->
|
||||||
|
<div class="filter-section">
|
||||||
|
<form action="" method="post">
|
||||||
|
<h2>'.($products_filters_h2 ?? 'Filter Products').'</h2>';
|
||||||
|
|
||||||
|
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 .= '<div class="filter-group">
|
||||||
|
<label>'.(${$filters['name']} ?? $filters['name']).'</label> ';
|
||||||
|
//Iterate through categories for subfilters
|
||||||
|
foreach ($categories as $subfilter){
|
||||||
|
if ($filters['rowID'] == $subfilter['parent_id'] && $subfilter['status'] == 1 && $subfilter['filter'] == 1){
|
||||||
|
$view .= '<div>
|
||||||
|
<input type="checkbox" id="'.$subfilter['name'].'" name="category['.$subfilter['rowID'].']">
|
||||||
|
<label for="'.$subfilter['name'].'">'.(${$subfilter['name']} ?? $subfilter['name']).'</label>
|
||||||
|
</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$view .= '</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$view .= '<input type="submit" value="'.($btn_filter ?? 'Filter').'" class="btn" >';
|
||||||
|
}
|
||||||
|
$view .= '</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="products content-wrapper"> ';
|
||||||
|
|
||||||
|
//ADD CATEGORIES
|
||||||
|
$view .= ' <div style="margin-top: 30px;display: flex;align-items: center;align-content: center;flex-wrap: nowrap;flex-direction: column;">
|
||||||
<div class="product_category_nav">
|
<div class="product_category_nav">
|
||||||
';
|
';
|
||||||
foreach ($categories as $categorie){
|
foreach ($categories as $categorie){
|
||||||
if ($categorie['parent_id'] == '0' && $categorie['status'] == 1){
|
if ($categorie['parent_id'] == '0' && $categorie['status'] == 1 && $categorie['filter'] != 1){
|
||||||
$weburl = url("index.php?page=products&category=".$categorie['id']."&sort=".$sort."");
|
$weburl = url('index.php?page=test&category='.$categorie['rowID'].'');
|
||||||
echo '<a href="'.$weburl.'">'.$categorie['name'].'</a>';
|
$view .= '<a href="'.$weburl.'">'.$categorie['name'].'</a>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo '
|
$view .= '
|
||||||
</div>';
|
</div>';
|
||||||
if (isset($_GET['category'])){
|
if (isset($_GET['category'])){
|
||||||
echo' <div class="product_category_nav">';
|
$view .= '<div class="product_category_nav">';
|
||||||
|
|
||||||
foreach ($categories as $categorie){
|
foreach ($categories as $categorie){
|
||||||
if ($categorie['parent_id'] == $_GET['category'] && $categorie['status'] == 1){
|
if ($categorie['parent_id'] == $_GET['category'] && $categorie['status'] == 1 && $categorie['filter'] != 1){
|
||||||
$weburl = url("index.php?page=products&category=".$categorie['id']."&sort=".$sort."");
|
$weburl = url('index.php?page=productsnew&category='.$categorie['rowID'].'');
|
||||||
echo '<a href="'.$weburl.'" style="color: #fff;background-color: #555555;font-size: 10px;">'.$categorie['name'].'</a>';
|
$view .= '<a href="'.$weburl.'" style="color: #fff;background-color: #555555;font-size: 10px;">'.$categorie['name'].'</a>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo '</div>';
|
$view .= '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo'
|
$view .= '
|
||||||
</div>';
|
</div>';
|
||||||
?>
|
|
||||||
<div class="products-header">
|
|
||||||
<?=$total_products?> <?=$product_count_1?><?=$total_products!=1? $product_count_2:''?></p>
|
|
||||||
<form action="" method="get" class="products-form">
|
|
||||||
<input type="hidden" name="page" value="products">
|
|
||||||
<label class="category">
|
|
||||||
<?=$main_filter_category?>
|
|
||||||
<select name="category">
|
|
||||||
<option value="<?=$main_category?>"<?=($category == $main_category ? ' selected' : '')?>><?=$main_category?></option>
|
|
||||||
<?=populate_categories($categories, $category)?>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<label class="sortby">
|
|
||||||
<?=$main_filter_sort?>
|
|
||||||
<select name="sort">
|
|
||||||
<option value="sort1"<?=($sort == 'sort1' ? ' selected' : '')?>><?=$sort1?></option>
|
|
||||||
<option value="sort2"<?=($sort == 'sort2' ? ' selected' : '')?>><?=$sort2?></option>
|
|
||||||
<option value="sort3"<?=($sort == 'sort3' ? ' selected' : '')?>><?=$sort3?></option>
|
|
||||||
<option value="sort4"<?=($sort == 'sort4' ? ' selected' : '')?>><?=$sort4?></option>
|
|
||||||
<option value="sort5"<?=($sort == 'sort5' ? ' selected' : '')?>><?=$sort5?></option>
|
|
||||||
<option value="sort6"<?=($sort == 'sort6' ? ' selected' : '')?>><?=$sort6?></option>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="products-wrapper">
|
|
||||||
<?php
|
|
||||||
foreach ($products as $product): ?>
|
|
||||||
<div class="product">
|
|
||||||
<?php
|
|
||||||
if (empty($product['product_config'])){
|
|
||||||
echo '<a href="'.url('index.php?page=product&id=' . ($product['url_slug'] ? ($product['url_slug'] ) : $product['id'])).'" id="'.$product['id'].'A" class="product">';
|
|
||||||
}
|
|
||||||
else{//ADD related optionID when configuration is found
|
|
||||||
$option_id = getPictureID($pdo,$product['id'],$product['product_config']);
|
|
||||||
|
|
||||||
echo '<a href="'.url('index.php?page=product&id=' . ($product['url_slug'] ? ($product['url_slug'].'/'.$option_id ) : $product['id'])).'" id="'.$product['id'].'A" class="product">';
|
$view .= '<div class="products-wrapper">';
|
||||||
}
|
|
||||||
?>
|
|
||||||
<?php if (!empty($product['img']) && file_exists($product['img'])): ?>
|
|
||||||
<?php if (empty($product['product_config'])): ?>
|
|
||||||
<img src="<?=base_url?><?=$product['img']?>" width="" height="250" alt="<?=$product['name']?>">
|
|
||||||
</a>
|
|
||||||
<!-- Show small image below main image in case of not configured -->
|
|
||||||
<div class="" style="display:flex;justify-content: center">
|
|
||||||
<div>
|
|
||||||
<img class="img_config" src="<?=base_url?><?=$product['img']?>"/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php else: ?>
|
foreach ($products as $product){
|
||||||
<img src="<?=base_url?><?=$product['img']?>" id="<?=$product['id']?>" width="" height="250" alt="<?=$product['name']?>">
|
|
||||||
</a>
|
|
||||||
<div class="" style="display:flex;justify-content: center">
|
|
||||||
<?php
|
|
||||||
$option_profile = json_decode($product['product_config']);
|
|
||||||
|
|
||||||
foreach ($option_profile as $option){
|
// Ensure product price is a numeric value
|
||||||
foreach ($media as $media_item){
|
$product_price = isset($product['price']) && $product['price'] > 0 ? floatval($product['price']) : 0.00;
|
||||||
if ($media_item['id'] == $option->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);
|
|
||||||
|
|
||||||
echo'
|
//SHOW LARGE PICTURE
|
||||||
|
$view .= '
|
||||||
|
<div class="product">
|
||||||
|
<a href="'.url('index.php?page=product&rowID=' . ($product['url_slug'] ? ($product['url_slug'] ) : $product['rowID'])).'" id="'.$product['rowID'].'A" class="product">
|
||||||
|
<img src="'.$img_url.$product['full_path'].'" id="'.$product['rowID'].'" width="200" height="" alt="'.$product['productname'].'">
|
||||||
|
</a>';
|
||||||
|
|
||||||
|
//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 .= '<div class="" style="display:flex;justify-content: center">';
|
||||||
|
|
||||||
|
//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 .= '
|
||||||
<div>
|
<div>
|
||||||
<img class="img_config" src="'.url($IMG_small_id).'" id="'.$option->IMG_small_id.'" onclick="update(\''.$product['id'].'\',\''.url($IMG_large_id).'\',\''.url('index.php?page=product&id=' . ($product['url_slug'] ? $product['url_slug'].'/'.$option_id : $product['id'].'/'.$option_id )).'\',\''.$option_price.'\')" />
|
<img class="img_config" src="'.$IMG_small_id.'" id="'.$attribute['item_media'].'" onclick="update(\''.$product['rowID'].'\',\''.$IMG_large_id.'\',\''.url('index.php?page=product&rowID=' . ($product['url_slug'] ? $product['url_slug'].'/'.$option_id : $product['rowID'].'/'.$option_id )).'\',\''.$option_price.'\')" />
|
||||||
|
</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$view .= '</div>';
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//SHOW SMALL IMAGE
|
||||||
|
$view .= '<div class="" style="display:flex;justify-content: center">
|
||||||
|
<div>
|
||||||
|
<img class="img_config" src="'.$img_url.$product['full_path'].'"/>
|
||||||
</div>
|
</div>
|
||||||
';
|
</div>';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
//Stock status
|
||||||
?>
|
$stock_status = (isset($product['quantity']) && $product['quantity'] != 0) ? $product_on_stock : $out_of_stock;
|
||||||
</div>
|
$style = ($stock_status == $product_on_stock) ? 'style="background-color: green;"' : 'style="background-color:gray;font-weight: lighter;"';
|
||||||
<?php endif; ?>
|
|
||||||
<?php endif; ?>
|
$view .= '
|
||||||
<?php
|
|
||||||
//Stock status
|
|
||||||
$stock_status = ($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;"';
|
|
||||||
?>
|
|
||||||
<span class="stock">
|
<span class="stock">
|
||||||
<p <?=$style?>> <?=$stock_status?> </p>
|
<p '.$style.'> '.$stock_status.'</p>
|
||||||
</span>
|
</span>';
|
||||||
<?php
|
|
||||||
if (free_shipment_indicator){
|
if (free_shipment_indicator){
|
||||||
freeShipment($product['price'],'span');
|
$shipment = freeShipment($product_price,'span');
|
||||||
|
$view .= $shipment;
|
||||||
}
|
}
|
||||||
|
$option_id ='';
|
||||||
|
$view .='<a href="'.url('index.php?page=product&rowID=' . ($product['url_slug'] ? $product['url_slug'].$option_id : $product['rowID'])).'" id="'.$product['rowID'].'B" class="product">
|
||||||
|
<span class="name">'.$product['productname'].'</span>';
|
||||||
|
|
||||||
//ADD related optionID when configuration is found
|
if (isset($product_price)){
|
||||||
if (empty($product['product_config'])){
|
|
||||||
$option_id = '';
|
$view .= '<span class="price" id="'.$product['rowID'].'C">'.(($product_price != 0.00) ? currency_code.number_format($product_price,2) : '').'';
|
||||||
}else {
|
|
||||||
$option_id = '/'.getPictureID($pdo,$product['id'],$product['product_config']);
|
if (isset($product['rrp']) && $product['rrp'] > 0){
|
||||||
|
$view .= '<span class="rrp">'.currency_code.number_format($product['rrp'],2).'</span>';
|
||||||
|
}
|
||||||
|
$view .= '</span>';
|
||||||
|
}
|
||||||
|
$view .= '
|
||||||
|
</a>
|
||||||
|
</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$view .= '
|
||||||
|
</div>';
|
||||||
|
|
||||||
|
$view .= '
|
||||||
|
<div class="buttons">';
|
||||||
|
if ($current_page > 1) {
|
||||||
|
$view .= '<a href="'.url('index.php?page=products&p=' . ($current_page-1) . '&category=' . $category . '&sort=' . $sort).'" class="btn">Prev</a>';
|
||||||
|
}
|
||||||
|
if ($total_products > ($current_page * $num_products_on_each_page) - $num_products_on_each_page + count($products)){
|
||||||
|
$view .= '<a href="'.url('index.php?page=products&p=' . ($current_page+1) . '&category=' . $category . '&sort=' . $sort).'" class="btn">Next</a>';
|
||||||
|
}
|
||||||
|
$view .= '</div>
|
||||||
|
</div>
|
||||||
|
</div>';
|
||||||
|
|
||||||
|
$view .= '<script>
|
||||||
|
function update(id_large, IMG_large, option_id, price){
|
||||||
|
let url_id_a = id_large + \'A\';
|
||||||
|
let url_id_b = id_large + \'B\';
|
||||||
|
let url_id_c = id_large + \'C\';
|
||||||
|
|
||||||
|
//change picture
|
||||||
|
document.getElementById(id_large).src = IMG_large;
|
||||||
|
document.getElementById(url_id_a).href = option_id;
|
||||||
|
document.getElementById(url_id_b).href = option_id;
|
||||||
|
document.getElementById(url_id_c).innerHTML = price;
|
||||||
|
document.getElementById(url_id_c).style = price;
|
||||||
}
|
}
|
||||||
?>
|
</script>';
|
||||||
<a href="<?=url('index.php?page=product&id=' . ($product['url_slug'] ? $product['url_slug'].$option_id : $product['id']))?>" id="<?=$product['id']?>B" class="product">
|
|
||||||
<span class="name"><?=$product['name']?></span>
|
|
||||||
<span class="price" id="<?=$product['id']?>C">
|
|
||||||
<?=currency_code?><?=number_format($product['price'],2)?>
|
|
||||||
<?php if ($product['rrp'] > 0): ?>
|
|
||||||
<span class="rrp"><?=currency_code?><?=number_format($product['rrp'],2)?></span>
|
|
||||||
<?php endif; ?>
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="buttons">
|
//OUTPUT
|
||||||
<?php if ($current_page > 1): ?>
|
echo $view;
|
||||||
<a href="<?=url('index.php?page=products&p=' . ($current_page-1) . '&category=' . $category . '&sort=' . $sort)?>" class="btn">Prev</a>
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php if ($total_products > ($current_page * $num_products_on_each_page) - $num_products_on_each_page + count($products)): ?>
|
|
||||||
<a href="<?=url('index.php?page=products&p=' . ($current_page+1) . '&category=' . $category . '&sort=' . $sort)?>" class="btn">Next</a>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
template_footer()
|
||||||
<script>
|
?>
|
||||||
function update(id_large, IMG_large, option_id, price){
|
|
||||||
let url_id_a = id_large + 'A';
|
|
||||||
let url_id_b = id_large + 'B';
|
|
||||||
let url_id_c = id_large + 'C';
|
|
||||||
|
|
||||||
//change picture
|
|
||||||
document.getElementById(id_large).src = IMG_large;
|
|
||||||
document.getElementById(url_id_a).href = option_id;
|
|
||||||
document.getElementById(url_id_b).href = option_id;
|
|
||||||
document.getElementById(url_id_c).innerHTML = price;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<?=template_footer()?>
|
|
||||||
Reference in New Issue
Block a user