ÿØÿà JFIF ` ` ÿþxØ
| Server IP : 109.234.164.53 / Your IP : 216.73.216.110 Web Server : Apache System : Linux cervelle.o2switch.net 4.18.0-553.32.1.lve.el8.x86_64 #1 SMP Thu Dec 19 13:14:03 UTC 2024 x86_64 User : computer3 ( 1098) PHP Version : 7.1.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/computer3/fermegarat.com/ |
Upload File : |
<?php
//****************************************************************************************//
//************************************* Configuration ************************************//
//****************************************************************************************//
// Chargement fichiers de configuration.
require('libs/Smarty.class.php');
// Demarrage du moteur TPL.
$smarty = new Smarty;
// Chargement des Fonctions Globals.
require('fonctions.php');
// Ne fait pas apparaitre le panier dans la colonne Right
$smarty->assign("noCart", '1');
$same_address= $_POST['same_address'];
$smarty->assign("same", $same_address);
$txt_discount= $_POST['txt_discount'];
$txt_discount= $_POST['discount'];
if ($txt_discount=='') { $txt_discount= $_POST['txt_discount']; }
$smarty->assign("txt_discount", $txt_discount);
$bienvenue_taux= $_POST['bienvenue_taux'];
$bienvenue_ttc= $_POST['bienvenue_ttc'];
if ($bienvenue_taux =='') { $bienvenue_taux =0; }
if ($bienvenue_ttc =='') { $bienvenue_ttc =0; }
//////////////////////////////////////////////////////
$invoice_firstname = $_POST['invoice_firstname'];
$invoice_firstname= strtoupper($invoice_firstname);
$smarty->assign("invoice_firstname", $invoice_firstname);
$invoice_lastname= $_POST['invoice_lastname'];
$invoice_lastname= strtoupper($invoice_lastname);
$smarty->assign("invoice_lastname", $invoice_lastname);
$invoice_company= $_POST['invoice_company'];
$invoice_company= strtoupper($invoice_company);
$smarty->assign("invoice_company", $invoice_company);
$invoice_city= $_POST['invoice_city'];
$invoice_city= strtoupper($invoice_city);
$smarty->assign("invoice_city", $invoice_city);
$invoice_zip_code= $_POST['invoice_zip_code'];
$smarty->assign("invoice_zip_code", $invoice_zip_code);
$invoice_phone= $_POST['invoice_phone'];
$smarty->assign("invoice_phone", $invoice_phone);
$email= $_POST['email'];
$smarty->assign("email", $email);
$invoice_address1= $_POST['invoice_address1'];
$smarty->assign("invoice_address1", $invoice_address1);
$invoice_address2= $_POST['invoice_address2'];
$smarty->assign("invoice_address2", $invoice_address2);
// recup id pays et retrouve le nom local du pays
$invoice_country = $_POST['invoice_country'];
if(empty($invoice_country)){ $invoice_country = '1'; }
$sqlii = $GLOBALS['bdd']->prepare('SELECT * FROM countries
WHERE id = :invoice_country');
$sqlii->execute(array('invoice_country' => $invoice_country));
$resulti = $sqlii->fetch();
$invoice_country_name = $resulti['localname'];
// Recup code transports colissimo
$invoice_country_colissimo = $resulti['countries_colissimo'];
$country_colissimo1 = $resulti['countries_colissimo'];
// Recup code transports chronopost
$invoice_country_chronopost = $resulti['countries_chronopost'];
$country_chronopost1 = $resulti['countries_chronopost'];
$smarty->assign("invoice_country_colissimo", $invoice_country_colissimo);
$smarty->assign("invoice_country_chronopost", $invoice_country_chronopost);
$smarty->assign("invoice_country", $invoice_country);
$smarty->assign("invoice_country_name", $invoice_country_name);
$smarty->assign("country_colissimo1", $country_colissimo1);
$smarty->assign("country_chronopost1", $country_chronopost1);
//////////////////////////////////////////////////////
$delivery_firstname = $_POST['delivery_firstname'];
$delivery_firstname= strtoupper($delivery_firstname);
$smarty->assign("delivery_firstname", $delivery_firstname);
$delivery_lastname= $_POST['delivery_lastname'];
$delivery_lastname= strtoupper($delivery_lastname);
$smarty->assign("delivery_lastname", $delivery_lastname);
$delivery_company= $_POST['delivery_company'];
$delivery_company= strtoupper($delivery_company);
$smarty->assign("delivery_company", $delivery_company);
$delivery_city= $_POST['delivery_city'];
$delivery_city= strtoupper($delivery_city);
$smarty->assign("delivery_city", $delivery_city);
$delivery_zip_code= $_POST['delivery_zip_code'];
$smarty->assign("delivery_zip_code", $delivery_zip_code);
$delivery_phone= $_POST['delivery_phone'];
$smarty->assign("delivery_phone", $delivery_phone);
$delivery_address1= $_POST['delivery_address1'];
$smarty->assign("delivery_address1", $delivery_address1);
$delivery_address2= $_POST['delivery_address2'];
$smarty->assign("delivery_address2", $delivery_address2);
// recup id pays et retrouve le nom local du pays
$delivery_country= $_POST['delivery_country'];
if(empty($delivery_country)){ $delivery_country = '1'; }
$sqlv = $GLOBALS['bdd']->prepare('SELECT * FROM countries
WHERE id = :delivery_country');
$sqlv->execute(array('delivery_country' => $delivery_country));
$resultv = $sqlv->fetch();
$delivery_country_name= $resultv['localname'];
// Recup code transports colissimo
$delivery_country_colissimo = $resultv['countries_colissimo'];
$country_colissimo2 = $resultv['countries_colissimo'];
// Recup code transports chronopost
$delivery_country_chronopost = $resultv['countries_chronopost'];
$country_chronopost2 = $resultv['countries_chronopost'];
$smarty->assign("delivery_country_colissimo", $delivery_country_colissimo);
$smarty->assign("delivery_country_chronopost", $delivery_country_chronopost);
$smarty->assign("delivery_country", $delivery_country);
$smarty->assign("delivery_country_name", $delivery_country_name);
$smarty->assign("country_colissimo2", $country_colissimo2);
$smarty->assign("country_chronopost2", $country_chronopost2);
$country_colissimo = $country_colissimo1;
$country_chronopost = $country_chronopost1;
$valid = "1";
if($same_address=='0') {
if ($delivery_firstname == '' || $delivery_lastname == '' || $delivery_phone == '' || $delivery_address1 == '' || $delivery_city == '' || $delivery_zip_code == '') {
$valid = "0";
} else {
$country_colissimo = $country_colissimo2;
$country_chronopost = $country_chronopost2;
}
}
$smarty->assign("valid", $valid);
$smarty->assign("country_colissimo", $country_colissimo);
$smarty->assign("country_chronopost", $country_chronopost);
//****************************************************************************************//
//********************************* Information de pays **********************************//
//***************************************************************************************//
$sql = $GLOBALS['bdd']->prepare('SELECT * FROM countries
WHERE status = 1
ORDER BY localname ASC');
$sql->execute();
$pays = $sql->fetchAll();
$smarty->assign("pays", $pays);
//****************************************************************************************//
//************************************ css pour mails ************************************//
//****************************************************************************************//
$thema = $GLOBALS['bdd']->query('SELECT * FROM info WHERE id = 1');
$resulta = $thema->fetchAll();
$fil = $resulta[0]['fil'] ;
$tfil = $resulta[0]['tfil'] ;
//****************************************************************************************//
//************************************ Recherche cgv. ************************************//
//****************************************************************************************//
$sql = $GLOBALS['bdd']->query('SELECT id, title, seo, content FROM cms
WHERE id = 1');
$result = $sql->fetchAll();
$smarty->assign("ccgv", $result[0]['content']);
// RGPD
$sql = $GLOBALS['bdd']->query('SELECT id, title, seo, content FROM cms
WHERE id = 4');
$result = $sql->fetchAll();
$smarty->assign("confid", $result[0]['content']);
//****************************************************************************************//
//************************************ Code promotion ************************************//
//****************************************************************************************//
if(isset($_POST['discount'])) {
$txt_discount= $_POST['discount'];
$sql = $GLOBALS['bdd']->prepare('SELECT discount FROM discounts
WHERE discount_code = :discount_code AND :now BETWEEN date_start AND date_end');
$sql->execute(array('discount_code' => $_POST['discount'],
'now' => date("Y-m-d")));
if($result = $sql->fetch()) {
$discount['status'] = "OK";
$discount['discount'] = $result['discount'];
$smarty->assign("txt_discount", $txt_discount);
} else {
$discount['status'] = "error";
}
}
//****************************************************************************************//
//************************************** bienvenue ***************************************//
//****************************************************************************************//
if(!empty($_SESSION['custo']['id']))
{
$smarty->assign("bienvenue", "0");
$smarty->assign("disc_pourc", "0");
$smarty->assign("disc_num", "0");
$nb_cde = 0;
$cptc = 0;
// Recherche si c est la 1ere cde du client
$sql = $GLOBALS['bdd']->prepare('SELECT customer FROM orders
WHERE customer = :sSid ORDER BY id LIMIT 1');
$sql->execute(array('sSid' => $_SESSION['custo']['id']));
$columns = $sql->fetchAll();
foreach ($columns as $col) {
$cptc = $cptc + 1 ;
}
$nb_cde = $cptc;
$smarty->assign('nb_cde', $nb_cde);
if ($nb_cde < 1) {
// Fait la remise de bienvenue
// premiere remise dans la liste
$sql = $GLOBALS['bdd']->prepare('SELECT * FROM bienvenue WHERE :now BETWEEN date_start AND date_end
ORDER BY id LIMIT 1');
$sql->execute(array('now' => date("Y-m-d")));
$resulta = $sql->fetch();
$disc_num = $resulta['discount'];
$disc_pourc = $resulta['discount_pourcent'];
}
}
//****************************************************************************************//
//************************************* Vider le panier **********************************//
//****************************************************************************************//
if(isset($_POST['empty'])) {
unset($_SESSION['cart']);
$sql = $GLOBALS['bdd']->prepare('DELETE FROM cart_attributes_values
WHERE session = :session');
$sql->execute(array('session' => $session));
}
//****************************************************************************************//
//**************************************** Panier ****************************************//
//****************************************************************************************//
$products = array();
$carriers = array();
$total = 0;
$weight = 0;
$stool = 0;
$tva_0 = 0;
$tva_1 = 0;
$tva_2 = 0;
$tva_3 = 0;
$discTotal = 0;
$nodiscTotal = 0;
$code_cumul = 0;
$code_bienvenue = 0;
if(is_array($_SESSION['cart'])) {
foreach ($_SESSION['cart'] as $num => $product) {
foreach ($product[0] as $key => $value) {
if ($key != 'product' && $key != 'quantity' && $key != 'Observ') {
if(substr($value,0,1) == "#" || substr($value,0,3) == "rgb"){
$value = '<div style="display: inline; padding-right: 16px; border: 1px solid black; background-color: ' . $value . ';"></div>';
}
if ($gesto > 0) {
// Refait la presentation de la ligne
// nom attribut
$array_attrib= explode('>', $value);
$attrib1 = $array_attrib[0];
$attrib2 = $array_attrib[1];
$attrib3 = $array_attrib[2];
$array_attrib1= explode(' : ', $attrib1);
$attrib11 = $array_attrib1[0];
$attrib12 = $array_attrib1[1];
$attrib13 = $array_attrib1[2];
$products[$num]['attribute'][$key] = $attrib11;
} else {
$products[$num]['attribute'][$key] = $value;
}
}
}
$sql = $GLOBALS['bdd']->prepare('SELECT seo, reference, stock, name, price, weight, discount, cle_tva FROM products
WHERE id = :id');
$sql->execute(array('id' => $product[0]['product']));
$result = $sql->fetch();
$id_produit = $product[0]['product'];
$price = $product[0]['quantity'] * ($result['price'] * (1 - $result['discount'] / 100));
$products[$num]['name'] = substr($result['name'], 0, 65);
$products[$num]['id'] = $product[0]['product'];
$products[$num]['seo'] = $result['seo'];
$products[$num]['stock'] = $result['stock'];
$products[$num]['reference'] = $result['reference'];
$products[$num]['discount'] = $result['discount'];
$products[$num]['quantity'] = $product[0]['quantity'];
$products[$num]['price'] = $result['price'] * (1 - $result['discount'] / 100);
$products[$num]['total'] = $price;
$price_base = $price;
if($discount['status'] == "OK") {
if ($result['discount'] > 0) {
$discTotal = $discTotal + $price;
$code_remise = 0;
$price = $price - $code_remise;
} else {
$nodiscTotal = $nodiscTotal + $price;
$code_remise = $discount['discount'] * $price/ 100;
$price = $price - $code_remise;
$code_cumul = $code_cumul + $code_remise ;
}
}
////////////////////////////////////////////////
//Bienvenue
///////////////////////////////////////////////
if(!empty($_SESSION['custo']['id']))
{
if ($nb_cde < 1) {
if ($disc_pourc > 0) {
$smarty->assign("bienvenue", "1");
$smarty->assign("disc_pourc", $disc_pourc);
$remise_s_total = $disc_pourc * $price/ 100;
$price = $price - $remise_s_total;
$code_bienvenue = $code_bienvenue + $remise_s_total ;
}
}
}
////////////////////////////////////////////////////
switch ($result['cle_tva']) {
case 0:
$tva_0 += $price * 0;
break;
case 1:
$coef1_2 = $T_1_valeur / 100; $coef1 = $coef1_2 + 1;
$tva_1 += ($price / $coef1) * $coef1_2;
break;
case 2:
$coef2_2 = $T_2_valeur / 100; $coef2 = $coef2_2 + 1;
$tva_2 += ($price / $coef2) * $coef2_2;
break;
case 3:
$coef3_2 = $T_3_valeur / 100; $coef3 = $coef3_2 + 1;
$tva_3 += ($price / $coef3) * $coef3_2;
break;
}
$weight += $result['weight'] * $product[0]['quantity'];
$total += $price;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Si vide on lui attribut le ID 1000
$carrierChoix = $_POST['carrierChoix'];
if(empty($carrierChoix)) {
$sql = $GLOBALS['bdd']->prepare('SELECT c.id, c.name, c.picture, MIN(pl.price) AS price FROM carrier c
INNER JOIN price_list pl
ON c.id = pl.id_carrier
WHERE c.status = 1 AND pl.weight >= :weight AND (class1 = :class1 OR class2 = :class2)
GROUP BY c.id ');
$sql->execute(array('weight' => $weight,
'class1' => $country_colissimo,
'class2' => $country_chronopost
));
$result = $sql->fetchAll();
if(count($result) != 0) {
$carriers[] = $result;
sort($carriers[0]);
}
$carri = '1000';
$smarty->assign("carrierChoix", $carri);
}
//////////////////////////////////////////////////////
// Si pas vide
// "lex" est la cl?dans la bdd pour enlevement au magasin (ID:2), pour france et etranger...
$carrierChoix = $_POST['carrierChoix'];
if(!empty($carrierChoix)) {
$sql = $GLOBALS['bdd']->prepare('SELECT c.id, c.name, c.picture, MIN(pl.price) AS price FROM carrier c
INNER JOIN price_list pl
ON c.id = pl.id_carrier
WHERE c.status = 1 AND pl.weight >= :weight AND (class1 = :class1 OR class2 = :class2 OR class1 = :lex)
GROUP BY c.id ');
$sql->execute(array('weight' => $weight,
'class1' => $country_colissimo,
'class2' => $country_chronopost,
'lex' => 'X'
));
$result = $sql->fetchAll();
if(count($result) != 0) {
$carriers[] = $result;
sort($carriers[0]);
}
}
}
$smarty->assign("carrierChoix", $carrierChoix);
///////////////////////////////////////////////////////////////
$carrierChoixA = $_POST['carrierChoixA'];
$smarty->assign("carrierChoixA", $carrierChoixA);
// Trouve le nom du transporteur d apres le ID et la tva sur transport
if($carrierChoix > 900){ $carrierChoix = $carrierChoixA ; }
$sqla = $GLOBALS['bdd']->prepare('SELECT name, tva FROM carrier
WHERE id = :idop');
$sqla->execute(array('idop' => $carrierChoix));
$resultaa = $sqla->fetch();
$carrierNam = $resultaa['name'];
$carrierTva = $resultaa['tva'];
//Fin Carriers ................................................
if($discount['status'] == "OK") {
// Si deja sold?pas de remise generale cumul? seulement le prix du produit remis?sans la remise global du code promo !
$discount['amount'] = $code_cumul;
$total = $discTotal + $nodiscTotal;
$smarty->assign("txt_discount", $txt_discount);
}
////////////////////////////////////////////////
//Bienvenue
///////////////////////////////////////////////
if(!empty($_SESSION['custo']['id']))
{
if ($nb_cde < 1) {
if (is_numeric($code_bienvenue)) {
//$total = $total - $code_bienvenue;
$smarty->assign("code_bienvenue", $code_bienvenue);
}
}
}
////////////////////////////////////////////////////
// echo '<pre>';
// var_dump($carriers[0]);
// echo '</pre>';
$smarty->assign("ssTotal", $total);
$smarty->assign("discount", $discount);
$smarty->assign("products", $products);
$smarty->assign("carriers", $carriers[0]);
$smarty->assign("tva_0", $tva_0);
$smarty->assign("tva_1", $tva_1);
$smarty->assign("tva_2", $tva_2);
$smarty->assign("tva_3", $tva_3);
//****************************************************************************************//
//************************************ Adresses client ***********************************//
//****************************************************************************************//
if(!empty($_SESSION['custo']['id']))
{
// Information de facturation
$sql = $GLOBALS['bdd']->prepare('SELECT c.id_invoice_address, c.id_delivery_address, a.* FROM customers c
INNER JOIN address a
ON a.id = c.id_invoice_address
WHERE c.id = :id');
$sql->execute(array('id' => $_SESSION['custo']['id']));
$invoice = $sql->fetch();
$smarty->assign("invoice", $invoice);
// Information de livraison
$sql = $GLOBALS['bdd']->prepare('SELECT c.id_delivery_address, a.* FROM customers c
INNER JOIN address a
ON a.id = c.id_delivery_address
WHERE c.id = :id');
$sql->execute(array('id' => $_SESSION['custo']['id']));
$delivery = $sql->fetch();
$smarty->assign("delivery", $delivery);
}
//****************************************************************************************//
//************************************* Enregistrements **********************************//
//****************************************************************************************//
if (!empty($_POST['invoice_lastname'])) {
if(isset($_POST['submit'])) {
// Enregistrement des adresses
if(!isset($_SESSION['custo']['id']))
{
$sql = $GLOBALS['bdd']->prepare('INSERT INTO address (firstname, lastname, company, phone, address1, address2, city, zip_code, id_country, country) VALUES
(:firstname, :lastname, :company, :phone, :address1, :address2, :city, :zip_code, :id_country, :country)');
$sql->execute(array('firstname' => $invoice_firstname,
'lastname' => $invoice_lastname,
'company' => $invoice_company,
'phone' => $_POST['invoice_phone'],
'address1' => $_POST['invoice_address1'],
'address2' => $_POST['invoice_address2'],
'city' => $invoice_city,
'zip_code' => $_POST['invoice_zip_code'],
'country' => $invoice_country_name,
'id_country' => $invoice_country));
$invoice['id_invoice_address'] = $GLOBALS['bdd']->lastInsertId();
if($_POST['same_address'] == '0')
{
$sql->execute(array('firstname' => $delivery_firstname,
'lastname' => $delivery_lastname,
'company' => $delivery_company,
'phone' => $_POST['delivery_phone'],
'address1' => $_POST['delivery_address1'],
'address2' => $_POST['delivery_address2'],
'city' => $delivery_city,
'zip_code' => $_POST['delivery_zip_code'],
'id_country' => $delivery_country,
'country' => $delivery_country_name));
}
$delivery['id_delivery_address'] = $GLOBALS['bdd']->lastInsertId();
// Newsletter commande rapide
$newsletter_ok = ($_POST['newslet'] == 'on') ? 1 : 0;
if ($newsletter_ok > 0) {
// V?ification si l'exp?iteur est pr?ent dans la base de donn?s Newsletter
$sql = $GLOBALS['bdd']->prepare('SELECT * FROM fe_mail_user WHERE email = :email');
$sql->execute(array('email' => $_POST['email']));
$result = $sql->fetch();
// Si non pr?ent, ?l'ajoute.
if($result['email'] !== $_POST['email'])
{
$unsubscribe_code = substr(md5(trim($_POST['name']).trim($_POST['email'])), 0, 7);
$sql = $GLOBALS['bdd']->prepare('INSERT INTO fe_mail_user (insert_date, id_user, id_cat, name, email, unsubscribe_code, time_unsubscribe, ip_unsubscribe, status) VALUES (:insert_date, :id_user, :id_cat, :name, :email, :unsubscribe_code, :time_unsubscribe, :ip_unsubscribe, :status)');
$sql->execute(array('insert_date' => time(),
'id_user' => '3',
'id_cat' => '3',
'name' => $_POST['invoice_firstname'],
'email' => $_POST['email'],
'unsubscribe_code' => $unsubscribe_code,
'time_unsubscribe' => '0',
'ip_unsubscribe' => '0',
'status' => '0'));
}
else
{
}
}
}
// Total frais de transport
if (is_numeric($_POST['discount_amount'])) {
$totalbrut = $_POST['sub_total'] - $_POST['discount_amount'];
$totalbrut = $totalbrut - $bienvenue_ttc;
} else {
$totalbrut = $_POST['sub_total'];
$totalbrut = $totalbrut - $bienvenue_ttc;
}
$frais_transp = $_POST['total'] - $totalbrut ;
$codeSuivi = substr(md5(time().trim($_POST['invoice_lastname']).trim($_POST['email'])), 0, 7);
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Enregistrement de la commande
$sql = $GLOBALS['bdd']->prepare('INSERT INTO orders(date_insere, id_order, payment, customer, email, invoice_address, delivery_address, sub_total, carrier, carrier_price, px_transport, discount, txt_discount, bienvenue_taux, bienvenue_ttc, txt_tva0, txt_tva1, txt_tva2, txt_tva3, tva_0, tva_1, tva_2, tva_3, total)
VALUES (:date_insere, :id_order, :payment, :customer, :email, :invoice_address, :delivery_address, :sub_total, :carrier, :carrier_price, :px_transport, :discount, :txt_discount, :bienvenue_taux, :bienvenue_ttc, :txt_tva0, :txt_tva1, :txt_tva2, :txt_tva3, :tva_0, :tva_1, :tva_2, :tva_3, :total)');
$sql->execute(array('date_insere' => date('Y-m-d'),
'id_order' => $codeSuivi,
'payment' => $_POST['payment'],
'customer' => (isset($_SESSION['custo']['id']) ? $_SESSION['custo']['id'] : 0),
'email' => $_POST['email'],
'invoice_address' => $invoice['id_invoice_address'],
'delivery_address' => ($_POST['same_address'] == '0' ? $delivery['id_delivery_address'] : $invoice['id_invoice_address']),
'sub_total' => $_POST['sub_total'],
'carrier' => $carrierNam,
'carrier_price' => $carrierTva,
'discount' => (isset($_POST['discount_amount']) ? $_POST['discount_amount'] : 0),
'txt_discount' => $txt_discount,
'bienvenue_taux' => $bienvenue_taux,
'bienvenue_ttc' => $bienvenue_ttc,
'px_transport' => $frais_transp,
'txt_tva0' => $T_0_text,
'txt_tva1' => $T_1_text,
'txt_tva2' => $T_2_text,
'txt_tva3' => $T_3_text,
'tva_0' => (isset($_POST['tva_0']) ? $_POST['tva_0'] : 0),
'tva_1' => (isset($_POST['tva_1']) ? $_POST['tva_1'] : 0),
'tva_2' => (isset($_POST['tva_2']) ? $_POST['tva_2'] : 0),
'tva_3' => (isset($_POST['tva_3']) ? $_POST['tva_3'] : 0),
'total' => $_POST['total']));
$id_order = $GLOBALS['bdd']->lastInsertId();
$totalCde = $_POST['total'];
// Enregistrement du statut de la commande
$sql = $GLOBALS['bdd']->prepare('INSERT INTO order_status(id_order, date_status, status)
VALUES (:order, :date_status, :status)');
$sql->execute(array('order' => $id_order,
'date_status' => date('Y-m-d H:i:s'),
'status' => 0));
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Enregistrement des produits du panier
if(is_array($_SESSION['cart'])) {
$recap = '';
$recap .= '<b>Produit(s)</b> :<br /><br />';
$insertOrdersProducts = $GLOBALS['bdd']->prepare('INSERT INTO orders_products(id_order, id_product, attributes, discount, price, quantity, observations)
VALUES (:id_order, :id_product, :attributes, :discount, :price, :quantity, :observations)');
//////////////////////////////////////////////////////////////////
////// Si ATTRIBUTS
/*
On recupere les donnees de la session :
1- le libell?pour l'affichage du panier et enregistrement de l attribut dans cde
2- les IDs value de l attribut pour le decompte stock par attribut
3- les stocks dispos des valeurs
4- Id product =$id_product
*/
/////////////////////////////////////////////////////////////////
foreach ($_SESSION['cart'] as $num => $product) {
$attributes = '';
$obs_art= '';
$avec_attribut = 0;
foreach ($product[0] as $key => $value) {
// observations article
if ($key == 'Observ') {
// 3 - Reprend les infos
$obs_art = $value; // valeur de l observation
}
if ($gesto > 0) {
if ($key != 'product' && $key != 'quantity' && $key != 'Dispo' && $key != 'Observ') {
// 1 - Trouve le libelle de la valeur pour l affichage et l email confirmation
$array_attrib= explode('>', $value);
$attrib1 = $array_attrib[0];
$attrib2 = $array_attrib[1];
$attrib3 = $array_attrib[2];
$attributes .= $attrib1; // Libell?OK
// 1 1 - Trouve le ID de la valeur : Tail40 bleu vert>N.10>Stock:4
$array_attrib= explode('>', $value);
$attrib1 = $array_attrib[0];
$attrib2 = $array_attrib[1];
$attrib3 = $array_attrib[2];
$attrib2= str_replace("N.", "", $attrib2);
$id_valeur = $attrib2; // ID Value OK
if (!empty($attributes)) { $avec_attribut = 1; }
}
if ($key == 'Dispo') {
// 2 - Reprend pour le stock dispo pour decompte
$stock_dispo = $value; // Dispo OK
}
} else {
// Si pas stock actif
if ($key != 'product' && $key != 'quantity' && $key != 'Dispo' && $key != 'Observ') {
$attributes .= $key . ' : ' . $value . ', ';
}
}
}
$sql = $GLOBALS['bdd']->prepare('SELECT reference, name, price, discount, stock FROM products
WHERE id = :id');
$sql->execute(array('id' => $product[0]['product']));
$result = $sql->fetch();
$stock_prod = $result['stock'];
$id_product = $product[0]['product'];
$discount = $result['discount'];
$quantity = $product[0]['quantity'];
$price = $result['price'] * (1 - $result['discount'] / 100);
$insertOrdersProducts->execute(array( 'id_order' => $id_order,
'id_product' => $id_product,
'attributes' => $attributes,
'discount' => $discount,
'price' => $price,
'quantity' => $quantity,
'observations' => $obs_art));
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
if ($gesto > 0) {
// Si stock et attribut unique
if ($avec_attribut > 0) {
$new_stock = $stock_dispo - $quantity;
// Met a jour le stock attribut dans products_attributes_values
$qid = $bdd->prepare("UPDATE " . $GLOBALS['db_table']['products_attributes_values'] . "
SET stock = :stock WHERE id_product = :id_product AND id_value = :id_value ");
$qid->execute(array( 'stock' => $new_stock,
'id_product' => $id_product,
'id_value' => $id_valeur));
// Met a jour le stock dans products
$new_stock_product = $stock_prod - $quantity;
$ishstock_fin ='';
if ($new_stock_product< 1) { $ishstock_fin ='1'; } else { $ishstock_fin ='0'; }
$qid = $bdd->prepare("UPDATE " . $GLOBALS['db_table']['products'] . "
SET stock = :stock, hstock= :hstock WHERE id= :id");
$qid->execute(array( 'stock' => $new_stock_product,
'hstock' => $ishstock_fin,
'id' => $id_product));
if ($caisse_ok >0) {
/////////////////
// MISE A JOUR SUR LA CAISSE
$num_attribut = '_'.$id_valeur;
// Trouve le id du produit caisse d apres la reference du produit site
$sqlr = $GLOBALS_0['bdd']->prepare('SELECT id FROM products
WHERE id_product = :id_product AND num_attribut = :num_attribut');
$sqlr->execute(array(
'id_product' => $product[0]['product'],
'num_attribut' => $num_attribut
));
$resultr = $sqlr->fetch();
$id_caisse = $resultr['id'];
// modifie stock sur la caisse principale
$qid = $GLOBALS_1['bdd']->prepare("UPDATE " . $GLOBALS_1['db_table'][TABLE_STOCK] . "
SET stock = :stock WHERE id_product = :id_product");
$qid->execute(array( 'stock' => $new_stock,
'id_product' => $id_caisse));
/////////////////
}
}
///////////////////////////////////////////////////
else {
// Met a jour le stock dans products
$new_stock_product = $stock_prod - $quantity;
$ishstock_fin ='';
if ($new_stock_product< 1) { $ishstock_fin ='1'; } else { $ishstock_fin ='0'; }
$qid = $bdd->prepare("UPDATE " . $GLOBALS['db_table']['products'] . "
SET stock = :stock, hstock= :hstock WHERE id= :id");
$qid->execute(array( 'stock' => $new_stock_product,
'hstock' => $ishstock_fin,
'id' => $id_product));
if ($caisse_ok >0) {
/////////////////
// MISE A JOUR SUR LA CAISSE
$id_caisse = $id_product;
// modifie stock sur la caisse principale
$qid = $GLOBALS_1['bdd']->prepare("UPDATE " . $GLOBALS_1['db_table'][TABLE_STOCK] . "
SET stock = :stock WHERE id_product = :id_product");
$qid->execute(array( 'stock' => $new_stock_product,
'id_product' => $id_caisse));
///////////////////
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// Preparation emails
$recap .= $quantity . ' x ' . $result['name'];
if($result['reference'] != '')
$recap .= ' (Ref : ' . $result['reference'] . ')';
$recap .= ' ' . $attributes . '';
$recap .= ' - prix unitaire : ' . number_format($price, 2, ',', ' ') . ' € - Total : ' . number_format(($price * $quantity), 2, ',', ' ') . ' €';
if($discount > 0)
$recap .= ' (Remise de ' . number_format($discount, 2, ',', ' ') . ' % incluse) ' . $attributes . '';
$recap .= '<br />' . $obs_art . '';
$recap .='<br /><br />';
}
}
// Fin enregistrement
unset($_SESSION['cart']);
$sql = $GLOBALS['bdd']->prepare('DELETE FROM cart_attributes_values
WHERE session = :session');
$sql->execute(array('session' => $session));
//////////////////////////////////////////////////////////
// Mails de confirmation
require('includes/phpmailer/class.phpmailer.php');
$msg ='
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>';
if ($emailo < 1) { $msg .='<img src="'.$wwwroot.'templates/shop/img/'.$Image_Logo.'" style="margin:10px; max-width:300px">';
} else {
$msg .='<img src="'.$wwwroot.'templates/shop/img/'.$Image_Logo.'" style="margin:10px;max-width:300px">';
}
$msg .='
<div style="background-color: #'.$fil.'; color:#'.$tfil.'; border-radius: 6px;">
<h3 style="font-size:20px; padding:10px;">Récapitulatif de la commande</h3>
</div>
<br />
<b>Numéro de commande</b> : ' . $id_order . '<br>
<b>Date de la commande</b> : ' . date('d/m/Y') . '<br>
<b>Numéro de suivi</b> : <a href="http://'.$shop_url.'/suivi-de-commande-' . $codeSuivi . '">' . $codeSuivi . '</a><br>
<b>Livraison</b> : ' . $carrierNam . '<br>
<br>';
if($_POST['same_address'] == '0')
{
$msg .= '
<div style="background-color: #'.$fil.'; color:#'.$tfil.'; border-radius: 6px;">
<h3 style="font-size:20px; padding:10px;">Adresse de livraison</h3>
</div>
<br />
' . $delivery_firstname . ' ' . $delivery_lastname . '<br>';
if (!empty($delivery_company))
{
$msg .= '' . $delivery_company . '<br>';
}
$msg .= '' . $_POST['delivery_address1'] . '<br>';
if (!empty($_POST['delivery_address2']))
{
$msg .= '' . $_POST['delivery_address2'] . '<br>';
}
$msg .= '' . $_POST['delivery_zip_code'] . ' ' . $_POST['delivery_city'] . '<br>
' . $delivery_country_name . '<br>
' . $_POST['delivery_phone'] . '<br>';
}
$msg .= '<br>
<div style="background-color: #'.$fil.'; color:#'.$tfil.'; border-radius: 6px;">
<h3 style="font-size:20px; padding:10px;">Adresse de facturation</h3>
</div>
<br />
' . $invoice_firstname. ' ' . $invoice_lastname . '<br>';
if (!empty($invoice_company))
{
$msg .= '' . $invoice_company . '<br>';
}
$msg .= '' . $_POST['invoice_address1'] . '<br>';
if (!empty($_POST['invoice_address2']))
{
$msg .= '' . $_POST['invoice_address2'] . '<br>';
}
$msg .= '' . $_POST['invoice_zip_code'] . ' ' . $_POST['invoice_city'] . '<br>
' . $invoice_country_name . '<br>
' . $_POST['invoice_phone'] . '<br>
<br><br>';
$msg .= '<div style="background-color: #'.$fil.'; color:#'.$tfil.'; border-radius: 6px;">
<h3 style="font-size:20px; padding:10px;">Vos produits</h3>
</div>
<br />';
$msg .= $recap;
///////////////////////////////////////////////////////////////////
$msg .= '<br><br />
<div style="background-color: #'.$fil.'; color:#'.$tfil.'; border-radius: 6px;">
<h3 style="font-size:20px; padding:10px;">Total de votre commande</h3>
</div>
<br />';
$msg .='<b>Sous-total TTC</b> : ' . number_format($_POST['sub_total'], 2, ',', ' ') . ' €<br>';
if (is_numeric($_POST['discount_amount'])) {
$totalbrut = $_POST['sub_total'] - $_POST['discount_amount'];
$totalbrut = $totalbrut - $bienvenue_ttc;
} else {
$totalbrut = $_POST['sub_total'];
$totalbrut = $totalbrut - $bienvenue_ttc;
}
$frais_transp = $_POST['total'] - $totalbrut ;
///////////////////////////////////////////////////////////////////
if(!empty($_POST['discount_amount'])){
$msg .= '<b>Remise code</b> : ' . number_format($_POST['discount_amount'], 2, ',', ' ') . ' €<br>';
}
if($bienvenue_taux >0){
$msg .= '<b>Remise de bienvenue ('.number_format($bienvenue_taux, 2, ',', ' ').'%)</b> : '.number_format($bienvenue_ttc, 2, ',', ' ').' €<br>';
}
$msg .= '<b>Frais de livraison</b> : ' . number_format($frais_transp, 2, ',', ' ') . ' €<br>';
$msg .= '<b>Total TTC</b> : ' . number_format($_POST['total'], 2, ',', ' ') . ' €<br>';
$msg .= '<b>Mode paiement</b> : ' . $_POST['payment'] . '';
$msg .= '<br /><br />';
$msg .= 'Toute notre équipe vous remercie de votre confiance,';
$msg .= '<br /><br /><b>'.$shop_title.'</b><br /><a href="http://'.$shop_url.'">'.$shop_url.'</a><br /><br />'.$shop_company.'<br />'.$shop_address.'<br />'.$shop_zip_code.' '.$shop_town.'<br />'.$shop_phone.'<br />'.$shop_email_contact.'</b>
<p style="padding-top:10px;"><a href="http://'.$shop_url.'">'.$shop_title.'</a></p>
</body>
</html>';
// Envoi message au client.
$mail2 = new PHPMailer();
$mail2->IsMail();
$mail2->AddReplyTo($shop_email_contact, $shop_company);
$mail2->AddAddress($_POST['email']);
$mail2->SetFrom($shop_email_rappel, $shop_company);
$mail2->Subject = "Confirmation de votre commande depuis le site " . $shop_title;
$mail2->MsgHTML($msg);
// Envoi message a l'administrateur du site.
$mail = new PHPMailer();
$mail->IsMail();
$mail->AddReplyTo($_POST['email'], $_POST['invoice_lastname']);
$mail->AddAddress($shop_email_rappel);
$mail->SetFrom($_POST['email'], $_POST['invoice_lastname']);
$mail->Subject = "Commande depuis le site " . $shop_title;
$mail->MsgHTML($msg);
if($mail->Send() & $mail2->Send())
{
$smarty->assign("emails_status", 'OK');
} else {
$smarty->assign("emails_status", 'erreur');
}
// Redirection pour le paiement////////////////////////////////////////////////
$idCommande = $id_order;
$prixTotal = $totalCde ;
switch ($_POST['payment']) {
case 'Paypal':
/******************************************************************************/
// Paiement par Paypal
/******************************************************************************/
echo '<script language="javascript">document.location.href="paypal.php?id=' . $codeSuivi . '&commandeid='.$idCommande.'"</script>';
break;
/////////////////////////////////////////////////////////////////////////////////////////
case 'cb':
/******************************************************************************/
// Paiement par CB
/******************************************************************************/
$requete = $bdd->prepare("INSERT INTO transactions (transaction_id, transaction_commande_id, transaction_total, transaction_statut)
VALUES (:transaction_id, :transaction_commande_id, :transaction_total, :transaction_statut)");
$requete->execute(array(
'transaction_id' => $idCommande,
'transaction_commande_id' => $idCommande,
'transaction_total' => stripslashes($prixTotal),
'transaction_statut' => null
));
$idTransaction = $bdd->lastInsertId();
/******************************************************************************/
// Paiement par CB : appel de la requete de type Cyberplus
/******************************************************************************/
// $wwwrequest = $wwwroot . "/cgi-bin/call_request.php?commandeid=" . $idCommande . "&transactionid=" . $idCommande. "&total=" . number_format($prixTotal, 2, '', '');
//$wwwrequest = $wwwroot . "/call_request.php?commandeid=" . $idCommande . "&transactionid=" . $idCommande. "&total=" . $prixTotal;
// $wwwrequest = "http://access.fr/ACAE/Paiement_Hmac.php?email=" . $_POST['email'] . "&idCommande =" . $idCommande . "&total=" . $prixTotal, 2, '', '') ;
//$wwwrequest = "http://access.fr/ACAE/Paiement_Hmac.php?commandeid=" . $idCommande . "&email=".$_POST['email']."&total=" . number_format($prixTotal, 2, '', '');
//$wwwrequest = "http://cmdistribution.fr/ci/Phase1Go.php?commandeid=" . $idCommande . "&email=".$_POST['email']."&total=" . $prixTotal;
//$prixTotal = number_format($prixTotal,2);
//$wwwrequest = "https://www.fermegarat.com/CE_payment/index.php?commandeid=" . $idCommande . "&email=".$_POST['email']."&total=" . $prixTotal;
// header("Location: $wwwrequest");
echo'
<form name="xxxl" action="./CE_payment/index.php" method="POST">
<input type="hidden" name="commandeid" value="' . $idCommande . '">
<input type="hidden" name="email" value="' . $_POST['email'] . '">
<input type="hidden" name="total" value="' . $prixTotal. '">
<script type="text/javascript">
document.xxxl.submit(); //on envoie le formulaire
</script>
</form>';
break;
//////////////////////////////////////////////////////////////////////////////////////
case 'Cheque':
echo '<script language="javascript">document.location.href="check.php?id=' . $codeSuivi . '"</script>';
break;
case 'Virement':
echo '<script language="javascript">document.location.href="transfer.php?id=' . $codeSuivi . '"</script>';
break;
}
}
}
//****************************************************************************************//
//*************************************** CMS ACCUEIL ************************************//
//****************************************************************************************//
$id_page = $page_panier;
if ($id_page >0) {
// Page CMS
$sqlpm = $GLOBALS['bdd']->query('SELECT title, content FROM cms
WHERE id = '.$id_page.'');
$com = $sqlpm->fetch();
$page_content= $com['content'];
} else {
$page_content="";
}
$smarty->assign("page_content", $page_content);
$smarty->assign("id_page", $id_page);
//*************************************** Affichage **************************************//
$smarty->display('cart.tpl');
?>