Skip to content

Commit d6f761a

Browse files
committed
Merge branch '2.3-develop' into MAGETWO-86867-cleanup
2 parents 0b266f5 + 39ff541 commit d6f761a

File tree

60 files changed

+1246
-60
lines changed

Some content is hidden

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

60 files changed

+1246
-60
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ public function execute()
139139
->setName($name)
140140
->getAttributeSet();
141141
} catch (AlreadyExistsException $alreadyExists) {
142-
$this->messageManager->addErrorMessage(
143-
__('A "%1" attribute set name already exists. Create a new name and try again.', $name)
144-
);
142+
$this->messageManager->addErrorMessage(__('An attribute set named \'%1\' already exists.', $name));
145143
$this->_session->setAttributeData($data);
146144
return $this->returnResult('catalog/*/edit', ['_current' => true], ['error' => true]);
147145
} catch (LocalizedException $e) {
@@ -202,6 +200,8 @@ public function execute()
202200
}
203201
}
204202

203+
$data = $this->presentation->convertPresentationDataToInputType($data);
204+
205205
if ($attributeId) {
206206
if (!$model->getId()) {
207207
$this->messageManager->addErrorMessage(__('This attribute no longer exists.'));
@@ -216,7 +216,7 @@ public function execute()
216216

217217
$data['attribute_code'] = $model->getAttributeCode();
218218
$data['is_user_defined'] = $model->getIsUserDefined();
219-
$data['frontend_input'] = $model->getFrontendInput();
219+
$data['frontend_input'] = $data['frontend_input'] ?? $model->getFrontendInput();
220220
} else {
221221
/**
222222
* @todo add to helper and specify all relations for properties
@@ -229,8 +229,6 @@ public function execute()
229229
);
230230
}
231231

232-
$data = $this->presentation->convertPresentationDataToInputType($data);
233-
234232
$data += ['is_filterable' => 0, 'is_filterable_in_search' => 0];
235233

236234
if ($model->getIsUserDefined() === null || $model->getIsUserDefined() != 0) {

app/code/Magento/Catalog/Model/Product/Attribute/Frontend/Inputtype/Presentation.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype;
810

911
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
@@ -19,9 +21,9 @@ class Presentation
1921
* Get input type for presentation layer from stored input type.
2022
*
2123
* @param Attribute $attribute
22-
* @return string
24+
* @return string|null
2325
*/
24-
public function getPresentationInputType(Attribute $attribute)
26+
public function getPresentationInputType(Attribute $attribute) :?string
2527
{
2628
$inputType = $attribute->getFrontendInput();
2729
if ($inputType == 'textarea' && $attribute->getIsWysiwygEnabled()) {
@@ -37,12 +39,12 @@ public function getPresentationInputType(Attribute $attribute)
3739
*
3840
* @return array
3941
*/
40-
public function convertPresentationDataToInputType(array $data)
42+
public function convertPresentationDataToInputType(array $data) : array
4143
{
42-
if ($data['frontend_input'] === 'texteditor') {
44+
if (isset($data['frontend_input']) && $data['frontend_input'] === 'texteditor') {
4345
$data['is_wysiwyg_enabled'] = 1;
4446
$data['frontend_input'] = 'textarea';
45-
} elseif ($data['frontend_input'] === 'textarea') {
47+
} elseif (isset($data['frontend_input']) && $data['frontend_input'] === 'textarea') {
4648
$data['is_wysiwyg_enabled'] = 0;
4749
}
4850
return $data;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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\Catalog\Test\Unit\Model\Product\Attribute\Frontend\InputType;
9+
10+
class PresentationTest extends \PHPUnit\Framework\TestCase
11+
{
12+
/**
13+
* @var \Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation
14+
*/
15+
private $presentation;
16+
17+
/**
18+
* @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute| \PHPUnit_Framework_MockObject_MockObject
19+
*/
20+
private $attributeMock;
21+
22+
protected function setUp()
23+
{
24+
$this->presentation = new \Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation();
25+
$this->attributeMock = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)
26+
->disableOriginalConstructor()
27+
->getMock();
28+
}
29+
30+
/**
31+
* @param string $inputType
32+
* @param boolean $isWysiwygEnabled
33+
* @param string $expectedResult
34+
* @dataProvider getPresentationInputTypeDataProvider
35+
*/
36+
public function testGetPresentationInputType(string $inputType, bool $isWysiwygEnabled, string $expectedResult)
37+
{
38+
$this->attributeMock->expects($this->once())->method('getFrontendInput')->willReturn($inputType);
39+
$this->attributeMock->expects($this->any())->method('getIsWysiwygEnabled')->willReturn($isWysiwygEnabled);
40+
$this->assertEquals($expectedResult, $this->presentation->getPresentationInputType($this->attributeMock));
41+
}
42+
43+
public function getPresentationInputTypeDataProvider()
44+
{
45+
return [
46+
'attribute_is_textarea_and_wysiwyg_enabled' => ['textarea', true, 'texteditor'],
47+
'attribute_is_input_and_wysiwyg_enabled' => ['input', true, 'input'],
48+
'attribute_is_textarea_and_wysiwyg_disabled' => ['textarea', false, 'textarea'],
49+
];
50+
}
51+
52+
/**
53+
* @param array $data
54+
* @param array $expectedResult
55+
* @dataProvider convertPresentationDataToInputTypeDataProvider
56+
*/
57+
public function testConvertPresentationDataToInputType(array $data, array $expectedResult)
58+
{
59+
$this->assertEquals($expectedResult, $this->presentation->convertPresentationDataToInputType($data));
60+
}
61+
62+
public function convertPresentationDataToInputTypeDataProvider()
63+
{
64+
return [
65+
[['key' => 'value'], ['key' => 'value']],
66+
[
67+
['frontend_input' => 'texteditor'],
68+
['frontend_input' => 'textarea', 'is_wysiwyg_enabled' => 1]
69+
],
70+
[
71+
['frontend_input' => 'textarea'],
72+
['frontend_input' => 'textarea', 'is_wysiwyg_enabled' => 0]
73+
],
74+
[
75+
['frontend_input' => 'input'],
76+
['frontend_input' => 'input']
77+
]
78+
];
79+
}
80+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@
6464
</parameter>
6565
<parameter name="cache_lifetime" xsi:type="text" visible="true">
6666
<label translate="true">Cache Lifetime (Seconds)</label>
67-
<description translate="true">86400 by default, if not set. To refresh instantly, clear the Blocks HTML Output cache.</description>
67+
<description translate="true">
68+
<![CDATA[Time in seconds between the widget updates.
69+
<br/>If not set, equals to 86400 seconds (24 hours). To update widget instantly, go to Cache Management and clear Blocks HTML Output cache.
70+
<br/>Widget will not show products that begin to match the specified conditions until cache is refreshed.]]>
71+
</description>
6872
</parameter>
6973
</parameters>
7074
<containers>

app/code/Magento/Catalog/i18n/en_US.csv

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,13 @@ Template,Template
705705
"New Products Names Only Template","New Products Names Only Template"
706706
"New Products Images Only Template","New Products Images Only Template"
707707
"Cache Lifetime (Seconds)","Cache Lifetime (Seconds)"
708-
"86400 by default, if not set. To refresh instantly, clear the Blocks HTML Output cache.","86400 by default, if not set. To refresh instantly, clear the Blocks HTML Output cache."
708+
"Time in seconds between the widget updates.
709+
<br/>If not set, equals to 86400 seconds (24 hours). To update widget instantly, go to Cache Management and clear Blocks HTML Output cache.
710+
<br/>Widget will not show products that begin to match the specified conditions until cache is refreshed."
711+
,
712+
"Time in seconds between the widget updates.
713+
<br/>If not set, equals to 86400 seconds (24 hours). To update widget instantly, go to Cache Management and clear Blocks HTML Output cache.
714+
<br/>Widget will not show products that begin to match the specified conditions until cache is refreshed."
709715
"Catalog Product Link","Catalog Product Link"
710716
"Link to a Specified Product","Link to a Specified Product"
711717
"Select Product...","Select Product..."
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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\CatalogGraphQl\Model\Resolver\Category;
9+
10+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Query\Resolver\Value;
13+
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
14+
use Magento\Framework\GraphQl\Query\ResolverInterface;
15+
16+
/**
17+
* Retrieves the sort fields data
18+
*/
19+
class SortFields implements ResolverInterface
20+
{
21+
/**
22+
* @var ValueFactory
23+
*/
24+
private $valueFactory;
25+
26+
/**
27+
* @var \Magento\Catalog\Model\Config
28+
*/
29+
private $catalogConfig;
30+
31+
/**
32+
* @var \Magento\Store\Model\StoreManagerInterface
33+
*/
34+
private $storeManager;
35+
36+
/**
37+
* @var \Magento\Catalog\Model\Category\Attribute\Source\Sortby
38+
*/
39+
private $sortbyAttributeSource;
40+
41+
/**
42+
* @param ValueFactory $valueFactory
43+
* @param \Magento\Catalog\Model\Config $catalogConfig
44+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
45+
* @oaram \Magento\Catalog\Model\Category\Attribute\Source\Sortby $sortbyAttributeSource
46+
*/
47+
public function __construct(
48+
ValueFactory $valueFactory,
49+
\Magento\Catalog\Model\Config $catalogConfig,
50+
\Magento\Store\Model\StoreManagerInterface $storeManager,
51+
\Magento\Catalog\Model\Category\Attribute\Source\Sortby $sortbyAttributeSource
52+
) {
53+
$this->valueFactory = $valueFactory;
54+
$this->catalogConfig = $catalogConfig;
55+
$this->storeManager = $storeManager;
56+
$this->sortbyAttributeSource = $sortbyAttributeSource;
57+
}
58+
59+
/**
60+
* {@inheritDoc}
61+
*/
62+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) : Value
63+
{
64+
$sortFieldsOptions = $this->sortbyAttributeSource->getAllOptions();
65+
array_walk(
66+
$sortFieldsOptions,
67+
function (&$option) {
68+
$option['label'] = (string)$option['label'];
69+
}
70+
);
71+
$data = [
72+
'default' => $this->catalogConfig->getProductListDefaultSortBy($this->storeManager->getStore()->getId()),
73+
'options' => $sortFieldsOptions,
74+
];
75+
76+
$result = function () use ($data) {
77+
return $data;
78+
};
79+
80+
return $this->valueFactory->create($result);
81+
}
82+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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\CatalogGraphQl\Model\Resolver\Product;
9+
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Query\Resolver\Value;
13+
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
14+
use Magento\Framework\GraphQl\Query\ResolverInterface;
15+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
17+
/**
18+
* Resolve data for product canonical URL
19+
*/
20+
class CanonicalUrl implements ResolverInterface
21+
{
22+
/**
23+
* @var ValueFactory
24+
*/
25+
private $valueFactory;
26+
27+
/**
28+
* @param ValueFactory $valueFactory
29+
*/
30+
public function __construct(
31+
ValueFactory $valueFactory
32+
) {
33+
$this->valueFactory = $valueFactory;
34+
}
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
public function resolve(
40+
Field $field,
41+
$context,
42+
ResolveInfo $info,
43+
array $value = null,
44+
array $args = null
45+
): Value {
46+
if (!isset($value['model'])) {
47+
$result = function () {
48+
return null;
49+
};
50+
return $this->valueFactory->create($result);
51+
}
52+
53+
/* @var $product Product */
54+
$product = $value['model'];
55+
$url = $product->getUrlModel()->getUrl($product, ['_ignore_category' => true]);
56+
$result = function () use ($url) {
57+
return $url;
58+
};
59+
60+
return $this->valueFactory->create($result);
61+
}
62+
}

0 commit comments

Comments
 (0)