2013-02-11 48 views
0

我用這個代碼從Magento的獲得產品價格:的Magento>如何獲得_defaultValues:保護

include_once '../../app/Mage.php'; 
Mage::app(); 
$model = Mage::getModel('catalog/product');//getting product model 
$collection = $model->getCollection(); //products collection 
foreach ($collection as $product) //loop for getting products 
{     
    $model->load($product->getId()); 
    echo $model['price']; 
} 

所以,當我使用這個腳本,對於一些產品,合適的價格給出,但對於一些產品是不合適的價格。

當我var_dump()$模型 - >負載($ product-> getId());合適的價格始終是在這裏:

["_defaultValues:protected"]=> 
    array(5) { 
    ["special_price"]=> 
    string(7) "32.0000" 
    ["visibility"]=> 
    NULL 
    ["status"]=> 
    string(1) "1" 
    ["price"]=> 
    string(8) "399.9900" 
    ["name"]=> 
    string(51) "Philips Home cinema met 3D Blu-ray iPod/iPhone-dock" 
    } 

如何更改代碼得到這個399,99價格,而不是「1」使用$模型[「價格」]當我得到什麼?

回答

0

檢查的文檔 Class Mage_Catalog_Model_Product_Type_Price

$model->getPrice(); 

$model->getFinalPrice(); 

,也許你嘗試運行價格索引

,所以你需要使用不同的方法(也檢查,如果該產品組合/配置產品$模式 - > getCalculatedPrice());

+0

我有同樣的問題,但這並沒有解決它:/ getPrice()和getFinalPrice都給我可配置的產品價格,而不是簡單的 – Gil 2015-12-14 12:33:30