Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = '*'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering why did you remove the line with the star?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at lines 49 and 54 in original code, you will see that there were two identical conditions in this OR statement. So we removed one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magently yes, I missed that. You are right

"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];
}
}