Skip to content

Commit

Permalink
Merge branch '2.2-develop' of github.com:magento/magento2 into fix-pr…
Browse files Browse the repository at this point in the history
…oduct-videos-gallery-events
  • Loading branch information
omiroshnichenko committed Dec 1, 2017
2 parents 56802d3 + 82caf48 commit 6f308b1
Show file tree
Hide file tree
Showing 668 changed files with 23,875 additions and 266 deletions.
18 changes: 18 additions & 0 deletions app/code/Magento/Analytics/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,22 @@
<argument name="responseResolver" xsi:type="object">NotifyDataChangedResponseResolver</argument>
</arguments>
</type>
<type name="Magento\Config\Model\Config\TypePool">
<arguments>
<argument name="sensitive" xsi:type="array">
<item name="analytics/url/signup" xsi:type="string">1</item>
<item name="analytics/url/update" xsi:type="string">1</item>
<item name="analytics/url/bi_essentials" xsi:type="string">1</item>
<item name="analytics/url/otp" xsi:type="string">1</item>
<item name="analytics/url/report" xsi:type="string">1</item>
<item name="analytics/url/notify_data_changed" xsi:type="string">1</item>
<item name="analytics/general/token" xsi:type="string">1</item>
</argument>
<argument name="environment" xsi:type="array">
<item name="crontab/default/jobs/analytics_collect_data/schedule/cron_expr" xsi:type="string">1</item>
<item name="crontab/default/jobs/analytics_update/schedule/cron_expr" xsi:type="string">1</item>
<item name="crontab/default/jobs/analytics_subscribe/schedule/cron_expr" xsi:type="string">1</item>
</argument>
</arguments>
</type>
</config>
3 changes: 3 additions & 0 deletions app/code/Magento/Backend/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
<item name="dev" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::HIDDEN</item>
<item name="general/locale/code" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::DISABLED</item>
</argument>
<argument name="exemptions" xsi:type="array">
<item name="dev/debug/debug_logging" xsi:type="string"/>
</argument>
</arguments>
</type>
<type name="Magento\Framework\View\Layout\Generator\Block">
Expand Down
8 changes: 3 additions & 5 deletions app/code/Magento/Catalog/Block/Product/View/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,13 @@ public function getAdditionalData(array $excludeAttr = [])
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
$value = $attribute->getFrontend()->getValue($product);

if (!$product->hasData($attribute->getAttributeCode())) {
$value = __('N/A');
} elseif ((string)$value == '') {
$value = __('No');
if ($value instanceof Phrase) {
$value = (string)$value;
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
$value = $this->priceCurrency->convertAndFormat($value);
}

if ($value instanceof Phrase || (is_string($value) && strlen($value))) {
if (is_string($value) && strlen($value)) {
$data[$attribute->getAttributeCode()] = [
'label' => __($attribute->getStoreLabel()),
'value' => $value,
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Block/Product/View/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function getGalleryImagesJson()
'thumb' => $image->getData('small_image_url'),
'img' => $image->getData('medium_image_url'),
'full' => $image->getData('large_image_url'),
'caption' => $image->getLabel(),
'caption' => ($image->getLabel() ?: $this->getProduct()->getName()),
'position' => $image->getPosition(),
'isMain' => $this->isMainImage($image),
'type' => str_replace('external-', '', $image->getMediaType()),
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/Model/Category/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ private function convertValues($category, $categoryData)

$categoryData[$attributeCode][0]['name'] = $fileName;
$categoryData[$attributeCode][0]['url'] = $category->getImageUrl($attributeCode);
$categoryData['image'][0]['size'] = isset($stat) ? $stat['size'] : 0;
$categoryData['image'][0]['type'] = $mime;
$categoryData[$attributeCode][0]['size'] = isset($stat) ? $stat['size'] : 0;
$categoryData[$attributeCode][0]['type'] = $mime;
}
}
}
Expand Down
101 changes: 85 additions & 16 deletions app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,19 @@ public function execute($product, $arguments = [])
if (empty($attrData) && empty($clearImages) && empty($newImages) && empty($existImages)) {
continue;
}
if (in_array($attrData, $clearImages)) {
$product->setData($mediaAttrCode, 'no_selection');
}

if (in_array($attrData, array_keys($newImages))) {
$product->setData($mediaAttrCode, $newImages[$attrData]['new_file']);
$product->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']);
}

if (in_array($attrData, array_keys($existImages)) && isset($existImages[$attrData]['label'])) {
$product->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']);
}
if (!empty($product->getData($mediaAttrCode))) {
$product->addAttributeUpdate(
$this->processMediaAttribute(
$product,
$mediaAttrCode,
$clearImages,
$newImages
);
if (in_array($mediaAttrCode, ['image', 'small_image', 'thumbnail'])) {
$this->processMediaAttributeLabel(
$product,
$mediaAttrCode,
$product->getData($mediaAttrCode),
$product->getStoreId()
$clearImages,
$newImages,
$existImages
);
}
}
Expand Down Expand Up @@ -448,4 +444,77 @@ private function getMediaAttributeCodes()
}
return $this->mediaAttributeCodes;
}

/**
* @param \Magento\Catalog\Model\Product $product
* @param $mediaAttrCode
* @param array $clearImages
* @param array $newImages
*/
private function processMediaAttribute(
\Magento\Catalog\Model\Product $product,
$mediaAttrCode,
array $clearImages,
array $newImages
) {
$attrData = $product->getData($mediaAttrCode);
if (in_array($attrData, $clearImages)) {
$product->setData($mediaAttrCode, 'no_selection');
}

if (in_array($attrData, array_keys($newImages))) {
$product->setData($mediaAttrCode, $newImages[$attrData]['new_file']);
}
if (!empty($product->getData($mediaAttrCode))) {
$product->addAttributeUpdate(
$mediaAttrCode,
$product->getData($mediaAttrCode),
$product->getStoreId()
);
}
}

/**
* @param \Magento\Catalog\Model\Product $product
* @param $mediaAttrCode
* @param array $clearImages
* @param array $newImages
* @param array $existImages
*/
private function processMediaAttributeLabel(
\Magento\Catalog\Model\Product $product,
$mediaAttrCode,
array $clearImages,
array $newImages,
array $existImages
) {
$resetLabel = false;
$attrData = $product->getData($mediaAttrCode);
if (in_array($attrData, $clearImages)) {
$product->setData($mediaAttrCode . '_label', null);
$resetLabel = true;
}

if (in_array($attrData, array_keys($newImages))) {
$product->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']);
}

if (in_array($attrData, array_keys($existImages)) && isset($existImages[$attrData]['label'])) {
$product->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']);
}

if ($attrData === 'no_selection' && !empty($product->getData($mediaAttrCode . '_label'))) {
$product->setData($mediaAttrCode . '_label', null);
$resetLabel = true;
}
if (!empty($product->getData($mediaAttrCode . '_label'))
|| $resetLabel === true
) {
$product->addAttributeUpdate(
$mediaAttrCode . '_label',
$product->getData($mediaAttrCode . '_label'),
$product->getStoreId()
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Test\Unit\Block\Product\View;

use \PHPUnit\Framework\TestCase;
use \Magento\Framework\Phrase;
use \Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
use \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend;
use \Magento\Catalog\Model\Product;
use \Magento\Framework\View\Element\Template\Context;
use \Magento\Framework\Registry;
use \Magento\Framework\Pricing\PriceCurrencyInterface;
use \Magento\Catalog\Block\Product\View\Attributes as AttributesBlock;

/**
* Test class for \Magento\Catalog\Block\Product\View\Attributes
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class AttributesTest extends TestCase
{
/**
* @var \Magento\Framework\Phrase
*/
private $phrase;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Eav\Model\Entity\Attribute\AbstractAttribute
*/
private $attribute;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend
*/
private $frontendAttribute;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product
*/
private $product;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\Element\Template\Context
*/
private $context;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Registry
*/
private $registry;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Pricing\PriceCurrencyInterface
*/
private $priceCurrencyInterface;

/**
* @var \Magento\Catalog\Block\Product\View\Attributes
*/
private $attributesBlock;

protected function setUp()
{
$this->attribute = $this
->getMockBuilder(AbstractAttribute::class)
->disableOriginalConstructor()
->getMock();
$this->attribute
->expects($this->any())
->method('getIsVisibleOnFront')
->willReturn(true);
$this->attribute
->expects($this->any())
->method('getAttributeCode')
->willReturn('phrase');
$this->frontendAttribute = $this
->getMockBuilder(AbstractFrontend::class)
->disableOriginalConstructor()
->getMock();
$this->attribute
->expects($this->any())
->method('getFrontendInput')
->willReturn('phrase');
$this->attribute
->expects($this->any())
->method('getFrontend')
->willReturn($this->frontendAttribute);
$this->product = $this
->getMockBuilder(Product::class)
->disableOriginalConstructor()
->getMock();
$this->product
->expects($this->any())
->method('getAttributes')
->willReturn([$this->attribute]);
$this->product
->expects($this->any())
->method('hasData')
->willReturn(true);
$this->context = $this
->getMockBuilder(Context::class)
->disableOriginalConstructor()
->getMock();
$this->registry = $this
->getMockBuilder(Registry::class)
->disableOriginalConstructor()
->getMock();
$this->registry
->expects($this->any())
->method('registry')
->willReturn($this->product);
$this->priceCurrencyInterface = $this
->getMockBuilder(PriceCurrencyInterface::class)
->disableOriginalConstructor()
->getMock();
$this->attributesBlock = new AttributesBlock(
$this->context,
$this->registry,
$this->priceCurrencyInterface
);
}

/**
* @return void
*/
public function testGetAttributeNoValue()
{
$this->phrase = '';
$this->frontendAttribute
->expects($this->any())
->method('getValue')
->willReturn($this->phrase);
$attributes = $this->attributesBlock->getAdditionalData();
$this->assertTrue(empty($attributes['phrase']));
}

/**
* @return void
*/
public function testGetAttributeHasValue()
{
$this->phrase = __('Yes');
$this->frontendAttribute
->expects($this->any())
->method('getValue')
->willReturn($this->phrase);
$attributes = $this->attributesBlock->getAdditionalData();
$this->assertNotTrue(empty($attributes['phrase']));
$this->assertNotTrue(empty($attributes['phrase']['value']));
$this->assertEquals('Yes', $attributes['phrase']['value']);
}
}
Loading

0 comments on commit 6f308b1

Please sign in to comment.