2012-05-21 48 views
0

另一個Magento問題, 任何人都可以幫助我嗎?即時通訊嘗試指定一系列product_id的更新屬性來設置標誌「USE DEFAULT VALUE」,但我不斷收到錯誤,我想我試圖以錯誤的方式設置範圍。Magento「使用Defualt值」大規模更新

<?php 
include_once '.../app/Mage.php'; 
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 
error_reporting (E_ALL^E_NOTICE); 

$prods = range(5490,5495); 

$product = Mage::getModel('catalog/product') 
->load($prods) 
->setStoreId(1) 
->setData('status', false) 
->setData('name', false) 
->setData('short_description', false) 
->save(); 
echo "successful"; 
?> 

當我運行該版本與丹尼爾的幫助下,

<?php 
include_once '/home/sites/billyguyatts.com.au/docs/app/Mage.php'; 
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 
error_reporting (E_ALL^E_NOTICE); 

$prods = range(5492,5498); 

$productCollection = Mage::getModel('catalog/product')->getCollection() 
->addAttributeToFilter('entity_id', array('in' => $prods)) 
->load(); 

$productCollection 
->setStoreId(1)  
->setDataToAll('status', false) 
->setDataToAll('name', false) 
->setDataToAll('short_description', false) 
->save(); 
echo "successful"; 
?> 

我獲得成功的回聲,但沒有結果,當我與

$productCollection->setDataToAll('status', false) 
    ->setData('name', false) 
->setData('short_description', false) 
    ->save(); 

運行它,我收到此錯誤:

Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection::setData()

回答

0

您不能使用單個模型加載幾個產品。使用集合:

$productCollection = Mage::getModel('catalog/product')->getCollection() 
    ->addAttributeToFilter('entity_id', array('in' => $prods)) 
    ->load(); 

$productCollection->setDataToAll('status', false) 
        ->... 
        ->... 
        ->save(); 
+0

感謝您的回答。正如你可以看到即時通訊在PHP的無望,不幸的是我仍然無法得到這個工作,不知道如果它是屬性過濾器或setdatatoall使它失敗。 – user1399952