2013-05-02 35 views
-1

我有我的购物车代码(Magento的1.6.2)腓如果选择按产地访问者(IP地址)

<?php if ($this->getQuote()->getSubtotal() < 41.28): ?> 
<?php $subtotalamt = $this->getQuote()->getSubtotal(); ?> 
<?php $freeshipamt = 41.28; ?> 
<?php $sumtotal = ($freeshipamt - $subtotalamt)* 1.21; ?> 
<?php Mage::helper('checkout')->formatPrice($sumtotal); ?> 
<p>Gratis verzending vanaf € 49,95 <br/>(binnen Nederland)</p><p> 
<strong>Nog <span>€ <?php print number_format($sumtotal, 2, ',', ' '); ?></span> 
tot gratis verzending!</strong></p> 
<?php else: ?><p><strong>Uw bestelling wordt GRATIS verzonden!</strong> <br/>(binnen Nederland)</p> 
<?php endif ?> 
<?php /* You are just <span>$<?php print ($sumtotal); ?></span> away from earning free shipping!</p> */ ?> 

此代码计算客户在荷兰境内免运费所需金额。

有没有办法添加一些代码,所以当一个来自其他国家的访客访问我们的网上商店的金额改变了免费送货。像德国或比利时一样。他们从149,95收到免费送货。

我想应该有一个php if whick可以确定访问者ip-adress的来源。 任何人都可以帮我设置这个吗?

+0

可能的重复[如何从IP地址中获取国家/地区名称](http://stackoverflow.com/questions/4191489/how-to-get-country-name-from-ip-address-in-php ) – Quentin 2013-05-02 11:16:08

回答

0

这是一些IP到国家的数据库和API。的API可能工作得很好,但你会为此付出一些钱,他们...

把你的时间来检查这个PHP类+ DB:

https://github.com/magorski/php-ip-2-country

PS:也许区议会并非如此不好,现在我在一个真正的系统上使用了一个PHP类,它有一个简单的数据库来完成这个工作,并且比我指出的那个小得多。 (也许不那么精确或什么)。