在Magento中以编程方式设置特价 [英] Set Special Price Programmatically In Magento

查看:63
本文介绍了在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.

我正在运行的代码如下:

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?

推荐答案

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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