Skip to content

Commit

Permalink
Fixed unable to select "free method" in UPS backend configuration (#4005
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fballiano authored May 27, 2024
1 parent 9199b82 commit 9b52744
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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)) {
Expand Down

0 comments on commit 9b52744

Please sign in to comment.