Production release

This commit is contained in:
“VeLiTi”
2025-08-12 15:04:56 +02:00
parent 580f835fff
commit 60a32a7ff9
33 changed files with 2030 additions and 5494 deletions

View File

@@ -29,7 +29,7 @@ $weighttotal = 0;
$shipping_methods = [];
$checkout_input = [
"selected_country" => isset($_POST['address_country']) ? $_POST['address_country'] : $account['address_country'],
"selected_country" => isset($_POST['address_country']) ? $_POST['address_country'] : (isset($account['address_country']) ? $account['address_country'] : 21) ,
"selected_shipment_method" => isset($_POST['shipping_method']) ? $_POST['shipping_method'] : '',
"business_type" => 'b2c',
"discount_code" => isset($_SESSION['discount']) ? $_SESSION['discount'] : ''
@@ -64,16 +64,30 @@ if (isset($_POST['discount_code']) && !empty($_POST['discount_code'])) {
} else if (isset($_POST['discount_code']) && empty($_POST['discount_code']) && isset($_SESSION['discount'])) {
unset($_SESSION['discount']);
}
if (isset($_POST['address_country'])){
// Retrieve shipping methods
$shipping_methods = ioAPIv2('/v2/shipping/list=methods&country='.$checkout_input['selected_country'].'&price_total='.$subtotal.'&weight_total='.$weighttotal,'',$clientsecret);
$shipping_methods = json_decode($shipping_methods,true);
}
//-------------------------------
// If there are products in cart handle the checkout
//-------------------------------
if ($products_in_cart) {
//Calculate shopping_cart
// First, calculate cart to get initial totals (without shipping)
$initial_payload = json_encode(array("cart" => $products_in_cart, "checkout_input" => $checkout_input), JSON_UNESCAPED_UNICODE);
$initial_cart = ioAPIv2('/v2/checkout/',$initial_payload,$clientsecret);
$initial_cart = json_decode($initial_cart,true);
// Get initial totals for shipping method calculation
$initial_subtotal = $initial_cart['totals']['subtotal'] ?? 0;
$initial_weighttotal = $initial_cart['totals']['weighttotal'] ?? 0;
// Now retrieve shipping methods with correct totals
$shipping_methods = ioAPIv2('/v2/shipping/list=methods&country='.$checkout_input['selected_country'].'&price_total='.$initial_subtotal.'&weight_total='.$initial_weighttotal,'',$clientsecret);
$shipping_methods = json_decode($shipping_methods,true);
// If no shipping method is selected and shipping methods are available, select the first one as default
if (empty($checkout_input['selected_shipment_method']) && !empty($shipping_methods) && count($shipping_methods) > 0) {
$checkout_input['selected_shipment_method'] = $shipping_methods[0]['id'];
}
// Recalculate shopping_cart with selected shipping method
$payload = json_encode(array("cart" => $products_in_cart, "checkout_input" => $checkout_input), JSON_UNESCAPED_UNICODE);
$products_in_cart = ioAPIv2('/v2/checkout/',$payload,$clientsecret);
$products_in_cart = json_decode($products_in_cart,true);
@@ -86,10 +100,6 @@ if ($products_in_cart) {
$tax_rate = $products_in_cart['totals']['tax_rate'];
$weighttotal = $products_in_cart['totals']['weighttotal'];
$total = $products_in_cart['totals']['total'];
// Retrieve shipping methods
$shipping_methods = ioAPIv2('/v2/shipping/list=methods&country='.$checkout_input['selected_country'].'&price_total='.$subtotal.'&weight_total='.$weighttotal,'',$clientsecret);
$shipping_methods = json_decode($shipping_methods,true);
// Redirect the user if the shopping cart is empty
if (empty($products_in_cart)) {