Php “显示”;免费送货文本“;启用免费送货价格规则时
已经在本论坛和朋友的帮助下制作了一个脚本,如:Php “显示”;免费送货文本“;启用免费送货价格规则时,php,magento,Php,Magento,已经在本论坛和朋友的帮助下制作了一个脚本,如: <?php // Determine if product "free shipping" is true if ($_product->getFreeShipping()) { echo '<span class="freeShip">'.$_product->getAttributeText('free_shipping').'</span>'; } // Determine if produc
<?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($\u product->$rule->getName()=免费送货规则)
{
echo“本产品免费送货!”;
}
使用此帖子中的信息完成此操作:
如果你看到我可以改变的东西,或者我可以做些什么来让它工作,请让我知道!谢谢
编辑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>';
}
?>
您的代码中的这些部分有bug
// Determine if product costs more than 65
else if ($_specialPrice = $_product->getFinalPrice() > 65)
{
echo '<span class="freeShip">FREE SHIPPING ON THIS PRODUCT!</span>';
}
//确定产品成本是否超过65%
否则如果($\u specialPrice=$\u product->getFinalPrice()>65)
{
echo“本产品免费送货!”;
}
您正在使用=
,这是一项分配(返回true),因此无论最终价格如何,它都将显示此产品的免费配送!
同样适用于
if($\u product->$rule->getName()=免费送货规则)
只是对您的编码风格的一点评论:请选择语言,荷兰语或英语,但不要两者兼而有之。最好选择英语,以防出现这种情况,这样不会说荷兰语的人会真正理解您的意思。谢谢您的评论!好的,我理解。只是将所有内容翻译成英语。我不知道“我不明白,您想查看规则是否已启用或是否适用于此产品?谢谢您的评论。我想查看规则是否适用于此产品,以及当它应用于某个产品时,它必须在产品列表中的某个产品内以文本形式显示“免费送货”。在Magento目录价格规则中,您可以将选项“免费送货”设置为”是的。当设置为“是”时,产品下方应显示文本“此产品免费送货”。谢谢您的评论。这很奇怪?代码现在已经起作用了?问题是,当产品免费送货时,例如价格规则,也应显示“此产品免费送货”!“已显示。现在仅当价格高于65欧元,或产品的“免费送货”属性设置为“是”时才会显示。编辑了startpost。您能看一下吗?有什么进一步的想法吗?现在无法使其工作。
// Determine if product costs more than 65
else if ($_specialPrice = $_product->getFinalPrice() > 65)
{
echo '<span class="freeShip">FREE SHIPPING ON THIS PRODUCT!</span>';
}