/**
  * @covers \Magento\Catalog\Block\Adminhtml\Category\AbstractCategory::getStore
  * @covers \Magento\Catalog\Block\Adminhtml\Category\AbstractCategory::getSaveUrl
  */
 public function testGetSaveUrl()
 {
     $storeId = 23;
     $saveUrl = 'save URL';
     $params = ['_current' => false, '_query' => false, 'store' => $storeId];
     $this->requestMock->expects($this->once())->method('getParam')->with('store')->willReturn($storeId);
     $this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId)->willReturn($this->storeMock);
     $this->storeMock->expects($this->once())->method('getId')->willReturn($storeId);
     $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('catalog/*/save', $params)->willReturn($saveUrl);
     $this->assertEquals($saveUrl, $this->category->getSaveUrl());
 }
Exemple #2
0
 /**
  * @param \Magento\Backend\Block\Template\Context $context
  * @param \Magento\Catalog\Model\Resource\Category\Tree $categoryTree
  * @param \Magento\Framework\Registry $registry
  * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
  * @param \Magento\Catalog\Model\ProductFactory $productFactory
  * @param \Magento\Catalog\Model\CategoryFactory $categoryFactory
  * @param \Magento\Backend\Helper\Data $adminhtmlData
  * @param array $data
  */
 public function __construct(\Magento\Backend\Block\Template\Context $context, \Magento\Catalog\Model\Resource\Category\Tree $categoryTree, \Magento\Framework\Registry $registry, \Magento\Catalog\Model\CategoryFactory $categoryFactory, \Magento\Framework\Json\EncoderInterface $jsonEncoder, \Magento\Catalog\Model\ProductFactory $productFactory, \Magento\Backend\Helper\Data $adminhtmlData, array $data = array())
 {
     $this->_jsonEncoder = $jsonEncoder;
     $this->_categoryFactory = $categoryFactory;
     $this->_productFactory = $productFactory;
     $this->_adminhtmlData = $adminhtmlData;
     parent::__construct($context, $categoryTree, $registry, $categoryFactory, $data);
 }
Exemple #3
0
 /**
  * @return $this
  */
 protected function _prepareLayout()
 {
     $addUrl = $this->getUrl("*/*/add", ['_current' => true, 'id' => null, '_query' => false]);
     $this->addChild('add_sub_button', 'Magento\\Backend\\Block\\Widget\\Button', ['label' => __('Add Subcategory'), 'onclick' => "addNew('" . $addUrl . "', false)", 'class' => 'add', 'id' => 'add_subcategory_button', 'style' => $this->canAddSubCategory() ? '' : 'display: none;']);
     if ($this->canAddRootCategory()) {
         $this->addChild('add_root_button', 'Magento\\Backend\\Block\\Widget\\Button', ['label' => __('Add Root Category'), 'onclick' => "addNew('" . $addUrl . "', true)", 'class' => 'add', 'id' => 'add_root_category_button']);
     }
     return parent::_prepareLayout();
 }
 public function __construct(\Ess\M2ePro\Block\Adminhtml\Magento\Context\Template $blockContext, \Magento\Backend\Block\Template\Context $context, \Magento\Catalog\Model\ResourceModel\Category\Tree $categoryTree, \Magento\Framework\Registry $registry, \Magento\Catalog\Model\CategoryFactory $categoryFactory, array $data = [])
 {
     $this->helperFactory = $blockContext->getHelperFactory();
     $this->modelFactory = $blockContext->getModelFactory();
     $this->activeRecordFactory = $blockContext->getActiveRecordFactory();
     $this->parentFactory = $blockContext->getParentFactory();
     $this->css = $blockContext->getCss();
     $this->jsPhp = $blockContext->getJsPhp();
     $this->js = $blockContext->getJs();
     $this->jsTranslator = $blockContext->getJsTranslator();
     $this->jsUrl = $blockContext->getJsUrl();
     parent::__construct($context, $categoryTree, $registry, $categoryFactory, $data);
 }
Exemple #5
0
 /**
  * @return $this
  */
 protected function _prepareLayout()
 {
     $category = $this->getCategory();
     $categoryId = (int) $category->getId();
     // 0 when we create category, otherwise some value for editing category
     $this->setChild('tabs', $this->getLayout()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Category\\Tabs', 'tabs'));
     // Save button
     if (!$category->isReadonly() && $this->hasStoreRootCategory()) {
         $this->addButton('save', ['id' => 'save', 'label' => __('Save Category'), 'class' => 'save primary save-category', 'data_attribute' => ['mage-init' => ['Magento_Catalog/catalog/category/edit' => ['url' => $this->getSaveUrl(), 'ajax' => true]]]]);
     }
     // Delete button
     if ($categoryId && !in_array($categoryId, $this->getRootIds()) && $category->isDeleteable()) {
         $this->addButton('delete', ['id' => 'delete', 'label' => __('Delete Category'), 'onclick' => "categoryDelete('" . $this->getDeleteUrl() . "')", 'class' => 'delete']);
     }
     // Reset button
     if (!$category->isReadonly() && $this->hasStoreRootCategory()) {
         $resetPath = $categoryId ? 'catalog/*/edit' : 'catalog/*/add';
         $this->addButton('reset', ['id' => 'reset', 'label' => __('Reset'), 'onclick' => "categoryReset('" . $this->getUrl($resetPath, $this->getDefaultUrlParams()) . "',true)", 'class' => 'reset']);
     }
     return parent::_prepareLayout();
 }
Exemple #6
0
 /**
  * @return $this
  */
 protected function _prepareLayout()
 {
     if ($head = $this->getLayout()->getBlock('head')) {
         $head->addChild('magento-adminhtml-catalog-category-edit-js', 'Magento\\Theme\\Block\\Html\\Head\\Script', array('file' => 'Magento_Catalog::catalog/category/edit.js'));
     }
     $category = $this->getCategory();
     $categoryId = (int) $category->getId();
     // 0 when we create category, otherwise some value for editing category
     $this->setChild('tabs', $this->getLayout()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Category\\Tabs', 'tabs'));
     // Save button
     if (!$category->isReadonly() && $this->hasStoreRootCategory()) {
         $this->addButton('save', array('id' => 'save', 'label' => __('Save Category'), 'onclick' => "categorySubmit('" . $this->getSaveUrl() . "', true)", 'class' => 'save primary save-category'));
     }
     // Delete button
     if ($categoryId && !in_array($categoryId, $this->getRootIds()) && $category->isDeleteable()) {
         $this->addButton('delete', array('id' => 'delete', 'label' => __('Delete Category'), 'onclick' => "categoryDelete('" . $this->getUrl('catalog/*/delete', array('_current' => true)) . "', true, {$categoryId})", 'class' => 'delete'));
     }
     // Reset button
     if (!$category->isReadonly() && $this->hasStoreRootCategory()) {
         $resetPath = $categoryId ? 'catalog/*/edit' : 'catalog/*/add';
         $this->addButton('reset', array('id' => 'reset', 'label' => __('Reset'), 'onclick' => "categoryReset('" . $this->getUrl($resetPath, array('_current' => true)) . "',true)", 'class' => 'reset'));
     }
     return parent::_prepareLayout();
 }
 public function testGetRootIds()
 {
     $this->storeManagerMock->expects($this->once())->method('getGroups')->willReturn([$this->storeMock]);
     $this->storeMock->expects($this->once())->method('getRootCategoryId')->willReturn('storeId');
     $this->assertEquals([\Magento\Catalog\Model\Category::TREE_ROOT_ID, 'storeId'], $this->category->getRootIds());
 }