Skip to content

Commit 7e4234a

Browse files
author
Oleksandr Iegorov
committed
Merge branch 'develop' of https://github.com/magento/magento2ce into MAGETWO-66825-1
2 parents 006cf57 + f63b0a1 commit 7e4234a

File tree

41 files changed

+506
-294
lines changed

Some content is hidden

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

41 files changed

+506
-294
lines changed

app/code/Magento/Bundle/Observer/LoadProductOptionsObserver.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

app/code/Magento/Bundle/etc/frontend/events.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
<event name="catalog_product_upsell">
1010
<observer name="bundle_observer" instance="Magento\Bundle\Observer\AppendUpsellProductsObserver"/>
1111
</event>
12-
<event name="catalog_product_collection_load_after">
13-
<observer name="bundle_observer" instance="Magento\Bundle\Observer\LoadProductOptionsObserver"/>
14-
</event>
1512
<event name="product_option_renderer_init">
1613
<observer name="bundle_observer" instance="Magento\Bundle\Observer\InitOptionRendererObserver"/>
1714
</event>

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,9 +2175,7 @@ private function fillTierPriceData(\Magento\Framework\DB\Select $select)
21752175
}
21762176
foreach ($this->getItems() as $item) {
21772177
$productId = $item->getData($this->getLinkField());
2178-
if (isset($tierPrices[$productId])) {
2179-
$this->getBackend()->setPriceData($item, $tierPrices[$productId]);
2180-
}
2178+
$this->getBackend()->setPriceData($item, isset($tierPrices[$productId]) ? $tierPrices[$productId] : []);
21812179
}
21822180
}
21832181

app/code/Magento/CatalogSearch/Model/Search/FilterMapper/ExclusionStrategy.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ public function apply(
9797
[
9898
$alias => $tableName
9999
],
100-
'search_index.entity_id = category_ids_index.product_id',
100+
$this->resourceConnection->getConnection()->quoteInto(
101+
'search_index.entity_id = category_ids_index.product_id AND category_ids_index.store_id = ?',
102+
$this->storeManager->getStore()->getId()
103+
),
101104
[]
102105
);
103106
$isApplied = true;

app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function getJsonConfig()
223223
],
224224
'productId' => $currentProduct->getId(),
225225
'chooseText' => __('Choose an Option...'),
226-
'images' => isset($options['images']) ? $options['images'] : [],
226+
'images' => $this->getOptionImages(),
227227
'index' => isset($options['index']) ? $options['index'] : [],
228228
];
229229

@@ -236,6 +236,33 @@ public function getJsonConfig()
236236
return $this->jsonEncoder->encode($config);
237237
}
238238

239+
/**
240+
* Get product images for configurable variations
241+
*
242+
* @return array
243+
*/
244+
protected function getOptionImages()
245+
{
246+
$images = [];
247+
foreach ($this->getAllowProducts() as $product) {
248+
249+
$productImages = $this->helper->getGalleryImages($product) ?: [];
250+
foreach ($productImages as $image) {
251+
$images[$product->getId()][] =
252+
[
253+
'thumb' => $image->getData('small_image_url'),
254+
'img' => $image->getData('medium_image_url'),
255+
'full' => $image->getData('large_image_url'),
256+
'caption' => $image->getLabel(),
257+
'position' => $image->getPosition(),
258+
'isMain' => $image->getFile() == $product->getImage(),
259+
];
260+
}
261+
}
262+
263+
return $images;
264+
}
265+
239266
/**
240267
* @return array
241268
*/

