2011-08-03 84 views
4

我试图在类别列表页面(catalog/product/list.phtml)上显示所有等级的价格,但只获得单个产品的基本价格。Magento:在类别列表页面显示等级价格

print_r($_product->getTierPrice()); 

回报:

Array 
(
    [0] => Array 
     (
      [price] => 0.5000 
      [website_price] => 0.5000 
      [price_qty] => 1 
      [cust_group] => 32000 
     ) 

) 

每个产品。在产品信息页面上,它工作不带任何问题。请指教。

ver。 1.5.0.1

UPDATE:

这里是与下面的答案激发了问题的解决方案:

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

对于Magento的2有什么去做? –

回答

1

Magento中的所有对象都可能在不同的页面上以不同的方式创建,并且在其中具有不同的数据。起初这似乎不直观。发生这种情况的是,将数据加载到Item页面上的$ _product对象中的数据库查询几乎包含所有数据。但出于优化目的,类别页面上使用的$ _product只包含一些数据 - 如果我没有记错,它甚至会从不同的数据库表中抽取。例如,类别页面上的查询会加入catalogindex *表中,以查找通常从常规eav表中检索的一些数据。

我没有任何具体信息给您,但您可以直接查看具有所有层定价的catalog_product_entity_tier_price表。至少这是我的magento版本中的表名,不是1.5。副作用是由于额外的查询/查询,类别页面需要更长的时间才能加载。

0

转到管理属性和编辑您要显示的属性。

也许产品不会出现在产品列表中,因为它们没有配置要做到这一点,所以,在编辑属性页,检查是否该被激活:

使用的产品清单

+0

我在产品列表页面显示产品时没有问题,我只能显示分层价格。 tier_price属性的“产品列表中使用”设置为“是”。 –

3

已经有一段时间了,因为这是被问到/回答,但我只是需要这样做,并找到了一个更好的方法,以便不使用直接的数据库访问。

如前所述,默认情况下$ _product对象不包含产品列表页面上的$ _tierPrices ...但如果您将tier_price值设置为null,则会从数据库中检索实际值并填充目的。所以,无论你需要的一线价格,增加:

$_product->setData('tier_price',null); 
$_tierPrices = $this->getTierPrices($_product); 

这应该保证一线价格在对象填充,这样你就可以在任何网页上使用它。

请记住,这仍然会导致与直接db访问相同的性能下降。

+0

哇,这很奇怪。谢谢。我会试一试。 –

+0

它像一个魅力:) –

1

我已经尝试了上述和其他一些在线的答案,并没有一个工作,所以我把几个黑客放到1,这是如何让它在任何地方工作。我甚至有一个自定义的主页旋转木马是这样拉它。

1。你开始通过建立连接附近的某处环外上方

$wh_resource = Mage::getSingleton('core/resource'); 
$wh_readConnection = $wh_resource->getConnection('core_read'); 

2.获取客户ID

$wh_customer = Mage::getSingleton('customer/session')->getCustomer(); 
$wh_id = $wh_customer->getGroupId(); 

3.接下来我们进入,你必须循环你的价格回声

注意:下面的即时通讯使用硬编码为2,因为批发默认为2。你可以建立自己的if/else &查询

if($wh_id == 2){ 
//get id 
$_eid = $_helper->productAttribute($_product, $_product->getId(), 'entity_id'); 
$wh_query = 'SELECT * FROM catalog_product_entity_group_price WHERE entity_id = '.$_eid.' LIMIT 1'; 
$wh_results = $wh_readConnection->fetchAll($wh_query); 
//var_dump($wh_results); 
/* var dump would look like this 
array(1) { [0]=> 
    array(6) { 
    ["value_id"]=> string(1) "1" 
    ["entity_id"]=> string(1) "3" 
    ["all_groups"]=> string(1) "0" 
    ["customer_group_id"]=> string(1) "2" 
    ["value"]=> string(6) "9.5000" 
    ["website_id"]=> string(1) "0" 
    } 
} 
*/ 
$wh_price = substr($wh_results[0]["value"], 0, -2); // this damn database gives us extra 00 
echo '<div class="price-box"><span class="regular-price"><span class="price">$'.$wh_price.'</span></span></div>'; 
} else { 
//not wholesale 
echo $this->getPriceHtml($_product, true); 
} 

好,这是我做到了。随意如果您需要任何帮助

4

如果你正在寻找一个Magento的方式与我联系:

$attribute = $_product->getResource()->getAttribute('tier_price'); 

    if ($attribute) { 
     $attribute->getBackend()->afterLoad($_product); 
     $tierPrices = $_product->getTierPrice(); 
    } 

/app/code/core/Mage/Catalog/Model/Product/Type/Price.phpgetTierPrice()

+0

感谢您的帮助,它为我工作 – Jalpesh

+0

对于Magento 2有什么要做? –

+0

@AnkitShah为Magento 2打开另一个问题 – WonderLand

3

这是另一种方式来获得一线价格

Mage::getResourceModel('catalog/product_attribute_backend_tierprice') 
      ->loadPriceData($product_id,Mage::app()->getWebsite()->getId()); 

响应与价格排列

[0] => Array 
    (
     [price_id] => 7 
     [website_id] => 0 
     [all_groups] => 1 
     [cust_group] => 0 
     [price] => 32.0000 
     [price_qty] => 6.0000 
    ) 

[1] => Array 
    (
     [price_id] => 8 
     [website_id] => 0 
     [all_groups] => 1 
     [cust_group] => 0 
     [price] => 31.0000 
     [price_qty] => 12.0000 
    ) 
+0

谢谢,这是为我工作的方法。 – Latheesan

1

内部应用程序/设计/前端/ your_theme /默认/模板/目录/产品/ list.phtml 添加该在foreach循环中的电网和/或列表

<?php $this->setProduct(Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($_product->getId()))?> 
<?php echo $this->getTierPriceHtml() ?> 
+0

如果使用这种方式,它会达到性能,因为您要为每个循环(产品)再次加载产品, –

相关问题