示例#1
0
 /**
  * Attributes validation action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function executeInternal()
 {
     $response = $this->_objectManager->create('Magento\\Framework\\DataObject');
     $response->setError(false);
     $attributesData = $this->getRequest()->getParam('attributes', []);
     $data = $this->_objectManager->create('Magento\\Catalog\\Model\\Product');
     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\Exception\LocalizedException $e) {
         $response->setError(true);
         $response->setMessage($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('Something went wrong while updating the product(s) attributes.'));
         $layout = $this->layoutFactory->create();
         $layout->initMessages();
         $response->setError(true);
         $response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml());
     }
     return $this->resultJsonFactory->create()->setJsonData($response->toJson());
 }
示例#2
0
 /**
  * @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());
 }
示例#3
0
 /**
  * @return string
  */
 protected function getStatusHtml()
 {
     $layout = $this->layoutFactory->create();
     /** @var \Tobai\GeoIp2\Block\Adminhtml\System\Config\Status $statusBlock */
     $statusBlock = $layout->createBlock('Tobai\\GeoIp2\\Block\\Adminhtml\\System\\Config\\Status');
     return $statusBlock->getDbStatus();
 }
 /**
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $layout = $this->layoutFactory->create();
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultFactory->create(ResultFactory::TYPE_RAW);
     $resultRaw->setContents($layout->createBlock('Magento\\Review\\Block\\Adminhtml\\Rating\\Detailed')->setIndependentMode()->toHtml());
     return $resultRaw;
 }
示例#5
0
文件: Grid.php 项目: opexsw/magento2
 /**
  * Grid with Google Content items
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
     /** @var \Magento\GoogleShopping\Block\Adminhtml\Items\Item $block */
     $block = $this->layoutFactory->create()->createBlock('Magento\\GoogleShopping\\Block\\Adminhtml\\Items\\Item');
     return $resultRaw->setContents($block->setIndex($this->getRequest()->getParam('index'))->toHtml());
 }
示例#6
0
 /**
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function executeInternal()
 {
     $layout = $this->layoutFactory->create();
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultFactory->create(ResultFactory::TYPE_RAW);
     $resultRaw->setContents($layout->createBlock('Magento\Review\Block\Adminhtml\Grid')->toHtml());
     return $resultRaw;
 }
示例#7
0
 public function testConstructorStructure()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $structure = $objectManager->get('Magento\\Framework\\View\\Layout\\Data\\Structure');
     $structure->createElement('test.container', []);
     /** @var $layout \Magento\Framework\View\LayoutInterface */
     $layout = $this->layoutFactory->create(['structure' => $structure]);
     $this->assertTrue($layout->hasElement('test.container'));
 }
 /**
  * Prepare a layout model with pre-loaded fixture of an update XML
  *
  * @param string $fixtureFile
  * @return \Magento\Framework\View\LayoutInterface
  */
 protected function _getLayoutModel($fixtureFile)
 {
     $this->objectManager->get('Magento\\Framework\\App\\Cache\\Type\\Layout')->clean();
     $layout = $this->layoutFactory->create();
     /** @var $xml \Magento\Framework\View\Layout\Element */
     $xml = simplexml_load_file(__DIR__ . "/_files/layout_directives_test/{$fixtureFile}", 'Magento\\Framework\\View\\Layout\\Element');
     $layout->loadString($xml->asXml());
     $layout->generateElements();
     return $layout;
 }
