Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 276c690

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1806 from magento-engcom/2.2-develop-prs
Public Pull Requests magento/magento2#12530 Added correction for og:type content value by @atishgoswami magento/magento2#12359 Add a --no-update option to sampledata:deploy and sampledata:remove commands by @schmengler magento/magento2#11617 Re saving product attribute by @raumatbel magento/magento2#11608 Fix for issue 9633 500 error on setup wizard with memcache by @sylink Fixed Public Issues magento/magento2#6770 M2.1.1 : Re-saving a product attribute with a different name than it's code results in an error magento/magento2#9633 Web Setup Wizard 500 error when session storage is configured to use memcache
2 parents 9eb883d + 2c4b5b0 commit 276c690

File tree

11 files changed

+495
-210
lines changed

11 files changed

+495
-210
lines changed

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

app/code/Magento/Catalog/view/frontend/templates/product/view/opengraph/general.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/** @var $block \Magento\Catalog\Block\Product\View */
1010
?>
1111

12-
<meta property="og:type" content="og:product" />
12+
<meta property="og:type" content="product" />
1313
<meta property="og:title" content="<?= $block->escapeHtmlAttr($block->stripTags($block->getProduct()->getName())) ?>" />
1414
<meta property="og:image" content="<?= $block->escapeUrl($block->getImage($block->getProduct(), 'product_base_image')->getImageUrl()) ?>" />
1515
<meta property="og:description" content="<?= $block->escapeHtmlAttr($block->stripTags($block->getProduct()->getShortDescription())) ?>" />

app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
use Symfony\Component\Console\Command\Command;
1313
use Symfony\Component\Console\Input\ArrayInput;
1414
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Input\InputOption;
1516
use Symfony\Component\Console\Output\OutputInterface;
1617

1718
/**
1819
* Command for deployment of Sample Data
1920
*/
2021
class SampleDataDeployCommand extends Command
2122
{
23+
const OPTION_NO_UPDATE = 'no-update';
24+
2225
/**
2326
* @var \Magento\Framework\Filesystem
2427
*/
@@ -66,6 +69,12 @@ protected function configure()
6669
{
6770
$this->setName('sampledata:deploy')
6871
->setDescription('Deploy sample data modules');
72+
$this->addOption(
73+
self::OPTION_NO_UPDATE,
74+
null,
75+
InputOption::VALUE_NONE,
76+
'Update composer.json without executing composer update'
77+
);
6978
parent::configure();
7079
}
7180

@@ -80,6 +89,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
8089
if (!empty($sampleDataPackages)) {
8190
$baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath();
8291
$commonArgs = ['--working-dir' => $baseDir, '--no-progress' => 1];
92+
if ($input->getOption(self::OPTION_NO_UPDATE)) {
93+
$commonArgs['--no-update'] = 1;
94+
}
8395
$packages = [];
8496
foreach ($sampleDataPackages as $name => $version) {
8597
$packages[] = "$name:$version";

app/code/Magento/SampleData/Console/Command/SampleDataRemoveCommand.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Symfony\Component\Console\Command\Command;
1010
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Input\InputOption;
1112
use Symfony\Component\Console\Output\OutputInterface;
1213
use Magento\SampleData\Model\Dependency;
1314
use Symfony\Component\Console\Input\ArrayInput;
@@ -22,6 +23,8 @@
2223
*/
2324
class SampleDataRemoveCommand extends Command
2425
{
26+
const OPTION_NO_UPDATE = 'no-update';
27+
2528
/**
2629
* @var Filesystem
2730
*/
@@ -69,6 +72,12 @@ protected function configure()
6972
{
7073
$this->setName('sampledata:remove')
7174
->setDescription('Remove all sample data packages from composer.json');
75+
$this->addOption(
76+
self::OPTION_NO_UPDATE,
77+
null,
78+
InputOption::VALUE_NONE,
79+
'Update composer.json without executing composer update'
80+
);
7281
parent::configure();
7382
}
7483

@@ -81,6 +90,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
8190
if (!empty($sampleDataPackages)) {
8291
$baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath();
8392
$commonArgs = ['--working-dir' => $baseDir, '--no-interaction' => 1, '--no-progress' => 1];
93+
if ($input->getOption(self::OPTION_NO_UPDATE)) {
94+
$commonArgs['--no-update'] = 1;
95+
}
8496
$packages = array_keys($sampleDataPackages);
8597
$arguments = array_merge(['command' => 'remove', 'packages' => $packages], $commonArgs);
8698
$commandInput = new ArrayInput($arguments);

0 commit comments

Comments
 (0)