Skip to content

Commit 4648956

Browse files
author
Andrii Kasian
committed
MAGETWO-37213: Unable to create fixed bundle product
1 parent e98a487 commit 4648956

File tree

2 files changed

+81
-4
lines changed
  • app/code/Magento/Bundle
    • Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes
    • Test/Unit/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes

2 files changed

+81
-4
lines changed

app/code/Magento/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Extend.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ public function getOptions()
110110
*/
111111
public function isDisabledField()
112112
{
113-
return $this->getProduct()->getId() &&
114-
$this->getAttribute()->getAttributeCode() === 'price' ||
115-
$this->getElement()->getReadonly();
113+
return $this->_getData('is_disabled_field')
114+
|| $this->getProduct()->getId()
115+
&& ($this->getAttribute()->getAttributeCode() === 'price'
116+
|| $this->getElement()->getReadonly()
117+
);
116118
}
117119

118120
/**
@@ -142,7 +144,9 @@ public function getExtendedElement($switchAttributeCode)
142144
'values' => $this->getOptions(),
143145
'value' => $switchAttributeCode,
144146
'class' => 'required-entry next-toinput',
145-
'disabled' => $this->isDisabledField()
147+
'no_span' => true,
148+
'disabled' => $this->isDisabledField(),
149+
'value' => $this->getProduct()->getData($switchAttributeCode),
146150
]
147151
);
148152
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Test\Unit\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes;
7+
8+
use Magento\Catalog\Model\Product;
9+
10+
class ExtendTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/** @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject */
13+
protected $registry;
14+
15+
/** @var \Magento\Framework\Data\FormFactory|\PHPUnit_Framework_MockObject_MockObject */
16+
protected $formFactory;
17+
18+
/** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
19+
protected $objectManagerHelper;
20+
21+
/** @var \Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes\Extend */
22+
protected $object;
23+
24+
public function setUp()
25+
{
26+
$this->registry = $this->getMockBuilder('Magento\\Framework\\Registry')->disableOriginalConstructor()->getMock(
27+
);
28+
$this->formFactory = $this->getMockBuilder('Magento\\Framework\\Data\\FormFactory')->disableOriginalConstructor(
29+
)->getMock();
30+
$this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
31+
$this->object = $this->objectManagerHelper->getObject(
32+
'Magento\\Bundle\\Block\\Adminhtml\\Catalog\\Product\\Edit\\Tab\\Attributes\\Extend',
33+
['registry' => $this->registry, 'formFactory' => $this->formFactory]
34+
);
35+
}
36+
37+
/**
38+
* @return \PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
public function getProduct()
41+
{
42+
$product = $this->getMockBuilder(Product::class)->disableOriginalConstructor()->getMock();
43+
$this->registry->expects($this->once())->method('registry')->with('product')->will(
44+
$this->returnValue($product)
45+
);
46+
return $product;
47+
}
48+
49+
public function testGetExtendedElement()
50+
{
51+
$switchAttributeCode = 'test_code';
52+
$form = $this->getMockBuilder(\Magento\Framework\Data\Form::class)->disableOriginalConstructor()->getMock();
53+
$and = new \PHPUnit_Framework_Constraint_And();
54+
$and->setConstraints(
55+
[
56+
new \PHPUnit_Framework_Constraint_ArrayHasKey('value')
57+
]
58+
);
59+
$form->expects($this->once())->method('addField')->with(
60+
$switchAttributeCode,
61+
'select',
62+
$and
63+
);
64+
65+
$this->formFactory->expects($this->once())->method('create')->with()->will($this->returnValue($form));
66+
$product = $this->getProduct();
67+
$product->expects($this->once())->method('getData')->with($switchAttributeCode)->will(
68+
$this->returnValue(123)
69+
);
70+
$this->object->setIsDisabledField(true);
71+
$this->object->getExtendedElement($switchAttributeCode);
72+
}
73+
}

0 commit comments

Comments
 (0)