Skip to content

Commit 1027e02

Browse files
authored
🔃 [Magento Community Engineering] Community Contributions
Accepted Community Pull Requests: - #26623: #26622 - Check quote item for parentItem instead of parentItemId (by @aligent-lturner) - #24691: Allows additional payment checks in payment method list (by @jensscherbl) - #26423: Update getCustomer method in order class (by @sertlab) - #26621: Set of fixes introduced during #CoreReview 31.01.2020 (by @lbajsarowicz) - #26339: Module xml extra end tag removed (by @tejash-wagento) - #26546: [fixed My Wish List Product not showing properly between >768px and <… (by @hitesh-wagento) Fixed GitHub Issues: - #26622: Fixed cart discount calculated incorrectly when product first added to cart. (reported by @aligent-lturner) has been fixed in #26623 by @aligent-lturner in 2.4-develop branch Related commits: 1. e943bda 2. 199afbf 3. 90c3540 4. 5f4cc5f 5. 0e9c4ef 6. 2c961af 7. 75b03e0 8. a037edf - #25268: $order->getCustomer() returns NULL for registered customer (reported by @qsolutions-pl) has been fixed in #26423 by @sertlab in 2.4-develop branch Related commits: 1. 92816ab 2. 427a4ad 3. f8bcd47 4. 80c737a 5. 5a1f48e 6. 57e2532 7. 3ca45d8 - #26338: Code cleanup for module xml extra end tag removed (reported by @tejash-wagento) has been fixed in #26339 by @tejash-wagento in 2.4-develop branch Related commits: 1. 0653539 2. 399fe8e - #26543: My Wish List Product not showing properly between >768px and <1023px (reported by @hitesh-wagento) has been fixed in #26546 by @hitesh-wagento in 2.4-develop branch Related commits: 1. 55e2e64 2. 6fbdbbe 3. 13b3ba7
2 parents 15b5c60 + f156cb4 commit 1027e02

File tree

13 files changed

+160
-62
lines changed

13 files changed

+160
-62
lines changed

app/code/Magento/CatalogWidget/Block/Product/ProductsList.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Catalog\Api\CategoryRepositoryInterface;
1010
use Magento\Catalog\Block\Product\AbstractProduct;
11+
use Magento\Catalog\Block\Product\Context;
1112
use Magento\Catalog\Block\Product\Widget\Html\Pager;
1213
use Magento\Catalog\Model\Product;
1314
use Magento\Catalog\Model\Product\Visibility;
@@ -16,7 +17,7 @@
1617
use Magento\Catalog\Pricing\Price\FinalPrice;
1718
use Magento\CatalogWidget\Model\Rule;
1819
use Magento\Framework\App\ActionInterface;
19-
use Magento\Framework\App\Http\Context;
20+
use Magento\Framework\App\Http\Context as HttpContext;
2021
use Magento\Framework\App\ObjectManager;
2122
use Magento\Framework\DataObject\IdentityInterface;
2223
use Magento\Framework\Exception\LocalizedException;
@@ -27,7 +28,7 @@
2728
use Magento\Framework\View\LayoutFactory;
2829
use Magento\Framework\View\LayoutInterface;
2930
use Magento\Rule\Model\Condition\Combine;
30-
use Magento\Rule\Model\Condition\Sql\Builder;
31+
use Magento\Rule\Model\Condition\Sql\Builder as SqlBuilder;
3132
use Magento\Widget\Block\BlockInterface;
3233
use Magento\Widget\Helper\Conditions;
3334

@@ -69,7 +70,7 @@ class ProductsList extends AbstractProduct implements BlockInterface, IdentityIn
6970
protected $pager;
7071

7172
/**
72-
* @var Context
73+
* @var HttpContext
7374
*/
7475
protected $httpContext;
7576

@@ -88,7 +89,7 @@ class ProductsList extends AbstractProduct implements BlockInterface, IdentityIn
8889
protected $productCollectionFactory;
8990

9091
/**
91-
* @var Builder
92+
* @var SqlBuilder
9293
*/
9394
protected $sqlBuilder;
9495

@@ -135,34 +136,34 @@ class ProductsList extends AbstractProduct implements BlockInterface, IdentityIn
135136
private $categoryRepository;
136137

