Skip to content

Commit

Permalink
Merge pull request #3291 from magento-tsg/2.2.7-develop-pr52
Browse files Browse the repository at this point in the history
[TSG] Upporting for 2.2 (pr52) (2.2.7-develop)
  • Loading branch information
Alexander Akimov authored Oct 11, 2018
2 parents 799a90d + a52b6cf commit 46b8319
Show file tree
Hide file tree
Showing 29 changed files with 921 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<element name="test" type="input" selector=".test"/>
<element name="success" type="text" selector="#messages div.message-success"/>
<element name="successMessageByIndex" type="text" selector=".message.message-success.success:nth-of-type({{n}})>div" parameterized="true"/>
<element name="error" type="text" selector="#messages div.message-error"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator;
use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Serialize\Serializer\FormData;
use Magento\Framework\Cache\FrontendInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\Result\Json;
Expand Down Expand Up @@ -68,6 +70,11 @@ class Save extends Attribute
*/
private $layoutFactory;

/**
* @var FormData
*/
private $formDataSerializer;

/**
* @param Context $context
* @param FrontendInterface $attributeLabelCache
Expand All @@ -80,6 +87,7 @@ class Save extends Attribute
* @param FilterManager $filterManager
* @param Product $productHelper
* @param LayoutFactory $layoutFactory
* @param FormData|null $formDataSerializer
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -93,7 +101,8 @@ public function __construct(
CollectionFactory $groupCollectionFactory,
FilterManager $filterManager,
Product $productHelper,
LayoutFactory $layoutFactory
LayoutFactory $layoutFactory,
FormData $formDataSerializer = null
) {
parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory);
$this->buildFactory = $buildFactory;
Expand All @@ -103,19 +112,37 @@ public function __construct(
$this->validatorFactory = $validatorFactory;
$this->groupCollectionFactory = $groupCollectionFactory;
$this->layoutFactory = $layoutFactory;
$this->formDataSerializer = $formDataSerializer ?? ObjectManager::getInstance()->get(FormData::class);
}

/**
* @return Redirect
* @inheritdoc
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function execute()
{
try {
$optionData = $this->formDataSerializer->unserialize(
$this->getRequest()->getParam('serialized_options', '[]')
);
} catch (\InvalidArgumentException $e) {
$message = __("The attribute couldn't be saved due to an error. Verify your information and try again. "
. "If the error persists, please try again later.");
$this->messageManager->addErrorMessage($message);

return $this->returnResult('catalog/*/edit', ['_current' => true], ['error' => true]);
}

$data = $this->getRequest()->getPostValue();
$data = array_replace_recursive(
$data,
$optionData
);

