Esempio n. 1
0
 /**
  * Callback function that filters collection by field "Used" from grid
  *
  * @param AbstractCollection $collection
  * @param Column $column
  * @return void
  */
 public function addIsUsedFilterCallback($collection, $column)
 {
     $filterValue = $column->getFilter()->getCondition();
     $expression = $this->getConnection()->getCheckSql('main_table.times_used > 0', 1, 0);
     $conditionSql = $this->_getConditionSql($expression, $filterValue);
     $collection->getSelect()->where($conditionSql);
 }
Esempio n. 2
0
 /**
  * Unhold selected orders
  *
  * @param AbstractCollection $collection
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $countUnHoldOrder = 0;
     /** @var \Magento\Sales\Model\Order $order */
     foreach ($collection->getItems() as $order) {
         $order->load($order->getId());
         if (!$order->canUnhold()) {
             continue;
         }
         $order->unhold();
         $order->save();
         $countUnHoldOrder++;
     }
     $countNonUnHoldOrder = $collection->count() - $countUnHoldOrder;
     if ($countNonUnHoldOrder && $countUnHoldOrder) {
         $this->messageManager->addError(__('%1 order(s) were not released from on hold status.', $countNonUnHoldOrder));
     } elseif ($countNonUnHoldOrder) {
         $this->messageManager->addError(__('No order(s) were released from on hold status.'));
     }
     if ($countUnHoldOrder) {
         $this->messageManager->addSuccess(__('%1 order(s) have been released from on hold status.', $countUnHoldOrder));
     }
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath($this->getComponentRefererUrl());
     return $resultRedirect;
 }
 /**
  * Print credit memos for selected orders
  *
  * @param AbstractCollection $collection
  * @return ResponseInterface|ResultInterface
  */
 protected function massAction(AbstractCollection $collection)
 {
     $creditmemoCollection = $this->collectionFactory->create()->setOrderFilter(['in' => $collection->getAllIds()]);
     if (!$creditmemoCollection->getSize()) {
         $this->messageManager->addError(__('There are no printable documents related to selected orders.'));
         return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl());
     }
     return $this->fileFactory->create(sprintf('creditmemo%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), $this->pdfCreditmemo->getPdf($creditmemoCollection->getItems())->render(), DirectoryList::VAR_DIR, 'application/pdf');
 }
Esempio n. 4
0
 /**
  * @inheritdoc
  */
 public function fetchItem()
 {
     $item = parent::fetchItem();
     if ($item) {
         $this->entitySnapshot->registerSnapshot($item);
     }
     return $item;
 }
Esempio n. 5
0
 /**
  * @param EntityFactory $entityFactory
  * @param Logger $logger
  * @param FetchStrategy $fetchStrategy
  * @param EventManager $eventManager
  * @param string $mainTable
  * @param string $resourceModel
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function __construct(EntityFactory $entityFactory, Logger $logger, FetchStrategy $fetchStrategy, EventManager $eventManager, $mainTable, $resourceModel)
 {
     $this->_init('Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\Document', $resourceModel);
     $this->setMainTable(true);
     parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, null, null);
     $this->setMainTable($this->_resource->getTable($mainTable));
     $this->_setIdFieldName($this->getResource()->getIdFieldName());
 }
Esempio n. 6
0
 /**
  * Initialize select object
  *
  * @return $this
  */
 protected function _initSelect()
 {
     parent::_initSelect();
     $locale = $this->_localeResolver->getLocale();
     $this->addBindParam(':region_locale', $locale);
     $this->getSelect()->joinLeft(['rname' => $this->_regionNameTable], 'main_table.region_id = rname.region_id AND rname.locale = :region_locale', ['name']);
     return $this;
 }
Esempio n. 7
0
 /**
  * Process loaded collection data
  *
  * @return $this
  */
 protected function _afterLoadData()
 {
     parent::_afterLoadData();
     $this->addCustomerTaxClassesToResult();
     $this->addProductTaxClassesToResult();
     $this->addRatesToResult();
     return $this;
 }
Esempio n. 8
0
 /**
  * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  * @param \Magento\Framework\Event\ManagerInterface $eventManager
  * @param null|\Zend_Db_Adapter_Abstract $mainTable
  * @param \Magento\Framework\Model\ModelResource\Db\AbstractDb $eventPrefix
  * @param string $eventObject
  * @param string $resourceModel
  * @param string $model
  * @param string|null $connection
  * @param \Magento\Framework\Model\ModelResource\Db\AbstractDb $resource
  *
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, $mainTable, $eventPrefix, $eventObject, $resourceModel, $model = 'Magento\\Sales\\Model\\ResourceModel\\Grid\\Document', $connection = null, \Magento\Framework\Model\ModelResource\Db\AbstractDb $resource = null)
 {
     $this->_eventPrefix = $eventPrefix;
     $this->_eventObject = $eventObject;
     $this->_init($model, $resourceModel);
     $this->setMainTable($mainTable);
     parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
 }
Esempio n. 9
0
 /**
  * Load collection data
  *
  * @return $this
  */
 public function _beforeLoad()
 {
     if (!$this->getLoadDefault()) {
         $this->setWithoutDefaultFilter();
     }
     $this->addOrder('main_table.name', self::SORT_ORDER_ASC);
     return parent::_beforeLoad();
 }
Esempio n. 10
0
 /**
  * Initialize select, add country iso3 code and region name
  *
  * @return void
  */
 public function _initSelect()
 {
     parent::_initSelect();
     $this->_select->joinLeft(['country_table' => $this->_countryTable], 'country_table.country_id = main_table.dest_country_id', ['dest_country' => 'iso3_code'])->joinLeft(['region_table' => $this->_regionTable], 'region_table.region_id = main_table.dest_region_id', ['dest_region' => 'code']);
     $this->addOrder('dest_country', self::SORT_ORDER_ASC);
     $this->addOrder('dest_region', self::SORT_ORDER_ASC);
     $this->addOrder('dest_zip', self::SORT_ORDER_ASC);
     $this->addOrder('condition_value', self::SORT_ORDER_ASC);
 }
Esempio n. 11
0
 /**
  * Initialize select
  *
  * @return $this
  */
 protected function _initSelect()
 {
     parent::_initSelect();
     $this->addFieldToSelect(['path', 'value'])->addFieldToFilter('scope', $this->_scope);
     if ($this->_scopeId !== null) {
         $this->addFieldToFilter('scope_id', $this->_scopeId);
     }
     return $this;
 }
 /**
  * Batch print shipping labels for whole shipments.
  * Push pdf document with shipping labels to user browser
  *
  * @param AbstractCollection $collection
  * @return ResponseInterface|ResultInterface
  */
 protected function massAction(AbstractCollection $collection)
 {
     $labelsContent = [];
     if ($collection->getSize()) {
         /** @var \Magento\Sales\Model\Order\Shipment $shipment */
         foreach ($collection as $shipment) {
             $labelContent = $shipment->getShippingLabel();
             if ($labelContent) {
                 $labelsContent[] = $labelContent;
             }
         }
     }
     if (!empty($labelsContent)) {
         $outputPdf = $this->labelGenerator->combineLabelsPdf($labelsContent);
         return $this->fileFactory->create('ShippingLabels.pdf', $outputPdf->render(), DirectoryList::VAR_DIR, 'application/pdf');
     }
     $this->messageManager->addError(__('There are no shipping labels related to selected shipments.'));
     return $this->resultRedirectFactory->create()->setPath('sales/shipment/');
 }
Esempio n. 13
0
 /**
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  * @param \Magento\Framework\Event\ManagerInterface $eventManager
  * @param \Magento\Framework\Locale\ListsInterface $localeLists
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\Directory\Model\ResourceModel\CountryFactory $countryFactory
  * @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
  * @param \Magento\Framework\Locale\ResolverInterface $localeResolver
  * @param \Magento\Framework\App\Helper\AbstractHelper $helperData
  * @param mixed $connection
  * @param \Magento\Framework\Model\ModelResource\Db\AbstractDb $resource
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\Locale\ListsInterface $localeLists, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Directory\Model\ResourceModel\CountryFactory $countryFactory, \Magento\Framework\Stdlib\ArrayUtils $arrayUtils, \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\App\Helper\AbstractHelper $helperData, \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, \Magento\Framework\Model\ModelResource\Db\AbstractDb $resource = null)
 {
     parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
     $this->_scopeConfig = $scopeConfig;
     $this->_localeLists = $localeLists;
     $this->_localeResolver = $localeResolver;
     $this->_countryFactory = $countryFactory;
     $this->_arrayUtils = $arrayUtils;
     $this->helperData = $helperData;
 }
Esempio n. 14
0
 /**
  * Set collection to pager
  *
  * @param \Magento\Framework\Data\Collection $collection
  * @return $this
  */
 public function setCollection($collection)
 {
     $this->_collection = $collection;
     $this->_collection->setCurPage($this->getCurrentPage());
     // we need to set pagination only if passed value integer and more that 0
     $limit = (int) $this->getLimit();
     if ($limit) {
         $this->_collection->setPageSize($limit);
     }
     if ($this->getCurrentOrder()) {
         $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
     }
     return $this;
 }
Esempio n. 15
0
 /**
  * Hold selected orders
  *
  * @param AbstractCollection $collection
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $countHoldOrder = 0;
     foreach ($collection->getItems() as $order) {
         if (!$order->canHold()) {
             continue;
         }
         $this->orderManagement->hold($order->getEntityId());
         $countHoldOrder++;
     }
     $countNonHoldOrder = $collection->count() - $countHoldOrder;
     if ($countNonHoldOrder && $countHoldOrder) {
         $this->messageManager->addError(__('%1 order(s) were not put on hold.', $countNonHoldOrder));
     } elseif ($countNonHoldOrder) {
         $this->messageManager->addError(__('No order(s) were put on hold.'));
     }
     if ($countHoldOrder) {
         $this->messageManager->addSuccess(__('You have put %1 order(s) on hold.', $countHoldOrder));
     }
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath($this->getComponentRefererUrl());
     return $resultRedirect;
 }
Esempio n. 16
0
 /**
  * Cancel selected orders
  *
  * @param AbstractCollection $collection
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $countCancelOrder = 0;
     foreach ($collection->getItems() as $order) {
         if (!$order->canCancel()) {
             continue;
         }
         $order->cancel();
         $order->save();
         $countCancelOrder++;
     }
     $countNonCancelOrder = $collection->count() - $countCancelOrder;
     if ($countNonCancelOrder && $countCancelOrder) {
         $this->messageManager->addError(__('%1 order(s) cannot be canceled.', $countNonCancelOrder));
     } elseif ($countNonCancelOrder) {
         $this->messageManager->addError(__('You cannot cancel the order(s).'));
     }
     if ($countCancelOrder) {
         $this->messageManager->addSuccess(__('We canceled %1 order(s).', $countCancelOrder));
     }
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath($this->getComponentRefererUrl());
     return $resultRedirect;
 }
Esempio n. 17
0
 /**
  * Fill array of options by item and product
  *
  * @return $this
  */
 protected function _afterLoad()
 {
     parent::_afterLoad();
     foreach ($this as $option) {
         $optionId = $option->getId();
         $itemId = $option->getItemId();
         $productId = $option->getProductId();
         if (isset($this->_optionsByItem[$itemId])) {
             $this->_optionsByItem[$itemId][] = $optionId;
         } else {
             $this->_optionsByItem[$itemId] = [$optionId];
         }
         if (isset($this->_optionsByProduct[$productId])) {
             $this->_optionsByProduct[$productId][] = $optionId;
         } else {
             $this->_optionsByProduct[$productId] = [$optionId];
         }
     }
     return $this;
 }
 /**
  * Apply filters common to reports
  *
  * @return $this
  */
 protected function _beforeLoad()
 {
     parent::_beforeLoad();
     $this->_applyAggregatedTable();
     $this->_applyDateRangeFilter();
     $this->_applyStoresFilter();
     $this->_applyCustomFilter();
     return $this;
 }
Esempio n. 19
0
 /**
  * {@inheritdoc}
  */
 public function getSelectCountSql()
 {
     $countSelect = parent::getSelectCountSql();
     $countSelect->reset(\Magento\Framework\DB\Select::COLUMNS);
     $countSelect->columns('COUNT(DISTINCT main_table.attribute_id)');
     return $countSelect;
 }
Esempio n. 20
0
 /**
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  * @param \Magento\Framework\Event\ManagerInterface $eventManager
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param mixed $connection
  * @param \Magento\Framework\Model\ModelResource\Db\AbstractDb $resource
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, \Magento\Framework\Model\ModelResource\Db\AbstractDb $resource = null)
 {
     $this->_storeManager = $storeManager;
     parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
 }
Esempio n. 21
0
 /**
  * Join reports info table
  *
  * @return $this
  */
 protected function _initSelect()
 {
     parent::_initSelect();
     $this->getSelect()->join(['report' => $this->getTable('paypal_settlement_report')], 'report.report_id = main_table.report_id', ['report.account_id', 'report.report_date']);
     return $this;
 }
Esempio n. 22
0
 /**
  * Define resource model
  *
  * @return void
  */
 protected function _construct()
 {
     parent::_construct();
     $this->_init('Magento\\Widget\\Model\\Layout\\Update', 'Magento\\Widget\\Model\\ResourceModel\\Layout\\Update');
 }
 /**
  * Get SQL for get record count
  *
  * Extra GROUP BY strip added.
  *
  * @return \Magento\Framework\DB\Select
  */
 public function getSelectCountSql()
 {
     $countSelect = parent::getSelectCountSql();
     $countSelect->reset(\Magento\Framework\DB\Select::GROUP);
     return $countSelect;
 }
Esempio n. 24
0
 /**
  * {@inheritdoc}
  */
 protected function _construct()
 {
     parent::_construct();
     $this->_init('Magento\\Sales\\Model\\Order', 'Magento\\Sales\\Model\\ResourceModel\\Order');
 }
Esempio n. 25
0
 /**
  * Return option array
  *
  * @return array
  */
 public function toOptionArray()
 {
     return parent::_toOptionArray('event_type_id', 'event_name');
 }
Esempio n. 26
0
 /**
  * Load collection data
  *
  * @param boolean $printQuery
  * @param boolean $logQuery
  * @return $this
  */
 public function load($printQuery = false, $logQuery = false)
 {
     $this->unshiftOrder('main_table.name', \Magento\Framework\DB\Select::SQL_ASC)->unshiftOrder('main_table.sort_order', \Magento\Framework\DB\Select::SQL_ASC);
     // website sort order FIRST
     return parent::load($printQuery, $logQuery);
 }
Esempio n. 27
0
 /**
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  * @param \Magento\Framework\Event\ManagerInterface $eventManager
  * @param \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerResFactory
  * @param mixed $connection
  * @param \Magento\Framework\Model\ModelResource\Db\AbstractDb $resource
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerResFactory, \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, \Magento\Framework\Model\ModelResource\Db\AbstractDb $resource = null)
 {
     parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
     $this->_customerResFactory = $customerResFactory;
 }
Esempio n. 28
0
 /**
  * Initialize db query
  *
  * @return void
  */
 protected function _initSelect()
 {
     parent::_initSelect();
     $this->addOrder('severity', self::SORT_ORDER_ASC)->addOrder('created_at');
 }
Esempio n. 29
0
 /**
  * Add data fetched from another database
  *
  * @return $this
  */
 protected function _afterLoad()
 {
     parent::_afterLoad();
     $items = $this->getItems();
     $productIds = [];
     foreach ($items as $item) {
         $productIds[] = $item->getProductId();
     }
     $productData = $this->getProductData($productIds);
     $orderData = $this->getOrdersData($productIds);
     foreach ($items as $item) {
         $item->setId($item->getProductId());
         $item->setPrice($productData[$item->getProductId()]['price'] * $item->getBaseToGlobalRate());
         $item->setName($productData[$item->getProductId()]['name']);
         $item->setOrders(0);
         if (isset($orderData[$item->getProductId()])) {
             $item->setOrders($orderData[$item->getProductId()]['orders']);
         }
     }
     return $this;
 }
Esempio n. 30
0
 /**
  * Print all documents for selected orders
  *
  * @param AbstractCollection $collection
  * @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function massAction(AbstractCollection $collection)
 {
     $orderIds = $collection->getAllIds();
     $shipments = $this->shipmentCollectionFactory->create()->setOrderFilter(['in' => $orderIds]);
     $invoices = $this->invoiceCollectionFactory->create()->setOrderFilter(['in' => $orderIds]);
     $creditmemos = $this->creditmemoCollectionFactory->create()->setOrderFilter(['in' => $orderIds]);
     $documents = [];
     if ($invoices->getSize()) {
         $documents[] = $this->pdfInvoice->getPdf($invoices);
     }
     if ($shipments->getSize()) {
         $documents[] = $this->pdfShipment->getPdf($shipments);
     }
     if ($creditmemos->getSize()) {
         $documents[] = $this->pdfCreditmemo->getPdf($creditmemos);
     }
     if (empty($documents)) {
         $this->messageManager->addError(__('There are no printable documents related to selected orders.'));
         return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl());
     }
     $pdf = array_shift($documents);
     foreach ($documents as $document) {
         $pdf->pages = array_merge($pdf->pages, $document->pages);
     }
     return $this->fileFactory->create(sprintf('docs%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf');
 }