示例#9
0
 /**
  * Get specified tab grid
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Products'));
     $this->productBuilder->build($this->getRequest());
     $block = $this->getRequest()->getParam('gridOnlyBlock');
     $blockClassSuffix = str_replace(' ', '_', ucwords(str_replace('_', ' ', $block)));
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Product\\Edit\\Tab\\' . $blockClassSuffix)->toHtml());
 }
示例#10
0
 /**
  * WYSIWYG editor action for ajax request
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $elementId = $this->getRequest()->getParam('element_id', md5(microtime()));
     $storeId = $this->getRequest()->getParam('store_id', 0);
     $storeMediaUrl = $this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore($storeId)->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
     $content = $this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Helper\\Form\\Wysiwyg\\Content', '', ['data' => ['editor_element_id' => $elementId, 'store_id' => $storeId, 'store_media_url' => $storeMediaUrl]]);
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($content->toHtml());
 }
 /**
  * Generate order history for ajax request
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $this->_initOrder();
     $layout = $this->layoutFactory->create();
     $html = $layout->createBlock('Magento\\Sales\\Block\\Adminhtml\\Order\\View\\Tab\\History')->toHtml();
     $this->_translateInline->processResponseBody($html);
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     $resultRaw->setContents($html);
     return $resultRaw;
 }
示例#12
0
 /**
  * Chooser Source action
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $uniqId = $this->getRequest()->getParam('uniq_id');
     /** @var \Magento\Framework\View\Layout $layout */
     $layout = $this->layoutFactory->create();
     $pagesGrid = $layout->createBlock('Magento\\Cms\\Block\\Adminhtml\\Page\\Widget\\Chooser', '', ['data' => ['id' => $uniqId]]);
     $html = $pagesGrid->toHtml();
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($html);
 }
示例#13
0
 /**
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $output = '';
     $blockTab = $this->getRequest()->getParam('block');
     $blockClassSuffix = str_replace(' ', '\\', ucwords(str_replace('_', ' ', $blockTab)));
     if (in_array($blockTab, ['tab_orders', 'tab_amounts', 'totals'])) {
         $output = $this->layoutFactory->create()->createBlock('Magento\\Backend\\Block\\Dashboard\\' . $blockClassSuffix)->toHtml();
     }
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($output);
 }
 /**
  * Get available attribute sets
  *
  * @return \Magento\Framework\Controller\Result\Raw
  * @throws \Exception
  */
 public function execute()
 {
     try {
         /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
         $resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
         return $resultRaw->setContents($this->layoutFactory->create()->getBlockSingleton('Magento\\GoogleShopping\\Block\\Adminhtml\\Types\\Edit\\Form')->getAttributeSetsSelectElement($this->getRequest()->getParam('target_country'))->toHtml());
     } catch (\Exception $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         // just need to output text with error
         $this->messageManager->addError(__("We can't load attribute sets."));
     }
 }
示例#15
0
 /**
  * Grid Action
  * Display list of products related to current category
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $category = $this->_initCategory(true);
     if (!$category) {
         /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]);
     }
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Category\\Tab\\Product', 'category.product.grid')->toHtml());
 }
示例#16
0
 /**
  * Constructor
  *
  * @param View\Element\Template\Context $context
  * @param View\LayoutFactory $layoutFactory
  * @param View\Layout\ReaderPool $layoutReaderPool
  * @param Framework\Translate\InlineInterface $translateInline
  * @param View\Layout\BuilderFactory $layoutBuilderFactory
  * @param View\Layout\GeneratorPool $generatorPool
  * @param bool $isIsolated
  */
 public function __construct(View\Element\Template\Context $context, View\LayoutFactory $layoutFactory, View\Layout\ReaderPool $layoutReaderPool, Framework\Translate\InlineInterface $translateInline, View\Layout\BuilderFactory $layoutBuilderFactory, View\Layout\GeneratorPool $generatorPool, $isIsolated = false)
 {
     $this->layoutFactory = $layoutFactory;
     $this->layoutBuilderFactory = $layoutBuilderFactory;
     $this->layoutReaderPool = $layoutReaderPool;
     $this->eventManager = $context->getEventManager();
     $this->request = $context->getRequest();
     $this->translateInline = $translateInline;
     // TODO Shared layout object will be deleted in MAGETWO-28359
     $this->layout = $isIsolated ? $this->layoutFactory->create(['reader' => $this->layoutReaderPool, 'generatorPool' => $generatorPool]) : $context->getLayout();
     $this->layout->setGeneratorPool($generatorPool);
     $this->initLayoutBuilder();
 }