if ($data) {
$this->preprocessOptionsData($data);
$setId = $this->getRequest()->getParam('set');

$attributeSet = null;
Expand All @@ -124,7 +151,7 @@ public function execute()
$name = trim($name);

try {
/** @var $attributeSet Set */
/** @var Set $attributeSet */
$attributeSet = $this->buildFactory->create()
->setEntityTypeId($this->_entityTypeId)
->setSkeletonId($setId)
Expand All @@ -147,7 +174,7 @@ public function execute()

$attributeId = $this->getRequest()->getParam('attribute_id');

/** @var $model ProductAttributeInterface */
/** @var ProductAttributeInterface $model */
$model = $this->attributeFactory->create();
if ($attributeId) {
$model->load($attributeId);
Expand Down Expand Up @@ -180,7 +207,7 @@ public function execute()

//validate frontend_input
if (isset($data['frontend_input'])) {
/** @var $inputType Validator */
/** @var Validator $inputType */
$inputType = $this->validatorFactory->create();
if (!$inputType->isValid($data['frontend_input'])) {
foreach ($inputType->getMessages() as $message) {
Expand Down Expand Up @@ -313,28 +340,8 @@ public function execute()
}

/**
* Extract options data from serialized options field and append to data array.
*
* This logic is required to overcome max_input_vars php limit
* that may vary and/or be inaccessible to change on different instances.
* Provides an initialized Result object.
*
* @param array $data
* @return void
*/
private function preprocessOptionsData(&$data)
{
if (isset($data['serialized_options'])) {
$serializedOptions = json_decode($data['serialized_options'], JSON_OBJECT_AS_ARRAY);
foreach ($serializedOptions as $serializedOption) {
$option = [];
parse_str($serializedOption, $option);
$data = array_replace_recursive($data, $option);
}
}
unset($data['serialized_options']);
}

/**
* @param string $path
* @param array $params
* @param array $response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
*/
namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute;

use Magento\Framework\Serialize\Serializer\FormData;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DataObject;

/**
* Product attribute validate controller.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Validate extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute
{
const DEFAULT_MESSAGE_KEY = 'message';
Expand All @@ -27,6 +34,11 @@ class Validate extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute
*/
private $multipleAttributeList;

/**
* @var FormData
*/
private $formDataSerializer;

/**
* Constructor
*
Expand All @@ -37,6 +49,7 @@ class Validate extends \Magento\Catalog\Controller\Adminhtml\Product\Attribute
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
* @param array $multipleAttributeList
* @param FormData|null $formDataSerializer
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
Expand All @@ -45,23 +58,36 @@ public function __construct(
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Framework\View\LayoutFactory $layoutFactory,
array $multipleAttributeList = []
array $multipleAttributeList = [],
FormData $formDataSerializer = null
) {
parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory);
$this->resultJsonFactory = $resultJsonFactory;
$this->layoutFactory = $layoutFactory;
$this->multipleAttributeList = $multipleAttributeList;
$this->formDataSerializer = $formDataSerializer ?? ObjectManager::getInstance()->get(FormData::class);
}

/**
* @return \Magento\Framework\Controller\ResultInterface
* @inheritdoc
*
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function execute()
{
$response = new DataObject();
$response->setError(false);
try {
$optionsData = $this->formDataSerializer->unserialize(
$this->getRequest()->getParam('serialized_options', '[]')
);
} catch (\InvalidArgumentException $e) {
$message = __("The attribute couldn't be validated due to an error. Verify your information and try again. "
. "If the error persists, please try again later.");
$this->setMessageToResponse($response, [$message]);
$response->setError(true);
}

$attributeCode = $this->getRequest()->getParam('attribute_code');
$frontendLabel = $this->getRequest()->getParam('frontend_label');
Expand Down Expand Up @@ -101,10 +127,10 @@ public function execute()
}

$multipleOption = $this->getRequest()->getParam("frontend_input");
$multipleOption = null == $multipleOption ? 'select' : $multipleOption;
$multipleOption = (null === $multipleOption) ? 'select' : $multipleOption;

if (isset($this->multipleAttributeList[$multipleOption]) && !(null == ($multipleOption))) {
$options = $this->getRequest()->getParam($this->multipleAttributeList[$multipleOption]);
$options = $optionsData[$this->multipleAttributeList[$multipleOption]] ?? null;
$this->checkUniqueOption(
$response,
$options
Expand All @@ -122,7 +148,8 @@ public function execute()
}

/**
* Throws Exception if not unique values into options
* Throws Exception if not unique values into options.
*
* @param array $optionsValues
* @param array $deletedOptions
* @return bool
Expand Down Expand Up @@ -156,6 +183,8 @@ private function setMessageToResponse($response, $messages)
}

/**
* Performs checking the uniqueness of the attribute options.
*
* @param DataObject $response
* @param array|null $options
* @return $this
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd">
<actionGroup name="deleteProductAttribute">
<arguments>
<argument name="ProductAttribute"/>
</arguments>
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="navigateToProductAttributeGrid"/>
<waitForPageLoad stepKey="waitForAttributeGridPageLoad"/>
<fillField selector="{{AdminProductAttributeGridSection.gridFilterAttributeCode}}"
userInput="{{ProductAttribute.attribute_code}}" stepKey="setAttributeCode"/>
<click selector="{{AdminProductAttributeGridSection.search}}" stepKey="searchForAttributeFromTheGrid"/>
<click selector="{{AdminProductAttributeGridSection.firstRow}}" stepKey="clickOnAttributeRow"/>
<waitForPageLoad stepKey="waitForAttributeEditPageLoad" />
<click selector="{{AttributePropertiesSection.deleteAttribute}}" stepKey="deleteAttribute"/>
<waitForElement selector="{{AdminConfirmationModalSection.message}}" stepKey="waitForDeleteConfirmation"/>
<see selector="{{AdminConfirmationModalSection.message}}" userInput="Are you sure you want to do this?" stepKey="seeConfirmationMessage"/>
<click selector="{{AdminConfirmationModalSection.ok}}" stepKey="confirmDeleteAttribute"/>
<waitForPageLoad stepKey="waitForPageLoadAfterDeleteAttribute"/>
<see selector="{{AdminMessagesSection.success}}" userInput="You deleted the product attribute." stepKey="seeDeleteSuccessMessage"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<page name="ProductAttributePage" url="catalog/product_attribute/new/" area="admin" module="Magento_Catalog">
<section name="AttributePropertiesSection"/>
<section name="StorefrontPropertiesSection"/>
<section name="AdvancedAttributePropertiesSection"/>
</page>
</pages>
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,22 @@
<section name="AttributePropertiesSection">
<element name="AdvancedProperties" type="button" selector="#advanced_fieldset-wrapper"/>
<element name="Save" type="button" selector="#save"/>
<element name="defaultLabel" type="input" selector="#attribute_label"/>
<element name="inputType" type="select" selector="#frontend_input"/>
<element name="deleteAttribute" type="button" selector="#delete" timeout="30"/>
</section>
<section name="StorefrontPropertiesSection">
<element name="pageTitle" type="text" selector="//span[text()='Storefront Properties']" />
<element name="storeFrontPropertiesTab" selector="#product_attribute_tabs_front" type="button"/>
<element name="enableWYSIWYG" type="select" selector="#enabled"/>
<element name="useForPromoRuleConditions" type="select" selector="#is_used_for_promo_rules"/>
</section>
<section name="AdvancedAttributePropertiesSection">
<element name="advancedAttributePropertiesSectionToggle"
type="button" selector="#advanced_fieldset-wrapper"/>
<element name="attributeCode" type="text" selector="#attribute_code"/>
<element name="scope" type="select" selector="#is_global"/>
<element name="addToColumnOptions" type="select" selector="#is_used_in_grid"/>
<element name="useInFilterOptions" type="select" selector="#is_filterable_in_grid"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<element name="attributeCode" type="text" selector="//td[contains(text(),'{{var1}}')]" parameterized="true"/>
<element name="createNewAttributeBtn" type="button" selector="#add"/>
<element name="gridFilterFrontEndLabel" type="input" selector="#attributeGrid_filter_frontend_label"/>
<element name="gridFilterAttributeCode" type="input" selector="#attributeGrid_filter_attribute_code"/>
<element name="search" type="button" selector="button[data-action=grid-filter-apply]" timeout="30"/>
<element name="resetFilter" type="button" selector="button[data-action='grid-filter-reset']" timeout="30"/>
<element name="firstRow" type="button" selector="//*[@id='attributeGrid_table']/tbody/tr[1]"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<click selector="{{AdminProductAttributeGridSection.firstRow}}" stepKey="clickOnAttributeRow1"/>
<waitForPageLoad stepKey="wait2"/>
<click selector="{{AdminNewAttributePanelSection.isDefault('1')}}" stepKey="resetOptionForStatusAttribute"/>
<click selector="{{AttributePropertiesSection.save}}" stepKey="saveAttribute1"/>
<click selector="{{AttributePropertiesSection.Save}}" stepKey="saveAttribute1"/>
<waitForPageLoad stepKey="waitForSaveAttribute1"/>
<actionGroup ref="ClearCacheActionGroup" stepKey="clearCache1"/>
<actionGroup ref="logout" stepKey="logoutOfAdmin"/>
Expand All @@ -42,7 +42,7 @@
<click selector="{{AdminProductAttributeGridSection.firstRow}}" stepKey="clickOnAttributeRow"/>
<waitForPageLoad stepKey="wait2"/>
<click selector="{{AdminNewAttributePanelSection.isDefault('2')}}" stepKey="chooseDisabledOptionForStatus"/>
<click selector="{{AttributePropertiesSection.save}}" stepKey="saveAttribute"/>
<click selector="{{AttributePropertiesSection.Save}}" stepKey="saveAttribute"/>
<waitForPageLoad stepKey="waitForAttributeToSave"/>
<actionGroup ref="ClearCacheActionGroup" stepKey="clearCache"/>
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex"/>
Expand Down
Loading

0 comments on commit 46b8319

Please sign in to comment.