Skip to content

Commit deff36e

Browse files
author
Igor Miniailo
committed
Merge branch 'develop' into product-video-PR3
2 parents 00b8154 + 9d31376 commit deff36e

File tree

128 files changed

+4484
-1311
lines changed

Some content is hidden

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

128 files changed

+4484
-1311
lines changed

app/code/Magento/Backend/view/adminhtml/templates/widget/form/renderer/fieldset/element.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
$element = $block->getElement();
1313
$note = $element->getNote() ? '<div class="note" id="' . $element->getId() . '-note">' . $element->getNote() . '</div>' : '';
1414
$elementBeforeLabel = $element->getExtType() == 'checkbox admin__control-checkbox' || $element->getExtType() == 'radio admin__control-radio';
15-
$addOn = $element->getBeforeElementHtml() || $element->getAfterElementHtml();
15+
$addOn = ($element->getBeforeElementHtml() || $element->getAfterElementHtml()) && !$element->getNoWrapAsAddon();
1616
$fieldId = ($element->getHtmlContainerId()) ? ' id="' . $element->getHtmlContainerId() . '"' : '';
1717
$fieldClass = "admin__field field field-{$element->getId()} {$element->getCssClass()}";
1818
$fieldClass .= ($elementBeforeLabel) ? ' choice' : '';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public function prepareSortableFieldsByCategory($category)
296296
}
297297
$availableOrders = $this->getAvailableOrders();
298298
if (!$this->getSortBy()) {
299-
$categorySortBy = $category->getDefaultSortBy();
299+
$categorySortBy = $this->getDefaultSortBy() ?: $category->getDefaultSortBy();
300300
if ($categorySortBy) {
301301
if (!$availableOrders) {
302302
$availableOrders = $this->_getConfig()->getAttributeUsedForSortByArray();

app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Catalog\Block\Product\ProductList;
77

8+
use Magento\Catalog\Helper\Product\ProductList;
89
use Magento\Catalog\Model\Product\ProductList\Toolbar as ToolbarModel;
910

1011
/**
@@ -63,7 +64,7 @@ class Toolbar extends \Magento\Framework\View\Element\Template
6364
*
6465
* @var string
6566
*/
66-
protected $_direction = \Magento\Catalog\Helper\Product\ProductList::DEFAULT_SORT_DIRECTION;
67+
protected $_direction = ProductList::DEFAULT_SORT_DIRECTION;
6768

6869
/**
6970
* Default View mode
@@ -102,7 +103,7 @@ class Toolbar extends \Magento\Framework\View\Element\Template
102103
protected $_toolbarModel;
103104

104105
/**
105-
* @var \Magento\Catalog\Helper\Product\ProductList
106+
* @var ProductList
106107
*/
107108
protected $_productListHelper;
108109

@@ -122,7 +123,7 @@ class Toolbar extends \Magento\Framework\View\Element\Template
122123
* @param \Magento\Catalog\Model\Config $catalogConfig
123124
* @param ToolbarModel $toolbarModel
124125
* @param \Magento\Framework\Url\EncoderInterface $urlEncoder
125-
* @param \Magento\Catalog\Helper\Product\ProductList $productListHelper
126+
* @param ProductList $productListHelper
126127
* @param \Magento\Framework\Data\Helper\PostHelper $postDataHelper
127128
* @param array $data
128129
*/
@@ -132,7 +133,7 @@ public function __construct(
132133
\Magento\Catalog\Model\Config $catalogConfig,
133134
ToolbarModel $toolbarModel,
134135
\Magento\Framework\Url\EncoderInterface $urlEncoder,
135-
\Magento\Catalog\Helper\Product\ProductList $productListHelper,
136+
ProductList $productListHelper,
136137
\Magento\Framework\Data\Helper\PostHelper $postDataHelper,
137138
array $data = []
138139
) {
@@ -355,7 +356,7 @@ public function removeOrderFromAvailableOrders($order)
355356
}
356357

357358
/**
358-
* Compare defined order field vith current order field
359+
* Compare defined order field with current order field
359360
*
360361
* @param string $order
361362
* @return bool
@@ -375,7 +376,7 @@ public function getPagerUrl($params = [])
375376
{
376377
$urlParams = [];
377378
$urlParams['_current'] = true;
378-
$urlParams['_escape'] = true;
379+
$urlParams['_escape'] = false;
379380
$urlParams['_use_rewrite'] = true;
380381
$urlParams['_query'] = $params;
381382
return $this->getUrl('*/*/*', $urlParams);
@@ -678,7 +679,7 @@ public function getWidgetOptionsJson(array $customOptions = [])
678679
'order' => ToolbarModel::ORDER_PARAM_NAME,
679680
'limit' => ToolbarModel::LIMIT_PARAM_NAME,
680681
'modeDefault' => $defaultMode,
681-
'directionDefault' => \Magento\Catalog\Helper\Product\ProductList::DEFAULT_SORT_DIRECTION,
682+
'directionDefault' => $this->_direction ?: ProductList::DEFAULT_SORT_DIRECTION,
682683
'orderDefault' => $this->_productListHelper->getDefaultSortField(),
683684
'limitDefault' => $this->_productListHelper->getDefaultLimitPerPageValue($defaultMode),
684685
'url' => $this->getPagerUrl(),

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

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Magento\Catalog\Block\Product\View;
1313

1414
use Magento\Framework\Data\Collection;
15+
use Magento\Framework\Json\EncoderInterface;
1516
use Magento\Catalog\Helper\Image;
1617

1718
class Gallery extends \Magento\Catalog\Block\Product\View\AbstractView
@@ -21,6 +22,27 @@ class Gallery extends \Magento\Catalog\Block\Product\View\AbstractView
2122
*/
2223
protected $configView;
2324

25+
/**
26+
* @var \Magento\Framework\Json\EncoderInterface
27+
*/
28+
protected $jsonEncoder;
29+
30+
/**
31+
* @param \Magento\Catalog\Block\Product\Context $context
32+
* @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
33+
* @param EncoderInterface $jsonEncoder
34+
* @param array $data
35+
*/
36+
public function __construct(
37+
\Magento\Catalog\Block\Product\Context $context,
38+
\Magento\Framework\Stdlib\ArrayUtils $arrayUtils,
39+
EncoderInterface $jsonEncoder,
40+
array $data = []
41+
) {
42+
$this->jsonEncoder = $jsonEncoder;
43+
parent::__construct($context, $arrayUtils, $data);
44+
}
45+
2446
/**
2547
* Retrieve collection of gallery images
2648
*
@@ -42,12 +64,14 @@ public function getGalleryImages()
4264
$image->setData(
4365
'medium_image_url',
4466
$this->_imageHelper->init($product, 'product_page_image_medium')
67+
->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
4568
->setImageFile($image->getFile())
4669
->getUrl()
4770
);
4871
$image->setData(
4972
'large_image_url',
5073
$this->_imageHelper->init($product, 'product_page_image_large')
74+
->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
5175
->setImageFile($image->getFile())
5276
->getUrl()
5377
);
@@ -57,6 +81,26 @@ public function getGalleryImages()
5781
return $images;
5882
}
5983

84+
/**
85+
* Return magnifier options
86+
*
87+
* @return string
88+
*/
89+
public function getMagnifier()
90+
{
91+
return $this->jsonEncoder->encode($this->getVar('magnifier'));
92+
}
93+
94+
/**
95+
* Return breakpoints options
96+
*
97+
* @return string
98+
*/
99+
public function getBreakpoints()
100+
{
101+
return $this->jsonEncoder->encode($this->getVar('breakpoints'));
102+
}
103+
60104
/**
61105
* Retrieve product images in JSON format
62106
*
@@ -69,12 +113,22 @@ public function getGalleryImagesJson()
69113
$imagesItems[] = [
70114
'thumb' => $image->getData('small_image_url'),
71115
'img' => $image->getData('medium_image_url'),
72-
'original' => $image->getData('large_image_url'),
116+
'full' => $image->getData('large_image_url'),
73117
'caption' => $image->getLabel(),
74118
'position' => $image->getPosition(),
75119
'isMain' => $this->isMainImage($image),
76120
];
77121
}
122+
if (empty($imagesItems)) {
123+
$imagesItems[] = [
124+
'thumb' => $this->_imageHelper->getDefaultPlaceholderUrl('thumbnail'),
125+
'img' => $this->_imageHelper->getDefaultPlaceholderUrl('image'),
126+
'full' => $this->_imageHelper->getDefaultPlaceholderUrl('image'),
127+
'caption' => '',
128+
'position' => '0',
129+
'isMain' => true,
130+
];
131+
}
78132
return json_encode($imagesItems);
79133
}
80134

app/code/Magento/Catalog/Helper/Image.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,13 @@ public function placeholder($fileName)
436436
*/
437437
public function getPlaceholder($placeholder = null)
438438
{
439-
if (!$this->_placeholder) {
440-
$placeholder = $placeholder ? : $this->_getModel()->getDestinationSubdir();
441-
$this->_placeholder = 'Magento_Catalog::images/product/placeholder/' . $placeholder . '.jpg';
439+
if ($placeholder) {
440+
$placeholderFullPath = 'Magento_Catalog::images/product/placeholder/' . $placeholder . '.jpg';
441+
} else {
442+
$placeholderFullPath = $this->_placeholder
443+
?: 'Magento_Catalog::images/product/placeholder/' . $this->_getModel()->getDestinationSubdir() . '.jpg';
442444
}
443-
return $this->_placeholder;
445+
return $placeholderFullPath;
444446
}
445447

446448
/**
@@ -816,7 +818,7 @@ public function getWidth()
816818
*/
817819
public function getHeight()
818820
{
819-
return $this->getAttribute('height') ? : $this->getAttribute('width');
821+
return $this->getAttribute('height') ?: $this->getAttribute('width');
820822
}
821823

822824
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* Catalog product model
2020
*
2121
* @method Product setHasError(bool $value)
22+
* @method \Magento\Catalog\Model\ResourceModel\Product getResource()
2223
* @method null|bool getHasError()
2324
* @method Product setAssociatedProductIds(array $productIds)
2425
* @method array getAssociatedProductIds()

app/code/Magento/Catalog/Model/Product/Image.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
* @SuppressWarnings(PHPMD.TooManyFields)
2020
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2121
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
22+
* @method string getFile()
23+
* @method string getLabel()
24+
* @method string getPosition()
2225
*/
2326
class Image extends \Magento\Framework\Model\AbstractModel
2427
{

app/code/Magento/Catalog/Setup/UpgradeData.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,31 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
4646
$entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
4747
$attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);
4848

49-
$attributeGroupId = $categorySetup->getAttributeGroupId($entityTypeId, $attributeSetId, 'Images');
50-
51-
// update General Group
52-
$categorySetup->updateAttributeGroup(
49+
$attributeGroup = $categorySetup->getAttributeGroup(
5350
$entityTypeId,
5451
$attributeSetId,
55-
$attributeGroupId,
56-
'attribute_group_name',
57-
'Images and Videos'
52+
'Images',
53+
'attribute_group_name'
5854
);
55+
if (isset($attributeGroup['attribute_group_name']) && $attributeGroup['attribute_group_name'] == 'Images') {
56+
// update General Group
57+
$categorySetup->updateAttributeGroup(
58+
$entityTypeId,
59+
$attributeSetId,
60+
$attributeGroup['attribute_group_id'],
61+
'attribute_group_name',
62+
'Images and Videos'
63+
);
64+
}
65+
}
66+
67+
if ($context->getVersion()
68+
&& version_compare($context->getVersion(), '2.0.1') < 0
69+
) {
5970
$select = $setup->getConnection()->select()
6071
->from(
6172
$setup->getTable('catalog_product_entity_group_price'),
6273
[
63-
'value_id',
6474
'entity_id',
6575
'all_groups',
6676
'customer_group_id',
@@ -69,11 +79,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
6979
'website_id'
7080
]
7181
);
72-
$setup->getConnection()->insertFromSelect(
82+
$select = $setup->getConnection()->insertFromSelect(
7383
$select,
74-
$setup->getTable('catalog_product_entity_group_price'),
84+
$setup->getTable('catalog_product_entity_tier_price'),
7585
[
76-
'value_id',
7786
'entity_id',
7887
'all_groups',
7988
'customer_group_id',
@@ -82,6 +91,8 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
8291
'website_id'
8392
]
8493
);
94+
$setup->getConnection()->query($select);
95+
8596
$categorySetupManager = $this->categorySetupFactory->create();
8697
$categorySetupManager->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'group_price');
8798
}

app/code/Magento/Catalog/Setup/UpgradeSchema.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ protected function addForeignKeys(SchemaSetupInterface $setup)
140140
*/
141141
private function addSupportVideoMediaAttributes(SchemaSetupInterface $setup)
142142
{
143+
if ($setup->tableExists(Media::GALLERY_VALUE_TO_ENTITY_TABLE)) {
144+
return;
145+
};
146+
143147
/** Add support video media attribute */
144148
$this->createValueToEntityTable($setup);
145149
/**

app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class GalleryTest extends \PHPUnit_Framework_TestCase
3232
*/
3333
protected $registry;
3434

35+
/**
36+
* @var \Magento\Framework\Json\EncoderInterface|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
protected $jsonEncoderMock;
39+
3540
protected function setUp()
3641
{
3742
$this->mockContext();
@@ -40,9 +45,14 @@ protected function setUp()
4045
->disableOriginalConstructor()
4146
->getMock();
4247

48+
$this->jsonEncoderMock = $this->getMockBuilder('Magento\Framework\Json\EncoderInterface')
49+
->disableOriginalConstructor()
50+
->getMock();
51+
4352
$this->model = new \Magento\Catalog\Block\Product\View\Gallery(
4453
$this->context,
45-
$this->arrayUtils
54+
$this->arrayUtils,
55+
$this->jsonEncoderMock
4656
);
4757
}
4858

@@ -103,7 +113,8 @@ public function testGetGalleryImages()
103113
[$productMock, 'product_page_image_small', [], $this->imageHelper],
104114
[$productMock, 'product_page_image_medium', [], $this->imageHelper],
105115
[$productMock, 'product_page_image_large', [], $this->imageHelper],
106-
]);
116+
])
117+
->willReturnSelf();
107118
$this->imageHelper->expects($this->exactly(3))
108119
->method('setImageFile')
109120
->with('test_file')
@@ -118,6 +129,19 @@ public function testGetGalleryImages()
118129
->method('getUrl')
119130
->willReturn('product_page_image_large_url');
120131

132+
$this->imageHelper->expects($this->exactly(2))
133+
->method('constrainOnly')
134+
->with(true)
135+
->willReturnSelf();
136+
$this->imageHelper->expects($this->exactly(2))
137+
->method('keepAspectRatio')
138+
->with(true)
139+
->willReturnSelf();
140+
$this->imageHelper->expects($this->exactly(2))
141+
->method('keepFrame')
142+
->with(false)
143+
->willReturnSelf();
144+
121145
$images = $this->model->getGalleryImages();
122146
$this->assertInstanceOf('Magento\Framework\Data\Collection', $images);
123147
}

0 commit comments

Comments
 (0)