示例#1
0
 /**
  * Get options
  *
  * @return array
  */
 public function toOptionArray()
 {
     if ($this->options === null) {
         $this->options = $this->collectionFactory->create()->toOptionArray();
     }
     return $this->options;
 }
示例#2
0
 /**
  * Render elemnt
  *
  * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  * @return string
  */
 public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
 {
     $html = '';
     $statuses = $this->_orderStatusCollection->create()->load()->toOptionHash();
     foreach ($statuses as $id => $status) {
         $html .= $this->_getFieldHtml($element, $id, $status);
     }
     return $html;
 }
示例#3
0
 public function testToOptionArray()
 {
     $collectionMock = $this->getMock('Magento\\Sales\\Model\\Resource\\Order\\Status\\Collection', [], [], '', false);
     $options = ['options'];
     $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock);
     $collectionMock->expects($this->once())->method('toOptionArray')->willReturn($options);
     $this->assertEquals($options, $this->model->toOptionArray());
     $this->assertEquals($options, $this->model->toOptionArray());
 }
示例#4
0
 public function testGetInvisibleOnFrontStatuses()
 {
     $statuses = [new \Magento\Framework\Object(['status' => 'canceled', 'is_default' => 1, 'visible_on_front' => 1]), new \Magento\Framework\Object(['status' => 'complete', 'is_default' => 1, 'visible_on_front' => 0]), new \Magento\Framework\Object(['status' => 'processing', 'is_default' => 1, 'visible_on_front' => 1]), new \Magento\Framework\Object(['status' => 'pending_payment', 'is_default' => 1, 'visible_on_front' => 0])];
     $expectedResult = ['complete', 'pending_payment'];
     $collectionMock = $this->getMock('Magento\\Sales\\Model\\Resource\\Order\\Status\\Collection', ['create', 'joinStates'], [], '', false, false);
     $this->orderStatusCollectionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($collectionMock));
     $collectionMock->expects($this->once())->method('joinStates')->will($this->returnValue($statuses));
     $result = $this->salesConfig->getInvisibleOnFrontStatuses();
     $this->assertSame($expectedResult, $result);
 }
示例#5
0
文件: Config.php 项目: aiesh/magento2
 /**
  * Retrieve statuses available for state
  * Get all possible statuses, or for specified state, or specified states array
  * Add labels by default. Return plain array of statuses, if no labels.
  *
  * @param mixed $state
  * @param bool $addLabels
  * @return array
  */
 public function getStateStatuses($state, $addLabels = true)
 {
     $key = md5(serialize(array($state, $addLabels)));
     if (isset($this->stateStatuses[$key])) {
         return $this->stateStatuses[$key];
     }
     $statuses = array();
     if (!is_array($state)) {
         $state = array($state);
     }
     foreach ($state as $_state) {
         $stateNode = $this->_getState($_state);
         if ($stateNode) {
             $collection = $this->orderStatusCollectionFactory->create()->addStateFilter($_state)->orderByLabel();
             foreach ($collection as $item) {
                 $status = $item->getData('status');
                 if ($addLabels) {
                     $statuses[$status] = $item->getStoreLabel();
                 } else {
                     $statuses[] = $status;
                 }
             }
         }
     }
     $this->stateStatuses[$key] = $statuses;
     return $statuses;
 }
示例#6
0
 /**
  * Prepare form fields
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'method' => 'post']]);
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Assignment Information')]);
     $statuses = $this->_collectionFactory->create()->toOptionArray();
     array_unshift($statuses, ['value' => '', 'label' => '']);
     $states = $this->_orderConfig->getStates();
     $states = array_merge(['' => ''], $states);
     $fieldset->addField('status', 'select', ['name' => 'status', 'label' => __('Order Status'), 'class' => 'required-entry', 'values' => $statuses, 'required' => true]);
     $fieldset->addField('state', 'select', ['name' => 'state', 'label' => __('Order State'), 'class' => 'required-entry', 'values' => $states, 'required' => true]);
     $fieldset->addField('is_default', 'checkbox', ['name' => 'is_default', 'label' => __('Use Order Status As Default'), 'value' => 1]);
     $fieldset->addField('visible_on_front', 'checkbox', ['name' => 'visible_on_front', 'label' => __('Visible On Frontend'), 'value' => 1]);
     $form->setAction($this->getUrl('sales/order_status/assignPost'));
     $form->setUseContainer(true);
     $this->setForm($form);
     return parent::_prepareForm();
 }
示例#7
0
 /**
  * Return option array
  *
  * @return array
  */
 public function toOptionArray()
 {
     $statuses = $this->_statusCollectionFactory->create()->toOptionHash();
     return $statuses;
 }
示例#8
0
文件: Status.php 项目: nja78/magento2
 /**
  * Constructor
  *
  * @param ContextInterface $context
  * @param UiComponentFactory $uiComponentFactory
  * @param CollectionFactory $collectionFactory
  * @param array $components
  * @param array $data
  */
 public function __construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, CollectionFactory $collectionFactory, array $components = [], array $data = [])
 {
     $this->statuses = $collectionFactory->create()->toOptionHash();
     parent::__construct($context, $uiComponentFactory, $components, $data);
 }