From 8d801bd2c64a5716ca368758952afb61db663a71 Mon Sep 17 00:00:00 2001 From: mahesh Date: Mon, 15 Oct 2018 13:30:06 +0530 Subject: [PATCH 1/4] Issue#18263#18493 Fixed --- .../Adminhtml/Product/Attribute/Save.php | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php index 91a98424c9ae1..830057c1346e1 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php @@ -222,14 +222,14 @@ public function execute() $data['backend_model'] = $this->productHelper->getAttributeBackendModelByInputType( $data['frontend_input'] ); - - if ($model->getIsUserDefined() === null) { - $data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']); - } } $data += ['is_filterable' => 0, 'is_filterable_in_search' => 0]; + if ($model->getIsUserDefined() === null || $model->getIsUserDefined() != 0) { + $data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']); + } + $defaultValueField = $model->getDefaultValueByInput($data['frontend_input']); if ($defaultValueField) { $data['default_value'] = $this->getRequest()->getParam($defaultValueField); @@ -327,8 +327,7 @@ private function preprocessOptionsData(&$data) $serializedOptions = json_decode($data['serialized_options'], JSON_OBJECT_AS_ARRAY); foreach ($serializedOptions as $serializedOption) { $option = []; - $serializedOptionWithParsedAmpersand = str_replace('&', '%26', $serializedOption); - parse_str($serializedOptionWithParsedAmpersand, $option); + parse_str($this->escapeSpecialChars($serializedOption), $option); $data = array_replace_recursive($data, $option); } } @@ -356,6 +355,18 @@ private function returnResult($path = '', array $params = [], array $response = return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath($path, $params); } + /** + * @param string $value + * @return string + */ + private function escapeSpecialChars($value) + { + $valueArray = explode("=", $value); + $valueArray[1] = isset($valueArray[1])? urlencode($valueArray[1]):''; + $finalValue = implode("=", $valueArray); + return $finalValue; + } + /** * Define whether request is Ajax * From 42ad9a9b9dd95af19ddad79a0f36c05f0d8aa5de Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 16 Oct 2018 11:41:56 +0530 Subject: [PATCH 2/4] issues #18616 #11552 fixed --- app/code/Magento/Quote/Model/QuoteManagement.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index e2ee8bbad01b9..7c1017df32fed 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -355,6 +355,9 @@ public function placeOrder($cartId, PaymentInterface $paymentMethod = null) if ($quote->getCheckoutMethod() === self::METHOD_GUEST) { $quote->setCustomerId(null); $quote->setCustomerEmail($quote->getBillingAddress()->getEmail()); + $quote->setCustomerFirstname($quote->getBillingAddress()->getFirstname()); + $quote->setCustomerMiddlename($quote->getBillingAddress()->getMiddlename()); + $quote->setCustomerLastname($quote->getBillingAddress()->getLastname()); $quote->setCustomerIsGuest(true); $quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID); } From 94ecdd5b3c76e6e018469f0d4fcbba01232c92d2 Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 16 Oct 2018 14:50:58 +0530 Subject: [PATCH 3/4] The Travis CI build fixed. --- app/code/Magento/Quote/Model/QuoteManagement.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index 7c1017df32fed..f3992fafd7b35 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -353,11 +353,13 @@ public function placeOrder($cartId, PaymentInterface $paymentMethod = null) } if ($quote->getCheckoutMethod() === self::METHOD_GUEST) { + $billingAddress = $quote->getBillingAddress(); + $quote->setCustomerId(null); - $quote->setCustomerEmail($quote->getBillingAddress()->getEmail()); - $quote->setCustomerFirstname($quote->getBillingAddress()->getFirstname()); - $quote->setCustomerMiddlename($quote->getBillingAddress()->getMiddlename()); - $quote->setCustomerLastname($quote->getBillingAddress()->getLastname()); + $quote->setCustomerEmail($billingAddress->getEmail()); + $quote->setCustomerFirstname($billingAddress->getFirstname()); + $quote->setCustomerMiddlename($billingAddress->getMiddlename()); + $quote->setCustomerLastname($billingAddress->getLastname()); $quote->setCustomerIsGuest(true); $quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID); } From ac074575a5cfa03ac6278cad81990a55ed542137 Mon Sep 17 00:00:00 2001 From: mahesh Date: Mon, 29 Oct 2018 12:40:05 +0530 Subject: [PATCH 4/4] unused file changing, fixed --- .../Adminhtml/Product/Attribute/Save.php | 58 +------------------ 1 file changed, 1 insertion(+), 57 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php index 830057c1346e1..e479d9402c6f5 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php @@ -4,9 +4,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute; - use Magento\Backend\App\Action\Context; use Magento\Backend\Model\View\Result\Redirect; use Magento\Catalog\Controller\Adminhtml\Product\Attribute; @@ -27,7 +25,6 @@ use Magento\Framework\Registry; use Magento\Framework\View\LayoutFactory; use Magento\Framework\View\Result\PageFactory; - /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ @@ -37,37 +34,30 @@ class Save extends Attribute * @var BuildFactory */ protected $buildFactory; - /** * @var FilterManager */ protected $filterManager; - /** * @var Product */ protected $productHelper; - /** * @var AttributeFactory */ protected $attributeFactory; - /** * @var ValidatorFactory */ protected $validatorFactory; - /** * @var CollectionFactory */ protected $groupCollectionFactory; - /** * @var LayoutFactory */ private $layoutFactory; - /** * @param Context $context * @param FrontendInterface $attributeLabelCache @@ -104,7 +94,6 @@ public function __construct( $this->groupCollectionFactory = $groupCollectionFactory; $this->layoutFactory = $layoutFactory; } - /** * @return Redirect * @SuppressWarnings(PHPMD.CyclomaticComplexity) @@ -117,12 +106,10 @@ public function execute() if ($data) { $this->preprocessOptionsData($data); $setId = $this->getRequest()->getParam('set'); - $attributeSet = null; if (!empty($data['new_attribute_set_name'])) { $name = $this->filterManager->stripTags($data['new_attribute_set_name']); $name = trim($name); - try { /** @var $attributeSet Set */ $attributeSet = $this->buildFactory->create() @@ -133,7 +120,6 @@ public function execute() } catch (AlreadyExistsException $alreadyExists) { $this->messageManager->addErrorMessage(__('An attribute set named \'%1\' already exists.', $name)); $this->_session->setAttributeData($data); - return $this->returnResult('catalog/*/edit', ['_current' => true], ['error' => true]); } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); @@ -144,9 +130,7 @@ public function execute() ); } } - $attributeId = $this->getRequest()->getParam('attribute_id'); - /** @var $model ProductAttributeInterface */ $model = $this->attributeFactory->create(); if ($attributeId) { @@ -168,7 +152,6 @@ public function execute() $attributeCode ) ); - return $this->returnResult( 'catalog/*/edit', ['attribute_id' => $attributeId, '_current' => true], @@ -177,7 +160,6 @@ public function execute() } } $data['attribute_code'] = $attributeCode; - //validate frontend_input if (isset($data['frontend_input'])) { /** @var $inputType Validator */ @@ -186,7 +168,6 @@ public function execute() foreach ($inputType->getMessages() as $message) { $this->messageManager->addErrorMessage($message); } - return $this->returnResult( 'catalog/*/edit', ['attribute_id' => $attributeId, '_current' => true], @@ -194,21 +175,17 @@ public function execute() ); } } - if ($attributeId) { if (!$model->getId()) { $this->messageManager->addErrorMessage(__('This attribute no longer exists.')); - return $this->returnResult('catalog/*/', [], ['error' => true]); } // entity type check if ($model->getEntityTypeId() != $this->_entityTypeId) { $this->messageManager->addErrorMessage(__('We can\'t update the attribute.')); $this->_session->setAttributeData($data); - return $this->returnResult('catalog/*/', [], ['error' => true]); } - $data['attribute_code'] = $model->getAttributeCode(); $data['is_user_defined'] = $model->getIsUserDefined(); $data['frontend_input'] = $data['frontend_input'] ?? $model->getFrontendInput(); @@ -223,30 +200,23 @@ public function execute() $data['frontend_input'] ); } - $data += ['is_filterable' => 0, 'is_filterable_in_search' => 0]; - if ($model->getIsUserDefined() === null || $model->getIsUserDefined() != 0) { $data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']); } - $defaultValueField = $model->getDefaultValueByInput($data['frontend_input']); if ($defaultValueField) { $data['default_value'] = $this->getRequest()->getParam($defaultValueField); } - if (!$model->getIsUserDefined() && $model->getId()) { // Unset attribute field for system attributes unset($data['apply_to']); } - $model->addData($data); - if (!$attributeId) { $model->setEntityTypeId($this->_entityTypeId); $model->setIsUserDefined(1); } - $groupCode = $this->getRequest()->getParam('group'); if ($setId && $groupCode) { // For creating product attribute on product page we need specify attribute set and group @@ -256,7 +226,6 @@ public function execute() ->addFieldToFilter('attribute_group_code', $groupCode) ->setPageSize(1) ->load(); - $group = $groupCollection->getFirstItem(); if (!$group->getId()) { $group->setAttributeGroupCode($groupCode); @@ -265,15 +234,12 @@ public function execute() $group->setAttributeSetId($attributeSetId); $group->save(); } - $model->setAttributeSetId($attributeSetId); $model->setAttributeGroupId($group->getId()); } - try { $model->save(); $this->messageManager->addSuccessMessage(__('You saved the product attribute.')); - $this->_attributeLabelCache->clean(); $this->_session->setAttributeData(false); if ($this->getRequest()->getParam('popup')) { @@ -286,7 +252,6 @@ public function execute() if ($attributeSet !== null) { $requestParams['new_attribute_set_id'] = $attributeSet->getId(); } - return $this->returnResult('catalog/product/addAttribute', $requestParams, ['error' => false]); } elseif ($this->getRequest()->getParam('back', false)) { return $this->returnResult( @@ -295,12 +260,10 @@ public function execute() ['error' => false] ); } - return $this->returnResult('catalog/*/', [], ['error' => false]); } catch (\Exception $e) { $this->messageManager->addErrorMessage($e->getMessage()); $this->_session->setAttributeData($data); - return $this->returnResult( 'catalog/*/edit', ['attribute_id' => $attributeId, '_current' => true], @@ -308,10 +271,8 @@ public function execute() ); } } - return $this->returnResult('catalog/*/', [], ['error' => true]); } - /** * Extract options data from serialized options field and append to data array. * @@ -327,13 +288,12 @@ private function preprocessOptionsData(&$data) $serializedOptions = json_decode($data['serialized_options'], JSON_OBJECT_AS_ARRAY); foreach ($serializedOptions as $serializedOption) { $option = []; - parse_str($this->escapeSpecialChars($serializedOption), $option); + parse_str($serializedOption, $option); $data = array_replace_recursive($data, $option); } } unset($data['serialized_options']); } - /** * @param string $path * @param array $params @@ -345,28 +305,12 @@ private function returnResult($path = '', array $params = [], array $response = if ($this->isAjax()) { $layout = $this->layoutFactory->create(); $layout->initMessages(); - $response['messages'] = [$layout->getMessagesBlock()->getGroupedHtml()]; $response['params'] = $params; - return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($response); } - return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath($path, $params); } - - /** - * @param string $value - * @return string - */ - private function escapeSpecialChars($value) - { - $valueArray = explode("=", $value); - $valueArray[1] = isset($valueArray[1])? urlencode($valueArray[1]):''; - $finalValue = implode("=", $valueArray); - return $finalValue; - } - /** * Define whether request is Ajax *