Skip to content

Commit e9025e3

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-97302' into 2.2-develop-pr17
2 parents afba9a4 + 225dc0b commit e9025e3

File tree

2 files changed

+96
-12
lines changed

2 files changed

+96
-12
lines changed

app/code/Magento/ConfigurableProduct/Plugin/Catalog/Model/Product/Pricing/Renderer/SalableResolver.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,24 @@
55
*/
66
namespace Magento\ConfigurableProduct\Plugin\Catalog\Model\Product\Pricing\Renderer;
77

8-
use Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProviderInterface;
8+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as TypeConfigurable;
99

1010
/**
1111
* A plugin for a salable resolver.
1212
*/
1313
class SalableResolver
1414
{
1515
/**
16-
* @var LowestPriceOptionsProviderInterface
16+
* @var TypeConfigurable
1717
*/
18-
private $lowestPriceOptionsProvider;
18+
private $typeConfigurable;
1919

2020
/**
21-
* @param LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider
21+
* @param TypeConfigurable $typeConfigurable
2222
*/
23-
public function __construct(
24-
LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider
25-
) {
26-
$this->lowestPriceOptionsProvider = $lowestPriceOptionsProvider;
23+
public function __construct(TypeConfigurable $typeConfigurable)
24+
{
25+
$this->typeConfigurable = $typeConfigurable;
2726
}
2827

2928
/**
@@ -33,18 +32,16 @@ public function __construct(
3332
* @param \Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolver $subject
3433
* @param bool $result
3534
* @param \Magento\Framework\Pricing\SaleableInterface $salableItem
36-
*
3735
* @return bool
38-
*
3936
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4037
*/
4138
public function afterIsSalable(
4239
\Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolver $subject,
4340
$result,
4441
\Magento\Framework\Pricing\SaleableInterface $salableItem
4542
) {
46-
if ($salableItem->getTypeId() == 'configurable' && $result) {
47-
$result = $salableItem->isSalable();
43+
if ($salableItem->getTypeId() === TypeConfigurable::TYPE_CODE && $result) {
44+
$result = $this->typeConfigurable->isSalable($salableItem);
4845
}
4946

5047
return $result;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ConfigurableProduct\Test\Unit\Plugin\Catalog\Model\Product\Pricing\Renderer;
9+
10+
use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolver;
11+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as TypeConfigurable;
12+
use Magento\ConfigurableProduct\Plugin\Catalog\Model\Product\Pricing\Renderer\SalableResolver as SalableResolverPlugin;
13+
use Magento\Framework\Pricing\SaleableInterface;
14+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Class SalableResolverTest
19+
*/
20+
class SalableResolverTest extends TestCase
21+
{
22+
/**
23+
* @var TypeConfigurable|MockObject
24+
*/
25+
private $typeConfigurable;
26+
27+
/**
28+
* @var SalableResolverPlugin
29+
*/
30+
private $salableResolver;
31+
32+
protected function setUp()
33+
{
34+
$this->typeConfigurable = $this->createMock(TypeConfigurable::class);
35+
$this->salableResolver = new SalableResolverPlugin($this->typeConfigurable);
36+
}
37+
38+
/**
39+
* @param SaleableInterface|MockObject $salableItem
40+
* @param bool $isSalable
41+
* @param bool $typeIsSalable
42+
* @param bool $expectedResult
43+
* @return void
44+
* @dataProvider afterIsSalableDataProvider
45+
*/
46+
public function testAfterIsSalable($salableItem, bool $isSalable, bool $typeIsSalable, bool $expectedResult)
47+
{
48+
$salableResolver = $this->createMock(SalableResolver::class);
49+
50+
$this->typeConfigurable->method('isSalable')
51+
->willReturn($typeIsSalable);
52+
53+
$result = $this->salableResolver->afterIsSalable($salableResolver, $isSalable, $salableItem);
54+
$this->assertEquals($expectedResult, $result);
55+
}
56+
57+
/**
58+
* Data provider for testAfterIsSalable
59+
*
60+
* @return array
61+
*/
62+
public function afterIsSalableDataProvider(): array
63+
{
64+
$simpleSalableItem = $this->createMock(SaleableInterface::class);
65+
$simpleSalableItem->method('getTypeId')
66+
->willReturn('simple');
67+
68+
$configurableSalableItem = $this->createMock(SaleableInterface::class);
69+
$configurableSalableItem->method('getTypeId')
70+
->willReturn('configurable');
71+
72+
return [
73+
[
74+
$simpleSalableItem,
75+
true,
76+
false,
77+
true,
78+
],
79+
[
80+
$configurableSalableItem,
81+
true,
82+
false,
83+
false,
84+
],
85+
];
86+
}
87+
}

0 commit comments

Comments
 (0)