137138
/**
138-
* @param \Magento\Catalog\Block\Product\Context $context
139+
* @param Context $context
139140
* @param CollectionFactory $productCollectionFactory
140141
* @param Visibility $catalogProductVisibility
141-
* @param Context $httpContext
142-
* @param Builder $sqlBuilder
142+
* @param HttpContext $httpContext
143+
* @param SqlBuilder $sqlBuilder
143144
* @param Rule $rule
144145
* @param Conditions $conditionsHelper
145-
* @param CategoryRepositoryInterface $categoryRepository
146146
* @param array $data
147147
* @param Json|null $json
148148
* @param LayoutFactory|null $layoutFactory
149149
* @param EncoderInterface|null $urlEncoder
150+
* @param CategoryRepositoryInterface|null $categoryRepository
150151
*
151152
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
152153
*/
153154
public function __construct(
154-
\Magento\Catalog\Block\Product\Context $context,
155+
Context $context,
155156
CollectionFactory $productCollectionFactory,
156157
Visibility $catalogProductVisibility,
157-
Context $httpContext,
158-
Builder $sqlBuilder,
158+
HttpContext $httpContext,
159+
SqlBuilder $sqlBuilder,
159160
Rule $rule,
160161
Conditions $conditionsHelper,
161-
CategoryRepositoryInterface $categoryRepository,
162162
array $data = [],
163163
Json $json = null,
164164
LayoutFactory $layoutFactory = null,
165-
EncoderInterface $urlEncoder = null
165+
EncoderInterface $urlEncoder = null,
166+
CategoryRepositoryInterface $categoryRepository = null
166167
) {
167168
$this->productCollectionFactory = $productCollectionFactory;
168169
$this->catalogProductVisibility = $catalogProductVisibility;
@@ -173,7 +174,8 @@ public function __construct(
173174
$this->json = $json ?: ObjectManager::getInstance()->get(Json::class);
174175
$this->layoutFactory = $layoutFactory ?: ObjectManager::getInstance()->get(LayoutFactory::class);
175176
$this->urlEncoder = $urlEncoder ?: ObjectManager::getInstance()->get(EncoderInterface::class);
176-
$this->categoryRepository = $categoryRepository;
177+
$this->categoryRepository = $categoryRepository ?? ObjectManager::getInstance()
178+
->get(CategoryRepositoryInterface::class);
177179
parent::__construct(
178180
$context,
179181
$data

app/code/Magento/Dhl/etc/module.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Dhl" >
10-
</module>
9+
<module name="Magento_Dhl"/>
1110
</config>

app/code/Magento/Payment/Model/MethodList.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,29 @@ class MethodList
3939
*/
4040
private $paymentMethodInstanceFactory;
4141

42+
/**
43+
* @var array
44+
*/
45+
private $additionalChecks;
46+
4247
/**
4348
* @param \Magento\Payment\Helper\Data $paymentHelper
44-
* @param Checks\SpecificationFactory $specificationFactory
49+
* @param Checks\SpecificationFactory $specificationFactory
50+
* @param array $additionalChecks
4551
*/
4652
public function __construct(
4753
\Magento\Payment\Helper\Data $paymentHelper,
48-
\Magento\Payment\Model\Checks\SpecificationFactory $specificationFactory
54+
\Magento\Payment\Model\Checks\SpecificationFactory $specificationFactory,
55+
array $additionalChecks = []
4956
) {
5057
$this->paymentHelper = $paymentHelper;
5158
$this->methodSpecificationFactory = $specificationFactory;
59+
$this->additionalChecks = $additionalChecks;
5260
}
5361

5462
/**
63+
* Returns all available payment methods for the given quote.
64+
*
5565
* @param \Magento\Quote\Api\Data\CartInterface $quote
5666
* @return \Magento\Payment\Model\MethodInterface[]
5767
*/
@@ -80,12 +90,15 @@ public function getAvailableMethods(\Magento\Quote\Api\Data\CartInterface $quote
8090
protected function _canUseMethod($method, \Magento\Quote\Api\Data\CartInterface $quote)
8191
{
8292
return $this->methodSpecificationFactory->create(
83-
[
84-
AbstractMethod::CHECK_USE_CHECKOUT,
85-
AbstractMethod::CHECK_USE_FOR_COUNTRY,
86-
AbstractMethod::CHECK_USE_FOR_CURRENCY,
87-
AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX,
88-
]
93+
array_merge(
94+
[
95+
AbstractMethod::CHECK_USE_CHECKOUT,
96+
AbstractMethod::CHECK_USE_FOR_COUNTRY,
97+
AbstractMethod::CHECK_USE_FOR_CURRENCY,
98+
AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX,
99+
],
100+
$this->additionalChecks
101+
)
89102
)->isApplicable(
90103
$method,
91104
$quote

app/code/Magento/Payment/Test/Unit/Model/MethodListTest.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace Magento\Payment\Test\Unit\Model;
88

9-
use Magento\Payment\Model\MethodList;
109
use Magento\Payment\Model\Method\AbstractMethod;
10+
use Magento\Payment\Model\MethodList;
1111

1212
class MethodListTest extends \PHPUnit\Framework\TestCase
1313
{
@@ -36,6 +36,11 @@ class MethodListTest extends \PHPUnit\Framework\TestCase
3636
*/
3737
protected $specificationFactoryMock;
3838

39+
/**
40+
* @var array $additionalChecks
41+
*/
42+
private $additionalChecks;
43+
3944
protected function setUp()
4045
{
4146
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -49,10 +54,14 @@ protected function setUp()
4954
)->disableOriginalConstructor()->getMock();
5055

5156
$this->specificationFactoryMock = $this->createMock(\Magento\Payment\Model\Checks\SpecificationFactory::class);
57+
58+
$this->additionalChecks = ['acme_custom_payment_method_check' => 'acme_custom_payment_method_check'];
59+
5260
$this->methodList = $this->objectManager->getObject(
5361
\Magento\Payment\Model\MethodList::class,
5462
[
55-
'specificationFactory' => $this->specificationFactoryMock
63+
'specificationFactory' => $this->specificationFactoryMock,
64+
'additionalChecks' => $this->additionalChecks
5665
]
5766
);
5867

@@ -68,6 +77,9 @@ protected function setUp()
6877
);
6978
}
7079

80+
/**
81+
* Verify available payment methods
82+
*/
7183
public function testGetAvailableMethods()
7284
{
7385
$storeId = 1;
@@ -90,13 +102,17 @@ public function testGetAvailableMethods()
90102

91103
$this->specificationFactoryMock->expects($this->atLeastOnce())
92104
->method('create')
93-
->with([
94-
AbstractMethod::CHECK_USE_CHECKOUT,
95-
AbstractMethod::CHECK_USE_FOR_COUNTRY,
96-
AbstractMethod::CHECK_USE_FOR_CURRENCY,
97-
AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX
98-
])
99-
->will($this->returnValue($compositeMock));
105+
->with(
106+
array_merge(
107+
[
108+
AbstractMethod::CHECK_USE_CHECKOUT,
109+
AbstractMethod::CHECK_USE_FOR_COUNTRY,
110+
AbstractMethod::CHECK_USE_FOR_CURRENCY,
111+
AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX
112+
],
113+
$this->additionalChecks
114+
)
115+
)->will($this->returnValue($compositeMock));
100116

101117
$methodMock = $this->getMockForAbstractClass(\Magento\Payment\Api\Data\PaymentMethodInterface::class);
102118
$this->paymentMethodList->expects($this->once())

app/code/Magento/Rss/etc/module.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Rss" >
10-
</module>
9+
<module name="Magento_Rss"/>
1110
</config>

app/code/Magento/Sales/Model/Order.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* @method bool hasCustomerNoteNotify()
5252
* @method bool hasForcedCanCreditmemo()
5353
* @method bool getIsInProcess()
54-
* @method \Magento\Customer\Model\Customer getCustomer()
54+
* @method \Magento\Customer\Model\Customer|null getCustomer()
5555
* @method \Magento\Sales\Model\Order setSendEmail(bool $value)
5656
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
5757
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -1326,7 +1326,7 @@ public function getTrackingNumbers()
13261326
*/
13271327
public function getShippingMethod($asObject = false)
13281328
{
1329-
$shippingMethod = parent::getShippingMethod();
1329+
$shippingMethod = $this->getData('shipping_method');
13301330
if (!$asObject || !$shippingMethod) {
13311331
return $shippingMethod;
13321332
} else {

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,7 @@ public function initTotals($items, Address $address)
383383

384384
foreach ($items as $item) {
385385
//Skipping child items to avoid double calculations
386-
if ($item->getParentItemId()) {
387-
continue;
388-
}
389-
if (!$rule->getActions()->validate($item)) {
390-
continue;
391-
}
392-
if (!$this->canApplyDiscount($item)) {
386+
if (!$this->isValidItemForRule($item, $rule)) {
393387
continue;
394388
}
395389
$qty = $this->validatorUtility->getItemQty($item, $rule);
@@ -409,6 +403,30 @@ public function initTotals($items, Address $address)
409403
return $this;
410404
}
411405

406+
/**
407+
* Determine if quote item is valid for a given sales rule
408+
*
409+
* @param AbstractItem $item
410+
* @param Rule $rule
411+
* @return bool
412+
*/
413+
private function isValidItemForRule(AbstractItem $item, Rule $rule)
414+
{
415+
if ($item->getParentItemId()) {
416+
return false;
417+
}
418+
if ($item->getParentItem()) {
419+
return false;
420+
}
421+
if (!$rule->getActions()->validate($item)) {
422+
return false;
423+
}
424+
if (!$this->canApplyDiscount($item)) {
425+
return false;
426+
}
427+
return true;
428+
}
429+
412430
/**
413431
* Return item price
414432
*

app/code/Magento/SalesRule/Test/Unit/Model/ValidatorTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use PHPUnit\Framework\MockObject\MockObject;
1414

1515
/**
16-
* Class ValidatorTest
16+
* Tests for Magento\SalesRule\Model\Validator
1717
* @@SuppressWarnings(PHPMD.CouplingBetweenObjects)
1818
*/
1919
class ValidatorTest extends \PHPUnit\Framework\TestCase
@@ -346,11 +346,14 @@ public function testInitTotalsCanApplyDiscount()
346346
'getDiscountCalculationPrice',
347347
'getBaseDiscountCalculationPrice',
348348
'getCalculationPrice',
349-
'getParentItemId'
349+
'getParentItemId',
350+
'getParentItem'
350351
]
351352
);
352353
$item2 = clone $item1;
353-
$items = [$item1, $item2];
354+
$item3 = clone $item1;
355+
$item4 = clone $item1;
356+
$items = [$item1, $item2, $item3, $item4];
354357

355358
$rule->expects($this->any())
356359
->method('getSimpleAction')
@@ -367,12 +370,22 @@ public function testInitTotalsCanApplyDiscount()
367370
$validator->expects($this->at(0))->method('isValid')->with($item1)->willReturn(false);
368371
$validator->expects($this->at(1))->method('isValid')->with($item2)->willReturn(true);
369372

370-
$item1->expects($this->any())->method('getParentItemId')->willReturn(false);
373+
$item1->expects($this->any())->method('getParentItemId')->willReturn(null);
374+
$item1->expects($this->any())->method('getParentItem')->willReturn(null);
371375
$item1->expects($this->never())->method('getDiscountCalculationPrice');
372376
$item1->expects($this->never())->method('getBaseDiscountCalculationPrice');
373-
$item2->expects($this->any())->method('getParentItemId')->willReturn(false);
377+
$item2->expects($this->any())->method('getParentItemId')->willReturn(null);
378+
$item2->expects($this->any())->method('getParentItem')->willReturn(null);
374379
$item2->expects($this->any())->method('getDiscountCalculationPrice')->willReturn(50);
375380
$item2->expects($this->once())->method('getBaseDiscountCalculationPrice')->willReturn(50);
381+
$item3->expects($this->any())->method('getParentItemId')->willReturn(null);
382+
$item3->expects($this->any())->method('getParentItem')->willReturn($item1);
383+
$item3->expects($this->never())->method('getDiscountCalculationPrice');
384+
$item3->expects($this->never())->method('getBaseDiscountCalculationPrice');
385+
$item4->expects($this->any())->method('getParentItemId')->willReturn(12345);
386+
$item4->expects($this->any())->method('getParentItem')->willReturn(null);
387+
$item4->expects($this->never())->method('getDiscountCalculationPrice');
388+
$item4->expects($this->never())->method('getBaseDiscountCalculationPrice');
376389
$this->utility->expects($this->once())->method('getItemQty')->willReturn(1);
377390
$this->utility->expects($this->any())->method('canProcessRule')->willReturn(true);
378391

app/code/Magento/Translation/etc/module.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Translation" >
10-
</module>
9+
<module name="Magento_Translation"/>
1110
</config>

app/code/Magento/Ups/etc/module.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Ups" >
10-
</module>
9+
<module name="Magento_Ups"/>
1110
</config>

0 commit comments

Comments
 (0)