/** * AJAX - Delete Custom shipping Rule */ function wpshop_ajax_delete_shipping_rule() { global $wpdb; $wps_shipping = new wps_shipping(); $fees_data = !empty($_POST['fees_data']) ? $_POST['fees_data'] : null; $country_and_weight = !empty($_POST['country_and_weight']) ? $_POST['country_and_weight'] : null; $datas = explode("|", $country_and_weight); $country = $datas[0]; $weight = $datas[1]; $shipping_mode_id = $datas[2]; $shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data)); /** Check the default weight unity **/ // $weight_unity_id = get_option('wpshop_shop_default_weight_unity'); // if ( !empty($weight_unity_id) ) { // $query = $wpdb->prepare('SELECT unit FROM ' .WPSHOP_DBT_ATTRIBUTE_UNIT. ' WHERE id=%d', $weight_unity_id); // $weight_unity = $wpdb->get_var( $query ); // if( $weight_unity == 'kg' ) { // $weight = $weight * 1000; // } // } if (array_key_exists($country, $shipping_rules)) { if (array_key_exists((string) $weight, $shipping_rules[$country]['fees'])) { unset($shipping_rules[$country]['fees'][$weight]); } if (empty($shipping_rules[$country]['fees'])) { unset($shipping_rules[$country]); } } foreach ($shipping_rules as $k => $shipping_rule) { if (!isset($shipping_rule['fees'])) { unset($shipping_rules[$k]); } } $status = true; if (!empty($shipping_rules)) { $rules = $wps_shipping->shipping_fees_array_2_string($shipping_rules); } else { $rules = ''; } $reponse = array('status' => $status, 'reponse' => $rules); echo json_encode($reponse); die; }
} else { if ($count == 0 && empty($selected_shipping_method)) { $checked = 'checked="checked"'; $class = 'wps-activ'; } else { $checked = $class = ''; } } } $shipping_cost_are_free = false; $free_shipping_cost_alert = ''; $currency = wpshop_tools::wpshop_get_currency(); $cart_items = !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) ? $_SESSION['cart']['order_items'] : ''; $price_piloting = get_option('wpshop_shop_price_piloting'); if (!empty($cart_items)) { $wps_shipping = new wps_shipping(); $cart_weight = $wps_shipping->calcul_cart_weight($cart_items); $total_cart_ht_or_ttc_regarding_config = !empty($price_piloting) && $price_piloting == 'HT' ? $_SESSION['cart']['order_total_ht'] : $_SESSION['cart']['order_total_ttc']; $total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost($cart_items); $shipping_cost = $wps_shipping->get_shipping_cost(count($cart_items), $total_cart_ht_or_ttc_regarding_config, $total_shipping_cost_for_products, $cart_weight, $shipping_mode_id) . ' ' . $currency; } if (!empty($shipping_mode['free_from'])) { $order_amount = !empty($price_piloting_option) && $price_piloting_option == 'HT' ? number_format((double) $_SESSION['cart']['order_total_ht'], 2, '.', '') : number_format((double) $_SESSION['cart']['order_total_ttc'], 2, '.', ''); if ($order_amount < $shipping_mode['free_from']) { $free_in = $shipping_mode['free_from'] - $order_amount; $shipping_cost .= ' ' . sprintf(__('Free in %s', 'wpshop'), $free_in . ' ' . $currency); } else { $shipping_cost = '<span class="wps-badge-vert">' . __('Free shipping cost', 'wpshop') . '</span>'; $shipping_cost_are_free = true; } }
/** * Add product if is queried and recalcule cart informations * @param array $product_list * @param string $custom_order_information * @param array $current_cart * @param boolean $from_admin * @return array */ function calcul_cart_information($product_list, $custom_order_information = '', $current_cart = array(), $from_admin = false) { // Price piloting option $price_piloting = get_option('wpshop_shop_price_piloting'); // Init vars $cart_infos = !empty($current_cart) ? $current_cart : (!empty($_SESSION) && !empty($_SESSION['cart']) && !$from_admin ? $_SESSION['cart'] : array()); $cart_items = !empty($current_cart) && !empty($current_cart['order_items']) ? $current_cart['order_items'] : array(); $cart_items = !empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items']) && !$from_admin ? $_SESSION['cart']['order_items'] : $cart_items; $order_total_ht = $order_total_ttc = $total_vat = 0; $order_tva = array(); $total_weight = $nb_of_items = $order_shipping_cost_by_article = 0; $order_discount_rate = $order_discount_amount = $order_items_discount_amount = $order_total_discount_amount = 0; // If Product list is not empty, add products to order if (!empty($product_list)) { foreach ($product_list as $product_id => $d) { $product_key = $product_id; if (isset($d['product_qty'])) { // Formate datas $product_id = $head_product_id = $d['product_id']; $product_qty = $d['product_qty']; $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null; // If product is a single variation product if (!empty($product_variation) && count($product_variation) == 1) { $product_id = $product_variation[0]; } // Construct final product $product = wpshop_products::get_product_data($d['product_id'], true, '"publish", "free_product"'); $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => $product_qty), $product); // Add variation to product into cart for storage if (!empty($product_variation)) { $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type'])); } // Free Variations Checking if (!empty($d['free_variation'])) { $the_product['item_meta']['free_variation'] = $d['free_variation']; $head_product_id = $the_product['product_id']; } // If product is a variation, we check parent product general if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { $parent_def = wpshop_products::get_parent_variation($the_product['product_id']); if (!empty($parent_def) && !empty($parent_def['parent_post'])) { $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true); $parent_meta = $parent_def['parent_post_meta']; if (!empty($variation_def) && !empty($variation_def['options']) && !empty($variation_def['options']['priority']) && in_array('combined', $variation_def['options']['priority']) && !empty($variation_def['options']['price_behaviour']) && in_array('addition', $variation_def['options']['price_behaviour']) && !empty($variation_def['attributes']) && count($variation_def['attributes']) > 1) { $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', ''); $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', ''); $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', ''); } } } // Delete product if its qty is equals to zero, else add this product to order if (empty($d['product_qty'])) { unset($cart_items[$product_key]); unset($cart_infos['order_items'][$product_key]); } else { $wps_orders = new wps_orders_ctr(); $cart_items[$product_key] = $wps_orders->add_product_to_order($the_product); } } } } // Add automaticaly Add-to-cart Products $cart_items = $this->add_automaticaly_product_to_cart($cart_items); // Calcul Cart Informations if (!empty($cart_items) && is_array($cart_items)) { foreach ($cart_items as $item_id => $item) { $order_total_ht += $item['item_total_ht']; $order_total_ttc += $item['item_total_ttc']; // VAT if (!empty($order_tva[$item['item_tva_rate']])) { $order_tva[$item['item_tva_rate']] += $item['item_tva_total_amount']; } else { $order_tva[$item['item_tva_rate']] = $item['item_tva_total_amount']; } } } else { return array(); } // Apply informations to cart $cart_infos['order_items'] = $cart_items; $cart_infos['order_total_ht'] = $order_total_ht; $cart_infos['order_total_ttc'] = $order_total_ttc; // Calcul Shipping cost if (!$from_admin) { $wps_shipping = new wps_shipping(); $total_cart_ht_or_ttc_regarding_config = !empty($price_piloting) && $price_piloting == 'HT' ? $cart_infos['order_total_ht'] : $cart_infos['order_total_ttc']; $cart_weight = $wps_shipping->calcul_cart_weight($cart_infos['order_items']); $total_shipping_cost_for_products = $wps_shipping->calcul_cart_items_shipping_cost($cart_infos['order_items']); $cart_infos['order_shipping_cost'] = $wps_shipping->get_shipping_cost(count($cart_infos['order_items']), $total_cart_ht_or_ttc_regarding_config, $total_shipping_cost_for_products, $cart_weight); } // If Price piloting is ET, calcul VAT on Shipping cost if (!empty($price_piloting) && $price_piloting == 'HT') { $shipping_cost_vat = !empty($cart_infos['order_shipping_cost']) ? WPSHOP_VAT_ON_SHIPPING_COST / 100 * number_format($cart_infos['order_shipping_cost'], 2, '.', '') : 0; $order_tva['VAT_shipping_cost'] = $shipping_cost_vat; } // Calcul VAT Total if (!empty($order_tva)) { foreach ($order_tva as $vat_rate => $vat_value) { $total_vat += $vat_value; } } // Recap totals $cart_infos['order_total_ttc'] = $cart_infos['order_total_ht'] + (!empty($cart_infos) && !empty($cart_infos['order_shipping_cost']) ? $cart_infos['order_shipping_cost'] : 0) + $total_vat; $cart_infos['order_grand_total_before_discount'] = $cart_infos['order_amount_to_pay_now'] = $cart_infos['order_grand_total'] = $cart_infos['order_total_ttc']; // Apply coupons if (!empty($_SESSION['cart']) && !$from_admin) { if (!empty($_SESSION['cart']['coupon_id'])) { $wps_coupon_mdl = new wps_coupon_model(); $coupon = $wps_coupon_mdl->get_coupon_data($_SESSION['cart']['coupon_id']); if (!empty($coupon) && !empty($coupon['wpshop_coupon_code'])) { $wps_coupon = new wps_coupon_ctr(); $coupon_checking = $wps_coupon->applyCoupon($coupon['wpshop_coupon_code']); // If Coupon conditions are Ok if (!empty($coupon_checking) && !empty($coupon_checking['status']) && $coupon_checking['status']) { $cart_infos['order_discount_type'] = $coupon['wpshop_coupon_discount_type']; $cart_infos['order_discount_value'] = $coupon['wpshop_coupon_discount_value']; } } } } // Checking Discounts if (!empty($cart_infos['order_discount_type']) && $cart_infos['order_discount_value']) { // Calcul discount on Order switch ($cart_infos['order_discount_type']) { case 'amount': $cart_infos['order_discount_amount_total_cart'] = number_format(str_replace(',', '.', $cart_infos['order_discount_value']), 2, '.', ''); break; case 'percent': $cart_infos['order_discount_amount_total_cart'] = number_format($cart_infos['order_grand_total'], 2, '.', '') * (number_format(str_replace(',', '.', $cart_infos['order_discount_value']), 2, '.', '') / 100); break; } $cart_infos['order_grand_total'] -= number_format($cart_infos['order_discount_amount_total_cart'], 2, '.', ''); $cart_infos['order_amount_to_pay_now'] = number_format($cart_infos['order_grand_total'], 2, '.', ''); } // Apply Partial Payments $wpshop_payment = new wpshop_payment(); $partial_payment = $wpshop_payment->partial_payment_calcul($cart_infos['order_grand_total']); if (!empty($partial_payment['amount_to_pay'])) { unset($partial_payment['display']); $cart_infos['order_partial_payment'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', ''); $cart_infos['order_amount_to_pay_now'] = number_format(str_replace(',', '.', $partial_payment['amount_to_pay']), 2, '.', ''); } // Cart Type if (isset($_SESSION['cart']['cart_type'])) { $cart_infos['cart_type'] = $_SESSION['cart']['cart_type']; } // Apply Extra actions on cart infos $cart_infos = apply_filters('wps_extra_calcul_in_cart', $cart_infos, $_SESSION); return $cart_infos; }
/** * Generate cutom fees resume table * @param array $fees_data * @param string $key */ function generate_shipping_rules_table($fees_data, $shipping_mode_id) { global $wpdb; $result = ''; if (!empty($fees_data)) { $wps_shipping = new wps_shipping(); $shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data)); $result = ''; $tpl_component = ''; $tpl_component['CUSTOM_SHIPPING_RULES_LINES'] = ''; $tpl_component['SHIPPING_MODE_ID'] = $shipping_mode_id; $country_list = unserialize(WPSHOP_COUNTRY_LIST); $weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity'); $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); $unity = $wpdb->get_var($query); ob_start(); require wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-custom-rules-table"); $result = ob_get_contents(); ob_end_clean(); } return $result; }
<?php $wps_shipping = new wps_shipping(); $shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data)); if (!empty($shipping_rules)) { ?> <div class="wps-table-header wps-table-row"> <div class="wps-table-cell"><?php _e('Country', 'wpshop'); ?> </div> <div class="wps-table-cell"><?php _e('Weight', 'wpshop'); ?> </div> <div class="wps-table-cell"><?php _e('Price', 'wpshop'); ?> </div> <div class="wps-table-cell"><?php _e('Delete', 'wpshop'); ?> </div> </div> <?php foreach ($shipping_rules as $shipping_rule) { $country_name = ''; $code_country = explode('-', $shipping_rule['destination']); $code_country = $code_country[0];