在 Magento 中以编程方式设置特价
我正在尝试编写一个脚本,该脚本将为具有开始日期和结束日期的产品设置特价。当我运行脚本时,它确实成功设置了特价,但开始和结束日期不会填充在管理面板中。
我运行的代码如下:
$product = Mage::getModel('catalog/product')->load(114912);
$product->setSpecialPrice( ($product->getPrice() * .90) );
$product->setSpecialFromDate('2010-11-01');
$product->setSpecialFromDateIsFormated(true);
$product->setSpecialToDate('2010-11-30');
$product->setSpecialToDateIsFormated(true);
$product->save();
有谁知道我在这里做错了什么?
I am trying to write a script that will set a special price on a product with a start and an end date. When I run my script it does successfully set the special price, but the start and end date do not populate in the admin panel.
The code I am running is as follows:
$product = Mage::getModel('catalog/product')->load(114912);
$product->setSpecialPrice( ($product->getPrice() * .90) );
$product->setSpecialFromDate('2010-11-01');
$product->setSpecialFromDateIsFormated(true);
$product->setSpecialToDate('2010-11-30');
$product->setSpecialToDateIsFormated(true);
$product->save();
Does anyone know what I am doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚在我的目录上尝试了你的代码,经过一些调整就可以工作。
您应该注意加载的商店;
如果当前未加载 ADMIN 商店,则不允许更新某些产品字段 (
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
)。I have just tried your code on my catalog and it worked with a little adjustement.
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);
).这只是一个猜测,但您是否尝试过传递类似
time()
的时间戳并省略setSpecialFromDateIsFormated(true)
?这应该会导致后端模型为您适当地重新格式化它。This is just a guess but have you tried passing a timestamp like from
time()
and leaving out thesetSpecialFromDateIsFormated(true)
? That should cause the backend model to reformat it appropriately for you.