Skip to content

Commit 5e9755d

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop
- merged latest code from mainline branch
2 parents c7ef8c3 + 4b78a41 commit 5e9755d

File tree

70 files changed

+1912
-550
lines changed

Some content is hidden

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

70 files changed

+1912
-550
lines changed

app/code/Magento/Backend/view/adminhtml/templates/widget/grid.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $numColumns = $block->getColumns() !== null ? count($block->getColumns()) : 0;
2323
<?php if ($block->canDisplayContainer()) : ?>
2424
<div id="<?= $block->escapeHtml($block->getId()) ?>" data-grid-id="<?= $block->escapeHtml($block->getId()) ?>">
2525
<?php else : ?>
26-
<?= $block->getLayout()->getMessagesBlock()->getGroupedHtml() ?>
26+
<?= $block->getLayout()->getMessagesBlock()->getGroupedHtml() ?>
2727
<?php endif; ?>
2828

2929
<div class="admin__data-grid-header admin__data-grid-toolbar">

app/code/Magento/Bundle/Model/ResourceModel/Option/Collection.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Bundle\Model\ResourceModel\Option;
77

8+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
9+
810
/**
911
* Bundle Options Resource Collection
1012
* @api
@@ -138,12 +140,10 @@ public function setPositionOrder()
138140

139141
/**
140142
* Append selection to options
141-
* stripBefore - indicates to reload
142-
* appendAll - indicates do we need to filter by saleable and required custom options
143143
*
144144
* @param \Magento\Bundle\Model\ResourceModel\Selection\Collection $selectionsCollection
145-
* @param bool $stripBefore
146-
* @param bool $appendAll
145+
* @param bool $stripBefore indicates to reload
146+
* @param bool $appendAll indicates do we need to filter by saleable and required custom options
147147
* @return \Magento\Framework\DataObject[]
148148
*/
149149
public function appendSelections($selectionsCollection, $stripBefore = false, $appendAll = true)
@@ -156,7 +156,9 @@ public function appendSelections($selectionsCollection, $stripBefore = false, $a
156156
foreach ($selectionsCollection->getItems() as $key => $selection) {
157157
$option = $this->getItemById($selection->getOptionId());
158158
if ($option) {
159-
if ($appendAll || $selection->isSalable() && !$selection->getRequiredOptions()) {
159+
if ($appendAll ||
160+
((int) $selection->getStatus()) === Status::STATUS_ENABLED && !$selection->getRequiredOptions()
161+
) {
160162
$selection->setOption($option);
161163
$option->addSelection($selection);
162164
} else {

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@ public function getItems($attributeCode)
4343
*/
4444
public function add($attributeCode, $option)
4545
{
46-
/** @var \Magento\Eav\Api\Data\AttributeOptionInterface[] $currentOptions */
47-
$currentOptions = $this->getItems($attributeCode);
48-
if (is_array($currentOptions)) {
49-
array_walk($currentOptions, function (&$attributeOption) {
50-
/** @var \Magento\Eav\Api\Data\AttributeOptionInterface $attributeOption */
51-
$attributeOption = $attributeOption->getLabel();
52-
});
53-
if (in_array($option->getLabel(), $currentOptions, true)) {
54-
return false;
55-
}
56-
}
5746
return $this->eavOptionManagement->add(
5847
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE,
5948
$attributeCode,

app/code/Magento/CatalogImportExport/Model/Import/Product/MediaGalleryProcessor.php

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,42 @@ private function initMediaGalleryResources()
284284
}
285285
}
286286

287+
/**
288+
* Get the last media position for each product from the given list
289+
*
290+
* @param int $storeId
291+
* @param array $productIds
292+
* @return array
293+
*/
294+
private function getLastMediaPositionPerProduct(int $storeId, array $productIds): array
295+
{
296+
$result = [];
297+
if ($productIds) {
298+
$productKeyName = $this->getProductEntityLinkField();
299+
// this result could be achieved by using GROUP BY. But there is no index on position column, therefore
300+
// it can be slower than the implementation below
301+
$positions = $this->connection->fetchAll(
302+
$this->connection
303+
->select()
304+
->from($this->mediaGalleryValueTableName, [$productKeyName, 'position'])
305+
->where("$productKeyName IN (?)", $productIds)
306+
->where('value_id is not null')
307+
->where('store_id = ?', $storeId)
308+
);
309+
// Make sure the result contains all product ids even if the product has no media files
310+
$result = array_fill_keys($productIds, 0);
311+
// Find the largest position for each product
312+
foreach ($positions as $record) {
313+
$productId = $record[$productKeyName];
314+
$result[$productId] = $result[$productId] < $record['position']
315+
? $record['position']
316+
: $result[$productId];
317+
}
318+
}
319+
320+
return $result;
321+
}
322+
287323
/**
288324
* Save media gallery data per store.
289325
*
@@ -301,24 +337,30 @@ private function processMediaPerStore(
301337
) {
302338
$multiInsertData = [];
303339
$dataForSkinnyTable = [];
340+
$lastMediaPositionPerProduct = $this->getLastMediaPositionPerProduct(
341+
$storeId,
342+
array_unique(array_merge(...array_values($valueToProductId)))
343+
);
344+
304345
foreach ($mediaGalleryData as $mediaGalleryRows) {
305346
foreach ($mediaGalleryRows as $insertValue) {
306-
foreach ($newMediaValues as $value_id => $values) {
347+
foreach ($newMediaValues as $valueId => $values) {
307348
if ($values['value'] == $insertValue['value']) {
308-
$insertValue['value_id'] = $value_id;
349+
$insertValue['value_id'] = $valueId;
309350
$insertValue[$this->getProductEntityLinkField()]
310351
= array_shift($valueToProductId[$values['value']]);
311-
unset($newMediaValues[$value_id]);
352+
unset($newMediaValues[$valueId]);
312353
break;
313354
}
314355
}
315356
if (isset($insertValue['value_id'])) {
357+
$productId = $insertValue[$this->getProductEntityLinkField()];
316358
$valueArr = [
317359
'value_id' => $insertValue['value_id'],
318360
'store_id' => $storeId,
319-
$this->getProductEntityLinkField() => $insertValue[$this->getProductEntityLinkField()],
361+
$this->getProductEntityLinkField() => $productId,
320362
'label' => $insertValue['label'],
321-
'position' => $insertValue['position'],
363+
'position' => $lastMediaPositionPerProduct[$productId] + $insertValue['position'],
322364
'disabled' => $insertValue['disabled'],
323365
];
324366
$multiInsertData[] = $valueArr;

app/code/Magento/CatalogUrlRewrite/Observer/CategoryUrlPathAutogeneratorObserver.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator;
1010
use Magento\CatalogUrlRewrite\Service\V1\StoreViewService;
1111
use Magento\Catalog\Api\CategoryRepositoryInterface;
12-
use Magento\Framework\Event\Observer;
1312
use Magento\CatalogUrlRewrite\Model\Category\ChildrenCategoriesProvider;
1413
use Magento\Framework\Event\ObserverInterface;
1514
use Magento\Store\Model\Store;
@@ -68,13 +67,15 @@ public function execute(\Magento\Framework\Event\Observer $observer)
6867
{
6968
/** @var Category $category */
7069
$category = $observer->getEvent()->getCategory();
71-
$useDefaultAttribute = !$category->isObjectNew() && !empty($category->getData('use_default')['url_key']);
70+
$useDefaultAttribute = !empty($category->getData('use_default')['url_key']);
7271
if ($category->getUrlKey() !== false && !$useDefaultAttribute) {
7372
$resultUrlKey = $this->categoryUrlPathGenerator->getUrlKey($category);
7473
$this->updateUrlKey($category, $resultUrlKey);
75-
} else if ($useDefaultAttribute) {
76-
$resultUrlKey = $category->formatUrlKey($category->getOrigData('name'));
77-
$this->updateUrlKey($category, $resultUrlKey);
74+
} elseif ($useDefaultAttribute) {
75+
if (!$category->isObjectNew()) {
76+
$resultUrlKey = $category->formatUrlKey($category->getOrigData('name'));
77+
$this->updateUrlKey($category, $resultUrlKey);
78+
}
7879
$category->setUrlKey(null)->setUrlPath(null);
7980
}
8081
}

0 commit comments

Comments
 (0)