Skip to content

Commit bd82ed4

Browse files
authored
Merge pull request #4168 from magento-tango/PR-05
Tango PR-05
2 parents 6a9860f + a12ecfd commit bd82ed4

File tree

12 files changed

+84
-107
lines changed

12 files changed

+84
-107
lines changed

app/code/Magento/Catalog/Block/Product/View.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ public function getAddToCartUrl($product, $additional = [])
169169
}
170170

171171
/**
172-
* Get JSON encoded configuration array which can be used for JS dynamic
173-
* price calculation depending on product options
172+
* Get JSON encoded configuration which can be used for JS dynamic price calculation depending on product options
174173
*
175174
* @return string
176175
*/
@@ -262,6 +261,7 @@ public function isStartCustomization()
262261

263262
/**
264263
* Get default qty - either as preconfigured, or as 1.
264+
*
265265
* Also restricts it by minimal qty.
266266
*
267267
* @param null|\Magento\Catalog\Model\Product $product
@@ -323,10 +323,7 @@ public function getQuantityValidators()
323323
public function getIdentities()
324324
{
325325
$identities = $this->getProduct()->getIdentities();
326-
$category = $this->_coreRegistry->registry('current_category');
327-
if ($category) {
328-
$identities[] = Category::CACHE_TAG . '_' . $category->getId();
329-
}
326+
330327
return $identities;
331328
}
332329

app/code/Magento/Catalog/Test/Unit/Block/Product/ViewTest.php

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

99
namespace Magento\Catalog\Test\Unit\Block\Product;
1010

11+
/**
12+
* Class ViewTest
13+
*/
1114
class ViewTest extends \PHPUnit\Framework\TestCase
1215
{
1316
/**
@@ -25,6 +28,9 @@ class ViewTest extends \PHPUnit\Framework\TestCase
2528
*/
2629
protected $registryMock;
2730

31+
/**
32+
* @inheritDoc
33+
*/
2834
protected function setUp()
2935
{
3036
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -36,6 +42,9 @@ protected function setUp()
3642
);
3743
}
3844

45+
/**
46+
* @return void
47+
*/
3948
public function testShouldRenderQuantity()
4049
{
4150
$productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
@@ -61,28 +70,26 @@ public function testShouldRenderQuantity()
6170
$this->assertEquals(false, $this->view->shouldRenderQuantity());
6271
}
6372

73+
/**
74+
* @return void
75+
*/
6476
public function testGetIdentities()
6577
{
6678
$productTags = ['cat_p_1'];
6779
$product = $this->createMock(\Magento\Catalog\Model\Product::class);
68-
$category = $this->createMock(\Magento\Catalog\Model\Category::class);
6980

7081
$product->expects($this->once())
7182
->method('getIdentities')
7283
->will($this->returnValue($productTags));
73-
$category->expects($this->once())
74-
->method('getId')
75-
->will($this->returnValue(1));
7684
$this->registryMock->expects($this->any())
7785
->method('registry')
7886
->will(
7987
$this->returnValueMap(
8088
[
8189
['product', $product],
82-
['current_category', $category],
8390
]
8491
)
8592
);
86-
$this->assertEquals(['cat_p_1', 'cat_c_1'], $this->view->getIdentities());
93+
$this->assertEquals($productTags, $this->view->getIdentities());
8794
}
8895
}

app/code/Magento/Customer/Model/Address/DataProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/**
2121
* Dataprovider of customer addresses for customer address grid.
22+
*
2223
* @property \Magento\Customer\Model\ResourceModel\Address\Collection $collection
2324
*/
2425
class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
@@ -222,8 +223,7 @@ private function getAttributesMeta(Type $entityType): array
222223
$meta[$attribute->getAttributeCode()] = $this->attributeMetadataResolver->getAttributesMeta(
223224
$attribute,
224225
$entityType,
225-
$this->allowToShowHiddenAttributes,
226-
$this->getRequestFieldName()
226+
$this->allowToShowHiddenAttributes
227227
);
228228
}
229229
$this->attributeMetadataResolver->processWebsiteMeta($meta);

