在 magento 2 中,邮政编码文本框用于搜索可用或不可用的商店
In magento 2, zip code text box to search the store available or not
我是 Magento 新手。
我想要一个文本框,我可以在其中输入邮政编码,如果该位置有商店,那么我需要显示该特定商店的产品,否则我们需要显示 "the store is not available in particular location".
以下是示例站点。我想要它的原样。
此站点提示用户输入 zip 位置。之后它将显示该特定商店。
Click on this link to see the working example
我该怎么做。我需要安装模块吗?
遵循一些步骤:
You need an entity 'store' that is bound to a geo location.
You need to create a multi select attribute which values are located (using a
source model) with these stores. This way, you can attach a single product to
multiple stores (one to many relation)
Then you need some sort of external API to convert a postcode entered by the
customer to a geo location. I assume the Google Maps API can do this. It would
be best to handle this server side.
Then you need the math to calculate the distance between 2 geo locations in
your database query (probably enough to find on that subject on Google) and
filter your product collection on that.
Once you have the collection you have the power.
The external API will probably have a request threshold so you might have to
pay for that (depending on the traffic).
You need to determine the radius of maximum distance between 2 geo locations.
In a small country like the Netherlands stores could be a couple of km's apart
from each other, whilst in the United States it's not uncommon to have stores
tens or hundreds of km's from each other.
**Best Of Luck For Your Project**
我是 Magento 新手。
我想要一个文本框,我可以在其中输入邮政编码,如果该位置有商店,那么我需要显示该特定商店的产品,否则我们需要显示 "the store is not available in particular location".
以下是示例站点。我想要它的原样。 此站点提示用户输入 zip 位置。之后它将显示该特定商店。
Click on this link to see the working example
我该怎么做。我需要安装模块吗?
遵循一些步骤:
You need an entity 'store' that is bound to a geo location.
You need to create a multi select attribute which values are located (using a source model) with these stores. This way, you can attach a single product to multiple stores (one to many relation)
Then you need some sort of external API to convert a postcode entered by the customer to a geo location. I assume the Google Maps API can do this. It would be best to handle this server side.
Then you need the math to calculate the distance between 2 geo locations in your database query (probably enough to find on that subject on Google) and filter your product collection on that.
Once you have the collection you have the power.
The external API will probably have a request threshold so you might have to pay for that (depending on the traffic).
You need to determine the radius of maximum distance between 2 geo locations. In a small country like the Netherlands stores could be a couple of km's apart from each other, whilst in the United States it's not uncommon to have stores tens or hundreds of km's from each other.
**Best Of Luck For Your Project**