1
votes

Already made a script with help from this forum and friends, like:

 <?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>';
}
?>

This works perfectly, but now I want also to show the "FREE SHIPPING ON THIS PRODUCT" text when a price rule called "Free Shipping Rule" is enabled. This price rule ensures that a selection of products gets free shipping.

I already made a short code, but don't know how to go further. //Load the rule object $rule = Mage::getModel('catalogrule/rule')->load($ruleID);

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

Done this with information from this post: Magento - get price rules from order

If you see something that I can change, or what I can do to make it work, please let me know! Thanks!

EDIT 1: I thought we can also do this when getting information about the shipping cost. I thought something like "If shipping cost = 0, display "FREE SHIPPING ON THIS PRODUCT". Just found something on the internet, and edited a bit. Do you think this code will work?

<?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>';
}
?>

EDIT 2: Edited the code to below, but still doesn't work. Looks like the is well, isn't it?

<?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>';
}

?>
1
Just a comment to your coding style: please choose language, either Dutch or English, but not a mix of both. It is best to choose English, just for in cases like this, so somebody who doesn't speak Dutch will actually understand what you are saying. - Jelmer
Thank you for your comment! Ok, I understand. Just translated everything to English. - user1681144
I don't understand, you want to see if the rules is enabled or if it applies to this product ? - dagfr
Thanks for your comment. I want to see if it applies to the product, and when it's applied to a product, it must show "Free Shipping" as text within a product in the product listing. - user1681144
In the Magento Catalog Price Rule you can set the option "Free shipping" to "Yes". When that's set to "Yes", the text "FREE SHIPPING ON THIS PRODUCT" should be showed under the product. - user1681144

1 Answers

0
votes

These parts of your code have bugs in it

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

You are using = which is an assignment (returns true), so no matter the final price it will show FREE SHIPPING ON THIS PRODUCT!

Same applies to if ($_product->$rule->getName() = Free Shipping Rule)