$ls_final_order_amount = fn_linked_products_in_cart_amount($ls_total_products, $product['product_id']); //for template logic to hide the add to cart button if ($ls_final_order_amount > 1) { //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) {
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; }