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

Commit

Permalink
Merge branch '2.3.0-release' of github.com:magento/magento2ce into MC…
Browse files Browse the repository at this point in the history
…-4277
  • Loading branch information
omiroshnichenko committed Oct 4, 2018
2 parents 3ad4214 + 32219a9 commit 8e5d2a0
Show file tree
Hide file tree
Showing 53 changed files with 1,835 additions and 4,261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Catalog\Controller\Adminhtml\Product\Attribute;
use Magento\Catalog\Helper\Product;
use Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation;
use Magento\Framework\Serialize\Serializer\FormData;
use Magento\Catalog\Model\Product\AttributeSet\BuildFactory;
use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory;
use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator;
Expand All @@ -32,6 +33,8 @@
use Magento\Framework\View\Result\PageFactory;

/**
* Product attribute save controller.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Save extends Attribute implements HttpPostActionInterface
Expand Down Expand Up @@ -76,6 +79,11 @@ class Save extends Attribute implements HttpPostActionInterface
*/
private $presentation;

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

/**
* @param Context $context
* @param FrontendInterface $attributeLabelCache
Expand All @@ -89,6 +97,7 @@ class Save extends Attribute implements HttpPostActionInterface
* @param Product $productHelper
* @param LayoutFactory $layoutFactory
* @param Presentation|null $presentation
* @param FormData|null $formDataSerializer
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -103,7 +112,8 @@ public function __construct(
FilterManager $filterManager,
Product $productHelper,
LayoutFactory $layoutFactory,
Presentation $presentation = null
Presentation $presentation = null,
FormData $formDataSerializer = null
) {
parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory);
$this->buildFactory = $buildFactory;
Expand All @@ -114,19 +124,38 @@ public function __construct(
$this->groupCollectionFactory = $groupCollectionFactory;
$this->layoutFactory = $layoutFactory;
$this->presentation = $presentation ?: ObjectManager::getInstance()->get(Presentation::class);
$this->formDataSerializer = $formDataSerializer
?: ObjectManager::getInstance()->get(FormData::class);
}

/**
* @inheritdoc
*
* @return Redirect
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @throws \Zend_Validate_Exception
*/
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 @@ -135,7 +164,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 @@ -157,7 +186,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 @@ -189,7 +218,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 @@ -317,28 +346,8 @@ public function execute()
}

/**
* Extract options data from serialized options field and append to data array.
* Provides an initialized Result object.
*
* This logic is required to overcome max_input_vars php limit
* that may vary and/or be inaccessible to change on different instances.
*
* @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 @@ -7,11 +7,18 @@

namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute;

use Magento\Framework\Serialize\Serializer\FormData;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DataObject;
use Magento\Catalog\Controller\Adminhtml\Product\Attribute as AttributeAction;

/**
* Product attribute validate controller.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Validate extends AttributeAction implements HttpGetActionInterface, HttpPostActionInterface
{
const DEFAULT_MESSAGE_KEY = 'message';
Expand All @@ -31,6 +38,11 @@ class Validate extends AttributeAction implements HttpGetActionInterface, HttpPo
*/
private $multipleAttributeList;

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

/**
* Constructor
*
Expand All @@ -41,6 +53,7 @@ class Validate extends AttributeAction implements HttpGetActionInterface, HttpPo
* @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 @@ -49,15 +62,20 @@ 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);
}

/**
* @inheritdoc
*
* @return \Magento\Framework\Controller\ResultInterface
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
Expand All @@ -66,6 +84,15 @@ 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 @@ -105,10 +132,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]);
if (isset($this->multipleAttributeList[$multipleOption])) {
$options = $optionsData[$this->multipleAttributeList[$multipleOption]] ?? null;
$this->checkUniqueOption(
$response,
$options
Expand All @@ -126,7 +153,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 @@ -160,6 +188,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
Expand Up @@ -14,7 +14,10 @@
</arguments>
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="navigateToProductAttributeGrid"/>
<waitForPageLoad stepKey="waitForPageLoad1"/>
<click selector="{{AdminProductAttributeGridSection.AttributeCode(ProductAttribute.attribute_code)}}" stepKey="navigateToAttributeEditPage1" />
<fillField selector="{{AdminProductAttributeGridSection.FilterByAttributeCode}}"
userInput="{{ProductAttribute.attribute_code}}" stepKey="setAttributeCode"/>
<click selector="{{AdminProductAttributeGridSection.Search}}" stepKey="searchForAttributeFromTheGrid"/>
<click selector="{{AdminProductAttributeGridSection.FirstRow}}" stepKey="clickOnAttributeRow"/>
<waitForPageLoad stepKey="waitForPageLoad2" />
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
<element name="DefaultValue" type="input" selector="#default_value_text"/>
<element name="Scope" type="select" selector="#is_global"/>
<element name="Save" type="button" selector="#save" timeout="30"/>
<element name="DeleteAttribute" type="button" selector="#delete" timeout="30"/>
<element name="SaveAndEdit" type="button" selector="#save_and_edit_button" timeout="30"/>
<element name="TinyMCE4" type="button" selector="//span[text()='Default Value']/parent::label/following-sibling::div//div[@class='mce-branding-powered-by']"/>
<element name="checkIfTabOpen" selector="//div[@id='advanced_fieldset-wrapper' and not(contains(@class,'opened'))]" type="button"/>
<element name="useInLayeredNavigation" type="select" selector="#is_filterable"/>
</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"/>
Expand Down Expand Up @@ -63,4 +65,12 @@
<element name="SpecialCharacter" type="button" selector=".mce-i-charmap" />
<element name="TextArea" type="input" selector="#default_value_textarea" />
</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 @@ -26,10 +26,9 @@
<requiredEntity createDataKey="myProductAttributeCreation"/>
</createData>
</before>
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="navigateToProductAttributeGrid1"/>
<waitForPageLoad stepKey="waitForPageLoad1"/>
<click selector="{{AdminProductAttributeGridSection.AttributeCode($$myProductAttributeCreation.attribute_code$$)}}" stepKey="navigateToAttributeEditPage1" />
<waitForPageLoad stepKey="waitForPageLoad2" />
<actionGroup ref="navigateToCreatedProductAttribute" stepKey="navigateToAttribute">
<argument name="ProductAttribute" value="productAttributeWysiwyg"/>
</actionGroup>
<seeOptionIsSelected selector="{{AttributePropertiesSection.InputType}}" userInput="Text Editor" stepKey="seeTextEditorSelected" />
<see selector="{{AttributePropertiesSection.InputType}}" userInput="Text Area" stepKey="seeTextArea1" />
<selectOption selector="{{AttributePropertiesSection.InputType}}" userInput="Text Area" stepKey="selectTextArea" />
Expand Down
Loading

0 comments on commit 8e5d2a0

Please sign in to comment.