app/code/Magento/ConfigurableProduct/Helper/Data.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,11 @@ public function getGalleryImages(\Magento\Catalog\Api\Data\ProductInterface $pro
7676
public function getOptions($currentProduct, $allowedProducts)
7777
{
7878
$options = [];
79+
$allowAttributes = $this->getAllowAttributes($currentProduct);
80+
7981
foreach ($allowedProducts as $product) {
8082
$productId = $product->getId();
81-
$images = $this->getGalleryImages($product);
82-
if ($images) {
83-
foreach ($images as $image) {
84-
$options['images'][$productId][] =
85-
[
86-
'thumb' => $image->getData('small_image_url'),
87-
'img' => $image->getData('medium_image_url'),
88-
'full' => $image->getData('large_image_url'),
89-
'caption' => $image->getLabel(),
90-
'position' => $image->getPosition(),
91-
'isMain' => $image->getFile() == $product->getImage(),
92-
];
93-
}
94-
}
95-
foreach ($this->getAllowAttributes($currentProduct) as $attribute) {
83+
foreach ($allowAttributes as $attribute) {
9684
$productAttribute = $attribute->getProductAttribute();
9785
$productAttributeId = $productAttribute->getId();
9886
$attributeValue = $product->getData($productAttribute->getAttributeCode());

app/code/Magento/Directory/view/frontend/templates/currency.phtml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,16 @@
1919
<div class="switcher currency switcher-currency" id="switcher-currency<?php echo $block->escapeHtmlAttr($id) ?>">
2020
<strong class="label switcher-label"><span><?php echo $block->escapeHtml(__('Currency')) ?></span></strong>
2121
<div class="actions dropdown options switcher-options">
22-
<div class="action toggle switcher-trigger" id="switcher-currency-trigger<?php echo $block->escapeHtmlAttr($id) ?>">
22+
<div class="action toggle switcher-trigger"
23+
id="switcher-currency-trigger<?php echo $block->escapeHtmlAttr($id) ?>"
24+
data-mage-init='{"dropdown":{}}'
25+
data-toggle="dropdown"
26+
data-trigger-keypress-button="true">
2327
<strong class="language-<?php echo $block->escapeHtml($block->getCurrentCurrencyCode()) ?>">
2428
<span><?php echo $block->escapeHtml($currentCurrencyCode) ?> - <?php echo @$block->escapeHtml($currencies[$currentCurrencyCode]) ?></span>
2529
</strong>
2630
</div>
27-
<ul class="dropdown switcher-dropdown" data-mage-init='{"dropdownDialog":{
28-
"appendTo":"#switcher-currency<?php echo $block->escapeJs($id) ?> > .options",
29-
"triggerTarget":"#switcher-currency-trigger<?php echo $block->escapeJs($id) ?>",
30-
"closeOnMouseLeave": false,
31-
"triggerClass":"active",
32-
"parentClass":"active",
33-
"buttons":null}}'>
31+
<ul class="dropdown switcher-dropdown" data-target="dropdown">
3432
<?php foreach ($currencies as $_code => $_name): ?>
3533
<?php if ($_code != $currentCurrencyCode): ?>
3634
<li class="currency-<?php echo $block->escapeHtmlAttr($_code) ?> switcher-option">

app/code/Magento/Store/view/frontend/templates/switch/languages.phtml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@
1313
<div class="switcher language switcher-language" data-ui-id="language-switcher" id="switcher-language<?php echo $block->escapeHtmlAttr($id) ?>">
1414
<strong class="label switcher-label"><span><?php echo $block->escapeHtml(__('Language')) ?></span></strong>
1515
<div class="actions dropdown options switcher-options">
16-
<div class="action toggle switcher-trigger" id="switcher-language-trigger<?php echo $block->escapeHtmlAttr($id) ?>">
16+
<div class="action toggle switcher-trigger"
17+
id="switcher-language-trigger<?php echo $block->escapeHtmlAttr($id) ?>"
18+
data-mage-init='{"dropdown":{}}'
19+
data-toggle="dropdown"
20+
data-trigger-keypress-button="true">
1721
<strong class="view-<?php echo $block->escapeHtml($block->getCurrentStoreCode()) ?>">
1822
<span><?php echo $block->escapeHtml($block->getStoreName()) ?></span>
1923
</strong>
2024
</div>
2125
<ul class="dropdown switcher-dropdown"
22-
data-mage-init='{"dropdownDialog":{
23-
"appendTo":"#switcher-language<?php echo $block->escapeJs($id) ?> > .options",
24-
"triggerTarget":"#switcher-language-trigger<?php echo $block->escapeJs($id) ?>",
25-
"closeOnMouseLeave": false,
26-
"triggerClass":"active",
27-
"parentClass":"active",
28-
"buttons":null}}'>
26+
data-target="dropdown">
2927
<?php foreach ($block->getStores() as $_lang): ?>
3028
<?php if ($_lang->getId() != $block->getCurrentStoreId()): ?>
3129
<li class="view-<?php echo $block->escapeHtml($_lang->getCode()); ?> switcher-option">

app/code/Magento/Swatches/Block/Product/Renderer/Listing/Configurable.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Swatches\Block\Product\Renderer\Listing;
77

8+
use Magento\Catalog\Model\Product;
9+
810
/**
911
* Swatch renderer block in Category page
1012
*
@@ -62,4 +64,82 @@ public function getJsonConfig()
6264
$this->unsetData('allow_products');
6365
return parent::getJsonConfig();
6466
}
67+
68+
/**
69+
* Do not load images for Configurable product with swatches due to its loaded by request
70+
*
71+
* @return array
72+
*/
73+
protected function getOptionImages()
74+
{
75+
return [];
76+
}
77+
78+
/**
79+
* Add images to result json config in case of Layered Navigation is used
80+
*
81+
* @return array
82+
*/
83+
protected function _getAdditionalConfig()
84+
{
85+
$config = parent::_getAdditionalConfig();
86+
if (!empty($this->getRequest()->getQuery()->toArray())) {
87+
$config['preSelectedGallery'] = $this->getProductVariationWithMedia(
88+
$this->getProduct(),
89+
$this->getRequest()->getQuery()->toArray()
90+
);
91+
}
92+
93+
return $config;
94+
}
95+
96+
/**
97+
* Get product images for chosen variation based on selected product attributes
98+
*
99+
* @param Product $configurableProduct
100+
* @param array $additionalAttributes
101+
* @return array
102+
*/
103+
private function getProductVariationWithMedia(
104+
Product $configurableProduct,
105+
array $additionalAttributes = []
106+
) {
107+
$configurableAttributes = $this->getLayeredAttributesIfExists($configurableProduct, $additionalAttributes);
108+
if (!$configurableAttributes) {
109+
return [];
110+
}
111+
112+
$product = $this->swatchHelper->loadVariationByFallback($configurableProduct, $configurableAttributes);
113+
114+
return $product ? $this->swatchHelper->getProductMediaGallery($product) : [];
115+
}
116+
117+
/**
118+
* Get product attributes which uses in layered navigation and present for given configurable product
119+
*
120+
* @param Product $configurableProduct
121+
* @param array $additionalAttributes
122+
* @return array
123+
*/
124+
private function getLayeredAttributesIfExists(Product $configurableProduct, array $additionalAttributes)
125+
{
126+
$configurableAttributes = $this->swatchHelper->getAttributesFromConfigurable($configurableProduct);
127+
128+
$layeredAttributes = [];
129+
130+
$configurableAttributes = array_map(function ($attribute) {
131+
return $attribute->getAttributeCode();
132+
}, $configurableAttributes);
133+
134+
$commonAttributeCodes = array_intersect(
135+
$configurableAttributes,
136+
array_keys($additionalAttributes)
137+
);
138+
139+
foreach ($commonAttributeCodes as $attributeCode) {
140+
$layeredAttributes[$attributeCode] = $additionalAttributes[$attributeCode];
141+
}
142+
143+
return $layeredAttributes;
144+
}
65145
}

