Magento:如何应用目录规则获取产品价格 [英] Magento: how to get the price of a product with catalog rules applied

查看:116
本文介绍了Magento:如何应用目录规则获取产品价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个脚本(Magento外部,而不是模块),旨在输出所有可用产品,其价格和其他一些属性的文本列表.但是,目录价格规则似乎并未应用于产品价格.如果我使用以下任何一种方法:

I'm developing a script (external to Magento, not a module) which aims to output a text list of all available products, their prices and some other attributes. However, catalog price rules don't seem to be applied to product prices. If I use any of the following:

$_product->getPrice()
$_product->getFinalPrice()

我得到正常价格(不应用规则).

I get the normal price (without rules being applied).

如果我使用:

$_product->getSpecialPrice()

除非产品实际上在产品本身中插入了特殊价格(即特殊价格与目录规则无关),否则我得到.

I get null unless the product actually has a special price inserted in the product itself (i.e. if special price is not related with catalog rules).

我也尝试过

Mage::getModel('catalogrule/rule')->calcProductPriceRule($product,$product->getPrice())

如Fabian Blechschmidt给出的答案中所建议的那样,但有趣的是,仅当产品受任何目录规则影响时,它才返回正常价格,否则返回 null .

as suggested in the answer given by Fabian Blechschmidt, but interestingly it returns the normal price only if the product is affected by any catalog rule, returning null otherwise.

StackOverflow中也有类似的问题 Magento论坛前一段时间,但提供了答案(插入下面的代码)对我不起作用(返回的价格保持不变).

There was a similar question in StackOverflow and Magento Forums some time ago, but the provided answer (which is to insert the code bellow) doesn't work for me (returned prices remain the same).

Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_FRONTEND,Mage_Core_Model_App_Area::PART_EVENTS);

有人知道如何实现这一目标吗?

Does anybody have an idea of how to achieve this?

我正在使用Magento 1.6.2.0. 预先感谢.

I'm using Magento 1.6.2.0. Thanks in advance.

推荐答案

我发现了问题.折扣价在商店前端显示确定".问题是我正在开发Magento的外部"脚本(因此不是Magento模块),例如:

I discovered the problem. The discounted prices display Ok in the store frontend. The problem was that I was developing a script "external" to Magento (thus not a Magento module), something like:

<?php

set_time_limit(0);
ignore_user_abort();
error_reporting(E_ALL^E_NOTICE);
header("Content-Type: text/plain; charset=utf-8");

require_once "app/Mage.php";

// Get default store code
$default_store = Mage::app()->getStore();
...

要使一切正常工作,似乎必须遵循正确的Magento引导程序,并将所有内容作为模块进行开发.我的脚本是如此简单,以至于我认为无需编写完整的模块.换句话说,Magento中的所有内容实际上都应该是一个模块.

For everything to work properly it seems that one must follow the proper Magento bootstrap, and develop everything as a module. My script was so simple that I thought it wouldn't be necessary to code a complete module. In other words, everything in Magento should really be a module.

使用模块方法得出结论,所有方法均按预期工作:

Concluding, using the module approach, all the methods work as expected:

$_product->getPrice()
$_product->getFinalPrice()
$_product->getSpecialPrice()

谢谢大家的投入.

这篇关于Magento:如何应用目录规则获取产品价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