Пример #1
0
 /**
  * Prepare group specific fieldset
  *
  * @param \Magento\Framework\Data\Form $form
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareStoreFieldset(\Magento\Framework\Data\Form $form)
 {
     $groupModel = $this->_coreRegistry->registry('store_data');
     $postData = $this->_coreRegistry->registry('store_post_data');
     if ($postData) {
         $groupModel->setData($postData['group']);
     }
     $fieldset = $form->addFieldset('group_fieldset', ['legend' => __('Store Information')]);
     $storeAction = $this->_coreRegistry->registry('store_action');
     if ($storeAction == 'edit' || $storeAction == 'add') {
         $websites = $this->_websiteFactory->create()->getCollection()->toOptionArray();
         $fieldset->addField('group_website_id', 'select', ['name' => 'group[website_id]', 'label' => __('Web Site'), 'value' => $groupModel->getWebsiteId(), 'values' => $websites, 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
         if ($groupModel->getId() && $groupModel->getWebsite()->getDefaultGroupId() == $groupModel->getId()) {
             if ($groupModel->getWebsite()->getIsDefault() || $groupModel->getWebsite()->getGroupsCount() == 1) {
                 $form->getElement('group_website_id')->setDisabled(true);
                 $fieldset->addField('group_hidden_website_id', 'hidden', ['name' => 'group[website_id]', 'no_span' => true, 'value' => $groupModel->getWebsiteId()]);
             } else {
                 $fieldset->addField('group_original_website_id', 'hidden', ['name' => 'group[original_website_id]', 'no_span' => true, 'value' => $groupModel->getWebsiteId()]);
             }
         }
     }
     $fieldset->addField('group_name', 'text', ['name' => 'group[name]', 'label' => __('Name'), 'value' => $groupModel->getName(), 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
     $categories = $this->_category->toOptionArray();
     $fieldset->addField('group_root_category_id', 'select', ['name' => 'group[root_category_id]', 'label' => __('Root Category'), 'value' => $groupModel->getRootCategoryId(), 'values' => $categories, 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
     if ($this->_coreRegistry->registry('store_action') == 'edit') {
         $storeActive = 1;
         $stores = $this->_storeFactory->create()->getCollection()->addGroupFilter($groupModel->getId())->addStatusFilter($storeActive)->toOptionArray();
         $fieldset->addField('group_default_store_id', 'select', ['name' => 'group[default_store_id]', 'label' => __('Default Store View'), 'value' => $groupModel->getDefaultStoreId(), 'values' => $stores, 'required' => false, 'disabled' => $groupModel->isReadOnly()]);
     }
     $fieldset->addField('group_group_id', 'hidden', ['name' => 'group[group_id]', 'no_span' => true, 'value' => $groupModel->getId()]);
 }
Пример #2
0
 public function testToOptionArray()
 {
     $expect = [['label' => __('-- Please Select a Category --'), 'value' => ''], ['label' => 'name', 'value' => 3]];
     $this->categoryCollection->expects($this->once())->method('addAttributeToSelect')->with($this->equalTo('name'))->will($this->returnValue($this->categoryCollection));
     $this->categoryCollection->expects($this->once())->method('addRootLevelFilter')->will($this->returnValue($this->categoryCollection));
     $this->categoryCollection->expects($this->once())->method('load');
     $this->categoryCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->category])));
     $this->category->expects($this->once())->method('getName')->will($this->returnValue('name'));
     $this->category->expects($this->once())->method('getId')->will($this->returnValue(3));
     $this->assertEquals($expect, $this->model->toOptionArray());
 }