예제 #1
0
 /**
  * Execute action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  * @throws \Magento\Framework\Exception\LocalizedException|\Exception
  */
 public function execute()
 {
     $collection = $this->filter->getCollection($this->collectionFactory->create());
     $collectionSize = $collection->getSize();
     foreach ($collection as $row) {
         $row->delete();
     }
     $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $collectionSize));
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     return $resultRedirect->setPath('*/*/');
 }
예제 #2
0
 /**
  * Load data collection by given search criteria
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @param \Magento\Framework\Api\SearchCriteriaInterface $criteria
  * @return \Swissup\Email\Model\ResourceModel\Service\Collection
  */
 public function getList(\Magento\Framework\Api\SearchCriteriaInterface $criteria)
 {
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($criteria);
     $collection = $this->serviceCollectionFactory->create();
     foreach ($criteria->getFilterGroups() as $filterGroup) {
         foreach ($filterGroup->getFilters() as $filter) {
             if ($filter->getField() === 'store_id') {
                 $collection->addStoreFilter($filter->getValue(), false);
                 continue;
             }
             $condition = $filter->getConditionType() ?: 'eq';
             $collection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]);
         }
     }
     $searchResults->setTotalCount($collection->getSize());
     $sortOrders = $criteria->getSortOrders();
     if ($sortOrders) {
         foreach ($sortOrders as $sortOrder) {
             $collection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($criteria->getCurrentPage());
     $collection->setPageSize($criteria->getPageSize());
     $services = [];
     /** @var Service $serviceModel */
     foreach ($collection as $serviceModel) {
         $serviceData = $this->dataServiceFactory->create();
         $this->dataObjectHelper->populateWithArray($serviceData, $serviceModel->getData(), 'Swissup\\Email\\Api\\Data\\ServiceInterface');
         $services[] = $this->dataObjectProcessor->buildOutputDataArray($serviceData, 'Swissup\\Email\\Api\\Data\\ServiceInterface');
     }
     $searchResults->setItems($services);
     return $searchResults;
 }
예제 #3
0
 /**
  * Execute action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  * @throws \Magento\Framework\Exception\LocalizedException|\Exception
  */
 public function execute()
 {
     $key = 'status';
     $value = 0;
     // $value = (int) $this->getRequest()->getParam('status');
     $collection = $this->filter->getCollection($this->collectionFactory->create());
     $collectionSize = $collection->getSize();
     foreach ($collection as $row) {
         $row->setData($key, $value);
         $row->save();
     }
     $this->messageManager->addSuccess(__('A total of %1 record(s) have been changed.', $collectionSize));
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     return $resultRedirect->setPath('*/*/');
 }