diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Abstract/Backend/Abstract.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Abstract/Backend/Abstract.php index aa8c57d3509..689ab84e0f6 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Abstract/Backend/Abstract.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Abstract/Backend/Abstract.php @@ -68,17 +68,13 @@ protected function _beforeSave() if (!method_exists($sourceModel, 'toOptionArray')) { Mage::throwException(Mage::helper('usa')->__('Method toOptionArray not found in source model.')); } - $hasCorrectValue = false; $value = $this->getValue(); foreach ($sourceModel->toOptionArray() as $allowedValue) { if (isset($allowedValue['value']) && $allowedValue['value'] == $value) { - $hasCorrectValue = true; - break; + return $this; } } - if (!$hasCorrectValue) { - Mage::throwException(Mage::helper('usa')->__('Field "%s" has wrong value.', $this->_nameErrorField)); - } - return $this; + + Mage::throwException(Mage::helper('usa')->__('Field "%s" has wrong value.', $this->_nameErrorField)); } } diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Method.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Method.php index 8f00799af02..64805ad8261 100644 --- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Method.php +++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Method.php @@ -23,9 +23,20 @@ public function toOptionArray() { $ups = Mage::getSingleton('usa/shipping_carrier_ups'); $arr = []; + + // necessary after the add of Rest API + $origins = $ups->getCode('originShipment'); + foreach ($origins as $origin) { + foreach ($origin as $k => $v) { + $arr[] = ['value' => $k, 'label' => Mage::helper('usa')->__($v)]; + } + } + + // old XML API codes foreach ($ups->getCode('method') as $k => $v) { $arr[] = ['value' => $k, 'label' => Mage::helper('usa')->__($v)]; } + return $arr; } } diff --git a/app/design/adminhtml/default/default/template/system/shipping/ups.phtml b/app/design/adminhtml/default/default/template/system/shipping/ups.phtml index f5a12706977..528dbb93987 100644 --- a/app/design/adminhtml/default/default/template/system/shipping/ups.phtml +++ b/app/design/adminhtml/default/default/template/system/shipping/ups.phtml @@ -17,7 +17,10 @@ $upsModel = Mage::getSingleton('usa/shipping_carrier_ups'); $orShipArr = $upsModel->getCode('originShipment'); $defShipArr = $upsModel->getCode('method'); - +$allMethodsCodes = []; +foreach (Mage::getModel('usa/shipping_carrier_ups_source_method')->toOptionArray() as $method) { + $allMethodsCodes[]= $method['value']; +} /** @var $this Mage_Adminhtml_Block_Template */ $sectionCode = $this->getRequest()->getParam('section'); $websiteCode = $this->getRequest()->getParam('website'); @@ -44,7 +47,7 @@ if (!$storeCode && $websiteCode) { if (!in_array($storedOriginShipment, array_keys($orShipArr))) { $storedOriginShipment = ''; } -if ($storedFreeShipment != '' && !in_array($storedFreeShipment, array_keys($defShipArr))) { +if ($storedFreeShipment != '' && !in_array($storedFreeShipment, $allMethodsCodes)) { $storedFreeShipment = ''; } if (!Mage::helper('usa')->validateUpsType($storedUpsType)) {