我试图在类别列表页面(catalog/product/list.phtml)上显示所有层级价格,但只获得单个产品的基本价格.
print_r($_product->getTierPrice());
Run Code Online (Sandbox Code Playgroud)
收益:
Array
(
[0] => Array
(
[price] => 0.5000
[website_price] => 0.5000
[price_qty] => 1
[cust_group] => 32000
)
)
Run Code Online (Sandbox Code Playgroud)
对于每个产品.在产品信息页面上,它没有问题.请指教.
版本.1.5.0.1
更新:
以下是答案的问题解决方案:
$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);
Run Code Online (Sandbox Code Playgroud)
小智 6
这是获得等级价格的另一种方式
Mage::getResourceModel('catalog/product_attribute_backend_tierprice')
->loadPriceData($product_id,Mage::app()->getWebsite()->getId());
Run Code Online (Sandbox Code Playgroud)
响应是价格阵列
[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
)
Run Code Online (Sandbox Code Playgroud)
如果您正在寻找Magento方式:
$attribute = $_product->getResource()->getAttribute('tier_price');
if ($attribute) {
$attribute->getBackend()->afterLoad($_product);
$tierPrices = $_product->getTierPrice();
}
Run Code Online (Sandbox Code Playgroud)
从 /app/code/core/Mage/Catalog/Model/Product/Type/Price.php getTierPrice()
Magento 中的所有对象都可能在不同页面上以不同方式创建,并且其中包含不同的数据。乍一看可能看起来不直观。碰巧,将数据加载到 Item 页面上的 $_product 对象中的数据库查询几乎包含了“所有”数据。但出于优化目的,类别页面上使用的 $_product 仅包含一些数据 - 如果我没记错的话,它甚至从不同的数据库表中提取数据。例如,类别页面上的查询会针对catalogindex* 表进行联接,以获取通常从常规eav 表中检索的某些数据。
我没有任何具体信息可以提供给您,但您可以查看直接针对catalog_product_entity_tier_price 表进行查询,该表包含所有层级定价。至少这是我的 magento 版本中的表名称,它不是 1.5。副作用是由于额外的查询,类别页面将需要更长的时间来加载。
| 归档时间: |
|
| 查看次数: |
10321 次 |
| 最近记录: |