示例#17
0
 /**
  * Get Google Content attributes list
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
     try {
         $resultRaw->setContents($this->layoutFactory->create()->createBlock('Magento\\GoogleShopping\\Block\\Adminhtml\\Types\\Edit\\Attributes')->setAttributeSetId($this->getRequest()->getParam('attribute_set_id'))->setTargetCountry($this->getRequest()->getParam('target_country'))->setAttributeSetSelected(true)->toHtml());
     } catch (\Exception $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         // just need to output text with error
         $this->messageManager->addError(__('We can\'t load attributes right now.'));
     }
     return $resultRaw;
 }
示例#18
0
 /**
  * Tree json action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultJsonFactory->create();
     try {
         $this->_initAction();
         /** @var \Magento\Framework\View\Layout $layout */
         $layout = $this->layoutFactory->create();
         $resultJson->setJsonData($layout->createBlock('Magento\\Cms\\Block\\Adminhtml\\Wysiwyg\\Images\\Tree')->getTreeJson());
     } catch (\Exception $e) {
         $result = ['error' => true, 'message' => $e->getMessage()];
         $resultJson->setData($result);
     }
     return $resultJson;
 }
示例#19
0
 /**
  * Retrieve inline giftmessage edit form for specified entity
  *
  * @param string $type
  * @param \Magento\Framework\Object $entity
  * @param bool $dontDisplayContainer
  * @return string
  */
 public function getInline($type, \Magento\Framework\Object $entity, $dontDisplayContainer = false)
 {
     if (!$this->skipPage($type) && !$this->isMessagesAvailable($type, $entity)) {
         return '';
     }
     return $this->_layoutFactory->create()->createBlock('Magento\\GiftMessage\\Block\\Message\\Inline')->setId('giftmessage_form_' . $this->_nextId++)->setDontDisplayContainer($dontDisplayContainer)->setEntity($entity)->setType($type)->toHtml();
 }
示例#20
0
 protected function initEmptyLayout()
 {
     if (!is_null($this->emptyLayout)) {
         return;
     }
     $this->emptyLayout = $this->layoutFactory->create();
 }
示例#21
0
 /**
  * Retrieve layout html directive callback
  *
  * @return string
  */
 public function emulateAreaCallback()
 {
     $skipParams = ['handle', 'area'];
     /** @var $layout \Magento\Framework\View\LayoutInterface */
     $layout = $this->_layoutFactory->create(['cacheable' => false]);
     $layout->getUpdate()->addHandle($this->_directiveParams['handle'])->load();
     $layout->generateXml();
     $layout->generateElements();
     $rootBlock = false;
     foreach ($layout->getAllBlocks() as $block) {
         /* @var $block \Magento\Framework\View\Element\AbstractBlock */
         if (!$block->getParentBlock() && !$rootBlock) {
             $rootBlock = $block;
         }
         foreach ($this->_directiveParams as $k => $v) {
             if (in_array($k, $skipParams)) {
                 continue;
             }
             $block->setDataUsingMethod($k, $v);
         }
     }
     /**
      * Add root block to output
      */
     if ($rootBlock) {
         $layout->addOutputElement($rootBlock->getNameInLayout());
     }
     $result = $layout->getOutput();
     $layout->__destruct();
     // To overcome bug with SimpleXML memory leak (https://bugs.php.net/bug.php?id=62468)
     return $result;
 }
