Skip to content

Commit ac9bbae

Browse files
Catch exception when invalid country_id is submitted in estimate ship… (#4427)
* Catch exception when invalid country_id is submitted in estimate shipping action. Fixes #4417 * phpstan --------- Co-authored-by: Sven Reichel <github-sr@hotmail.com>
1 parent 10ed208 commit ac9bbae

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

.phpstan.dist.baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,11 +3415,6 @@ parameters:
34153415
count: 2
34163416
path: app/code/core/Mage/Directory/Model/Observer.php
34173417

3418-
-
3419-
message: "#^Parameter \\#2 \\$countryId of method Mage_Directory_Model_Resource_Region\\:\\:_loadByCountry\\(\\) expects int, string given\\.$#"
3420-
count: 2
3421-
path: app/code/core/Mage/Directory/Model/Resource/Region.php
3422-
34233418
-
34243419
message: "#^Left side of && is always true\\.$#"
34253420
count: 1

app/code/core/Mage/Checkout/controllers/CartController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,14 @@ public function estimatePostAction()
533533
$regionId = (string) $this->getRequest()->getParam('region_id');
534534
$region = (string) $this->getRequest()->getParam('region');
535535

536+
try {
537+
Mage::getModel('directory/country')->loadByCode($country);
538+
} catch (Mage_Core_Exception $e) {
539+
$this->_getSession()->addError($e->getMessage());
540+
$this->_goBack();
541+
return;
542+
}
543+
536544
$this->_getQuote()->getShippingAddress()
537545
->setCountryId($country)
538546
->setCity($city)

app/code/core/Mage/Directory/Model/Resource/Region.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function _getLoadSelect($field, $value, $object)
8484
* Load object by country id and code or default name
8585
*
8686
* @param Mage_Core_Model_Abstract $object
87-
* @param int $countryId
87+
* @param string $countryId
8888
* @param string $value
8989
* @param string $field
9090
*

0 commit comments

Comments
 (0)