Skip to content

Commit 6f308b1

Browse files
Merge branch '2.2-develop' of github.com:magento/magento2 into fix-product-videos-gallery-events
2 parents 56802d3 + 82caf48 commit 6f308b1

File tree

668 files changed

+23875
-266
lines changed

Some content is hidden

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

668 files changed

+23875
-266
lines changed

app/code/Magento/Analytics/etc/di.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,22 @@
254254
<argument name="responseResolver" xsi:type="object">NotifyDataChangedResponseResolver</argument>
255255
</arguments>
256256
</type>
257+
<type name="Magento\Config\Model\Config\TypePool">
258+
<arguments>
259+
<argument name="sensitive" xsi:type="array">
260+
<item name="analytics/url/signup" xsi:type="string">1</item>
261+
<item name="analytics/url/update" xsi:type="string">1</item>
262+
<item name="analytics/url/bi_essentials" xsi:type="string">1</item>
263+
<item name="analytics/url/otp" xsi:type="string">1</item>
264+
<item name="analytics/url/report" xsi:type="string">1</item>
265+
<item name="analytics/url/notify_data_changed" xsi:type="string">1</item>
266+
<item name="analytics/general/token" xsi:type="string">1</item>
267+
</argument>
268+
<argument name="environment" xsi:type="array">
269+
<item name="crontab/default/jobs/analytics_collect_data/schedule/cron_expr" xsi:type="string">1</item>
270+
<item name="crontab/default/jobs/analytics_update/schedule/cron_expr" xsi:type="string">1</item>
271+
<item name="crontab/default/jobs/analytics_subscribe/schedule/cron_expr" xsi:type="string">1</item>
272+
</argument>
273+
</arguments>
274+
</type>
257275
</config>

app/code/Magento/Backend/etc/adminhtml/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@
145145
<item name="dev" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::HIDDEN</item>
146146
<item name="general/locale/code" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::DISABLED</item>
147147
</argument>
148+
<argument name="exemptions" xsi:type="array">
149+
<item name="dev/debug/debug_logging" xsi:type="string"/>
150+
</argument>
148151
</arguments>
149152
</type>
150153
<type name="Magento\Framework\View\Layout\Generator\Block">

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,13 @@ public function getAdditionalData(array $excludeAttr = [])
8383
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
8484
$value = $attribute->getFrontend()->getValue($product);
8585

