} elseif ($ls_total_products[$combination_hash]['tracking'] === 'D') { //no tracking //generate the availability list($ls_msg['ls_product_availability'], $ls_msg['ls_hide_button']) = fn_ls_availability_message($ls_total_products[$combination_hash]['ls_main_product_info']['amount'], $product_id, CART_LANGUAGE, $sufficient_in_stock, $ls_total_products[$combination_hash]['tracking'], $ls_total_products[$combination_hash]['order_amount'], $ls_total_products[$combination_hash]['ls_main_product_info']['out_of_stock_actions'], $ls_total_products[$combination_hash]['ls_main_product_info']['avail_since']); if ($ls_total_products[$combination_hash]['ls_main_product_info']['out_of_stock_actions'] == 'S' && $ls_total_products[$combination_hash]['ls_main_product_info']['amount'] < 1) { $ls_msg['ls_notification_signup'] = fn_ls_generate_notification_signup($product_id, CART_LANGUAGE); } } } else { //product in cart //get product and linked products details fn_ls_get_linked_products($ls_total_products); //get total linked products for the order fn_ls_linked_products_order_total($ls_total_products); //the total amount of the product found in cart, including linked variants and the product page amount $ls_final_order_amount = fn_linked_products_in_cart_amount($ls_total_products, $ls_total_products[$combination_hash]['product_id']); foreach ($ls_total_products as $hash => $array) { if ($array['ls_db_hash'] == $combination_hash) { //this product is already in cart //set the product page order amount // $array['order_amount']=1; if ($array['tracking'] === 'B' || $array['tracking'] === 'D') { $array['amount'] = $array['amount'] - $ls_final_order_amount + 1; //substract the amount present in cart from product page array } $sufficient_in_stock = fn_ls_sufficient_stock($ls_total_products[$hash]); // decrement the inventory amount if ($array['tracking'] === 'B') { //tracking without options //generate the availability list($ls_msg['ls_product_availability'], $ls_msg['ls_hide_button']) = fn_ls_availability_message($array['ls_main_product_info']['amount'], $product_id, CART_LANGUAGE, $sufficient_in_stock, $array['tracking'], $array['order_amount'], $array['ls_main_product_info']['out_of_stock_actions'], $array['ls_main_product_info']['avail_since']);
//linked variants(not products present in cart) //decrement the inventory $product['amount'] = $product['amount'] - $ls_final_order_amount + 1; } //custom availability message for linked products $sufficient_in_stock = fn_ls_sufficient_stock($ls_total_products[$product['combination_hash']]); Registry::get('view')->assign('sufficient_in_stock', $sufficient_in_stock); $ls_individual_estimation = fn_ls_delivery_estimation($ls_total_products[$product['combination_hash']], $product['combination_hash'], 0, true); } else { //product in cart Registry::get('view')->assign('ls_product_in_cart', true); //get product and linked products details fn_ls_get_linked_products($ls_total_products); //get total linked products for the order fn_ls_linked_products_order_total($ls_total_products); $ls_final_order_amount = fn_linked_products_in_cart_amount($ls_total_products, $product['product_id']); foreach ($ls_total_products as $hash => $array) { if ($array['ls_db_hash'] == $product['combination_hash']) { //this product is already in cart //custom availability message for linked products $sufficient_in_stock = fn_ls_sufficient_stock($ls_total_products[$hash]); Registry::get('view')->assign('sufficient_in_stock', $sufficient_in_stock); //set the product page order amount // $array['order_amount'] = 1; // decrement the inventory amount if ($product['tracking'] === 'B') { //tracking without options if ($ls_final_order_amount > 1) { //linked variants(not products present in cart) $product['amount'] = $product['amount'] - $ls_final_order_amount + 1; //substract the amount present in cart from product page array(including component products in cart and linked)
function fn_ls_delivery_estimation_total($cart_products) { //var_dump($cart_products); //get linked products and its details fn_ls_get_linked_products($cart_products); //get common linked products order total fn_ls_linked_products_order_total($cart_products); //pass here only linked products that are in cart //correct the inventory and order amounts if there are linked products in cart fn_linked_products_in_cart_amount($cart_products); $ls_shipping_estimation = 0; $ls_individual_estimations = array(); $ls_all_estimations = array(); foreach ($cart_products as $combination_hash => $product) { $ls_shipping_estimation = max(fn_ls_delivery_estimation($product, $combination_hash, $ls_shipping_estimation), $ls_shipping_estimation); //total delivery estimation //shipping estimation for individual products // $ls_individual_estimations[$combination_hash] = fn_ls_delivery_estimation($product, $combination_hash, 0); $ls_individual_estimations[$combination_hash] = fn_ls_delivery_estimation($product, $combination_hash, 0); //check if the estimation is Sunday if (date("D", $ls_individual_estimations[$combination_hash]) === 'Sun') { //add one more day to the estimation $ls_individual_estimations[$combination_hash] = $ls_individual_estimations[$combination_hash] + 24 * 60 * 60; } // echo "<br>ls_individual_estimation for $combination_hash is ".date('d m Y ',$ls_individual_estimations[$combination_hash]); } //check if the estimation is Sunday if (date("D", $ls_shipping_estimation) === 'Sun') { //add one more day to the estimation $ls_shipping_estimation = $ls_shipping_estimation + 24 * 60 * 60; } $ls_all_estimations['total_estimation'] = $ls_shipping_estimation; $ls_all_estimations['individual_estimations'] = $ls_individual_estimations; return $ls_all_estimations; }