Skip to content

Commit

Permalink
Catch exception when invalid country_id is submitted in estimate ship… (
Browse files Browse the repository at this point in the history
#4427)

* Catch exception when invalid country_id is submitted in estimate shipping action. Fixes #4417

* phpstan

---------

Co-authored-by: Sven Reichel <[email protected]>
  • Loading branch information
colinmollenhour and sreichel authored Dec 28, 2024
1 parent 10ed208 commit ac9bbae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 0 additions & 5 deletions .phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3415,11 +3415,6 @@ parameters:
count: 2
path: app/code/core/Mage/Directory/Model/Observer.php

-
message: "#^Parameter \\#2 \\$countryId of method Mage_Directory_Model_Resource_Region\\:\\:_loadByCountry\\(\\) expects int, string given\\.$#"
count: 2
path: app/code/core/Mage/Directory/Model/Resource/Region.php

-
message: "#^Left side of && is always true\\.$#"
count: 1
Expand Down
8 changes: 8 additions & 0 deletions app/code/core/Mage/Checkout/controllers/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,14 @@ public function estimatePostAction()
$regionId = (string) $this->getRequest()->getParam('region_id');
$region = (string) $this->getRequest()->getParam('region');

try {
Mage::getModel('directory/country')->loadByCode($country);
} catch (Mage_Core_Exception $e) {
$this->_getSession()->addError($e->getMessage());
$this->_goBack();
return;
}

$this->_getQuote()->getShippingAddress()
->setCountryId($country)
->setCity($city)
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Directory/Model/Resource/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function _getLoadSelect($field, $value, $object)
* Load object by country id and code or default name
*
* @param Mage_Core_Model_Abstract $object
* @param int $countryId
* @param string $countryId
* @param string $value
* @param string $field
*
Expand Down

0 comments on commit ac9bbae

Please sign in to comment.