Skip to content

Commit b7b6754

Browse files
committed
Merge branch '2.2-develop' into MAGETWO-90940
2 parents b3eb621 + 0383b22 commit b7b6754

File tree

103 files changed

+724
-207
lines changed

Some content is hidden

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

103 files changed

+724
-207
lines changed

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

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
*/
77
namespace Magento\Catalog\Controller\Adminhtml\Product\Set;
88

9+
use Magento\Framework\App\ObjectManager;
10+
11+
/**
12+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13+
*/
914
class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Set
1015
{
1116
/**
@@ -17,22 +22,49 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Set
1722
* @var \Magento\Framework\Controller\Result\JsonFactory
1823
*/
1924
protected $resultJsonFactory;
20-
25+
26+
/*
27+
* @var \Magento\Eav\Model\Entity\Attribute\SetFactory
28+
*/
29+
private $attributeSetFactory;
30+
31+
/*
32+
* @var \Magento\Framework\Filter\FilterManager
33+
*/
34+
private $filterManager;
35+
36+
/*
37+
* @var \Magento\Framework\Json\Helper\Data
38+
*/
39+
private $jsonHelper;
40+
2141
/**
2242
* @param \Magento\Backend\App\Action\Context $context
2343
* @param \Magento\Framework\Registry $coreRegistry
2444
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
2545
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
46+
* @param \Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory
47+
* @param \Magento\Framework\Filter\FilterManager $filterManager
48+
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
2649
*/
2750
public function __construct(
2851
\Magento\Backend\App\Action\Context $context,
2952
\Magento\Framework\Registry $coreRegistry,
3053
\Magento\Framework\View\LayoutFactory $layoutFactory,
31-
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
54+
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
55+
\Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory = null,
56+
\Magento\Framework\Filter\FilterManager $filterManager = null,
57+
\Magento\Framework\Json\Helper\Data $jsonHelper = null
3258
) {
3359
parent::__construct($context, $coreRegistry);
3460
$this->layoutFactory = $layoutFactory;
3561
$this->resultJsonFactory = $resultJsonFactory;
62+
$this->attributeSetFactory = $attributeSetFactory ?: ObjectManager::getInstance()
63+
->get(\Magento\Eav\Model\Entity\Attribute\SetFactory::class);
64+
$this->filterManager = $filterManager ?: ObjectManager::getInstance()
65+
->get(\Magento\Framework\Filter\FilterManager::class);
66+
$this->jsonHelper = $jsonHelper ?: ObjectManager::getInstance()
67+
->get(\Magento\Framework\Json\Helper\Data::class);
3668
}
3769

3870
/**
@@ -65,16 +97,12 @@ public function execute()
6597
$isNewSet = $this->getRequest()->getParam('gotoEdit', false) == '1';
6698

6799
/* @var $model \Magento\Eav\Model\Entity\Attribute\Set */
68-
$model = $this->_objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class)
69-
->setEntityTypeId($entityTypeId);
70-
71-
/** @var $filterManager \Magento\Framework\Filter\FilterManager */
72-
$filterManager = $this->_objectManager->get(\Magento\Framework\Filter\FilterManager::class);
100+
$model = $this->attributeSetFactory->create()->setEntityTypeId($entityTypeId);
73101

74102
try {
75103
if ($isNewSet) {
76104
//filter html tags
77-
$name = $filterManager->stripTags($this->getRequest()->getParam('attribute_set_name'));
105+
$name = $this->filterManager->stripTags($this->getRequest()->getParam('attribute_set_name'));
78106
$model->setAttributeSetName(trim($name));
79107
} else {
80108
if ($attributeSetId) {
@@ -85,11 +113,10 @@ public function execute()
85113
__('This attribute set no longer exists.')
86114
);
87115
}
88-
$data = $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)
89-
->jsonDecode($this->getRequest()->getPost('data'));
116+
$data = $this->jsonHelper->jsonDecode($this->getRequest()->getPost('data'));
90117

91118
//filter html tags
92-
$data['attribute_set_name'] = $filterManager->stripTags($data['attribute_set_name']);
119+
$data['attribute_set_name'] = $this->filterManager->stripTags($data['attribute_set_name']);
93120

