Created
April 10, 2020 12:39
-
-
Save edavydova/0e7eb069ce911d5462a7606d7b1584c3 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/suppliers/func.php b/app/addons/suppliers/func.php | |
index 492d84bd10..26ca94ff79 100644 | |
--- a/app/addons/suppliers/func.php | |
+++ b/app/addons/suppliers/func.php | |
@@ -1204,23 +1204,101 @@ function fn_suppliers_filter_objects_by_sharing( | |
$shared_type, | |
$shared_object_id | |
) { | |
- $shared_object_companies = fn_ult_get_object_shared_companies($shared_type, $shared_object_id); | |
- if (!$shared_object_companies) { | |
+ if ($shared_type === 'shippings') { | |
+ /** @var \Tygh\Storefront\Repository $repository */ | |
+ $repository = Tygh::$app['storefront.repository']; | |
+ list($shipping_storefronts, ) = $repository->find(['shipping_ids' => $shared_object_id]); | |
+ $shared_object_storefront_ids = array_keys($shipping_storefronts); | |
+ } else { | |
+ $shared_object_storefront_ids = fn_suppliers_get_object_storefront_ids($shared_type, $shared_object_id); | |
+ } | |
+ | |
+ if (!$shared_object_storefront_ids) { | |
return []; | |
} | |
- $filtered_list = array_filter( | |
- $objects_list, | |
- function ($source_object) use ($source_id_field, $source_type, $shared_object_companies) { | |
- foreach ($shared_object_companies as $company_id) { | |
- if (fn_ult_is_shared_object($source_type, $source_object[$source_id_field], $company_id)) { | |
- return true; | |
+ if ($source_type === 'shippings') { | |
+ $shippings_ids = array_column($objects_list, 'shipping_id'); | |
+ | |
+ /** @var \Tygh\Storefront\Repository $repository */ | |
+ $repository = Tygh::$app['storefront.repository']; | |
+ list($available_storefronts, ) = $repository->find(['shipping_ids' => $shippings_ids]); | |
+ foreach ($available_storefronts as $storefront_id => $storefront) { | |
+ foreach ($objects_list as &$object) { | |
+ if (in_array($object['shipping_id'], $storefront->getShippingIds())) { | |
+ $object['storefront_ids'][] = $storefront_id; | |
} | |
} | |
- | |
- return false; | |
+ unset($object); | |
} | |
- ); | |
+ } else { | |
+ $object_company_ids = []; | |
+ foreach ($objects_list as $object) { | |
+ $object_company_ids = array_merge( | |
+ $object_company_ids, | |
+ fn_ult_get_object_shared_companies($source_type, $object[$source_id_field]) | |
+ ); | |
+ } | |
+ /** @var \Tygh\Storefront\Repository $repository */ | |
+ $repository = Tygh::$app['storefront.repository']; | |
+ list($available_storefronts, ) = $repository->find(['company_ids' => $object_company_ids]); | |
+ foreach ($available_storefronts as $storefront_id => $storefront) { | |
+ foreach ($objects_list as &$object) { | |
+ if (in_array($object['company_id'], $storefront->getCompanyIds())) { | |
+ $object['storefront_ids'][] = $storefront_id; | |
+ } | |
+ } | |
+ unset($object); | |
+ } | |
+ } | |
+ | |
+ $filtered_list = fn_suppliers_filter_objects_by_storefronts($objects_list, $shared_object_storefront_ids); | |
return $filtered_list; | |
} | |
+ | |
+/** | |
+ * Gets object shared companies and searches storefronts based on them | |
+ * | |
+ * @param string $object_type Type for searching shared companies | |
+ * @param int $object_id Object identifier | |
+ * | |
+ * @return array Storefronts identifies | |
+ */ | |
+function fn_suppliers_get_object_storefront_ids($object_type, $object_id) | |
+{ | |
+ $shared_companies = fn_ult_get_object_shared_companies($object_type, $object_id); | |
+ if (empty($shared_companies)) { | |
+ return []; | |
+ } | |
+ | |
+ /** @var \Tygh\Storefront\Repository $repository */ | |
+ $repository = Tygh::$app['storefront.repository']; | |
+ list($storefronts, ) = $repository->find(['company_ids' => $shared_companies]); | |
+ | |
+ return array_keys($storefronts); | |
+}; | |
+ | |
+/** | |
+ * Filters objects list by its availability for getting storefronts. | |
+ * | |
+ * @param array $objects List of prepared objects each of them contains 'storefront_ids' key for filtering | |
+ * @param array $storefront_ids List of storefronts identifiers | |
+ * | |
+ * @return array List of objects with are fit the condition | |
+ */ | |
+function fn_suppliers_filter_objects_by_storefronts($objects, $storefront_ids) | |
+{ | |
+ return array_filter($objects, function($object) use ($storefront_ids) { | |
+ if (empty($object['storefront_ids'])) { | |
+ return false; | |
+ } | |
+ foreach ($object['storefront_ids'] as $object_storefront_id) { | |
+ if (in_array($object_storefront_id, $storefront_ids)) { | |
+ return true; | |
+ } | |
+ } | |
+ | |
+ return false; | |
+ }); | |
+} | |
\ No newline at end of file |
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/design/backend/templates/addons/suppliers/views/suppliers/update.tpl b/design/backend/templates/addons/suppliers/views/suppliers/update.tpl | |
index 6a92f10127..5f503bf6bf 100644 | |
--- a/design/backend/templates/addons/suppliers/views/suppliers/update.tpl | |
+++ b/design/backend/templates/addons/suppliers/views/suppliers/update.tpl | |
@@ -136,7 +136,7 @@ | |
{include file="pickers/products/picker.tpl" input_name="supplier_data[products]" data_id="supplier_products" item_ids=$supplier.products type="links"} | |
</div> | |
- <div id="content_shippings"> | |
+ <div id="content_shippings" class="hidden"> | |
{hook name="companies:shipping_methods"} | |
{if $shippings} | |
<div class="table-responsive-wrapper"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment