Magento - 使用 IP 地址按国家/地区划分的产品

发布于 2024-11-10 06:11:10 字数 494 浏览 8 评论 0原文

我想添加一个单选按钮,其中包含以下选项

“显示产品”

> United States
> International
> Both

选择后,产品将使用 IP 检测在前端为适当的客户显示

我用 google 搜索,发现一个插件

http://www.magentocommerce.com/magento-connect/Vinay.N+%28+Tumkur%2CKethohalli%29/extension/2413/product-by-ipaddress

但它不兼容与 Magento 版本。 1.5.0.1。请帮忙。谢谢

I want to add a radio button with the following option

Show product in

> United States
> International
> Both

Upon selection the product will show on the front end for the appropriate customers using IP detection

I google it and i found one plugin

http://www.magentocommerce.com/magento-connect/Vinay.N+%28+Tumkur%2CKethohalli%29/extension/2413/product-by-ipaddress

But it is not compatible with Magento ver. 1.5.0.1. Please help. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄情伤 2024-11-17 06:11:10

为您的商店设置两个网站,其中“网站”不一定意味着不同的 URL,只是在 Magento 内部它是一个“网站”。对于此示例,请使用代码“usd”和“row”。

如果您可以在发行版上安装软件包,请在 Apache 中使用 GeoIP。如果没有,那么您可以使用 PHP geoip 插件 - 再次查看为您的设置推荐的内容。

将您的客户引导至 Magento 认为的网站,而网站访问者不知道他们已被“重定向”。在您的index.php中,您将需要类似的内容:

$country=$_SERVER['GEOIP_COUNTRY_CODE'];
switch ($country)
{ case "CA":
  case "MX":
  case "US":
    $_SERVER['MAGE_RUN_CODE'] = "usd";
    $_SERVER['MAGE_RUN_TYPE'] = "website";
    break;
  default:
    $_SERVER['MAGE_RUN_CODE'] = "row";
    $_SERVER['MAGE_RUN_TYPE'] = "store";
}
Mage::run($_SERVER['MAGE_RUN_CODE'], $_SERVER['MAGE_RUN_TYPE']);

对于您的产品,在网站选项卡中,选择您希望产品显示的网站。根据显示方式,在两个框中或仅在一个框中打勾。

与“黑客”解决方案相比,这将很容易更新。

更新。

运行 GeoIP 最时尚的方式是作为 apache 模块。以下是说明和下载的链接:

http://www.maxmind.com/app/mod_geoip

如果由于共享主机或操作系统不稳定而无法安装 Apache 模块,则可以使用 PHP 模块。 geoIP 的完整说明和下载可以在这里找到:

http://www.maxmind.com/app/php< /a>

安装后交换 $country=$_SERVER['GEOIP_COUNTRY_CODE'];对于以下内容:

include("geoip/geoip.inc");

// Uncomment if querying against GeoIP/Lite City.
// include("geoipcity.inc");

$gi = geoip_open("/your/path/to/geoip/GeoIP.dat",GEOIP_STANDARD);
$country=geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);

可以从上述链接获得有关 GeoIP 的更多帮助。

Setup two websites for your shop, where 'website' does not have to mean a different URL, just, internally for Magento it is a 'website'. For this example use codes 'usd' and 'row'.

Use GeoIP in Apache if you can install packages on your distro. If not then you can use PHP geoip plugins - again see what is recommended for your setup.

To send your customers to what Magento thinks is a website, with the site visitor not knowing they have been 'redirected'. In your index.php you will need something like:

$country=$_SERVER['GEOIP_COUNTRY_CODE'];
switch ($country)
{ case "CA":
  case "MX":
  case "US":
    $_SERVER['MAGE_RUN_CODE'] = "usd";
    $_SERVER['MAGE_RUN_TYPE'] = "website";
    break;
  default:
    $_SERVER['MAGE_RUN_CODE'] = "row";
    $_SERVER['MAGE_RUN_TYPE'] = "store";
}
Mage::run($_SERVER['MAGE_RUN_CODE'], $_SERVER['MAGE_RUN_TYPE']);

For your products, in the website tab, select the websites that you want the product to show in. Put a tick in both boxes or just one depending on how it is to show.

This will be easy to update compared to a 'hacked' solution.

Update.

The sleekest way to run GeoIP is as an apache module. Here is the link to the instructions and download:

http://www.maxmind.com/app/mod_geoip

If installing an Apache module is not possible due to shared hosting or operating system flakiness then the PHP module can be used instead. Full instructions and download for geoIP can be found here:

http://www.maxmind.com/app/php

Once installed swap out $country=$_SERVER['GEOIP_COUNTRY_CODE']; for the following:

include("geoip/geoip.inc");

// Uncomment if querying against GeoIP/Lite City.
// include("geoipcity.inc");

$gi = geoip_open("/your/path/to/geoip/GeoIP.dat",GEOIP_STANDARD);
$country=geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);

More help on GeoIP is available from the above links.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文