无法在自定义脚本中检索打折的产品价格 [英] Cant retrieve discounted product price in custom script

查看:56
本文介绍了无法在自定义脚本中检索打折的产品价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义脚本,以csv格式输出特定产品的列表.商店的前端运行良好,但是在我的脚本中检索产品价格时,实际的FinalPrice并未考虑我的目录价格规则,这有点搞砸了,因为getFinalPrice()方法在模板文件等.

I have a custom script that outputs a list of particular products in csv format. The frontend of the store just runs fine, however when retrieving the price of a product in my script, the actual FinalPrice does not take my catalog price rules into account, which is kind of messed up, since the getFinalPrice() method works perfectly in template files ect..

这是我的代码,出于演示目的,我已对其进行了大幅缩短:

This is my code, which I have drastically shortened for demonstration purposes:

<?php   
    require 'app/Mage.php';
    Mage::app('default');

    $product = Mage::getModel("catalog/product")->load(27809);

    echo $product->getFinalPrice();
?>

这将输出产品的正常价格,但不会计入目录价格规则的价格.我刚刚再次应用了所有目录规则,还重建了所有索引.就像我说的那样,折扣价格在前端显示良好,但是由于某种原因,我无法在脚本中检索到它们.

This outputs the product's regular price, but not the price accounted for the catalog price rule. I have just applied all catalog rules again and have also rebuilt all indexes. As I said, the discount prices show fine in the frontend, but for some reason I am not able to retrieve them in my script.

我希望有人知道这里可能出了什么问题.预先感谢!

I hope someone has an idea what could be going wrong here. Thanks in advance!

推荐答案

产品最终价格是在观察者中计算的,并且脚本未加载事件配置.

Product final price is calculated in an observer, and your script is not loading the events configuration.

请参阅下面的内容.

<?php   
    require 'app/Mage.php';
    Mage::app('default');

    //load event configuration areas
    Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_FRONTEND, Mage_Core_Model_App_Area::PART_EVENTS);

    $product = Mage::getModel("catalog/product")->load(27809);

    echo $product->getFinalPrice();
?>

请参见Mage_CatalogRule_Model_Observer::processFrontFinalPrice();.

这篇关于无法在自定义脚本中检索打折的产品价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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