在 Magento 中以编程方式设置特价 [英] Set Special Price Programmatically In Magento
问题描述
我正在尝试编写一个脚本,该脚本将为具有开始日期和结束日期的产品设置特价.当我运行我的脚本时,它确实成功地设置了特价,但开始和结束日期不会填充在管理面板中.
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.
我运行的代码如下:
$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?
推荐答案
我刚刚在我的目录中尝试了您的代码,并进行了一些调整.
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();
?>
这篇关于在 Magento 中以编程方式设置特价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!