@@ -42,6 +42,7 @@ public function prepareSelect(\Magento\Framework\DB\Select $select)
42
42
') OR ( ' ,
43
43
[
44
44
"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 " ,
45
46
"dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = '' " ,
46
47
47
48
// Handle asterisk in dest_zip field
@@ -51,7 +52,7 @@ public function prepareSelect(\Magento\Framework\DB\Select $select)
51
52
"dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = '*' " ,
52
53
"dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '' " ,
53
54
"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 "
55
56
]
56
57
) . ') ' ;
57
58
$ select ->where ($ orWhere );
@@ -85,6 +86,7 @@ public function getBindings()
85
86
':country_id ' => $ this ->request ->getDestCountryId (),
86
87
':region_id ' => (int )$ this ->request ->getDestRegionId (),
87
88
':postcode ' => $ this ->request ->getDestPostcode (),
89
+ ':postcode_prefix ' => $ this ->getDestPostcodePrefix ()
88
90
];
89
91
90
92
// Render condition by condition name
@@ -112,4 +114,18 @@ public function getRequest()
112
114
{
113
115
return $ this ->request ;
114
116
}
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
+ }
115
131
}
0 commit comments