Skip to content

Commit

Permalink
Merge pull request #24 from magento-firedrakes/MAGETWO-44160
Browse files Browse the repository at this point in the history
[Merchant Beta][Firedrakes] Bugfixes
  • Loading branch information
Korshenko, Olexii(okorshenko) committed Oct 23, 2015
2 parents 77fbc91 + ee348f0 commit f8e1571
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
20 changes: 16 additions & 4 deletions app/code/Magento/SalesRule/Model/Resource/Rule/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ public function setValidationFilter($websiteId, $customerGroupId, $couponCode =
/* We need to overwrite joinLeft if coupon is applied */
$this->getSelect()->reset();
parent::_initSelect();

$this->addWebsiteGroupDateFilter($websiteId, $customerGroupId, $now);
$select = $this->getSelect();

$connection = $this->getConnection();
if (strlen($couponCode)) {
$select->joinLeft(
Expand All @@ -103,8 +101,11 @@ public function setValidationFilter($websiteId, $customerGroupId, $couponCode =
),
['code']
);
$select->where('main_table.coupon_type = ? ', \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON);
$orWhereConditions = [
$connection->quoteInto(
'main_table.coupon_type = ? ',
\Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON
),
$connection->quoteInto(
'(main_table.coupon_type = ? AND rule_coupons.type = 0)',
\Magento\SalesRule\Model\Rule::COUPON_TYPE_AUTO
Expand All @@ -118,8 +119,19 @@ public function setValidationFilter($websiteId, $customerGroupId, $couponCode =
\Magento\SalesRule\Model\Rule::COUPON_TYPE_SPECIFIC
),
];
$andWhereConditions = [
$connection->quoteInto(
'rule_coupons.code = ?',
$couponCode
),
$connection->quoteInto(
'(rule_coupons.expiration_date IS NULL OR rule_coupons.expiration_date >= ?)',
$this->_date->date('Y-m-d')
),
];
$orWhereCondition = implode(' OR ', $orWhereConditions);
$select->orWhere('(' . $orWhereCondition . ') AND rule_coupons.code = ?', $couponCode);
$andWhereCondition = implode(' AND ', $andWhereConditions);
$select->where('(' . $orWhereCondition . ') AND ' . $andWhereCondition);
} else {
$this->addFieldToFilter(
'main_table.coupon_type',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<?php if ($block->isShowPerPage()): ?>
<div class="limiter">
<strong class="limiter-label"><?php echo __('Show') ?></strong>
<select id="limiter" data-mage-redirect="{'event':'change'}" class="limiter-options">
<select id="limiter" data-mage-init='{"redirectUrl": {"event":"change"}}' class="limiter-options">
<?php foreach ($block->getAvailableLimit() as $_key => $_limit): ?>
<option value="<?php echo $block->getLimitUrl($_key) ?>"<?php if ($block->isLimitCurrent($_key)): ?>
selected="selected"<?php endif ?>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public function testSetValidationFilter($couponCode, $expectedItems)
public function setValidationFilterDataProvider()
{
return [
'Check type COUPON' => ['coupon_code', ['#1', '#2', '#5']],
'Check type COUPON' => ['coupon_code', ['#1', '#5']],
'Check type NO_COUPON' => ['', ['#2', '#5']],
'Check type COUPON_AUTO' => ['coupon_code_auto', ['#2', '#4', '#5']],
'Check result with auto generated coupon' => ['autogenerated_3_1', ['#2', '#3', '#5']],
'Check type COUPON_AUTO' => ['coupon_code_auto', ['#4', '#5']],
'Check result with auto generated coupon' => ['autogenerated_3_1', ['#3', '#5']],
'Check result with non actual previously generated coupon' => [
'autogenerated_2_1',
['#2', '#5'],
],
'Check result with wrong code' => ['wrong_code', ['#2', '#5']]
'Check result with wrong code' => ['wrong_code', ['#5']]
];
}
}

0 comments on commit f8e1571

Please sign in to comment.