2012-09-05 25 views
0

问题Magento的:如何检索产品的最终价格(以帐户目录价格规则等),而从前端的

而在后端Ø的cron任务(例如在定制产品feed生成用户运行请求或在cron事件中),并且通常不在前端,Mage_Catalog_Model_Product的方法getFinalPrice()返回产品的基本价格,而没有考虑到,例如适用于该产品的Magento目录价格规则。

这意味着生成的Feed中导出的价格与Magento前端中显示的价格不同,这很容易成为问题。

那么,如何获得产品的最终价格如前所示?

回答

1

SOLUTION

使用一个辅助类,与定义了以下方法:

class My_Package_Helper_Price extends Mage_Core_Helper_Abstract { 
    private $_init_rule = false; 

    private function initRuleData($product) { 
    if ($this->_init_rule || empty($product)) return $this; 
    $productStore = Mage::getModel('core/store')->load($product->getStoreId()); 
    if (!empty($productStore)) { 
     Mage::register('rule_data', new Varien_Object(array(
     'store_id' => $product->getStoreId(), 
     'website_id' => $productStore->getWebsiteId(), 
     'customer_group_id' => 0, // NOT_LOGGED_IN 
    ))); 
     $this->_init_rule = true; 
    } 
    return $this; 
    } 

    public function getProductFinalPrice($product) { 
    $this->initRuleData($product); 
    return $product->getFinalPrice(); 
    } 

} 

然后,您可以使用:

Mage::helper('my_package/price')->getProductFinalPrice($product); 

其中$产品的加载实例Mage_Catalog_Model_Product类。

4

由谁问的问题只能在管理员的网站,如果你加入这一行接近顶部的人指出了解决方案:

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

这会将前端事件,发生在帐户中定义的目录价格规则在管理员网站上。

希望它可以帮助未来的人。

+0

这是很好的解决方案!谢谢 – bla0009

相关问题