Created
December 23, 2015 13:49
-
-
Save torunar/61b8bfc233006f897d40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/addons/paypal/func.php b/app/addons/paypal/func.php | |
index ea78fff..d40a805 100644 | |
--- a/app/addons/paypal/func.php | |
+++ b/app/addons/paypal/func.php | |
@@ -302,6 +302,9 @@ function fn_process_paypal_ipn($order_id, $data) | |
fn_change_order_status($order_id, STATUS_INCOMPLETED_ORDER); | |
//Sometimes, for some reasons cart_id in product products calculated incorrectly, so we need recalculate it. | |
$cart['change_cart_products'] = true; | |
+ // Store shipping rates | |
+ fn_store_shipping_rates($order_id, $cart, $customer_auth); | |
+ | |
fn_calculate_cart_content($cart, $customer_auth); | |
$cart['payment_info']['order_status'] = $pp_settings['pp_statuses'][strtolower($data['payment_status'])]; | |
list($order_id, ) = fn_update_order($cart, $order_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/addons/suppliers/func.php b/app/addons/suppliers/func.php | |
index 78666ce..7838ab0 100644 | |
--- a/app/addons/suppliers/func.php | |
+++ b/app/addons/suppliers/func.php | |
@@ -628,7 +628,11 @@ function fn_suppliers_pre_place_order(&$cart, &$allow, &$product_groups) | |
foreach ($product_groups as $key_group => $group) { | |
if (empty($new_product_groups[$group['company_id']])) { | |
$new_product_groups[$group['company_id']] = $group; | |
- $new_product_groups[$group['company_id']]['name'] = fn_get_company_name($group['company_id']); | |
+ if (isset($group['supplier_id'])) { | |
+ $new_product_groups[$group['company_id']]['name'] = fn_get_supplier_name($group['supplier_id']); | |
+ } else { | |
+ $new_product_groups[$group['company_id']]['name'] = fn_get_company_name($group['company_id']); | |
+ } | |
$new_product_groups[$group['company_id']]['products'] = array(); | |
$new_product_groups[$group['company_id']]['chosen_shippings'] = array(); | |
if (!empty($group['supplier_id'])) { | |
@@ -666,6 +670,7 @@ function fn_suppliers_pre_place_order(&$cart, &$allow, &$product_groups) | |
if (empty($group['chosen_shippings'][0]['group_name'])) { | |
$group['chosen_shippings'][0]['group_name'] = $group['name']; | |
} | |
+ $new_product_groups[$group['company_id']]['shippings'][$group['chosen_shippings'][0]['shipping_id']] = $group['chosen_shippings'][0]; | |
$new_product_groups[$group['company_id']]['chosen_shippings'] = array_merge($new_product_groups[$group['company_id']]['chosen_shippings'], $group['chosen_shippings']); | |
} | |
$new_product_groups[$group['company_id']]['products'] = $new_product_groups[$group['company_id']]['products'] + $group['products']; | |
@@ -935,3 +940,17 @@ function fn_exim_put_supplier($product_id, $supplier_name) | |
fn_suppliers_link_product($supplier_id, $product_id); | |
} | |
+ | |
+/** | |
+ * Modifies stored shipping rates | |
+ * | |
+ * @param int $order_id Order number | |
+ * @param array $cart Cart content | |
+ * @param array $customer_auth Authentication data | |
+ */ | |
+function fn_suppliers_store_shipping_rates_pre($order_id, &$cart, $customer_auth) | |
+{ | |
+ foreach($cart['shipping'] as $shipping_key => $shipping) { | |
+ $cart['stored_shipping'][$shipping['group_key']][] = $shipping['rate']; | |
+ } | |
+} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/addons/suppliers/init.php b/app/addons/suppliers/init.php | |
index a2465d0..5cabdd0 100644 | |
--- a/app/addons/suppliers/init.php | |
+++ b/app/addons/suppliers/init.php | |
@@ -30,5 +30,6 @@ fn_register_hooks( | |
'get_shipments_info_post', | |
'get_orders_post', | |
'get_order_info', | |
- 'clone_product' | |
+ 'clone_product', | |
+ 'store_shipping_rates_pre' | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/controllers/backend/order_management.php b/app/controllers/backend/order_management.php | |
index 74d97c8..306e01c 100644 | |
--- a/app/controllers/backend/order_management.php | |
+++ b/app/controllers/backend/order_management.php | |
@@ -294,17 +294,7 @@ if ($mode == 'edit' && !empty($_REQUEST['order_id'])) { | |
$cart_status = md5(serialize($cart)); | |
fn_form_cart($_REQUEST['order_id'], $cart, $customer_auth); | |
- if (!empty($cart['product_groups'])) { | |
- foreach ($cart['product_groups'] as $group_key => $group) { | |
- if (!empty($group['chosen_shippings'])) { | |
- foreach ($group['chosen_shippings'] as $shipping_key => $shipping) { | |
- if (!empty($shipping['stored_shipping']) && empty($cart['stored_shipping'][$group_key][$shipping_key])) { | |
- $cart['stored_shipping'][$group_key][$shipping_key] = $shipping['rate']; | |
- } | |
- } | |
- } | |
- } | |
- } | |
+ fn_store_shipping_rates($_REQUEST['order_id'], $cart, $customer_auth); | |
if ($cart_status == md5(serialize($cart))) { | |
// Order info was not found or customer does not have enought permissions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/functions/fn.cart.php b/app/functions/fn.cart.php | |
index 2704390..5a8dd5e 100644 | |
--- a/app/functions/fn.cart.php | |
+++ b/app/functions/fn.cart.php | |
@@ -6897,34 +6897,36 @@ function fn_apply_stored_shipping_rates(&$cart, $order_id = 0) | |
if (!empty($cart['stored_shipping'])) { | |
$total_cost = 0; | |
foreach ($cart['product_groups'] as $group_key => $group) { | |
- foreach ($group['chosen_shippings'] as $shipping_key => $shipping) { | |
- if (isset($cart['stored_shipping'][$group_key][$shipping_key])) { | |
- if (!empty($cart['free_shipping']) && in_array($shipping['shipping_id'], $cart['free_shipping'])) { | |
- if (!empty($cart['stored_shipping'][$group_key][$shipping_key])) { | |
- // save original value | |
- $cart['original_stored_shipping'][$group_key][$shipping_key] = $cart['stored_shipping'][$group_key][$shipping_key]; | |
- // apply free shipping | |
- $cart['stored_shipping'][$group_key][$shipping_key] = 0; | |
- } else { | |
- // save calulated rates as orignal: shipping is zero due to free shipping | |
- $cart['original_stored_shipping'][$group_key][$shipping_key] = $shipping['rate']; | |
+ if (isset($group['chosen_shippings'])) { | |
+ foreach ($group['chosen_shippings'] as $shipping_key => $shipping) { | |
+ if (isset($cart['stored_shipping'][$group_key][$shipping_key])) { | |
+ if (!empty($cart['free_shipping']) && in_array($shipping['shipping_id'], $cart['free_shipping'])) { | |
+ if (!empty($cart['stored_shipping'][$group_key][$shipping_key])) { | |
+ // save original value | |
+ $cart['original_stored_shipping'][$group_key][$shipping_key] = $cart['stored_shipping'][$group_key][$shipping_key]; | |
+ // apply free shipping | |
+ $cart['stored_shipping'][$group_key][$shipping_key] = 0; | |
+ } else { | |
+ // save calulated rates as orignal: shipping is zero due to free shipping | |
+ $cart['original_stored_shipping'][$group_key][$shipping_key] = $shipping['rate']; | |
+ } | |
+ } elseif (empty($cart['stored_shipping'][$group_key][$shipping_key]) && isset($cart['original_stored_shipping'][$group_key][$shipping_key])) { | |
+ // free shiping was disabled - restore previous price | |
+ $cart['stored_shipping'][$group_key][$shipping_key] = !empty($cart['original_stored_shipping'][$group_key][$shipping_key]) ? $cart['original_stored_shipping'][$group_key][$shipping_key] : $shipping['rate']; | |
+ unset($cart['original_stored_shipping'][$group_key][$shipping_key]); | |
} | |
- } elseif (empty($cart['stored_shipping'][$group_key][$shipping_key]) && isset($cart['original_stored_shipping'][$group_key][$shipping_key])) { | |
- // free shiping was disabled - restore previous price | |
- $cart['stored_shipping'][$group_key][$shipping_key] = !empty($cart['original_stored_shipping'][$group_key][$shipping_key]) ? $cart['original_stored_shipping'][$group_key][$shipping_key] : $shipping['rate']; | |
- unset($cart['original_stored_shipping'][$group_key][$shipping_key]); | |
- } | |
- $piece = fn_format_price($cart['stored_shipping'][$group_key][$shipping_key]); | |
- $cart['product_groups'][$group_key]['chosen_shippings'][$shipping_key]['rate'] = $piece; | |
- $cart['product_groups'][$group_key]['shippings'][$shipping['shipping_id']]['rate'] = $piece; | |
- $cart['product_groups'][$group_key]['chosen_shippings'][$shipping_key]['stored_shipping'] = true; | |
- $cart['product_groups'][$group_key]['shippings'][$shipping['shipping_id']]['stored_shipping'] = true; | |
- $shipping['rate'] = $piece; | |
- $total_cost += $piece; | |
- } else { | |
- if (!empty($shipping['rate'])) { | |
- $total_cost += $shipping['rate']; | |
+ $piece = fn_format_price($cart['stored_shipping'][$group_key][$shipping_key]); | |
+ $cart['product_groups'][$group_key]['chosen_shippings'][$shipping_key]['rate'] = $piece; | |
+ $cart['product_groups'][$group_key]['shippings'][$shipping['shipping_id']]['rate'] = $piece; | |
+ $cart['product_groups'][$group_key]['chosen_shippings'][$shipping_key]['stored_shipping'] = true; | |
+ $cart['product_groups'][$group_key]['shippings'][$shipping['shipping_id']]['stored_shipping'] = true; | |
+ $shipping['rate'] = $piece; | |
+ $total_cost += $piece; | |
+ } else { | |
+ if (!empty($shipping['rate'])) { | |
+ $total_cost += $shipping['rate']; | |
+ } | |
} | |
} | |
} | |
@@ -8406,3 +8408,27 @@ function fn_get_cart_products($user_id, $params = array()) | |
return $cart_products; | |
} | |
+ | |
+/** | |
+ * Stores shipping rates when managing order | |
+ * | |
+ * @param int $order_id Order number | |
+ * @param array $cart Cart contents | |
+ * @param array $customer_auth Authentication data | |
+ */ | |
+function fn_store_shipping_rates($order_id = 0, &$cart, $customer_auth) | |
+{ | |
+ fn_set_hook('store_shipping_rates_pre', $order_id, $cart, $customer_auth); | |
+ if (!empty($cart['product_groups'])) { | |
+ foreach ($cart['product_groups'] as $group_key => $group) { | |
+ if (!empty($group['chosen_shippings'])) { | |
+ foreach ($group['chosen_shippings'] as $shipping_key => $shipping) { | |
+ if (!empty($shipping['stored_shipping']) && empty($cart['stored_shipping'][$group_key][$shipping_key])) { | |
+ $cart['stored_shipping'][$group_key][$shipping_key] = $shipping['rate']; | |
+ } | |
+ } | |
+ } | |
+ } | |
+ } | |
+ fn_set_hook('store_shipping_rates_post', $order_id, $cart, $customer_auth); | |
+} | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment