且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Magento中以编程方式设置特价

更新时间:2023-11-30 13:20:52

我刚刚在目录上尝试了您的代码,并且稍加调整即可工作.

I have just tried your code on my catalog and it worked with a little adjustement.

您应该注意已加载的商店; 如果当前未加载ADMIN存储库(Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);),则不允许更新某些产品字段.

You should pay attention to the loaded store; it is not allowed to update certain product fields if the ADMIN store is not the currently loaded (Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);).

<?php

require_once('app/Mage.php');

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

...

$product->save();
?>