显示";免费送货文本";启用免费运费规则时


Show "Free Shipping text" when free shipping price rule is enabled

已经在这个论坛和朋友的帮助下制作了一个脚本,比如:

 <?php
 // Determine if product "free shipping" is true
if ($_product->getFreeShipping())
{
echo '<span class="freeShip">'.$_product->getAttributeText('free_shipping').'</span>';
}
 // Determine if product costs more than 65
else if ($_specialPrice = $_product->getFinalPrice() > 65)
{
echo '<span class="freeShip">FREE SHIPPING ON THIS PRODUCT!</span>';
}
?>

这非常有效,但现在我也想在启用名为"免费送货规则"的价格规则时显示"此产品免费送货"文本。这个价格规则确保了选择的产品可以免费送货。

我已经制作了一个简短的代码,但不知道如何进一步。//加载规则对象$rule=Mage::getModel('catalogrule/rule'(->load($ruleID(;

        if ($_product->$rule->getName() = Free Shipping Rule)
        {
        echo '<span class="freeShip">FREE SHIPPING ON THIS PRODUCT!</span>';
        }

完成这与此帖子的信息:Magento-从订单获得价格规则

如果你看到我可以改变的东西,或者我可以做些什么来让它发挥作用,请告诉我!谢谢

编辑1:我想我们在获得有关运费的信息时也可以这样做。我想了一些类似"如果运费=0,显示"免费送货在这个产品"。刚刚在互联网上找到了一些东西,并编辑了一些。你认为这个代码会工作吗?

<?php
if($_product->isSaleable())
{
$quote = Mage::getModel('sales/quote');
$quote->getShippingAddress()->setCountryId('*');
$quote->addProduct($_product);
$quote->getShippingAddress()->collectTotals();
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->getShippingAddress()->collectShippingRates();
$rates = $quote->getShippingAddress()->getShippingRatesCollection();
foreach ($rates as $rate)
}
// Check the product shipping price
php if ($rate->getPrice() == 0)
{
echo '<span class="freeShip">FREE SHIPPING ON THIS PRODUCT!</span>';
}
?>

编辑2:将代码编辑到下面,但仍然不起作用。看起来很好,不是吗?

<?php
 // Determine if product "free shipping" is true
if ($_product->getGratisVerzending())
{
echo '<span class="freeShip">'.$_product->getAttributeText('gratis_verzending').'</span>';
}
 // Determine if product costs more than 65
else if ($_specialPrice = $_product->getFinalPrice() > 65)
{
echo '<span class="freeShip">GRATIS VERZONDEN!</span>';
}
$quote = Mage::getModel('sales/quote');
$quote->getShippingAddress()->setCountryId('*');
$quote->addProduct($_product);
$quote->getShippingAddress()->collectTotals();
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->getShippingAddress()->collectShippingRates();
$rates = $quote->getShippingAddress()->getShippingRatesCollection();
foreach ($rates as $rate)
// Determine if shipping is 0
else if ($rate->getPrice() == 0)
{
echo '<span class="freeShip">FREE SHIPPING ON THIS PRODUCT!</span>';
}
?>

代码的这些部分在中有错误

 // Determine if product costs more than 65
else if ($_specialPrice = $_product->getFinalPrice() > 65)
{
echo '<span class="freeShip">FREE SHIPPING ON THIS PRODUCT!</span>';
}

您使用的是=,这是一个赋值(返回true(,因此无论最终价格如何,它都将显示FREE SHIPPING ON THIS PRODUCT!

同样适用于if ($_product->$rule->getName() = Free Shipping Rule)