Skip to content

Commit d5dbbbd

Browse files
[EngCom] Public Pull Requests - 2.3-develop
- merged latest code from mainline branch
2 parents 2366b96 + ddfc271 commit d5dbbbd

File tree

42 files changed

+1046
-183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1046
-183
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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_Backend" >
9+
<module name="Magento_Backend">
1010
<sequence>
1111
<module name="Magento_Directory"/>
1212
</sequence>

app/code/Magento/Catalog/Plugin/Model/Attribute/Backend/AttributeValidation.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@
77

88
use Magento\Store\Model\Store;
99

10+
/**
11+
* Attribute validation
12+
*/
1013
class AttributeValidation
1114
{
1215
/**
1316
* @var \Magento\Store\Model\StoreManagerInterface
1417
*/
1518
private $storeManager;
1619

20+
/**
21+
* @var array
22+
*/
23+
private $allowedEntityTypes;
24+
1725
/**
1826
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
1927
* @param array $allowedEntityTypes
@@ -27,9 +35,12 @@ public function __construct(
2735
}
2836

2937
/**
38+
* Around validate
39+
*
3040
* @param \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject
3141
* @param \Closure $proceed
3242
* @param \Magento\Framework\DataObject $entity
43+
* @throws \Magento\Framework\Exception\NoSuchEntityException
3344
* @return bool
3445
*/
3546
public function aroundValidate(
@@ -41,7 +52,7 @@ public function aroundValidate(
4152
return $entity instanceof $allowedEntity;
4253
}, $this->allowedEntityTypes)));
4354

