Skip to content

Commit 061ff8b

Browse files
author
Elena Marchenko
committed
Merge branch 'develop' of github.corp.ebay.com:magento2/magento2ce into MTA-559
2 parents 6a3021f + 6ab300f commit 061ff8b

File tree

70 files changed

+2774
-401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2774
-401
lines changed

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

Lines changed: 74 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414
class Extend extends \Magento\Catalog\Block\Adminhtml\Form\Renderer\Fieldset\Element
1515
{
16+
/**
17+
* Initialize block template
18+
*/
19+
private $template = 'Magento_Bundle::catalog/product/edit/tab/attributes/extend.phtml';
20+
1621
const DYNAMIC = 0;
1722

1823
const FIXED = 1;
@@ -24,18 +29,26 @@ class Extend extends \Magento\Catalog\Block\Adminhtml\Form\Renderer\Fieldset\Ele
2429
*/
2530
protected $_coreRegistry = null;
2631

32+
/**
33+
* @var \Magento\Framework\Data\FormFactory
34+
*/
35+
private $formFactory;
36+
2737
/**
2838
* @param \Magento\Backend\Block\Template\Context $context
2939
* @param \Magento\Framework\Registry $registry
40+
* @param \Magento\Framework\Data\FormFactory $formFactory
3041
* @param array $data
3142
*/
3243
public function __construct(
3344
\Magento\Backend\Block\Template\Context $context,
3445
\Magento\Framework\Registry $registry,
46+
\Magento\Framework\Data\FormFactory $formFactory,
3547
array $data = []
3648
) {
3749
$this->_coreRegistry = $registry;
3850
parent::__construct($context, $data);
51+
$this->formFactory = $formFactory;
3952
}
4053

4154
/**
@@ -54,112 +67,52 @@ protected function _construct()
5467
* Get Element Html
5568
*
5669
* @return string
57-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
58-
* @SuppressWarnings(PHPMD.NPathComplexity)
59-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
6070
*/
6171
public function getElementHtml()
6272
{
63-
$elementHtml = parent::getElementHtml();
64-
65-
$switchAttributeCode = $this->getAttribute()->getAttributeCode() . '_type';
66-
$switchAttributeValue = $this->getProduct()->getData($switchAttributeCode);
67-
68-
$html = '<select name="product[' .
69-
$switchAttributeCode .
70-
']" id="' .
71-
$switchAttributeCode .
72-
'" type="select" class="required-entry select next-toinput"' .
73-
($this->getProduct()->getId() &&
74-
$this->getAttribute()->getAttributeCode() == 'price' ||
75-
$this->getElement()->getReadonly() ? ' disabled="disabled"' : '') . '>
76-
<option value="">' . __('-- Select --') . '</option>
77-
<option ' . ($switchAttributeValue ==
78-
self::DYNAMIC ? 'selected' : '') . ' value="' . self::DYNAMIC . '">' . __('Dynamic') . '</option>
79-
<option ' . ($switchAttributeValue ==
80-
self::FIXED ? 'selected' : '') . ' value="' . self::FIXED . '">' . __('Fixed') . '</option>
81-
</select>';
82-
83-
if (!($this->getAttribute()->getAttributeCode() == 'price' && $this->getCanReadPrice() === false)) {
84-
$html = '<div class="' .
85-
$this->getAttribute()->getAttributeCode() .
86-
' ">' .
87-
$elementHtml .
88-
'</div>' .
89-
$html;
90-
}
91-
if ($this->getDisableChild() && !$this->getElement()->getReadonly()) {
92-
$html .= "<script>
93-
require(['prototype'], function(){
94-
function " .
95-
$switchAttributeCode .
96-
"_change() {
97-
if ($('" .
98-
$switchAttributeCode .
99-
"').value == '" .
100-
self::DYNAMIC .
101-
"') {
102-
if ($('" .
103-
$this->getAttribute()->getAttributeCode() .
104-
"')) {
105-
$('" .
106-
$this->getAttribute()->getAttributeCode() .
107-
"').disabled = true;
108-
$('" .
109-
$this->getAttribute()->getAttributeCode() .
110-
"').value = '';
111-
$('" .
112-
$this->getAttribute()->getAttributeCode() .
113-
"').removeClassName('required-entry');
114-
}
115-
116-
if ($('dynamic-price-warning')) {
117-
$('dynamic-price-warning').show();
118-
}
119-
} else {
120-
if ($('" .
121-
$this->getAttribute()->getAttributeCode() .
122-
"')) {";
123-
124-
if ($this->getAttribute()->getAttributeCode() == 'price' &&
125-
$this->getCanEditPrice() === false &&
126-
$this->getCanReadPrice() === true &&
127-
$this->getProduct()->isObjectNew()
128-
) {
129-
$defaultProductPrice = $this->getDefaultProductPrice() ? $this->getDefaultProductPrice() : "''";
130-
$html .= "$('" .
131-
$this->getAttribute()->getAttributeCode() .
132-
"').value = " .
133-
$defaultProductPrice .
134-
";";
135-
} else {
136-
$html .= "$('" .
137-
$this->getAttribute()->getAttributeCode() .
138-
"').disabled = false;
139-
$('" .
140-
$this->getAttribute()->getAttributeCode() .
141-
"').addClassName('required-entry');";
142-
}
73+
$templateFile = $this->getTemplateFile($this->template);
74+
return $this->fetchView($templateFile);
75+
}
14376

144-
$html .= "}
77+
/**
78+
* Execute method getElementHtml from parrent class
79+
*
80+
* @return string
81+
*/
82+
public function getParentElementHtml()
83+
{
84+
return parent::getElementHtml();
85+
}
14586

146-
if ($('dynamic-price-warning')) {
147-
$('dynamic-price-warning').hide();
148-
}
149-
}
150-
}" . "\n";
87+
/**
88+
* @return array
89+
*/
90+
public function getOptions()
91+
{
92+
return [
93+
[
94+
'value' => '',
95+
'label' => __('-- Select --')
96+
],
97+
[
98+
'value' => self::DYNAMIC,
99+
'label' => __('Dynamic')
100+
],
101+
[
102+
'value' => self::FIXED,
103+
'label' => __('Fixed')
104+
]
105+
];
106+
}
151107

152-
if (!($this->getAttribute()->getAttributeCode() == 'price' &&
153-
!$this->getCanEditPrice() &&
154-
!$this->getProduct()->isObjectNew())
155-
) {
156-
$html .= "$('" . $switchAttributeCode . "').observe('change', " . $switchAttributeCode . "_change);";
157-
}
158-
$html .= $switchAttributeCode . "_change();
159-
});
160-
</script>";
161-
}
162-
return $html;
108+
/**
109+
* @return bool
110+
*/
111+
public function isDisabledField()
112+
{
113+
return $this->getProduct()->getId() &&
114+
$this->getAttribute()->getAttributeCode() === 'price' ||
115+
$this->getElement()->getReadonly();
163116
}
164117

165118
/**
@@ -172,4 +125,25 @@ public function getProduct()
172125
}
173126
return $this->getData('product');
174127
}
128+
129+
/**
130+
* @param string $switchAttributeCode
131+
* @return \Magento\Framework\Data\Form\Element\Select
132+
* @throws \Magento\Framework\Exception\LocalizedException
133+
*/
134+
public function getExtendedElement($switchAttributeCode)
135+
{
136+
$form = $this->formFactory->create();
137+
return $form->addField(
138+
$switchAttributeCode,
139+
'select',
140+
[
141+
'name' => "product[{$switchAttributeCode}]",
142+
'values' => $this->getOptions(),
143+
'value' => $switchAttributeCode,
144+
'class' => 'required-entry next-toinput',
145+
'disabled' => $this->isDisabledField()
146+
]
147+
);
148+
}
175149
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
// @codingStandardsIgnoreFile
8+
9+
/** @var $block \Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes\Extend */
10+
$elementHtml = $block->getParentElementHtml();
11+
12+
$attributeCode = $block->getAttribute()
13+
->getAttributeCode();
14+
15+
$switchAttributeCode = "{$attributeCode}_type";
16+
$switchAttributeValue = $block->getProduct()
17+
->getData($switchAttributeCode);
18+
19+
$isElementReadonly = $block->getElement()
20+
->getReadonly();
21+
?>
22+
23+
<?php if (!($attributeCode === 'price' && $block->getCanReadPrice() === false)) { ?>
24+
<div class="<?= $attributeCode ?> "><?= $elementHtml ?></div>
25+
<?php } ?>
26+
27+
<?=$block->getExtendedElement($switchAttributeCode)->toHtml(); ?>
28+
29+
<?php if (!$isElementReadonly && $block->getDisableChild()) { ?>
30+
<script>
31+
require(['prototype'], function () {
32+
function <?=$switchAttributeCode?>_change() {
33+
var $attribute = $('<?=$attributeCode?>');
34+
if ($('<?=$switchAttributeCode?>').value == '<?=$block::DYNAMIC?>') {
35+
if ($attribute) {
36+
$attribute.disabled = true;
37+
$attribute.value = '';
38+
$attribute.removeClassName('required-entry');
39+
}
40+
if ($('dynamic-price-warning')) {
41+
$('dynamic-price-warning').show();
42+
}
43+
} else {
44+
if ($attribute) {
45+
<?php if ($attributeCode === 'price' && !$block->getCanEditPrice() && $block->getCanReadPrice()
46+
&& $block->getProduct()->isObjectNew()) { ?>
47+
<?php $defaultProductPrice = $block->getDefaultProductPrice() ?: "''"; ?>
48+
$attribute.value = <?=$defaultProductPrice?>;
49+
<?php } else { ?>
50+
$attribute.disabled = false;
51+
$attribute.addClassName('required-entry');
52+
<?php } ?>
53+
}
54+
if ($('dynamic-price-warning')) {
55+
$('dynamic-price-warning').hide();
56+
}
57+
}
58+
}
59+
60+
<?php if (!($attributeCode === 'price' && !$block->getCanEditPrice()
61+
&& !$block->getProduct()->isObjectNew())) { ?>
62+
$('<?=$switchAttributeCode?>').observe('change', <?=$switchAttributeCode?>_change);
63+
<?php } ?>
64+
<?=$switchAttributeCode?>_change();
65+
});
66+
</script>
67+
<?php } ?>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<item name="category_ids" xsi:type="string">category_ids</item>
8989
<item name="entity_id" xsi:type="string">entity_id</item>
9090
<item name="store_id" xsi:type="string">store_id</item>
91+
<item name="website_ids" xsi:type="string">website_ids</item>
9192
<item name="visibility" xsi:type="string">visibility</item>
9293
<item name="status" xsi:type="string">status</item>
9394
</item>

app/code/Magento/CatalogInventory/Model/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function __construct(
150150
*/
151151
public function getDefaultWebsiteId()
152152
{
153-
return (int) $this->storeManager->getWebsite(true)->getId();
153+
return (int) $this->storeManager->getWebsite()->getId();
154154
}
155155

156156
/**

app/code/Magento/CatalogInventory/Test/Unit/Model/ConfigurationTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public function testGetDefaultWebsiteId()
7070
->willReturn($id);
7171
$this->storeManagerMock->expects($this->once())
7272
->method('getWebsite')
73-
->with(true)
7473
->willReturn($websiteMock);
7574
$this->assertEquals($id, $this->model->getDefaultWebsiteId());
7675
}
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\CatalogSearch\Model\Advanced\Request;
7+
8+
use Magento\Framework\Search\Request\Builder as RequestBuilder;
9+
10+
class Builder extends RequestBuilder
11+
{
12+
/**
13+
* @param string $attributeCode
14+
* @param array|string $attributeValue
15+
* @return void
16+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
17+
*/
18+
public function bindRequestValue($attributeCode, $attributeValue)
19+
{
20+
if (isset($attributeValue['from']) || isset($attributeValue['to'])) {
21+
if (isset($attributeValue['from']) && '' !== $attributeValue['from']) {
22+
$this->bind("{$attributeCode}.from", $attributeValue['from']);
23+
}
24+
if (isset($attributeValue['to']) && '' !== $attributeValue['to']) {
25+
$this->bind("{$attributeCode}.to", $attributeValue['to']);
26+
}
27+
} elseif (!is_array($attributeValue)) {
28+
$this->bind($attributeCode, $attributeValue);
29+
} elseif (isset($attributeValue['like'])) {
30+
$this->bind($attributeCode, trim($attributeValue['like'], '%'));
31+
} elseif (isset($attributeValue['in'])) {
32+
$this->bind($attributeCode, $attributeValue['in']);
33+
} elseif (isset($attributeValue['in_set'])) {
34+
$this->bind($attributeCode, $attributeValue['in_set']);
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)