Skip to content

Commit

Permalink
ACPT-10: [Checkout] Sales Rules limitation improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
vzabaznov committed Jun 19, 2023
1 parent cfaeeae commit fe84b95
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
17 changes: 14 additions & 3 deletions app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\SalesRule\Model\ResourceModel\Rule;

use Magento\Framework\DB\Select;
use Magento\Framework\Model\AbstractExtensibleModel;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Quote\Model\Quote\Address;
use Magento\SalesRule\Api\Data\CouponInterface;
Expand Down Expand Up @@ -83,6 +84,7 @@ public function __construct(
$this->_date = $date;
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Json::class);
$this->_associatedEntitiesMap = $this->getAssociatedEntitiesMap();
$this->_setIdFieldName('row_id');
}

/**
Expand Down Expand Up @@ -123,10 +125,19 @@ protected function mapAssociatedEntities($entityType, $objectField)
);

$associatedEntities = $this->getConnection()->fetchAll($select);

$ruleIdFieldName = $this->getIdFieldName();
if (empty($this->getIdFieldName()) && $this->getNewEmptyItem() instanceof AbstractExtensibleModel)
{
/** @var AbstractExtensibleModel $item */
$ruleIdFieldName = $this->getNewEmptyItem()->getIdFieldName();
}
array_map(
function ($associatedEntity) use ($entityInfo, $ruleIdField, $objectField) {
$item = $this->getItemByColumnValue($ruleIdField, $associatedEntity[$ruleIdField]);
function ($associatedEntity) use ($entityInfo, $ruleIdField, $objectField, $ruleIdFieldName) {
if ($ruleIdField === $ruleIdFieldName) {
$item = $this->getItemById($associatedEntity[$ruleIdField]);
} else {
$item = $this->getItemByColumnValue($ruleIdField, $associatedEntity[$ruleIdField]);
}
$itemAssociatedValue = $item->getData($objectField) ?? [];
$itemAssociatedValue[] = $associatedEntity[$entityInfo['entity_id_field']];
$item->setData($objectField, $itemAssociatedValue);
Expand Down
12 changes: 11 additions & 1 deletion app/code/Magento/SalesRule/Model/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
* @method \Magento\SalesRule\Model\Rule setProductIds(string $value)
* @method int getSortOrder()
* @method \Magento\SalesRule\Model\Rule setSortOrder(int $value)
* @method string getSimpleAction()
* @method \Magento\SalesRule\Model\Rule setSimpleAction(string $value)
* @method float getDiscountAmount()
* @method \Magento\SalesRule\Model\Rule setDiscountAmount(float $value)
Expand Down Expand Up @@ -547,6 +546,17 @@ public function getFromDate()
return $this->getData('from_date');
}

/**
* Get from date.
*
* @return string
* @since 100.1.0
*/
public function getSimpleAction()
{
return $this->_getData('simple_action');
}

/**
* Get to date.
*
Expand Down
7 changes: 5 additions & 2 deletions setup/src/Magento/Setup/Fixtures/CartPriceRulesFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public function execute()
*/
public function generateCondition($ruleId, $categoriesArray)
{
//$value = $this->cartPriceRulesProductsFloor + $ruleId % 3;
return [
'conditions' => [
1 => [
Expand All @@ -136,6 +137,7 @@ public function generateCondition($ruleId, $categoriesArray)
'attribute' => 'total_qty',
'operator' => '>=',
'value' => $this->cartPriceRulesProductsFloor + $ruleId,
// 'value' => $value,
],
'1--2' => [
'type' => \Magento\SalesRule\Model\Rule\Condition\Product\Found::class,
Expand All @@ -147,7 +149,8 @@ public function generateCondition($ruleId, $categoriesArray)
'type' => \Magento\SalesRule\Model\Rule\Condition\Product::class,
'attribute' => 'category_ids',
'operator' => '==',
'value' => $categoriesArray[$ruleId % count($categoriesArray)][0],
// 'value' => $categoriesArray[$ruleId % count($categoriesArray)][0],
'value' => 2,
],
],
'actions' => [
Expand Down Expand Up @@ -199,7 +202,7 @@ public function generateRules($ruleFactory, $categoriesArray)
'discount_step' => '',
'apply_to_shipping' => '0',
'simple_free_shipping' => '0',
'stop_rules_processing' => '1',
'stop_rules_processing' => '0',
'reward_points_delta' => '',
'store_labels' => [
0 => '',
Expand Down

0 comments on commit fe84b95

Please sign in to comment.