Skip to content

Commit

Permalink
ENGCOM-3057: Fix table rate failing for zip+4 address #17770 #18166
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Idolov authored Oct 9, 2018
2 parents f0cc492 + aa65cf9 commit 744344a
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function prepareSelect(\Magento\Framework\DB\Select $select)
') OR (',
[
"dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode",
"dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode_prefix",
"dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''",

// Handle asterisk in dest_zip field
Expand All @@ -51,7 +52,7 @@ public function prepareSelect(\Magento\Framework\DB\Select $select)
"dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = '*'",
"dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''",
"dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode",
"dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = '*'"
"dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode_prefix"
]
) . ')';
$select->where($orWhere);
Expand Down Expand Up @@ -85,6 +86,7 @@ public function getBindings()
':country_id' => $this->request->getDestCountryId(),
':region_id' => (int)$this->request->getDestRegionId(),
':postcode' => $this->request->getDestPostcode(),
':postcode_prefix' => $this->getDestPostcodePrefix()
];

// Render condition by condition name
Expand Down Expand Up @@ -112,4 +114,18 @@ public function getRequest()
{
return $this->request;
}

/**
* Returns the entire postcode if it contains no dash
* or the part of it prior to the dash in the other case
* @return string
*/
private function getDestPostcodePrefix()
{
if (!preg_match("/^(.+)-(.+)$/", $this->request->getDestPostcode(), $zipParts)) {
return $this->request->getDestPostcode();
}

return $zipParts[1];
}
}

0 comments on commit 744344a

Please sign in to comment.