在我问到关于编写代码让Magento为新的电子邮件订户生成随机优惠券代码之前,我已经在这里讨论过了- Creating a single random Magento coupon
这段代码运行得很完美,对于那些帮助过我的人,我永远感激不尽。我现在正在寻找一种方法来删除这些优惠券,因为他们在批量到期的方式,因为删除他们通过Magento管理是一个巨大的痛苦。正如你从下面的图片中看到的,在几天的时间里,我们产生了超过300张优惠券(都已经过期了)。

修改上面链接(来自我的原始问题)中详细说明的创建优惠券代码会起作用吗?类似于:
$model = Mage::getModel('salesrule/rule')
$model->getName('New newsletter subscriber discount');
$model->getToDate(date('Y-m-d'));
$model->delete();还是我完全找错人了?
发布于 2012-10-31 06:44:30
很抱歉回答我自己的问题,但几乎就在我发帖的时候,我就能弄明白了。所以,如果其他人有类似我的问题:
ini_set('auto_detect_line_endings', true);
// Requires Mage
require_once('../../app/Mage.php');
//Initializes Mage
Mage::app('default');
deleteCoupon();
function deleteCoupon() {
$collection = Mage::getModel('salesrule/rule')->getCollection()->load();
foreach($collection as $model) {
// Delete all new newsletter sub coupons
if ($model->getName() == 'New newsletter subscriber discount') {
// Delete all coupons expiring today
if ($model->getToDate() == date('Y-m-d')) {
$model->delete();
echo "Deleted <br />";
} else {
echo "No coupons found! <br />";
}
}
}https://stackoverflow.com/questions/13147835
复制相似问题