Skip to content

Commit 60f8542

Browse files
committed
Merge branch 'develop' into develop-team-pr1
2 parents 07f4f58 + 265bfae commit 60f8542

File tree

16 files changed

+210
-261
lines changed

16 files changed

+210
-261
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/Catalog/Setup/InstallSchema.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,18 +2022,6 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
20222022
'attribute_id',
20232023
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
20242024
)
2025-
->addForeignKey(
2026-
$installer->getFkName(
2027-
'catalog_product_entity_media_gallery',
2028-
'entity_id',
2029-
'catalog_product_entity',
2030-
'entity_id'
2031-
),
2032-
'entity_id',
2033-
$installer->getTable('catalog_product_entity'),
2034-
'entity_id',
2035-
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
2036-
)
20372025
->setComment(
20382026
'Catalog Product Media Gallery Attribute Backend Table'
20392027
);

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/Eav/Setup/EavSetup.php

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,35 +1002,36 @@ private function _updateAttributeAdditionalData($entityTypeId, $id, $field, $val
10021002
return $this;
10031003
}
10041004
$additionalTableExists = $this->setup->getConnection()->isTableExists($this->setup->getTable($additionalTable));
1005-
if ($additionalTable && $additionalTableExists) {
1006-
$attributeFields = $this->setup->getConnection()->describeTable($this->setup->getTable($additionalTable));
1007-
if (is_array($field)) {
1008-
$bind = [];
1009-
foreach ($field as $k => $v) {
1010-
if (isset($attributeFields[$k])) {
1011-
$bind[$k] = $this->setup->getConnection()->prepareColumnValue($attributeFields[$k], $v);
1012-
}
1013-
}
1014-
if (!$bind) {
1015-
return $this;
1016-
}
1017-
$field = $bind;
1018-
} else {
1019-
if (!isset($attributeFields[$field])) {
1020-
return $this;
1005+
if (!$additionalTableExists) {
1006+
return $this;
1007+
}
1008+
$attributeFields = $this->setup->getConnection()->describeTable($this->setup->getTable($additionalTable));
1009+
if (is_array($field)) {
1010+
$bind = [];
1011+
foreach ($field as $k => $v) {
1012+
if (isset($attributeFields[$k])) {
1013+
$bind[$k] = $this->setup->getConnection()->prepareColumnValue($attributeFields[$k], $v);
10211014
}
10221015
}
1023-
$this->setup->updateTableRow(
1024-
$this->setup->getTable($additionalTable),
1025-
'attribute_id',
1026-
$this->getAttributeId($entityTypeId, $id),
1027-
$field,
1028-
$value
1029-
);
1030-
1031-
$attribute = $this->getAttribute($entityTypeId, $id);
1032-
$this->updateCachedRow($field, $value, $attribute);
1016+
if (!$bind) {
1017+
return $this;
1018+
}
1019+
$field = $bind;
1020+
} else {
1021+
if (!isset($attributeFields[$field])) {
1022+
return $this;
1023+
}
10331024
}
1025+
$this->setup->updateTableRow(
1026+
$this->setup->getTable($additionalTable),
1027+
'attribute_id',
1028+
$this->getAttributeId($entityTypeId, $id),
1029+
$field,
1030+
$value
1031+
);
1032+
1033+
$attribute = $this->getAttribute($entityTypeId, $id);
1034+
$this->updateCachedRow($field, $value, $attribute);
10341035

10351036
return $this;
10361037
}

app/code/Magento/Sales/Model/ResourceModel/Order/Status.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @author Magento Core Team <core@magentocommerce.com>
1919
*/
20-
class Status extends \Magento\Framework\Model\ResourceModel\Db\VersionControl\AbstractDb
20+
class Status extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
2121
{
2222
/**
2323
* Status labels table

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
}

0 commit comments

Comments
 (0)