';
}
function getSamples($pdo, $categoryID){
include './custom/translations/translations_'.strtoupper(language_code).'.php';
$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 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 WHERE p.status = 1');
$stmt->bindValue(':category_id', $categoryID, PDO::PARAM_INT);
$stmt->execute();
$additional_products = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo '
'.$h2_cart_samples.'
';
foreach ($additional_products as $additional_product){
if (!empty($additional_product['img']) && file_exists($additional_product['img'])){
//Pricing override for samples
if (sample_pricing_override){
$additional_product['price'] = sample_pricing_override_price; // Price override for free sample! Remove for standard price
}
$url_contents = 'index.php?page=product&id=';
$url_contents .= $additional_product['url_slug'] ? $additional_product['url_slug'] : $additional_product['id'];
$additional_product_url = url($url_contents);
echo'
';
}
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.txn_id = ti.txn_id INNER JOIN products_categories p ON ti.item_id = p.product_id WHERE p.category_id = ? AND ti.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($pdo, $orderID){
// Retrieve order items
$stmt = $pdo->prepare('SELECT ti.*, p.productcode, p.name FROM transactions t JOIN transactions_items ti ON ti.txn_id = t.txn_id LEFT JOIN products p ON p.id = ti.item_id WHERE t.txn_id = ?');
$stmt->execute([ $orderID ]);
$order_items = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Retrieve order details
$stmt = $pdo->prepare('SELECT a.email, a.id AS a_id, a.first_name AS a_first_name, a.last_name AS a_last_name, a.address_street AS a_address_street, a.address_city AS a_address_city, a.address_state AS a_address_state, a.address_zip AS a_address_zip, a.address_country AS a_address_country, t.* FROM transactions t LEFT JOIN transactions_items ti ON ti.txn_id = t.txn_id LEFT JOIN accounts a ON a.id = t.account_id WHERE t.txn_id = ?');
$stmt->execute([ $orderID]);
$order = $stmt->fetch(PDO::FETCH_ASSOC);
// Get tax
$stmt = $pdo->prepare('SELECT * FROM taxes WHERE country = ?');
$stmt->execute([$order['a_address_country']]);
$tax = $stmt->fetch(PDO::FETCH_ASSOC);
$tax_rate = $tax ? $tax['rate'] : 0.00;
//$stmt->debugDumpParams();
//Variables
$customer_email = htmlspecialchars($order['payer_email'] ?? '', ENT_QUOTES);
$address_name = htmlspecialchars($order['first_name'] ?? '', ENT_QUOTES).' '.htmlspecialchars($order['last_name'] ?? '', ENT_QUOTES);
$address_street = htmlspecialchars($order['address_street'] ?? '', ENT_QUOTES);
$address_city = htmlspecialchars($order['address_city'] ?? '', ENT_QUOTES);
$address_state = htmlspecialchars($order['address_state'] ?? '', ENT_QUOTES);
$address_zip = htmlspecialchars($order['address_zip'] ?? '', ENT_QUOTES);
$address_country = htmlspecialchars($order['address_country'] ?? '', ENT_QUOTES);
$order_id = $order['id'];
$products = $order_items;
$shippingtotal = $order['shipping_amount'];
$total = $order['payment_amount'];
$taxtotal = $order['tax_amount'];
$order_created = $order['created'];
//Generate invoice
ob_start();
include dirname(__FILE__).'/custom/order-invoice-template.php';
$order_invoice_template = ob_get_clean();
return array($order_invoice_template,$customer_email,$order_id);
}
function freeShipment($price, $type){
include './custom/translations/translations_'.strtoupper(language_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;"';
echo '
<'.$type.' class="delivery">
'.$delivery_status.'
'.$type.'>';
}
function consent()
{
include './custom/translations/translations_'.strtoupper(language_code).'.php';
$age_consent = '
'.$age_consent_h4.'
'.$age_consent_text.'
';
return $age_consent;
}
function banner()
{
include './custom/translations/translations_'.strtoupper(language_code).'.php';
$banner = '
'.banner_wow.'
'.banner_text.'
';
return $banner;
}
function maintenanceMode()
{
include './custom/translations/translations_'.strtoupper(language_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($pdo,$categoryID,$range){
include './custom/translations/translations_'.strtoupper(language_code).'.php';
$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 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 WHERE p.status = 1');
$stmt->bindValue(':category_id', $categoryID, PDO::PARAM_INT);
$stmt->execute();
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
$view = '