3

On the page where I show some previewed products I can't get the getTierPrices() value. When I export that information on a span tag:

<span class="price">
<?php
   echo 'From '.$this->getTierPrices()[2]['formated_price']; 
?>
</span>

And on the catalog page I do get that information by using the getPriceHtml.
So the code out there is:

<?php echo $this->getPriceHtml($_product) ?>  

Do anyone know why I can see the tier priced value on the catalog product but nothing on the previous page?

Edited:

I finally found a way to do it. On the product list page I changed the code for:

$_coreHelper->formatPrice($_minimalPriceValue, false)

which refers to:

$_store->roundPrice($_store->convertPrice($_product->getMinimalPrice()));

So it seemed there was a variable with the information I wanted there which I could use. Doing this I got 0,00€ on the product page so I decided to change the $this->getPriceHtml($_product) for:

$_tierPrices = $this->getTierPrices();

$countprice = count($_tierPrices);

echo "From: ".($_tierPrices[--$countprice]['formated_price']);

With this "function" I get the lesser price from the tierprices as I move to the last array data.

1

You cannot get trier easily.

You can Tierprice using below getFormatedTierPrice() function. It give the price in array for of objects.

Solution is :

Step1: get price in format stucuture:

  $prices = $product->getFormatedTierPrice();

Step2: getting trier price using below calculation for loop and logic

    $res = array();
    if (is_array($prices)) {
        foreach ($prices as $price) {
            $price['price_qty'] = $price['price_qty'] * 1;

            $_productPrice = $product->getPrice();
            if ($_productPrice != $product->getFinalPrice()) {
                $_productPrice = $product->getFinalPrice();
            }

            // Group price must be used for percent calculation if it is lower
            $groupPrice = $product->getGroupPrice();
            if ($_productPrice > $groupPrice) {
                $_productPrice = $groupPrice;
            }

            if ($price['price'] < $_productPrice) {
                $price['savePercent'] = ceil(100 - ((100 / $_productPrice) * $price['price']));

                $tierPrice = Mage::app()->getStore()->convertPrice(
                    Mage::helper('tax')->getPrice($product, $price['website_price'])
                );
                $price['formated_price'] = Mage::app()->getStore()->formatPrice($tierPrice);
                $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(
                    Mage::app()->getStore()->convertPrice(
                        Mage::helper('tax')->getPrice($product, $price['website_price'], true)
                    )
                );
            echo $price_formated_price=Mage::app()->getStore()->formatPrice($tierPrice);
            echo $price_formated_price_incl_tax = Mage::app()->getStore()->formatPrice(
                    Mage::app()->getStore()->convertPrice(
                        Mage::helper('tax')->getPrice($product, $price['website_price'], true)
                    )
                );



                $res[] = $price;
            }
        }
    }
 $res;

To show the tier price proper format this link Show tier price on home page in Magento

| improve this answer | |
  • Thank you for your help, but this didn't work either. Same think happens, I can see the whole prices on the product page but a blank text on the preview product. It's strange, because the text it shows on the product page should be the same than the preview product one where there is nothing. – danibg Mar 27 '15 at 10:26
1

By the page before I assume you mean a product list page, either category or search results page.

The reason it does not work is because not all attributes are loaded into the product collection as you do not always need everything.

So how can you load tier prices?

Well you could do it nice and quick and simply make a connection to the database.

$resource = Mage::getSingleton('core/resource');
$query = 'SELECT * FROM '.$resource->getTableName('catalog/product').'_tier_price';
$_tier_prices = $resource->getConnection('core_read')->fetchAll($query);

So this will get all the tier price entries and since it is simply a select you could add your where and job done. Ok so it is not really "best practice" but it will work.

Next thing you could do is to try adding the attribute tier_price to the collection. Now tier_price is no simple attribute so I am not sure how this will work, but you never know it could work sometimes Magento do work "well" :)

Another thing you could try is a reported workaround where you set the attribute as false and then request that same attribute and Magento will try to load it. Again not tested but it is possible that it will work, just try adding the following inside your product loop :)

$_product->setData('tier_price',null);
$_tierPrices = $this->getTierPrices($_product); 
| improve this answer | |
  • Thank you for your help, I finally found by myself a way to do it. You can see it on the edited part from the question I did. – danibg Apr 13 '15 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.