6

I am having an issue getting the tierPriceHtml to display for each item on the cart page.

This is what I have inside checkout/cart/item/default.phtml:

$custom = Mage::getModel('catalog/product')->load($_item->getProductId());
$tierPrice = $custom->getTierPriceHtml();
echo $tierPrice;

However this will not echo out anything. I also tried this with no luck:

echo $this->getTierPriceHtml()

How can I do this? Should I do something to modify the checkout.xml file in order to display it?

Here is my entire checkout/cart/item/default.phtml file:

http://pastebin.com/4wK2P9zU

7

I'm assuming you want to display the tiered pricing for each cart item on the cart view page, it might be worth clarifying this in your question.

It looks like you are trying to call the method getTierPrice() from the Mage_Catalog_Model_Product class instead of the Mage_Catalog_Block_Product_Abstract class.

You could create your own custom block that extends Mage_Catalog_Block_Product_Abstract but the easiest way to achieve what you want is to create a new instance of Mage_Catalog_Block_Product_View for each item.

Add this after $_item = $this->getItem(); inside checkout/cart/item/default.phtml:

$_tierPricing = $this->getLayout()->createBlock(
    'catalog/product_view',
    'product.tierprices',
    array(
        'product_id' => $_item->getProductId()
    )
);
$_tierPricing->setTemplate('catalog/product/view/tierprices.phtml');

And then where you want to put your pricing info:

<?php echo $_tierPricing->getTierPriceHtml();?>
  1. On the first line we create a new product view block and pass in the products' ID. It is important this is done now during the creation phase rather after the block is instantiated to avoid errors in the _prepareLayout method.
  2. Then we set the tiered pricing template, you should probably make a new template used just for the cart. Perhaps checkout/cart/item/tierprices.phtml
  3. Now we can use the getTierPriceHtml() method successfully.
  • Thank you for your reply! I just tried this but this did not work either. It still is not outputting the results. The product has tier pricing and cache is off and I even flushed it. – user693 Mar 12 '13 at 4:15
  • No worries! Are you sure you're adding it to the correct template file? i.e. it's not being overridden by another file somewhere? can you echo out "hello world" where the tiered prices are supposed to go? – jharrison.au Mar 12 '13 at 4:53
  • I've just tested this on a blank installation of Magento and it definitely works, I hope you can figure out what's going on! – jharrison.au Mar 12 '13 at 7:05
  • thank you for confirming it works on a new installation. That lets me know it has something to do with the original developers coding. I was starting to think I was going crazy lol. I'll compare the file with an orignial and etc. I'll mark you answer correct since you went through the trouble to confirm it working. I will also post an update above with the file I am trying to get it working on and maybe you can spot the issue for me. P.S. I used the template path hints so it is the correct file. Thanks again! – user693 Mar 12 '13 at 14:31
  • I'm only posting the top half of the file since it is long ;) – user693 Mar 12 '13 at 14:33
4

I was able to get an array of tiered prices for the product like this:

$custom = Mage::getModel('catalog/product')->load($_item->getProductId());
var_dump($custom->getTierPrice());

With this you could format the array into something easily readable. Here is sample output from my demo:

array(3) {
  [0]=>
  array(7) {
["price_id"]=>
string(2) "11"
["website_id"]=>
string(1) "0"
["all_groups"]=>
string(1) "1"
["cust_group"]=>
int(32000)
["price_qty"]=>
string(6) "5.0000"
["price"]=>
string(8) "599.0000"
["website_price"]=>
string(8) "599.0000"
 }
 [1]=>
array(7) {
["price_id"]=>
string(2) "12"
["website_id"]=>
string(1) "0"
["all_groups"]=>
string(1) "1"
["cust_group"]=>
int(32000)
["price_qty"]=>
string(7) "10.0000"
["price"]=>
string(8) "499.0000"
["website_price"]=>
string(8) "499.0000"
}
[2]=>
array(7) {
["price_id"]=>
string(2) "13"
["website_id"]=>
string(1) "0"
["all_groups"]=>
string(1) "1"
["cust_group"]=>
int(32000)
["price_qty"]=>
string(7) "15.0000"
["price"]=>
string(8) "399.0000"
 ["website_price"]=>
 string(8) "399.0000"
  }
}
  • Thank you for your post. I just tried this but it still didn't output anything. The html is still empty. Any other ideas? – user693 Mar 11 '13 at 3:32
  • I'm going to try this out in a sandbox now – seanbreeden Mar 11 '13 at 3:39
  • That didn't work either. I don't know why this is so hard lol. Thanks, I look forward to seeing your working results ;) – user693 Mar 11 '13 at 3:48
  • I wasn't able to get the Html version to render, but I was able to pull the tier pricing information. This piqued my interest though and I think there must be a way to extend it to pull the html-formatted from the getTierPriceHtml() function. – seanbreeden Mar 11 '13 at 4:21
  • I know. It has had me scratching my head all night lol. – user693 Mar 11 '13 at 4:48
2

The implementation suggest by jharrison.au work but if you want to use another design for the tier price in the shopping cart you have to modify

$_tierPricing->setTemplate('catalog/product/view/tierprices.phtml');

for

$_tierPricing->setTierPriceTemplate('catalog/product/view/tierprices.phtml');

Thanks

Your Answer

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