سؤال

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

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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"
  }
}

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top