Skip to content

Commit

Permalink
add module files for branch magento 2.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
ecomteck committed Jul 29, 2019
1 parent 333bfb5 commit 07f2d77
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions Controller/Adminhtml/Order/Attribute/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
use Magento\Framework\Filter\FilterManager;
use Magento\Framework\Registry;
use Magento\Store\Model\WebsiteFactory;
use Magento\Framework\Serialize\Serializer\FormData;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\View\LayoutFactory;

Expand All @@ -54,10 +53,7 @@ class Save extends \Ecomteck\OrderCustomAttributes\Controller\Adminhtml\Order\At
* @var FilterManager
*/
protected $filterManager;
/**
* @var FormData
*/
private $formDataSerializer;

/**
* @var LayoutFactory
*/
Expand All @@ -74,7 +70,6 @@ class Save extends \Ecomteck\OrderCustomAttributes\Controller\Adminhtml\Order\At
* @param HelperOrder $helperOrder
* @param FilterManager $filterManager
* @param LayoutFactory $layoutFactory
* @param FormData|null $formDataSerializer
*/
public function __construct(
Context $context,
Expand All @@ -86,8 +81,7 @@ public function __construct(
HelperData $helperData,
HelperOrder $helperOrder,
FilterManager $filterManager,
LayoutFactory $layoutFactory,
FormData $formDataSerializer = null
LayoutFactory $layoutFactory
) {
$this->helperData = $helperData;
$this->helperOrder = $helperOrder;
Expand All @@ -101,7 +95,6 @@ public function __construct(
$websiteFactory
);
$this->layoutFactory = $layoutFactory;
$this->formDataSerializer = $formDataSerializer ?? ObjectManager::getInstance()->get(FormData::class);
}

/**
Expand All @@ -114,26 +107,12 @@ public function __construct(
*/
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('adminhtml/*/edit', ['_current' => true], ['error' => true]);
}
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);

$data = $this->getRequest()->getPostValue();
$data = array_replace_recursive(
$data,
$optionData
);
if ($this->getRequest()->isPost() && $data) {
$this->preprocessOptionsData($data);
/* @var $attributeObject \Ecomteck\OrderCustomAttributes\Model\Sales\Order\Attribute */
$attributeObject = $this->_initAttribute();

Expand Down Expand Up @@ -270,6 +249,27 @@ public function execute()
$resultRedirect->setPath('adminhtml/*/');
return $resultRedirect;
}
/**
* 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.
*
* @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']);
}
/**
* Provides an initialized Result object.
*
Expand Down

0 comments on commit 07f2d77

Please sign in to comment.