已经在这个论坛和朋友的帮助下制作了一个脚本,比如:
<?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>';
}
?>