app/code/Magento/Customer/Model/AttributeMetadataResolver.php

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,13 @@ public function __construct(
101101
* @param AbstractAttribute $attribute
102102
* @param Type $entityType
103103
* @param bool $allowToShowHiddenAttributes
104-
* @param string $requestFieldName
105104
* @return array
106105
* @throws \Magento\Framework\Exception\LocalizedException
107106
*/
108107
public function getAttributesMeta(
109108
AbstractAttribute $attribute,
110109
Type $entityType,
111-
bool $allowToShowHiddenAttributes,
112-
string $requestFieldName
110+
bool $allowToShowHiddenAttributes
113111
): array {
114112
$meta = $this->modifyBooleanAttributeMeta($attribute);
115113
// use getDataUsingMethod, since some getters are defined and apply additional processing of returning value
@@ -138,7 +136,6 @@ public function getAttributesMeta(
138136
$meta['arguments']['data']['config']['componentType'] = Field::NAME;
139137
$meta['arguments']['data']['config']['visible'] = $this->canShowAttribute(
140138
$attribute,
141-
$requestFieldName,
142139
$allowToShowHiddenAttributes
143140
);
144141

@@ -155,48 +152,16 @@ public function getAttributesMeta(
155152
* Detect can we show attribute on specific form or not
156153
*
157154
* @param AbstractAttribute $customerAttribute
158-
* @param string $requestFieldName
159155
* @param bool $allowToShowHiddenAttributes
160156
* @return bool
161157
*/
162158
private function canShowAttribute(
163159
AbstractAttribute $customerAttribute,
164-
string $requestFieldName,
165160
bool $allowToShowHiddenAttributes
166161
) {
167-
$userDefined = (bool)$customerAttribute->getIsUserDefined();
168-
if (!$userDefined) {
169-
return $customerAttribute->getIsVisible();
170-
}
171-
172-
$canShowOnForm = $this->canShowAttributeInForm($customerAttribute, $requestFieldName);
173-
174-
return ($allowToShowHiddenAttributes && $canShowOnForm) ||
175-
(!$allowToShowHiddenAttributes && $canShowOnForm && $customerAttribute->getIsVisible());
176-
}
177-
178-
/**
179-
* Check whether the specific attribute can be shown in form: customer registration, customer edit, etc...
180-
*
181-
* @param AbstractAttribute $customerAttribute
182-
* @param string $requestFieldName
183-
* @return bool
184-
*/
185-
private function canShowAttributeInForm(AbstractAttribute $customerAttribute, string $requestFieldName): bool
186-
{
187-
$isRegistration = $this->context->getRequestParam($requestFieldName) === null;
188-
189-
if ($customerAttribute->getEntityType()->getEntityTypeCode() === 'customer') {
190-
return \is_array($customerAttribute->getUsedInForms()) &&
191-
(
192-
(\in_array('customer_account_create', $customerAttribute->getUsedInForms(), true)
193-
&& $isRegistration) ||
194-
(\in_array('customer_account_edit', $customerAttribute->getUsedInForms(), true)
195-
&& !$isRegistration)
196-
);
197-
}
198-
return \is_array($customerAttribute->getUsedInForms()) &&
199-
\in_array('customer_address_edit', $customerAttribute->getUsedInForms(), true);
162+
return $allowToShowHiddenAttributes && (bool) $customerAttribute->getIsUserDefined()
163+
? true
164+
: (bool) $customerAttribute->getIsVisible();
200165
}
201166

202167
/**

app/code/Magento/Customer/Model/Customer/DataProvider.php

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -307,45 +307,17 @@ protected function getAttributesMeta(Type $entityType)
307307
return $meta;
308308
}
309309

310-
/**
311-
* Check whether the specific attribute can be shown in form: customer registration, customer edit, etc...
312-
*
313-
* @param Attribute $customerAttribute
314-
* @return bool
315-
*/
316-
private function canShowAttributeInForm(AbstractAttribute $customerAttribute)
317-
{
318-
$isRegistration = $this->context->getRequestParam($this->getRequestFieldName()) === null;
319-
320-
if ($customerAttribute->getEntityType()->getEntityTypeCode() === 'customer') {
321-
return is_array($customerAttribute->getUsedInForms()) &&
322-
(
323-
(in_array('customer_account_create', $customerAttribute->getUsedInForms()) && $isRegistration) ||
324-
(in_array('customer_account_edit', $customerAttribute->getUsedInForms()) && !$isRegistration)
325-
);
326-
} else {
327-
return is_array($customerAttribute->getUsedInForms()) &&
328-
in_array('customer_address_edit', $customerAttribute->getUsedInForms());
329-
}
330-
}
331-
332310
/**
333311
* Detect can we show attribute on specific form or not
334312
*
335313
* @param Attribute $customerAttribute
336314
* @return bool
337315
*/
338-
private function canShowAttribute(AbstractAttribute $customerAttribute)
316+
private function canShowAttribute(AbstractAttribute $customerAttribute): bool
339317
{
340-
$userDefined = (bool) $customerAttribute->getIsUserDefined();
341-
if (!$userDefined) {
342-
return $customerAttribute->getIsVisible();
343-
}
344-
345-
$canShowOnForm = $this->canShowAttributeInForm($customerAttribute);
346-
347-
return ($this->allowToShowHiddenAttributes && $canShowOnForm) ||
348-
(!$this->allowToShowHiddenAttributes && $canShowOnForm && $customerAttribute->getIsVisible());
318+
return $this->allowToShowHiddenAttributes && (bool) $customerAttribute->getIsUserDefined()
319+
? true
320+
: (bool) $customerAttribute->getIsVisible();
349321
}
350322

351323
/**

app/code/Magento/Customer/Model/Customer/DataProviderWithDefaultAddresses.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ private function getAttributesMeta(Type $entityType): array
188188
$meta[$attribute->getAttributeCode()] = $this->attributeMetadataResolver->getAttributesMeta(
189189
$attribute,
190190
$entityType,
191-
$this->allowToShowHiddenAttributes,
192-
$this->getRequestFieldName()
191+
$this->allowToShowHiddenAttributes
193192
);
194193
}
195194
$this->attributeMetadataResolver->processWebsiteMeta($meta);

app/code/Magento/Customer/Test/Unit/Model/Customer/DataProviderTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,16 +1087,15 @@ public function testGetDataWithVisibleAttributesWithAccountEdit()
10871087

10881088
$meta = $dataProvider->getMeta();
10891089
$this->assertNotEmpty($meta);
1090-
$this->assertEquals($this->getExpectationForVisibleAttributes(false), $meta);
1090+
$this->assertEquals($this->getExpectationForVisibleAttributes(), $meta);
10911091
}
10921092

10931093
/**
10941094
* Retrieve all customer variations of attributes with all variations of visibility
10951095
*
1096-
* @param bool $isRegistration
10971096
* @return array
10981097
*/
1099-
private function getCustomerAttributeExpectations($isRegistration)
1098+
private function getCustomerAttributeExpectations()
11001099
{
11011100
return [
11021101
self::ATTRIBUTE_CODE . "_1" => [
@@ -1106,7 +1105,7 @@ private function getCustomerAttributeExpectations($isRegistration)
11061105
'dataType' => 'frontend_input',
11071106
'formElement' => 'frontend_input',
11081107
'options' => 'test-options',
1109-
'visible' => !$isRegistration,
1108+
'visible' => true,
11101109
'required' => 'is_required',
11111110
'label' => __('frontend_label'),
11121111
'sortOrder' => 'sort_order',
@@ -1143,7 +1142,7 @@ private function getCustomerAttributeExpectations($isRegistration)
11431142
'config' => [
11441143
'dataType' => 'frontend_input',
11451144
'formElement' => 'frontend_input',
1146-
'visible' => $isRegistration,
1145+
'visible' => true,
11471146
'required' => 'is_required',
11481147
'label' => __('frontend_label'),
11491148
'sortOrder' => 'sort_order',
@@ -1166,7 +1165,7 @@ private function getCustomerAttributeExpectations($isRegistration)
11661165
'config' => [
11671166
'dataType' => 'frontend_input',
11681167
'formElement' => 'frontend_input',
1169-
'visible' => $isRegistration,
1168+
'visible' => true,
11701169
'required' => 'is_required',
11711170
'label' => __('frontend_label'),
11721171
'sortOrder' => 'sort_order',
@@ -1189,14 +1188,13 @@ private function getCustomerAttributeExpectations($isRegistration)
11891188
/**
11901189
* Retrieve all variations of attributes with all variations of visibility
11911190
*
1192-
* @param bool $isRegistration
11931191
* @return array
11941192
*/
1195-
private function getExpectationForVisibleAttributes($isRegistration = true)
1193+
private function getExpectationForVisibleAttributes()
11961194
{
11971195
return [
11981196
'customer' => [
1199-
'children' => $this->getCustomerAttributeExpectations($isRegistration),
1197+
'children' => $this->getCustomerAttributeExpectations(),
12001198
],
12011199
'address' => [
12021200
'children' => [

app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if ($block->getIsShipping()):
3232
require(["Magento_Sales/order/create/form"], function(){
3333

3434
order.shippingAddressContainer = '<?= /* @escapeNotVerified */ $_fieldsContainerId ?>';
35-
order.setAddresses(<?= /* @escapeNotVerified */ $customerAddressFormatter->getAddressesJson($addressArray) ?>);
35+
order.setAddresses(<?= /* @escapeVerfied */ $block->getAddressCollectionJson() ?>);
3636

3737
});
3838
</script>

app/design/frontend/Magento/luma/Magento_Checkout/web/css/source/module/_cart.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
height: 36px;
211211
margin-top: -7px;
212212
text-align: center;
213-
width: 45px;
213+
width: 60px;
214214
}
215215
}
216216

app/design/frontend/Magento/luma/Magento_Checkout/web/css/source/module/_minicart.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@
371371
.item-qty {
372372
margin-right: @indent__s;
373373
text-align: center;
374-
width: 45px;
374+
width: 60px;
375375
}
376376

377377
.update-cart-item {

lib/internal/Magento/Framework/Api/ExtensibleDataObjectConverter.php

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,30 @@ public function toNestedArray(
4545
}
4646
$dataObjectArray = $this->dataObjectProcessor->buildOutputDataArray($dataObject, $dataObjectType);
4747
//process custom attributes if present
48+
$dataObjectArray = $this->processCustomAttributes($dataObjectArray, $skipAttributes);
49+
50+
if (!empty($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY])) {
51+
/** @var array $extensionAttributes */
52+
$extensionAttributes = $dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY];
53+
unset($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]);
54+
foreach ($extensionAttributes as $attributeKey => $attributeValue) {
55+
if (!in_array($attributeKey, $skipAttributes)) {
56+
$dataObjectArray[$attributeKey] = $attributeValue;
57+
}
58+
}
59+
}
60+
return $dataObjectArray;
61+
}
62+
63+
/**
64+
* Recursive process array to process customer attributes
65+
*
66+
* @param array $dataObjectArray
67+
* @param array $skipAttributes
68+
* @return array
69+
*/
70+
private function processCustomAttributes(array $dataObjectArray, array $skipAttributes): array
71+
{
4872
if (!empty($dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY])) {
4973
/** @var AttributeValue[] $customAttributes */
5074
$customAttributes = $dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY];
@@ -56,14 +80,9 @@ public function toNestedArray(
5680
}
5781
}
5882
}
59-
if (!empty($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY])) {
60-
/** @var array $extensionAttributes */
61-
$extensionAttributes = $dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY];
62-
unset($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]);
63-
foreach ($extensionAttributes as $attributeKey => $attributeValue) {
64-
if (!in_array($attributeKey, $skipAttributes)) {
65-
$dataObjectArray[$attributeKey] = $attributeValue;
66-
}
83+
foreach ($dataObjectArray as $key => $value) {
84+
if (is_array($value)) {
85+
$dataObjectArray[$key] = $this->processCustomAttributes($value, $skipAttributes);
6786
}
6887
}
6988
return $dataObjectArray;

0 commit comments

Comments
 (0)