脚本宝典收集整理的这篇文章主要介绍了php – 以编程方式更新Magento属性,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
该属性默认设置为“否”,我希望在脚本运行时将其更改为“是”,反之亦然.
require_once('app/Mage.PHP'); umask(0); Mage::app('default'); Mage :: app ()->setcurrentStore(Mage_Core_Model_App :: ADMIN_STORE_ID); $PRoductCollection = Mage::getModel('cataLOG/product')->getCollection(); foreach($productCollection as $_product) { echo "\n".'updating '.$_product->getSku()."...\n"; $product = Mage::getModel('catalog/product')->load($_product->getEntITyId()); $product->setAddTenPence(true); $product->save(); }
require_once('app/Mage.PHP'); umask(0); Mage::app('default'); Mage::app ()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $productCollection = Mage::getModel('catalog/product')->getCollection(); foreach($productCollection as $_product) { echo "\n".'updating '.$_product->getSku()."...\n"; $_product->setData('add_ten_pence',1)->getResource()->saveAttribute($_product,'add_ten_pence'); }
UPDATE
更快的方式:
$productCollection = Mage::getModel('catalog/product')->getCollection(); $array_product = $productCollection->getAllIds(); Mage::getSingleton('catalog/product_action')>updateAttributes($array_product,array('add_ten_pence' => 1),Mage_Core_Model_App::ADMIN_STORE_ID);
以上是脚本宝典为你收集整理的php – 以编程方式更新Magento属性全部内容,希望文章能够帮你解决php – 以编程方式更新Magento属性所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。