94121
$model->organizeData($data);
95122
}

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2675,7 +2675,12 @@ protected function checkUrlKeyDuplicates()
26752675
);
26762676
foreach ($urlKeyDuplicates as $entityData) {
26772677
$rowNum = $this->rowNumbers[$entityData['store_id']][$entityData['request_path']];
2678-
$this->addRowError(ValidatorInterface::ERROR_DUPLICATE_URL_KEY, $rowNum);
2678+
$message = sprintf(
2679+
$this->retrieveMessageTemplate(ValidatorInterface::ERROR_DUPLICATE_URL_KEY),
2680+
$entityData['request_path'],
2681+
$entityData['sku']
2682+
);
2683+
$this->addRowError(ValidatorInterface::ERROR_DUPLICATE_URL_KEY, $rowNum, 'url_key', $message);
26792684
}
26802685
}
26812686
}

app/code/Magento/CatalogUrlRewrite/Model/ProductUrlPathGenerator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,12 @@ public function getCanonicalUrlPath($product, $category = null)
120120
* Generate product url key based on url_key entered by merchant or product name
121121
*
122122
* @param \Magento\Catalog\Model\Product $product
123-
* @return string
123+
* @return string|null
124124
*/
125125
public function getUrlKey($product)
126126
{
127-
return $product->getUrlKey() === false ? false : $this->prepareProductUrlKey($product);
127+
$generatedProductUrlKey = $this->prepareProductUrlKey($product);
128+
return ($product->getUrlKey() === false || empty($generatedProductUrlKey)) ? null : $generatedProductUrlKey;
128129
}
129130

130131
/**

app/code/Magento/CatalogUrlRewrite/Observer/ProductUrlKeyAutogeneratorObserver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public function execute(\Magento\Framework\Event\Observer $observer)
3333
{
3434
/** @var Product $product */
3535
$product = $observer->getEvent()->getProduct();
36-
$product->setUrlKey($this->productUrlPathGenerator->getUrlKey($product));
36+
$urlKey = $this->productUrlPathGenerator->getUrlKey($product);
37+
if (null !== $urlKey) {
38+
$product->setUrlKey($urlKey);
39+
}
3740
}
3841
}

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/ProductUrlPathGeneratorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function testGetUrlKey($productUrlKey, $expectedUrlKey)
105105
{
106106
$this->product->expects($this->any())->method('getUrlKey')->will($this->returnValue($productUrlKey));
107107
$this->product->expects($this->any())->method('formatUrlKey')->will($this->returnValue($productUrlKey));
108-
$this->assertEquals($expectedUrlKey, $this->productUrlPathGenerator->getUrlKey($this->product));
108+
$this->assertSame($expectedUrlKey, $this->productUrlPathGenerator->getUrlKey($this->product));
109109
}
110110

