CMXX - API based checkout
This commit is contained in:
539
product.php
539
product.php
@@ -1,115 +1,75 @@
|
||||
<?php
|
||||
// Prevent direct access to file
|
||||
defined(security_key) or exit;
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++
|
||||
// TODO
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++
|
||||
/*
|
||||
|
||||
3. product notifier when out of stock
|
||||
|
||||
*/
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++
|
||||
// END TODO
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
|
||||
// Check to make sure the id parameter is specified in the URL
|
||||
if (isset($_GET['id'])) {
|
||||
// Prepare statement and execute, prevents SQL injection
|
||||
$stmt = $pdo->prepare('SELECT * FROM products WHERE status = 1 AND (id = ? OR url_slug = ?)');
|
||||
$stmt->execute([ $_GET['id'], $_GET['id'] ]);
|
||||
// Fetch the product from the database and return the result as an Array
|
||||
$product = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
//GET CATALOG DATA
|
||||
$product = ioAPIv2('/v2/catalog/product_id='.$_GET['id'],'',$clientsecret);
|
||||
$product = json_decode($product,true);
|
||||
$product = $product[0] ?? '';
|
||||
|
||||
// Check if the product exists (array is not empty)
|
||||
if (!$product) {
|
||||
// Output simple error if the id for the product doesn't exists (array is empty)
|
||||
http_response_code(404);
|
||||
exit('Product does not exist!');
|
||||
}
|
||||
// Select the product images (if any) from the products_images table
|
||||
$stmt = $pdo->prepare('SELECT m.*, pm.position FROM products_media pm JOIN media m ON m.id = pm.media_id WHERE pm.product_id = ? ORDER BY pm.position ASC');
|
||||
$stmt->execute([ $product['id'] ]);
|
||||
// Fetch the product images from the database and return the result as an Array
|
||||
$product_media = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
// Select the product options (if any) from the products_options table
|
||||
$stmt = $pdo->prepare('SELECT CONCAT(title, "::", type, "::", required) AS k, name, quantity, price, price_modifier, weight, weight_modifier, type, id, required FROM products_options WHERE product_id = ? ORDER BY position ASC');
|
||||
$stmt->execute([ $product['id'] ]);
|
||||
// Fetch the product options from the database and return the result as an Array
|
||||
$product_options = $stmt->fetchAll(PDO::FETCH_GROUP);
|
||||
|
||||
// Add the HTML meta data (for SEO purposes)
|
||||
$meta = '
|
||||
<meta property="og:url" content="' . url('index.php?page=product&id=' . ($product['url_slug'] ? $product['url_slug'] : $product['id'])) . '">
|
||||
<meta property="og:title" content="' . $product['name'] . '">
|
||||
<meta property="og:url" content="' . url('index.php?page=product&id=' . ($product['url_slug'] ? $product['url_slug'] : $product['rowID'])) . '">
|
||||
<meta property="og:title" content="' . (${$product['productname']} ?? $product['productname']) . '">
|
||||
';
|
||||
if (isset($product_media[0]) && file_exists($product_media[0]['full_path'])) {
|
||||
$meta .= '<meta property="og:image" content="' . base_url . $product_media[0]['full_path'] . '">';
|
||||
if (isset($product['full_path'])) {
|
||||
$meta .= '<meta property="og:image" content="'.$img_url.$product['full_path'].'">';
|
||||
}
|
||||
|
||||
//GET RELATED MEDIA
|
||||
$product_media = ioAPIv2('/v2/products_media/product_id='.$product['rowID'],'',$clientsecret);
|
||||
$product_media = json_decode($product_media,true);
|
||||
|
||||
// If the user clicked the add to cart button
|
||||
if (isset($_POST['quantity']) && is_numeric($_POST['quantity'])) {
|
||||
// abs() function will prevent minus quantity and (int) will ensure the value is an integer (number)
|
||||
$quantity = abs((int)$_POST['quantity']);
|
||||
// Get product options
|
||||
$options = '';
|
||||
$options_price = (float)$product['price'];
|
||||
$options_weight = (float)$product['weight'];
|
||||
// Iterate post data
|
||||
foreach ($_POST as $k => $v) {
|
||||
if (strpos($k, 'option-') !== false) {
|
||||
if (is_array($v)) {
|
||||
// Option is checkbox or radio element
|
||||
foreach ($v as $vv) {
|
||||
if (empty($vv)) continue;
|
||||
$options .= str_replace(['_', 'option-'], [' ', ''], $k) . '-' . $vv . ',';
|
||||
$stmt = $pdo->prepare('SELECT * FROM products_options WHERE title = ? AND name = ? AND product_id = ?');
|
||||
$stmt->execute([ str_replace(['_', 'option-'], [' ', ''], $k), $vv, $product['id'] ]);
|
||||
$option = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$options_price = $option['price_modifier'] == 'add' ? $options_price + $option['price'] : $options_price - $option['price'];
|
||||
$options_weight = $option['weight_modifier'] == 'add' ? $options_weight + $option['weight'] : $options_weight - $option['weight'];
|
||||
}
|
||||
} else {
|
||||
if (empty($v)) continue;
|
||||
$options .= str_replace(['_', 'option-'], [' ', ''], $k) . '-' . $v . ',';
|
||||
//------------------
|
||||
//Update name otherwise option is not found
|
||||
//------------------
|
||||
$name_update = '%|^|'.$v;
|
||||
$stmt = $pdo->prepare('SELECT * FROM products_options WHERE title = ? AND name like ? AND product_id = ?');
|
||||
$stmt->execute([ str_replace(['_', 'option-'], [' ', ''], $k), $name_update, $product['id'] ]);
|
||||
//------------------
|
||||
// OLD CODE
|
||||
//------------------
|
||||
//$stmt = $pdo->prepare('SELECT * FROM products_options WHERE title = ? AND name = ? AND product_id = ?');
|
||||
//$stmt->execute([ str_replace(['_', 'option-'], [' ', ''], $k), $v, $product['id'] ]);
|
||||
//------------------
|
||||
$option = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$option) {
|
||||
// Option is text or datetime element
|
||||
$stmt = $pdo->prepare('SELECT * FROM products_options WHERE title = ? AND product_id = ?');
|
||||
$stmt->execute([ str_replace(['_', 'option-'], [' ', ''], $k), $product['id'] ]);
|
||||
$option = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
$options_price = $option['price_modifier'] == 'add' ? $options_price + $option['price'] : $options_price - $option['price'];
|
||||
$options_weight = $option['weight_modifier'] == 'add' ? $options_weight + $option['weight'] : $options_weight - $option['weight'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$options_price = $options_price < 0 ? 0 : $options_price;
|
||||
$options = rtrim($options, ',');
|
||||
if (isset($_POST['product'])) {
|
||||
|
||||
//VALIDATE THE INPUT FOR THE SHOPPING CART
|
||||
$payload = json_encode($_POST['product'], JSON_UNESCAPED_UNICODE);
|
||||
$product_to_cart = ioAPIv2('/v2/shopping_cart/',$payload,$clientsecret);
|
||||
$product_to_cart = json_decode($product_to_cart,true);
|
||||
|
||||
// Check if the product exists (array is not empty)
|
||||
if ($quantity > 0) {
|
||||
if ($product_to_cart['quantity'] > 0) {
|
||||
// Product exists in database, now we can create/update the session variable for the cart
|
||||
if (!isset($_SESSION['cart'])) {
|
||||
// Shopping cart session variable doesnt exist, create it
|
||||
$_SESSION['cart'] = [];
|
||||
}
|
||||
$cart_product = &get_cart_product($product['id'], $options);
|
||||
$cart_product = &get_cart_product($product_to_cart['id'], $product_to_cart['options']);
|
||||
if ($cart_product) {
|
||||
// Product exists in cart, update the quanity
|
||||
$cart_product['quantity'] += $quantity;
|
||||
} else {
|
||||
// Product is not in cart, add it
|
||||
$_SESSION['cart'][] = [
|
||||
'id' => $product['id'],
|
||||
'quantity' => $quantity,
|
||||
'options' => $options,
|
||||
'options_price' => $options_price,
|
||||
'options_weight' => $options_weight,
|
||||
'shipping_price' => 0.00
|
||||
];
|
||||
$_SESSION['cart'][] = $product_to_cart;
|
||||
}
|
||||
}
|
||||
// Prevent form resubmission...
|
||||
header('Location: ' . url('index.php?page=cart'));
|
||||
|
||||
exit;
|
||||
header('Location: ' . url('index.php?page=cart'));
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
@@ -120,16 +80,11 @@ if (isset($_GET['id'])) {
|
||||
exit('Product does not exist!');
|
||||
}
|
||||
|
||||
//get all media
|
||||
$stmt = $pdo->query('SELECT id, full_path, caption FROM media');
|
||||
$stmt->execute();
|
||||
$media2 = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
//LINK to products page:
|
||||
$products_link = url(link_to_collection);
|
||||
$product_link = url('index.php?page=product&id='.($product['url_slug'] ? $product['url_slug'] : $product['id']));
|
||||
$product_link = url('index.php?page=product&id='.($product['url_slug'] ? $product['url_slug'] : $product['rowID']));
|
||||
|
||||
//Notifier - when 1 user ask for product notification
|
||||
/*Notifier - when 1 user ask for product notification
|
||||
$notifier = 0;
|
||||
|
||||
if (isset($_POST["notifier"])){
|
||||
@@ -140,226 +95,242 @@ if (isset($_POST["notifier"])){
|
||||
send_product_notification_email($email, $_POST["product_details"]);
|
||||
$notifier = 1;
|
||||
}
|
||||
//CREATE OPTION_PICTURE ARRAY FOR USE IN OPTION OVERVIEW
|
||||
$option_profile = json_decode($product['product_config']) ?? '';
|
||||
if (!empty($option_profile) && $option_profile !=''){
|
||||
//CREATE OPTION PICTURE ARRAY
|
||||
$option_picture[] = '';
|
||||
foreach ($option_profile as $option){
|
||||
//CHECK FOR RELATED MEDIA
|
||||
foreach ($media2 as $media_item2){
|
||||
if ($media_item2['id'] == $option->IMG_large_id){
|
||||
$option_picture[$option->option_id] = $media_item2['full_path'];
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
$view = '';
|
||||
template_header((${$product['productname']} ?? $product['productname']), $meta);
|
||||
|
||||
if ($error){
|
||||
|
||||
$view .='<p class="content-wrapper error">'.$error.'</p>';
|
||||
|
||||
}
|
||||
?>
|
||||
<?=template_header($product['name'], $meta)?>
|
||||
|
||||
<?php if ($error): ?>
|
||||
|
||||
<p class="content-wrapper error"><?=$error?></p>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
else {
|
||||
$view .='
|
||||
<div class="product content-wrapper">
|
||||
<div class="product-imgs">
|
||||
<?php if (isset($_GET['option_id']) && !empty($_GET['option_id']) && $_GET['option_id'] !='') : ?>
|
||||
<?php
|
||||
$option_profile = json_decode($product['product_config']);
|
||||
foreach ($option_profile as $option){
|
||||
//GET RIGHT PICTURE BASED ON SELECTED OPTION IN OVERVIEW PAGE
|
||||
if ($option->option_id == $_GET['option_id']){
|
||||
$IMG_large_id = $option->IMG_large_id;
|
||||
foreach ($media2 as $media_item2){
|
||||
if ($media_item2['id'] == $IMG_large_id){
|
||||
|
||||
$IMG_large_path = $media_item2['full_path'];
|
||||
echo '
|
||||
<div class="product-img-large">
|
||||
<img src="'.$base_url.$media_item2['full_path'].'" id="'.$product['id'].'" alt="'.$media_item2['caption'].'">
|
||||
</div>';
|
||||
<div class="product-imgs">';
|
||||
if (isset($_GET['option_id']) && !empty($_GET['option_id']) && $_GET['option_id'] !=''){
|
||||
|
||||
$fullPath = null;
|
||||
foreach ($product['configurations'] as $configuration) {
|
||||
if (isset($configuration['attributes'])) {
|
||||
foreach ($configuration['attributes'] as $attribute) {
|
||||
if ($attribute['attribute_id'] == $_GET['option_id']) {
|
||||
$fullPath = $attribute['alternative_media_full_path'] ?? $attribute['full_path'];
|
||||
$altTitle = $attribute['alternative_media_title'] ?? $attribute['title'];
|
||||
$view .='
|
||||
<div class="product-img-large">
|
||||
<img src="'.$img_url.$fullPath.'" id="'.$product['rowID'].'" alt="'.$altTitle.'">
|
||||
</div>';
|
||||
break 2; // Exit all loops once found
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php elseif (isset($product_media[0]) && file_exists($product_media[0]['full_path'])): ?>
|
||||
<div class="product-img-large">
|
||||
<img src="<?=base_url . $product_media[0]['full_path']?>" alt="<?=$product_media[0]['caption']?>">
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="product-small-imgs">
|
||||
<?php
|
||||
}
|
||||
|
||||
} elseif (isset($product['full_path']) && $product['full_path'] != ''){
|
||||
$view .='
|
||||
<div class="product-img-large">
|
||||
<img src="'.$img_url.$product['full_path'].'" id="'.$product['rowID'].'" alt="'.(${$product['productname']} ?? $product['productname']).'">
|
||||
</div>';
|
||||
}
|
||||
$view .='
|
||||
<div class="product-small-imgs">';
|
||||
//Show small images
|
||||
foreach ($product_media as $media){
|
||||
if (isset($_GET['option_id']) && !empty($_GET['option_id']) && $_GET['option_id'] !='' && show_option_images != true){
|
||||
$option_profile = json_decode($product['product_config']);
|
||||
//create array with all option imagesIDs
|
||||
$option_images = [];
|
||||
foreach($option_profile as $option){
|
||||
$option_images[] = $option->IMG_large_id;
|
||||
}
|
||||
if (in_array($media['id'], $option_images)){
|
||||
//Do nothing
|
||||
} else {
|
||||
echo ' <div class="product-img-small '.($media['position']==1?' selected':'').'">
|
||||
<img src="'.base_url.$media['full_path'].'" width="150" height="150" alt="'.$media['caption'].'">
|
||||
</div>';
|
||||
}
|
||||
|
||||
$view .=' <div class="product-img-small '.($media['position']==1?' selected':'').'">
|
||||
<img src="'.$img_url.$media['full_path'].'" width="150" height="150" alt="">
|
||||
</div>';
|
||||
}
|
||||
else {
|
||||
//No Option profile - show all images
|
||||
echo ' <div class="product-img-small '.($media['position']==1?' selected':'').'">
|
||||
<img src="'.base_url.$media['full_path'].'" width="150" height="150" alt="'.$media['caption'].'">
|
||||
</div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
$view .='
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="product-wrapper">
|
||||
|
||||
<div class="breadcrum">
|
||||
<a href="<?=$products_link?>"><?=$breadcrum_products?></a> <p>/ <?=$product['name']?></p>
|
||||
<a href="'.$products_link.'">'.$breadcrum_products.'</a> <p>/ '.(${$product['productname']} ?? $product['productname']).'</p>
|
||||
</div>
|
||||
<h1 class="name"><?=$product['name']?></h1>
|
||||
|
||||
<h1 class="name">'.(${$product['productname']} ?? $product['productname']).'</h1>
|
||||
|
||||
<div class="prices">
|
||||
<span class="price" data-price="<?=$product['price']?>"><?=currency_code?><?=number_format($product['price'],2)?></span>
|
||||
<?php if ($product['rrp'] > 0): ?>
|
||||
<span class="rrp"><?=currency_code?><?=number_format($product['rrp'],2)?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<!-- On Stock indicator -->
|
||||
<div class="stock">
|
||||
<?php //Stock status
|
||||
$stock_status = ($product['quantity'] != 0) ? $product_on_stock : $out_of_stock;
|
||||
$style = ($stock_status == $product_on_stock) ? 'style="color:green;font-weight: bold;"' : 'style="color:gray;font-weight: lighter;"';
|
||||
echo ' <span class="stock_product">
|
||||
<p '.$style.'> '.$stock_status.' </p>
|
||||
</span>';
|
||||
?>
|
||||
</div>
|
||||
<!-- Free shipment indicator -->
|
||||
<?php
|
||||
<span class="price" data-price="'.$product['price'].'">'.currency_code.''.number_format($product['price'],2).'</span>';
|
||||
if ($product['rrp'] > 0){
|
||||
$view .= '<span class="rrp" data-rrp="'.$product['rrp'].'">'.currency_code.''.number_format($product['rrp'],2).'</span>';
|
||||
}
|
||||
$view .='</div>
|
||||
<div class="stock">';
|
||||
//Stock status
|
||||
$stock_status = ($product['quantity'] != 0) ? $product_on_stock : $out_of_stock;
|
||||
$style = ($stock_status == $product_on_stock) ? 'style="color:green;font-weight: bold;"' : 'style="color:gray;font-weight: lighter;"';
|
||||
$view .= '<span class="stock_product">
|
||||
<p '.$style.'> '.$stock_status.' </p>
|
||||
</span>';
|
||||
$view .='</div>';
|
||||
//FREE SHIPMENT INDICATOR
|
||||
if (free_shipment_indicator){
|
||||
freeShipment($product['price'],'div');
|
||||
}
|
||||
|
||||
$view .='<form id="product-form" action="" method="post">';
|
||||
|
||||
//CHECK FOR OPTIONS ASSIGNED
|
||||
if(isset($product['configurations'])){
|
||||
foreach ($product['configurations'] as $configuration) {
|
||||
//CHECK FOR GROUPS
|
||||
if (isset($configuration['type']) && $configuration['type'] == 'product'){
|
||||
|
||||
$view .= '<input id="product" type="hidden" name="product[option][products][]" value="'.$configuration['assignment'].'">';
|
||||
}
|
||||
|
||||
//CHECK FOR GROUPS
|
||||
if (isset($configuration['type']) && $configuration['type'] == 'group'){
|
||||
|
||||
$view .= '<label for="">'.(${$configuration['assignment_name']} ?? $configuration['assignment_name']).'</label>';
|
||||
|
||||
//BASED ON GROUP TYPE CREATE INPUT FORM
|
||||
switch($configuration['group_type']) {
|
||||
case 0: //Radiobutton
|
||||
|
||||
$output ='';
|
||||
|
||||
foreach ($configuration['attributes'] as $attribute){
|
||||
|
||||
if(isset($attribute['full_path']) && $attribute['full_path'] !=''){
|
||||
|
||||
$onclick ='';
|
||||
//ADD updateOption to change pictures when GROUP is IN configuration
|
||||
if(isset($product['config_setting']) && $product['config_setting'] == $configuration['assignment']){
|
||||
|
||||
$IMG_large_id = $img_url.$attribute['alternative_media_full_path']; //URL TO LARGE IMAGE
|
||||
$onclick = 'onclick="updateOption(\''.$product['rowID'].'\',\''.$IMG_large_id.'\')"';
|
||||
}
|
||||
|
||||
$IMG_small_id = $img_url.$attribute['full_path']; //URL TO SMALL IMAGE
|
||||
|
||||
$output .= '
|
||||
<label class="picture_select_label">
|
||||
<input id="'.$attribute['attribute_id'].'" class="option radio" value="'.$attribute['attribute_id'].'" name="product[option]['.$configuration['assignment'].'][]" type="radio" data-price="'.($attribute['price'] ?? 0).'" data-rrp="'.($attribute['rrp'] ?? 0).'" data-modifier="'.($attribute['price_modifier'] ?? '').'" '.(($configuration['group_mandatory'] == 1 ) ? ' required' : '').'>
|
||||
<span class="picture_select"><img '.$onclick.' src="'.$IMG_small_id.'"></span>
|
||||
</label>';
|
||||
|
||||
} else {
|
||||
$output .= '
|
||||
<label>
|
||||
<input id="'.$attribute['attribute_id'].'>" class="option radio" value="'.$attribute['attribute_id'].'" name="product[option]['.$configuration['assignment'].'][]" type="radio" data-price="'.($attribute['price'] ?? 0).'" data-rrp="'.($attribute['rrp'] ?? 0).'" data-modifier="'.($attribute['price_modifier'] ?? '').'" '.(($configuration['group_mandatory'] == 1 ) ? ' required' : '').'>'.(${$attribute['item_name']} ?? $attribute['item_name']).'
|
||||
</label>';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$view .= '<div class="radio-checkbox">'.$output.'</div>';
|
||||
|
||||
break;
|
||||
case 1: //Checkbox
|
||||
$output ='';
|
||||
|
||||
foreach ($configuration['attributes'] as $attribute){
|
||||
|
||||
if(isset($attribute['full_path']) && $attribute['full_path'] !=''){
|
||||
|
||||
$onclick ='';
|
||||
//ADD updateOption to change pictures when GROUP is IN configuration
|
||||
if(isset($product['config_setting']) && $product['config_setting'] == $configuration['assignment']){
|
||||
|
||||
$IMG_large_id = $img_url.$attribute['alternative_media_full_path']; //URL TO LARGE IMAGE
|
||||
$onclick = 'onclick="updateOption(\''.$product['rowID'].'\',\''.$IMG_large_id.'\')"';
|
||||
}
|
||||
|
||||
$IMG_small_id = $img_url.$attribute['full_path']; //URL TO SMALL IMAGE
|
||||
|
||||
$output .= '
|
||||
<label class="picture_select_label">
|
||||
<input id="'.$attribute['attribute_id'].'>" class="option checkbox" value="'.$attribute['attribute_id'].'" name="product[option]['.$configuration['assignment'].'][]" type="checkbox" data-price="'.($attribute['price'] ?? 0).'" data-rrp="'.($attribute['rrp'] ?? 0).'" data-modifier="'.($attribute['price_modifier'] ?? '').'" '.(($configuration['group_mandatory'] == 1 ) ? ' required' : '').'>
|
||||
<span class="picture_select"><img '.$onclick.' src="'.$IMG_small_id.'"></span>
|
||||
</label>';
|
||||
|
||||
} else {
|
||||
$output .= '
|
||||
<label>
|
||||
<input id="'.$attribute['attribute_id'].'>" class="option checkbox" value="'.$attribute['attribute_id'].'" name="product[option]['.$configuration['assignment'].'][]" type="checkbox" data-price="'.($attribute['price'] ?? 0).'" data-rrp="'.($attribute['rrp'] ?? 0).'" data-modifier="'.($attribute['price_modifier'] ?? '').'" '.(($configuration['group_mandatory'] == 1 ) ? ' required' : '').'>'.(${$attribute['item_name']} ?? $attribute['item_name']).'
|
||||
</label>';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$view .= '<div class="radio-checkbox">'.$output.'</div>';
|
||||
|
||||
break;
|
||||
|
||||
case 2: //Dropdown
|
||||
$output ='
|
||||
<select id="'.$configuration['assignment'].'" class="option select" name="product[option]['.$configuration['assignment'].']" '.(($configuration['group_mandatory'] == 1 ) ? ' required' : '').'>
|
||||
<option value="" selected disabled style="display:none">'.$configuration['assignment_name'].'</option>
|
||||
';
|
||||
|
||||
foreach ($configuration['attributes'] as $attribute){
|
||||
|
||||
if(isset($attribute['full_path']) && $attribute['full_path'] !=''){
|
||||
|
||||
$onclick ='';
|
||||
//ADD updateOption to change pictures when GROUP is IN configuration
|
||||
if(isset($product['config_setting']) && $product['config_setting'] == $configuration['assignment']){
|
||||
|
||||
$IMG_large_id = $img_url.$attribute['alternative_media_full_path']; //URL TO LARGE IMAGE
|
||||
$onclick = 'onclick="updateOption(\''.$product['rowID'].'\',\''.$IMG_large_id.'\')"';
|
||||
}
|
||||
|
||||
$IMG_small_id = $img_url.$attribute['full_path']; //URL TO SMALL IMAGE
|
||||
|
||||
$output .= '
|
||||
<option id="'.$attribute['attribute_id'].'" value="'.$attribute['attribute_id'].'" data-price="'.($attribute['price'] ?? 0).'" data-rrp="'.($attribute['rrp'] ?? 0).'" data-modifier="'.($attribute['price_modifier'] ?? '').'">'.(${$attribute['item_name']} ?? $attribute['item_name']).'</option>';
|
||||
|
||||
|
||||
} else {
|
||||
$output .= '
|
||||
<option id="'.$attribute['attribute_id'].'" value="'.$attribute['attribute_id'].'" data-price="'.($attribute['price'] ?? 0).'" data-rrp="'.($attribute['rrp'] ?? 0).'" data-modifier="'.($attribute['price_modifier'] ?? '').'">'.(${$attribute['item_name']} ?? $attribute['item_name']).'</option>';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$view .= $output.'</select></div>';
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<form id="product-form" action="" method="post">
|
||||
<?php foreach ($product_options as $id => $option): ?>
|
||||
<?php $id = explode('::', $id); ?>
|
||||
<?php if ($id[1] == 'select'): ?>
|
||||
<label for="<?=$id[0]?>"><?=$id[0]?></label>
|
||||
<select id="<?=$id[0]?>" class="option select" name="option-<?=$id[0]?>"<?=$id[2] ? ' required' : ''?>>
|
||||
<option value="" selected disabled style="display:none"><?=$id[0]?></option>
|
||||
<?php foreach ($option as $option_value): ?>
|
||||
<option id="<?=$option_value['id']?>" value="<?=$option_value['name']?>" data-price="<?=$option_value['price']?>" data-modifier="<?=$option_value['price_modifier']?>"<?=$option_value['quantity']==0?' disabled':''?>><?=$option_value['name']?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php elseif ($id[1] == 'radio'): ?>
|
||||
<label for="<?=$id[0]?>"><?=$id[0]?></label>
|
||||
<div class="radio-checkbox">
|
||||
<?php foreach ($option as $n => $option_value): ?>
|
||||
<?php //check if option has picture ID
|
||||
if (str_contains($option_value['name'], '|^|')): ?>
|
||||
<?php $check=explode('|^|', $option_value['name']);?>
|
||||
<?php foreach ($media2 as $media_item):?>
|
||||
<?php if ($media_item['id'] == $check[0]):?>
|
||||
<label class="picture_select_label">
|
||||
<input id="<?=$option_value['id']?>" class="option radio" value="<?=$check[1]?>" name="option-<?=$id[0]?>" type="radio" data-price="<?=$option_value['price']?>" data-modifier="<?=$option_value['price_modifier']?>">
|
||||
<span class="picture_select"><img onclick="updateOption('<?=$product['id']?>','<?=url($option_picture[$option_value['id']])?>')" src="<?=url($media_item['full_path'])?>"></span>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<label>
|
||||
<input id="<?=$option_value['id']?>" class="option radio" value="<?=$option_value['name']?>" name="option-<?=$id[0]?>" type="radio" data-price="<?=$option_value['price']?>" data-modifier="<?=$option_value['price_modifier']?>"<?=$id[2] && $n == 0 ? ' required' : ''?><?=$option_value['quantity']==0?' disabled':''?>><?=$option_value['name']?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php elseif ($id[1] == 'checkbox'): ?>
|
||||
<label for="<?=$id[0]?>"><?=$id[0]?></label>
|
||||
<div class="radio-checkbox">
|
||||
<?php foreach ($option as $n => $option_value): ?>
|
||||
|
||||
<?php //check if option has picture ID
|
||||
if (str_contains($option_value['name'], '|^|')): ?>
|
||||
<?php $check=explode('|^|', $option_value['name']);?>
|
||||
<?php foreach ($media2 as $media_item):?>
|
||||
<?php if ($media_item['id'] == $check[0]):?>
|
||||
<label class="picture_select_label">
|
||||
<input id="<?=$option_value['id']?>" class="option checkbox" id="<?=$option_value['id']?>" value="<?=$check[1]?>" name="option-<?=$id[0]?>[]" type="checkbox" data-price="<?=$option_value['price']?>" data-modifier="<?=$option_value['price_modifier']?>"<?=$id[2] && $n == 0 ? ' required' : ''?><?=$option_value['quantity']==0?' disabled':''?>>
|
||||
<span class="picture_select"><img src="<?=$media_item['full_path']?>"></span>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<label>
|
||||
<input id="<?=$option_value['id']?>" class="option checkbox" id="<?=$option_value['id']?>" value="<?=$option_value['name']?>" name="option-<?=$id[0]?>[]" type="checkbox" data-price="<?=$option_value['price']?>" data-modifier="<?=$option_value['price_modifier']?>"<?=$id[2] && $n == 0 ? ' required' : ''?><?=$option_value['quantity']==0?' disabled':''?>><?=$option_value['name']?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php elseif ($id[1] == 'text'): ?>
|
||||
<?php foreach ($option as $option_value): ?>
|
||||
<label for="<?=$id[0]?>"><?=$id[0]?></label>
|
||||
<input id="<?=$id[0]?>" class="option text" name="option-<?=$id[0]?>" type="text" placeholder="<?=$option_value['name']?>" data-price="<?=$option_value['price']?>" data-modifier="<?=$option_value['price_modifier']?>"<?=$id[2] ? ' required' : ''?><?=$option_value['quantity']==0?' disabled':''?>>
|
||||
<?php endforeach; ?>
|
||||
<?php elseif ($id[1] == 'datetime'): ?>
|
||||
<?php foreach ($option as $option_value): ?>
|
||||
<label for="<?=$id[0]?>"><?=$id[0]?></label>
|
||||
<input id="<?=$id[0]?>" class="option datetime" name="option-<?=$id[0]?>" type="datetime-local"<?=$option_value['name'] ? 'value="' . date('Y-m-d\TH:i', strtotime($product['date_added'])) . '" ' : ''?> data-price="<?=$option_value['price']?>" data-modifier="<?=$option_value['price_modifier']?>"<?=$id[2] ? ' required' : ''?><?=$option_value['quantity']==0?' disabled':''?>>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php if ($product['quantity'] == 0): ?>
|
||||
<?php if ((isset($_SESSION['account_loggedin'])) && $notifier == 0) :?>
|
||||
<input type="hidden" value="1" name="notifier">
|
||||
<input type="hidden" value="<?=$product['id'].' - '.$product['name']?>" name="product_details">
|
||||
<input type="submit" value="<?=$out_of_stock_notify?>" class="btn">
|
||||
<?php elseif (link_to_external_product_site != ''): ?>
|
||||
<a href="<?= link_to_external_product_site ?>" style="text-align: center;font-style: italic;" class="btn" target="blank"><?=$out_of_stock_notify_2?></a>
|
||||
<?php else: ?>
|
||||
<label for="quantity"><?=$product_quantity?></label>
|
||||
<input id="quantity" type="number" name="quantity" value="1" min="1"<?php if ($product['quantity'] != -1): ?> max="<?=$product['quantity']?>"<?php endif; ?> placeholder="Quantity" required>
|
||||
<input type="submit" value="<?=$out_of_stock?>" class="btn" disabled>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<label for="quantity"><?=$product_quantity?></label>
|
||||
<input id="quantity" type="number" name="quantity" value="1" min="1"<?php if ($product['quantity'] != -1): ?> max="<?=$product['quantity']?>"<?php endif; ?> placeholder="Quantity" required>
|
||||
<input type="submit" value="<?=$add_to_basket?>" class="btn">
|
||||
<?php endif; ?>
|
||||
}
|
||||
|
||||
$view .='
|
||||
<label for="quantity">'.$product_quantity.'</label>
|
||||
<input id="quantity" type="number" name="product[quantity]" value="1" min="1" placeholder="Quantity" required>
|
||||
<input id="product" type="hidden" name="product[product]" value="'.$product['rowID'].'">
|
||||
<input id="product" type="hidden" name="product[version]" value="'.($product['version_id'] ?? '').'">
|
||||
|
||||
<input type="submit" value="'.$add_to_basket.'" class="btn">
|
||||
</form>
|
||||
|
||||
<div class="description">
|
||||
<?=$product['description']?>
|
||||
'.(${$product['productdescription']} ?? $product['productdescription']).'
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
</div>
|
||||
|
||||
$view .= '
|
||||
<script>
|
||||
//Read urlstring
|
||||
const queryString = window.location.href;
|
||||
const option_id = queryString.substring(queryString.lastIndexOf(\'/\') + 1)
|
||||
|
||||
</div>
|
||||
|
||||
<?php endif; ?>
|
||||
<script>
|
||||
|
||||
//Read urlstring
|
||||
const queryString = window.location.href;
|
||||
const option_id = queryString.substring(queryString.lastIndexOf('/') + 1)
|
||||
|
||||
console.log(queryString)
|
||||
//Check for option_id
|
||||
if (option_id != ''){
|
||||
document.getElementById(option_id).checked = true;
|
||||
//Check for option_id
|
||||
if (option_id != \'\'){
|
||||
document.getElementById(option_id).checked = true;
|
||||
}
|
||||
</script>';
|
||||
}
|
||||
|
||||
//OUTPUT
|
||||
echo $view;
|
||||
|
||||
</script>
|
||||
template_footer();
|
||||
|
||||
<?=template_footer()?>
|
||||
?>
|
||||
Reference in New Issue
Block a user