From 3424c9fadc784ea6a93d9b377106e1de8dc9b896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CVeLiTi=E2=80=9D?= <“info@veliti.nl”> Date: Thu, 13 Feb 2025 11:23:15 +0100 Subject: [PATCH] CMXX - Placeorder initial version --- admin/settings.php | 2 +- cart.php | 2 +- checkout.php | 264 +++++-------------- custom/css/custom.css | 137 +++++++++- custom/css/style.css | 15 ++ custom/customfunctions.php | 1 + custom/email/order-details-template.php | 8 +- custom/email/order-notification-template.php | 8 +- custom/settings/config.php | 22 +- functions.php | 193 +++++++------- home.php | 140 +++++++--- index.php | 3 - product.php | 20 +- products.php | 8 +- 14 files changed, 446 insertions(+), 377 deletions(-) diff --git a/admin/settings.php b/admin/settings.php index 06d3aee..ebd1f98 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -63,7 +63,7 @@ if (!empty($_POST)) { $v = in_array(strtolower($v), ['true', 'false']) ? strtolower($v) : '\'' . $v . '\''; $contents = preg_replace('/define\(\'' . $k . '\'\, ?(.*?)\)/s', 'define(\'' . $k . '\',' . $v . ')', $contents); } - file_put_contents('../config.php', $contents); + file_put_contents('../custom/settings/config.php', $contents); header('Location: index.php?page=settings&success_msg=1'); exit; } diff --git a/cart.php b/cart.php index 916a7b1..eaf4afe 100644 --- a/cart.php +++ b/cart.php @@ -145,7 +145,7 @@ $view = ' '; if (!empty($product['meta']['img'])){ $view .= ' - '.$product['meta']['name'].' + '.$product['meta']['name'].' '; } $view .= ' diff --git a/checkout.php b/checkout.php index 0817d21..a452af9 100644 --- a/checkout.php +++ b/checkout.php @@ -29,9 +29,9 @@ $weighttotal = 0; $checkout_input = [ "selected_country" => isset($_POST['address_country']) ? $_POST['address_country'] : $account['address_country'], - "selected_shipment_method" => isset($_POST['shipping_method']) ? $_POST['shipping_method'] : null, + "selected_shipment_method" => isset($_POST['shipping_method']) ? $_POST['shipping_method'] : '', "business_type" => 'b2c', - "discount_code" => isset($_SESSION['discount']) ? $_SESSION['discount'] : null + "discount_code" => isset($_SESSION['discount']) ? $_SESSION['discount'] : '' ]; $selected_shipping_method_name = ''; @@ -39,9 +39,9 @@ $shipping_methods_available = []; // Error array, output errors on the form $errors = []; -// --------------------------------------- -// --------------------------------------- -// --------------------------------------- +// --------------------------------------------- +// End defaults -------------------------------- +// --------------------------------------------- // Redirect the user if the shopping cart is empty if (empty($_SESSION['cart'])) { @@ -56,16 +56,17 @@ if (isset($_SESSION['account_loggedin'])) { // Fetch the account from the database and return the result as an Array $account = $stmt->fetch(PDO::FETCH_ASSOC); } + // Update discount code if (isset($_POST['discount_code']) && !empty($_POST['discount_code'])) { $_SESSION['discount'] = $_POST['discount_code']; } else if (isset($_POST['discount_code']) && empty($_POST['discount_code']) && isset($_SESSION['discount'])) { unset($_SESSION['discount']); } + //------------------------------- // If there are products in cart handle the checkout //------------------------------- - if ($products_in_cart) { //Calculate shopping_cart @@ -103,7 +104,6 @@ if ($products_in_cart) { //------------------------------- //Place order //------------------------------- - // Make sure when the user submits the form all data was submitted and shopping cart is not empty if (isset($_POST['method'], $_POST['first_name'], $_POST['last_name'], $_POST['address_street'], $_POST['address_city'], $_POST['address_state'], $_POST['address_zip'], $_POST['address_country'], $_POST['address_phone'], $_SESSION['cart']) && !isset($_POST['update'])) { $account_id = null; @@ -146,19 +146,28 @@ if (isset($_POST['method'], $_POST['first_name'], $_POST['last_name'], $_POST['a } if (!$errors && $products_in_cart) { - //Process checkout - //Calculate shopping_cart - $payload = json_encode(array("cart" => $products_in_cart, "checkout_input" => $checkout_input, "customer_details" => $account), JSON_UNESCAPED_UNICODE); + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + //Process checkout => add payment_method to checkout_input array + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + $checkout_input['payment_method'] = $_POST['method']; + + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + // Calculate shopping_cart based on session + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + $payload = json_encode(array("cart" => $_SESSION['cart'], "checkout_input" => $checkout_input, "customer_details" => $account), JSON_UNESCAPED_UNICODE); $place_order = ioAPIv2('/v2/placeorder/',$payload,$clientsecret); - $place_order = json_decode($products_in_cart,true); - + $place_order = json_decode($place_order,true); + + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //Check if transaction is succesfull and send order confirmation to customer + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + if ($place_order['error'] == '' && $place_order['id'] != ''){ - + //SEND CONFIRMATION TO CUSTOMER send_order_details_email( $account['email'], - $products_in_cart, + $place_order['products_checked-out'], $account['first_name'], $account['last_name'], $account['address_street'], @@ -173,22 +182,14 @@ if (isset($_POST['method'], $_POST['first_name'], $_POST['last_name'], $_POST['a $place_order['payment_amount'], $place_order['transaction_id'] ); - } - - //Pay on delivery = 2 - if (pay_on_delivery_enabled && $place_order['payment_method'] == 2){ - - //header('Location: ' . url('index.php?page=placeorder')); - //exit; - } - /* + //Disable giftcard if (isset($_SESSION['discount'])){ if (preg_match("/[#][0-9]/", $_SESSION['discount']) == 1){ useGiftCart($pdo, $_SESSION['discount']); } } - + // Authenticate the user if ($account_id != null) { // Log the user in with the details provided @@ -197,87 +198,22 @@ if (isset($_POST['method'], $_POST['first_name'], $_POST['last_name'], $_POST['a $_SESSION['account_id'] = $account_id; $_SESSION['account_role'] = $account ? $account['role'] : 'Member'; } - // Send order details to the specified email address - send_order_details_email( - isset($account['email']) && !empty($account['email']) ? $account['email'] : $_POST['email'], - $products_in_cart, - $_POST['first_name'], - $_POST['last_name'], - $_POST['address_street'], - $_POST['address_city'], - $_POST['address_state'], - $_POST['address_zip'], - $_POST['address_country'], - $subtotal, - $discounttotal, - $shippingtotal, - $taxtotal, - $payment_amount, - $order_id - ); - header('Location: ' . url('index.php?page=placeorder')); - exit; - */ + } + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // Mollie ++++++++++++++++++++++++++++++++++++++++++++++++++++ + //Pay on delivery = 2 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - if (mollie_enabled && $_POST['method'] == 'mollie') { - // Process Normal Checkout - // Generate unique transaction ID - $transaction_id = strtoupper(uniqid('SC') . substr(md5(mt_rand()), 0, 5)); - // Insert transaction into database - $stmt = $pdo->prepare('INSERT INTO transactions (txn_id, payment_amount, payment_status, created, payer_email, first_name, last_name, address_street, address_city, address_state, address_zip, address_country, account_id, payment_method, shipping_method, shipping_amount, discount_code, address_phone, tax_amount) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'); - $stmt->execute([ - $transaction_id, - $payment_amount, - default_payment_status, - date('Y-m-d H:i:s'), - isset($account['email']) && !empty($account['email']) ? $account['email'] : $_POST['email'], - $_POST['first_name'], - $_POST['last_name'], - $_POST['address_street'], - $_POST['address_city'], - $_POST['address_state'], - $_POST['address_zip'], - $_POST['address_country'], - $account_id, - 'Debit/Credit', - $selected_shipping_method_name, - $shippingtotal, - isset($_SESSION['discount']) ? $_SESSION['discount'] : '', - $_POST['address_phone'], - $taxtotal - ]); - // Get order ID - $order_id = $pdo->lastInsertId(); - // Iterate products and deduct quantities - foreach ($products_in_cart as $product) { - // For every product in the shopping cart insert a new transaction into our database - $stmt = $pdo->prepare('INSERT INTO transactions_items (txn_id, item_id, item_price, item_quantity, item_options) VALUES (?,?,?,?,?)'); - $stmt->execute([ $transaction_id, $product['id'], $product['final_price'], $product['quantity'], $product['options'] ]); - // Update product quantity in the products table - $stmt = $pdo->prepare('UPDATE products SET quantity = quantity - ? WHERE quantity > 0 AND id = ?'); - $stmt->execute([ $product['quantity'], $product['id'] ]); - // Deduct option quantities - if ($product['options']) { - $options = explode(',', $product['options']); - foreach ($options as $opt) { - $option_name = explode('-', $opt)[0]; - $option_value = explode('-', $opt)[1]; - $stmt = $pdo->prepare('UPDATE products_options SET quantity = quantity - ? WHERE quantity > 0 AND title = ? AND (name = ? OR name = "")'); - $stmt->execute([ $product['quantity'], $option_name, $option_value ]); - } - } - } - // Authenticate the user - if ($account_id != null) { - // Log the user in with the details provided - session_regenerate_id(); - $_SESSION['account_loggedin'] = TRUE; - $_SESSION['account_id'] = $account_id; - $_SESSION['account_role'] = $account ? $account['role'] : 'Member'; - } + if (pay_on_delivery_enabled && $place_order['payment_method'] == 2){ + header('Location: ' . url('index.php?page=placeorder')); + exit; + } + + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + // Mollie = 0 ++++++++++++++++++++++++++++++++++++++++++++++++++ + // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + if (mollie_enabled && $_POST['method'] == 0) { try { /* @@ -291,8 +227,8 @@ if (isset($_POST['method'], $_POST['first_name'], $_POST['last_name'], $_POST['a * Generate a unique order id for this example. It is important to include this unique attribute * in the redirectUrl (below) so a proper return page can be shown to the customer. */ - $orderId = $transaction_id; - $value = number_format(($subtotal-$discounttotal)+$shippingtotal,2,'.',''); + $orderId = $place_order['transaction_id']; + $value = number_format($place_order['payment_amount'],2,'.',''); /* * Determine the url parts to these example files. @@ -333,25 +269,6 @@ if (isset($_POST['method'], $_POST['first_name'], $_POST['last_name'], $_POST['a * This request should always be a GET, thus we enforce 303 http response code */ - // Send order details to the specified email address - send_order_details_email( - isset($account['email']) && !empty($account['email']) ? $account['email'] : $_POST['email'], - $products_in_cart, - $_POST['first_name'], - $_POST['last_name'], - $_POST['address_street'], - $_POST['address_city'], - $_POST['address_state'], - $_POST['address_zip'], - $_POST['address_country'], - $subtotal, - $discounttotal, - $shippingtotal, - $taxtotal, - $payment_amount, - $order_id - ); - // Send customer to checkout header("Location: " . $payment->getCheckoutUrl(), true, 303); @@ -362,89 +279,36 @@ if (isset($_POST['method'], $_POST['first_name'], $_POST['last_name'], $_POST['a } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // PayPal Payment + +++++++++++++++++++++++++++++++++++++++++ + // PayPal Payment = 1 +++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if (paypal_enabled && $_POST['method'] == 'paypal') { - // Process Normal Checkout first then do PayPal related - // Generate unique transaction ID - $transaction_id = strtoupper(uniqid('SC') . substr(md5(mt_rand()), 0, 5)); - // Insert transaction into database - $stmt = $pdo->prepare('INSERT INTO transactions (txn_id, payment_amount, payment_status, created, payer_email, first_name, last_name, address_street, address_city, address_state, address_zip, address_country, account_id, payment_method, shipping_method, shipping_amount, discount_code, address_phone, tax_amount) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'); - $stmt->execute([ - $transaction_id, - $payment_amount, - default_payment_status, - date('Y-m-d H:i:s'), - isset($account['email']) && !empty($account['email']) ? $account['email'] : $_POST['email'], - $_POST['first_name'], - $_POST['last_name'], - $_POST['address_street'], - $_POST['address_city'], - $_POST['address_state'], - $_POST['address_zip'], - $_POST['address_country'], - $account_id, - 'paypal', - $selected_shipping_method_name, - $shippingtotal, - isset($_SESSION['discount']) ? $_SESSION['discount'] : '', - $_POST['address_phone'], - $taxtotal - ]); - // Get order ID - $order_id = $pdo->lastInsertId(); - // Iterate products and deduct quantities - foreach ($products_in_cart as $product) { - // For every product in the shopping cart insert a new transaction into our database - $stmt = $pdo->prepare('INSERT INTO transactions_items (txn_id, item_id, item_price, item_quantity, item_options) VALUES (?,?,?,?,?)'); - $stmt->execute([ $transaction_id, $product['id'], $product['final_price'], $product['quantity'], $product['options'] ]); - // Update product quantity in the products table - $stmt = $pdo->prepare('UPDATE products SET quantity = quantity - ? WHERE quantity > 0 AND id = ?'); - $stmt->execute([ $product['quantity'], $product['id'] ]); - // Deduct option quantities - if ($product['options']) { - $options = explode(',', $product['options']); - foreach ($options as $opt) { - $option_name = explode('-', $opt)[0]; - $option_value = explode('-', $opt)[1]; - $stmt = $pdo->prepare('UPDATE products_options SET quantity = quantity - ? WHERE quantity > 0 AND title = ? AND (name = ? OR name = "")'); - $stmt->execute([ $product['quantity'], $option_name, $option_value ]); - } - } - } - if ($account_id != null) { - // Log the user in with the details provided - session_regenerate_id(); - $_SESSION['account_loggedin'] = TRUE; - $_SESSION['account_id'] = $account_id; - $_SESSION['account_role'] = $account ? $account['role'] : 'Member'; - } + //Process Payment require_once __DIR__."/lib/paypal/paypal.php"; - $base = PAYPAL_URL; - $id = PAYPAL_CLIENT_ID; - $secret = PAYPAL_CLIENT_SECRET; + $base = PAYPAL_URL; + $id = PAYPAL_CLIENT_ID; + $secret = PAYPAL_CLIENT_SECRET; + + //init input + $order = $place_order['transaction_id']; + $price = number_format($place_order['payment_amount'],2,'.',''); + $currency = "EUR"; + + //make payment + $paypal = new paypalCurl(); + $paypal->init($id,$secret,$base); + $result = $paypal->makePaymentURL($order,$price,$currency); - //init input - $order = $transaction_id; - $price = $payment_amount; - $currency = "EUR"; - - //make payment - $paypal = new paypalCurl(); - $paypal->init($id,$secret,$base); - $result = $paypal->makePaymentURL($order,$price,$currency); - - if ($result->status === true) { - header("location:". $result->url); - die; - } - else { //raise error - echo $result->msg; - die; - } + if ($result->status === true) { + header("location:". $result->url); + die; + } + else { //raise error + echo $result->msg; + die; + } } } @@ -563,7 +427,7 @@ $view .= ' foreach($products_in_cart['cart_details']['products'] as $product){ $view .= ' - '.$product['meta']['name'].' + '.$product['meta']['name'].' '.$product['quantity'].' x '.$product['meta']['name'].' '.currency_code.''.number_format($product['options_price'] * $product['quantity'],2).' '; diff --git a/custom/css/custom.css b/custom/css/custom.css index 68dd3d8..f81409b 100644 --- a/custom/css/custom.css +++ b/custom/css/custom.css @@ -1586,7 +1586,7 @@ a.link-button { } .breadcrum a{ text-decoration: none; - color: #555555; + color: #4a90e2; cursor: pointer; font-family: inherit; font-size: 0.8em; @@ -1832,6 +1832,12 @@ input.banner_deny:hover { .filtersection { display: flex; margin: 0 auto; + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); + background: white; + border-radius: 12px; + margin-bottom: 50px; + padding: 10px; + width: 95%; } /* Filter Section */ @@ -1870,4 +1876,133 @@ input.banner_deny:hover { border-right: none; border-bottom: 1px solid #e0e0e0; } +} + +.news-section { + padding: 80px 20px; + background-color: #f8f8f8; +} + +.news-container { + max-width: 1200px; + margin: 0 auto; +} + +.news-header { + text-align: center; + margin-bottom: 50px; +} + +.news-header h2 { + font-size: 2rem; + margin-bottom: 15px; + font-family: 'gerb', sans-serif; +} + +.news-header p { + color: #666; + font-size: 1.1rem; +} + +.news-grid { + display: grid; + grid-template-columns: repeat(3, 1fr); + gap: 30px; + margin-bottom: 50px; +} + +.news-card { + background: white; + border-radius: 8px; + overflow: hidden; + box-shadow: 0 2px 4px rgba(0,0,0,0.1); + transition: box-shadow 0.3s ease; +} + +.news-card:hover { + box-shadow: 0 4px 8px rgba(0,0,0,0.2); +} + +.news-card-content { + padding: 20px; +} + +.news-meta { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 15px; +} + +.news-date { + color: #666; + font-size: 0.9rem; +} + +.news-tag { + background: #e6f0ff; + color: #0066cc; + padding: 4px 12px; + border-radius: 15px; + font-size: 0.8rem; +} + +.news-title { + font-size: 1.25rem; + margin-bottom: 15px; + color: #333; + font-weight: 600; +} + +.news-preview { + color: #666; + margin-bottom: 20px; + line-height: 1.5; +} + +.read-more { + color: #0066cc; + text-decoration: none; + display: inline-flex; + align-items: center; + font-weight: 500; +} + +.read-more:hover { + color: #0052a3; +} + +.read-more::after { + content: '>'; + margin-left: 5px; +} + +.view-all-container { + text-align: center; +} + +.view-all-btn { + background: #0066cc; + color: white; + padding: 12px 24px; + border-radius: 4px; + text-decoration: none; + display: inline-block; + transition: background-color 0.3s ease; +} + +.view-all-btn:hover { + background: #0052a3; +} + +@media (max-width: 1024px) { + .news-grid { + grid-template-columns: repeat(2, 1fr); + } +} + +@media (max-width: 768px) { + .news-grid { + grid-template-columns: 1fr; + } } \ No newline at end of file diff --git a/custom/css/style.css b/custom/css/style.css index 2d3dd3a..adc341d 100644 --- a/custom/css/style.css +++ b/custom/css/style.css @@ -407,6 +407,12 @@ main .recentlyadded .products .product:hover .name, main .products .products-wra main > .product { display: flex; padding: 40px 0; + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); + background: white; + border-radius: 12px; + margin-bottom: 50px; + padding: 10px; + width: 95%; } main > .product h1 { @@ -523,6 +529,15 @@ main > .product form .btn { margin-top: 10px; width: 400px; text-transform: uppercase; + padding: 16px; + background: #4a90e2; + color: white; + border: none; + border-radius: 8px; + font-size: 1.1rem; + font-weight: 500; + cursor: pointer; + transition: background-color 0.2s; } main > .products h1 { diff --git a/custom/customfunctions.php b/custom/customfunctions.php index 0136581..d0c4c39 100644 --- a/custom/customfunctions.php +++ b/custom/customfunctions.php @@ -250,6 +250,7 @@ function template_footer() { echo <<