示例#22
0
 /**
  * Chooser Source action
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function executeInternal()
 {
     $uniqId = $this->getRequest()->getParam('uniq_id');
     $massAction = $this->getRequest()->getParam('use_massaction', false);
     $productTypeId = $this->getRequest()->getParam('product_type_id', null);
     $layout = $this->layoutFactory->create();
     $productsGrid = $layout->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Product\\Widget\\Chooser', '', ['data' => ['id' => $uniqId, 'use_massaction' => $massAction, 'product_type_id' => $productTypeId, 'category_id' => $this->getRequest()->getParam('category_id')]]);
     $html = $productsGrid->toHtml();
     if (!$this->getRequest()->getParam('products_grid')) {
         $categoriesTree = $layout->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Category\\Widget\\Chooser', '', ['data' => ['id' => $uniqId . 'Tree', 'node_click_listener' => $productsGrid->getCategoryClickListenerJs(), 'with_empty_node' => true]]);
         $html = $layout->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Product\\Widget\\Chooser\\Container')->setTreeHtml($categoriesTree->toHtml())->setGridHtml($html)->toHtml();
     }
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     return $resultRaw->setContents($html);
 }
示例#23
0
 /**
  * Get progress html checkout step
  *
  * @param string $checkoutStep
  * @return mixed
  */
 protected function getProgressHtml($checkoutStep = '')
 {
     $layout = $this->layoutFactory->create();
     $layout->getUpdate()->load(['checkout_onepage_progress']);
     $layout->generateXml();
     $layout->generateElements();
     $block = $layout->getBlock('progress')->setAttribute('next_step', $checkoutStep);
     return $block->toHtml();
 }
示例#24
0
 /**
  * Construct
  *
  * @param \Magento\Framework\App\Helper\Context $context
  * @param LayoutFactory $layoutFactory
  * @param \Magento\Payment\Model\Method\Factory $paymentMethodFactory
  * @param \Magento\Store\Model\App\Emulation $appEmulation
  * @param \Magento\Payment\Model\Config $paymentConfig
  * @param \Magento\Framework\App\Config\Initial $initialConfig
  */
 public function __construct(\Magento\Framework\App\Helper\Context $context, LayoutFactory $layoutFactory, \Magento\Payment\Model\Method\Factory $paymentMethodFactory, \Magento\Store\Model\App\Emulation $appEmulation, \Magento\Payment\Model\Config $paymentConfig, \Magento\Framework\App\Config\Initial $initialConfig)
 {
     parent::__construct($context);
     $this->_layout = $layoutFactory->create();
     $this->_methodFactory = $paymentMethodFactory;
     $this->_appEmulation = $appEmulation;
     $this->_paymentConfig = $paymentConfig;
     $this->_initialConfig = $initialConfig;
 }
示例#25
0
 /**
  * Render HTML based on requested layout handle name
  *
  * @param string $handle
  * @return string
  */
 protected function _getHtmlByHandle($handle)
 {
     $layout = $this->layoutFactory->create();
     $layout->getUpdate()->load([$handle]);
     $layout->generateXml();
     $layout->generateElements();
     $output = $layout->getOutput();
     $this->_translateInline->processResponseBody($output);
     return $output;
 }
示例#26
0
 /**
  * @param string $path
  * @param array $params
  * @param array $response
  * @return \Magento\Framework\Controller\Result\Json|\Magento\Backend\Model\View\Result\Redirect
  */
 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);
 }
示例#27
0
 /**
  * Validate product
  *
  * @return \Magento\Framework\Controller\Result\Json
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute()
 {
     $response = new \Magento\Framework\DataObject();
     $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;
         }
         $storeId = $this->getRequest()->getParam('store', 0);
         $store = $this->getStoreManager()->getStore($storeId);
         $this->getStoreManager()->setCurrentStore($store->getCode());
         /* @var $product \Magento\Catalog\Model\Product */
         $product = $this->productFactory->create();
         $product->setData('_edit_mode', true);
         if ($storeId) {
             $product->setStoreId($storeId);
         }
         $setId = $this->getRequest()->getPost('set') ?: $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);
         }
         $product = $this->getInitializationHelper()->initializeFromData($product, $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->setMessages([$e->getMessage()]);
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $response->setError(true);
         $response->setMessages([$e->getMessage()]);
     } catch (\Exception $e) {
         $this->messageManager->addError($e->getMessage());
         $layout = $this->layoutFactory->create();
         $layout->initMessages();
         $response->setError(true);
         $response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml());
     }
     return $this->resultJsonFactory->create()->setData($response);
 }
 /**
  * Get tree node (Ajax version)
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     if ($this->getRequest()->getParam('expand_all')) {
         $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session')->setIsTreeWasExpanded(true);
     } else {
         $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session')->setIsTreeWasExpanded(false);
     }
     $categoryId = (int) $this->getRequest()->getPost('id');
     if ($categoryId) {
         $this->getRequest()->setParam('id', $categoryId);
         $category = $this->_initCategory();
         if (!$category) {
             /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
             $resultRedirect = $this->resultRedirectFactory->create();
             return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]);
         }
         /** @var \Magento\Framework\Controller\Result\Json $resultJson */
         $resultJson = $this->resultJsonFactory->create();
         return $resultJson->setJsonData($this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Category\\Tree')->getTreeJson($category));
     }
 }
