Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/units/shipping_quote_engines/shipping_quote_collector.php
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | |||||
} | } | ||||
} | } | ||||
uasort($shipping_types, Array(&$this, 'price_sort')); | uasort($shipping_types, Array(&$this, 'price_sort')); | ||||
// exclude not available shipping quotes by products | // exclude not available shipping quotes by products | ||||
$limit_types = unserialize($params['limit_types']); | $limit_types = unserialize($params['limit_types']); | ||||
if (is_array($limit_types) && !in_array('ANY', $limit_types)) { | if ( is_array($limit_types) && count($limit_types) && !in_array('ANY', $limit_types) ) { | ||||
if (count($limit_types) == 0) { | $shipping_types = $this->applyLimitations($shipping_types, $limit_types); | ||||
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; | |||||
} | } | ||||
// exclude Selected Products Only shipping types, not matching products | // exclude Selected Products Only shipping types, not matching products | ||||
$available_types = Array(); | $available_types = Array(); | ||||
foreach ($shipping_types as $a_type) { | foreach ($shipping_types as $a_type) { | ||||
if (getArrayValue($a_type, 'SelectedOnly')) { | if (getArrayValue($a_type, 'SelectedOnly')) { | ||||
if (!is_array($limit_types) || !in_array($a_type['ShippingId'], $limit_types)) { | if (!is_array($limit_types) || !in_array($a_type['ShippingId'], $limit_types)) { | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
$available_types[ $a_type['ShippingId'] ] = $a_type; | $available_types[ $a_type['ShippingId'] ] = $a_type; | ||||
} | } | ||||
$shipping_types = $available_types; | $shipping_types = $available_types; | ||||
if ($quotes_valid) { | if ($quotes_valid) { | ||||
$this->Application->setDBCache($cached_var_name, serialize($shipping_types), 24 * 3600); | $this->Application->setDBCache($cached_var_name, serialize($shipping_types), 24 * 3600); | ||||
} | } | ||||
return $shipping_types; | 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() | function GetAvailableShippingTypes() | ||||
{ | { | ||||
$shipping_types = Array (); | $shipping_types = Array (); | ||||
$classes = $this->getEngineClasses(); | $classes = $this->getEngineClasses(); | ||||
foreach ($classes as $class) { | foreach ($classes as $class) { | ||||
/** @var ShippingQuoteEngine $object */ | /** @var ShippingQuoteEngine $object */ | ||||
$object = $this->Application->recallObject($class); | $object = $this->Application->recallObject($class); | ||||
▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines |