From 944adbf1150ac7dedc40b3f4c4eebbe28f30ee9f Mon Sep 17 00:00:00 2001 From: Mohammad HAJ SALEM Date: Tue, 12 Dec 2017 16:22:17 +0100 Subject: [PATCH 01/14] :bug: add fallback for Product_links position attribute if position index was not set in API request --- .../Model/Product/Link/SaveHandler.php | 73 ++++++++++++++++++- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php index 13c6a13a50407..72bfaeba8d0b8 100644 --- a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php @@ -31,18 +31,28 @@ class SaveHandler private $linkResource; /** + * @var linkTypeProvider + */ + private $linkTypeProvider; + + /** + * SaveHandler constructor. * @param MetadataPool $metadataPool * @param Link $linkResource * @param ProductLinkRepositoryInterface $productLinkRepository + * @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider */ public function __construct( MetadataPool $metadataPool, Link $linkResource, - ProductLinkRepositoryInterface $productLinkRepository - ) { + ProductLinkRepositoryInterface $productLinkRepository, + \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider + ) + { $this->metadataPool = $metadataPool; $this->linkResource = $linkResource; $this->productLinkRepository = $productLinkRepository; + $this->linkTypeProvider = $linkTypeProvider; } /** @@ -55,12 +65,36 @@ public function execute($entityType, $entity) { $link = $entity->getData($this->metadataPool->getMetadata($entityType)->getLinkField()); if ($this->linkResource->hasProductLinks($link)) { - /** @var \Magento\Catalog\Api\Data\ProductInterface $entity*/ + /** @var \Magento\Catalog\Api\Data\ProductInterface $entity */ foreach ($this->productLinkRepository->getList($entity) as $link) { $this->productLinkRepository->delete($link); } } $productLinks = $entity->getProductLinks(); + + // Build links per type + $linksByType = []; + foreach ($productLinks as $link) { + $linksByType[$link->getLinkType()][] = $link; + } + + // Do check + $hasPositionLinkType = $this->isPositionsSet($linksByType); + + + // Bug fix for API if the Position was not set to force set Position attribute in "catalog_product_link_attribute_int" + // set Positions attribute values + foreach ($hasPositionLinkType as $linkType => $hasPosition) { + if (!$hasPosition) { + array_walk($linksByType[$linkType], function ($productLink, $position) { + $productLink->setPosition(++$position); + }); + } + } + + // Flatten multi-dimensional linksByType in ProductLinks + $productLinks = array_reduce($linksByType, 'array_merge', []); + if (count($productLinks) > 0) { foreach ($entity->getProductLinks() as $link) { $this->productLinkRepository->save($link); @@ -68,4 +102,37 @@ public function execute($entityType, $entity) } return $entity; } + + /** + * Check if the position is set for all product links per link type. + * array with boolean per type + * + * @param $linksByType + * @return array + */ + private function isPositionsSet($linksByType) + { + $linkTypes = $this->linkTypeProvider->getLinkTypes(); + + // Initialize isPositionSet for existent link types + $isPositionSet = []; + foreach (array_keys($linkTypes) as $typeName) { + if (array_key_exists($typeName, $linksByType)) { + $isPositionSet[$typeName] = count($linksByType[$typeName]) > 0; + } + } + + + // Check if at least on link without position exists per Link type + foreach ($linksByType as $type => $links) { + foreach ($links as $link) { + if (!array_key_exists('position', $link->getData())) { + $isPositionSet[$type] = false; + break; + } + } + } + + return $isPositionSet; + } } From aa5bc4f00e1847546c42cb0b12e1736395c5f0fe Mon Sep 17 00:00:00 2001 From: Mohammad HAJ SALEM Date: Wed, 13 Dec 2017 08:13:12 +0100 Subject: [PATCH 02/14] :ok_hand: shortening variable name --- .../Magento/Catalog/Model/Product/Link/SaveHandler.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php index 72bfaeba8d0b8..e9321e9d10902 100644 --- a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php @@ -18,7 +18,7 @@ class SaveHandler /** * @var ProductLinkRepositoryInterface */ - protected $productLinkRepository; + protected $productLinkRepo; /** * @var MetadataPool @@ -39,19 +39,19 @@ class SaveHandler * SaveHandler constructor. * @param MetadataPool $metadataPool * @param Link $linkResource - * @param ProductLinkRepositoryInterface $productLinkRepository + * @param ProductLinkRepositoryInterface $productLinkRepo * @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider */ public function __construct( MetadataPool $metadataPool, Link $linkResource, - ProductLinkRepositoryInterface $productLinkRepository, + ProductLinkRepositoryInterface $productLinkRepo, \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider ) { $this->metadataPool = $metadataPool; $this->linkResource = $linkResource; - $this->productLinkRepository = $productLinkRepository; + $this->productLinkRepo = $productLinkRepo; $this->linkTypeProvider = $linkTypeProvider; } From 828f18bbd2f495ec9fcaac32eaf5b7b73bda429c Mon Sep 17 00:00:00 2001 From: Mohammad HAJ SALEM Date: Wed, 13 Dec 2017 08:20:56 +0100 Subject: [PATCH 03/14] :bug: fix variable re-naming --- app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php index e9321e9d10902..9f0f17f7339f1 100644 --- a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php @@ -66,8 +66,8 @@ public function execute($entityType, $entity) $link = $entity->getData($this->metadataPool->getMetadata($entityType)->getLinkField()); if ($this->linkResource->hasProductLinks($link)) { /** @var \Magento\Catalog\Api\Data\ProductInterface $entity */ - foreach ($this->productLinkRepository->getList($entity) as $link) { - $this->productLinkRepository->delete($link); + foreach ($this->productLinkRepo->getList($entity) as $link) { + $this->productLinkRepo->delete($link); } } $productLinks = $entity->getProductLinks(); @@ -97,7 +97,7 @@ public function execute($entityType, $entity) if (count($productLinks) > 0) { foreach ($entity->getProductLinks() as $link) { - $this->productLinkRepository->save($link); + $this->productLinkRepo->save($link); } } return $entity; From 005e3eb9068437c9cbe2e9bbd59d3adad4f03e39 Mon Sep 17 00:00:00 2001 From: Mohammad HAJ SALEM Date: Wed, 13 Dec 2017 08:26:17 +0100 Subject: [PATCH 04/14] :ok_hand: drop multiple empty lines --- app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php index 9f0f17f7339f1..ff22abc90911b 100644 --- a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php @@ -81,7 +81,6 @@ public function execute($entityType, $entity) // Do check $hasPositionLinkType = $this->isPositionsSet($linksByType); - // Bug fix for API if the Position was not set to force set Position attribute in "catalog_product_link_attribute_int" // set Positions attribute values foreach ($hasPositionLinkType as $linkType => $hasPosition) { @@ -122,7 +121,6 @@ private function isPositionsSet($linksByType) } } - // Check if at least on link without position exists per Link type foreach ($linksByType as $type => $links) { foreach ($links as $link) { From 27cc0b615d86c5d5e4ec826bbc9a3354b94c443a Mon Sep 17 00:00:00 2001 From: Mohammad HAJ SALEM Date: Wed, 13 Dec 2017 08:29:50 +0100 Subject: [PATCH 05/14] :ok_hand: closing parenthesis and the opening brace of a multi-line function on the same line --- app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php index ff22abc90911b..5983504715a31 100644 --- a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php @@ -47,8 +47,7 @@ public function __construct( Link $linkResource, ProductLinkRepositoryInterface $productLinkRepo, \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider - ) - { + ) { $this->metadataPool = $metadataPool; $this->linkResource = $linkResource; $this->productLinkRepo = $productLinkRepo; From 12653a128052645ff308311b039005d10c7128e4 Mon Sep 17 00:00:00 2001 From: Mohammad HAJ SALEM Date: Wed, 13 Dec 2017 08:29:50 +0100 Subject: [PATCH 06/14] :ok_hand: closing parenthesis and the opening brace of a multi-line function on the same line --- app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php index ff22abc90911b..abf465ac270bd 100644 --- a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php @@ -47,8 +47,7 @@ public function __construct( Link $linkResource, ProductLinkRepositoryInterface $productLinkRepo, \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider - ) - { + ) { $this->metadataPool = $metadataPool; $this->linkResource = $linkResource; $this->productLinkRepo = $productLinkRepo; @@ -81,8 +80,7 @@ public function execute($entityType, $entity) // Do check $hasPositionLinkType = $this->isPositionsSet($linksByType); - // Bug fix for API if the Position was not set to force set Position attribute in "catalog_product_link_attribute_int" - // set Positions attribute values + // Set array position as a fallback position if necessary foreach ($hasPositionLinkType as $linkType => $hasPosition) { if (!$hasPosition) { array_walk($linksByType[$linkType], function ($productLink, $position) { From 9e51c51c81ff5fed99f65c2a106d7d597ad24c25 Mon Sep 17 00:00:00 2001 From: Mohammad HAJ SALEM Date: Wed, 13 Dec 2017 22:10:17 +0100 Subject: [PATCH 07/14] :ok_hand: reset protected variable naming --- .../Catalog/Model/Product/Link/SaveHandler.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php index abf465ac270bd..10c89bdd1f813 100644 --- a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php @@ -18,7 +18,7 @@ class SaveHandler /** * @var ProductLinkRepositoryInterface */ - protected $productLinkRepo; + protected $productLinkRepository; /** * @var MetadataPool @@ -39,18 +39,18 @@ class SaveHandler * SaveHandler constructor. * @param MetadataPool $metadataPool * @param Link $linkResource - * @param ProductLinkRepositoryInterface $productLinkRepo + * @param ProductLinkRepositoryInterface $productLinkRepository * @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider */ public function __construct( MetadataPool $metadataPool, Link $linkResource, - ProductLinkRepositoryInterface $productLinkRepo, + ProductLinkRepositoryInterface $productLinkRepository, \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider ) { $this->metadataPool = $metadataPool; $this->linkResource = $linkResource; - $this->productLinkRepo = $productLinkRepo; + $this->productLinkRepository = $productLinkRepository; $this->linkTypeProvider = $linkTypeProvider; } @@ -65,8 +65,8 @@ public function execute($entityType, $entity) $link = $entity->getData($this->metadataPool->getMetadata($entityType)->getLinkField()); if ($this->linkResource->hasProductLinks($link)) { /** @var \Magento\Catalog\Api\Data\ProductInterface $entity */ - foreach ($this->productLinkRepo->getList($entity) as $link) { - $this->productLinkRepo->delete($link); + foreach ($this->productLinkRepository->getList($entity) as $link) { + $this->productLinkRepository->delete($link); } } $productLinks = $entity->getProductLinks(); @@ -94,7 +94,7 @@ public function execute($entityType, $entity) if (count($productLinks) > 0) { foreach ($entity->getProductLinks() as $link) { - $this->productLinkRepo->save($link); + $this->productLinkRepository->save($link); } } return $entity; From ccaf7487bb5a75bb7f843c8260e58334fa4cfab7 Mon Sep 17 00:00:00 2001 From: Mohammad HAJ SALEM Date: Wed, 13 Dec 2017 22:22:31 +0100 Subject: [PATCH 08/14] :ok_hand: rename isPositionsSet function to isPositionSet to keep consistency --- app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php index 10c89bdd1f813..1d581566148fd 100644 --- a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php @@ -78,7 +78,7 @@ public function execute($entityType, $entity) } // Do check - $hasPositionLinkType = $this->isPositionsSet($linksByType); + $hasPositionLinkType = $this->isPositionSet($linksByType); // Set array position as a fallback position if necessary foreach ($hasPositionLinkType as $linkType => $hasPosition) { @@ -107,7 +107,7 @@ public function execute($entityType, $entity) * @param $linksByType * @return array */ - private function isPositionsSet($linksByType) + private function isPositionSet($linksByType) { $linkTypes = $this->linkTypeProvider->getLinkTypes(); From 0b14b4e1a1dc0763f597f7a423c79c8a3f12094a Mon Sep 17 00:00:00 2001 From: Matthias Zeis Date: Wed, 20 Dec 2017 18:02:21 +0100 Subject: [PATCH 09/14] Fix typo --- app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php index 1d581566148fd..64c7fe54b31a6 100644 --- a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php @@ -119,7 +119,7 @@ private function isPositionSet($linksByType) } } - // Check if at least on link without position exists per Link type + // Check if at least one link without position exists per Link type foreach ($linksByType as $type => $links) { foreach ($links as $link) { if (!array_key_exists('position', $link->getData())) { From da1833a57ea21ea559919ce2803dbaf8a51a67d1 Mon Sep 17 00:00:00 2001 From: Mohammad HAJ SALEM Date: Fri, 12 Jan 2018 08:31:27 +0100 Subject: [PATCH 10/14] :ok_hand: apply code enhancement --- .../Model/Product/Link/SaveHandler.php | 40 +++++-------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php index 64c7fe54b31a6..22034d486e876 100644 --- a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php @@ -77,12 +77,9 @@ public function execute($entityType, $entity) $linksByType[$link->getLinkType()][] = $link; } - // Do check - $hasPositionLinkType = $this->isPositionSet($linksByType); - // Set array position as a fallback position if necessary - foreach ($hasPositionLinkType as $linkType => $hasPosition) { - if (!$hasPosition) { + foreach ($linksByType as $linkType => $links) { + if (!$this->hasPosition($links)) { array_walk($linksByType[$linkType], function ($productLink, $position) { $productLink->setPosition(++$position); }); @@ -101,34 +98,17 @@ public function execute($entityType, $entity) } /** - * Check if the position is set for all product links per link type. - * array with boolean per type - * - * @param $linksByType - * @return array + * Check if at least one link without position + * @param $links + * @return bool */ - private function isPositionSet($linksByType) + public function hasPosition($links) { - $linkTypes = $this->linkTypeProvider->getLinkTypes(); - - // Initialize isPositionSet for existent link types - $isPositionSet = []; - foreach (array_keys($linkTypes) as $typeName) { - if (array_key_exists($typeName, $linksByType)) { - $isPositionSet[$typeName] = count($linksByType[$typeName]) > 0; - } - } - - // Check if at least one link without position exists per Link type - foreach ($linksByType as $type => $links) { - foreach ($links as $link) { - if (!array_key_exists('position', $link->getData())) { - $isPositionSet[$type] = false; - break; - } + foreach ($links as $link) { + if (!array_key_exists('position', $link->getData())) { + return false; } } - - return $isPositionSet; + return true; } } From 3d87303fb7087571f5e1f9cf09a5629944d9e89b Mon Sep 17 00:00:00 2001 From: Mohammad HAJ SALEM Date: Sun, 21 Jan 2018 12:40:02 +0100 Subject: [PATCH 11/14] :ok_hand: apply code enhancement --- .../Magento/Catalog/Model/Product/Link/SaveHandler.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php index 22034d486e876..951bba9aa8be3 100644 --- a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php @@ -69,11 +69,10 @@ public function execute($entityType, $entity) $this->productLinkRepository->delete($link); } } - $productLinks = $entity->getProductLinks(); // Build links per type $linksByType = []; - foreach ($productLinks as $link) { + foreach ($entity->getProductLinks() as $link) { $linksByType[$link->getLinkType()][] = $link; } @@ -99,10 +98,10 @@ public function execute($entityType, $entity) /** * Check if at least one link without position - * @param $links + * @param array $links * @return bool */ - public function hasPosition($links) + private function hasPosition($links) { foreach ($links as $link) { if (!array_key_exists('position', $link->getData())) { From 30b494b90ae707c2ba2e2aa434553375307b219f Mon Sep 17 00:00:00 2001 From: Matthias Zeis Date: Mon, 22 Jan 2018 20:27:52 +0100 Subject: [PATCH 12/14] Add type hint --- app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php index 951bba9aa8be3..6d053537a659e 100644 --- a/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php +++ b/app/code/Magento/Catalog/Model/Product/Link/SaveHandler.php @@ -101,7 +101,7 @@ public function execute($entityType, $entity) * @param array $links * @return bool */ - private function hasPosition($links) + private function hasPosition(array $links) { foreach ($links as $link) { if (!array_key_exists('position', $link->getData())) { From 5714ffd97f8b8f21c46e047d74a02bd75742002b Mon Sep 17 00:00:00 2001 From: Arnoud Beekman Date: Tue, 23 Jan 2018 13:32:55 +0100 Subject: [PATCH 13/14] Remove ui-state-active from siblings of the expanded menu item Previously when a menu item was expanded the class `ui-state-active` was not removed from the previous expanded menu item. This resulted in two (or more if you expanded more) menu items with this class. --- lib/web/mage/menu.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/web/mage/menu.js b/lib/web/mage/menu.js index 6ad60333d2e1b..41730aa036b08 100644 --- a/lib/web/mage/menu.js +++ b/lib/web/mage/menu.js @@ -626,6 +626,9 @@ define([ return; } + // remove the active state class from the siblings + this.active.siblings().children('.ui-state-active').removeClass('ui-state-active'); + this._open(newItem.parent()); // Delay so Firefox will not hide activedescendant change in expanding submenu from AT From 1b2a17cd137a32718d9732905adabd6d9ed843cc Mon Sep 17 00:00:00 2001 From: Enrique Guadalupe Date: Thu, 25 Jan 2018 14:41:57 +0100 Subject: [PATCH 14/14] Clean region when select country --- .../Magento/Checkout/view/frontend/web/js/region-updater.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Checkout/view/frontend/web/js/region-updater.js b/app/code/Magento/Checkout/view/frontend/web/js/region-updater.js index 79050ca087740..dacebd75c3c68 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/region-updater.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/region-updater.js @@ -195,6 +195,8 @@ define([ regionInput.hide(); label.attr('for', regionList.attr('id')); } else { + this._removeSelectOptions(regionList); + if (this.options.isRegionRequired) { regionInput.addClass('required-entry').removeAttr('disabled'); requiredLabel.addClass('required');