/** * Preparing collection. Filter canceled statuses for orders in taxes * * @return $this * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ protected function _prepareCollection() { $filterData = $this->getFilterData(); if (!$filterData->hasData('order_statuses')) { $orderConfig = $this->_configFactory->create(); $statusValues = []; $canceledStatuses = $orderConfig->getStateStatuses(\Magento\Sales\Model\Order::STATE_CANCELED); foreach ($orderConfig->getStatuses() as $code => $label) { if (!isset($canceledStatuses[$code])) { $statusValues[] = $code; } } $filterData->setOrderStatuses($statusValues); } return parent::_prepareCollection(); }
/** * Add fields to base fieldset which are general to sales reports * * @return $this */ protected function _prepareForm() { parent::_prepareForm(); $form = $this->getForm(); $htmlIdPrefix = $form->getHtmlIdPrefix(); /** @var \Magento\Framework\Data\Form\Element\Fieldset $fieldset */ $fieldset = $this->getForm()->getElement('base_fieldset'); if (is_object($fieldset) && $fieldset instanceof \Magento\Framework\Data\Form\Element\Fieldset) { $statuses = $this->_orderConfig->create()->getStatuses(); $values = []; foreach ($statuses as $code => $label) { if (false === strpos($code, 'pending')) { $values[] = ['label' => __($label), 'value' => $code]; } } $fieldset->addField('show_order_statuses', 'select', ['name' => 'show_order_statuses', 'label' => __('Order Status'), 'options' => ['0' => __('Any'), '1' => __('Specified')], 'note' => __('Applies to Any of the Specified Order Statuses except canceled orders')], 'to'); $fieldset->addField('order_statuses', 'multiselect', ['name' => 'order_statuses', 'values' => $values, 'display' => 'none'], 'show_order_statuses'); // define field dependencies if ($this->getFieldVisibility('show_order_statuses') && $this->getFieldVisibility('order_statuses')) { $this->setChild('form_after', $this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Element\\Dependence')->addFieldMap("{$htmlIdPrefix}show_order_statuses", 'show_order_statuses')->addFieldMap("{$htmlIdPrefix}order_statuses", 'order_statuses')->addFieldDependence('order_statuses', 'show_order_statuses', '1')); } } return $this; }
/** * Prepare grid columns * * TODO: fix up this mess * * @return $this */ protected function _prepareColumns() { $this->addColumn('real_order_id', array('header' => __('Order'), 'width' => '80px', 'type' => 'text', 'index' => 'increment_id')); if (!$this->_storeManager->isSingleStoreMode()) { $this->addColumn('store_id', array('header' => __('Purchase Point'), 'index' => 'store_id', 'type' => 'store', 'store_view' => true, 'display_deleted' => true)); } $this->addColumn('created_at', array('header' => __('Purchased Date'), 'index' => 'created_at', 'type' => 'datetime', 'width' => '100px')); $this->addColumn('billing_name', array('header' => __('Bill-to Name'), 'index' => 'billing_name')); $this->addColumn('shipping_name', array('header' => __('Ship-to Name'), 'index' => 'shipping_name')); $this->addColumn('base_grand_total', array('header' => __('Grand Total (Base)'), 'index' => 'base_grand_total', 'type' => 'currency', 'currency' => 'base_currency_code')); $this->addColumn('grand_total', array('header' => __('Grand Total (Purchased)'), 'index' => 'grand_total', 'type' => 'currency', 'currency' => 'order_currency_code')); $this->addColumn('status', array('header' => __('Status'), 'index' => 'status', 'type' => 'options', 'width' => '70px', 'options' => $this->_orderConfig->create()->getStatuses())); if ($this->_authorization->isAllowed('Magento_Sales::actions_view')) { $this->addColumn('action', array('header' => __('Action'), 'width' => '50px', 'type' => 'action', 'getter' => 'getId', 'actions' => array(array('caption' => __('View'), 'url' => array('base' => 'sales/order/view'), 'field' => 'order_id')), 'filter' => false, 'sortable' => false, 'index' => 'stores', 'is_system' => true)); } return parent::_prepareColumns(); }