Skip to content

Commit 8217244

Browse files
author
Maksym Aposov
committed
Merge branch 'MAGETWO-44774' into BugFestW5
2 parents 620b519 + 9476a29 commit 8217244

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Model\Plugin;
7+
8+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
9+
10+
/**
11+
* Class PriceBackend
12+
*
13+
* Make price validation optional for configurable product
14+
*/
15+
class PriceBackend
16+
{
17+
/**
18+
* @param \Magento\Catalog\Model\Product\Attribute\Backend\Price $subject
19+
* @param \Closure $proceed
20+
* @param \Magento\Catalog\Model\Product|\Magento\Framework\DataObject $object
21+
* @return bool
22+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
23+
*/
24+
public function aroundValidate(
25+
\Magento\Catalog\Model\Product\Attribute\Backend\Price $subject,
26+
\Closure $proceed,
27+
$object
28+
) {
29+
if ($object instanceof \Magento\Catalog\Model\Product
30+
&& $object->getTypeId() == Configurable::TYPE_CODE
31+
) {
32+
return true;
33+
} else {
34+
return $proceed($object);
35+
}
36+
}
37+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\ConfigurableProduct\Test\Unit\Model\Plugin;
8+
9+
use Magento\ConfigurableProduct\Model\Plugin\PriceBackend;
10+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
11+
use Magento\Catalog\Model\Product\Type;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
14+
class PriceBackendTest extends \PHPUnit_Framework_TestCase
15+
{
16+
const CLOSURE_VALUE = 'CLOSURE';
17+
/** @var PriceBackend */
18+
private $priceBackendPlugin;
19+
/** @var \PHPUnit_Framework_MockObject_MockObject */
20+
private $priceAttributeMock;
21+
/** @var \Closure */
22+
private $closure;
23+
/** @var \PHPUnit_Framework_MockObject_MockObject */
24+
private $productMock;
25+
26+
protected function setUp()
27+
{
28+
$objectManager = new ObjectManager($this);
29+
$this->priceBackendPlugin = $objectManager->getObject('Magento\ConfigurableProduct\Model\Plugin\PriceBackend');
30+
31+
$this->closure = function () {
32+
return static::CLOSURE_VALUE;
33+
};
34+
$this->priceAttributeMock = $this->getMockBuilder('Magento\Catalog\Model\Product\Attribute\Backend\Price')
35+
->disableOriginalConstructor()
36+
->getMock();
37+
$this->productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
38+
->disableOriginalConstructor()
39+
->setMethods(['getTypeId', 'getPriceType', '__wakeUp'])
40+
->getMock();
41+
}
42+
43+
/**
44+
* @dataProvider aroundValidateDataProvider
45+
*
46+
* @param $typeId
47+
* @param $expectedResult
48+
*/
49+
public function testAroundValidate($typeId, $expectedResult)
50+
{
51+
$this->productMock->expects($this->any())->method('getTypeId')->will($this->returnValue($typeId));
52+
$result = $this->priceBackendPlugin->aroundValidate(
53+
$this->priceAttributeMock,
54+
$this->closure,
55+
$this->productMock
56+
);
57+
$this->assertEquals($expectedResult, $result);
58+
}
59+
60+
/**
61+
* Data provider for testAroundValidate
62+
*
63+
* @return array
64+
*/
65+
public function aroundValidateDataProvider()
66+
{
67+
return [
68+
['type' => Configurable::TYPE_CODE, 'result' => true],
69+
['type' => Type::TYPE_VIRTUAL, 'result' => static::CLOSURE_VALUE],
70+
];
71+
}
72+
}

app/code/Magento/ConfigurableProduct/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,7 @@
123123
<argument name="priceResolver" xsi:type="object">ConfigurableRegularPriceResolver</argument>
124124
</arguments>
125125
</type>
126+
<type name="Magento\Catalog\Model\Product\Attribute\Backend\Price">
127+
<plugin name="configurable" type="Magento\ConfigurableProduct\Model\Plugin\PriceBackend" sortOrder="100" />
128+
</type>
126129
</config>

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/variations.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,10 @@ define([
375375
var priceContainer = $('[id="attribute-price-container"]');
376376
if (this.productMatrix().length !== 0) {
377377
priceContainer.hide();
378+
priceContainer.find('input').prop('disabled', true);
378379
} else {
379380
priceContainer.show();
381+
priceContainer.find('input').prop('disabled', false);
380382
}
381383
},
382384

0 commit comments

Comments
 (0)