Skip to content

Instantly share code, notes, and snippets.

@torunar
Created September 30, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torunar/5fc033b576e1c93e6639 to your computer and use it in GitHub Desktop.
Save torunar/5fc033b576e1c93e6639 to your computer and use it in GitHub Desktop.
diff --git a/app/addons/suppliers/func.php b/app/addons/suppliers/func.php
index 724e6ce..f738b91 100644
--- a/app/addons/suppliers/func.php
+++ b/app/addons/suppliers/func.php
@@ -517,16 +517,36 @@ function fn_suppliers_update_shipping_post(&$shipping_data, &$shipping_id, &$lan
*/
function fn_suppliers_shippings_group_products_list(&$products, &$groups)
{
- if (Registry::get('addons.suppliers.display_shipping_methods_separately') == 'N') {
- return;
- }
+ $separated_shippings_disabled = Registry::get('addons.suppliers.display_shipping_methods_separately') == 'N';
+
+ $stored_supplier_ids = array();
+ $common_supplier_shippings = array();
$suppliers = array();
$suppliers_groups = array();
foreach ($groups as $group) {
foreach ($group['products'] as $cart_id => $product) {
$supplier_id = fn_get_product_supplier_id($product['product_id']);
- $suppliers_group_key = $supplier_id ? $group['company_id'] . "_" . $supplier_id : $group['company_id'];
+ // check if products in group are dedicated to different suppliers that don't have common shippings
+ if ($separated_shippings_disabled) {
+ if (array_search($supplier_id, $stored_supplier_ids) === false) {
+ $stored_supplier_ids[] = $supplier_id;
+ $supplier_shippings = fn_get_supplier_shippings($supplier_id);
+ if (empty($common_supplier_shippings)) {
+ $common_supplier_shippings = $supplier_shippings;
+ } else {
+ $common_supplier_shippings = array_intersect($common_supplier_shippings, $supplier_shippings);
+ if (empty($common_supplier_shippings)) {
+ return;
+ }
+ }
+ }
+
+ $suppliers_group_key = $group['company_id'];
+ } else {
+ $suppliers_group_key = $supplier_id ? $group['company_id'] . "_" . $supplier_id : $group['company_id'];
+ }
+
if (empty($suppliers_groups[$suppliers_group_key]) && $supplier_id) {
$supplier_data = fn_get_supplier_data($supplier_id);
$origination_data = array(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment