Skip to content

Commit 0a545eb

Browse files
Merge branch '2.2-develop' of github.com:magento/magento2 into experius-2.2-patch-customer-accountmanagement-is-confirmation-required
2 parents 6227a14 + 3839c0f commit 0a545eb

File tree

483 files changed

+8752
-5793
lines changed

Some content is hidden

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

483 files changed

+8752
-5793
lines changed

app/code/Magento/Backend/Test/Unit/Model/Config/SessionLifetime/BackendModelTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public function testBeforeSave($value, $errorMessage = null)
2020
\Magento\Backend\Model\Config\SessionLifetime\BackendModel::class
2121
);
2222
if ($errorMessage !== null) {
23-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $errorMessage);
23+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
24+
$this->expectExceptionMessage($errorMessage);
2425
}
2526
$model->setValue($value);
2627
$object = $model->beforeSave();

app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ public function getWidgetOptionsJson(array $customOptions = [])
689689
'limit' => ToolbarModel::LIMIT_PARAM_NAME,
690690
'modeDefault' => $defaultMode,
691691
'directionDefault' => $this->_direction ?: ProductList::DEFAULT_SORT_DIRECTION,
692-
'orderDefault' => $this->_productListHelper->getDefaultSortField(),
692+
'orderDefault' => $this->getOrderField(),
693693
'limitDefault' => $this->_productListHelper->getDefaultLimitPerPageValue($defaultMode),
694694
'url' => $this->getPagerUrl(),
695695
];

app/code/Magento/Catalog/Console/Command/ImagesResizeCommand.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Catalog\Console\Command;
77

8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
811
class ImagesResizeCommand extends \Symfony\Component\Console\Command\Command
912
{
1013
/**
@@ -58,10 +61,8 @@ protected function configure()
5861
/**
5962
* {@inheritdoc}
6063
*/
61-
protected function execute(
62-
\Symfony\Component\Console\Input\InputInterface $input,
63-
\Symfony\Component\Console\Output\OutputInterface $output
64-
) {
64+
protected function execute(InputInterface $input, OutputInterface $output)
65+
{
6566
$this->appState->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
6667

6768
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
@@ -73,6 +74,7 @@ protected function execute(
7374
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
7475
}
7576

77+
$errorMessage = '';
7678
try {
7779
foreach ($productIds as $productId) {
7880
try {
@@ -82,9 +84,13 @@ protected function execute(
8284
continue;
8385
}
8486

85-
/** @var \Magento\Catalog\Model\Product\Image\Cache $imageCache */
86-
$imageCache = $this->imageCacheFactory->create();
87-
$imageCache->generate($product);
87+
try {
88+
/** @var \Magento\Catalog\Model\Product\Image\Cache $imageCache */
89+
$imageCache = $this->imageCacheFactory->create();
90+
$imageCache->generate($product);
91+
} catch (\Magento\Framework\Exception\RuntimeException $e) {
92+
$errorMessage = $e->getMessage();
93+
}
8894

8995
$output->write(".");
9096
}
@@ -95,6 +101,12 @@ protected function execute(
95101
}
96102

97103
$output->write("\n");
98-
$output->writeln("<info>Product images resized successfully</info>");
104+
$output->writeln("<info>Product images resized successfully.</info>");
105+
106+
if ($errorMessage !== '') {
107+
$output->writeln("<comment>{$errorMessage}</comment>");
108+
}
109+
110+
return 0;
99111
}
100112
}

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

Lines changed: 91 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,79 +5,95 @@
55
* See COPYING.txt for license details.
66
*/
77

8-
// @codingStandardsIgnoreFile
9-
108
namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute;
119

10+
use Magento\Backend\App\Action\Context;
11+
use Magento\Backend\Model\View\Result\Redirect;
12+
use Magento\Catalog\Controller\Adminhtml\Product\Attribute;
13+
use Magento\Catalog\Model\Product\AttributeSet\BuildFactory;
14+
use Magento\Catalog\Helper\Product;
15+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
16+
use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory;
17+
use Magento\Eav\Model\Entity\Attribute\Set;
18+
use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator;
19+
use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory;
20+
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory;
21+
use Magento\Framework\Cache\FrontendInterface;
1222
use Magento\Framework\Controller\ResultFactory;
23+
use Magento\Framework\Controller\Result\Json;
1324
use Magento\Framework\Exception\AlreadyExistsException;
25+
use Magento\Framework\Exception\LocalizedException;
26+
use Magento\Framework\Filter\FilterManager;
27+
use Magento\Framework\Registry;
28+
use Magento\Framework\View\LayoutFactory;
29+
use Magento\Framework\View\Result\PageFactory;
1430

1531
/**
1632
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1733
*/
18-
class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute
34+
class Save extends Attribute
1935
{
2036
/**
21-
* @var \Magento\Catalog\Model\Product\AttributeSet\BuildFactory
37+
* @var BuildFactory
2238
*/
2339
protected $buildFactory;
2440

2541
/**
26-
* @var \Magento\Framework\Filter\FilterManager
42+
* @var FilterManager
2743
*/
2844
protected $filterManager;
2945

3046
/**
31-
* @var \Magento\Catalog\Helper\Product
47+
* @var Product
3248
*/
3349
protected $productHelper;
3450

3551
/**
36-
* @var \Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory
52+
* @var AttributeFactory
3753
*/
3854
protected $attributeFactory;
3955

4056
/**
41-
* @var \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory
57+
* @var ValidatorFactory
4258
*/
4359
protected $validatorFactory;
4460

4561
/**
46-
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory
62+
* @var CollectionFactory
4763
*/
4864
protected $groupCollectionFactory;
4965

5066
/**
51-
* @var \Magento\Framework\View\LayoutFactory
67+
* @var LayoutFactory
5268
*/
5369
private $layoutFactory;
5470

5571
/**
56-
* @param \Magento\Backend\App\Action\Context $context
57-
* @param \Magento\Framework\Cache\FrontendInterface $attributeLabelCache
58-
* @param \Magento\Framework\Registry $coreRegistry
59-
* @param \Magento\Catalog\Model\Product\AttributeSet\BuildFactory $buildFactory
60-
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
61-
* @param \Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory $attributeFactory
62-
* @param \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory $validatorFactory
63-
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory $groupCollectionFactory
64-
* @param \Magento\Framework\Filter\FilterManager $filterManager
65-
* @param \Magento\Catalog\Helper\Product $productHelper
66-
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
72+
* @param Context $context
73+
* @param FrontendInterface $attributeLabelCache
74+
* @param Registry $coreRegistry
75+
* @param BuildFactory $buildFactory
76+
* @param PageFactory $resultPageFactory
77+
* @param AttributeFactory $attributeFactory
78+
* @param ValidatorFactory $validatorFactory
79+
* @param CollectionFactory $groupCollectionFactory
80+
* @param FilterManager $filterManager
81+
* @param Product $productHelper
82+
* @param LayoutFactory $layoutFactory
6783
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6884
*/
6985
public function __construct(
70-
\Magento\Backend\App\Action\Context $context,
71-
\Magento\Framework\Cache\FrontendInterface $attributeLabelCache,
72-
\Magento\Framework\Registry $coreRegistry,
73-
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
74-
\Magento\Catalog\Model\Product\AttributeSet\BuildFactory $buildFactory,
75-
\Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory $attributeFactory,
76-
\Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory $validatorFactory,
77-
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory $groupCollectionFactory,
78-
\Magento\Framework\Filter\FilterManager $filterManager,
79-
\Magento\Catalog\Helper\Product $productHelper,
80-
\Magento\Framework\View\LayoutFactory $layoutFactory
86+
Context $context,
87+
FrontendInterface $attributeLabelCache,
88+
Registry $coreRegistry,
89+
PageFactory $resultPageFactory,
90+
BuildFactory $buildFactory,
91+
AttributeFactory $attributeFactory,
92+
ValidatorFactory $validatorFactory,
93+
CollectionFactory $groupCollectionFactory,
94+
FilterManager $filterManager,
95+
Product $productHelper,
96+
LayoutFactory $layoutFactory
8197
) {
8298
parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory);
8399
$this->buildFactory = $buildFactory;
@@ -90,7 +106,7 @@ public function __construct(
90106
}
91107

92108
/**
93-
* @return \Magento\Backend\Model\View\Result\Redirect
109+
* @return Redirect
94110
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
95111
* @SuppressWarnings(PHPMD.NPathComplexity)
96112
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -107,36 +123,51 @@ public function execute()
107123
$name = trim($name);
108124

109125
try {
110-
/** @var $attributeSet \Magento\Eav\Model\Entity\Attribute\Set */
126+
/** @var $attributeSet Set */
111127
$attributeSet = $this->buildFactory->create()
112128
->setEntityTypeId($this->_entityTypeId)
113129
->setSkeletonId($setId)
114130
->setName($name)
115131
->getAttributeSet();
116132
} catch (AlreadyExistsException $alreadyExists) {
117-
$this->messageManager->addError(__('An attribute set named \'%1\' already exists.', $name));
133+
$this->messageManager->addErrorMessage(__('An attribute set named \'%1\' already exists.', $name));
118134
$this->_session->setAttributeData($data);
135+
119136
return $this->returnResult('catalog/*/edit', ['_current' => true], ['error' => true]);
120-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
121-
$this->messageManager->addError($e->getMessage());
137+
} catch (LocalizedException $e) {
138+
$this->messageManager->addErrorMessage($e->getMessage());
122139
} catch (\Exception $e) {
123-
$this->messageManager->addException($e, __('Something went wrong while saving the attribute.'));
140+
$this->messageManager->addExceptionMessage(
141+
$e,
142+
__('Something went wrong while saving the attribute.')
143+
);
124144
}
125145
}
126146

127147
$attributeId = $this->getRequest()->getParam('attribute_id');
128-
$attributeCode = $this->getRequest()->getParam('attribute_code')
129-
?: $this->generateCode($this->getRequest()->getParam('frontend_label')[0]);
148+
149+
/** @var $model ProductAttributeInterface */
150+
$model = $this->attributeFactory->create();
151+
if ($attributeId) {
152+
$model->load($attributeId);
153+
}
154+
$attributeCode = $model && $model->getId()
155+
? $model->getAttributeCode()
156+
: $this->getRequest()->getParam('attribute_code');
157+
$attributeCode = $attributeCode ?: $this->generateCode($this->getRequest()->getParam('frontend_label')[0]);
130158
if (strlen($attributeCode) > 0) {
131-
$validatorAttrCode = new \Zend_Validate_Regex(['pattern' => '/^[a-z\x{600}-\x{6FF}][a-z\x{600}-\x{6FF}_0-9]{0,30}$/u']);
159+
$validatorAttrCode = new \Zend_Validate_Regex(
160+
['pattern' => '/^[a-z\x{600}-\x{6FF}][a-z\x{600}-\x{6FF}_0-9]{0,30}$/u']
161+
);
132162
if (!$validatorAttrCode->isValid($attributeCode)) {
133-
$this->messageManager->addError(
163+
$this->messageManager->addErrorMessage(
134164
__(
135165
'Attribute code "%1" is invalid. Please use only letters (a-z), ' .
136166
'numbers (0-9) or underscore(_) in this field, first character should be a letter.',
137167
$attributeCode
138168
)
139169
);
170+
140171
return $this->returnResult(
141172
'catalog/*/edit',
142173
['attribute_id' => $attributeId, '_current' => true],
@@ -148,12 +179,13 @@ public function execute()
148179

149180
//validate frontend_input
150181
if (isset($data['frontend_input'])) {
151-
/** @var $inputType \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator */
182+
/** @var $inputType Validator */
152183
$inputType = $this->validatorFactory->create();
153184
if (!$inputType->isValid($data['frontend_input'])) {
154185
foreach ($inputType->getMessages() as $message) {
155-
$this->messageManager->addError($message);
186+
$this->messageManager->addErrorMessage($message);
156187
}
188+
157189
return $this->returnResult(
158190
'catalog/*/edit',
159191
['attribute_id' => $attributeId, '_current' => true],
@@ -162,19 +194,17 @@ public function execute()
162194
}
163195
}
164196

165-
/* @var $model \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
166-
$model = $this->attributeFactory->create();
167-
168197
if ($attributeId) {
169-
$model->load($attributeId);
170198
if (!$model->getId()) {
171-
$this->messageManager->addError(__('This attribute no longer exists.'));
199+
$this->messageManager->addErrorMessage(__('This attribute no longer exists.'));
200+
172201
return $this->returnResult('catalog/*/', [], ['error' => true]);
173202
}
174203
// entity type check
175204
if ($model->getEntityTypeId() != $this->_entityTypeId) {
176-
$this->messageManager->addError(__('We can\'t update the attribute.'));
205+
$this->messageManager->addErrorMessage(__('We can\'t update the attribute.'));
177206
$this->_session->setAttributeData($data);
207+
178208
return $this->returnResult('catalog/*/', [], ['error' => true]);
179209
}
180210

@@ -195,7 +225,7 @@ public function execute()
195225

196226
$data += ['is_filterable' => 0, 'is_filterable_in_search' => 0];
197227

198-
if (is_null($model->getIsUserDefined()) || $model->getIsUserDefined() != 0) {
228+
if ($model->getIsUserDefined() === null || $model->getIsUserDefined() != 0) {
199229
$data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']);
200230
}
201231

@@ -241,7 +271,7 @@ public function execute()
241271

242272
try {
243273
$model->save();
244-
$this->messageManager->addSuccess(__('You saved the product attribute.'));
274+
$this->messageManager->addSuccessMessage(__('You saved the product attribute.'));
245275

246276
$this->_attributeLabelCache->clean();
247277
$this->_session->setAttributeData(false);
@@ -252,9 +282,10 @@ public function execute()
252282
'_current' => true,
253283
'product_tab' => $this->getRequest()->getParam('product_tab'),
254284
];
255-
if (!is_null($attributeSet)) {
285+
if ($attributeSet !== null) {
256286
$requestParams['new_attribute_set_id'] = $attributeSet->getId();
257287
}
288+
258289
return $this->returnResult('catalog/product/addAttribute', $requestParams, ['error' => false]);
259290
} elseif ($this->getRequest()->getParam('back', false)) {
260291
return $this->returnResult(
@@ -263,25 +294,28 @@ public function execute()
263294
['error' => false]
264295
);
265296
}
297+
266298
return $this->returnResult('catalog/*/', [], ['error' => false]);
267299
} catch (\Exception $e) {
268-
$this->messageManager->addError($e->getMessage());
300+
$this->messageManager->addErrorMessage($e->getMessage());
269301
$this->_session->setAttributeData($data);
302+
270303
return $this->returnResult(
271304
'catalog/*/edit',
272305
['attribute_id' => $attributeId, '_current' => true],
273306
['error' => true]
274307
);
275308
}
276309
}
310+
277311
return $this->returnResult('catalog/*/', [], ['error' => true]);
278312
}
279313

280314
/**
281315
* @param string $path
282316
* @param array $params
283317
* @param array $response
284-
* @return \Magento\Framework\Controller\Result\Json|\Magento\Backend\Model\View\Result\Redirect
318+
* @return Json|Redirect
285319
*/
286320
private function returnResult($path = '', array $params = [], array $response = [])
287321
{
@@ -291,8 +325,10 @@ private function returnResult($path = '', array $params = [], array $response =
291325

292326
$response['messages'] = [$layout->getMessagesBlock()->getGroupedHtml()];
293327
$response['params'] = $params;
328+
294329
return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($response);
295330
}
331+
296332
return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath($path, $params);
297333
}
298334

0 commit comments

Comments
 (0)