Skip to content

Commit 96790ee

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-209' into PR_L3_18_04_2022
2 parents 9f3a4cf + c97bd78 commit 96790ee

File tree

11 files changed

+598
-13
lines changed

11 files changed

+598
-13
lines changed

app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ public function collectRates(RateRequest $request)
133133
$freeQty += $item->getQty() * ($child->getQty() - $freeShipping);
134134
}
135135
}
136-
} elseif (
137-
($item->getFreeShipping() || $item->getAddress()->getFreeShipping()) &&
136+
} elseif (($item->getFreeShipping() || $item->getAddress()->getFreeShipping()) &&
138137
($item->getFreeShippingMethod() == null || $item->getFreeShippingMethod() &&
139138
$item->getFreeShippingMethod() == 'tablerate_bestway')
140139
) {
@@ -194,6 +193,7 @@ public function collectRates(RateRequest $request)
194193
* Free package weight has been already taken into account.
195194
*/
196195
$request->setPackageValue($freePackageValue);
196+
$request->setPackageValueWithDiscount($freePackageValue);
197197
$request->setPackageQty($freeQty);
198198
$rate = $this->getRate($request);
199199
if (!empty($rate) && $rate['price'] >= 0) {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesRule\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Framework\DataObjectFactory;
12+
use Magento\SalesRule\Model\Rule\Condition\Address;
13+
use Magento\TestFramework\Fixture\DataFixtureInterface;
14+
15+
class AddressCondition implements DataFixtureInterface
16+
{
17+
public const DEFAULT_DATA = [
18+
'type' => Address::class,
19+
'attribute' => null,
20+
'operator' => '==',
21+
'value' => null,
22+
'is_value_processed' => false,
23+
];
24+
25+
/**
26+
* @var DataObjectFactory
27+
*/
28+
private $dataObjectFactory;
29+
30+
/**
31+
* @param DataObjectFactory $dataObjectFactory
32+
*/
33+
public function __construct(
34+
DataObjectFactory $dataObjectFactory
35+
) {
36+
$this->dataObjectFactory = $dataObjectFactory;
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
* @param array $data Parameters. Same format as AddressCondition::DEFAULT_DATA.
42+
*/
43+
public function apply(array $data = []): ?DataObject
44+
{
45+
return $this->dataObjectFactory->create(['data' => array_merge(self::DEFAULT_DATA, $data)]);
46+
}
47+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesRule\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Framework\DataObjectFactory;
12+
use Magento\SalesRule\Model\Rule\Condition\Product\Combine;
13+
use Magento\TestFramework\Fixture\DataFixtureInterface;
14+
15+
class Conditions implements DataFixtureInterface
16+
{
17+
public const DEFAULT_DATA = [
18+
'type' => Combine::class,
19+
'attribute' => null,
20+
'operator' => null,
21+
'value' => true,
22+
'aggregator' => 'all',
23+
'is_value_processed' => null,
24+
'conditions' => [
25+
26+
],
27+
];
28+
29+
/**
30+
* @var DataObjectFactory
31+
*/
32+
private $dataObjectFactory;
33+
34+
/**
35+
* @param DataObjectFactory $dataObjectFactory
36+
*/
37+
public function __construct(DataObjectFactory $dataObjectFactory)
38+
{
39+
$this->dataObjectFactory = $dataObjectFactory;
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
* @param array $data Parameters. Same format as Conditions::DEFAULT_DATA.
45+
* - $data['conditions']: An array of any:
46+
* - Conditions
47+
* - ProductFoundInCartConditions
48+
* - ProductSubselectionInCartConditions
49+
*/
50+
public function apply(array $data = []): ?DataObject
51+
{
52+
return $this->dataObjectFactory->create(['data' => $this->prepareData($data)]);
53+
}
54+
55+
/**
56+
* Prepare conditions data
57+
*
58+
* @param array $data
59+
* @return array
60+
*/
61+
private function prepareData(array $data): array
62+
{
63+
$conditions = [];
64+
$data = array_merge(self::DEFAULT_DATA, $data);
65+
66+
foreach ($data['conditions'] as $condition) {
67+
$conditionData = $condition instanceof DataObject ? $condition->toArray() : $condition;
68+
if (!isset($condition['conditions'])) {
69+
$conditionData += AddressCondition::DEFAULT_DATA;
70+
}
71+
$conditions[] = $conditionData;
72+
}
73+
$data['conditions'] = $conditions;
74+
return $data;
75+
}
76+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesRule\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Framework\DataObjectFactory;
12+
use Magento\SalesRule\Model\Rule\Condition\Product;
13+
use Magento\TestFramework\Fixture\DataFixtureInterface;
14+
15+
class ProductCondition implements DataFixtureInterface
16+
{
17+
public const DEFAULT_DATA = [
18+
'type' => Product::class,
19+
'attribute' => null,
20+
'operator' => '==',
21+
'value' => null,
22+
'is_value_processed' => false,
23+
];
24+
25+
/**
26+
* @var DataObjectFactory
27+
*/
28+
private $dataObjectFactory;
29+
30+
/**
31+
* @param DataObjectFactory $dataObjectFactory
32+
*/
33+
public function __construct(
34+
DataObjectFactory $dataObjectFactory
35+
) {
36+
$this->dataObjectFactory = $dataObjectFactory;
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
* @param array $data Parameters. Same format as ProductCondition::DEFAULT_DATA.
42+
*/
43+
public function apply(array $data = []): ?DataObject
44+
{
45+
return $this->dataObjectFactory->create(['data' => array_merge(self::DEFAULT_DATA, $data)]);
46+
}
47+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesRule\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Framework\DataObjectFactory;
12+
use Magento\SalesRule\Model\Rule\Condition\Product\Combine;
13+
use Magento\TestFramework\Fixture\DataFixtureInterface;
14+
15+
class ProductConditions implements DataFixtureInterface
16+
{
17+
public const DEFAULT_DATA = [
18+
'type' => Combine::class,
19+
'attribute' => null,
20+
'operator' => null,
21+
'value' => true,
22+
'is_value_processed' => null,
23+
'aggregator' => 'all',
24+
'conditions' => [
25+
26+
],
27+
];
28+
29+
/**
30+
* @var DataObjectFactory
31+
*/
32+
private $dataObjectFactory;
33+
34+
/**
35+
* @param DataObjectFactory $dataObjectFactory
36+
*/
37+
public function __construct(
38+
DataObjectFactory $dataObjectFactory
39+
) {
40+
$this->dataObjectFactory = $dataObjectFactory;
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
* @param array $data Parameters. Same format as ProductConditions::DEFAULT_DATA.
46+
* - $data['conditions']: An array of conditions
47+
* - ProductConditions
48+
* - ProductCondition
49+
*/
50+
public function apply(array $data = []): ?DataObject
51+
{
52+
return $this->dataObjectFactory->create(['data' => $this->prepareData($data)]);
53+
}
54+
55+
/**
56+
* Prepare product conditions data
57+
*
58+
* @param array $data
59+
* @return array
60+
*/
61+
private function prepareData(array $data): array
62+
{
63+
$data = array_merge(self::DEFAULT_DATA, $data);
64+
$conditions = [];
65+
66+
foreach ($data['conditions'] as $condition) {
67+
$conditionData = $condition instanceof DataObject ? $condition->toArray() : $condition;
68+
if (!isset($condition['conditions'])) {
69+
$conditionData += ProductCondition::DEFAULT_DATA;
70+
}
71+
$conditions[] = $conditionData;
72+
}
73+
$data['conditions'] = $conditions;
74+
75+
return $data;
76+
}
77+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesRule\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\SalesRule\Model\Rule\Condition\Product\Found;
12+
13+
class ProductFoundInCartConditions extends ProductConditions
14+
{
15+
public const DEFAULT_DATA = [
16+
'type' => Found::class,
17+
];
18+
19+
/**
20+
* @inheritdoc
21+
*/
22+
public function apply(array $data = []): ?DataObject
23+
{
24+
return parent::apply(array_merge(self::DEFAULT_DATA, $data));
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesRule\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\SalesRule\Model\Rule\Condition\Product\Subselect;
12+
13+
class ProductSubselectionInCartConditions extends ProductConditions
14+
{
15+
public const DEFAULT_DATA = [
16+
'type' => Subselect::class,
17+
];
18+
19+
/**
20+
* @inheritdoc
21+
*/
22+
public function apply(array $data = []): ?DataObject
23+
{
24+
return parent::apply(array_merge(self::DEFAULT_DATA, $data));
25+
}
26+
}

0 commit comments

Comments
 (0)