Ejemplo n.º 1
0
 /**
  * @return \Magento\Backend\Block\Widget\Grid
  */
 protected function _prepareCollection()
 {
     $website = $this->getRequest()->getParam('website');
     $group = $this->getRequest()->getParam('group');
     $store = $this->getRequest()->getParam('store');
     if ($website) {
         $storeIds = $this->_storeManager->getWebsite($website)->getStoreIds();
         $storeId = array_pop($storeIds);
     } else {
         if ($group) {
             $storeIds = $this->_storeManager->getGroup($group)->getStoreIds();
             $storeId = array_pop($storeIds);
         } else {
             if ($store) {
                 $storeId = (int) $store;
             } else {
                 $storeId = '';
             }
         }
     }
     /** @var $collection \Magento\Reports\Model\Resource\Product\Lowstock\Collection  */
     $collection = $this->_lowstocksFactory->create()->addAttributeToSelect('*')->setStoreId($storeId)->filterByIsQtyProductTypes()->joinInventoryItem('qty')->useManageStockFilter($storeId)->useNotifyStockQtyFilter($storeId)->setOrder('qty', \Magento\Framework\Data\Collection::SORT_ORDER_ASC);
     if ($storeId) {
         $collection->addStoreFilter($storeId);
     }
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
Ejemplo n.º 2
0
 /**
  * Prepare collection for grid
  *
  * @return \Magento\Backend\Block\Widget\Grid
  */
 protected function _prepareCollection()
 {
     if ($this->getRequest()->getParam('queue', false)) {
         $this->getCollection()->useQueue($this->_queueFactory->create()->load($this->getRequest()->getParam('queue')));
     }
     return parent::_prepareCollection();
 }
Ejemplo n.º 3
0
 /**
  * Retrieve count totals
  *
  * @param \Magento\Backend\Block\Widget\Grid $grid
  * @param string $from
  * @param string $to
  * @return \Magento\Framework\Object
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function countTotals($grid, $from, $to)
 {
     $columns = [];
     foreach ($grid->getColumns() as $col) {
         $columns[$col->getIndex()] = ["total" => $col->getTotal(), "value" => 0];
     }
     $count = 0;
     /**
      * This method doesn't work because of commit 6e15235, see MAGETWO-4751
      */
     $report = $grid->getCollection()->getReportFull($from, $to);
     foreach ($report as $item) {
         if ($grid->getSubReportSize() && $count >= $grid->getSubReportSize()) {
             continue;
         }
         $data = $item->getData();
         foreach ($columns as $field => $a) {
             if ($field !== '') {
                 $columns[$field]['value'] = $columns[$field]['value'] + (isset($data[$field]) ? $data[$field] : 0);
             }
         }
         $count++;
     }
     $data = [];
     foreach ($columns as $field => $a) {
         if ($a['total'] == 'avg') {
             if ($field !== '') {
                 if ($count != 0) {
                     $data[$field] = $a['value'] / $count;
                 } else {
                     $data[$field] = 0;
                 }
             }
         } elseif ($a['total'] == 'sum') {
             if ($field !== '') {
                 $data[$field] = $a['value'];
             }
         } elseif (strpos($a['total'], '/') !== false) {
             if ($field !== '') {
                 $data[$field] = 0;
             }
         }
     }
     $totals = new \Magento\Framework\Object();
     $totals->setData($data);
     return $totals;
 }
Ejemplo n.º 4
0
 protected function _prepareCollection()
 {
     if ($this->getCollection()) {
         foreach ($this->getDefaultFilter() as $field => $value) {
             $this->getCollection()->addFieldToFilter($field, $value);
         }
     }
     return parent::_prepareCollection();
 }
Ejemplo n.º 5
0
 /**
  * @return Grid
  */
 protected function _prepareCollection()
 {
     if ($this->getCategory()->getId()) {
         $this->setDefaultFilter(['in_category' => 1]);
     }
     $collection = $this->_productFactory->create()->getCollection()->addAttributeToSelect('name')->addAttributeToSelect('image')->addAttributeToSelect('sku')->addAttributeToSelect('price')->addStoreFilter($this->getRequest()->getParam('store'))->joinField('position', 'catalog_category_product', 'position', 'product_id=entity_id', 'category_id=' . (int) $this->getRequest()->getParam('id', 0), 'left');
     $this->setCollection($collection);
     if ($this->getCategory()->getProductsReadonly()) {
         $productIds = $this->_getSelectedProducts();
         if (empty($productIds)) {
             $productIds = 0;
         }
         $this->getCollection()->addFieldToFilter('entity_id', ['in' => $productIds]);
     }
     return \Magento\Backend\Block\Widget\Grid::_prepareCollection();
 }
Ejemplo n.º 6
0
 /**
  * Return row url for js event handlers
  *
  * @param \Magento\Catalog\Model\Product|\Magento\Framework\Object $item
  * @return string
  */
 public function getRowUrl($item)
 {
     $res = parent::getRowUrl($item);
     return $res ? $res : '#';
 }
Ejemplo n.º 7
0
 /**
  * Prepare collection for grid
  *
  * @return $this
  */
 protected function _prepareCollection()
 {
     $customerId = $this->_coreRegistry->registry('current_customer_id');
     if (!$customerId) {
         $customerId = $this->_coreRegistry->registry('current_customer')->getId();
     }
     $collection = $this->_agreementFactory->create()->addFieldToFilter('customer_id', $customerId)->setOrder('created_at');
     $this->setCollection($collection);
     return \Magento\Backend\Block\Widget\Grid::_prepareCollection();
 }
Ejemplo n.º 8
0
 /**
  * Prepare collection for grid
  *
  * @return $this
  */
 protected function _prepareCollection()
 {
     $customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
     $collection = $this->_agreementFactory->create()->addFieldToFilter('customer_id', $customerId)->setOrder('created_at');
     $this->setCollection($collection);
     return \Magento\Backend\Block\Widget\Grid::_prepareCollection();
 }
Ejemplo n.º 9
0
 /**
  * Append custom filter for Store Id
  *
  * @SuppressWarnings(PHPMD.CamelCaseMethodName)
  */
 protected function _preparePage()
 {
     parent::_preparePage();
     $this->getColumnSet()->getChildBlock('store_id')->setFilterConditionCallback([$this, 'filterStoreCondition']);
     $this->getColumnSet()->getChildBlock('thesaurus_terms_summary')->setFilterConditionCallback([$this, 'filterTermsCondition']);
 }