Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Collection.php
Go to the documentation of this file.
1 <?php
7 
11 
18 {
24  protected function _construct()
25  {
26  parent::_construct();
27  $this->_init(\Magento\SalesRule\Model\Coupon::class, \Magento\SalesRule\Model\ResourceModel\Coupon::class);
28  }
29 
36  public function addRuleToFilter($rule)
37  {
38  if ($rule instanceof Rule) {
39  $ruleId = $rule->getId();
40  } else {
41  $ruleId = (int)$rule;
42  }
43 
44  $this->addFieldToFilter('rule_id', $ruleId);
45 
46  return $this;
47  }
48 
55  public function addRuleIdsToFilter(array $ruleIds)
56  {
57  $this->addFieldToFilter('rule_id', ['in' => $ruleIds]);
58  return $this;
59  }
60 
66  public function addGeneratedCouponsFilter()
67  {
68  $this->addFieldToFilter('is_primary', ['null' => 1])->addFieldToFilter('type', '1');
69  return $this;
70  }
71 
79  public function addIsUsedFilterCallback($collection, $column)
80  {
81  $filterValue = $column->getFilter()->getCondition();
82 
83  $expression = $this->getConnection()->getCheckSql('main_table.times_used > 0', 1, 0);
84  $conditionSql = $this->_getConditionSql($expression, $filterValue);
85  $collection->getSelect()->where($conditionSql);
86  }
87 }