Skip to content

Commit 9b52744

Browse files
authored
Fixed unable to select "free method" in UPS backend configuration (#4005)
1 parent 9199b82 commit 9b52744

File tree

3 files changed

+19
-9
lines changed
  • app
    • code/core/Mage/Usa/Model/Shipping/Carrier
    • design/adminhtml/default/default/template/system/shipping

3 files changed

+19
-9
lines changed

app/code/core/Mage/Usa/Model/Shipping/Carrier/Abstract/Backend/Abstract.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,13 @@ protected function _beforeSave()
6868
if (!method_exists($sourceModel, 'toOptionArray')) {
6969
Mage::throwException(Mage::helper('usa')->__('Method toOptionArray not found in source model.'));
7070
}
71-
$hasCorrectValue = false;
7271
$value = $this->getValue();
7372
foreach ($sourceModel->toOptionArray() as $allowedValue) {
7473
if (isset($allowedValue['value']) && $allowedValue['value'] == $value) {
75-
$hasCorrectValue = true;
76-
break;
74+
return $this;
7775
}
7876
}
79-
if (!$hasCorrectValue) {
80-
Mage::throwException(Mage::helper('usa')->__('Field "%s" has wrong value.', $this->_nameErrorField));
81-
}
82-
return $this;
77+
78+
Mage::throwException(Mage::helper('usa')->__('Field "%s" has wrong value.', $this->_nameErrorField));
8379
}
8480
}

app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups/Source/Method.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,20 @@ public function toOptionArray()
2323
{
2424
$ups = Mage::getSingleton('usa/shipping_carrier_ups');
2525
$arr = [];
26+
27+
// necessary after the add of Rest API
28+
$origins = $ups->getCode('originShipment');
29+
foreach ($origins as $origin) {
30+
foreach ($origin as $k => $v) {
31+
$arr[] = ['value' => $k, 'label' => Mage::helper('usa')->__($v)];
32+
}
33+
}
34+
35+
// old XML API codes
2636
foreach ($ups->getCode('method') as $k => $v) {
2737
$arr[] = ['value' => $k, 'label' => Mage::helper('usa')->__($v)];
2838
}
39+
2940
return $arr;
3041
}
3142
}

app/design/adminhtml/default/default/template/system/shipping/ups.phtml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
$upsModel = Mage::getSingleton('usa/shipping_carrier_ups');
1818
$orShipArr = $upsModel->getCode('originShipment');
1919
$defShipArr = $upsModel->getCode('method');
20-
20+
$allMethodsCodes = [];
21+
foreach (Mage::getModel('usa/shipping_carrier_ups_source_method')->toOptionArray() as $method) {
22+
$allMethodsCodes[]= $method['value'];
23+
}
2124
/** @var $this Mage_Adminhtml_Block_Template */
2225
$sectionCode = $this->getRequest()->getParam('section');
2326
$websiteCode = $this->getRequest()->getParam('website');
@@ -44,7 +47,7 @@ if (!$storeCode && $websiteCode) {
4447
if (!in_array($storedOriginShipment, array_keys($orShipArr))) {
4548
$storedOriginShipment = '';
4649
}
47-
if ($storedFreeShipment != '' && !in_array($storedFreeShipment, array_keys($defShipArr))) {
50+
if ($storedFreeShipment != '' && !in_array($storedFreeShipment, $allMethodsCodes)) {
4851
$storedFreeShipment = '';
4952
}
5053
if (!Mage::helper('usa')->validateUpsType($storedUpsType)) {

0 commit comments

Comments
 (0)