Page MenuHomeIn-Portal Phabricator

D348.diff
No OneTemporary

File Metadata

Created
Fri, Jun 13, 6:01 PM

D348.diff

Index: branches/5.2.x/units/shipping_quote_engines/shipping_quote_collector.php
===================================================================
--- branches/5.2.x/units/shipping_quote_engines/shipping_quote_collector.php
+++ branches/5.2.x/units/shipping_quote_engines/shipping_quote_collector.php
@@ -60,30 +60,8 @@
// exclude not available shipping quotes by products
$limit_types = unserialize($params['limit_types']);
- if (is_array($limit_types) && !in_array('ANY', $limit_types)) {
- if (count($limit_types) == 0) {
- break;
- }
-
- $available_types = Array ();
- foreach ($shipping_types as $a_type) {
- $include = false; // exclude by default
-
- foreach ($limit_types as $limit) {
- $include = $include || preg_match("/^$limit/", $a_type['ShippingId']);
- if ($include) {
- break;
- }
- }
-
- if (!$include) {
- continue;
- }
-
- $available_types[ $a_type['ShippingId'] ] = $a_type;
- }
-
- $shipping_types = $available_types;
+ if ( is_array($limit_types) && count($limit_types) && !in_array('ANY', $limit_types) ) {
+ $shipping_types = $this->applyLimitations($shipping_types, $limit_types);
}
// exclude Selected Products Only shipping types, not matching products
@@ -108,6 +86,39 @@
return $shipping_types;
}
+ /**
+ * Applies limitations to shipping types
+ *
+ * @param array $shipping_types Shipping types.
+ * @param array $limit_types Limit types.
+ *
+ * @return array
+ */
+ protected function applyLimitations(array $shipping_types, array $limit_types)
+ {
+ $available_types = array();
+
+ foreach ( $shipping_types as $a_type ) {
+ $include = false; // Exclude by default.
+
+ foreach ( $limit_types as $limit ) {
+ $include = $include || preg_match('/^' . $limit . '/', $a_type['ShippingId']);
+
+ if ( $include ) {
+ break;
+ }
+ }
+
+ if ( !$include ) {
+ continue;
+ }
+
+ $available_types[$a_type['ShippingId']] = $a_type;
+ }
+
+ return $available_types;
+ }
+
function GetAvailableShippingTypes()
{
$shipping_types = Array ();

Event Timeline