app/code/Magento/Swatches/Controller/Ajax/Media.php

Lines changed: 12 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,104 +8,55 @@
88

99
use Magento\Framework\App\Action\Context;
1010
use Magento\Framework\Controller\ResultFactory;
11-
use Magento\Catalog\Model\Product;
1211

1312
/**
1413
* Class Media
1514
*/
1615
class Media extends \Magento\Framework\App\Action\Action
1716
{
1817
/**
19-
* @var \Magento\Swatches\Helper\Data
18+
* @var \Magento\Catalog\Model\Product Factory
2019
*/
21-
protected $swatchHelper;
20+
protected $productModelFactory;
2221

2322
/**
24-
* @var \Magento\Catalog\Model\ProductFactory
23+
* @var \Magento\Swatches\Helper\Data
2524
*/
26-
protected $productModelFactory;
25+
private $swatchHelper;
2726

2827
/**
2928
* @param Context $context
30-
* @param \Magento\Swatches\Helper\Data $swatchHelper
3129
* @param \Magento\Catalog\Model\ProductFactory $productModelFactory
30+
* @param \Magento\Swatches\Helper\Data $swatchHelper
3231
*/
3332
public function __construct(
3433
Context $context,
35-
\Magento\Swatches\Helper\Data $swatchHelper,
36-
\Magento\Catalog\Model\ProductFactory $productModelFactory
34+
\Magento\Catalog\Model\ProductFactory $productModelFactory,
35+
\Magento\Swatches\Helper\Data $swatchHelper
3736
) {
38-
$this->swatchHelper = $swatchHelper;
3937
$this->productModelFactory = $productModelFactory;
38+
$this->swatchHelper = $swatchHelper;
4039

4140
parent::__construct($context);
4241
}
4342

4443
/**
45-
* Get product media by fallback:
46-
* 1stly by default attribute values
47-
* 2ndly by getting base image from configurable product
44+
* Get product media for specified configurable product variation
4845
*
4946
* @return string
5047
*/
5148
public function execute()
5249
{
5350
$productMedia = [];
5451
if ($productId = (int)$this->getRequest()->getParam('product_id')) {
55-
$currentConfigurable = $this->productModelFactory->create()->load($productId);
56-
$attributes = (array)$this->getRequest()->getParam('attributes');
57-
if (!empty($attributes)) {
58-
$product = $this->getProductVariationWithMedia($currentConfigurable, $attributes);
59-
}
60-
if ((empty($product) || (!$product->getImage() || $product->getImage() == 'no_selection'))
61-
&& isset($currentConfigurable)
62-
) {
63-
$product = $currentConfigurable;
64-
}
65-
$productMedia = $this->swatchHelper->getProductMediaGallery($product);
52+
$productMedia = $this->swatchHelper->getProductMediaGallery(
53+
$this->productModelFactory->create()->load($productId)
54+
);
6655
}
6756

6857
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
6958
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
7059
$resultJson->setData($productMedia);
7160
return $resultJson;
7261
}
73-
74-
protected function getProductVariationWithMedia(Product $currentConfigurable, array $attributes)
75-
{
76-
$product = null;
77-
$layeredAttributes = [];
78-
$configurableAttributes = $this->swatchHelper->getAttributesFromConfigurable($currentConfigurable);
79-
if ($configurableAttributes) {
80-
$layeredAttributes = $this->getLayeredAttributesIfExists($configurableAttributes);
81-
}
82-
$resultAttributes = array_merge($layeredAttributes, $attributes);
83-
84-
$product = $this->swatchHelper->loadVariationByFallback($currentConfigurable, $resultAttributes);
85-
if (!$product || (!$product->getImage() || $product->getImage() == 'no_selection')) {
86-
$product = $this->swatchHelper->loadFirstVariationWithSwatchImage($currentConfigurable, $resultAttributes);
87-
}
88-
if (!$product) {
89-
$product = $this->swatchHelper->loadFirstVariationWithImage($currentConfigurable, $resultAttributes);
90-
}
91-
return $product;
92-
}
93-
94-
/**
95-
* @param array $configurableAttributes
96-
* @return array
97-
*/
98-
protected function getLayeredAttributesIfExists(array $configurableAttributes)
99-
{
100-
$layeredAttributes = [];
101-
102-
foreach ($configurableAttributes as $attribute) {
103-
if ($urlAdditional = (array)$this->getRequest()->getParam('additional')) {
104-
if (array_key_exists($attribute['attribute_code'], $urlAdditional)) {
105-
$layeredAttributes[$attribute['attribute_code']] = $urlAdditional[$attribute['attribute_code']];
106-
}
107-
}
108-
}
109-
return $layeredAttributes;
110-
}
11162
}

0 commit comments

Comments
 (0)