Skip to content

Commit 6e4a4b2

Browse files
Krzysztof Wolowskikrzysztof-wolowski
Krzysztof Wolowski
authored andcommitted
Fix table rate failing for zip+4 address #17770
1 parent 34ee561 commit 6e4a4b2

File tree

1 file changed

+17
-1
lines changed
  • app/code/Magento/OfflineShipping/Model/ResourceModel/Carrier/Tablerate

1 file changed

+17
-1
lines changed

app/code/Magento/OfflineShipping/Model/ResourceModel/Carrier/Tablerate/RateQuery.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function prepareSelect(\Magento\Framework\DB\Select $select)
4242
') OR (',
4343
[
4444
"dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode",
45+
"dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode_prefix",
4546
"dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''",
4647

4748
// Handle asterisk in dest_zip field
@@ -51,7 +52,7 @@ public function prepareSelect(\Magento\Framework\DB\Select $select)
5152
"dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = '*'",
5253
"dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''",
5354
"dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode",
54-
"dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'"
55+
"dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode_prefix"
5556
]
5657
) . ')';
5758
$select->where($orWhere);
@@ -85,6 +86,7 @@ public function getBindings()
8586
':country_id' => $this->request->getDestCountryId(),
8687
':region_id' => (int)$this->request->getDestRegionId(),
8788
':postcode' => $this->request->getDestPostcode(),
89+
':postcode_prefix' => $this->getDestPostcodePrefix()
8890
];
8991

9092
// Render condition by condition name
@@ -112,4 +114,18 @@ public function getRequest()
112114
{
113115
return $this->request;
114116
}
117+
118+
/**
119+
* Returns the entire postcode if it contains no dash
120+
* or the part of it prior to the dash in the other case
121+
* @return string
122+
*/
123+
private function getDestPostcodePrefix()
124+
{
125+
if (!preg_match("/^(.+)-(.+)$/", $this->request->getDestPostcode(), $zipParts)) {
126+
return $this->request->getDestPostcode();
127+
}
128+
129+
return $zipParts[1];
130+
}
115131
}

0 commit comments

Comments
 (0)