以编程方式删除大量的Magento优惠券(购物车价格规则) [英] Deleting a large number of Magento coupons (shopping cart price rules) programatically

查看:72
本文介绍了以编程方式删除大量的Magento优惠券(购物车价格规则)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在询问有关编写代码以使Magento为新电子邮件订阅者生成随机优惠券代码之前,我一直在这里-

I've been on here before asking about writing code to get Magento to generate a random coupon code for a new e-mail subscriber - Creating a single random Magento coupon

此代码非常有效,对于那些帮助我的人,我永远心怀感激.现在我正在寻找一种方式,因为他们按批量过期,因为删除它们分别通过Magento管理是一个巨大的痛苦,以删除这些优惠券.从下面的图片中可以看到,在几天的时间里,我们生成了300多张优惠券(现已全部过期).

This code worked perfectly and to those who helped I am eternally grateful. I am now looking for a way to delete these coupons as they expire in a bulk fashion because deleting them individually through the Magento admin is a huge pain. As you can see from the picture below, in the span of a couple of days we generated over 300 coupons (all now expired).

是否会修改上面工作中的链接(来自我的原始问题)中详细说明的创建优惠券代码?像这样:

Would modifying the create coupon code detailed in the link (from my original question) above work? Something like:

$model = Mage::getModel('salesrule/rule')
       $model->getName('New newsletter subscriber discount');
       $model->getToDate(date('Y-m-d'));
$model->delete();

还是我完全在这里树错树了?

Or am I totally barking up the wrong tree here?

推荐答案

很抱歉回答我自己的问题,但是几乎在我发布后,我就能弄清楚.因此,万一其他人有像我这样的问题:

Sorry to answer my own question but almost as soon as I posted, I was able to figure it out. So in case anyone else has a question like mine:

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 />"; 
    }
  }
}

这篇关于以编程方式删除大量的Magento优惠券(购物车价格规则)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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