86-
if (!$product->hasData($attribute->getAttributeCode())) {
87-
$value = __('N/A');
88-
} elseif ((string)$value == '') {
89-
$value = __('No');
86+
if ($value instanceof Phrase) {
87+
$value = (string)$value;
9088
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
9189
$value = $this->priceCurrency->convertAndFormat($value);
9290
}
9391

94-
if ($value instanceof Phrase || (is_string($value) && strlen($value))) {
92+
if (is_string($value) && strlen($value)) {
9593
$data[$attribute->getAttributeCode()] = [
9694
'label' => __($attribute->getStoreLabel()),
9795
'value' => $value,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function getGalleryImagesJson()
116116
'thumb' => $image->getData('small_image_url'),
117117
'img' => $image->getData('medium_image_url'),
118118
'full' => $image->getData('large_image_url'),
119-
'caption' => $image->getLabel(),
119+
'caption' => ($image->getLabel() ?: $this->getProduct()->getName()),
120120
'position' => $image->getPosition(),
121121
'isMain' => $this->isMainImage($image),
122122
'type' => str_replace('external-', '', $image->getMediaType()),

app/code/Magento/Catalog/Model/Category/DataProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ private function convertValues($category, $categoryData)
494494

495495
$categoryData[$attributeCode][0]['name'] = $fileName;
496496
$categoryData[$attributeCode][0]['url'] = $category->getImageUrl($attributeCode);
497-
$categoryData['image'][0]['size'] = isset($stat) ? $stat['size'] : 0;
498-
$categoryData['image'][0]['type'] = $mime;
497+
$categoryData[$attributeCode][0]['size'] = isset($stat) ? $stat['size'] : 0;
498+
$categoryData[$attributeCode][0]['type'] = $mime;
499499
}
500500
}
501501
}

app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php

Lines changed: 85 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,19 @@ public function execute($product, $arguments = [])
167167
if (empty($attrData) && empty($clearImages) && empty($newImages) && empty($existImages)) {
168168
continue;
169169
}
170-
if (in_array($attrData, $clearImages)) {
171-
$product->setData($mediaAttrCode, 'no_selection');
172-
}
173-
174-
if (in_array($attrData, array_keys($newImages))) {
175-
$product->setData($mediaAttrCode, $newImages[$attrData]['new_file']);
176-
$product->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']);
177-
}
178-
179-
if (in_array($attrData, array_keys($existImages)) && isset($existImages[$attrData]['label'])) {
180-
$product->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']);
181-
}
182-
if (!empty($product->getData($mediaAttrCode))) {
183-
$product->addAttributeUpdate(
170+
$this->processMediaAttribute(
171+
$product,
172+
$mediaAttrCode,
173+
$clearImages,
174+
$newImages
175+
);
176+
if (in_array($mediaAttrCode, ['image', 'small_image', 'thumbnail'])) {
177+
$this->processMediaAttributeLabel(
178+
$product,
184179
$mediaAttrCode,
185-
$product->getData($mediaAttrCode),
186-
$product->getStoreId()
180+
$clearImages,
181+
$newImages,
182+
$existImages
187183
);
188184
}
189185
}
@@ -448,4 +444,77 @@ private function getMediaAttributeCodes()
448444
}
449445
return $this->mediaAttributeCodes;
450446
}
447+
448+
/**
449+
* @param \Magento\Catalog\Model\Product $product
450+
* @param $mediaAttrCode
451+
* @param array $clearImages
452+
* @param array $newImages
453+
*/
454+
private function processMediaAttribute(
455+
\Magento\Catalog\Model\Product $product,
456+
$mediaAttrCode,
457+
array $clearImages,
458+
array $newImages
459+
) {
460+
$attrData = $product->getData($mediaAttrCode);
461+
if (in_array($attrData, $clearImages)) {
462+
$product->setData($mediaAttrCode, 'no_selection');
463+
}
464+
465+
if (in_array($attrData, array_keys($newImages))) {
466+
$product->setData($mediaAttrCode, $newImages[$attrData]['new_file']);
467+
}
468+
if (!empty($product->getData($mediaAttrCode))) {
469+
$product->addAttributeUpdate(
470+
$mediaAttrCode,
471+
$product->getData($mediaAttrCode),
472+
$product->getStoreId()
473+
);
474+
}
475+
}
476+
477+
/**
478+
* @param \Magento\Catalog\Model\Product $product
479+
* @param $mediaAttrCode
480+
* @param array $clearImages
481+
* @param array $newImages
482+
* @param array $existImages
483+
*/
484+
private function processMediaAttributeLabel(
485+
\Magento\Catalog\Model\Product $product,
486+
$mediaAttrCode,
487+
array $clearImages,
488+
array $newImages,
489+
array $existImages
490+
) {
491+
$resetLabel = false;
492+
$attrData = $product->getData($mediaAttrCode);
493+
if (in_array($attrData, $clearImages)) {
494+
$product->setData($mediaAttrCode . '_label', null);
495+
$resetLabel = true;
496+
}
497+
498+
if (in_array($attrData, array_keys($newImages))) {
499+
$product->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']);
500+
}
501+
502+
if (in_array($attrData, array_keys($existImages)) && isset($existImages[$attrData]['label'])) {
503+
$product->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']);
504+
}
505+
506+
if ($attrData === 'no_selection' && !empty($product->getData($mediaAttrCode . '_label'))) {
507+
$product->setData($mediaAttrCode . '_label', null);
508+
$resetLabel = true;
509+
}
510+
if (!empty($product->getData($mediaAttrCode . '_label'))
511+
|| $resetLabel === true
512+
) {
513+
$product->addAttributeUpdate(
514+
$mediaAttrCode . '_label',
515+
$product->getData($mediaAttrCode . '_label'),
516+
$product->getStoreId()
517+
);
518+
}
519+
}
451520
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Unit\Block\Product\View;
8+
9+
use \PHPUnit\Framework\TestCase;
10+
use \Magento\Framework\Phrase;
11+
use \Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
12+
use \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend;
13+
use \Magento\Catalog\Model\Product;
14+
use \Magento\Framework\View\Element\Template\Context;
15+
use \Magento\Framework\Registry;
16+
use \Magento\Framework\Pricing\PriceCurrencyInterface;
17+
use \Magento\Catalog\Block\Product\View\Attributes as AttributesBlock;
18+
19+
/**
20+
* Test class for \Magento\Catalog\Block\Product\View\Attributes
21+
*
22+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
23+
*/
24+
class AttributesTest extends TestCase
25+
{
26+
/**
27+
* @var \Magento\Framework\Phrase
28+
*/
29+
private $phrase;
30+
31+
/**
32+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Eav\Model\Entity\Attribute\AbstractAttribute
33+
*/
34+
private $attribute;
35+
36+
/**
37+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend
38+
*/
39+
private $frontendAttribute;
40+
41+
/**
42+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product
43+
*/
44+
private $product;
45+
46+
/**
47+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\Element\Template\Context
48+
*/
49+
private $context;
50+
51+
/**
52+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Registry
53+
*/
54+
private $registry;
55+
56+
/**
57+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Pricing\PriceCurrencyInterface
58+
*/
59+
private $priceCurrencyInterface;
60+
61+
/**
62+
* @var \Magento\Catalog\Block\Product\View\Attributes
63+
*/
64+
private $attributesBlock;
65+
66+
protected function setUp()
67+
{
68+
$this->attribute = $this
69+
->getMockBuilder(AbstractAttribute::class)
70+
->disableOriginalConstructor()
71+
->getMock();
72+
$this->attribute
73+
->expects($this->any())
74+
->method('getIsVisibleOnFront')
75+
->willReturn(true);
76+
$this->attribute
77+
->expects($this->any())
78+
->method('getAttributeCode')
79+
->willReturn('phrase');
80+
$this->frontendAttribute = $this
81+
->getMockBuilder(AbstractFrontend::class)
82+
->disableOriginalConstructor()
83+
->getMock();
84+
$this->attribute
85+
->expects($this->any())
86+
->method('getFrontendInput')
87+
->willReturn('phrase');
88+
$this->attribute
89+
->expects($this->any())
90+
->method('getFrontend')
91+
->willReturn($this->frontendAttribute);
92+
$this->product = $this
93+
->getMockBuilder(Product::class)
94+
->disableOriginalConstructor()
95+
->getMock();
96+
$this->product
97+
->expects($this->any())
98+
->method('getAttributes')
99+
->willReturn([$this->attribute]);
100+
$this->product
101+
->expects($this->any())
102+
->method('hasData')
103+
->willReturn(true);
104+
$this->context = $this
105+
->getMockBuilder(Context::class)
106+
->disableOriginalConstructor()
107+
->getMock();
108+
$this->registry = $this
109+
->getMockBuilder(Registry::class)
110+
->disableOriginalConstructor()
111+
->getMock();
112+
$this->registry
113+
->expects($this->any())
114+
->method('registry')
115+
->willReturn($this->product);
116+
$this->priceCurrencyInterface = $this
117+
->getMockBuilder(PriceCurrencyInterface::class)
118+
->disableOriginalConstructor()
119+
->getMock();
120+
$this->attributesBlock = new AttributesBlock(
121+
$this->context,
122+
$this->registry,
123+
$this->priceCurrencyInterface
124+
);
125+
}
126+
127+
/**
128+
* @return void
129+
*/
130+
public function testGetAttributeNoValue()
131+
{
132+
$this->phrase = '';
133+
$this->frontendAttribute
134+
->expects($this->any())
135+
->method('getValue')
136+
->willReturn($this->phrase);
137+
$attributes = $this->attributesBlock->getAdditionalData();
138+
$this->assertTrue(empty($attributes['phrase']));
139+
}
140+
141+
/**
142+
* @return void
143+
*/
144+
public function testGetAttributeHasValue()
145+
{
146+
$this->phrase = __('Yes');
147+
$this->frontendAttribute
148+
->expects($this->any())
149+
->method('getValue')
150+
->willReturn($this->phrase);
151+
$attributes = $this->attributesBlock->getAdditionalData();
152+
$this->assertNotTrue(empty($attributes['phrase']));
153+
$this->assertNotTrue(empty($attributes['phrase']['value']));
154+
$this->assertEquals('Yes', $attributes['phrase']['value']);
155+
}
156+
}

0 commit comments

Comments
 (0)