Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CouponsMassDelete.php
Go to the documentation of this file.
1 <?php
8 
10 {
16  public function execute()
17  {
18  $this->_initRule();
19  $rule = $this->_coreRegistry->registry(\Magento\SalesRule\Model\RegistryConstants::CURRENT_SALES_RULE);
20 
21  if (!$rule->getId()) {
22  $this->_forward('noroute');
23  }
24 
25  $codesIds = $this->getRequest()->getParam('ids');
26 
27  if (is_array($codesIds)) {
28  $couponsCollection = $this->_objectManager->create(
29  \Magento\SalesRule\Model\ResourceModel\Coupon\Collection::class
30  )->addFieldToFilter(
31  'coupon_id',
32  ['in' => $codesIds]
33  );
34 
35  foreach ($couponsCollection as $coupon) {
36  $coupon->delete();
37  }
38  }
39  }
40 }
$coupon
_forward($action, $controller=null, $module=null, array $params=null)