SettingsModel::getRegionByCountry()` Returns No Shipping Methods When Region States Are Configured
- Product: JoomShaper EasyStore (
com_easystore) - Product Version:
3.1.1 - Joomla Version:
6.2.0(PHP8.4) - File:
components/com_easystore/src/Model/SettingsModel.php(getRegionByCountry(), lines 79-99)
What the Bug Is
When a store administrator configures a shipping region for a country and selects specific states ($value->states is non-empty), SettingsModel::getRegion($shipping, $country, $state) calls getRegionByCountry($shipping, $country) when $state is empty on initial checkout page load. getRegionByCountry() requires empty($value->states) on line 86, so it returns null (data: []) whenever states are configured for that country, preventing shipping methods from loading until states is emptied in the database.
How to Reproduce It
- In EasyStore Settings -> Shipping, configure a shipping region for United States (
840) with one or more states selected and an enabled shipping method. - Add a product to the cart and open
/component/easystore/checkout(or callGET /index.php?option=com_easystore&task=checkout.getShipping&country=840). - The endpoint returns
{"status":"success","data":[]}because$stateis not passed on initial load andgetRegionByCountry()rejects any region where!empty($value->states).
Fix (Unified Patch Against Clean com_easystore 3.1.1)
--- a/components/com_easystore/src/Model/SettingsModel.php
+++ b/components/com_easystore/src/Model/SettingsModel.php
@@ -80,12 +80,20 @@
{
$region = null;
+ $fallbackRegion = null;
+
foreach ($shipping as $item) {
if (!empty($item->regions)) {
foreach ($item->regions as $value) {
- if ($value->country == $country && empty($value->states)) {
- $region = $item;
- break;
+ if ($value->country == $country) {
+ if (empty($value->states)) {
+ $region = $item;
+ break;
+ }
+
+ if ($fallbackRegion === null) {
+ $fallbackRegion = $item;
+ }
}
}
}
@@ -95,7 +103,7 @@
}
}
- return $region;
+ return $region ?? $fallbackRegion;
}
private function isRegionMatched($region, $country, $state)