44-
if ($isAllowedType && $this->storeManager->getStore()->getId() !== Store::DEFAULT_STORE_ID) {
55+
if ($isAllowedType && (int) $this->storeManager->getStore()->getId() !== Store::DEFAULT_STORE_ID) {
4556
$attrCode = $subject->getAttribute()->getAttributeCode();
4657
// Null is meaning "no value" which should be overridden by value from default scope
4758
if (array_key_exists($attrCode, $entity->getData()) && $entity->getData($attrCode) === null) {
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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\Catalog\Test\Unit\Plugin\Model\Attribute\Backend;
9+
10+
use Magento\Catalog\Plugin\Model\Attribute\Backend\AttributeValidation;
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
use Magento\Store\Model\StoreManagerInterface;
13+
use Magento\Store\Api\Data\StoreInterface;
14+
use Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend;
15+
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
16+
use Magento\Framework\DataObject;
17+
18+
class AttributeValidationTest extends \PHPUnit\Framework\TestCase
19+
{
20+
/**
21+
* @var AttributeValidation
22+
*/
23+
private $attributeValidation;
24+
25+
/**
26+
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $storeManagerMock;
29+
30+
/**
31+
* @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $storeMock;
34+
35+
/**
36+
* @var array
37+
*/
38+
private $allowedEntityTypes;
39+
40+
/**
41+
* @var \Callable
42+
*/
43+
private $proceedMock;
44+
45+
/**
46+
* @var bool
47+
*/
48+
private $isProceedMockCalled = false;
49+
50+
/**
51+
* @var AbstractBackend|\PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
private $subjectMock;
54+
55+
/**
56+
* @var AbstractAttribute|\PHPUnit_Framework_MockObject_MockObject
57+
*/
58+
private $attributeMock;
59+
60+
/**
61+
* @var DataObject|\PHPUnit_Framework_MockObject_MockObject
62+
*/
63+
private $entityMock;
64+
65+
protected function setUp()
66+
{
67+
$objectManager = new ObjectManager($this);
68+
69+
$this->attributeMock = $this->getMockBuilder(AbstractBackend::class)
70+
->setMethods(['getAttributeCode'])
71+
->getMockForAbstractClass();
72+
$this->subjectMock = $this->getMockBuilder(AbstractBackend::class)
73+
->setMethods(['getAttribute'])
74+
->getMockForAbstractClass();
75+
$this->subjectMock->expects($this->any())
76+
->method('getAttribute')
77+
->willReturn($this->attributeMock);
78+
79+
$this->storeMock = $this->getMockBuilder(StoreInterface::class)
80+
->setMethods(['getId'])
81+
->getMockForAbstractClass();
82+
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
83+
->setMethods(['getStore'])
84+
->getMockForAbstractClass();
85+
$this->storeManagerMock->expects($this->any())
86+
->method('getStore')
87+
->willReturn($this->storeMock);
88+
89+
$this->entityMock = $this->getMockBuilder(DataObject::class)
90+
->setMethods(['getData'])
91+
->getMock();
92+
93+
$this->allowedEntityTypes = [$this->entityMock];
94+
95+
$this->proceedMock = function () {
96+
$this->isProceedMockCalled = true;
97+
};
98+
99+
$this->attributeValidation = $objectManager->getObject(
100+
AttributeValidation::class,
101+
[
102+
'storeManager' => $this->storeManagerMock,
103+
'allowedEntityTypes' => $this->allowedEntityTypes,
104+
]
105+
);
106+
}
107+
108+
/**
109+
* @param bool $shouldProceedRun
110+
* @param bool $defaultStoreUsed
111+
* @param null|int|string $storeId
112+
* @dataProvider aroundValidateDataProvider
113+
* @throws \Magento\Framework\Exception\NoSuchEntityException
114+
* @return void
115+
*/
116+
public function testAroundValidate(bool $shouldProceedRun, bool $defaultStoreUsed, $storeId)
117+
{
118+
$this->isProceedMockCalled = false;
119+
$attributeCode = 'code';
120+
121+
$this->storeMock->expects($this->once())
122+
->method('getId')
123+
->willReturn($storeId);
124+
if ($defaultStoreUsed) {
125+
$this->attributeMock->expects($this->once())
126+
->method('getAttributeCode')
127+
->willReturn($attributeCode);
128+
$this->entityMock->expects($this->at(0))
129+
->method('getData')
130+
->willReturn([$attributeCode => null]);
131+
$this->entityMock->expects($this->at(1))
132+
->method('getData')
133+
->with($attributeCode)
134+
->willReturn(null);
135+
}
136+
137+
$this->attributeValidation->aroundValidate($this->subjectMock, $this->proceedMock, $this->entityMock);
138+
$this->assertSame($shouldProceedRun, $this->isProceedMockCalled);
139+
}
140+
141+
/**
142+
* Data provider for testAroundValidate
143+
* @return array
144+
*/
145+
public function aroundValidateDataProvider(): array
146+
{
147+
return [
148+
[true, false, '0'],
149+
[true, false, 0],
150+
[true, false, null],
151+
[false, true, 1],
152+
];
153+
}
154+
}

app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
define([
77
'jquery',
88
'mage/translate',
9+
'underscore',
10+
'Magento_Catalog/js/product/view/product-ids-resolver',
911
'jquery/ui'
10-
], function ($, $t) {
12+
], function ($, $t, _, idsResolver) {
1113
'use strict';
1214

1315
$.widget('mage.catalogAddToCart', {
@@ -76,17 +78,18 @@ define([
7678
/**
7779
* Handler for the form 'submit' event
7880
*
79-
* @param {Object} form
81+
* @param {jQuery} form
8082
*/
8183
submitForm: function (form) {
8284
this.ajaxSubmit(form);
8385
},
8486

8587
/**
86-
* @param {String} form
88+
* @param {jQuery} form
8789
*/
8890
ajaxSubmit: function (form) {
8991
var self = this,
92+
productIds = idsResolver(form),
9093
formData;
9194

9295
$(self.options.minicartSelector).trigger('contentLoading');
@@ -115,6 +118,7 @@ define([
115118

116119
$(document).trigger('ajax:addToCart', {
117120
'sku': form.data().productSku,
121+
'productIds': productIds,
118122
'form': form,
119123
'response': res
120124
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'underscore',
7+
'Magento_Catalog/js/product/view/product-ids'
8+
], function (_, productIds) {
9+
'use strict';
10+
11+
/**
12+
* Returns id's of products in form.
13+
*
14+
* @param {jQuery} $form
15+
* @return {Array}
16+
*/
17+
return function ($form) {
18+
var idSet = productIds(),
19+
product = _.findWhere($form.serializeArray(), {
20+
name: 'product'
21+
});
22+
23+
if (!_.isUndefined(product)) {
24+
idSet.push(product.value);
25+
}
26+
27+
return _.uniq(idSet);
28+
};
29+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'ko'
8+
], function (ko) {
9+
'use strict';
10+
11+
return ko.observableArray([]);
12+
});

0 commit comments

Comments
 (0)