Skip to content

Commit fe84b95

Browse files
committed
ACPT-10: [Checkout] Sales Rules limitation improvement
1 parent cfaeeae commit fe84b95

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\SalesRule\Model\ResourceModel\Rule;
88

99
use Magento\Framework\DB\Select;
10+
use Magento\Framework\Model\AbstractExtensibleModel;
1011
use Magento\Framework\Serialize\Serializer\Json;
1112
use Magento\Quote\Model\Quote\Address;
1213
use Magento\SalesRule\Api\Data\CouponInterface;
@@ -83,6 +84,7 @@ public function __construct(
8384
$this->_date = $date;
8485
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Json::class);
8586
$this->_associatedEntitiesMap = $this->getAssociatedEntitiesMap();
87+
$this->_setIdFieldName('row_id');
8688
}
8789

8890
/**
@@ -123,10 +125,19 @@ protected function mapAssociatedEntities($entityType, $objectField)
123125
);
124126

125127
$associatedEntities = $this->getConnection()->fetchAll($select);
126-
128+
$ruleIdFieldName = $this->getIdFieldName();
129+
if (empty($this->getIdFieldName()) && $this->getNewEmptyItem() instanceof AbstractExtensibleModel)
130+
{
131+
/** @var AbstractExtensibleModel $item */
132+
$ruleIdFieldName = $this->getNewEmptyItem()->getIdFieldName();
133+
}
127134
array_map(
128-
function ($associatedEntity) use ($entityInfo, $ruleIdField, $objectField) {
129-
$item = $this->getItemByColumnValue($ruleIdField, $associatedEntity[$ruleIdField]);
135+
function ($associatedEntity) use ($entityInfo, $ruleIdField, $objectField, $ruleIdFieldName) {
136+
if ($ruleIdField === $ruleIdFieldName) {
137+
$item = $this->getItemById($associatedEntity[$ruleIdField]);
138+
} else {
139+
$item = $this->getItemByColumnValue($ruleIdField, $associatedEntity[$ruleIdField]);
140+
}
130141
$itemAssociatedValue = $item->getData($objectField) ?? [];
131142
$itemAssociatedValue[] = $associatedEntity[$entityInfo['entity_id_field']];
132143
$item->setData($objectField, $itemAssociatedValue);

app/code/Magento/SalesRule/Model/Rule.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
* @method \Magento\SalesRule\Model\Rule setProductIds(string $value)
3939
* @method int getSortOrder()
4040
* @method \Magento\SalesRule\Model\Rule setSortOrder(int $value)
41-
* @method string getSimpleAction()
4241
* @method \Magento\SalesRule\Model\Rule setSimpleAction(string $value)
4342
* @method float getDiscountAmount()
4443
* @method \Magento\SalesRule\Model\Rule setDiscountAmount(float $value)
@@ -547,6 +546,17 @@ public function getFromDate()
547546
return $this->getData('from_date');
548547
}
549548

549+
/**
550+
* Get from date.
551+
*
552+
* @return string
553+
* @since 100.1.0
554+
*/
555+
public function getSimpleAction()
556+
{
557+
return $this->_getData('simple_action');
558+
}
559+
550560
/**
551561
* Get to date.
552562
*

setup/src/Magento/Setup/Fixtures/CartPriceRulesFixture.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public function execute()
123123
*/
124124
public function generateCondition($ruleId, $categoriesArray)
125125
{
126+
//$value = $this->cartPriceRulesProductsFloor + $ruleId % 3;
126127
return [
127128
'conditions' => [
128129
1 => [
@@ -136,6 +137,7 @@ public function generateCondition($ruleId, $categoriesArray)
136137
'attribute' => 'total_qty',
137138
'operator' => '>=',
138139
'value' => $this->cartPriceRulesProductsFloor + $ruleId,
140+
// 'value' => $value,
139141
],
140142
'1--2' => [
141143
'type' => \Magento\SalesRule\Model\Rule\Condition\Product\Found::class,
@@ -147,7 +149,8 @@ public function generateCondition($ruleId, $categoriesArray)
147149
'type' => \Magento\SalesRule\Model\Rule\Condition\Product::class,
148150
'attribute' => 'category_ids',
149151
'operator' => '==',
150-
'value' => $categoriesArray[$ruleId % count($categoriesArray)][0],
152+
// 'value' => $categoriesArray[$ruleId % count($categoriesArray)][0],
153+
'value' => 2,
151154
],
152155
],
153156
'actions' => [
@@ -199,7 +202,7 @@ public function generateRules($ruleFactory, $categoriesArray)
199202
'discount_step' => '',
200203
'apply_to_shipping' => '0',
201204
'simple_free_shipping' => '0',
202-
'stop_rules_processing' => '1',
205+
'stop_rules_processing' => '0',
203206
'reward_points_delta' => '',
204207
'store_labels' => [
205208
0 => '',

0 commit comments

Comments
 (0)