Skip to content

Commit 3572ee9

Browse files
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - #13341: Bugfix/13327 ui active state not removed from previous menu item (by @arnoudhgz) - #13364: [Backport 2.2] In checkout->multishipping-> new addres clean region when select country without dropdown for states (by @enriquei4) - #12650: Add fallback for Product_links position attribute if not set in request (by @mohammedsalem) Fixed GitHub Issues: - #13327: Menu ui-state-active not removed from previous opened menu item (reported by @arnoudhgz) has been fixed in #13341 by @arnoudhgz in 2.2-develop branch Related commits: 1. 5714ffd 2. 5773225 - #8621: M2.1 Multishipping Checkout step New Address - Old State is saved when country is changed (reported by @ajaysinghrana23) has been fixed in #13364 by @enriquei4 in 2.2-develop branch Related commits: 1. 1b2a17c
2 parents 04d90c2 + 6c0fbaf commit 3572ee9

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

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

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,27 @@ class SaveHandler
3131
private $linkResource;
3232

3333
/**
34+
* @var linkTypeProvider
35+
*/
36+
private $linkTypeProvider;
37+
38+
/**
39+
* SaveHandler constructor.
3440
* @param MetadataPool $metadataPool
3541
* @param Link $linkResource
3642
* @param ProductLinkRepositoryInterface $productLinkRepository
43+
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
3744
*/
3845
public function __construct(
3946
MetadataPool $metadataPool,
4047
Link $linkResource,
41-
ProductLinkRepositoryInterface $productLinkRepository
48+
ProductLinkRepositoryInterface $productLinkRepository,
49+
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
4250
) {
4351
$this->metadataPool = $metadataPool;
4452
$this->linkResource = $linkResource;
4553
$this->productLinkRepository = $productLinkRepository;
54+
$this->linkTypeProvider = $linkTypeProvider;
4655
}
4756

4857
/**
@@ -55,17 +64,50 @@ public function execute($entityType, $entity)
5564
{
5665
$link = $entity->getData($this->metadataPool->getMetadata($entityType)->getLinkField());
5766
if ($this->linkResource->hasProductLinks($link)) {
58-
/** @var \Magento\Catalog\Api\Data\ProductInterface $entity*/
67+
/** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
5968
foreach ($this->productLinkRepository->getList($entity) as $link) {
6069
$this->productLinkRepository->delete($link);
6170
}
6271
}
63-
$productLinks = $entity->getProductLinks();
72+
73+
// Build links per type
74+
$linksByType = [];
75+
foreach ($entity->getProductLinks() as $link) {
76+
$linksByType[$link->getLinkType()][] = $link;
77+
}
78+
79+
// Set array position as a fallback position if necessary
80+
foreach ($linksByType as $linkType => $links) {
81+
if (!$this->hasPosition($links)) {
82+
array_walk($linksByType[$linkType], function ($productLink, $position) {
83+
$productLink->setPosition(++$position);
84+
});
85+
}
86+
}
87+
88+
// Flatten multi-dimensional linksByType in ProductLinks
89+
$productLinks = array_reduce($linksByType, 'array_merge', []);
90+
6491
if (count($productLinks) > 0) {
6592
foreach ($entity->getProductLinks() as $link) {
6693
$this->productLinkRepository->save($link);
6794
}
6895
}
6996
return $entity;
7097
}
98+
99+
/**
100+
* Check if at least one link without position
101+
* @param array $links
102+
* @return bool
103+
*/
104+
private function hasPosition(array $links)
105+
{
106+
foreach ($links as $link) {
107+
if (!array_key_exists('position', $link->getData())) {
108+
return false;
109+
}
110+
}
111+
return true;
112+
}
71113
}

app/code/Magento/Checkout/view/frontend/web/js/region-updater.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ define([
195195
regionInput.hide();
196196
label.attr('for', regionList.attr('id'));
197197
} else {
198+
this._removeSelectOptions(regionList);
199+
198200
if (this.options.isRegionRequired) {
199201
regionInput.addClass('required-entry').removeAttr('disabled');
200202
requiredLabel.addClass('required');

lib/web/mage/menu.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,9 @@ define([
626626
return;
627627
}
628628

629+
// remove the active state class from the siblings
630+
this.active.siblings().children('.ui-state-active').removeClass('ui-state-active');
631+
629632
this._open(newItem.parent());
630633

631634
// Delay so Firefox will not hide activedescendant change in expanding submenu from AT

0 commit comments

Comments
 (0)