Magento显示的分层定价在购物车页面上
题
我有一个问题 tierPriceHtml
在购物车页面上显示每个项目。
这就是我里面的 checkout/cart/item/default.phtml
:
$custom = Mage::getModel('catalog/product')->load($_item->getProductId());
$tierPrice = $custom->getTierPriceHtml();
echo $tierPrice;
但是,这不会回荡任何东西。我也没有运气尝试过:
echo $this->getTierPriceHtml()
我怎样才能做到这一点?我应该做点事来修改checkout.xml文件以显示它吗?
这是我的整个结帐/购物车/item/default.phtml文件:
解决方案
我假设您想在“购物车”查看页面上显示每个购物车项目的分层定价,可能值得在问题中澄清这一点。
看起来您正在尝试调用该方法 getTierPrice()
来自 Mage_Catalog_Model_Product
班级而不是 Mage_Catalog_Block_Product_Abstract
班级。
您可以创建自己的自定义块,扩展 Mage_Catalog_Block_Product_Abstract
但是,实现您想要的最简单方法是创建一个新实例 Mage_Catalog_Block_Product_View
对于每个项目。
添加此之后 $_item = $this->getItem();
内部结帐/购物车/item/default.phtml:
$_tierPricing = $this->getLayout()->createBlock(
'catalog/product_view',
'product.tierprices',
array(
'product_id' => $_item->getProductId()
)
);
$_tierPricing->setTemplate('catalog/product/view/tierprices.phtml');
然后您想提供的定价信息:
<?php echo $_tierPricing->getTierPriceHtml();?>
- 在第一行中,我们创建一个新的产品视图块并传递产品ID。 重要的是,这是在创建阶段进行的,而不是在块实例化之后完成的,以避免_preparelayout方法中的错误。
- 然后,我们设置了分层的定价模板,您可能应该制作一个仅用于购物车的新模板。也许
checkout/cart/item/tierprices.phtml
- 现在,我们可以成功使用getTierPriceHtml()方法。
其他提示
我能够为这样的产品获得一系列分层的价格:
$custom = Mage::getModel('catalog/product')->load($_item->getProductId());
var_dump($custom->getTierPrice());
有了这个,您可以将数组格式化为易于阅读的内容。这是我的演示中的样本输出:
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"
}
}
jharrison.au的实施工作工作,但如果您想在购物车中使用另一种设计,则必须修改
$_tierPricing->setTemplate('catalog/product/view/tierprices.phtml');
为了
$_tierPricing->setTierPriceTemplate('catalog/product/view/tierprices.phtml');
谢谢