111111
/**
@@ -114,7 +114,7 @@ public function testGetUrlKey($productUrlKey, $expectedUrlKey)
114114
public function getUrlKeyDataProvider()
115115
{
116116
return [
117-
'URL Key use default' => [false, false],
117+
'URL Key use default' => [false, null],
118118
'URL Key empty' => ['product-url', 'product-url'],
119119
];
120120
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogUrlRewrite\Test\Unit\Observer;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
9+
use \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator;
10+
11+
/**
12+
* Unit tests for \Magento\CatalogUrlRewrite\Observer\ProductUrlKeyAutogeneratorObserver class
13+
*/
14+
class ProductUrlKeyAutogeneratorObserverTest extends \PHPUnit\Framework\TestCase
15+
{
16+
/**
17+
* @var \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator|\PHPUnit_Framework_MockObject_MockObject
18+
*/
19+
private $productUrlPathGenerator;
20+
21+
/** @var \Magento\CatalogUrlRewrite\Observer\ProductUrlKeyAutogeneratorObserver */
22+
private $productUrlKeyAutogeneratorObserver;
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
protected function setUp()
28+
{
29+
$this->productUrlPathGenerator = $this->getMockBuilder(ProductUrlPathGenerator::class)
30+
->disableOriginalConstructor()
31+
->setMethods(['getUrlKey'])
32+
->getMock();
33+
34+
$this->productUrlKeyAutogeneratorObserver = (new ObjectManagerHelper($this))->getObject(
35+
\Magento\CatalogUrlRewrite\Observer\ProductUrlKeyAutogeneratorObserver::class,
36+
[
37+
'productUrlPathGenerator' => $this->productUrlPathGenerator
38+
]
39+
);
40+
}
41+
42+
public function testExecuteWithUrlKey()
43+
{
44+
$urlKey = 'product_url_key';
45+
46+
$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
47+
->disableOriginalConstructor()
48+
->setMethods(['setUrlKey'])
49+
->getMock();
50+
$product->expects($this->atLeastOnce())->method('setUrlKey')->with($urlKey);
51+
$event = $this->getMockBuilder(\Magento\Framework\Event::class)
52+
->disableOriginalConstructor()
53+
->setMethods(['getProduct'])
54+
->getMock();
55+
$event->expects($this->atLeastOnce())->method('getProduct')->willReturn($product);
56+
/** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $observer */
57+
$observer = $this->getMockBuilder(\Magento\Framework\Event\Observer::class)
58+
->disableOriginalConstructor()
59+
->setMethods(['getEvent'])
60+
->getMock();
61+
$observer->expects($this->atLeastOnce())->method('getEvent')->willReturn($event);
62+
$this->productUrlPathGenerator->expects($this->atLeastOnce())->method('getUrlKey')->with($product)
63+
->willReturn($urlKey);
64+
65+
$this->productUrlKeyAutogeneratorObserver->execute($observer);
66+
}
67+
68+
public function testExecuteWithEmptyUrlKey()
69+
{
70+
$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
71+
->disableOriginalConstructor()
72+
->setMethods(['setUrlKey'])
73+
->getMock();
74+
$product->expects($this->never())->method('setUrlKey');
75+
$event = $this->getMockBuilder(\Magento\Framework\Event::class)
76+
->disableOriginalConstructor()
77+
->setMethods(['getProduct'])
78+
->getMock();
79+
$event->expects($this->atLeastOnce())->method('getProduct')->willReturn($product);
80+
/** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $observer */
81+
$observer = $this->getMockBuilder(\Magento\Framework\Event\Observer::class)
82+
->disableOriginalConstructor()
83+
->setMethods(['getEvent'])
84+
->getMock();
85+
$observer->expects($this->atLeastOnce())->method('getEvent')->willReturn($event);
86+
$this->productUrlPathGenerator->expects($this->atLeastOnce())->method('getUrlKey')->with($product)
87+
->willReturn(null);
88+
89+
$this->productUrlKeyAutogeneratorObserver->execute($observer);
90+
}
91+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,5 @@ Payment,Payment
176176
"Not yet calculated","Not yet calculated"
177177
"We received your order!","We received your order!"
178178
"Thank you for your purchase!","Thank you for your purchase!"
179-
"optional", "optional"
179+
"Password", "Password"
180180
"Something went wrong while saving the page. Please refresh the page and try again.","Something went wrong while saving the page. Please refresh the page and try again."

app/code/Magento/Checkout/view/frontend/web/template/form/element/email.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<input class="input-text"
4242
data-bind="
4343
attr: {
44-
placeholder: $t('optional'),
44+
placeholder: $t('Password'),
4545
}"
4646
type="password"
4747
name="password"

app/code/Magento/Newsletter/Block/Adminhtml/Problem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Problem extends \Magento\Backend\Block\Template
1919
/**
2020
* @var string
2121
*/
22-
protected $_template = 'problem/list.phtml';
22+
protected $_template = 'Magento_Newsletter::problem/list.phtml';
2323

2424
/**
2525
* @var \Magento\Newsletter\Model\ResourceModel\Problem\Collection

app/code/Magento/Newsletter/Block/Adminhtml/Queue/Edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Edit extends \Magento\Backend\Block\Template
1919
/**
2020
* @var string
2121
*/
22-
protected $_template = 'queue/edit.phtml';
22+
protected $_template = 'Magento_Newsletter::queue/edit.phtml';
2323

2424
/**
2525
* Core registry

0 commit comments

Comments
 (0)