另一个Magento问题, 谁能帮我这个?我试图指定一个product_id的范围来更新属性以设置标志“USE DEFAULT VALUE”,但我一直在收到错误,我想我正试图以错误的方式设置范围。
<?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";
?>
当我在Daniel S的帮助下运行此版本时,
<?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();
我收到此错误:
致命错误:调用未定义的方法Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection :: setData()
答案 0 :(得分:0)
您无法使用单个模型加载多个产品。使用集合:
$productCollection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('entity_id', array('in' => $prods))
->load();
$productCollection->setDataToAll('status', false)
->...
->...
->save();