示例#29
0
 /**
  * Tree Action
  * Retrieve category tree
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $storeId = (int) $this->getRequest()->getParam('store');
     $categoryId = (int) $this->getRequest()->getParam('id');
     if ($storeId) {
         if (!$categoryId) {
             $store = $this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore($storeId);
             $rootId = $store->getRootCategoryId();
             $this->getRequest()->setParam('id', $rootId);
         }
     }
     $category = $this->_initCategory(true);
     if (!$category) {
         /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]);
     }
     $block = $this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Category\\Tree');
     $root = $block->getRoot();
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultJsonFactory->create();
     return $resultJson->setData(['data' => $block->getTree(), 'parameters' => ['text' => $block->buildNodeName($root), 'draggable' => false, 'allowDrop' => (bool) $root->getIsVisible(), 'id' => (int) $root->getId(), 'expanded' => (int) $block->getIsWasExpanded(), 'store_id' => (int) $block->getStore()->getId(), 'category_id' => (int) $category->getId(), 'root_visible' => (int) $root->getIsVisible()]]);
 }
示例#30
0
 /**
  * run the action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $data = $this->getRequest()->getPost('category');
     $resultRedirect = $this->resultRedirectFactory->create();
     if ($data) {
         $category = $this->initCategory();
         if (!$category) {
             return $resultRedirect->setPath('mageplaza_blog/*/', ['_current' => true, 'id' => null]);
         }
         $category->addData($data);
         if ($posts = $this->getRequest()->getPost('category_posts')) {
             $posts = json_decode($posts, true);
             $category->setPostsData($posts);
         }
         $refreshTree = false;
         if (!$category->getId()) {
             $parentId = $this->getRequest()->getParam('parent');
             if (!$parentId) {
                 $parentId = \Mageplaza\Blog\Model\Category::TREE_ROOT_ID;
             }
             $parentCategory = $this->categoryFactory->create()->load($parentId);
             $category->setPath($parentCategory->getPath());
             $category->setParentId($parentId);
         }
         $this->_eventManager->dispatch('mageplaza_blog_category_prepare_save', ['category' => $category, 'request' => $this->getRequest()]);
         try {
             $category->save();
             $this->messageManager->addSuccess(__('You saved the Category.'));
             $refreshTree = true;
         } catch (\Exception $e) {
             $this->messageManager->addError($e->getMessage());
             $this->_getSession()->setMageplazaBlogCategoryData($data);
             $refreshTree = false;
         }
         if ($this->getRequest()->getPost('return_session_messages_only')) {
             $category->load($category->getId());
             // to obtain truncated Category Name
             /** @var $block \Magento\Framework\View\Element\Messages */
             $block = $this->layoutFactory->create()->getMessagesBlock();
             $block->setMessages($this->messageManager->getMessages(true));
             /** @var \Magento\Framework\Controller\Result\Json $resultJson */
             $resultJson = $this->resultJsonFactory->create();
             return $resultJson->setData(['messages' => $block->getGroupedHtml(), 'error' => !$refreshTree, 'category' => $category->toArray()]);
         }
         $redirectParams = ['_current' => true, 'category_id' => $category->getId()];
         return $resultRedirect->setPath('mageplaza_blog/*/edit', $redirectParams);
     }
     $redirectParams = ['_current' => true];
     return $resultRedirect->setPath('mageplaza_blog/*/edit', $redirectParams);
 }