/** * Attributes validation action * * @return void */ public function execute() { $response = new \Magento\Framework\Object(); $response->setError(false); $attributesData = $this->getRequest()->getParam('attributes', array()); $data = new \Magento\Framework\Object(); try { if ($attributesData) { foreach ($attributesData as $attributeCode => $value) { $attribute = $this->_objectManager->get('Magento\\Eav\\Model\\Config')->getAttribute('catalog_product', $attributeCode); if (!$attribute->getAttributeId()) { unset($attributesData[$attributeCode]); continue; } $data->setData($attributeCode, $value); $attribute->getBackend()->validate($data); } } } catch (\Magento\Eav\Model\Entity\Attribute\Exception $e) { $response->setError(true); $response->setAttribute($e->getAttributeCode()); $response->setMessage($e->getMessage()); } catch (\Magento\Framework\Model\Exception $e) { $response->setError(true); $response->setMessage($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong while updating the product(s) attributes.')); $this->_view->getLayout()->initMessages(); $response->setError(true); $response->setHtmlMessage($this->_view->getLayout()->getMessagesBlock()->getGroupedHtml()); } $this->getResponse()->representJson($response->toJson()); }
/** * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $response = new \Magento\Framework\Object(); $response->setError(false); $attributeCode = $this->getRequest()->getParam('attribute_code'); $frontendLabel = $this->getRequest()->getParam('frontend_label'); $attributeCode = $attributeCode ?: $this->generateCode($frontendLabel[0]); $attributeId = $this->getRequest()->getParam('attribute_id'); $attribute = $this->_objectManager->create('Magento\\Catalog\\Model\\Resource\\Eav\\Attribute')->loadByCode($this->_entityTypeId, $attributeCode); if ($attribute->getId() && !$attributeId) { if (strlen($this->getRequest()->getParam('attribute_code'))) { $response->setAttributes(['attribute_code' => __('An attribute with this code already exists.')]); } else { $response->setAttributes(['attribute_label' => __('Attribute with the same code (%1) already exists.', $attributeCode)]); } $response->setError(true); } if ($this->getRequest()->has('new_attribute_set_name')) { $setName = $this->getRequest()->getParam('new_attribute_set_name'); /** @var $attributeSet \Magento\Eav\Model\Entity\Attribute\Set */ $attributeSet = $this->_objectManager->create('Magento\\Eav\\Model\\Entity\\Attribute\\Set'); $attributeSet->setEntityTypeId($this->_entityTypeId)->load($setName, 'attribute_set_name'); if ($attributeSet->getId()) { $setName = $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($setName); $this->messageManager->addError(__('Attribute Set with name \'%1\' already exists.', $setName)); $layout = $this->layoutFactory->create(); $layout->initMessages(); $response->setError(true); $response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml()); } } return $this->resultJsonFactory->create()->setJsonData($response->toJson()); }
/** * AJAX customer validation action * * @return void */ public function execute() { $response = new \Magento\Framework\Object(); $response->setError(0); $errors = null; $userId = (int) $this->getRequest()->getParam('user_id'); $data = $this->getRequest()->getPost(); try { /** @var $model \Magento\User\Model\User */ $model = $this->_userFactory->create()->load($userId); $model->setData($this->_getAdminUserData($data)); $errors = $model->validate(); } catch (\Magento\Framework\Model\Exception $exception) { /* @var $error Error */ foreach ($exception->getMessages(\Magento\Framework\Message\MessageInterface::TYPE_ERROR) as $error) { $errors[] = $error->getText(); } } if ($errors !== true && !empty($errors)) { foreach ($errors as $error) { $this->messageManager->addError($error); } $response->setError(1); $this->_view->getLayout()->initMessages(); $response->setHtmlMessage($this->_view->getLayout()->getMessagesBlock()->getGroupedHtml()); } $this->getResponse()->representJson($response->toJson()); }
/** * Create backup action * * @return void|\Magento\Backend\App\Action * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { if (!$this->getRequest()->isAjax()) { return $this->_redirect('*/*/index'); } $response = new \Magento\Framework\Object(); /** * @var \Magento\Backup\Helper\Data $helper */ $helper = $this->_objectManager->get('Magento\\Backup\\Helper\\Data'); try { $type = $this->getRequest()->getParam('type'); if ($type == \Magento\Framework\Backup\Factory::TYPE_SYSTEM_SNAPSHOT && $this->getRequest()->getParam('exclude_media')) { $type = \Magento\Framework\Backup\Factory::TYPE_SNAPSHOT_WITHOUT_MEDIA; } $backupManager = $this->_backupFactory->create($type)->setBackupExtension($helper->getExtensionByType($type))->setTime(time())->setBackupsDir($helper->getBackupsDir()); $backupManager->setName($this->getRequest()->getParam('backup_name')); $this->_coreRegistry->register('backup_manager', $backupManager); if ($this->getRequest()->getParam('maintenance_mode')) { if (!$this->maintenanceMode->set(true)) { $response->setError(__('You need more permissions to activate maintenance mode right now.') . ' ' . __('To create the backup, please deselect ' . '"Put store into maintenance mode" or update your permissions.')); $backupManager->setErrorMessage(__("Something went wrong while putting your store into maintenance mode.")); return $this->getResponse()->representJson($response->toJson()); } } if ($type != \Magento\Framework\Backup\Factory::TYPE_DB) { /** @var Filesystem $filesystem */ $filesystem = $this->_objectManager->get('Magento\\Framework\\Filesystem'); $backupManager->setRootDir($filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath())->addIgnorePaths($helper->getBackupIgnorePaths()); } $successMessage = $helper->getCreateSuccessMessageByType($type); $backupManager->create(); $this->messageManager->addSuccess($successMessage); $response->setRedirectUrl($this->getUrl('*/*/index')); } catch (\Magento\Framework\Backup\Exception\NotEnoughFreeSpace $e) { $errorMessage = __('You need more free space to create a backup.'); } catch (\Magento\Framework\Backup\Exception\NotEnoughPermissions $e) { $this->_objectManager->get('Psr\\Log\\LoggerInterface')->info($e->getMessage()); $errorMessage = __('You need more permissions to create a backup.'); } catch (\Exception $e) { $this->_objectManager->get('Psr\\Log\\LoggerInterface')->info($e->getMessage()); $errorMessage = __('We can\'t create the backup right now.'); } if (!empty($errorMessage)) { $response->setError($errorMessage); $backupManager->setErrorMessage($errorMessage); } if ($this->getRequest()->getParam('maintenance_mode')) { $this->maintenanceMode->set(false); } $this->getResponse()->representJson($response->toJson()); }
/** * @return void */ public function execute() { $response = new \Magento\Framework\Object(); $id = $this->getRequest()->getParam('id'); if (intval($id) > 0) { $product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product')->load($id); $response->setId($id); $response->addData($product->getData()); $response->setError(0); } else { $response->setError(1); $response->setMessage(__('We can\'t get the product ID.')); } $this->getResponse()->representJson($response->toJSON()); }
/** * @return void */ public function execute() { $response = new \Magento\Framework\Object(); $id = $this->getRequest()->getParam('id'); if (intval($id) > 0) { $product = $this->productRepository->getById($id); $response->setId($id); $response->addData($product->getData()); $response->setError(0); } else { $response->setError(1); $response->setMessage(__('We can\'t get the product ID.')); } $this->getResponse()->representJson($response->toJSON()); }
/** * Validate action * * @return void */ public function execute() { $response = new \Magento\Framework\Object(); $response->setError(false); $widgetInstance = $this->_initWidgetInstance(); $result = $widgetInstance->validate(); if ($result !== true && is_string($result)) { $this->messageManager->addError($result); $this->_view->getLayout()->initMessages(); $response->setError(true); $response->setHtmlMessage($this->_view->getLayout()->getMessagesBlock()->getGroupedHtml()); } $response = $response->toJson(); $this->_translateInline->processResponseBody($response); $this->_response->representJson($response); }
/** * Ajax handler to response configuration fieldset of composite product in quote items * * @return void */ public function execute() { // Prepare data $configureResult = new \Magento\Framework\Object(); try { $quoteItemId = (int) $this->getRequest()->getParam('id'); if (!$quoteItemId) { throw new \Magento\Framework\Model\Exception(__('Quote item id is not received.')); } $quoteItem = $this->_objectManager->create('Magento\\Sales\\Model\\Quote\\Item')->load($quoteItemId); if (!$quoteItem->getId()) { throw new \Magento\Framework\Model\Exception(__('Quote item is not loaded.')); } $configureResult->setOk(true); $optionCollection = $this->_objectManager->create('Magento\\Sales\\Model\\Quote\\Item\\Option')->getCollection()->addItemFilter(array($quoteItemId)); $quoteItem->setOptions($optionCollection->getOptionsByItem($quoteItem)); $configureResult->setBuyRequest($quoteItem->getBuyRequest()); $configureResult->setCurrentStoreId($quoteItem->getStoreId()); $configureResult->setProductId($quoteItem->getProductId()); $sessionQuote = $this->_objectManager->get('Magento\\Backend\\Model\\Session\\Quote'); $configureResult->setCurrentCustomerId($sessionQuote->getCustomerId()); } catch (\Exception $e) { $configureResult->setError(true); $configureResult->setMessage($e->getMessage()); } // Render page $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\Composite')->renderConfigureResult($configureResult); }
/** * Add attribute to product template * * @return \Magento\Framework\Controller\Result\Json */ public function execute() { $request = $this->getRequest(); $resultJson = $this->resultJsonFactory->create(); try { /** @var \Magento\Eav\Model\Entity\Attribute $attribute */ $attribute = $this->_objectManager->create('Magento\\Eav\\Model\\Entity\\Attribute')->load($request->getParam('attribute_id')); $attributeSet = $this->_objectManager->create('Magento\\Eav\\Model\\Entity\\Attribute\\Set')->load($request->getParam('template_id')); /** @var \Magento\Eav\Model\Resource\Entity\Attribute\Group\Collection $attributeGroupCollection */ $attributeGroupCollection = $this->_objectManager->get('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Group\\Collection'); $attributeGroupCollection->setAttributeSetFilter($attributeSet->getId()); $attributeGroupCollection->addFilter('attribute_group_code', $request->getParam('group')); $attributeGroupCollection->setPageSize(1); $attributeGroup = $attributeGroupCollection->getFirstItem(); $attribute->setAttributeSetId($attributeSet->getId())->loadEntityAttributeIdBySet(); $attribute->setAttributeSetId($request->getParam('template_id'))->setAttributeGroupId($attributeGroup->getId())->setSortOrder('0')->save(); $resultJson->setJsonData($attribute->toJson()); } catch (\Exception $e) { $response = new \Magento\Framework\Object(); $response->setError(false); $response->setMessage($e->getMessage()); $resultJson->setJsonData($response->toJson()); } return $resultJson; }
public function testRenderConfigureResultNotOK() { $configureResult = new \Magento\Framework\Object(); $configureResult->setError(true)->setMessage('Test Message'); $this->helper->renderConfigureResult($configureResult); $customerId = $this->registry->registry(RegistryConstants::CURRENT_CUSTOMER_ID); $this->assertNull($customerId); $errorMessage = $this->registry->registry('composite_configure_result_error_message'); $this->assertEquals('Test Message', $errorMessage); }
/** * Create shipping label action for specific shipment * * @return void */ public function execute() { $response = new \Magento\Framework\Object(); try { $shipment = $this->shipmentLoader->load($this->_request); if ($this->labelGenerator->create($shipment, $this->_request)) { $shipment->save(); $this->messageManager->addSuccess(__('You created the shipping label.')); $response->setOk(true); } } catch (\Magento\Framework\Model\Exception $e) { $response->setError(true); $response->setMessage($e->getMessage()); } catch (\Exception $e) { $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e); $response->setError(true); $response->setMessage(__('An error occurred while creating shipping label.')); } $this->getResponse()->representJson($response->toJson()); }
/** * Validate Action * * @return void */ public function execute() { $response = new \Magento\Framework\Object(array('error' => false)); $variable = $this->_initVariable(); $variable->addData($this->getRequest()->getPost('variable')); $result = $variable->validate(); if ($result !== true && is_string($result)) { $this->messageManager->addError($result); $this->_view->getLayout()->initMessages(); $response->setError(true); $response->setHtmlMessage($this->_view->getLayout()->getMessagesBlock()->getGroupedHtml()); } $this->getResponse()->representJson($response->toJson()); }
/** * Create shipping label action for specific shipment * * @return void */ public function execute() { $response = new \Magento\Framework\Object(); try { $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id')); $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id')); $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment')); $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking')); $shipment = $this->shipmentLoader->load(); $this->labelGenerator->create($shipment, $this->_request); $shipment->save(); $this->messageManager->addSuccess(__('You created the shipping label.')); $response->setOk(true); } catch (\Magento\Framework\Exception\LocalizedException $e) { $response->setError(true); $response->setMessage($e->getMessage()); } catch (\Exception $e) { $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e); $response->setError(true); $response->setMessage(__('An error occurred while creating shipping label.')); } $this->getResponse()->representJson($response->toJson()); }
/** * Ajax handler to response configuration fieldset of composite product in customer's wishlist. * * @return void */ public function execute() { $configureResult = new \Magento\Framework\Object(); try { $this->_initData(); $configureResult->setProductId($this->_wishlistItem->getProductId()); $configureResult->setBuyRequest($this->_wishlistItem->getBuyRequest()); $configureResult->setCurrentStoreId($this->_wishlistItem->getStoreId()); $configureResult->setCurrentCustomerId($this->_wishlist->getCustomerId()); $configureResult->setOk(true); } catch (Exception $e) { $configureResult->setError(true); $configureResult->setMessage($e->getMessage()); } $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\Composite')->renderConfigureResult($configureResult); }
/** * AJAX customer validation action * * @return \Magento\Framework\Controller\Result\Json */ public function execute() { $response = new \Magento\Framework\Object(); $response->setError(0); $customer = $this->_validateCustomer($response); if ($customer) { $this->_validateCustomerAddress($response); } $resultJson = $this->resultJsonFactory->create(); if ($response->getError()) { $layout = $this->layoutFactory->create(); $layout->initMessages(); $response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml()); } $resultJson->setData($response); return $resultJson; }
/** * Validate Action * * @return \Magento\Framework\Controller\Result\Json */ public function execute() { $response = new \Magento\Framework\Object(['error' => false]); $webhook = $this->_initWebhook(); $webhook->addData($this->getRequest()->getPost('webhook')); $result = $webhook->validate(); if ($result instanceof \Magento\Framework\Phrase) { $this->messageManager->addError($result->getText()); $layout = $this->layoutFactory->create(); $layout->initMessages(); $response->setError(true); $response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml()); } /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultJsonFactory->create(); return $resultJson->setData($response->toArray()); }
/** * IFrame handler for submitted configuration for quote item * * @return void */ public function execute() { $updateResult = new \Magento\Framework\Object(); try { $this->_initData(); $buyRequest = new \Magento\Framework\Object($this->getRequest()->getParams()); $this->_quote->updateItem($this->_quoteItem->getId(), $buyRequest); $this->_quote->collectTotals()->save(); $updateResult->setOk(true); } catch (\Exception $e) { $updateResult->setError(true); $updateResult->setMessage($e->getMessage()); } $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname')); $this->_objectManager->get('Magento\\Backend\\Model\\Session')->setCompositeProductResult($updateResult); $this->_redirect('catalog/product/showUpdateResult'); }
/** * IFrame handler for submitted configuration for wishlist item. * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { // Update wishlist item $updateResult = new \Magento\Framework\Object(); try { $this->_initData(); $buyRequest = new \Magento\Framework\Object($this->getRequest()->getParams()); $this->_wishlist->updateItem($this->_wishlistItem->getId(), $buyRequest)->save(); $updateResult->setOk(true); } catch (Exception $e) { $updateResult->setError(true); $updateResult->setMessage($e->getMessage()); } $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname')); $this->_objectManager->get('Magento\\Backend\\Model\\Session')->setCompositeProductResult($updateResult); return $this->resultRedirectFactory->create()->setPath('catalog/product/showUpdateResult'); }
/** * Validate Action * * @return \Magento\Framework\Controller\Result\JSON */ public function execute() { $response = new \Magento\Framework\Object(['error' => false]); $variable = $this->_initVariable(); $variable->addData($this->getRequest()->getPost('variable')); $result = $variable->validate(); if ($result !== true && is_string($result)) { $this->messageManager->addError($result); $layout = $this->layoutFactory->create(); $layout->initMessages(); $response->setError(true); $response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml()); } /** @var \Magento\Framework\Controller\Result\JSON $resultJson */ $resultJson = $this->resultJsonFactory->create(); return $resultJson->setData($response->toArray()); }
/** * Ajax handler to response configuration fieldset of composite product in customer's cart * * @return void */ public function execute() { $configureResult = new \Magento\Framework\Object(); try { $this->_initData(); $quoteItem = $this->_quoteItem; $optionCollection = $this->_objectManager->create('Magento\\Sales\\Model\\Quote\\Item\\Option')->getCollection()->addItemFilter($quoteItem); $quoteItem->setOptions($optionCollection->getOptionsByItem($quoteItem)); $configureResult->setOk(true); $configureResult->setProductId($quoteItem->getProductId()); $configureResult->setBuyRequest($quoteItem->getBuyRequest()); $configureResult->setCurrentStoreId($quoteItem->getStoreId()); $configureResult->setCurrentCustomerId($this->_customerId); } catch (\Exception $e) { $configureResult->setError(true); $configureResult->setMessage($e->getMessage()); } $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\Composite')->renderConfigureResult($configureResult); }
/** * Adds configured product to quote * * @return void */ public function execute() { $errorMessage = null; try { $this->_initSession()->_processData(); } catch (\Exception $e) { $this->_reloadQuote(); $errorMessage = $e->getMessage(); } // Form result for client javascript $updateResult = new \Magento\Framework\Object(); if ($errorMessage) { $updateResult->setError(true); $updateResult->setMessage($errorMessage); } else { $updateResult->setOk(true); } $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname')); $this->_objectManager->get('Magento\\Backend\\Model\\Session')->setCompositeProductResult($updateResult); $this->_redirect('catalog/product/showUpdateResult'); }
/** * AJAX customer validation action * * @return void */ public function execute() { $response = new \Magento\Framework\Object(); $response->setError(0); $customer = $this->_validateCustomer($response); if ($customer) { $this->_validateCustomerAddress($response); } if ($response->getError()) { $this->_view->getLayout()->initMessages(); $response->setHtmlMessage($this->_view->getLayout()->getMessagesBlock()->getGroupedHtml()); } $this->getResponse()->representJson($response->toJson()); }
/** * Save shipment * We can save only new shipment. Existing shipments are not editable * * @return void */ public function execute() { $data = $this->getRequest()->getParam('shipment'); if (!empty($data['comment_text'])) { $this->_objectManager->get('Magento\\Backend\\Model\\Session')->setCommentText($data['comment_text']); } try { $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id')); $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id')); $this->shipmentLoader->setShipment($data); $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking')); $shipment = $this->shipmentLoader->load(); if (!$shipment) { $this->_forward('noroute'); return; } $shipment->register(); $comment = ''; if (!empty($data['comment_text'])) { $shipment->addComment($data['comment_text'], isset($data['comment_customer_notify']), isset($data['is_visible_on_front'])); if (isset($data['comment_customer_notify'])) { $comment = $data['comment_text']; } } if (!empty($data['send_email'])) { $shipment->setEmailSent(true); } $shipment->getOrder()->setCustomerNoteNotify(!empty($data['send_email'])); $responseAjax = new \Magento\Framework\Object(); $isNeedCreateLabel = isset($data['create_shipping_label']) && $data['create_shipping_label']; if ($isNeedCreateLabel) { $this->labelGenerator->create($shipment, $this->_request); $responseAjax->setOk(true); } $this->_saveShipment($shipment); $this->shipmentSender->send($shipment, !empty($data['send_email']), $comment); $shipmentCreatedMessage = __('The shipment has been created.'); $labelCreatedMessage = __('You created the shipping label.'); $this->messageManager->addSuccess($isNeedCreateLabel ? $shipmentCreatedMessage . ' ' . $labelCreatedMessage : $shipmentCreatedMessage); $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getCommentText(true); } catch (\Magento\Framework\Model\Exception $e) { if ($isNeedCreateLabel) { $responseAjax->setError(true); $responseAjax->setMessage($e->getMessage()); } else { $this->messageManager->addError($e->getMessage()); $this->_redirect('*/*/new', array('order_id' => $this->getRequest()->getParam('order_id'))); } } catch (\Exception $e) { $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e); if ($isNeedCreateLabel) { $responseAjax->setError(true); $responseAjax->setMessage(__('An error occurred while creating shipping label.')); } else { $this->messageManager->addError(__('Cannot save shipment.')); $this->_redirect('*/*/new', array('order_id' => $this->getRequest()->getParam('order_id'))); } } if ($isNeedCreateLabel) { $this->getResponse()->representJson($responseAjax->toJson()); } else { $this->_redirect('sales/order/view', ['order_id' => $shipment->getOrderId()]); } }
/** * AJAX customer validation action * * @return \Magento\Framework\Controller\Result\Json */ public function execute() { $response = new \Magento\Framework\Object(); $response->setError(0); $customer = $this->_validateCustomer($response); if ($customer) { $this->_validateCustomerAddress($response); } $resultJson = $this->resultJsonFactory->create(); if ($response->getError()) { $response->setError(true); $response->setMessages($response->getMessages()); } $resultJson->setData($response); return $resultJson; }
/** * Rollback Action * * @return void|\Magento\Backend\App\Action * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function execute() { if (!$this->_objectManager->get('Magento\\Backup\\Helper\\Data')->isRollbackAllowed()) { $this->_forward('denied'); } if (!$this->getRequest()->isAjax()) { return $this->_redirect('*/*/index'); } $helper = $this->_objectManager->get('Magento\\Backup\\Helper\\Data'); $response = new \Magento\Framework\Object(); try { /* @var $backup \Magento\Backup\Model\Backup */ $backup = $this->_backupModelFactory->create($this->getRequest()->getParam('time'), $this->getRequest()->getParam('type')); if (!$backup->getTime() || !$backup->exists()) { return $this->_redirect('backup/*'); } if (!$backup->getTime()) { throw new \Magento\Framework\Backup\Exception\CantLoadSnapshot(); } $type = $backup->getType(); $backupManager = $this->_backupFactory->create($type)->setBackupExtension($helper->getExtensionByType($type))->setTime($backup->getTime())->setBackupsDir($helper->getBackupsDir())->setName($backup->getName(), false)->setResourceModel($this->_objectManager->create('Magento\\Backup\\Model\\Resource\\Db')); $this->_coreRegistry->register('backup_manager', $backupManager); $passwordValid = $this->_objectManager->create('Magento\\Backup\\Model\\Backup')->validateUserPassword($this->getRequest()->getParam('password')); if (!$passwordValid) { $response->setError(__('Please correct the password.')); $backupManager->setErrorMessage(__('Please correct the password.')); return $this->getResponse()->representJson($response->toJson()); } if ($this->getRequest()->getParam('maintenance_mode')) { if (!$this->maintenanceMode->set(true)) { $response->setError(__('You need more permissions to activate maintenance mode right now.') . ' ' . __('To continue with the rollback, you need to either deselect ' . '"Put store on the maintenance mode" or update your permissions.')); $backupManager->setErrorMessage(__('Something went wrong putting your store into maintenance mode.')); return $this->getResponse()->representJson($response->toJson()); } } if ($type != \Magento\Framework\Backup\Factory::TYPE_DB) { /** @var Filesystem $filesystem */ $filesystem = $this->_objectManager->get('Magento\\Framework\\Filesystem'); $backupManager->setRootDir($filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath())->addIgnorePaths($helper->getRollbackIgnorePaths()); if ($this->getRequest()->getParam('use_ftp', false)) { $backupManager->setUseFtp($this->getRequest()->getParam('ftp_host', ''), $this->getRequest()->getParam('ftp_user', ''), $this->getRequest()->getParam('ftp_pass', ''), $this->getRequest()->getParam('ftp_path', '')); } } $backupManager->rollback(); $helper->invalidateCache(); $adminSession = $this->_getSession(); $adminSession->destroy(); $response->setRedirectUrl($this->getUrl('*')); } catch (\Magento\Framework\Backup\Exception\CantLoadSnapshot $e) { $errorMsg = __('The backup file was not found.'); } catch (\Magento\Framework\Backup\Exception\FtpConnectionFailed $e) { $errorMsg = __('We couldn\'t connect to the FTP.'); } catch (\Magento\Framework\Backup\Exception\FtpValidationFailed $e) { $errorMsg = __('Failed to validate FTP'); } catch (\Magento\Framework\Backup\Exception\NotEnoughPermissions $e) { $this->_objectManager->get('Psr\\Log\\LoggerInterface')->info($e->getMessage()); $errorMsg = __('Not enough permissions to perform rollback.'); } catch (\Exception $e) { $this->_objectManager->get('Psr\\Log\\LoggerInterface')->info($e->getMessage()); $errorMsg = __('Failed to rollback'); } if (!empty($errorMsg)) { $response->setError($errorMsg); $backupManager->setErrorMessage($errorMsg); } if ($this->getRequest()->getParam('maintenance_mode')) { $this->maintenanceMode->set(false); } $this->getResponse()->representJson($response->toJson()); }
/** * Validate product * * @return void */ public function execute() { $response = new \Magento\Framework\Object(); $response->setError(false); try { $productData = $this->getRequest()->getPost('product'); if ($productData && !isset($productData['stock_data']['use_config_manage_stock'])) { $productData['stock_data']['use_config_manage_stock'] = 0; } /* @var $product \Magento\Catalog\Model\Product */ $product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product'); $product->setData('_edit_mode', true); $storeId = $this->getRequest()->getParam('store'); if ($storeId) { $product->setStoreId($storeId); } $setId = $this->getRequest()->getParam('set'); if ($setId) { $product->setAttributeSetId($setId); } $typeId = $this->getRequest()->getParam('type'); if ($typeId) { $product->setTypeId($typeId); } $productId = $this->getRequest()->getParam('id'); if ($productId) { $product->load($productId); } $dateFieldFilters = array(); $attributes = $product->getAttributes(); foreach ($attributes as $attrKey => $attribute) { if ($attribute->getBackend()->getType() == 'datetime') { if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') { $dateFieldFilters[$attrKey] = $this->_dateFilter; } } } $inputFilter = new \Zend_Filter_Input($dateFieldFilters, array(), $productData); $productData = $inputFilter->getUnescaped(); $product->addData($productData); /* set restrictions for date ranges */ $resource = $product->getResource(); $resource->getAttribute('special_from_date')->setMaxValue($product->getSpecialToDate()); $resource->getAttribute('news_from_date')->setMaxValue($product->getNewsToDate()); $resource->getAttribute('custom_design_from')->setMaxValue($product->getCustomDesignTo()); $this->productValidator->validate($product, $this->getRequest(), $response); } catch (\Magento\Eav\Model\Entity\Attribute\Exception $e) { $response->setError(true); $response->setAttribute($e->getAttributeCode()); $response->setMessage($e->getMessage()); } catch (\Magento\Framework\Model\Exception $e) { $response->setError(true); $response->setMessage($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); $this->_view->getLayout()->initMessages(); $response->setError(true); $response->setHtmlMessage($this->_view->getLayout()->getMessagesBlock()->getGroupedHtml()); } $this->getResponse()->representJson($response->toJson()); }