';
return $output;
}
function createGiftCart($pdo, $orderID){
$giftcard_ID = giftcard_id;
//Check if Giftcard is ordered
$stmt = $pdo->prepare('SELECT t.payer_email as email, ti.id as id, ti.txn_id as txn, ti.item_price as item_price, ti.item_quantity as item_quantity FROM transactions t INNER JOIN transactions_items ti ON t.id = ti.txn_id INNER JOIN products_categories p ON ti.item_id = p.product_id WHERE p.category_id = ? AND t.txn_id = ?');
$stmt->execute([$giftcard_ID,$orderID]);
$giftcards = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($giftcards) {
foreach ($giftcards as $giftcard) {
//For each quantity
$x = 0;
while ($x < $giftcard['item_quantity']){
//Generate discount code = TXN/ID/X
$discount_code = $giftcard['txn'].'#'.$giftcard['id'].'#'.$x;
$value = $giftcard['item_price'];
// Get the current date
$start_date = date("Y-m-d H:i:s");
$end_date = date("Y-m-d H:i:s", strtotime("+5 years"));;
//Check if Giftcard already exists
$stmt = $pdo->prepare('SELECT * from discounts WHERE discount_code = ?');
$stmt->execute([$discount_code]);
$discount_exist = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($discount_exist) || $discount_exist == '') {
//Insert Giftcard
//SQL Insert
$stmt = $pdo->prepare('INSERT INTO discounts (discount_code,discount_type,discount_value,start_date,end_date) VALUES (?,?,?,?,?)');
$stmt->execute([$discount_code, 'Fixed', $value, $start_date, $end_date]);
}
$x++;
}
}
}
}
function useGiftCart($pdo, $giftcard){
$discount_code = $giftcard;
// Get the current date
$end_date = date("Y-m-d H:i:s");
//Check if Giftcard already exists
$stmt = $pdo->prepare('SELECT * from discounts WHERE discount_code = ?');
$stmt->execute([$discount_code]);
$discount_exist = $stmt->fetchAll(PDO::FETCH_ASSOC);
//Dump parameters
//$stmt->debugDumpParams();
if (!empty($discount_exist) || $discount_exist != '') {
//Update Giftcard end data
$stmt = $pdo->prepare('UPDATE discounts SET end_date = ? WHERE discount_code = ?');
$stmt->execute([$end_date,$discount_code]);
}
}
function removeGiftCart($pdo, $orderID){
$discount_code = $orderID.'#%#%';
//Check if Giftcard already exists
$stmt = $pdo->prepare('SELECT * from discounts WHERE discount_code like ?');
$stmt->execute([$discount_code]);
$discount_exist = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (!empty($discount_exist) || $discount_exist != '') {
//Remove all Giftcards related to order
$stmt = $pdo->prepare('DELETE FROM discounts WHERE discount_code like ?');
$stmt->execute([$discount_code]);
}
}
function generateInvoice($invoice,$orderID){
//Variables
$customer_email = htmlspecialchars($invoice['customer']['email'] ?? '', ENT_QUOTES);
//Generate invoice
ob_start();
include dirname(__FILE__).'/custom/email/order-invoice-template.php';
$order_invoice_template = ob_get_clean();
return array($order_invoice_template,$customer_email,$orderId);
}
function freeShipment($price, $type){
include './custom/translations/translations_'.strtoupper($_SESSION['country_code']).'.php';
//Free delivery indicator
$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;"';
$shipment = '
<'.$type.' class="delivery">
'.$delivery_status.'
'.$type.'>';
return $shipment;
}
function consent()
{
include './custom/translations/translations_'.strtoupper($_SESSION['country_code']).'.php';
$age_consent = '
'.$age_consent_h4.'
'.$age_consent_text.'
';
return $age_consent;
}
function banner()
{
include './custom/translations/translations_'.strtoupper($_SESSION['country_code']).'.php';
$banner = '
'.banner_wow.'
'.banner_text.'
';
return $banner;
}
function maintenanceMode()
{
include './custom/translations/translations_'.strtoupper($_SESSION['country_code']).'.php';
$maintenanceMode = '
'.$maintenanceMode_h4.'
'.$maintenanceMode_text.'
';
return $maintenanceMode;
}
//++++++++++++++++++++++++++++++++++++++++
//HomePage Products
//++++++++++++++++++++++++++++++++++++++++
function getPictureID($pdo,$id,$config){
$stmt = $pdo->prepare('SELECT * FROM products_media where product_id = :product_id ORDER BY position ASC');
$stmt->bindValue(':product_id', $id, PDO::PARAM_INT);
$stmt->execute();
$product_media = $stmt->fetchAll(PDO::FETCH_ASSOC);
//Search for option_id
$option_profile = json_decode($config,true) ?? '';
if (!empty($option_profile) && $option_profile !=''){
foreach ($option_profile as $option){
if ($option['IMG_large_id'] == $product_media[0]['media_id']){
return $option['option_id'];
}
}
}
}
//++++++++++++++++++++++++++++++++++++++++
//HomePage Products
//++++++++++++++++++++++++++++++++++++++++
function highlightedProducts($clientsecret,$categoryID,$range){
include './custom/translations/translations_'.strtoupper($_SESSION['country_code']).'.php';
//GET CATALOG DATA
$products = ioAPIv2('/v2/catalog/category='.$categoryID,'',$clientsecret);
$products = json_decode($products,true);
$view = '
'.$range.'Limited edition
';
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 .= '
';
//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 .= '
';
//GET ALL RELATED ATTRIBUTES
foreach ($config['attributes'] as $attribute){
$option_id = $attribute['attribute_id']; // 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'])
// 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 .= '