-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2219 from magento-tango/2.2-PR-part-3
Fixed issues: - MAGETWO-77754 [2.2.x] - Related Products Rule for Up-sell Products with Customer Segments Specified Doesn't Work - MAGETWO-87570 [2.2.x] "Hide from Product Page" option does not work for child of configurable product
- Loading branch information
Showing
14 changed files
with
416 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/code/Magento/ConfigurableProduct/Model/Plugin/ProductIdentitiesExtender.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\ConfigurableProduct\Model\Plugin; | ||
|
||
use Magento\ConfigurableProduct\Model\Product\Type\Configurable; | ||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\Product; | ||
|
||
/** | ||
* Extender of product identities for child of configurable products | ||
*/ | ||
class ProductIdentitiesExtender | ||
{ | ||
/** | ||
* @var Configurable | ||
*/ | ||
private $configurableType; | ||
|
||
/** | ||
* @var ProductRepositoryInterface | ||
*/ | ||
private $productRepository; | ||
|
||
/** | ||
* @param Configurable $configurableType | ||
* @param ProductRepositoryInterface $productRepository | ||
*/ | ||
public function __construct(Configurable $configurableType, ProductRepositoryInterface $productRepository) | ||
{ | ||
$this->configurableType = $configurableType; | ||
$this->productRepository = $productRepository; | ||
} | ||
|
||
/** | ||
* Add parent identities to product identities | ||
* | ||
* @param Product $subject | ||
* @param array $identities | ||
* @return array | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterGetIdentities(Product $subject, array $identities): array | ||
{ | ||
$identities = (array) $identities; | ||
|
||
foreach ($this->configurableType->getParentIdsByChild($subject->getId()) as $parentId) { | ||
$parentProduct = $this->productRepository->getById($parentId); | ||
$identities = array_merge($identities, (array) $parentProduct->getIdentities()); | ||
} | ||
|
||
return array_unique($identities); | ||
} | ||
} |
51 changes: 0 additions & 51 deletions
51
app/code/Magento/ConfigurableProduct/Model/Product/Cache/Tag/Configurable.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...code/Magento/ConfigurableProduct/Test/Unit/Model/Plugin/ProductIdentitiesExtenderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\ConfigurableProduct\Test\Unit\Model\Plugin; | ||
|
||
use Magento\ConfigurableProduct\Model\Plugin\ProductIdentitiesExtender; | ||
use Magento\ConfigurableProduct\Model\Product\Type\Configurable; | ||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\Product; | ||
|
||
/** | ||
* Class ProductIdentitiesExtenderTest | ||
*/ | ||
class ProductIdentitiesExtenderTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject|Configurable | ||
*/ | ||
private $configurableTypeMock; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject|ProductRepositoryInterface | ||
*/ | ||
private $productRepositoryMock; | ||
|
||
/** | ||
* @var ProductIdentitiesExtender | ||
*/ | ||
private $plugin; | ||
|
||
protected function setUp() | ||
{ | ||
$this->configurableTypeMock = $this->getMockBuilder(Configurable::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class) | ||
->getMock(); | ||
|
||
$this->plugin = new ProductIdentitiesExtender($this->configurableTypeMock, $this->productRepositoryMock); | ||
} | ||
|
||
public function testAfterGetIdentities() | ||
{ | ||
$productId = 1; | ||
$productIdentity = 'cache_tag_1'; | ||
$productMock = $this->getMockBuilder(Product::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$parentProductId = 2; | ||
$parentProductIdentity = 'cache_tag_2'; | ||
$parentProductMock = $this->getMockBuilder(Product::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$productMock->expects($this->once()) | ||
->method('getId') | ||
->willReturn($productId); | ||
$this->configurableTypeMock->expects($this->once()) | ||
->method('getParentIdsByChild') | ||
->with($productId) | ||
->willReturn([$parentProductId]); | ||
$this->productRepositoryMock->expects($this->once()) | ||
->method('getById') | ||
->with($parentProductId) | ||
->willReturn($parentProductMock); | ||
$parentProductMock->expects($this->once()) | ||
->method('getIdentities') | ||
->willReturn([$parentProductIdentity]); | ||
|
||
$productIdentities = $this->plugin->afterGetIdentities($productMock, [$productIdentity]); | ||
$this->assertEquals([$productIdentity, $parentProductIdentity], $productIdentities); | ||
} | ||
} |
66 changes: 0 additions & 66 deletions
66
app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Cache/Tag/ConfigurableTest.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.