diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php index 4a312adfb6366..945e80c93e44c 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php @@ -6,69 +6,58 @@ */ namespace Magento\Catalog\Controller\Adminhtml\Product; -use Magento\Catalog\Model\Resource\Product\Collection; use Magento\Framework\Controller\ResultFactory; +use Magento\Catalog\Controller\Adminhtml\Product\Builder; +use Magento\Backend\App\Action\Context; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Catalog\Model\Resource\Product\CollectionFactory; class MassDelete extends \Magento\Catalog\Controller\Adminhtml\Product { /** - * Field id + * Massactions filter + * + * @var Filter */ - const ID_FIELD = 'entity_id'; + protected $filter; /** - * Redirect url + * @var CollectionFactory */ - const REDIRECT_URL = 'catalog/*/index'; + protected $collectionFactory; /** - * Resource collection - * - * @var string + * @param Context $context + * @param Builder $productBuilder + * @param Filter $filter + * @param CollectionFactory $collectionFactory */ - protected $collection = 'Magento\Catalog\Model\Resource\Product\Collection'; + public function __construct( + Context $context, + Builder $productBuilder, + Filter $filter, + CollectionFactory $collectionFactory + ) { + $this->filter = $filter; + $this->collectionFactory = $collectionFactory; + parent::__construct($context, $productBuilder); + } /** * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { - $selected = $this->getRequest()->getParam('selected'); - $excluded = $this->getRequest()->getParam('excluded'); - - $collection = $this->_objectManager->create($this->collection); - try { - if (!empty($excluded)) { - $collection->addFieldToFilter(static::ID_FIELD, ['nin' => $excluded]); - $this->massAction($collection); - } elseif (!empty($selected)) { - $collection->addFieldToFilter(static::ID_FIELD, ['in' => $selected]); - $this->massAction($collection); - } else { - $this->messageManager->addError(__('Please select product(s).')); - } - } catch (\Exception $e) { - $this->messageManager->addError($e->getMessage()); - } - - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - return $resultRedirect->setPath(static::REDIRECT_URL); - } - - /** - * Cancel selected orders - * - * @param Collection $collection - * @return void - */ - protected function massAction($collection) - { - $count = 0; + $collection = $this->filter->getCollection($this->collectionFactory->create()); + $productDeleted = 0; foreach ($collection->getItems() as $product) { $product->delete(); - ++$count; + $productDeleted++; } - $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $count)); + $this->messageManager->addSuccess( + __('A total of %1 record(s) have been deleted.', $productDeleted) + ); + + return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('catalog/*/index'); } } diff --git a/app/code/Magento/Catalog/Model/Resource/Product/Collection.php b/app/code/Magento/Catalog/Model/Resource/Product/Collection.php index d4412878e504b..85cad10802f68 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product/Collection.php +++ b/app/code/Magento/Catalog/Model/Resource/Product/Collection.php @@ -34,6 +34,11 @@ class Collection extends \Magento\Catalog\Model\Resource\Collection\AbstractColl */ const MAIN_TABLE_ALIAS = 'e'; + /** + * @var string + */ + protected $_idFieldName = 'entity_id'; + /** * Catalog Product Flat is enabled cache per store * diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/AddStoreFieldToCollection.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/AddStoreFieldToCollection.php index 439c62044ba52..ea841e030babf 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/AddStoreFieldToCollection.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/AddStoreFieldToCollection.php @@ -34,6 +34,7 @@ public function __construct(StoreManagerInterface $storeManager) public function addFilter(Collection $collection, $field, $condition = null) { if (isset($condition['eq']) && $condition['eq']) { + /** @var \Magento\Catalog\Model\Resource\Product\Collection $collection */ $collection->addStoreFilter($this->storeManager->getStore($condition['eq'])); } } diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/ProductDataProvider.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/ProductDataProvider.php index c26416b4a2ac5..8e558d9318deb 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/ProductDataProvider.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/ProductDataProvider.php @@ -57,16 +57,6 @@ public function __construct( $this->addFilterStrategies = $addFilterStrategies; } - /** - * Get collection - * - * @return \Magento\Catalog\Model\Resource\Product\Collection - */ - protected function getCollection() - { - return $this->collection; - } - /** * Get data * @@ -104,12 +94,17 @@ public function addField($field, $alias = null) /** * {@inheritdoc} */ - public function addFilter($condition, $field = null, $type = 'regular') + public function addFilter(\Magento\Framework\Api\Filter $filter) { - if (isset($this->addFilterStrategies[$field])) { - $this->addFilterStrategies[$field]->addFilter($this->getCollection(), $field, $condition); + if (isset($this->addFilterStrategies[$filter->getField()])) { + $this->addFilterStrategies[$filter->getField()] + ->addFilter( + $this->getCollection(), + $filter->getField(), + [$filter->getConditionType() => $filter->getValue()] + ); } else { - parent::addFilter($condition, $field); + parent::addFilter($filter); } } } diff --git a/app/code/Magento/Cms/Controller/Adminhtml/AbstractMassDelete.php b/app/code/Magento/Cms/Controller/Adminhtml/AbstractMassDelete.php deleted file mode 100644 index b8b22afca1ab7..0000000000000 --- a/app/code/Magento/Cms/Controller/Adminhtml/AbstractMassDelete.php +++ /dev/null @@ -1,145 +0,0 @@ -getRequest()->getParam('selected'); - $excluded = $this->getRequest()->getParam('excluded'); - - try { - if (isset($excluded)) { - if (!empty($excluded)) { - $this->excludedDelete($excluded); - } else { - $this->deleteAll(); - } - } elseif (!empty($selected)) { - $this->selectedDelete($selected); - } else { - $this->messageManager->addError(__('Please select item(s).')); - } - } catch (\Exception $e) { - $this->messageManager->addError($e->getMessage()); - } - - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - return $resultRedirect->setPath(static::REDIRECT_URL); - } - - /** - * Delete all - * - * @return void - * @throws \Exception - */ - protected function deleteAll() - { - /** @var AbstractCollection $collection */ - $collection = $this->_objectManager->get($this->collection); - $this->setSuccessMessage($this->delete($collection)); - } - - /** - * Delete all but the not selected - * - * @param array $excluded - * @return void - * @throws \Exception - */ - protected function excludedDelete(array $excluded) - { - /** @var AbstractCollection $collection */ - $collection = $this->_objectManager->get($this->collection); - $collection->addFieldToFilter(static::ID_FIELD, ['nin' => $excluded]); - $this->setSuccessMessage($this->delete($collection)); - } - - /** - * Delete selected items - * - * @param array $selected - * @return void - * @throws \Exception - */ - protected function selectedDelete(array $selected) - { - /** @var AbstractCollection $collection */ - $collection = $this->_objectManager->get($this->collection); - $collection->addFieldToFilter(static::ID_FIELD, ['in' => $selected]); - $this->setSuccessMessage($this->delete($collection)); - } - - /** - * Delete collection items - * - * @param AbstractCollection $collection - * @return int - */ - protected function delete(AbstractCollection $collection) - { - $count = 0; - foreach ($collection->getAllIds() as $id) { - /** @var \Magento\Framework\Model\AbstractModel $model */ - $model = $this->_objectManager->get($this->model); - $model->load($id); - $model->delete(); - ++$count; - } - - return $count; - } - - /** - * Set error messages - * - * @param int $count - * @return void - */ - protected function setSuccessMessage($count) - { - $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $count)); - } -} diff --git a/app/code/Magento/Cms/Controller/Adminhtml/AbstractMassStatus.php b/app/code/Magento/Cms/Controller/Adminhtml/AbstractMassStatus.php deleted file mode 100644 index fa2219309b56b..0000000000000 --- a/app/code/Magento/Cms/Controller/Adminhtml/AbstractMassStatus.php +++ /dev/null @@ -1,137 +0,0 @@ -getRequest()->getParam('selected'); - $excluded = $this->getRequest()->getParam('excluded'); - try { - if (isset($excluded)) { - if (!empty($excluded)) { - $this->excludedSetStatus($excluded); - } else { - $this->setStatusAll(); - } - } elseif (!empty($selected)) { - $this->selectedSetStatus($selected); - } else { - $this->messageManager->addError(__('Please select item(s).')); - } - } catch (\Exception $e) { - $this->messageManager->addError($e->getMessage()); - } - - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - return $resultRedirect->setPath(static::REDIRECT_URL); - } - - /** - * Set status to all - * - * @return void - * @throws \Exception - */ - protected function setStatusAll() - { - /** @var AbstractCollection $collection */ - $collection = $this->_objectManager->get($this->collection); - $this->setStatus($collection); - } - - /** - * Set status to all but the not selected - * - * @param array $excluded - * @return void - * @throws \Exception - */ - protected function excludedSetStatus(array $excluded) - { - /** @var AbstractCollection $collection */ - $collection = $this->_objectManager->get($this->collection); - $collection->addFieldToFilter(static::ID_FIELD, ['nin' => $excluded]); - $this->setStatus($collection); - } - - /** - * Set status to selected items - * - * @param array $selected - * @return void - * @throws \Exception - */ - protected function selectedSetStatus(array $selected) - { - /** @var AbstractCollection $collection */ - $collection = $this->_objectManager->get($this->collection); - $collection->addFieldToFilter(static::ID_FIELD, ['in' => $selected]); - $this->setStatus($collection); - } - - /** - * Set status to collection items - * - * @param AbstractCollection $collection - * @return void - */ - protected function setStatus(AbstractCollection $collection) - { - foreach ($collection->getAllIds() as $id) { - /** @var \Magento\Framework\Model\AbstractModel $model */ - $model = $this->_objectManager->get($this->model); - $model->load($id); - $model->setIsActive($this->status); - $model->save(); - } - } -} diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Block/MassDelete.php b/app/code/Magento/Cms/Controller/Adminhtml/Block/MassDelete.php index c40c373d205d0..d9a8c044873cf 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Block/MassDelete.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Block/MassDelete.php @@ -6,29 +6,56 @@ */ namespace Magento\Cms\Controller\Adminhtml\Block; -use Magento\Cms\Controller\Adminhtml\AbstractMassDelete; +use Magento\Framework\Controller\ResultFactory; +use Magento\Backend\App\Action\Context; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Cms\Model\Resource\Block\CollectionFactory; /** * Class MassDelete */ -class MassDelete extends AbstractMassDelete +class MassDelete extends \Magento\Backend\App\Action { /** - * Field id + * @var Filter */ - const ID_FIELD = 'block_id'; + protected $filter; /** - * Resource collection - * - * @var string + * @var CollectionFactory + */ + protected $collectionFactory; + + /** + * @param Context $context + * @param Filter $filter + * @param CollectionFactory $collectionFactory */ - protected $collection = 'Magento\Cms\Model\Resource\Block\Collection'; + public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) + { + $this->filter = $filter; + $this->collectionFactory = $collectionFactory; + parent::__construct($context); + } /** - * Block model + * Execute action * - * @var string + * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ - protected $model = 'Magento\Cms\Model\Block'; + public function execute() + { + $collection = $this->filter->getCollection($this->collectionFactory->create()); + + foreach ($collection as $item) { + $item->delete(); + } + + $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $collection->getSize())); + + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + return $resultRedirect->setPath('*/*/'); + } } diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDelete.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDelete.php index b255b784a1ac9..e5cfcf22966f5 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDelete.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDelete.php @@ -5,29 +5,56 @@ */ namespace Magento\Cms\Controller\Adminhtml\Page; -use Magento\Cms\Controller\Adminhtml\AbstractMassDelete; +use Magento\Framework\Controller\ResultFactory; +use Magento\Backend\App\Action\Context; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Cms\Model\Resource\Page\CollectionFactory; /** * Class MassDelete */ -class MassDelete extends AbstractMassDelete +class MassDelete extends \Magento\Backend\App\Action { /** - * Field id + * @var Filter */ - const ID_FIELD = 'page_id'; + protected $filter; /** - * Resource collection - * - * @var string + * @var CollectionFactory + */ + protected $collectionFactory; + + /** + * @param Context $context + * @param Filter $filter + * @param CollectionFactory $collectionFactory */ - protected $collection = 'Magento\Cms\Model\Resource\Page\Collection'; + public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) + { + $this->filter = $filter; + $this->collectionFactory = $collectionFactory; + parent::__construct($context); + } /** - * Page model + * Execute action * - * @var string + * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ - protected $model = 'Magento\Cms\Model\Page'; + public function execute() + { + $collection = $this->filter->getCollection($this->collectionFactory->create()); + + foreach ($collection as $item) { + $item->delete(); + } + + $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $collection->getSize())); + + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + return $resultRedirect->setPath('*/*/'); + } } diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php index ef56988a592c7..a3c5b07513f1e 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php @@ -5,36 +5,57 @@ */ namespace Magento\Cms\Controller\Adminhtml\Page; -use Magento\Cms\Controller\Adminhtml\AbstractMassStatus; +use Magento\Framework\Controller\ResultFactory; +use Magento\Backend\App\Action\Context; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Cms\Model\Resource\Page\CollectionFactory; /** * Class MassDisable */ -class MassDisable extends AbstractMassStatus +class MassDisable extends \Magento\Backend\App\Action { /** - * Field id + * @var Filter */ - const ID_FIELD = 'page_id'; + protected $filter; /** - * Resource collection - * - * @var string + * @var CollectionFactory */ - protected $collection = 'Magento\Cms\Model\Resource\Page\Collection'; + protected $collectionFactory; /** - * Page model - * - * @var string + * @param Context $context + * @param Filter $filter + * @param CollectionFactory $collectionFactory */ - protected $model = 'Magento\Cms\Model\Page'; + public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) + { + $this->filter = $filter; + $this->collectionFactory = $collectionFactory; + parent::__construct($context); + } /** - * Page disable status + * Execute action * - * @var boolean + * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ - protected $status = false; + public function execute() + { + $collection = $this->filter->getCollection($this->collectionFactory->create()); + + foreach ($collection as $item) { + $item->setIsActive(false); + $item->save(); + } + + $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $collection->getSize())); + + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + return $resultRedirect->setPath('*/*/'); + } } diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassEnable.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassEnable.php index 4eac33a6fa4a7..fff1f58a5b1c0 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassEnable.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassEnable.php @@ -5,36 +5,57 @@ */ namespace Magento\Cms\Controller\Adminhtml\Page; -use Magento\Cms\Controller\Adminhtml\AbstractMassStatus; +use Magento\Framework\Controller\ResultFactory; +use Magento\Backend\App\Action\Context; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Cms\Model\Resource\Page\CollectionFactory; /** * Class MassEnable */ -class MassEnable extends AbstractMassStatus +class MassEnable extends \Magento\Backend\App\Action { /** - * Field id + * @var Filter */ - const ID_FIELD = 'page_id'; + protected $filter; /** - * Resource collection - * - * @var string + * @var CollectionFactory */ - protected $collection = 'Magento\Cms\Model\Resource\Page\Collection'; + protected $collectionFactory; /** - * Page model - * - * @var string + * @param Context $context + * @param Filter $filter + * @param CollectionFactory $collectionFactory */ - protected $model = 'Magento\Cms\Model\Page'; + public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) + { + $this->filter = $filter; + $this->collectionFactory = $collectionFactory; + parent::__construct($context); + } /** - * Page enable status + * Execute action * - * @var boolean + * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ - protected $status = true; + public function execute() + { + $collection = $this->filter->getCollection($this->collectionFactory->create()); + + foreach ($collection as $item) { + $item->setIsActive(true); + $item->save(); + } + + $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $collection->getSize())); + + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + return $resultRedirect->setPath('*/*/'); + } } diff --git a/app/code/Magento/Cms/Model/Block/DataProvider.php b/app/code/Magento/Cms/Model/Block/DataProvider.php deleted file mode 100644 index a1aed9394efe9..0000000000000 --- a/app/code/Magento/Cms/Model/Block/DataProvider.php +++ /dev/null @@ -1,87 +0,0 @@ -collection = $collectionFactory->create(); - $this->filterPool = $filterPool; - } - - /** - * @return \Magento\Cms\Model\Resource\Block\Collection - */ - protected function getCollection() - { - return $this->collection; - } - - /** - * @inheritdoc - */ - public function addFilter($condition, $field = null, $type = 'regular') - { - $this->filterPool->registerNewFilter($condition, $field, $type); - } - - /** - * Get data - * - * @return array - */ - public function getData() - { - $this->filterPool->applyFilters($this->collection); - return $this->collection->toArray(); - } - - /** - * Retrieve count of loaded items - * - * @return int - */ - public function count() - { - $this->filterPool->applyFilters($this->collection); - return $this->collection->count(); - } -} diff --git a/app/code/Magento/Cms/Model/Page/DataProvider.php b/app/code/Magento/Cms/Model/Page/DataProvider.php deleted file mode 100644 index f3d4d61303bd1..0000000000000 --- a/app/code/Magento/Cms/Model/Page/DataProvider.php +++ /dev/null @@ -1,88 +0,0 @@ -filterPool = $filterPool; - $this->collection = $collectionFactory->create(); - $this->collection->setFirstStoreFlag(true); - } - - /** - * @return \Magento\Cms\Model\Resource\Page\Collection - */ - protected function getCollection() - { - return $this->collection; - } - - /** - * @inheritdoc - */ - public function addFilter($condition, $field = null, $type = 'regular') - { - $this->filterPool->registerNewFilter($condition, $field, $type); - } - - /** - * Get data - * - * @return array - */ - public function getData() - { - $this->filterPool->applyFilters($this->collection); - return $this->collection->toArray(); - } - - /** - * Retrieve count of loaded items - * - * @return int - */ - public function count() - { - $this->filterPool->applyFilters($this->collection); - return $this->collection->count(); - } -} diff --git a/app/code/Magento/Cms/Model/Resource/Block/Collection.php b/app/code/Magento/Cms/Model/Resource/Block/Collection.php index 0bed33c3c0308..bb7657bdb357f 100644 --- a/app/code/Magento/Cms/Model/Resource/Block/Collection.php +++ b/app/code/Magento/Cms/Model/Resource/Block/Collection.php @@ -12,6 +12,11 @@ */ class Collection extends \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection { + /** + * @var string + */ + protected $_idFieldName = 'block_id'; + /** * @return \Magento\Cms\Model\Resource\Block\Collection */ diff --git a/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php b/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php new file mode 100644 index 0000000000000..427dbe5f1b67a --- /dev/null +++ b/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php @@ -0,0 +1,150 @@ +_eventPrefix = $eventPrefix; + $this->_eventObject = $eventObject; + $this->_init($model, $resourceModel); + $this->setMainTable($mainTable); + } + + /** + * @return AggregationInterface + */ + public function getAggregations() + { + return $this->aggregations; + } + + /** + * @param AggregationInterface $aggregations + * @return $this + */ + public function setAggregations($aggregations) + { + $this->aggregations = $aggregations; + } + + + /** + * Retrieve all ids for collection + * Backward compatibility with EAV collection + * + * @param int $limit + * @param int $offset + * @return array + */ + public function getAllIds($limit = null, $offset = null) + { + return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams); + } + + /** + * Get search criteria. + * + * @return \Magento\Framework\Api\SearchCriteriaInterface|null + */ + public function getSearchCriteria() + { + return null; + } + + /** + * Set search criteria. + * + * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria + * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null) + { + return $this; + } + + /** + * Get total count. + * + * @return int + */ + public function getTotalCount() + { + return $this->getSize(); + } + + /** + * Set total count. + * + * @param int $totalCount + * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setTotalCount($totalCount) + { + return $this; + } + + /** + * Set items list. + * + * @param \Magento\Framework\Api\ExtensibleDataInterface[] $items + * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setItems(array $items = null) + { + return $this; + } +} diff --git a/app/code/Magento/Cms/Model/Resource/Page/Collection.php b/app/code/Magento/Cms/Model/Resource/Page/Collection.php index 7e6aa38ddf9f4..b8eadc87623f8 100644 --- a/app/code/Magento/Cms/Model/Resource/Page/Collection.php +++ b/app/code/Magento/Cms/Model/Resource/Page/Collection.php @@ -12,6 +12,11 @@ */ class Collection extends \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection { + /** + * @var string + */ + protected $_idFieldName = 'page_id'; + /** * Load data for preview flag * diff --git a/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php b/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php new file mode 100644 index 0000000000000..f2df536005439 --- /dev/null +++ b/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php @@ -0,0 +1,153 @@ +_eventPrefix = $eventPrefix; + $this->_eventObject = $eventObject; + $this->_init($model, $resourceModel); + $this->setMainTable($mainTable); + } + + /** + * @return AggregationInterface + */ + public function getAggregations() + { + return $this->aggregations; + } + + /** + * @param AggregationInterface $aggregations + * @return $this + */ + public function setAggregations($aggregations) + { + $this->aggregations = $aggregations; + } + + + /** + * Retrieve all ids for collection + * Backward compatibility with EAV collection + * + * @param int $limit + * @param int $offset + * @return array + */ + public function getAllIds($limit = null, $offset = null) + { + return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams); + } + + /** + * Get search criteria. + * + * @return \Magento\Framework\Api\SearchCriteriaInterface|null + */ + public function getSearchCriteria() + { + return null; + } + + /** + * Set search criteria. + * + * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria + * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null) + { + return $this; + } + + /** + * Get total count. + * + * @return int + */ + public function getTotalCount() + { + return $this->getSize(); + } + + /** + * Set total count. + * + * @param int $totalCount + * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setTotalCount($totalCount) + { + return $this; + } + + /** + * Set items list. + * + * @param \Magento\Framework\Api\ExtensibleDataInterface[] $items + * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setItems(array $items = null) + { + return $this; + } +} diff --git a/app/code/Magento/Cms/etc/di.xml b/app/code/Magento/Cms/etc/di.xml index ae53723ea07a3..3c24a50d54504 100644 --- a/app/code/Magento/Cms/etc/di.xml +++ b/app/code/Magento/Cms/etc/di.xml @@ -56,6 +56,30 @@ + + + + Magento\Cms\Model\Resource\Page\Grid\Collection + Magento\Cms\Model\Resource\Block\Grid\Collection + + + + + + cms_page + cms_page_grid_collection + page_grid_collection + Magento\Cms\Model\Resource\Page + + + + + cms_block + cms_block_grid_collection + block_grid_collection + Magento\Cms\Model\Resource\Block + + diff --git a/app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_listing.xml b/app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_listing.xml index 0c39341b9fc6f..0edc6d6f675f4 100644 --- a/app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_listing.xml +++ b/app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_listing.xml @@ -25,7 +25,7 @@ PageGridDataProvider cms_page_listing_data_source - block_id + page_id id diff --git a/app/code/Magento/ConfigurableProduct/Ui/DataProvider/Attributes.php b/app/code/Magento/ConfigurableProduct/Ui/DataProvider/Attributes.php index 2a59355b82834..69506ea143107 100644 --- a/app/code/Magento/ConfigurableProduct/Ui/DataProvider/Attributes.php +++ b/app/code/Magento/ConfigurableProduct/Ui/DataProvider/Attributes.php @@ -37,7 +37,7 @@ public function __construct( /** * @return \Magento\Catalog\Model\Resource\Product\Attribute\Collection */ - protected function getCollection() + public function getCollection() { return $this->collection; } diff --git a/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Orders.php b/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Orders.php index 93effab82be11..3705f6451156f 100644 --- a/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Orders.php +++ b/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Orders.php @@ -27,16 +27,14 @@ class Orders extends \Magento\Backend\Block\Widget\Grid\Extended protected $_coreRegistry = null; /** - * @var \Magento\Sales\Model\Resource\Order\Grid\CollectionFactory + * @var \Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory */ - protected $_collectionFactory; + protected $collectionFactory; /** - * Constructor - * * @param \Magento\Backend\Block\Template\Context $context * @param \Magento\Backend\Helper\Data $backendHelper - * @param \Magento\Sales\Model\Resource\Order\Grid\CollectionFactory $collectionFactory + * @param \Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory $collectionFactory * @param \Magento\Sales\Helper\Reorder $salesReorder * @param \Magento\Framework\Registry $coreRegistry * @param array $data @@ -44,7 +42,7 @@ class Orders extends \Magento\Backend\Block\Widget\Grid\Extended public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Backend\Helper\Data $backendHelper, - \Magento\Sales\Model\Resource\Order\Grid\CollectionFactory $collectionFactory, + \Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory $collectionFactory, \Magento\Sales\Helper\Reorder $salesReorder, \Magento\Framework\Registry $coreRegistry, array $data = [] @@ -73,7 +71,7 @@ protected function _construct() */ protected function _prepareCollection() { - $collection = $this->_collectionFactory->create()->addFieldToSelect( + $collection = $this->_collectionFactory->getReport('sales_order_grid_data_source')->addFieldToSelect( 'entity_id' )->addFieldToSelect( 'increment_id' @@ -94,8 +92,6 @@ protected function _prepareCollection() )->addFieldToFilter( 'customer_id', $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID) - )->setIsCustomerMode( - true ); $this->setCollection($collection); diff --git a/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/View/Orders.php b/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/View/Orders.php deleted file mode 100644 index adc9caffbf026..0000000000000 --- a/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/View/Orders.php +++ /dev/null @@ -1,151 +0,0 @@ -_coreRegistry = $coreRegistry; - $this->_collectionFactory = $collectionFactory; - parent::__construct($context, $backendHelper, $data); - } - - /** - * Initialize the orders grid. - * - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->setId('customer_view_orders_grid'); - $this->setDefaultSort('created_at', 'desc'); - $this->setSortable(false); - $this->setPagerVisibility(false); - $this->setFilterVisibility(false); - } - - /** - * {@inheritdoc} - */ - protected function _preparePage() - { - $this->getCollection()->setPageSize(5)->setCurPage(1); - } - - /** - * {@inheritdoc} - */ - protected function _prepareCollection() - { - $collection = $this->_collectionFactory->create()->addFieldToFilter( - 'customer_id', - $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID) - )->setIsCustomerMode( - true - ); - $this->setCollection($collection); - return parent::_prepareCollection(); - } - - /** - * {@inheritdoc} - */ - protected function _prepareColumns() - { - $this->addColumn( - 'increment_id', - ['header' => __('Order'), 'align' => 'center', 'index' => 'increment_id', 'width' => '100px'] - ); - - $this->addColumn( - 'created_at', - ['header' => __('Purchased'), 'index' => 'created_at', 'type' => 'datetime'] - ); - - $this->addColumn('billing_name', ['header' => __('Bill-to Name'), 'index' => 'billing_name']); - - $this->addColumn('shipping_name', ['header' => __('Shipped-to Name'), 'index' => 'shipping_name']); - - $this->addColumn( - 'grand_total', - [ - 'header' => __('Grand Total'), - 'index' => 'grand_total', - 'type' => 'currency', - 'currency' => 'order_currency_code' - ] - ); - - if (!$this->_storeManager->isSingleStoreMode()) { - $this->addColumn( - 'store_id', - ['header' => __('Purchase Point'), 'index' => 'store_id', 'type' => 'store', 'store_view' => true] - ); - } - - $this->addColumn( - 'action', - [ - 'header' => ' ', - 'filter' => false, - 'sortable' => false, - 'width' => '100px', - 'renderer' => 'Magento\Sales\Block\Adminhtml\Reorder\Renderer\Action' - ] - ); - - return parent::_prepareColumns(); - } - - /** - * {@inheritdoc} - */ - public function getRowUrl($row) - { - return $this->getUrl('sales/order/view', ['order_id' => $row->getId()]); - } - - /** - * {@inheritdoc} - */ - public function getHeadersVisibility() - { - return $this->getCollection()->getSize() >= 0; - } -} diff --git a/app/code/Magento/Customer/Model/Customer/DataProvider.php b/app/code/Magento/Customer/Model/Customer/DataProvider.php index 23fe67286f29a..750e3b9dba7b6 100644 --- a/app/code/Magento/Customer/Model/Customer/DataProvider.php +++ b/app/code/Magento/Customer/Model/Customer/DataProvider.php @@ -108,22 +108,6 @@ public function __construct( ); } - /** - * @return Collection|\Magento\Framework\Model\Resource\Db\Collection\AbstractCollection - */ - protected function getCollection() - { - return $this->collection; - } - - /** - * @inheritdoc - */ - public function addFilter($condition, $field = null, $type = 'regular') - { - $this->filterPool->registerNewFilter($condition, $field, $type); - } - /** * Get data * @@ -134,7 +118,6 @@ public function getData() if (isset($this->loadedData)) { return $this->loadedData; } - $this->filterPool->applyFilters($this->collection); $items = $this->collection->getItems(); /** @var Customer $customer */ foreach ($items as $customer) { @@ -158,17 +141,6 @@ public function getData() return $this->loadedData; } - /** - * Retrieve count of loaded items - * - * @return int - */ - public function count() - { - $this->filterPool->applyFilters($this->collection); - return $this->collection->count(); - } - /** * Get attributes meta * diff --git a/app/code/Magento/Customer/view/adminhtml/layout/customer_index_lastorders.xml b/app/code/Magento/Customer/view/adminhtml/layout/customer_index_lastorders.xml deleted file mode 100644 index 49c2cf49f3488..0000000000000 --- a/app/code/Magento/Customer/view/adminhtml/layout/customer_index_lastorders.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php deleted file mode 100644 index f3b8531f03bb6..0000000000000 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php +++ /dev/null @@ -1,15 +0,0 @@ - - */ -class Grid extends \Magento\Backend\Block\Widget\Grid -{ -} diff --git a/app/code/Magento/Sales/Block/Adminhtml/Reorder/Renderer/Action.php b/app/code/Magento/Sales/Block/Adminhtml/Reorder/Renderer/Action.php index 31827e5595f30..3780d74a3b9bd 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Reorder/Renderer/Action.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Reorder/Renderer/Action.php @@ -47,7 +47,7 @@ public function __construct( public function render(\Magento\Framework\DataObject $row) { $this->_actions = []; - if ($this->_salesReorder->canReorder($row)) { + if ($this->_salesReorder->canReorder($row->getId())) { $reorderAction = [ '@' => [ 'href' => $this->getUrl('sales/order_create/reorder', ['order_id' => $row->getId()]), diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php index 1e5bce8fb535a..920be7c4c242a 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php @@ -7,31 +7,56 @@ use Magento\Framework\App\ResponseInterface; use Magento\Framework\App\Filesystem\DirectoryList; - use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; +use Magento\Sales\Model\Order\Pdf\Creditmemo; +use Magento\Framework\Stdlib\DateTime\DateTime; +use Magento\Backend\App\Action\Context; +use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Sales\Model\Resource\Order\Creditmemo\CollectionFactory; +/** + * Class Pdfcreditmemos + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class Pdfcreditmemos extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { /** - * @var \Magento\Framework\App\Response\Http\FileFactory + * @var FileFactory */ - protected $_fileFactory; + protected $fileFactory; /** - * @var string + * @var Creditmemo */ - protected $collection = 'Magento\Sales\Model\Resource\Order\Creditmemo\Grid\Collection'; + protected $pdfCreditmemo; /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @var DateTime + */ + protected $dateTime; + + /** + * @param Context $context + * @param Filter $filter + * @param Creditmemo $pdfCreditmemo + * @param DateTime $dateTime + * @param FileFactory $fileFactory + * @param CollectionFactory $collectionFactory */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + Context $context, + Filter $filter, + Creditmemo $pdfCreditmemo, + DateTime $dateTime, + FileFactory $fileFactory, + CollectionFactory $collectionFactory ) { - $this->_fileFactory = $fileFactory; - parent::__construct($context); + $this->pdfCreditmemo = $pdfCreditmemo; + $this->fileFactory = $fileFactory; + $this->dateTime = $dateTime; + $this->collectionFactory = $collectionFactory; + parent::__construct($context, $filter); } /** @@ -44,22 +69,15 @@ protected function _isAllowed() /** * @param AbstractCollection $collection - * @return ResponseInterface|\Magento\Framework\Controller\Result\Redirect + * @return ResponseInterface * @throws \Exception + * @throws \Zend_Pdf_Exception */ public function massAction(AbstractCollection $collection) { - if (!isset($pdf)) { - $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Creditmemo')->getPdf($collection); - } else { - $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Creditmemo')->getPdf($collection); - $pdf->pages = array_merge($pdf->pages, $pages->pages); - } - $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime')->date('Y-m-d_H-i-s'); - - return $this->_fileFactory->create( - 'creditmemo' . $date . '.pdf', - $pdf->render(), + return $this->fileFactory->create( + sprintf('creditmemo%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), + $this->pdfCreditmemo->getPdf($collection)->render(), DirectoryList::VAR_DIR, 'application/pdf' ); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/ExportCsv.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/ExportCsv.php deleted file mode 100644 index b7b09998c15f7..0000000000000 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/ExportCsv.php +++ /dev/null @@ -1,59 +0,0 @@ -_fileFactory = $fileFactory; - $this->resultLayoutFactory = $resultLayoutFactory; - parent::__construct($context); - } - - /** - * {@inheritdoc} - */ - protected function _isAllowed() - { - return $this->_authorization->isAllowed('Magento_Sales::sales_creditmemo'); - } - - /** - * Export credit memo grid to CSV format - * - * @return ResponseInterface - */ - public function execute() - { - $fileName = 'creditmemos.csv'; - $resultLayout = $this->resultLayoutFactory->create(); - $grid = $resultLayout->getLayout()->getChildBlock('sales.creditmemo.grid', 'grid.export'); - $csvFile = $grid->getCsvFile(); - return $this->_fileFactory->create($fileName, $csvFile, DirectoryList::VAR_DIR); - } -} diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/ExportExcel.php b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/ExportExcel.php deleted file mode 100644 index 8fe35c3d16a05..0000000000000 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/ExportExcel.php +++ /dev/null @@ -1,59 +0,0 @@ -_fileFactory = $fileFactory; - $this->resultLayoutFactory = $resultLayoutFactory; - parent::__construct($context); - } - - /** - * {@inheritdoc} - */ - protected function _isAllowed() - { - return $this->_authorization->isAllowed('Magento_Sales::sales_creditmemo'); - } - - /** - * Export credit memo grid to Excel XML format - * - * @return ResponseInterface - */ - public function execute() - { - $fileName = 'creditmemos.xml'; - $resultLayout = $this->resultLayoutFactory->create(); - $grid = $resultLayout->getLayout()->getChildBlock('sales.creditmemo.grid', 'grid.export'); - $excelFile = $grid->getExcelFile($fileName); - return $this->_fileFactory->create($fileName, $excelFile, DirectoryList::VAR_DIR); - } -} diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php index 12c563f57151d..8753a3f8a4c15 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php @@ -9,31 +9,51 @@ use Magento\Framework\App\ResponseInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Sales\Model\Order\Pdf\Invoice; +use Magento\Framework\Stdlib\DateTime\DateTime; +use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Backend\App\Action\Context; +use Magento\Sales\Model\Resource\Order\Invoice\CollectionFactory; abstract class Pdfinvoices extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { /** - * @var \Magento\Framework\App\Response\Http\FileFactory + * @var FileFactory */ - protected $_fileFactory; + protected $fileFactory; /** - * Resource collection - * - * @var string + * @var DateTime */ - protected $collection = 'Magento\Sales\Model\Resource\Order\Invoice\Grid\Collection'; + protected $dateTime; /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @var Invoice + */ + protected $pdfInvoice; + + /** + * @param Context $context + * @param Filter $filter + * @param DateTime $dateTime + * @param FileFactory $fileFactory + * @param Invoice $pdfInvoice + * @param CollectionFactory $collectionFactory */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + Context $context, + Filter $filter, + DateTime $dateTime, + FileFactory $fileFactory, + Invoice $pdfInvoice, + CollectionFactory $collectionFactory ) { - $this->_fileFactory = $fileFactory; - parent::__construct($context); + $this->fileFactory = $fileFactory; + $this->dateTime = $dateTime; + $this->pdfInvoice = $pdfInvoice; + $this->collectionFactory = $collectionFactory; + parent::__construct($context, $filter); } /** @@ -53,17 +73,9 @@ protected function _isAllowed() */ public function massAction(AbstractCollection $collection) { - if (!isset($pdf)) { - $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Invoice')->getPdf($collection); - } else { - $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Invoice')->getPdf($collection); - $pdf->pages = array_merge($pdf->pages, $pages->pages); - } - $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime')->date('Y-m-d_H-i-s'); - - return $this->_fileFactory->create( - 'invoice' . $date . '.pdf', - $pdf->render(), + return $this->fileFactory->create( + sprintf('invoice%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), + $this->pdfInvoice->getPdf($collection)->render(), DirectoryList::VAR_DIR, 'application/pdf' ); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportCsv.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportCsv.php deleted file mode 100644 index d682c410cfb86..0000000000000 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportCsv.php +++ /dev/null @@ -1,65 +0,0 @@ -_fileFactory = $fileFactory; - parent::__construct($context); - $this->resultLayoutFactory = $resultLayoutFactory; - } - - /** - * {@inheritdoc} - */ - protected function _isAllowed() - { - return $this->_authorization->isAllowed('Magento_Sales::sales_invoice'); - } - - /** - * Export invoice grid to CSV format - * - * @return ResponseInterface - */ - public function execute() - { - $fileName = 'invoices.csv'; - /** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock */ - $exportBlock = $this->resultLayoutFactory->create() - ->getLayout() - ->getChildBlock('sales.invoice.grid', 'grid.export'); - return $this->_fileFactory->create( - $fileName, - $exportBlock->getCsvFile(), - DirectoryList::VAR_DIR - ); - } -} diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportExcel.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportExcel.php deleted file mode 100644 index ab6d4519ffb61..0000000000000 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportExcel.php +++ /dev/null @@ -1,64 +0,0 @@ -_fileFactory = $fileFactory; - parent::__construct($context); - $this->resultLayoutFactory = $resultLayoutFactory; - } - - /** - * {@inheritdoc} - */ - protected function _isAllowed() - { - return $this->_authorization->isAllowed('Magento_Sales::sales_invoice'); - } - - /** - * Export invoice grid to Excel XML format - * - * @return ResponseInterface - */ - public function execute() - { - $fileName = 'invoices.xml'; - $exportBlock = $this->resultLayoutFactory->create() - ->getLayout() - ->getChildBlock('sales.invoice.grid', 'grid.export'); - return $this->_fileFactory->create( - $fileName, - $exportBlock->getExcelFile($fileName), - DirectoryList::VAR_DIR - ); - } -} diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order.php b/app/code/Magento/Sales/Controller/Adminhtml/Order.php index 4232fc9173aba..32e3e51051881 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order.php @@ -6,12 +6,18 @@ namespace Magento\Sales\Controller\Adminhtml; use Magento\Backend\App\Action; +use Magento\Sales\Api\OrderManagementInterface; +use Magento\Sales\Api\OrderRepositoryInterface; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Exception\InputException; +use Psr\Log\LoggerInterface; /** * Adminhtml sales orders controller * * @author Magento Core Team * @SuppressWarnings(PHPMD.NumberOfChildren) + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ abstract class Order extends \Magento\Backend\App\Action { @@ -59,6 +65,21 @@ abstract class Order extends \Magento\Backend\App\Action */ protected $resultRawFactory; + /** + * @var OrderManagementInterface + */ + protected $orderManagement; + + /** + * @var OrderRepositoryInterface + */ + protected $orderRepository; + + /** + * @var LoggerInterface + */ + protected $logger; + /** * @param Action\Context $context * @param \Magento\Framework\Registry $coreRegistry @@ -68,6 +89,12 @@ abstract class Order extends \Magento\Backend\App\Action * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory + * @param OrderManagementInterface $orderManagement + * @param OrderRepositoryInterface $orderRepository + * @param LoggerInterface $logger + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ public function __construct( Action\Context $context, @@ -77,7 +104,10 @@ public function __construct( \Magento\Framework\View\Result\PageFactory $resultPageFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory, - \Magento\Framework\Controller\Result\RawFactory $resultRawFactory + \Magento\Framework\Controller\Result\RawFactory $resultRawFactory, + OrderManagementInterface $orderManagement, + OrderRepositoryInterface $orderRepository, + LoggerInterface $logger ) { $this->_coreRegistry = $coreRegistry; $this->_fileFactory = $fileFactory; @@ -86,6 +116,9 @@ public function __construct( $this->resultJsonFactory = $resultJsonFactory; $this->resultLayoutFactory = $resultLayoutFactory; $this->resultRawFactory = $resultRawFactory; + $this->orderManagement = $orderManagement; + $this->orderRepository = $orderRepository; + $this->logger = $logger; parent::__construct($context); } @@ -106,14 +139,18 @@ protected function _initAction() /** * Initialize order model instance * - * @return \Magento\Sales\Model\Order|false + * @return \Magento\Sales\Api\Data\OrderInterface|false */ protected function _initOrder() { $id = $this->getRequest()->getParam('order_id'); - $order = $this->_objectManager->create('Magento\Sales\Model\Order')->load($id); - - if (!$order->getId()) { + try { + $order = $this->orderRepository->get($id); + } catch (NoSuchEntityException $e) { + $this->messageManager->addError(__('This order no longer exists.')); + $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); + return false; + } catch (InputException $e) { $this->messageManager->addError(__('This order no longer exists.')); $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); return false; diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php index fe4f2aeb163b6..08fbda748c577 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php @@ -7,6 +7,10 @@ use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\ResultInterface; +use Magento\Backend\App\Action\Context; +use Magento\Ui\Component\MassAction\Filter; /** * Class AbstractMassStatus @@ -14,21 +18,29 @@ abstract class AbstractMassAction extends \Magento\Backend\App\Action { /** - * Field id + * @var string */ - const ID_FIELD = 'entity_id'; + protected $redirectUrl = '*/*/'; /** - * Redirect url + * @var \Magento\Ui\Component\MassAction\Filter */ - const REDIRECT_URL = 'sales/order/'; + protected $filter; /** - * Resource collection - * - * @var string + * @var object + */ + protected $collectionFactory; + + /** + * @param Context $context + * @param Filter $filter */ - protected $collection = 'Magento\Sales\Model\Resource\Order\Grid\Collection'; + public function __construct(Context $context, Filter $filter) + { + parent::__construct($context); + $this->filter = $filter; + } /** * Execute action @@ -38,34 +50,32 @@ abstract class AbstractMassAction extends \Magento\Backend\App\Action */ public function execute() { - $selected = $this->getRequest()->getParam('selected'); - $excluded = $this->getRequest()->getParam('excluded'); - - $collection = $this->_objectManager->create($this->collection); try { - if (!empty($excluded)) { - $collection->addFieldToFilter(static::ID_FIELD, ['nin' => $excluded]); - $this->massAction($collection); - } elseif (!empty($selected)) { - $collection->addFieldToFilter(static::ID_FIELD, ['in' => $selected]); - $this->massAction($collection); - } else { - $this->messageManager->addError(__('Please select item(s).')); - } + $collection = $this->filter->getCollection($this->collectionFactory->create()); + return $this->massAction($collection); } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + return $resultRedirect->setPath($this->redirectUrl); } - - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - return $resultRedirect->setPath(static::REDIRECT_URL); } + /** + * Return component referer url + * TODO: Technical dept referer url should be implement as a part of Action configuration in in appropriate way + * + * @return null|string + */ + protected function getComponentRefererUrl() + { + return $this->filter->getComponentRefererUrl()?: 'sales/*/'; + } /** * Set status to collection items * * @param AbstractCollection $collection - * @return void + * @return ResponseInterface|ResultInterface */ abstract protected function massAction(AbstractCollection $collection); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Cancel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Cancel.php index bbe955546d34f..78ddf1b55c588 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Cancel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Cancel.php @@ -19,8 +19,7 @@ public function execute() $resultRedirect = $this->resultRedirectFactory->create(); if ($order) { try { - $orderManagement = $this->_objectManager->get('Magento\Sales\Api\OrderManagementInterface'); - $orderManagement->cancel($order->getEntityId()); + $this->orderManagement->cancel($order->getEntityId()); $this->messageManager->addSuccess(__('You canceled the order.')); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php index 42515bde1f868..54774ec719e7d 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php @@ -7,7 +7,14 @@ namespace Magento\Sales\Controller\Adminhtml\Order; use Magento\Backend\App\Action; +use Magento\Sales\Api\OrderManagementInterface; +use Magento\Sales\Api\OrderRepositoryInterface; +use Psr\Log\LoggerInterface; +/** + * Class CommentsHistory + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class CommentsHistory extends \Magento\Sales\Controller\Adminhtml\Order { /** @@ -24,9 +31,13 @@ class CommentsHistory extends \Magento\Sales\Controller\Adminhtml\Order * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory + * @param OrderManagementInterface $orderManagement + * @param OrderRepositoryInterface $orderRepository + * @param LoggerInterface $logger * @param \Magento\Framework\View\LayoutFactory $layoutFactory * * @SuppressWarnings(PHPMD.ExcessiveParameterList) + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ public function __construct( Action\Context $context, @@ -37,6 +48,9 @@ public function __construct( \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory, + OrderManagementInterface $orderManagement, + OrderRepositoryInterface $orderRepository, + LoggerInterface $logger, \Magento\Framework\View\LayoutFactory $layoutFactory ) { $this->layoutFactory = $layoutFactory; @@ -48,7 +62,10 @@ public function __construct( $resultPageFactory, $resultJsonFactory, $resultLayoutFactory, - $resultRawFactory + $resultRawFactory, + $orderManagement, + $orderRepository, + $logger ); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Reorder.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Reorder.php index 8a6ec65118647..b64cb14c95c39 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Reorder.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Reorder.php @@ -15,7 +15,7 @@ public function execute() $this->_getSession()->clearStorage(); $orderId = $this->getRequest()->getParam('order_id'); $order = $this->_objectManager->create('Magento\Sales\Model\Order')->load($orderId); - if (!$this->_objectManager->get('Magento\Sales\Helper\Reorder')->canReorder($order)) { + if (!$this->_objectManager->get('Magento\Sales\Helper\Reorder')->canReorder($order->getEntityId())) { return $this->resultForwardFactory->create()->forward('noroute'); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Email.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Email.php index cae0ea11baacd..ae1763485bdbc 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Email.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Email.php @@ -17,16 +17,20 @@ public function execute() $order = $this->_initOrder(); if ($order) { try { - $orderManagement = $this->_objectManager->create('Magento\Sales\Api\OrderManagementInterface'); - $orderManagement->notify($order->getEntityId()); + $this->orderManagement->notify($order->getEntityId()); $this->messageManager->addSuccess(__('You sent the order email.')); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError(__('We can\'t send the email order right now.')); - $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); + $this->logger->critical($e); } - return $this->resultRedirectFactory->create()->setPath('sales/order/view', ['order_id' => $order->getId()]); + return $this->resultRedirectFactory->create()->setPath( + 'sales/order/view', + [ + 'order_id' => $order->getEntityId() + ] + ); } return $this->resultRedirectFactory->create()->setPath('sales/*/'); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/ExportCsv.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/ExportCsv.php deleted file mode 100644 index 6c80caafe4184..0000000000000 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/ExportCsv.php +++ /dev/null @@ -1,28 +0,0 @@ -resultPageFactory->create() - ->getLayout() - ->getChildBlock('sales.order.grid', 'grid.export'); - return $this->_fileFactory->create($fileName, $exportBlock->getCsvFile(), DirectoryList::VAR_DIR); - } -} diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/ExportExcel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/ExportExcel.php deleted file mode 100644 index 9cb3c880464f2..0000000000000 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/ExportExcel.php +++ /dev/null @@ -1,28 +0,0 @@ -resultPageFactory->create() - ->getLayout() - ->getChildBlock('sales.order.grid', 'grid.export'); - return $this->_fileFactory->create($fileName, $exportBlock->getExcelFile($fileName), DirectoryList::VAR_DIR); - } -} diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Hold.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Hold.php index ba69fe6510059..a03f07f99dd2d 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Hold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Hold.php @@ -18,8 +18,7 @@ public function execute() $resultRedirect = $this->resultRedirectFactory->create(); if ($order) { try { - $orderManagement = $this->_objectManager->get('Magento\Sales\Api\OrderManagementInterface'); - $orderManagement->hold($order->getEntityId()); + $this->orderManagement->hold($order->getEntityId()); $this->messageManager->addSuccess(__('You put the order on hold.')); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php index 24330e58bf0d8..46a83b9afb198 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php @@ -6,26 +6,38 @@ namespace Magento\Sales\Controller\Adminhtml\Order; use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; +use Magento\Backend\App\Action\Context; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Sales\Model\Resource\Order\CollectionFactory; class MassCancel extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { + /** + * @param Context $context + * @param Filter $filter + * @param CollectionFactory $collectionFactory + */ + public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) + { + parent::__construct($context, $filter); + $this->collectionFactory = $collectionFactory; + } + /** * Cancel selected orders * * @param AbstractCollection $collection - * @return void + * @return \Magento\Backend\Model\View\Result\Redirect */ protected function massAction(AbstractCollection $collection) { $countCancelOrder = 0; - - /** @var \Magento\Sales\Api\OrderManagementInterface $orderManagement */ - $orderManagement = $this->_objectManager->get('Magento\Sales\Api\OrderManagementInterface'); foreach ($collection->getItems() as $order) { if (!$order->canCancel()) { continue; } - $orderManagement->cancel($order->getEntityId()); + $order->cancel(); + $order->save(); $countCancelOrder++; } $countNonCancelOrder = $collection->count() - $countCancelOrder; @@ -39,5 +51,8 @@ protected function massAction(AbstractCollection $collection) if ($countCancelOrder) { $this->messageManager->addSuccess(__('We canceled %1 order(s).', $countCancelOrder)); } + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath($this->getComponentRefererUrl()); + return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php index cce9ab02eb325..9f660fd61f6cd 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php @@ -6,9 +6,38 @@ namespace Magento\Sales\Controller\Adminhtml\Order; use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; +use Magento\Backend\App\Action\Context; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Sales\Model\Resource\Order\CollectionFactory; +use Magento\Sales\Api\OrderManagementInterface; +/** + * Class MassHold + */ class MassHold extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { + /** + * @var OrderManagementInterface + */ + protected $orderManagement; + + /** + * @param Context $context + * @param Filter $filter + * @param CollectionFactory $collectionFactory + * @param OrderManagementInterface $orderManagement + */ + public function __construct( + Context $context, + Filter $filter, + CollectionFactory $collectionFactory, + OrderManagementInterface $orderManagement + ) { + parent::__construct($context, $filter); + $this->collectionFactory = $collectionFactory; + $this->orderManagement = $orderManagement; + } + /** * Hold selected orders * @@ -18,12 +47,11 @@ class MassHold extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAct protected function massAction(AbstractCollection $collection) { $countHoldOrder = 0; - $orderManagement = $this->_objectManager->get('Magento\Sales\Api\OrderManagementInterface'); foreach ($collection->getItems() as $order) { if (!$order->canHold()) { continue; } - $orderManagement->hold($order->getEntityId()); + $this->orderManagement->hold($order->getEntityId()); $countHoldOrder++; } $countNonHoldOrder = $collection->count() - $countHoldOrder; @@ -39,7 +67,7 @@ protected function massAction(AbstractCollection $collection) } $resultRedirect = $this->resultRedirectFactory->create(); - $resultRedirect->setPath('sales/*/'); + $resultRedirect->setPath($this->getComponentRefererUrl()); return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php index 307f8dae53735..cdbdf98f37eb0 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php @@ -6,13 +6,22 @@ namespace Magento\Sales\Controller\Adminhtml\Order; use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; +use Magento\Backend\App\Action\Context; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Sales\Model\Resource\Order\CollectionFactory; -class MassUnhold extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction +class MassUnhold extends AbstractMassAction { /** - * @var string + * @param Context $context + * @param Filter $filter + * @param CollectionFactory $collectionFactory */ - protected $collection = 'Magento\Sales\Model\Resource\Order\Collection'; + public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) + { + parent::__construct($context, $filter); + $this->collectionFactory = $collectionFactory; + } /** * Unhold selected orders @@ -24,12 +33,14 @@ protected function massAction(AbstractCollection $collection) { $countUnHoldOrder = 0; - $orderManagement = $this->_objectManager->get('Magento\Sales\Api\OrderManagementInterface'); + /** @var \Magento\Sales\Model\Order $order */ foreach ($collection->getItems() as $order) { + $order->load($order->getId()); if (!$order->canUnhold()) { continue; } - $orderManagement->unHold($order->getEntityId()); + $order->unhold(); + $order->save(); $countUnHoldOrder++; } @@ -49,7 +60,7 @@ protected function massAction(AbstractCollection $collection) ); } $resultRedirect = $this->resultRedirectFactory->create(); - $resultRedirect->setPath('sales/*/'); + $resultRedirect->setPath($this->getComponentRefererUrl()); return $resultRedirect; } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php index 24d9f9d69a654..81da53f4b9f8e 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php @@ -8,47 +8,83 @@ use Magento\Framework\App\ResponseInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Sales\Model\Order\Pdf\Creditmemo; +use Magento\Framework\Stdlib\DateTime\DateTime; +use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Backend\App\Action\Context; +use Magento\Framework\Controller\ResultInterface; +use Magento\Sales\Model\Resource\Order\Creditmemo\CollectionFactory; +use Magento\Sales\Model\Resource\Order\Collection as OrderCollection; +/** + * Class Pdfcreditmemos + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class Pdfcreditmemos extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { + /** + * @var FileFactory + */ + protected $fileFactory; + + /** + * @var DateTime + */ + protected $dateTime; + + /** + * @var Creditmemo + */ + protected $pdfCreditmemo; + + /** + * @var CollectionFactory + */ + protected $collectionFactory; + + /** + * @param Context $context + * @param Filter $filter + * @param CollectionFactory $collectionFactory + * @param DateTime $dateTime + * @param FileFactory $fileFactory + * @param Creditmemo $pdfCreditmemo + */ + public function __construct( + Context $context, + Filter $filter, + CollectionFactory $collectionFactory, + DateTime $dateTime, + FileFactory $fileFactory, + Creditmemo $pdfCreditmemo + ) { + $this->fileFactory = $fileFactory; + $this->dateTime = $dateTime; + $this->pdfCreditmemo = $pdfCreditmemo; + $this->collectionFactory = $collectionFactory; + parent::__construct($context, $filter); + } + /** * Print credit memos for selected orders * * @param AbstractCollection $collection - * @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect + * @return ResponseInterface|ResultInterface */ protected function massAction(AbstractCollection $collection) { - $resultRedirect = $this->resultRedirectFactory->create(); - $flag = false; - /** @var \Magento\Sales\Model\Order $order */ - foreach ($collection->getItems() as $order) { - $creditmemos = $order->getCreditmemosCollection(); - if ($creditmemos->getSize()) { - $flag = true; - if (!isset($pdf)) { - $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Creditmemo') - ->getPdf($creditmemos); - } else { - $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Creditmemo') - ->getPdf($creditmemos); - $pdf->pages = array_merge($pdf->pages, $pages->pages); - } - } - } - if ($flag) { - $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime') - ->date('Y-m-d_H-i-s'); - return $this->_fileFactory->create( - 'creditmemo' . $date . '.pdf', - $pdf->render(), - DirectoryList::VAR_DIR, - 'application/pdf' - ); - } else { + + $creditmemoCollection = $this->collectionFactory->create()->setOrderFilter(['in' => $collection->getAllIds()]); + if (!$creditmemoCollection->getSize()) { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); - $resultRedirect->setPath('sales/*/'); - return $resultRedirect; + 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' + ); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php index 352abdf5bc265..53dc90c91e2ed 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php @@ -8,7 +8,22 @@ use Magento\Framework\App\ResponseInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; +use Magento\Sales\Model\Order\Pdf\Invoice; +use Magento\Backend\App\Action\Context; +use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Sales\Model\Order\Pdf\Shipment; +use Magento\Sales\Model\Order\Pdf\Creditmemo; +use Magento\Framework\Stdlib\DateTime\DateTime; +use Magento\Sales\Model\Resource\Order\CollectionFactory as OrderCollectionFactory; +use Magento\Sales\Model\Resource\Order\Shipment\CollectionFactory as ShipmentCollectionFactory; +use Magento\Sales\Model\Resource\Order\Invoice\CollectionFactory as InvoiceCollectionFactory; +use Magento\Sales\Model\Resource\Order\Creditmemo\CollectionFactory as CreditmemoCollectionFactory; +/** + * Class Pdfdocs + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class Pdfdocs extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { /** @@ -17,15 +32,77 @@ class Pdfdocs extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassActi protected $fileFactory; /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @var Invoice + */ + protected $pdfInvoice; + + /** + * @var Shipment + */ + protected $pdfShipment; + + /** + * @var Creditmemo + */ + protected $pdfCreditmemo; + + /** + * @var DateTime + */ + protected $dateTime; + + /** + * @var ShipmentCollectionFactory + */ + protected $shipmentCollectionFactory; + + /** + * @var InvoiceCollectionFactory + */ + protected $invoiceCollectionFactory; + + /** + * @var CreditmemoCollectionFactory + */ + protected $creditmemoCollectionFactory; + + /** + * @param Context $context + * @param Filter $filter + * @param FileFactory $fileFactory + * @param Invoice $pdfInvoice + * @param Shipment $pdfShipment + * @param Creditmemo $pdfCreditmemo + * @param DateTime $dateTime + * @param ShipmentCollectionFactory $shipmentCollectionFactory + * @param InvoiceCollectionFactory $invoiceCollectionFactory + * @param CreditmemoCollectionFactory $creditmemoCollectionFactory + * @param OrderCollectionFactory $orderCollectionFactory + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + Context $context, + Filter $filter, + FileFactory $fileFactory, + Invoice $pdfInvoice, + Shipment $pdfShipment, + Creditmemo $pdfCreditmemo, + DateTime $dateTime, + ShipmentCollectionFactory $shipmentCollectionFactory, + InvoiceCollectionFactory $invoiceCollectionFactory, + CreditmemoCollectionFactory $creditmemoCollectionFactory, + OrderCollectionFactory $orderCollectionFactory ) { + $this->pdfInvoice = $pdfInvoice; + $this->pdfShipment = $pdfShipment; + $this->pdfCreditmemo = $pdfCreditmemo; $this->fileFactory = $fileFactory; - parent::__construct($context); + $this->dateTime = $dateTime; + $this->shipmentCollectionFactory = $shipmentCollectionFactory; + $this->invoiceCollectionFactory = $invoiceCollectionFactory; + $this->creditmemoCollectionFactory = $creditmemoCollectionFactory; + $this->collectionFactory = $orderCollectionFactory; + parent::__construct($context, $filter); } /** @@ -38,62 +115,38 @@ public function __construct( */ protected function massAction(AbstractCollection $collection) { - $resultRedirect = $this->resultRedirectFactory->create(); - $flag = false; - /** @var \Magento\Sales\Model\Order $order */ - foreach ($collection->getItems() as $order) { - $invoices = $order->getInvoiceCollection(); - if ($invoices->getSize()) { - $flag = true; - if (!isset($pdf)) { - $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Invoice') - ->getPdf($invoices); - } else { - $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Invoice') - ->getPdf($invoices); - $pdf->pages = array_merge($pdf->pages, $pages->pages); - } - } - - $shipments = $order->getShipmentsCollection(); - if ($shipments->getSize()) { - $flag = true; - if (!isset($pdf)) { - $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Shipment') - ->getPdf($shipments); - } else { - $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Shipment') - ->getPdf($shipments); - $pdf->pages = array_merge($pdf->pages, $pages->pages); - } - } - - $creditmemos = $order->getCreditmemosCollection(); - if ($creditmemos->getSize()) { - $flag = true; - if (!isset($pdf)) { - $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Creditmemo') - ->getPdf($creditmemos); - } else { - $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Creditmemo') - ->getPdf($creditmemos); - $pdf->pages = array_merge($pdf->pages, $pages->pages); - } - } + $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 ($flag) { - $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime') - ->date('Y-m-d_H-i-s'); - return $this->fileFactory->create( - 'docs' . $date . '.pdf', - $pdf->render(), - DirectoryList::VAR_DIR, - 'application/pdf' - ); - } else { + if ($creditmemos->getSize()) { + $documents[] = $this->pdfCreditmemo->getPdf($creditmemos); + } + + if (empty($documents)) { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); - $resultRedirect->setPath('sales/*/'); - return $resultRedirect; + 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' + ); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php index be03358130a1c..1eb43a64759a7 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php @@ -8,64 +8,78 @@ use Magento\Framework\App\ResponseInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Sales\Model\Order\Pdf\Invoice; +use Magento\Framework\Stdlib\DateTime\DateTime; +use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Backend\App\Action\Context; +use Magento\Framework\Controller\ResultInterface; +use Magento\Sales\Model\Resource\Order\Invoice\CollectionFactory; +use Magento\Sales\Model\Resource\Order\Collection as OrderCollection; class Pdfinvoices extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { /** - * @var \Magento\Framework\App\Response\Http\FileFactory + * @var FileFactory */ protected $fileFactory; /** - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @var DateTime + */ + protected $dateTime; + + /** + * @var Invoice + */ + protected $pdfInvoice; + + /** + * @var CollectionFactory + */ + protected $collectionFactory; + + /** + * @param Context $context + * @param Filter $filter + * @param CollectionFactory $collectionFactory + * @param DateTime $dateTime + * @param FileFactory $fileFactory + * @param Invoice $pdfInvoice */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + Context $context, + Filter $filter, + CollectionFactory $collectionFactory, + DateTime $dateTime, + FileFactory $fileFactory, + Invoice $pdfInvoice ) { $this->fileFactory = $fileFactory; - parent::__construct($context); + $this->dateTime = $dateTime; + $this->pdfInvoice = $pdfInvoice; + $this->collectionFactory = $collectionFactory; + parent::__construct($context, $filter); } /** * Print invoices for selected orders * * @param AbstractCollection $collection - * @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect + * @return ResponseInterface|ResultInterface */ protected function massAction(AbstractCollection $collection) { - $resultRedirect = $this->resultRedirectFactory->create(); - $flag = false; - /** @var \Magento\Sales\Model\Order $order */ - foreach ($collection->getItems() as $order) { - $invoices = $order->getInvoiceCollection(); - if ($invoices->getSize() > 0) { - $flag = true; - if (!isset($pdf)) { - $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Invoice') - ->getPdf($invoices); - } else { - $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Invoice') - ->getPdf($invoices); - $pdf->pages = array_merge($pdf->pages, $pages->pages); - } - } - } - if ($flag) { - $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime') - ->date('Y-m-d_H-i-s'); - return $this->fileFactory->create( - 'invoice' . $date . '.pdf', - $pdf->render(), - DirectoryList::VAR_DIR, - 'application/pdf' - ); - } else { + $invoicesCollection = $this->collectionFactory->create()->setOrderFilter(['in' => $collection->getAllIds()]); + if (!$invoicesCollection->getSize()) { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); - $resultRedirect->setPath('sales/*/'); - return $resultRedirect; + return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl()); } + return $this->fileFactory->create( + sprintf('packingslip%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), + $this->pdfInvoice->getPdf($invoicesCollection->getItems())->render(), + DirectoryList::VAR_DIR, + 'application/pdf' + ); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php index ddcd0677c09ff..4c9b57a55558a 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php @@ -8,9 +8,66 @@ use Magento\Framework\App\ResponseInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; +use Magento\Backend\App\Action\Context; +use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Sales\Model\Order\Pdf\Shipment; +use Magento\Framework\Stdlib\DateTime\DateTime; +use Magento\Sales\Model\Resource\Order\Shipment\CollectionFactory as ShipmentCollectionFactory; +use Magento\Sales\Model\Resource\Order\CollectionFactory; +/** + * Class Pdfshipments + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class Pdfshipments extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { + /** + * @var FileFactory + */ + protected $fileFactory; + + /** + * @var DateTime + */ + protected $dateTime; + + /** + * @var Shipment + */ + protected $pdfShipment; + + /** + * @var ShipmentCollectionFactory + */ + protected $shipmentCollectionFactotory; + + /** + * @param Context $context + * @param Filter $filter + * @param CollectionFactory $collectionFactory + * @param DateTime $dateTime + * @param FileFactory $fileFactory + * @param Shipment $shipment + * @param ShipmentCollectionFactory $shipmentCollectionFactory + */ + public function __construct( + Context $context, + Filter $filter, + CollectionFactory $collectionFactory, + DateTime $dateTime, + FileFactory $fileFactory, + Shipment $shipment, + ShipmentCollectionFactory $shipmentCollectionFactory + ) { + $this->fileFactory = $fileFactory; + $this->dateTime = $dateTime; + $this->pdfShipment = $shipment; + $this->collectionFactory = $collectionFactory; + $this->shipmentCollectionFactotory = $shipmentCollectionFactory; + parent::__construct($context, $filter); + } + /** * Print shipments for selected orders * @@ -19,36 +76,18 @@ class Pdfshipments extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMas */ protected function massAction(AbstractCollection $collection) { - $resultRedirect = $this->resultRedirectFactory->create(); - $flag = false; - /** @var \Magento\Sales\Model\Order $order */ - foreach ($collection->getItems() as $order) { - $shipments = $order->getShipmentsCollection(); - if ($shipments->getSize()) { - $flag = true; - if (!isset($pdf)) { - $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Shipment') - ->getPdf($shipments); - } else { - $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Shipment') - ->getPdf($shipments); - $pdf->pages = array_merge($pdf->pages, $pages->pages); - } - } - } - if ($flag) { - $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime') - ->date('Y-m-d_H-i-s'); - return $this->_fileFactory->create( - 'packingslip' . $date . '.pdf', - $pdf->render(), - DirectoryList::VAR_DIR, - 'application/pdf' - ); - } else { + $shipmentsCollection = $this->shipmentCollectionFactotory + ->create() + ->setOrderFilter(['in' => $collection->getAllIds()]); + if (!$shipmentsCollection->getSize()) { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); - $resultRedirect->setPath('sales/*/'); - return $resultRedirect; + return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl()); } + return $this->fileFactory->create( + sprintf('packingslip%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), + $this->pdfShipment->getPdf($shipmentsCollection->getItems())->render(), + DirectoryList::VAR_DIR, + 'application/pdf' + ); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/ReviewPayment.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/ReviewPayment.php index 1b5c239c17835..8a0d64c9bcb6e 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/ReviewPayment.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/ReviewPayment.php @@ -45,7 +45,7 @@ public function execute() default: throw new \Exception(sprintf('Action "%s" is not supported.', $action)); } - $order->save(); + $this->orderRepository->save($order); $this->messageManager->addSuccess($message); } else { $resultRedirect->setPath('sales/*/'); @@ -55,9 +55,9 @@ public function execute() $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError(__('We can\'t update the payment right now.')); - $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); + $this->logger->critical($e); } - $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]); + $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getEntityId()]); return $resultRedirect; } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Unhold.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Unhold.php index 186e70709e3ba..7ea8dfbb7a48d 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Unhold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Unhold.php @@ -18,11 +18,10 @@ public function execute() $resultRedirect = $this->resultRedirectFactory->create(); if ($order) { try { - $orderManagement = $this->_objectManager->get('Magento\Sales\Api\OrderManagementInterface'); if (!$order->canUnhold()) { throw new \Magento\Framework\Exception\LocalizedException(__('Can\'t unhold order.')); } - $orderManagement->unhold($order->getEntityId()); + $this->orderManagement->unhold($order->getEntityId()); $this->messageManager->addSuccess(__('You released the order from holding status.')); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/View.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/View.php index e4881766b1b04..831538fa21d11 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/View.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/View.php @@ -23,12 +23,12 @@ public function execute() $resultPage = $this->_initAction(); $resultPage->getConfig()->getTitle()->prepend(__('Orders')); } catch (\Exception $e) { - $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); + $this->logger->critical($e); $this->messageManager->addError(__('Exception occurred during order load')); $resultRedirect->setPath('sales/order/index'); return $resultRedirect; } - $resultPage->getConfig()->getTitle()->prepend(sprintf("#%s", $order->getRealOrderId())); + $resultPage->getConfig()->getTitle()->prepend(sprintf("#%s", $order->getIncrementId())); return $resultPage; } $resultRedirect->setPath('sales/*/'); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php index 8c0b9baa42114..7a0ee9b827cc0 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php @@ -11,28 +11,49 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\Response\Http\FileFactory; use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Sales\Model\Order\Pdf\Shipment; +use Magento\Framework\Stdlib\DateTime\DateTime; +use Magento\Sales\Model\Resource\Order\Shipment\CollectionFactory; abstract class Pdfshipments extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { /** * @var FileFactory */ - protected $_fileFactory; + protected $fileFactory; + /** - * Resource collection - * - * @var string + * @var DateTime */ - protected $collection = 'Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection'; + protected $dateTime; + + /** + * @var Shipment + */ + protected $pdfShipment; /** * @param Context $context + * @param Filter $filter + * @param DateTime $dateTime * @param FileFactory $fileFactory + * @param Shipment $shipment + * @param CollectionFactory $collectionFactory */ - public function __construct(Context $context, FileFactory $fileFactory) - { - $this->_fileFactory = $fileFactory; - parent::__construct($context); + public function __construct( + Context $context, + Filter $filter, + DateTime $dateTime, + FileFactory $fileFactory, + Shipment $shipment, + CollectionFactory $collectionFactory + ) { + $this->fileFactory = $fileFactory; + $this->dateTime = $dateTime; + $this->pdfShipment = $shipment; + $this->collectionFactory = $collectionFactory; + parent::__construct($context, $filter); } /** @@ -50,16 +71,9 @@ protected function _isAllowed() */ public function massAction(AbstractCollection $collection) { - if (!isset($pdf)) { - $pdf = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Shipment')->getPdf($collection); - } else { - $pages = $this->_objectManager->create('Magento\Sales\Model\Order\Pdf\Shipment')->getPdf($collection); - $pdf->pages = array_merge($pdf->pages, $pages->pages); - } - $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime')->date('Y-m-d_H-i-s'); - return $this->_fileFactory->create( - 'packingslip' . $date . '.pdf', - $pdf->render(), + return $this->fileFactory->create( + sprintf('packingslip%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), + $this->pdfShipment->getPdf($collection)->render(), DirectoryList::VAR_DIR, 'application/pdf' ); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportCsv.php b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportCsv.php deleted file mode 100644 index 301d7fceacf20..0000000000000 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportCsv.php +++ /dev/null @@ -1,67 +0,0 @@ -_fileFactory = $fileFactory; - $this->resultLayoutFactory = $resultLayoutFactory; - } - - /** - * @return bool - */ - protected function _isAllowed() - { - return $this->_authorization->isAllowed('Magento_Sales::shipment'); - } - - /** - * Export shipment grid to CSV format - * - * @return ResponseInterface - */ - public function execute() - { - $fileName = 'shipments.csv'; - /** @var \Magento\Framework\View\Result\Layout $resultLayout */ - $resultLayout = $this->resultLayoutFactory->create(); - $grid = $resultLayout->getLayout()->getChildBlock('sales.shipment.grid', 'grid.export'); - return $this->_fileFactory->create( - $fileName, - $grid->getCsvFile(), - DirectoryList::VAR_DIR - ); - } -} diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportExcel.php b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportExcel.php deleted file mode 100644 index 45f47691e9856..0000000000000 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportExcel.php +++ /dev/null @@ -1,67 +0,0 @@ -_fileFactory = $fileFactory; - $this->resultLayoutFactory = $resultLayoutFactory; - parent::__construct($context); - } - - /** - * @return bool - */ - protected function _isAllowed() - { - return $this->_authorization->isAllowed('Magento_Sales::shipment'); - } - - /** - * Export shipment grid to Excel XML format - * - * @return ResponseInterface - */ - public function execute() - { - $fileName = 'shipments.xml'; - /** @var \Magento\Framework\View\Result\Layout $resultLayout */ - $resultLayout = $this->resultLayoutFactory->create(); - $grid = $resultLayout->getLayout()->getChildBlock('sales.shipment.grid', 'grid.export'); - return $this->_fileFactory->create( - $fileName, - $grid->getExcelFile($fileName), - DirectoryList::VAR_DIR - ); - } -} diff --git a/app/code/Magento/Sales/Helper/Reorder.php b/app/code/Magento/Sales/Helper/Reorder.php index 56ee37c0e0891..6c735c919ad00 100644 --- a/app/code/Magento/Sales/Helper/Reorder.php +++ b/app/code/Magento/Sales/Helper/Reorder.php @@ -18,17 +18,25 @@ class Reorder extends \Magento\Framework\App\Helper\AbstractHelper /** * @var \Magento\Customer\Model\Session */ - protected $_customerSession; + protected $customerSession; + + /** + * @var \Magento\Sales\Api\OrderRepositoryInterface + */ + protected $orderRepository; /** * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository */ public function __construct( \Magento\Framework\App\Helper\Context $context, - \Magento\Customer\Model\Session $customerSession + \Magento\Customer\Model\Session $customerSession, + \Magento\Sales\Api\OrderRepositoryInterface $orderRepository ) { - $this->_customerSession = $customerSession; + $this->orderRepository = $orderRepository; + $this->customerSession = $customerSession; parent::__construct( $context ); @@ -57,15 +65,18 @@ public function isAllowed($store = null) } /** - * @param \Magento\Sales\Model\Order $order + * Check is it possible to reorder + * + * @param int $orderId * @return bool */ - public function canReorder(\Magento\Sales\Model\Order $order) + public function canReorder($orderId) { + $order = $this->orderRepository->get($orderId); if (!$this->isAllowed($order->getStore())) { return false; } - if ($this->_customerSession->isLoggedIn()) { + if ($this->customerSession->isLoggedIn()) { return $order->canReorder(); } else { return true; diff --git a/app/code/Magento/Sales/Model/Order.php b/app/code/Magento/Sales/Model/Order.php index 87dffadfa8dfd..e7982a26035c1 100755 --- a/app/code/Magento/Sales/Model/Order.php +++ b/app/code/Magento/Sales/Model/Order.php @@ -1397,13 +1397,13 @@ public function addPayment(Payment $payment) } /** - * @param Payment $payment + * @param \Magento\Sales\Api\Data\OrderPaymentInterface $payment * @return Payment */ - public function setPayment(Payment $payment) + public function setPayment(\Magento\Sales\Api\Data\OrderPaymentInterface $payment) { - if (!$this->getIsMultiPayment() && ($old = $this->getPayment())) { - $payment->setId($old->getId()); + if (!$this->getIsMultiPayment() && ($previousPayment = $this->getPayment())) { + $payment->setEntityId($previousPayment->getEntityId()); } $this->addPayment($payment); return $payment; diff --git a/app/code/Magento/Sales/Model/Order/Builder.php b/app/code/Magento/Sales/Model/Order/Builder.php deleted file mode 100644 index f0c2e25e4cdb4..0000000000000 --- a/app/code/Magento/Sales/Model/Order/Builder.php +++ /dev/null @@ -1,387 +0,0 @@ -orderFactory = $orderFactory; - } - - /** - * @param Customer $customer - * @return $this - */ - public function setCustomer(Customer $customer) - { - $this->customer = $customer; - return $this; - } - - /** - * @param Address $address - * @return $this - */ - public function setShippingAddress(Address $address) - { - $this->shippingAddress = $address; - return $this; - } - - /** - * @param Address $address - * @return $this - */ - public function setBillingAddress(Address $address) - { - $this->billingAddress = $address; - return $this; - } - - /** - * @param int $quoteId - * @return $this - */ - public function setQuoteId($quoteId) - { - $this->quoteId = $quoteId; - return $this; - } - - /** - * @param array $appliedRuleIds - * @return $this - */ - public function setAppliedRuleIds($appliedRuleIds) - { - $this->appliedRuleIds = $appliedRuleIds; - return $this; - } - - /** - * @param int $isVirtual - * @return $this - */ - public function setIsVirtual($isVirtual) - { - $this->isVirtual = $isVirtual; - return $this; - } - - /** - * @param string $remoteIp - * @return $this - */ - public function setRemoteIp($remoteIp) - { - $this->remoteIp = $remoteIp; - return $this; - } - - /** - * @param string $baseSubtotal - * @return $this - */ - public function setBaseSubtotal($baseSubtotal) - { - $this->baseSubtotal = $baseSubtotal; - return $this; - } - - /** - * @param string $subtotal - * @return $this - */ - public function setSubtotal($subtotal) - { - $this->subtotal = $subtotal; - return $this; - } - - /** - * @param string $baseGrandTotal - * @return $this - */ - public function setBaseGrandTotal($baseGrandTotal) - { - $this->baseGrandTotal = $baseGrandTotal; - return $this; - } - - /** - * @param string $grandTotal - * @return $this - */ - public function setGrandTotal($grandTotal) - { - $this->grandTotal = $grandTotal; - return $this; - } - - /** - * @param string $baseCurrencyCode - * @return $this - */ - public function setBaseCurrencyCode($baseCurrencyCode) - { - $this->baseCurrencyCode = $baseCurrencyCode; - return $this; - } - - /** - * @param string $globalCurrencyCode - * @return $this - */ - public function setGlobalCurrencyCode($globalCurrencyCode) - { - $this->globalCurrencyCode = $globalCurrencyCode; - return $this; - } - - /** - * @param string $storeCurrencyCode - * @return $this - */ - public function setStoreCurrencyCode($storeCurrencyCode) - { - $this->storeCurrencyCode = $storeCurrencyCode; - return $this; - } - - /** - * @param int $storeId - * @return $this - */ - public function setStoreId($storeId) - { - $this->storeId = $storeId; - return $this; - } - - /** - * @param string $storeToBaseRate - * @return $this - */ - public function setStoreToBaseRate($storeToBaseRate) - { - $this->storeToBaseRate = $storeToBaseRate; - return $this; - } - - /** - * @param string $baseToGlobalRate - * @return $this - */ - public function setBaseToGlobalRate($baseToGlobalRate) - { - $this->baseToGlobalRate = $baseToGlobalRate; - return $this; - } - - /** - * @param string $couponCode - * @return $this - */ - public function setCouponCode($couponCode) - { - $this->couponCode = $couponCode; - return $this; - } - - /** - * @param Item[] $items - * @return $this - */ - public function setItems($items) - { - $this->items = $items; - return $this; - } - - /** - * @param Payment[] $payments - * @return $this - */ - public function setPayments($payments) - { - $this->payments = $payments; - return $this; - } - - /** - * @return \Magento\Sales\Model\Order - * @throws \Exception - */ - public function create() - { - /**@var $order \Magento\Sales\Model\Order */ - $order = $this->orderFactory->create([ - 'data' => [ - 'quote_id' => $this->quoteId, - 'applied_rule_ids' => $this->appliedRuleIds, - 'is_virtual' => $this->isVirtual, - 'remote_ip' => $this->remoteIp, - 'base_subtotal' => $this->baseSubtotal, - 'subtotal' => $this->subtotal, - 'base_grand_total' => $this->baseGrandTotal, - 'grand_total' => $this->grandTotal, - 'base_currency_code' => $this->baseCurrencyCode, - 'global_currency_code' => $this->globalCurrencyCode, - 'store_currency_code' => $this->storeCurrencyCode, - 'store_id' => $this->storeId, - 'store_to_base_rate' => $this->storeToBaseRate, - 'base_to_global_rate' => $this->baseToGlobalRate, - 'coupon_code' => $this->couponCode, - 'customer_dob' => $this->customer->getDob(), - 'customer_email' => $this->customer->getEmail(), - 'customer_firstname' => $this->customer->getFirstName(), - 'customer_gender' => $this->customer->getGender(), - 'customer_group_id' => $this->customer->getGroupId(), - 'customer_id' => $this->customer->getId(), - 'customer_is_guest' => $this->customer->getIsGuest(), - 'customer_lastname' => $this->customer->getLastName(), - 'customer_middlename' => $this->customer->getMiddleName(), - 'customer_note' => $this->customer->getNote(), - 'customer_note_notify' => $this->customer->getNoteNotify(), - 'customer_prefix' => $this->customer->getPrefix(), - 'customer_suffix' => $this->customer->getSuffix(), - 'customer_taxvat' => $this->customer->getTaxvat(), - ], - ]); - $order->setBillingAddress($this->billingAddress) - ->setShippingAddress($this->shippingAddress); - foreach ($this->items as $item) { - if ($item instanceof Item) { - $order->addItem($item); - } else { - throw new \InvalidArgumentException('Cannot add item, instance of wrong type is given'); - } - } - foreach ($this->payments as $payment) { - if ($payment instanceof Payment) { - $order->addPayment($payment); - } else { - throw new \InvalidArgumentException('Cannot add payment, instance of wrong type is given'); - } - } - return $order; - } -} diff --git a/app/code/Magento/Sales/Model/Order/Customer.php b/app/code/Magento/Sales/Model/Order/Customer.php deleted file mode 100644 index 87fb453e710f7..0000000000000 --- a/app/code/Magento/Sales/Model/Order/Customer.php +++ /dev/null @@ -1,241 +0,0 @@ -customerDob = $customerDob; - $this->customerEmail = $customerEmail; - $this->customerFirstName = $customerFirstName; - $this->customerGender = $customerGender; - $this->customerGroupId = $customerGroupId; - $this->customerId = $customerId; - $this->customerIsGuest = $customerIsGuest; - $this->customerLastName = $customerLastName; - $this->customerMiddleName = $customerMiddleName; - $this->customerNote = $customerNote; - $this->customerNoteNotify = $customerNoteNotify; - $this->customerPrefix = $customerPrefix; - $this->customerSuffix = $customerSuffix; - $this->customerTaxvat = $customerTaxvat; - } - - /** - * @return string - */ - public function getDob() - { - return $this->customerDob; - } - - /** - * @return string - */ - public function getEmail() - { - return $this->customerEmail; - } - - /** - * @return string - */ - public function getFirstName() - { - return $this->customerFirstName; - } - - /** - * @return string - */ - public function getGender() - { - return $this->customerGender; - } - - /** - * @return string - */ - public function getGroupId() - { - return $this->customerGroupId; - } - - /** - * @return string - */ - public function getId() - { - return $this->customerId; - } - - /** - * @return string - */ - public function getIsGuest() - { - return $this->customerIsGuest; - } - - /** - * @return string - */ - public function getLastName() - { - return $this->customerLastName; - } - - /** - * @return string - */ - public function getMiddleName() - { - return $this->customerMiddleName; - } - - /** - * @return string - */ - public function getNote() - { - return $this->customerNote; - } - - /** - * @return string - */ - public function getNoteNotify() - { - return $this->customerNoteNotify; - } - - /** - * @return string - */ - public function getPrefix() - { - return $this->customerPrefix; - } - - /** - * @return string - */ - public function getSuffix() - { - return $this->customerSuffix; - } - - /** - * @return string - */ - public function getTaxvat() - { - return $this->customerTaxvat; - } -} diff --git a/app/code/Magento/Sales/Model/Order/Customer/Builder.php b/app/code/Magento/Sales/Model/Order/Customer/Builder.php deleted file mode 100644 index 9106e71fad825..0000000000000 --- a/app/code/Magento/Sales/Model/Order/Customer/Builder.php +++ /dev/null @@ -1,260 +0,0 @@ -objectManager = $objectManager; - } - - /** - * @param string $customerDob - * @return \Magento\Sales\Model\Order\Customer\Builder - */ - public function setDob($customerDob) - { - $this->customerDob = $customerDob; - return $this; - } - - /** - * @param string $customerEmail - * @return \Magento\Sales\Model\Order\Customer\Builder - */ - public function setEmail($customerEmail) - { - $this->customerEmail = $customerEmail; - return $this; - } - - /** - * @param string $customerFirstName - * @return \Magento\Sales\Model\Order\Customer\Builder - */ - public function setFirstName($customerFirstName) - { - $this->customerFirstName = $customerFirstName; - return $this; - } - - /** - * @param string $customerGender - * @return \Magento\Sales\Model\Order\Customer\Builder - */ - public function setGender($customerGender) - { - $this->customerGender = $customerGender; - return $this; - } - - /** - * @param int $customerGroupId - * @return \Magento\Sales\Model\Order\Customer\Builder - */ - public function setGroupId($customerGroupId) - { - $this->customerGroupId = $customerGroupId; - return $this; - } - - /** - * @param int $customerId - * @return \Magento\Sales\Model\Order\Customer\Builder - */ - public function setId($customerId) - { - $this->customerId = $customerId; - return $this; - } - - /** - * @param int $customerIsGuest - * @return \Magento\Sales\Model\Order\Customer\Builder - */ - public function setIsGuest($customerIsGuest) - { - $this->customerIsGuest = $customerIsGuest; - return $this; - } - - /** - * @param string $customerLastName - * @return \Magento\Sales\Model\Order\Customer\Builder - */ - public function setLastName($customerLastName) - { - $this->customerLastName = $customerLastName; - return $this; - } - - /** - * @param string $customerMiddleName - * @return \Magento\Sales\Model\Order\Customer\Builder - */ - public function setMiddleName($customerMiddleName) - { - $this->customerMiddleName = $customerMiddleName; - return $this; - } - - /** - * @param string $customerNote - * @return \Magento\Sales\Model\Order\Customer\Builder - */ - public function setNote($customerNote) - { - $this->customerNote = $customerNote; - return $this; - } - - /** - * @param int $customerNoteNotify - * @return \Magento\Sales\Model\Order\Customer\Builder - */ - public function setNoteNotify($customerNoteNotify) - { - $this->customerNoteNotify = $customerNoteNotify; - return $this; - } - - /** - * @param string $customerPrefix - * @return \Magento\Sales\Model\Order\Customer\Builder - */ - public function setPrefix($customerPrefix) - { - $this->customerPrefix = $customerPrefix; - return $this; - } - - /** - * @param string $customerSuffix - * @return \Magento\Sales\Model\Order\Customer\Builder - */ - public function setSuffix($customerSuffix) - { - $this->customerSuffix = $customerSuffix; - return $this; - } - - /** - * @param string $customerTaxvat - * @return \Magento\Sales\Model\Order\Customer\Builder - */ - public function setTaxvat($customerTaxvat) - { - $this->customerTaxvat = $customerTaxvat; - return $this; - } - - /** - * @return \Magento\Sales\Model\Order\Customer - */ - public function create() - { - return $this->objectManager->create('Magento\Sales\Model\Order\Customer', [ - 'customerDob' => $this->customerDob, - 'customerEmail' => $this->customerEmail, - 'customerFirstName' => $this->customerFirstName, - 'customerGender' => $this->customerGender, - 'customerGroupId' => $this->customerGroupId, - 'customerId' => $this->customerId, - 'customerIsGuest' => $this->customerIsGuest, - 'customerLastName' => $this->customerLastName, - 'customerMiddleName' => $this->customerMiddleName, - 'customerNote' => $this->customerNote, - 'customerNoteNotify' => $this->customerNoteNotify, - 'customerPrefix' => $this->customerPrefix, - 'customerSuffix' => $this->customerSuffix, - 'customerTaxvat' => $this->customerTaxvat - ]); - } -} diff --git a/app/code/Magento/Sales/Model/Order/Customer/Management.php b/app/code/Magento/Sales/Model/Order/CustomerManagement.php similarity index 96% rename from app/code/Magento/Sales/Model/Order/Customer/Management.php rename to app/code/Magento/Sales/Model/Order/CustomerManagement.php index 8944df974d221..0a5b3ee6ccbf3 100644 --- a/app/code/Magento/Sales/Model/Order/Customer/Management.php +++ b/app/code/Magento/Sales/Model/Order/CustomerManagement.php @@ -3,11 +3,14 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sales\Model\Order\Customer; +namespace Magento\Sales\Model\Order; use Magento\Framework\Exception\AlreadyExistsException; -class Management implements \Magento\Sales\Api\OrderCustomerManagementInterface +/** + * Class CustomerManagement + */ +class CustomerManagement implements \Magento\Sales\Api\OrderCustomerManagementInterface { /** * @var \Magento\Customer\Api\AccountManagementInterface diff --git a/app/code/Magento/Sales/Model/Order/Pdf/Invoice.php b/app/code/Magento/Sales/Model/Order/Pdf/Invoice.php index 954c6c1d3c263..5482bc01322a5 100644 --- a/app/code/Magento/Sales/Model/Order/Pdf/Invoice.php +++ b/app/code/Magento/Sales/Model/Order/Pdf/Invoice.php @@ -5,6 +5,8 @@ */ namespace Magento\Sales\Model\Order\Pdf; +use Magento\Sales\Model\Resource\Order\Invoice\Collection; + /** * Sales Order Invoice PDF model * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -110,7 +112,7 @@ protected function _drawHeader(\Zend_Pdf_Page $page) /** * Return PDF document * - * @param array $invoices + * @param array|Collection $invoices * @return \Zend_Pdf */ public function getPdf($invoices = []) diff --git a/app/code/Magento/Sales/Model/Order/Pdf/Shipment.php b/app/code/Magento/Sales/Model/Order/Pdf/Shipment.php index dc97fc8153830..168f7c327aecc 100644 --- a/app/code/Magento/Sales/Model/Order/Pdf/Shipment.php +++ b/app/code/Magento/Sales/Model/Order/Pdf/Shipment.php @@ -104,7 +104,7 @@ protected function _drawHeader(\Zend_Pdf_Page $page) /** * Return PDF document * - * @param array $shipments + * @param \Magento\Sales\Model\Order\Shipment[] $shipments * @return \Zend_Pdf */ public function getPdf($shipments = []) diff --git a/app/code/Magento/Sales/Model/OrderRepository.php b/app/code/Magento/Sales/Model/OrderRepository.php index d04a2d7005f09..e7993f850fe53 100644 --- a/app/code/Magento/Sales/Model/OrderRepository.php +++ b/app/code/Magento/Sales/Model/OrderRepository.php @@ -56,14 +56,14 @@ public function __construct( public function get($id) { if (!$id) { - throw new InputException('Id required'); + throw new InputException(__('Id required')); } if (!isset($this->registry[$id])) { /** @var \Magento\Sales\Api\Data\OrderInterface $entity */ $entity = $this->metadata->getNewInstance(); $this->metadata->getMapper()->load($entity, $id); if (!$entity->getEntityId()) { - throw new NoSuchEntityException('Requested entity doesn\'t exist'); + throw new NoSuchEntityException(__('Requested entity doesn\'t exist')); } $this->registry[$id] = $entity; } diff --git a/app/code/Magento/Sales/Model/Resource/Grid.php b/app/code/Magento/Sales/Model/Resource/Grid.php index f4dbb4d49b304..5c0ff84007435 100644 --- a/app/code/Magento/Sales/Model/Resource/Grid.php +++ b/app/code/Magento/Sales/Model/Resource/Grid.php @@ -144,7 +144,11 @@ protected function getGridOriginSelect() } $columns = []; foreach ($this->columns as $key => $value) { - $columns[$key] = new \Zend_Db_Expr((string) $value); + if ($value instanceof \Zend_Db_Expr) { + $columns[$key] = $value; + } else { + $columns[$key] = new \Zend_Db_Expr($value); + } } $select->columns($columns); return $select; diff --git a/app/code/Magento/Sales/Model/Resource/Grid/Collection.php b/app/code/Magento/Sales/Model/Resource/Grid/Collection.php new file mode 100644 index 0000000000000..57d2d31060dcf --- /dev/null +++ b/app/code/Magento/Sales/Model/Resource/Grid/Collection.php @@ -0,0 +1,151 @@ +_eventPrefix = $eventPrefix; + $this->_eventObject = $eventObject; + $this->_init($model, $resourceModel); + $this->setMainTable($mainTable); + parent::__construct( + $entityFactory, + $logger, + $fetchStrategy, + $eventManager, + $connection, + $resource + ); + } + + /** + * @return AggregationInterface + */ + public function getAggregations() + { + return $this->aggregations; + } + + /** + * @param AggregationInterface $aggregations + * @return $this + */ + public function setAggregations($aggregations) + { + $this->aggregations = $aggregations; + } + + + /** + * Retrieve all ids for collection + * Backward compatibility with EAV collection + * + * @param int $limit + * @param int $offset + * @return array + */ + public function getAllIds($limit = null, $offset = null) + { + return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams); + } + + /** + * Get search criteria. + * + * @return \Magento\Framework\Api\SearchCriteriaInterface|null + */ + public function getSearchCriteria() + { + return null; + } + + /** + * Set search criteria. + * + * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria + * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null) + { + return $this; + } + + /** + * Get total count. + * + * @return int + */ + public function getTotalCount() + { + return $this->getSize(); + } + + /** + * Set total count. + * + * @param int $totalCount + * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setTotalCount($totalCount) + { + return $this; + } + + /** + * Set items list. + * + * @param \Magento\Framework\Api\ExtensibleDataInterface[] $items + * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setItems(array $items = null) + { + return $this; + } +} diff --git a/app/code/Magento/Sales/Model/Resource/Order/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Collection.php index f5a3f3b7b813e..be70c20b24992 100644 --- a/app/code/Magento/Sales/Model/Resource/Order/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Order/Collection.php @@ -15,6 +15,11 @@ */ class Collection extends AbstractCollection implements OrderSearchResultInterface { + /** + * @var string + */ + protected $_idFieldName = 'entity_id'; + /** * Event prefix * diff --git a/app/code/Magento/Sales/Model/Resource/Order/Collection/AbstractCollection.php b/app/code/Magento/Sales/Model/Resource/Order/Collection/AbstractCollection.php index 4e9d402839f71..392a6600dd839 100644 --- a/app/code/Magento/Sales/Model/Resource/Order/Collection/AbstractCollection.php +++ b/app/code/Magento/Sales/Model/Resource/Order/Collection/AbstractCollection.php @@ -58,7 +58,7 @@ public function getSalesOrder() /** * Add order filter * - * @param int|\Magento\Sales\Model\Order $order + * @param int|\Magento\Sales\Model\Order|array $order * @return $this */ public function setOrderFilter($order) diff --git a/app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Collection.php index 2059ca2046576..ca6a64f6ae482 100644 --- a/app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Collection.php @@ -15,6 +15,13 @@ */ class Collection extends AbstractCollection implements CreditmemoSearchResultInterface { + /** + * Id field name + * + * @var string + */ + protected $_idFieldName = 'entity_id'; + /** * Event prefix * diff --git a/app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Grid/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Grid/Collection.php deleted file mode 100644 index 7db54682b380f..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Grid/Collection.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ -class Collection extends \Magento\Sales\Model\Resource\Order\Creditmemo\Collection -{ - /** - * Event prefix - * - * @var string - */ - protected $_eventPrefix = 'sales_order_creditmemo_grid_collection'; - - /** - * Event object - * - * @var string - */ - protected $_eventObject = 'order_creditmemo_grid_collection'; - - /** - * Model initialization - * - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->setMainTable('sales_creditmemo_grid'); - } -} diff --git a/app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Order/Grid/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Order/Grid/Collection.php deleted file mode 100644 index 0c794de75eca3..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Order/Grid/Collection.php +++ /dev/null @@ -1,72 +0,0 @@ - - */ -class Collection extends \Magento\Sales\Model\Resource\Order\Creditmemo\Grid\Collection -{ - /** - * @var \Magento\Framework\Registry - */ - protected $registryManager; - - /** - * @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 \Magento\Framework\Registry $registryManager - * @param \Magento\Framework\Model\Resource\Db\VersionControl\Snapshot $entitySnapshot - * @param null $connection - * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource - */ - 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, - \Magento\Framework\Model\Resource\Db\VersionControl\Snapshot $entitySnapshot, - \Magento\Framework\Registry $registryManager, - \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, - \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null - ) { - $this->registryManager = $registryManager; - parent::__construct( - $entityFactory, - $logger, - $fetchStrategy, - $eventManager, - $entitySnapshot, - $connection, - $resource - ); - } - - /** - * Retrieve order model instance - * - * @return \Magento\Sales\Model\Order - */ - public function getOrder() - { - return $this->registryManager->registry('current_order'); - } - - /** - * Apply sorting and filtering to collection - * - * @return $this - */ - protected function _initSelect() - { - parent::_initSelect()->setOrderFilter($this->getOrder()); - return $this; - } -} diff --git a/app/code/Magento/Sales/Model/Resource/Order/Grid/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Grid/Collection.php deleted file mode 100644 index 5ed0b75ef7a66..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Order/Grid/Collection.php +++ /dev/null @@ -1,95 +0,0 @@ - - */ -class Collection extends \Magento\Sales\Model\Resource\Order\Collection -{ - /** - * Event prefix - * - * @var string - */ - protected $_eventPrefix = 'sales_order_grid_collection'; - - /** - * Event object - * - * @var string - */ - protected $_eventObject = 'order_grid_collection'; - - /** - * Customer mode flag - * - * @var bool - */ - protected $_customerModeFlag = false; - - /** - * Model initialization - * - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->setMainTable('sales_order_grid'); - } - - /** - * Get SQL for get record count - * - * @return \Magento\Framework\DB\Select - */ - public function getSelectCountSql() - { - if ($this->getIsCustomerMode()) { - $this->_renderFilters(); - - $unionSelect = clone $this->getSelect(); - - $unionSelect->reset(\Magento\Framework\DB\Select::ORDER); - $unionSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT); - $unionSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET); - - $countSelect = clone $this->getSelect(); - $countSelect->reset(); - $countSelect->from(['a' => $unionSelect], 'COUNT(*)'); - } else { - $countSelect = parent::getSelectCountSql(); - } - - return $countSelect; - } - - /** - * Set customer mode flag value - * - * @param bool $value - * @return $this - */ - public function setIsCustomerMode($value) - { - $this->_customerModeFlag = (bool)$value; - return $this; - } - - /** - * Get customer mode flag value - * - * @return bool - * @SuppressWarnings(PHPMD.BooleanGetMethodName) - */ - public function getIsCustomerMode() - { - return $this->_customerModeFlag; - } -} diff --git a/app/code/Magento/Sales/Model/Resource/Order/Grid/Sql/Concat.php b/app/code/Magento/Sales/Model/Resource/Order/Grid/Sql/Concat.php deleted file mode 100644 index 5a40a3fcb049f..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Order/Grid/Sql/Concat.php +++ /dev/null @@ -1,50 +0,0 @@ -columns = $columns; - $this->separator = $separator; - } - - /** - * @return string - */ - public function __toString() - { - $columns = []; - foreach ($this->columns as $key => $column) { - $columns[$key] = sprintf("ifnull(%s, '')", $column); - } - return sprintf( - 'trim(concat(%s))', - implode( - sprintf(", '%s' ,", $this->separator), - $columns - ) - ); - } -} diff --git a/app/code/Magento/Sales/Model/Resource/Order/Grid/Sql/SubSelect.php b/app/code/Magento/Sales/Model/Resource/Order/Grid/Sql/SubSelect.php deleted file mode 100644 index b588c47bda30e..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Order/Grid/Sql/SubSelect.php +++ /dev/null @@ -1,101 +0,0 @@ -resource = $resource; - $this->connectionName = $connectionName; - $this->table = $table; - $this->columns = $columns; - $this->originColumn = $originColumn; - $this->targetColumn = $targetColumn; - } - - /** - * @return string - */ - public function __toString() - { - $select = $this->getConnection()->select()->from( - $this->resource->getTableName($this->table), - array_values($this->columns) - )->where( - sprintf('`%s` = %s', $this->originColumn, $this->targetColumn) - )->limit(1); - return sprintf('(%s)', $select); - } - - /** - * Returns connection - * - * @return AdapterInterface - */ - protected function getConnection() - { - if (!$this->connection) { - $this->connection = $this->resource->getConnection($this->connectionName); - } - return $this->connection; - } -} diff --git a/app/code/Magento/Sales/Model/Resource/Order/Grid/StatusesArray.php b/app/code/Magento/Sales/Model/Resource/Order/Grid/StatusesArray.php deleted file mode 100644 index ee14b65c2d47c..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Order/Grid/StatusesArray.php +++ /dev/null @@ -1,36 +0,0 @@ -_statusCollectionFactory = $statusCollectionFactory; - } - - /** - * Return option array - * - * @return array - */ - public function toOptionArray() - { - $statuses = $this->_statusCollectionFactory->create()->toOptionHash(); - return $statuses; - } -} diff --git a/app/code/Magento/Sales/Model/Resource/Order/Invoice/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Invoice/Collection.php index 7248f5b13190a..a8bb205da49af 100644 --- a/app/code/Magento/Sales/Model/Resource/Order/Invoice/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Order/Invoice/Collection.php @@ -15,6 +15,13 @@ */ class Collection extends AbstractCollection implements InvoiceSearchResultInterface { + /** + * Id field name + * + * @var string + */ + protected $_idFieldName = 'entity_id'; + /** * Event prefix * diff --git a/app/code/Magento/Sales/Model/Resource/Order/Invoice/Grid/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Invoice/Grid/Collection.php deleted file mode 100644 index e8ec35930f11f..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Order/Invoice/Grid/Collection.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ -class Collection extends \Magento\Sales\Model\Resource\Order\Invoice\Collection -{ - /** - * Event prefix - * - * @var string - */ - protected $_eventPrefix = 'sales_order_invoice_grid_collection'; - - /** - * Event object - * - * @var string - */ - protected $_eventObject = 'order_invoice_grid_collection'; - - /** - * Model initialization - * - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->setMainTable('sales_invoice_grid'); - } -} diff --git a/app/code/Magento/Sales/Model/Resource/Order/Invoice/Orders/Grid/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Invoice/Orders/Grid/Collection.php deleted file mode 100644 index 3e9bb8a7ad065..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Order/Invoice/Orders/Grid/Collection.php +++ /dev/null @@ -1,68 +0,0 @@ -registryManager = $registryManager; - parent::__construct( - $entityFactory, - $logger, - $fetchStrategy, - $eventManager, - $entitySnapshot, - $connection, - $resource - ); - } - - /** - * Retrieve order model instance - * - * @return \Magento\Sales\Model\Order - */ - public function getOrder() - { - return $this->registryManager->registry('current_order'); - } - - /** - * Apply sorting and filtering to collection - * - * @return $this - */ - protected function _initSelect() - { - parent::_initSelect(); - $this->setOrderFilter($this->getOrder()); - return $this; - } -} diff --git a/app/code/Magento/Sales/Model/Resource/Order/Shipment/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Shipment/Collection.php index ccdefda10fd30..63744b59dca9f 100644 --- a/app/code/Magento/Sales/Model/Resource/Order/Shipment/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Order/Shipment/Collection.php @@ -15,6 +15,11 @@ */ class Collection extends AbstractCollection implements ShipmentSearchResultInterface { + /** + * @var string + */ + protected $_idFieldName = 'entity_id'; + /** * Event prefix * diff --git a/app/code/Magento/Sales/Model/Resource/Order/Shipment/Grid/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Shipment/Grid/Collection.php deleted file mode 100644 index cae68ec151da9..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Order/Shipment/Grid/Collection.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ -class Collection extends \Magento\Sales\Model\Resource\Order\Shipment\Collection -{ - /** - * Event prefix - * - * @var string - */ - protected $_eventPrefix = 'sales_order_shipment_grid_collection'; - - /** - * Event object - * - * @var string - */ - protected $_eventObject = 'order_shipment_grid_collection'; - - /** - * Model initialization - * - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->setMainTable('sales_shipment_grid'); - } -} diff --git a/app/code/Magento/Sales/Model/Resource/Order/Shipment/Order/Grid/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Shipment/Order/Grid/Collection.php deleted file mode 100644 index e57f863368298..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Order/Shipment/Order/Grid/Collection.php +++ /dev/null @@ -1,73 +0,0 @@ - - */ -class Collection extends \Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection -{ - /** - * @var \Magento\Framework\Registry - */ - protected $registryManager; - - /** - * @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 \Magento\Framework\Model\Resource\Db\VersionControl\Snapshot $entitySnapshot - * @param \Magento\Framework\Registry $registryManager - * @param null $connection - * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource - */ - 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, - \Magento\Framework\Model\Resource\Db\VersionControl\Snapshot $entitySnapshot, - \Magento\Framework\Registry $registryManager, - \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, - \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null - ) { - $this->registryManager = $registryManager; - parent::__construct( - $entityFactory, - $logger, - $fetchStrategy, - $eventManager, - $entitySnapshot, - $connection, - $resource - ); - } - - /** - * Retrieve order model instance - * - * @return \Magento\Sales\Model\Order - */ - public function getOrder() - { - return $this->registryManager->registry('current_order'); - } - - /** - * Apply sorting and filtering to collection - * - * @return $this - */ - protected function _initSelect() - { - parent::_initSelect(); - $this->setOrderFilter($this->getOrder()); - return $this; - } -} diff --git a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/GridTest.php b/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/GridTest.php deleted file mode 100644 index 2a3ddf1b44011..0000000000000 --- a/app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/GridTest.php +++ /dev/null @@ -1,81 +0,0 @@ -requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface') - ->disableOriginalConstructor() - ->setMethods(['has']) - ->getMockForAbstractClass(); - $this->contextMock = $this->getMockBuilder('Magento\Backend\Block\Template\Context') - ->disableOriginalConstructor() - ->getMock(); - $this->contextMock->expects($this->any()) - ->method('getRequest') - ->willReturn($this->requestMock); - $arguments = [ - 'context' => $this->contextMock - ]; - $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - /** @var \Magento\Sales\Block\Adminhtml\Order\Grid $block */ - $this->block = $helper->getObject('Magento\Sales\Block\Adminhtml\Order\Grid', $arguments); - } - - public function testPrepareCollection() - { - $collectionMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\Grid\Collection') - ->disableOriginalConstructor() - ->getMock(); - $this->requestMock->expects($this->any()) - ->method('has') - ->withAnyParameters() - ->willReturn(false); - $layoutMock = $this->getMockBuilder('Magento\Framework\View\LayoutInterface') - ->disableOriginalConstructor() - ->getMock(); - - $blockMock = $this->getMockBuilder('Magento\Framework\View\Element\AbstractBlock') - ->disableOriginalConstructor() - ->setMethods(['getLayout']) - ->getMockForAbstractClass(); - $blockMock->expects($this->any()) - ->method('getLayout') - ->willReturn($layoutMock); - - $layoutMock->expects($this->any()) - ->method('getBlock') - ->willReturn($blockMock); - $layoutMock->expects($this->any()) - ->method('getChildName') - ->willReturn($blockMock); - $this->block->setData('id', 1); - $this->block->setLayout($layoutMock); - $this->block->setCollection($collectionMock); - $this->assertEquals($collectionMock, $this->block->getPreparedCollection()); - } -} diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/EmailTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/EmailTest.php index fe36332d13983..73396196f9723 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/EmailTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/EmailTest.php @@ -13,7 +13,7 @@ /** * Class EmailTest - * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @package Magento\Sales\Controller\Adminhtml\Order */ class EmailTest extends \PHPUnit_Framework_TestCase @@ -68,6 +68,26 @@ class EmailTest extends \PHPUnit_Framework_TestCase */ protected $helper; + /** + * @var \Magento\Sales\Api\OrderManagementInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderManagementMock; + + /** + * @var \Magento\Sales\Api\OrderRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderRepositoryMock; + + /** + * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $loggerMock; + + /** + * @var \Magento\Sales\Api\Data\OrderInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderMock; + public function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); @@ -88,6 +108,12 @@ public function setUp() '', false ); + $this->orderManagementMock = $this->getMockBuilder('Magento\Sales\Api\OrderManagementInterface') + ->getMockForAbstractClass(); + $this->orderRepositoryMock = $this->getMockBuilder('Magento\Sales\Api\OrderRepositoryInterface') + ->getMockForAbstractClass(); + $this->loggerMock = $this->getMockBuilder('Psr\Log\LoggerInterface') + ->getMockForAbstractClass(); $resultRedirectFactory = $this->getMock( 'Magento\Backend\Model\View\Result\RedirectFactory', ['create'], @@ -104,13 +130,6 @@ public function setUp() ); $this->request = $this->getMockBuilder('Magento\Framework\App\Request\Http') ->disableOriginalConstructor()->getMock(); - $this->objectManager = $this->getMock( - 'Magento\Framework\ObjectManager\ObjectManager', - ['create'], - [], - '', - false - ); $this->messageManager = $this->getMock( 'Magento\Framework\Message\Manager', ['addSuccess', 'addError'], @@ -118,6 +137,9 @@ public function setUp() '', false ); + + $this->orderMock = $this->getMockBuilder('Magento\Sales\Api\Data\OrderInterface') + ->getMockForAbstractClass(); $this->session = $this->getMock('Magento\Backend\Model\Session', ['setIsUrlNotice'], [], '', false); $this->actionFlag = $this->getMock('Magento\Framework\App\ActionFlag', ['get', 'set'], [], '', false); $this->helper = $this->getMock('\Magento\Backend\Helper\Data', ['getUrl'], [], '', false); @@ -138,7 +160,10 @@ public function setUp() [ 'context' => $this->context, 'request' => $this->request, - 'response' => $this->response + 'response' => $this->response, + 'orderManagement' => $this->orderManagementMock, + 'orderRepository' => $this->orderRepositoryMock, + 'logger' => $this->loggerMock ] ); } @@ -146,35 +171,21 @@ public function setUp() public function testEmail() { $orderId = 10000031; - $orderClassName = 'Magento\Sales\Model\Order'; - $orderNotifierClassName = 'Magento\Sales\Api\OrderManagementInterface'; - $order = $this->getMock($orderClassName, ['load', 'getId', '__wakeup'], [], '', false); - $cmNotifier = $this->getMockBuilder('Magento\Sales\Api\OrderManagementInterface') - ->disableOriginalConstructor() - ->getMock(); - $this->request->expects($this->once()) ->method('getParam') ->with('order_id') ->will($this->returnValue($orderId)); - $this->objectManager->expects($this->at(0)) - ->method('create') - ->with($orderClassName) - ->will($this->returnValue($order)); - $order->expects($this->once()) - ->method('load') + $this->orderRepositoryMock->expects($this->once()) + ->method('get') ->with($orderId) - ->will($this->returnSelf()); - $order->expects($this->atLeastOnce()) - ->method('getId') + ->willReturn($this->orderMock); + $this->orderMock->expects($this->atLeastOnce()) + ->method('getEntityId') ->will($this->returnValue($orderId)); - $this->objectManager->expects($this->at(1)) - ->method('create') - ->with($orderNotifierClassName) - ->will($this->returnValue($cmNotifier)); - $cmNotifier->expects($this->once()) + $this->orderManagementMock->expects($this->once()) ->method('notify') - ->will($this->returnValue(true)); + ->with($orderId) + ->willReturn(true); $this->messageManager->expects($this->once()) ->method('addSuccess') ->with('You sent the order email.'); @@ -192,21 +203,16 @@ public function testEmail() public function testEmailNoOrderId() { - $orderClassName = 'Magento\Sales\Model\Order'; - $order = $this->getMock($orderClassName, ['load', 'getId', '__wakeup'], [], '', false); $this->request->expects($this->once()) ->method('getParam') ->with('order_id') ->will($this->returnValue(null)); - - $this->objectManager->expects($this->at(0)) - ->method('create') - ->with($orderClassName) - ->will($this->returnValue($order)); - $order->expects($this->once()) - ->method('load') + $this->orderRepositoryMock->expects($this->once()) + ->method('get') ->with(null) - ->will($this->returnSelf()); + ->willThrowException( + new \Magento\Framework\Exception\NoSuchEntityException(__('Requested entity doesn\'t exist')) + ); $this->messageManager->expects($this->once()) ->method('addError') ->with('This order no longer exists.'); diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/MassCancelTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/MassCancelTest.php index f26c096c20ae6..0359eed52b0d9 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/MassCancelTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/MassCancelTest.php @@ -71,56 +71,27 @@ class MassCancelTest extends \PHPUnit_Framework_TestCase protected $orderMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Sales\Model\Resource\Order\Collection|\PHPUnit_Framework_MockObject_MockObject */ protected $orderCollectionMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Sales\Model\Resource\Order\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $orderManagement; + protected $orderCollectionFactoryMock; /** - * @return void - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @var \Magento\Ui\Component\MassAction\Filter|\PHPUnit_Framework_MockObject_MockObject */ + protected $filterMock; + public function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); - $this->contextMock = $this->getMock( - 'Magento\Backend\App\Action\Context', - [ - 'getRequest', - 'getResponse', - 'getMessageManager', - 'getRedirect', - 'getObjectManager', - 'getSession', - 'getActionFlag', - 'getHelper', - 'getResultRedirectFactory', - 'getResultFactory' - ], - [], - '', - false - ); - $resultRedirectFactory = $this->getMock( - 'Magento\Backend\Model\View\Result\RedirectFactory', - ['create'], - [], - '', - false - ); - $this->responseMock = $this->getMock( - 'Magento\Framework\App\ResponseInterface', - ['setRedirect', 'sendResponse'], - [], - '', - false - ); - $this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http') - ->disableOriginalConstructor()->getMock(); + $this->contextMock = $this->getMock('Magento\Backend\App\Action\Context', [], [], '', false); + $this->messageManagerMock = $this->getMock('Magento\Framework\Message\Manager', [], [], '', false); + $this->responseMock = $this->getMock('Magento\Framework\App\ResponseInterface', [], [], '', false); + $this->requestMock = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false); $this->objectManagerMock = $this->getMock( 'Magento\Framework\ObjectManager\ObjectManager', [], @@ -128,9 +99,10 @@ public function setUp() '', false ); - $this->messageManagerMock = $this->getMock( - 'Magento\Framework\Message\Manager', - ['addSuccess', 'addError'], + + $resultRedirectFactory = $this->getMock( + 'Magento\Backend\Model\View\Result\RedirectFactory', + [], [], '', false @@ -140,6 +112,12 @@ public function setUp() ->disableOriginalConstructor() ->getMock(); + $resourceCollection = 'Magento\Sales\Model\Resource\Order\CollectionFactory'; + $this->orderCollectionFactoryMock = $this->getMockBuilder($resourceCollection) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->sessionMock = $this->getMock('Magento\Backend\Model\Session', ['setIsUrlNotice'], [], '', false); $this->actionFlagMock = $this->getMock('Magento\Framework\App\ActionFlag', ['get', 'set'], [], '', false); $this->helperMock = $this->getMock('\Magento\Backend\Helper\Data', ['getUrl'], [], '', false); @@ -165,26 +143,26 @@ public function setUp() $this->contextMock->expects($this->once())->method('getSession')->willReturn($this->sessionMock); $this->contextMock->expects($this->once())->method('getActionFlag')->willReturn($this->actionFlagMock); $this->contextMock->expects($this->once())->method('getHelper')->willReturn($this->helperMock); - $this->contextMock - ->expects($this->once()) + $this->contextMock->expects($this->once()) ->method('getResultRedirectFactory') ->willReturn($resultRedirectFactory); $this->contextMock->expects($this->any()) ->method('getResultFactory') ->willReturn($resultFactoryMock); - - $this->orderManagement = $this->getMockBuilder('Magento\Sales\Api\OrderManagementInterface') - ->disableOriginalConstructor() - ->getMock(); - $this->objectManagerMock->expects($this->any()) - ->method('get') - ->with('Magento\Sales\Api\OrderManagementInterface') - ->willReturn($this->orderManagement); - + $this->filterMock = $this->getMock('Magento\Ui\Component\MassAction\Filter', [], [], '', false); + $this->filterMock->expects($this->once()) + ->method('getCollection') + ->with($this->orderCollectionMock) + ->willReturn($this->orderCollectionMock); + $this->orderCollectionFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->orderCollectionMock); $this->massAction = $objectManagerHelper->getObject( 'Magento\Sales\Controller\Adminhtml\Order\MassCancel', [ - 'context' => $this->contextMock + 'context' => $this->contextMock, + 'filter' => $this->filterMock, + 'collectionFactory' => $this->orderCollectionFactoryMock ] ); } @@ -193,48 +171,28 @@ public function setUp() * Test for selected orders * Two orders, only $order1 can be canceled */ - public function testExecuteTwoOrderCanceled() + public function testExecuteCanCancelOneOrder() { - $selected = [1, 2]; - $countOrders = count($selected); - $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); $order2 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); + $orders = [$order1, $order2]; + $countOrders = count($orders); - $this->requestMock->expects($this->at(0)) - ->method('getParam') - ->with('selected') - ->willReturn($selected); - - $this->requestMock->expects($this->at(1)) - ->method('getParam') - ->with('excluded') - ->willReturn([]); - - $this->objectManagerMock->expects($this->once()) - ->method('create') - ->with('Magento\Sales\Model\Resource\Order\Grid\Collection') - ->willReturn($this->orderCollectionMock); - $this->orderCollectionMock->expects($this->once()) - ->method('addFieldToFilter') - ->with(\Magento\Sales\Controller\Adminhtml\Order\MassCancel::ID_FIELD, ['in' => $selected]); $this->orderCollectionMock->expects($this->any()) ->method('getItems') - ->willReturn([$order1, $order2]); + ->willReturn($orders); - $this->orderManagement->expects($this->at(0)) - ->method('cancel') - ->with(1); $order1->expects($this->once()) ->method('canCancel') ->willReturn(true); $order1->expects($this->once()) - ->method('getEntityId') - ->willReturn(1); + ->method('cancel'); + $order1->expects($this->once()) + ->method('save'); $this->orderCollectionMock->expects($this->once()) ->method('count') @@ -252,6 +210,11 @@ public function testExecuteTwoOrderCanceled() ->method('addSuccess') ->with('We canceled 1 order(s).'); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with('sales/*/') + ->willReturnSelf(); + $this->massAction->execute(); } @@ -259,11 +222,8 @@ public function testExecuteTwoOrderCanceled() * Test for excluded orders * Two orders could't be canceled */ - public function testExcludedOrderCannotBeCanceled() + public function testExcludedCannotCancelOrders() { - $excluded = [1, 2]; - $countOrders = count($excluded); - $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); @@ -271,23 +231,9 @@ public function testExcludedOrderCannotBeCanceled() ->disableOriginalConstructor() ->getMock(); - $this->requestMock->expects($this->at(0)) - ->method('getParam') - ->with('selected') - ->willReturn([]); - - $this->requestMock->expects($this->at(1)) - ->method('getParam') - ->with('excluded') - ->willReturn($excluded); + $orders = [$order1, $order2]; + $countOrders = count($orders); - $this->objectManagerMock->expects($this->once()) - ->method('create') - ->with('Magento\Sales\Model\Resource\Order\Grid\Collection') - ->willReturn($this->orderCollectionMock); - $this->orderCollectionMock->expects($this->once()) - ->method('addFieldToFilter') - ->with(\Magento\Sales\Controller\Adminhtml\Order\MassCancel::ID_FIELD, ['nin' => $excluded]); $this->orderCollectionMock->expects($this->any()) ->method('getItems') ->willReturn([$order1, $order2]); @@ -308,19 +254,10 @@ public function testExcludedOrderCannotBeCanceled() ->method('addError') ->with('You cannot cancel the order(s).'); - $this->massAction->execute(); - } - - public function testNoExcludedNoSelectedOrders() - { - $this->objectManagerMock->expects($this->once()) - ->method('create') - ->with('Magento\Sales\Model\Resource\Order\Grid\Collection') - ->willReturn($this->orderCollectionMock); - - $this->messageManagerMock->expects($this->once()) - ->method('addError') - ->with('Please select item(s).'); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with('sales/*/') + ->willReturnSelf(); $this->massAction->execute(); } @@ -330,44 +267,21 @@ public function testNoExcludedNoSelectedOrders() */ public function testException() { - $selected = [1]; $exception = new \Exception('Can not cancel'); $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); - - $this->requestMock->expects($this->at(0)) - ->method('getParam') - ->with('selected') - ->willReturn($selected); - - $this->requestMock->expects($this->at(1)) - ->method('getParam') - ->with('excluded') - ->willReturn([]); - - $this->objectManagerMock->expects($this->once()) - ->method('create') - ->with('Magento\Sales\Model\Resource\Order\Grid\Collection') - ->willReturn($this->orderCollectionMock); - $this->orderCollectionMock->expects($this->once()) - ->method('addFieldToFilter') - ->with(\Magento\Sales\Controller\Adminhtml\Order\MassCancel::ID_FIELD, ['in' => $selected]); $this->orderCollectionMock->expects($this->any()) ->method('getItems') ->willReturn([$order1]); - $this->orderManagement->expects($this->once()) - ->method('cancel') - ->with(1) - ->willThrowException($exception); $order1->expects($this->once()) ->method('canCancel') ->willReturn(true); $order1->expects($this->once()) - ->method('getEntityId') - ->willReturn(1); + ->method('cancel') + ->willThrowException($exception); $this->messageManagerMock->expects($this->once()) ->method('addError') diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/MassHoldTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/MassHoldTest.php index d74b5139766b9..9e7f392b3ecf8 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/MassHoldTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/MassHoldTest.php @@ -71,74 +71,57 @@ class MassHoldTest extends \PHPUnit_Framework_TestCase protected $orderMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Sales\Model\Resource\Order\Collection|\PHPUnit_Framework_MockObject_MockObject */ protected $orderCollectionMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Sales\Model\Resource\Order\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $orderManagement; + protected $orderCollectionFactoryMock; /** - * @return void - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @var \Magento\Ui\Component\MassAction\Filter|\PHPUnit_Framework_MockObject_MockObject */ + protected $filterMock; + + /** + * @var \Magento\Sales\Api\OrderManagementInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderManagementMock; + public function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); - $this->contextMock = $this->getMock( - 'Magento\Backend\App\Action\Context', - [ - 'getRequest', - 'getResponse', - 'getMessageManager', - 'getRedirect', - 'getObjectManager', - 'getSession', - 'getActionFlag', - 'getHelper', - 'getResultRedirectFactory', - 'getResultFactory' - ], - [], - '', - false - ); + $this->orderManagementMock = $this->getMockBuilder('Magento\Sales\Api\OrderManagementInterface') + ->getMockForAbstractClass(); + $this->contextMock = $this->getMock('Magento\Backend\App\Action\Context', [], [], '', false); $resultRedirectFactory = $this->getMock( 'Magento\Backend\Model\View\Result\RedirectFactory', - ['create'], [], - '', - false - ); - $this->responseMock = $this->getMock( - 'Magento\Framework\App\ResponseInterface', - ['setRedirect', 'sendResponse'], [], '', false ); + $this->responseMock = $this->getMock('Magento\Framework\App\ResponseInterface', [], [], '', false); $this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http') ->disableOriginalConstructor()->getMock(); $this->objectManagerMock = $this->getMock( 'Magento\Framework\ObjectManager\ObjectManager', - [], - [], - '', - false - ); - $this->messageManagerMock = $this->getMock( - 'Magento\Framework\Message\Manager', - ['addSuccess', 'addError'], + ['create'], [], '', false ); + $this->messageManagerMock = $this->getMock('Magento\Framework\Message\Manager', [], [], '', false); $this->orderCollectionMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\Collection') ->disableOriginalConstructor() ->getMock(); - + $orderCollection = 'Magento\Sales\Model\Resource\Order\CollectionFactory'; + $this->orderCollectionFactoryMock = $this->getMockBuilder($orderCollection) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); $redirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') ->disableOriginalConstructor() ->getMock(); @@ -172,26 +155,28 @@ public function setUp() ->method('getResultFactory') ->willReturn($resultFactoryMock); - $this->orderManagement = $this->getMockBuilder('Magento\Sales\Api\OrderManagementInterface') - ->disableOriginalConstructor() - ->getMock(); - $this->objectManagerMock->expects($this->any()) - ->method('get') - ->with('Magento\Sales\Api\OrderManagementInterface') - ->willReturn($this->orderManagement); + $this->filterMock = $this->getMock('Magento\Ui\Component\MassAction\Filter', [], [], '', false); + $this->filterMock->expects($this->once()) + ->method('getCollection') + ->with($this->orderCollectionMock) + ->willReturn($this->orderCollectionMock); + $this->orderCollectionFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->orderCollectionMock); + $this->massAction = $objectManagerHelper->getObject( 'Magento\Sales\Controller\Adminhtml\Order\MassHold', [ 'context' => $this->contextMock, + 'filter' => $this->filterMock, + 'collectionFactory' => $this->orderCollectionFactoryMock, + 'orderManagement' => $this->orderManagementMock ] ); } - public function testExecuteTwoOrdersPutOnHold() + public function testExecuteOneOrderPutOnHold() { - $selected = [1, 2]; - $countOrders = count($selected); - $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); @@ -199,37 +184,18 @@ public function testExecuteTwoOrdersPutOnHold() ->disableOriginalConstructor() ->getMock(); - $this->requestMock->expects($this->at(0)) - ->method('getParam') - ->with('selected') - ->willReturn($selected); - - $this->requestMock->expects($this->at(1)) - ->method('getParam') - ->with('excluded') - ->willReturn([]); + $orders = [$order1, $order2]; + $countOrders = count($orders); - $this->objectManagerMock->expects($this->once()) - ->method('create') - ->with('Magento\Sales\Model\Resource\Order\Grid\Collection') - ->willReturn($this->orderCollectionMock); - $this->orderCollectionMock->expects($this->once()) - ->method('addFieldToFilter') - ->with(\Magento\Sales\Controller\Adminhtml\Order\MassCancel::ID_FIELD, ['in' => $selected]); $this->orderCollectionMock->expects($this->any()) ->method('getItems') - ->willReturn([$order1, $order2]); + ->willReturn($orders); - $this->orderManagement->expects($this->once()) - ->method('hold') - ->with(1); $order1->expects($this->once()) ->method('canHold') ->willReturn(true); - $order1->expects($this->once()) - ->method('getEntityId') - ->willReturn(1); - + $this->orderManagementMock->expects($this->once()) + ->method('hold'); $this->orderCollectionMock->expects($this->once()) ->method('count') ->willReturn($countOrders); @@ -254,11 +220,8 @@ public function testExecuteTwoOrdersPutOnHold() $this->massAction->execute(); } - public function testExecuteOneOrderCannotBePutOnHold() + public function testExecuteNoOrdersPutOnHold() { - $excluded = [1, 2]; - $countOrders = count($excluded); - $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); @@ -266,26 +229,12 @@ public function testExecuteOneOrderCannotBePutOnHold() ->disableOriginalConstructor() ->getMock(); - $this->requestMock->expects($this->at(0)) - ->method('getParam') - ->with('selected') - ->willReturn([]); - - $this->requestMock->expects($this->at(1)) - ->method('getParam') - ->with('excluded') - ->willReturn($excluded); + $orders = [$order1, $order2]; + $countOrders = count($orders); - $this->objectManagerMock->expects($this->once()) - ->method('create') - ->with('Magento\Sales\Model\Resource\Order\Grid\Collection') - ->willReturn($this->orderCollectionMock); - $this->orderCollectionMock->expects($this->once()) - ->method('addFieldToFilter') - ->with(\Magento\Sales\Controller\Adminhtml\Order\MassCancel::ID_FIELD, ['nin' => $excluded]); $this->orderCollectionMock->expects($this->any()) ->method('getItems') - ->willReturn([$order1, $order2]); + ->willReturn($orders); $order1->expects($this->once()) ->method('canHold') diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/MassUnholdTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/MassUnholdTest.php index cec2ba1b5ae99..dd43b7ac2c570 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/MassUnholdTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/MassUnholdTest.php @@ -71,54 +71,32 @@ class MassUnholdTest extends \PHPUnit_Framework_TestCase protected $orderMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Sales\Model\Resource\Order\Collection|\PHPUnit_Framework_MockObject_MockObject */ protected $orderCollectionMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Sales\Model\Resource\Order\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $orderManagement; + protected $orderCollectionFactoryMock; /** - * @return void - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @var \Magento\Ui\Component\MassAction\Filter|\PHPUnit_Framework_MockObject_MockObject */ + protected $filterMock; + public function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); - $this->contextMock = $this->getMock( - 'Magento\Backend\App\Action\Context', - [ - 'getRequest', - 'getResponse', - 'getMessageManager', - 'getRedirect', - 'getObjectManager', - 'getSession', - 'getActionFlag', - 'getHelper', - 'getResultRedirectFactory', - 'getResultFactory' - ], - [], - '', - false - ); + $this->contextMock = $this->getMock('Magento\Backend\App\Action\Context', [], [], '', false); $resultRedirectFactory = $this->getMock( 'Magento\Backend\Model\View\Result\RedirectFactory', - ['create'], [], - '', - false - ); - $this->responseMock = $this->getMock( - 'Magento\Framework\App\ResponseInterface', - ['setRedirect', 'sendResponse'], [], '', false ); + $this->responseMock = $this->getMock('Magento\Framework\App\ResponseInterface', [], [], '', false); $this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http') ->disableOriginalConstructor()->getMock(); $this->objectManagerMock = $this->getMock( @@ -128,18 +106,16 @@ public function setUp() '', false ); - $this->messageManagerMock = $this->getMock( - 'Magento\Framework\Message\Manager', - ['addSuccess', 'addError'], - [], - '', - false - ); + $this->messageManagerMock = $this->getMock('Magento\Framework\Message\Manager', [], [], '', false); $this->orderCollectionMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\Collection') ->disableOriginalConstructor() ->getMock(); - + $orderCollection = 'Magento\Sales\Model\Resource\Order\CollectionFactory'; + $this->orderCollectionFactoryMock = $this->getMockBuilder($orderCollection) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); $this->sessionMock = $this->getMock('Magento\Backend\Model\Session', ['setIsUrlNotice'], [], '', false); $this->actionFlagMock = $this->getMock('Magento\Framework\App\ActionFlag', ['get', 'set'], [], '', false); $this->helperMock = $this->getMock('\Magento\Backend\Helper\Data', ['getUrl'], [], '', false); @@ -173,28 +149,27 @@ public function setUp() ->method('getResultFactory') ->willReturn($resultFactoryMock); - $this->orderManagement = $this->getMockBuilder('Magento\Sales\Api\OrderManagementInterface') - ->disableOriginalConstructor() - ->getMock(); - - $this->objectManagerMock->expects($this->any()) - ->method('get') - ->with('Magento\Sales\Api\OrderManagementInterface') - ->willReturn($this->orderManagement); + $this->filterMock = $this->getMock('Magento\Ui\Component\MassAction\Filter', [], [], '', false); + $this->filterMock->expects($this->once()) + ->method('getCollection') + ->with($this->orderCollectionMock) + ->willReturn($this->orderCollectionMock); + $this->orderCollectionFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($this->orderCollectionMock); $this->massAction = $objectManagerHelper->getObject( 'Magento\Sales\Controller\Adminhtml\Order\MassUnhold', [ 'context' => $this->contextMock, + 'filter' => $this->filterMock, + 'collectionFactory' => $this->orderCollectionFactoryMock ] ); } - public function testExecuteTwoOrdersReleasedFromHold() + public function testExecuteOneOrdersReleasedFromHold() { - $selected = [1, 2]; - $countOrders = count($selected); - $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); @@ -202,41 +177,23 @@ public function testExecuteTwoOrdersReleasedFromHold() ->disableOriginalConstructor() ->getMock(); - $this->requestMock->expects($this->at(0)) - ->method('getParam') - ->with('selected') - ->willReturn($selected); - - $this->requestMock->expects($this->at(1)) - ->method('getParam') - ->with('excluded') - ->willReturn([]); + $orders = [$order1, $order2]; - $this->objectManagerMock->expects($this->once()) - ->method('create') - ->with('Magento\Sales\Model\Resource\Order\Collection') - ->willReturn($this->orderCollectionMock); - $this->orderCollectionMock->expects($this->once()) - ->method('addFieldToFilter') - ->with(\Magento\Sales\Controller\Adminhtml\Order\MassCancel::ID_FIELD, ['in' => $selected]); $this->orderCollectionMock->expects($this->any()) ->method('getItems') - ->willReturn([$order1, $order2]); - - $this->orderManagement->expects($this->once()) - ->method('unHold') - ->with(1); + ->willReturn($orders); $order1->expects($this->once()) ->method('canUnhold') ->willReturn(true); $order1->expects($this->once()) - ->method('getEntityId') - ->willReturn(1); + ->method('unhold'); + $order1->expects($this->once()) + ->method('save'); $this->orderCollectionMock->expects($this->once()) ->method('count') - ->willReturn($countOrders); + ->willReturn(count($orders)); $order2->expects($this->once()) ->method('canUnhold') @@ -258,11 +215,8 @@ public function testExecuteTwoOrdersReleasedFromHold() $this->massAction->execute(); } - public function testExecuteOneOrderWhereNotReleasedFromHold() + public function testExecuteNoReleasedOrderFromHold() { - $excluded = [1, 2]; - $countOrders = count($excluded); - $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); @@ -270,26 +224,11 @@ public function testExecuteOneOrderWhereNotReleasedFromHold() ->disableOriginalConstructor() ->getMock(); - $this->requestMock->expects($this->at(0)) - ->method('getParam') - ->with('selected') - ->willReturn([]); + $orders = [$order1, $order2]; - $this->requestMock->expects($this->at(1)) - ->method('getParam') - ->with('excluded') - ->willReturn($excluded); - - $this->objectManagerMock->expects($this->once()) - ->method('create') - ->with('Magento\Sales\Model\Resource\Order\Collection') - ->willReturn($this->orderCollectionMock); - $this->orderCollectionMock->expects($this->once()) - ->method('addFieldToFilter') - ->with(\Magento\Sales\Controller\Adminhtml\Order\MassCancel::ID_FIELD, ['nin' => $excluded]); $this->orderCollectionMock->expects($this->any()) ->method('getItems') - ->willReturn([$order1, $order2]); + ->willReturn($orders); $order1->expects($this->once()) ->method('canUnhold') @@ -297,7 +236,7 @@ public function testExecuteOneOrderWhereNotReleasedFromHold() $this->orderCollectionMock->expects($this->once()) ->method('count') - ->willReturn($countOrders); + ->willReturn(count($orders)); $order2->expects($this->once()) ->method('canUnhold') diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/ReviewPaymentTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/ReviewPaymentTest.php index 1f53e7b02b597..866c083c049a9 100755 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/ReviewPaymentTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/ReviewPaymentTest.php @@ -18,10 +18,7 @@ class ReviewPaymentTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Backend\App\Action\Context| \PHPUnit_Framework_MockObject_MockObject */ protected $contextMock; - /** @var \Magento\Framework\ObjectManager\ObjectManager|\PHPUnit_Framework_MockObject_MockObject */ - protected $objectManagerMock; - - /** @var \Magento\Sales\Model\Order |\PHPUnit_Framework_MockObject_MockObject */ + /** @var \Magento\Sales\Api\Data\OrderInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $orderMock; /** @var \Magento\Backend\Model\View\Result\RedirectFactory | \PHPUnit_Framework_MockObject_MockObject*/ @@ -39,6 +36,21 @@ class ReviewPaymentTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Framework\Message\Manager|\PHPUnit_Framework_MockObject_MockObject */ protected $messageManagerMock; + /** + * @var \Magento\Sales\Api\OrderManagementInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderManagementMock; + + /** + * @var \Magento\Sales\Api\OrderRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderRepositoryMock; + + /** + * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $loggerMock; + protected function setUp() { $this->contextMock = $this->getMock( @@ -58,7 +70,15 @@ protected function setUp() '', false ); - + $this->orderManagementMock = $this->getMockBuilder('Magento\Sales\Api\OrderManagementInterface') + ->getMockForAbstractClass(); + $this->orderRepositoryMock = $this->getMockBuilder('Magento\Sales\Api\OrderRepositoryInterface') + ->getMockForAbstractClass(); + $this->loggerMock = $this->getMockBuilder('Psr\Log\LoggerInterface') + ->getMockForAbstractClass(); + $this->orderMock = $this->getMockBuilder('Magento\Sales\Api\Data\OrderInterface') + ->setMethods(['getPayment']) + ->getMockForAbstractClass(); $this->messageManagerMock = $this->getMock( 'Magento\Framework\Message\Manager', ['addSuccess', 'addError'], @@ -83,23 +103,6 @@ protected function setUp() false ); - $this->orderMock = $this->getMock( - 'Magento\Sales\Model\Order', - ['load', 'getId', 'getPayment', 'save'], - [], - '', - false - ); - - $this->objectManagerMock = $this->getMock( - 'Magento\Framework\ObjectManager\ObjectManager', - ['create'], - [], - '', - false - ); - - $this->resultRedirectMock = $this->getMock( 'Magento\Backend\Model\View\Result\Redirect', ['setPath'], @@ -111,8 +114,6 @@ protected function setUp() $this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http') ->setMethods(['getParam']) ->disableOriginalConstructor()->getMock(); - - $this->contextMock->expects($this->once())->method('getObjectManager')->willReturn($this->objectManagerMock); $this->contextMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock); $this->contextMock->expects($this->once())->method('getMessageManager')->willReturn($this->messageManagerMock); $this->contextMock->expects($this->once()) @@ -122,7 +123,9 @@ protected function setUp() $this->reviewPayment = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject( 'Magento\Sales\Controller\Adminhtml\Order\ReviewPayment', [ - 'context' => $this->contextMock + 'context' => $this->contextMock, + 'orderManager' => $this->orderManagementMock, + 'orderRepository' => $this->orderRepositoryMock ] ); } @@ -138,13 +141,17 @@ public function testExecuteUpdateAction() $this->resultRedirectFactoryMock->expects($this->once())->method('create') ->willReturn($this->resultRedirectMock); - $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\Sales\Model\Order') - ->willReturn($this->orderMock); - $this->orderMock->expects($this->once())->method('load')->with($orderId)->willReturn($this->orderMock); - $this->orderMock->expects($this->any())->method('getId')->willReturn($orderId); + $this->orderRepositoryMock->expects($this->once()) + ->method('get') + ->with($orderId) + ->willReturn($this->orderMock); + $this->orderMock->expects($this->any())->method('getEntityId')->willReturn($orderId); $this->orderMock->expects($this->any())->method('getPayment')->willReturn($this->paymentMock); - $this->orderMock->expects($this->once())->method('save')->willReturnSelf(); + $this->orderRepositoryMock->expects($this->once()) + ->method('save') + ->with($this->orderMock) + ->willReturnSelf(); $this->paymentMock->expects($this->once())->method('update'); $this->paymentMock->expects($this->any())->method('getIsTransactionApproved')->willReturn(true); diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/ViewTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/ViewTest.php index b10539c45a0db..3037e323da0ce 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/ViewTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/ViewTest.php @@ -8,6 +8,7 @@ /** * @covers \Magento\Sales\Controller\Adminhtml\Order\View * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.TooManyFields) */ class ViewTest extends \PHPUnit_Framework_TestCase { @@ -86,8 +87,24 @@ class ViewTest extends \PHPUnit_Framework_TestCase */ protected $loggerMock; + /** + * @var \Magento\Sales\Api\OrderManagementInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderManagementMock; + + /** + * @var \Magento\Sales\Api\OrderRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderRepositoryMock; + public function setUp() { + $this->orderManagementMock = $this->getMockBuilder('Magento\Sales\Api\OrderManagementInterface') + ->getMockForAbstractClass(); + $this->orderRepositoryMock = $this->getMockBuilder('Magento\Sales\Api\OrderRepositoryInterface') + ->getMockForAbstractClass(); + $this->loggerMock = $this->getMockBuilder('Psr\Log\LoggerInterface') + ->getMockForAbstractClass(); $this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface') ->getMock(); $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') @@ -123,8 +140,6 @@ public function setUp() $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') ->disableOriginalConstructor() ->getMock(); - $this->loggerMock = $this->getMockBuilder('Psr\Log\LoggerInterface') - ->getMock(); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->context = $objectManager->getObject( @@ -143,7 +158,10 @@ public function setUp() 'context' => $this->context, 'coreRegistry' => $this->coreRegistryMock, 'resultPageFactory' => $this->resultPageFactoryMock, - 'resultRedirectFactory' => $this->resultRedirectFactoryMock + 'resultRedirectFactory' => $this->resultRedirectFactoryMock, + 'orderManagement' => $this->orderManagementMock, + 'orderRepository' => $this->orderRepositoryMock, + 'logger' => $this->loggerMock ] ); } @@ -167,7 +185,7 @@ public function testExecute() ->method('getTitle') ->willReturn($this->pageTitleMock); $this->orderMock->expects($this->atLeastOnce()) - ->method('getRealOrderId') + ->method('getIncrementId') ->willReturn($id); $this->pageTitleMock->expects($this->exactly(2)) ->method('prepend') @@ -188,7 +206,18 @@ public function testExecute() */ public function testExecuteNoOrder() { - $this->initOrder(); + $orderIdParam = 111; + + $this->requestMock->expects($this->atLeastOnce()) + ->method('getParam') + ->with('order_id') + ->willReturn($orderIdParam); + $this->orderRepositoryMock->expects($this->once()) + ->method('get') + ->with($orderIdParam) + ->willThrowException( + new \Magento\Framework\Exception\NoSuchEntityException(__('Requested entity doesn\'t exist')) + ); $this->initOrderFail(); $this->prepareRedirect(); $this->setPath('sales/*/'); @@ -213,10 +242,6 @@ public function testGlobalException() $this->resultPageFactoryMock->expects($this->once()) ->method('create') ->willThrowException($exception); - $this->objectManagerMock->expects($this->once()) - ->method('get') - ->with('Psr\Log\LoggerInterface') - ->willReturn($this->loggerMock); $this->loggerMock->expects($this->once()) ->method('critical') ->with($exception); @@ -240,24 +265,17 @@ protected function initOrder() ->method('getParam') ->with('order_id') ->willReturn($orderIdParam); - $this->objectManagerMock->expects($this->once()) - ->method('create') - ->with('Magento\Sales\Model\Order') - ->willReturn($this->orderMock); - $this->orderMock->expects($this->once()) - ->method('load') + $this->orderRepositoryMock->expects($this->once()) + ->method('get') ->with($orderIdParam) - ->willReturnSelf(); + ->willReturn($this->orderMock); } /** - * @param int $orderId + * init Order Success */ - protected function initOrderSuccess($orderId) + protected function initOrderSuccess() { - $this->orderMock->expects($this->atLeastOnce()) - ->method('getId') - ->willReturn($orderId); $this->coreRegistryMock->expects($this->exactly(2)) ->method('register') ->withConsecutive( @@ -268,9 +286,6 @@ protected function initOrderSuccess($orderId) protected function initOrderFail() { - $this->orderMock->expects($this->atLeastOnce()) - ->method('getId') - ->willReturn(null); $this->messageManagerMock->expects($this->once()) ->method('addError') ->with('This order no longer exists.') diff --git a/app/code/Magento/Sales/Test/Unit/Helper/ReorderTest.php b/app/code/Magento/Sales/Test/Unit/Helper/ReorderTest.php index 0c46eb0207282..d67ae1d63a08f 100644 --- a/app/code/Magento/Sales/Test/Unit/Helper/ReorderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Helper/ReorderTest.php @@ -35,6 +35,11 @@ class ReorderTest extends \PHPUnit_Framework_TestCase */ protected $customerSessionMock; + /** + * @var \Magento\Sales\Api\OrderRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $repositoryMock; + /** * @return void */ @@ -55,9 +60,12 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); + $this->repositoryMock = $this->getMockBuilder('Magento\Sales\Api\OrderRepositoryInterface') + ->getMockForAbstractClass(); $this->helper = new \Magento\Sales\Helper\Reorder( $contextMock, - $this->customerSessionMock + $this->customerSessionMock, + $this->repositoryMock ); $this->storeParam = $this->getMockBuilder('Magento\Sales\Model\Store') @@ -131,7 +139,11 @@ protected function setupScopeConfigMock($returnValue) public function testCanReorderStoreNotAllowed() { $this->setupOrderMock(false); - $this->assertFalse($this->helper->canReorder($this->orderMock)); + $this->repositoryMock->expects($this->once()) + ->method('get') + ->with(1) + ->willReturn($this->orderMock); + $this->assertFalse($this->helper->canReorder(1)); } /** @@ -146,8 +158,11 @@ public function testCanReorderCustomerNotLoggedIn() $this->customerSessionMock->expects($this->once()) ->method('isLoggedIn') ->will($this->returnValue(false)); - - $this->assertTrue($this->helper->canReorder($this->orderMock)); + $this->repositoryMock->expects($this->once()) + ->method('get') + ->with(1) + ->willReturn($this->orderMock); + $this->assertTrue($this->helper->canReorder(1)); } /** @@ -168,8 +183,11 @@ public function testCanReorderCustomerLoggedInAndOrderCanReorder($orderCanReorde $this->orderMock->expects($this->once()) ->method('canReorder') ->will($this->returnValue($orderCanReorder)); - - $this->assertEquals($orderCanReorder, $this->helper->canReorder($this->orderMock)); + $this->repositoryMock->expects($this->once()) + ->method('get') + ->with(1) + ->willReturn($this->orderMock); + $this->assertEquals($orderCanReorder, $this->helper->canReorder(1)); } /** diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Customer/BuilderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Customer/BuilderTest.php deleted file mode 100644 index b7d3ac881228f..0000000000000 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Customer/BuilderTest.php +++ /dev/null @@ -1,160 +0,0 @@ -objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface'); - - $this->builder = new \Magento\Sales\Model\Order\Customer\Builder($this->objectManagerMock); - } - - /** - * Run test setDob method - */ - public function testSetDob() - { - $this->assertEquals($this->builder, $this->builder->setDob('dob')); - } - - /** - * Run test setEmail method - */ - public function testSetEmail() - { - $this->assertEquals($this->builder, $this->builder->setEmail('email')); - } - - /** - * Run test setFirstName method - */ - public function testSetFirstName() - { - $this->assertEquals($this->builder, $this->builder->setFirstName('first_name')); - } - - /** - * Run test setGender method - */ - public function testSetGender() - { - $this->assertEquals($this->builder, $this->builder->setGender('gender')); - } - - /** - * Run test setGroupId method - */ - public function testSetGroupId() - { - $this->assertEquals($this->builder, $this->builder->setGroupId('group_id')); - } - - /** - * Run test setId method - */ - public function testSetId() - { - $this->assertEquals($this->builder, $this->builder->setId('id')); - } - - /** - * Run test setIsGuest method - */ - public function testSetIsGuest() - { - $this->assertEquals($this->builder, $this->builder->setIsGuest('is_guest')); - } - - /** - * Run test setLastName method - */ - public function testSetLastName() - { - $this->assertEquals($this->builder, $this->builder->setLastName('last_name')); - } - - /** - * Run test setMiddleName method - */ - public function testSetMiddleName() - { - $this->assertEquals($this->builder, $this->builder->setMiddleName('middle_name')); - } - - /** - * Run test setNote method - */ - public function testSetNote() - { - $this->assertEquals($this->builder, $this->builder->setNote('note')); - } - - /** - * Run test setNoteNotify method - */ - public function testSetNoteNotify() - { - $this->assertEquals($this->builder, $this->builder->setNoteNotify('note_notify')); - } - - /** - * Run test setPrefix method - */ - public function testSetPrefix() - { - $this->assertEquals($this->builder, $this->builder->setPrefix('prefix')); - } - - /** - * Run test setSuffix method - */ - public function testSetSuffix() - { - $this->assertEquals($this->builder, $this->builder->setSuffix('suffix')); - } - - /** - * Run test setTaxvat method - */ - public function testSetTaxvat() - { - $this->assertEquals($this->builder, $this->builder->setTaxvat('taxvat')); - } - - /** - * Run test create method - */ - public function testCreate() - { - $customerMock = $this->getMock( - 'Magento\Sales\Model\Order\Customer', - [], - [], - '', - false - ); - $this->objectManagerMock->expects($this->once()) - ->method('create') - ->will($this->returnValue($customerMock)); - - $this->assertEquals($customerMock, $this->builder->create()); - } -} diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Customer/ManagementTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php similarity index 96% rename from app/code/Magento/Sales/Test/Unit/Model/Order/Customer/ManagementTest.php rename to app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php index f7f64f25d4127..62ab12af42dda 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Customer/ManagementTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php @@ -3,12 +3,12 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sales\Test\Unit\Model\Order\Customer; +namespace Magento\Sales\Test\Unit\Model\Order; /** * Class BuilderTest */ -class ManagementTest extends \PHPUnit_Framework_TestCase +class CustomerManagementTest extends \PHPUnit_Framework_TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject @@ -41,7 +41,7 @@ class ManagementTest extends \PHPUnit_Framework_TestCase protected $regionFactory; /** - * @var \Magento\Sales\Model\Order\Customer\Management + * @var \Magento\Sales\Model\Order\CustomerManagement */ protected $service; @@ -72,7 +72,7 @@ protected function setUp() ); $this->orderRepository = $this->getMock('\Magento\Sales\Api\OrderRepositoryInterface'); - $this->service = new \Magento\Sales\Model\Order\Customer\Management( + $this->service = new \Magento\Sales\Model\Order\CustomerManagement( $this->objectCopyService, $this->accountManagement, $this->customerFactory, diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerTest.php deleted file mode 100644 index 938d894805101..0000000000000 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerTest.php +++ /dev/null @@ -1,247 +0,0 @@ -objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - } - - /** - * Run test getDob method - * - * @param array $parameters - * @dataProvider providerCustomerData - */ - public function testGetDob(array $parameters) - { - /** @var \Magento\Sales\Model\Order\Customer $customer */ - $customer = $this->objectManager->getObject('Magento\Sales\Model\Order\Customer', $parameters); - - $this->assertEquals($parameters['customerDob'], $customer->getDob()); - } - - /** - * Run test getEmail method - * - * @param array $parameters - * @dataProvider providerCustomerData - */ - public function testGetEmail(array $parameters) - { - /** @var \Magento\Sales\Model\Order\Customer $customer */ - $customer = $this->objectManager->getObject('Magento\Sales\Model\Order\Customer', $parameters); - - $this->assertEquals($parameters['customerEmail'], $customer->getEmail()); - } - - /** - * Run test getFirstName method - * - * @param array $parameters - * @dataProvider providerCustomerData - */ - public function testGetFirstName(array $parameters) - { - /** @var \Magento\Sales\Model\Order\Customer $customer */ - $customer = $this->objectManager->getObject('Magento\Sales\Model\Order\Customer', $parameters); - - $this->assertEquals($parameters['customerFirstName'], $customer->getFirstName()); - } - - /** - * Run test getGender method - * - * @param array $parameters - * @dataProvider providerCustomerData - */ - public function testGetGender(array $parameters) - { - /** @var \Magento\Sales\Model\Order\Customer $customer */ - $customer = $this->objectManager->getObject('Magento\Sales\Model\Order\Customer', $parameters); - - $this->assertEquals($parameters['customerGender'], $customer->getGender()); - } - - /** - * Run test getGroupId method - * - * @param array $parameters - * @dataProvider providerCustomerData - */ - public function testGetGroupId(array $parameters) - { - /** @var \Magento\Sales\Model\Order\Customer $customer */ - $customer = $this->objectManager->getObject('Magento\Sales\Model\Order\Customer', $parameters); - - $this->assertEquals($parameters['customerGroupId'], $customer->getGroupId()); - } - - /** - * Run test getId method - * - * @param array $parameters - * @dataProvider providerCustomerData - */ - public function testGetId(array $parameters) - { - /** @var \Magento\Sales\Model\Order\Customer $customer */ - $customer = $this->objectManager->getObject('Magento\Sales\Model\Order\Customer', $parameters); - - $this->assertEquals($parameters['customerId'], $customer->getId()); - } - - /** - * Run test getIsGuest method - * - * @param array $parameters - * @dataProvider providerCustomerData - */ - public function testGetIsGuest(array $parameters) - { - /** @var \Magento\Sales\Model\Order\Customer $customer */ - $customer = $this->objectManager->getObject('Magento\Sales\Model\Order\Customer', $parameters); - - $this->assertEquals($parameters['customerIsGuest'], $customer->getIsGuest()); - } - - /** - * Run test getLastName method - * - * @param array $parameters - * @dataProvider providerCustomerData - */ - public function testGetLastName(array $parameters) - { - /** @var \Magento\Sales\Model\Order\Customer $customer */ - $customer = $this->objectManager->getObject('Magento\Sales\Model\Order\Customer', $parameters); - - $this->assertEquals($parameters['customerLastName'], $customer->getLastName()); - } - - /** - * Run test getMiddleName method - * - * @param array $parameters - * @dataProvider providerCustomerData - */ - public function testGetMiddleName(array $parameters) - { - /** @var \Magento\Sales\Model\Order\Customer $customer */ - $customer = $this->objectManager->getObject('Magento\Sales\Model\Order\Customer', $parameters); - - $this->assertEquals($parameters['customerMiddleName'], $customer->getMiddleName()); - } - - /** - * Run test getNote method - * - * @param array $parameters - * @dataProvider providerCustomerData - */ - public function testGetNote(array $parameters) - { - /** @var \Magento\Sales\Model\Order\Customer $customer */ - $customer = $this->objectManager->getObject('Magento\Sales\Model\Order\Customer', $parameters); - - $this->assertEquals($parameters['customerNote'], $customer->getNote()); - } - - /** - * Run test getNoteNotify method - * - * @param array $parameters - * @dataProvider providerCustomerData - */ - public function testGetNoteNotify(array $parameters) - { - /** @var \Magento\Sales\Model\Order\Customer $customer */ - $customer = $this->objectManager->getObject('Magento\Sales\Model\Order\Customer', $parameters); - - $this->assertEquals($parameters['customerNoteNotify'], $customer->getNoteNotify()); - } - - /** - * Run test getPrefix method - * - * @param array $parameters - * @dataProvider providerCustomerData - */ - public function testGetPrefix(array $parameters) - { - /** @var \Magento\Sales\Model\Order\Customer $customer */ - $customer = $this->objectManager->getObject('Magento\Sales\Model\Order\Customer', $parameters); - - $this->assertEquals($parameters['customerPrefix'], $customer->getPrefix()); - } - - /** - * Run test getSuffix method - * - * @param array $parameters - * @dataProvider providerCustomerData - */ - public function testGetSuffix(array $parameters) - { - /** @var \Magento\Sales\Model\Order\Customer $customer */ - $customer = $this->objectManager->getObject('Magento\Sales\Model\Order\Customer', $parameters); - - $this->assertEquals($parameters['customerSuffix'], $customer->getSuffix()); - } - - /** - * Run test getTaxvat method - * - * @param array $parameters - * @dataProvider providerCustomerData - */ - public function testGetTaxvat(array $parameters) - { - /** @var \Magento\Sales\Model\Order\Customer $customer */ - $customer = $this->objectManager->getObject('Magento\Sales\Model\Order\Customer', $parameters); - - $this->assertEquals($parameters['customerTaxvat'], $customer->getTaxvat()); - } - - /** - * Data to insert into constructor of the test object - * - * @return array - */ - public function providerCustomerData() - { - return [ - [ - [ - 'customerDob' => 'customer_dob', - 'customerEmail' => 'customer_email', - 'customerFirstName' => 'customer_first_name', - 'customerGender' => 'customer_gender', - 'customerGroupId' => 'customer_group_id', - 'customerId' => 'customer_id', - 'customerIsGuest' => 'customer_is_guest', - 'customerLastName' => 'customer_last_name', - 'customerMiddleName' => 'customer_middle_name', - 'customerNote' => 'customer_note', - 'customerNoteNotify' => 'customer_note_notify', - 'customerPrefix' => 'customer_prefix', - 'customerSuffix' => 'customer_suffix', - 'customerTaxvat' => 'customer_taxvat', - ], - ] - ]; - } -} diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/DataProviderTest,php b/app/code/Magento/Sales/Test/Unit/Model/Order/DataProviderTest,php deleted file mode 100644 index d16ed34395e13..0000000000000 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/DataProviderTest,php +++ /dev/null @@ -1,206 +0,0 @@ -collectionFactoryMock = $this->getMockBuilder( - 'Magento\Sales\Model\Resource\Order\Grid\CollectionFactory' - ) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $this->collectionMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\Grid\Collection') - ->disableOriginalConstructor() - ->getMock(); - - $this->collectionFactoryMock->expects($this->once()) - ->method('create') - ->willReturn($this->collectionMock); - - $this->dataProvider = new \Magento\Sales\Model\Order\DataProvider( - 'data-provider-name', - 'entity_id', - 'entity_id', - $this->collectionFactoryMock, - [ - 'fieldSet' => [ - 'fields' => [ - 'field' => null - ] - ] - ], - [ - 'config' => [] - ] - ); - } - - public function testGetName() - { - $this->assertEquals($this->dataProvider->getName(), 'data-provider-name'); - } - - public function testGetPrimaryFieldName() - { - $this->assertEquals($this->dataProvider->getPrimaryFieldName(), 'entity_id'); - } - - public function testGetRequestFieldName() - { - $this->assertEquals($this->dataProvider->getRequestFieldName(), 'entity_id'); - } - - public function testGetMeta() - { - $this->assertEquals( - $this->dataProvider->getMeta(), - [ - 'fieldSet' => [ - 'fields' => [ - 'field' => null - ] - ] - ] - ); - } - - public function testGetFieldSetMetaInfo() - { - $this->assertEquals( - $this->dataProvider->getFieldSetMetaInfo('fieldSet'), - [ - 'fields' => [ - 'field' => null - ] - ] - ); - } - - public function testGetFieldsMetaInfo() - { - $this->assertEquals( - $this->dataProvider->getFieldsMetaInfo('fieldSet'), - [ - 'field' => null - ] - ); - } - - public function testGetFieldMetaInfo() - { - $this->assertEquals( - $this->dataProvider->getFieldMetaInfo('fieldSet', 'field'), - [] - ); - } - - public function testAddFilter() - { - $this->collectionMock->expects($this->once()) - ->method('addFieldToFilter') - ->with('field', ['condition' => 1]) - ->willReturnSelf(); - $this->dataProvider->addFilter('field', ['condition' => 1]); - } - - public function testAddField() - { - $this->collectionMock->expects($this->once()) - ->method('addFieldToSelect') - ->with('field', 'alias') - ->willReturnSelf(); - $this->dataProvider->addField('field', 'alias'); - } - - public function testAddOrder() - { - $this->collectionMock->expects($this->once()) - ->method('addOrder') - ->with('field', 'DESC') - ->willReturnSelf(); - $this->dataProvider->addOrder('field', 'DESC'); - } - - public function testSetLimit() - { - $this->collectionMock->expects($this->once()) - ->method('setPageSize') - ->with(10) - ->willReturnSelf(); - $this->collectionMock->expects($this->once()) - ->method('setCurPage') - ->with(10) - ->willReturnSelf(); - $this->dataProvider->setLimit(10, 10); - } - - public function testRemoveField() - { - $this->collectionMock->expects($this->once()) - ->method('removeFieldFromSelect') - ->with('field', 'alias') - ->willReturnSelf(); - $this->dataProvider->removeField('field', 'alias'); - } - - public function testRemoveAllFields() - { - $this->collectionMock->expects($this->once()) - ->method('removeAllFieldsFromSelect') - ->willReturnSelf(); - $this->dataProvider->removeAllFields(); - } - - public function testGetData() - { - $this->collectionMock->expects($this->once()) - ->method('toArray') - ->willReturn(['data' => 'data']); - $this->assertEquals( - $this->dataProvider->getData(), - ['data' => 'data'] - ); - } - - public function testCount() - { - $this->collectionMock->expects($this->once()) - ->method('count') - ->willReturn(1); - $this->assertEquals(1, $this->dataProvider->count()); - } - - public function testGetConfigData() - { - $this->assertEquals( - [], - $this->dataProvider->getConfigData() - ); - } -} diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 48b8ace07b2a3..adaeb021711d2 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -466,61 +466,104 @@ - + - sales_order.customer_firstname - sales_order.customer_lastname + + sales_order + customer_firstname + + + sales_order + customer_lastname + - + - sales_shipping_address.firstname - sales_shipping_address.lastname + + sales_shipping_address + firstname + + + sales_shipping_address + lastname + - + - sales_billing_address.firstname - sales_billing_address.lastname + + sales_billing_address + firstname + + + sales_billing_address + lastname + - + - sales_shipping_address.street - sales_shipping_address.city - sales_shipping_address.region - sales_shipping_address.postcode + + sales_shipping_address + street + + + sales_shipping_address + city + + + sales_shipping_address + region + + + sales_shipping_address + postcode + , - + - sales_billing_address.street - sales_billing_address.city - sales_billing_address.region - sales_billing_address.postcode + + sales_billing_address + street + + + sales_billing_address + city + + + sales_billing_address + region + + + sales_billing_address + postcode + , - + - sales_read - sales_order_payment - - method + sales_order_payment + method + + + sales_order + entity_id + - parent_id - sales_order.entity_id @@ -533,43 +576,74 @@ - + Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter + + + + + Magento\Sales\Model\Resource\Order\Grid\Collection + Magento\Sales\Model\Resource\Order\Invoice\Grid\Collection + Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection + Magento\Sales\Model\Resource\Order\Creditmemo\Grid\Collection + Magento\Sales\Model\Resource\Order\Invoice\Orders\Grid\Collection + Magento\Sales\Model\Resource\Order\Shipment\Order\Grid\Collection + Magento\Sales\Model\Resource\Order\Creditmemo\Order\Grid\Collection + + + + + + Magento\Framework\App\State\Proxy + + + + + sales_order_grid + Magento\Sales\Model\Resource\Order + - + - Magento\Sales\Model\Resource\Order\Grid\Collection - SalesGirdFilterPool + sales_invoice_grid + Magento\Sales\Model\Resource\Order\Invoice - + - Magento\Sales\Model\Resource\Order\Invoice\Grid\Collection - SalesGirdFilterPool + sales_shipment_grid + Magento\Sales\Model\Resource\Order\Shipment - + - Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection - SalesGirdFilterPool + sales_creditmemo_grid + Magento\Sales\Model\Resource\Order\Creditmemo - + - Magento\Sales\Model\Resource\Order\Creditmemo\Grid\Collection - SalesGirdFilterPool + sales_invoice_grid + Magento\Sales\Model\Resource\Order\Invoice - + - Magento\Framework\App\State\Proxy + sales_shipment_grid + Magento\Sales\Model\Resource\Order\Shipment - + + + + sales_creditmemo_grid + Magento\Sales\Model\Resource\Order\Creditmemo + + Magento\Sales\Model\Resource\Order diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_creditmemo_grid_block.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_creditmemo_grid_block.xml deleted file mode 100644 index e4cb20d646cbe..0000000000000 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_creditmemo_grid_block.xml +++ /dev/null @@ -1,158 +0,0 @@ - - - - - - - - sales_creditmemo_grid - Magento\Sales\Model\Resource\Order\Creditmemo\Grid\Collection - true - created_at - DESC - - 1 - - - - - entity_id - creditmemo_ids - false - - - PDF Credit Memos - sales/creditmemo/pdfcreditmemos - - - - - - - - - */*/exportCsv - CSV - - - */*/exportExcel - Excel XML - - - - - - - sales_creditmemo_grid - - Magento\Sales\Model\Order\Grid\Row\UrlGenerator - sales/creditmemo/view - - getId - - - - - - Credit Memo - text - increment_id - real_creditmemo_id - col-memo-number - col-memo-number - - - - - Created - datetime - created_at - created_at - col-period - col-period - - - - - Order - text - order_increment_id - order_increment_id - col-order-number - col-order-number - - - - - Order Date - datetime - order_created_at - order_created_at - col-period - col-period - - - - - billing_name - Bill-to Name - billing_name - col-bill-to-name - col-bill-to-name - - - - - state - Status - options - state - - col-status - col-status - - - - - base_grand_total - Refunded - currency - order_currency_code - 1 - base_grand_total - col-refunded - col-refunded - - - - - action - Action - action - getId - false - false - true - - - View - - sales/creditmemo/view - - creditmemo_id - - - col-actions - col-actions - - - - - - - diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_grid_block.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_grid_block.xml deleted file mode 100644 index 2525c2c4c1430..0000000000000 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_grid_block.xml +++ /dev/null @@ -1,159 +0,0 @@ - - - - - - - - sales_invoice_grid - Magento\Sales\Model\Resource\Order\Invoice\Grid\Collection - true - created_at - DESC - true - - 1 - - - - - entity_id - invoice_ids - false - - - PDF Invoices - sales/invoice/pdfinvoices - - - - - - - - - */*/exportCsv - CSV - - - */*/exportExcel - Excel XML - - - - - - - sales_invoice_grid - - Magento\Sales\Model\Order\Invoice\Grid\Row\UrlGenerator - sales/invoice/view - - getId - - - - - - Invoice - text - increment_id - increment_id - col-invoice-number - col-invoice-number - - - - - Invoice Date - datetime - created_at - created_at - col-period - col-period - - - - - Order - text - order_increment_id - order_increment_id - col-order-number - col-order-number - - - - - Order Date - datetime - order_created_at - order_created_at - col-period - col-period - - - - - billing_name - Bill-to Name - billing_name - col-bill-to-name - col-bill-to-name - - - - - state - Status - options - state - - col-status - col-status - - - - - grand_total - Amount - currency - order_currency_code - grand_total - col-gtpurchased - col-gtpurchased - right - - - - - action - Action - action - getId - false - false - true - - - View - - sales/invoice/view - - invoice_id - - - col-actions - col-actions - - - - - - - diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_grid_block.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_grid_block.xml deleted file mode 100644 index 2af914b40b228..0000000000000 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_grid_block.xml +++ /dev/null @@ -1,206 +0,0 @@ - - - - - - - - sales_order_grid - Magento\Sales\Model\Resource\Order\Grid\Collection - true - created_at - DESC - 1 - - 1 - - - - - entity_id - order_ids - 0 - - Magento\Sales\Model\Order\Grid\Massaction\ItemsUpdater - - Cancel - sales/order/massCancel - - - Hold - sales/order/massHold - - - Unhold - sales/order/massUnhold - - - Print Invoices - sales/order/pdfinvoices - - - Print Packing Slips - sales/order/pdfshipments - - - Print Credit Memos - sales/order/pdfcreditmemos - - - Print All - sales/order/pdfdocs - - - Print Shipping Labels - adminhtml/order_shipment/massPrintShippingLabel - - - - - - - - - sales/*/exportCsv - CSV - - - sales/*/exportExcel - Excel XML - - - - - - - sales_order_grid - - Magento\Sales\Model\Order\Grid\Row\UrlGenerator - sales/order/view - - getId - - - - - - Order - text - increment_id - real_order_id - col-order-number - col-order-number - - - - - Purchase Point - store - 1 - 1 - store_id - store_id - col-from-store - col-from-store - - - - - Purchased - datetime - created_at - created_at - col-period - col-period - - - - - billing_name - Bill-to Name - billing_name - col-name - col-name - - - - - shipping_name - Ship-to Name - shipping_name - col-name - col-name - - - - - base_grand_total - Grand Total (Base) - currency - base_currency_code - 1 - base_grand_total - col-gtbase - col-gtbase - - - - - grand_total - Grand Total (Purchased) - currency - order_currency_code - 1 - grand_total - col-gtpurchased - col-gtpurchased - - - - - status - Status - options - order_currency_code - status - - col-status - col-status - - - - - action - Action - action - getId - 0 - 0 - stores - 1 - - - View - - sales/order/view - - order_id - - - col-actions - col-actions - - - - - - - - - - diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_view.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_view.xml index f0c99ecaf4464..8702286537943 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_view.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_view.xml @@ -6,10 +6,7 @@ */ --> - - - @@ -75,5 +72,14 @@ + + + + + + + + + diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_shipment_grid_block.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_shipment_grid_block.xml deleted file mode 100644 index f8e567d12027e..0000000000000 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_shipment_grid_block.xml +++ /dev/null @@ -1,148 +0,0 @@ - - - - - - - - sales_shipment_grid - Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection - created_at - DESC - - 1 - - - - - entity_id - shipment_ids - false - - - PDF Packing Slips - sales/shipment/pdfshipments - - - Print Shipping Labels - adminhtml/order_shipment/massPrintShippingLabel - - - - - - - - - */*/exportCsv - CSV - - - */*/exportExcel - Excel XML - - - - - - - sales_shipment_grid - - Magento\Sales\Model\Order\Grid\Row\UrlGenerator - sales/shipment/view - - getId - - - - - - Shipment - text - increment_id - real_shipment_id - col-shipment-number - col-shipment-number - - - - - Ship Date - datetime - created_at - created_at - col-period - col-period - - - - - Order - text - order_increment_id - order_increment_id - col-order-number - col-order-number - - - - - Order Date - datetime - order_created_at - order_created_at - col-period - col-period - - - - - shipping_name - Ship-to Name - shipping_name - col-ship-to-name - col-ship-to-name - - - - - total_qty - Total Quantity - number - total_qty - col-qty - col-qty - - - - - action - Action - action - getId - false - false - true - - - View - - sales/shipment/view - - shipment_id - - - col-actions - col-actions - - - - - - - diff --git a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_creditmemo_grid.xml b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_creditmemo_grid.xml index a787c2fe16237..c9f6758153c87 100644 --- a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_creditmemo_grid.xml +++ b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_creditmemo_grid.xml @@ -15,9 +15,9 @@ - CreditmemoGridDataProvider + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_creditmemo_grid_data_source - increment_id + entity_id id @@ -64,17 +64,18 @@ + sales_order_creditmemo_grid.sales_order_creditmemo_grid.sales_order_creditmemo_columns.ids dataGridActions csv CSV - sales/creditmemo/exportCsv + mui/export/gridToCsv xml Excel XML - sales/creditmemo/exportExcel + mui/export/gridToCsv diff --git a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_grid.xml b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_grid.xml index b6f4916e26f2e..df77cdd12091d 100644 --- a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_grid.xml +++ b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_grid.xml @@ -23,9 +23,9 @@ - OrderGridDataProvider + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_grid_data_source - increment_id + entity_id id @@ -72,17 +72,18 @@ + sales_order_grid.sales_order_grid.sales_order_columns.ids dataGridActions csv CSV - sales/order/exportCsv + mui/export/gridToCsv xml Excel XML - sales/order/exportExcel + mui/export/gridToCsv @@ -759,7 +760,7 @@ false actions - increment_id + entity_id left Action actions diff --git a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_invoice_grid.xml b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_invoice_grid.xml index 225011e3c30db..072539d481891 100644 --- a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_invoice_grid.xml +++ b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_invoice_grid.xml @@ -15,9 +15,9 @@ - InvoiceGridDataProvider + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_invoice_grid_data_source - increment_id + entity_id id @@ -64,17 +64,18 @@ + sales_order_invoice_grid.sales_order_invoice_grid.sales_order_invoice_columns.ids dataGridActions csv CSV - sales/invoice/exportCsv + mui/export/gridToCsv xml Excel XML - sales/invoice/exportExcel + mui/export/gridToCsv diff --git a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_shipment_grid.xml b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_shipment_grid.xml index cecfe5eefea19..45ca566605822 100644 --- a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_shipment_grid.xml +++ b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_shipment_grid.xml @@ -15,9 +15,9 @@ - ShipmentGridDataProvider + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_shipment_grid_data_source - increment_id + entity_id id @@ -64,17 +64,18 @@ + sales_order_shipment_grid.sales_order_shipment_grid.sales_order_shipment_columns.ids dataGridActions csv CSV - sales/shipment/exportCsv + mui/export/gridToCsv xml Excel XML - sales/shipment/exportExcel + mui/export/gridToCsv @@ -324,6 +325,11 @@ PDF Shipments sales/shipment/pdfshipments + + print_shipping_label + Print Shipping Labels + adminhtml/shipment/massPrintShippingLabel + entity_id diff --git a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_creditmemo_grid.xml b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_creditmemo_grid.xml new file mode 100644 index 0000000000000..15b85280df3aa --- /dev/null +++ b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_creditmemo_grid.xml @@ -0,0 +1,786 @@ + + ++ + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid_data_source + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid_data_source + + sales_order_creditmemo_columns + + + + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider + sales_order_view_creditmemo_grid_data_source + entity_id + id + + + + + * + + + + + + + Magento_Ui/js/grid/provider + + + + + + + ui/grid/toolbar + + + + + + Magento_Ui/js/grid/controls/bookmarks/bookmarks + dataGridActions + + + + sales_order_view_creditmemo_grid + + + + + + + + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.sales_order_creditmemo_columns + + Magento_Ui/js/grid/controls/columns + dataGridActions + + + + + + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.sales_order_view_creditmemo_columns.ids + dataGridActions + + + csv + CSV + sales/creditmemo/exportCsv + + + xml + Excel XML + sales/creditmemo/exportExcel + + + + + + + + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid_data_source + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.listing_top.listing_filters_chips + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.listing_top.bookmarks + current.search + + + + + + + + dataGridFilters + filters + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.listing_top.bookmarks + current.filters + + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.listing_top.listing_filters + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.listing_top.bookmarks:current.columns.${ $.index }.visible + + + + + + + + increment_id + Credit Memo + + + + + + + created_at + Created + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.listing_top.listing_filters + + + + + + + from + From + From + MM/dd/YYYY + + + + + + + to + To + To + MM/dd/YYYY + + + + + + + + order_increment_id + Order + + + + + + + order_created_at + Order Date + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.listing_top.listing_filters + + + + + + + from + From + From + MM/dd/YYYY + + + + + + + to + To + To + MM/dd/YYYY + + + + + + + + billing_name + Bill-to Name + + + + + + Magento\Sales\Ui\Component\Listing\Column\Creditmemo\State\Options + + + + Select... + state + Status + + + + + + + base_grand_total + Refunded + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.listing_top.listing_filters + + + + + + + from + From + From + + + + + + + to + To + To + + + + + + + Magento\Sales\Ui\Component\Listing\Column\Status\Options + + + + Select... + order_status + Order Status + + + + + + Magento\Store\Ui\Component\Listing\Column\Store\Options + + + + Select... + store_id + Purchased From + + + + + + + billing_address + Billing Address + + + + + + + shipping_address + Shipping Address + + + + + + + customer_name + Customer Name + + + + + + + customer_email + Customer Email + + + + + + Magento\Customer\Ui\Component\Listing\Column\Group\Options + + + + Select... + customer_group_id + Customer Group + + + + + + Magento\Payment\Ui\Component\Listing\Column\Method\Options + + + + Select... + payment_method + Payment Method + + + + + + + shipping_information + Shipping Information + + + + + + + subtotal + Subtotal + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.listing_top.listing_filters + + + + + + + from + From + From + + + + + + + to + To + To + + + + + + + + shipping_and_handling + Shipping and Handling + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.listing_top.listing_filters + + + + + + + from + From + From + + + + + + + to + To + To + + + + + + + + order_base_grand_total + Grand Total + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.listing_top.listing_filters + + + + + + + from + From + From + + + + + + + to + To + To + + + + + + + + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.sales_order_creditmemo_columns.ids + bottom + + + pdfcreditmemos_order + PDF Creditmemos + sales/creditmemo/pdfcreditmemos + + + entity_id + + + + + + + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.listing_top.bookmarks + current.paging + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.sales_order_creditmemo_columns.ids + bottom + + + 20 + 20 + + + 30 + 30 + + + 50 + 50 + + + 100 + 100 + + + 200 + 200 + + + + + + + + + + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.listing_top.bookmarks + current + + + true + actions + view + + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.listing_top.bookmarks + columns.${ $.index } + current.${ $.storageConfig.root} + + + + + + + + Magento_Ui/js/grid/columns/multiselect + + + false + entity_id + false + + + + + + + Magento_Ui/js/grid/columns/column + + + text + left + Credit Memo + + + + + + + Magento_Ui/js/grid/columns/date + + + date + left + Created + + + + + + + Magento_Ui/js/grid/columns/column + + + text + left + Order + + + + + + + Magento_Ui/js/grid/columns/date + + + date + left + Order Date + + + + + + + Magento_Ui/js/grid/columns/column + + + text + left + Bill-to Name + + + + + + + Magento_Ui/js/grid/columns/select + + + text + left + Status + + + + + + + Magento_Ui/js/grid/columns/column + + + text + left + Refunded + + + + + + + Magento_Ui/js/grid/columns/select + + + false + text + left + Order Status + + + + + + + Magento_Ui/js/grid/columns/column + + + ui/grid/cells/html + false + false + text + left + Purchased From + + + + + + + Magento_Ui/js/grid/columns/column + + + ui/grid/cells/html + false + text + left + Billing Address + + + + + + + Magento_Ui/js/grid/columns/column + + + ui/grid/cells/html + false + text + left + Shipping Address + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Customer Name + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Email + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Customer Group + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Payment Method + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Shipping Information + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Subtotal + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Shipping & Handling + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Adjustment Refund + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Adjustment Fee + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Grand Total + + + + + + + false + actions + entity_id + left + Action + actions + false + false + + + + + diff --git a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_invoice_grid.xml b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_invoice_grid.xml new file mode 100644 index 0000000000000..a194c0b37dc5e --- /dev/null +++ b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_invoice_grid.xml @@ -0,0 +1,695 @@ + + ++ + + sales_order_view_invoice_grid.sales_order_view_invoice_grid_data_source + sales_order_view_invoice_grid.sales_order_view_invoice_grid_data_source + + sales_order_invoice_columns + + + + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider + sales_order_view_invoice_grid_data_source + entity_id + id + + + + + * + + + + + + + Magento_Ui/js/grid/provider + + + + + + + ui/grid/toolbar + + + + + + Magento_Ui/js/grid/controls/bookmarks/bookmarks + dataGridActions + + + + sales_order_view_invoice_grid + + + + + + + + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.sales_order_invoice_columns + + Magento_Ui/js/grid/controls/columns + dataGridActions + + + + + + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.sales_order_view_invoice_columns.ids + dataGridActions + + + csv + CSV + mui/export/gridToCsv + + + xml + Excel XML + mui/export/gridToCsv + + + + + + + + + sales_order_view_invoice_grid.sales_order_view_invoice_grid_data_source + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters_chips + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.bookmarks + current.search + + + + + + + + dataGridFilters + filters + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.bookmarks + current.filters + + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.bookmarks:current.columns.${ $.index }.visible + + + + + + + + increment_id + Invoice # + + + + + + + created_at + Invoice Date + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + + + + + + + from + From + From + MM/dd/YYYY + + + + + + + to + To + To + MM/dd/YYYY + + + + + + + + order_increment_id + Order # + + + + + + + order_created_at + Order Date + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + + + + + + + from + From + From + MM/dd/YYYY + + + + + + + to + To + To + MM/dd/YYYY + + + + + + + + billing_name + Bill-to Name + + + + + + Magento\Sales\Ui\Component\Listing\Column\Invoice\State\Options + + + + Select... + state + Status + + + + + + Magento\Store\Ui\Component\Listing\Column\Store\Options + + + + Select... + store_id + Purchased From + + + + + + + billing_address + Billing Address + + + + + + + shipping_address + Shipping Address + + + + + + + customer_name + Customer Name + + + + + + + customer_email + Customer Email + + + + + + Magento\Customer\Ui\Component\Listing\Column\Group\Options + + + + Select... + customer_group_id + Customer Group + + + + + + Magento\Payment\Ui\Component\Listing\Column\Method\Options + + + + Select... + payment_method + Payment Method + + + + + + + shipping_information + Shipping Information + + + + + + + subtotal + Subtotal + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + + + + + + + from + From + From + + + + + + + to + To + To + + + + + + + + shipping_and_handling + Shipping and Handling + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + + + + + + + from + From + From + + + + + + + to + To + To + + + + + + + + grand_total + Grand Total + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + + + + + + + from + From + From + + + + + + + to + To + To + + + + + + + + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.sales_order_invoice_columns.ids + bottom + + + pdfinvoices_order + PDF Invoices + sales/invoice/pdfinvoices + + + entity_id + + + + + + + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.bookmarks + current.paging + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.sales_order_invoice_columns.ids + bottom + + + 20 + 20 + + + 30 + 30 + + + 50 + 50 + + + 100 + 100 + + + 200 + 200 + + + + + + + + + + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.bookmarks + current + + + true + actions + view + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.bookmarks + columns.${ $.index } + current.${ $.storageConfig.root} + + + + + + + + Magento_Ui/js/grid/columns/multiselect + + + false + entity_id + false + + + + + + + Magento_Ui/js/grid/columns/column + + + text + asc + left + Invoice + + + + + + + Magento_Ui/js/grid/columns/date + + + date + left + Invoice Date + + + + + + + Magento_Ui/js/grid/columns/column + + + text + asc + left + Order # + + + + + + + Magento_Ui/js/grid/columns/date + + + date + left + Order Date + + + + + + + Magento_Ui/js/grid/columns/column + + + text + left + Bill-to Name + + + + + + + Magento_Ui/js/grid/columns/select + + + text + left + Status + + + + + + + Magento_Ui/js/grid/columns/column + + + text + left + Amount + + + + + + + Magento_Ui/js/grid/columns/column + + + ui/grid/cells/html + false + false + text + left + Purchased From + + + + + + + Magento_Ui/js/grid/columns/column + + + ui/grid/cells/html + false + text + left + Billing Address + + + + + + + Magento_Ui/js/grid/columns/column + + + ui/grid/cells/html + false + text + left + Shipping Address + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Customer Name + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Email + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Customer Group + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Payment Method + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Shipping Information + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Subtotal + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Shipping and Handling + + + + + + + false + actions + increment_id + left + Action + actions + false + false + + + + + diff --git a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_shipment_grid.xml b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_shipment_grid.xml new file mode 100644 index 0000000000000..46fa0fc448aaa --- /dev/null +++ b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_shipment_grid.xml @@ -0,0 +1,612 @@ + + ++ + + sales_order_view_shipment_grid.sales_order_view_shipment_grid_data_source + sales_order_view_shipment_grid.sales_order_view_shipment_grid_data_source + + sales_order_shipment_columns + + + + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider + sales_order_view_shipment_grid_data_source + entity_id + id + + + + + * + + + + + + + Magento_Ui/js/grid/provider + + + + + + + ui/grid/toolbar + + + + + + Magento_Ui/js/grid/controls/bookmarks/bookmarks + dataGridActions + + + + sales_order_view_shipment_grid + + + + + + + + + sales_order_view_shipment_grid.sales_order_view_shipment_grid.sales_order_shipment_columns + + Magento_Ui/js/grid/controls/columns + dataGridActions + + + + + + + sales_order_view_shipment_grid.sales_order_view_shipment_grid.sales_order_view_shipment_columns.ids + dataGridActions + + + csv + CSV + mui/export/gridToCsv + + + xml + Excel XML + mui/export/gridToCsv + + + + + + + + + sales_order_view_shipment_grid.sales_order_view_shipment_grid_data_source + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.listing_filters_chips + + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.bookmarks + current.search + + + + + + + + dataGridFilters + filters + + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.bookmarks + current.filters + + + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.listing_filters + + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.bookmarks:current.columns.${ $.index }.visible + + + + + + + + increment_id + Shipment # + + + + + + + created_at + Ship Date + + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.listing_filters + + + + + + + from + From + From + MM/dd/YYYY + + + + + + + to + To + To + MM/dd/YYYY + + + + + + + + order_increment_id + Order # + + + + + + + order_created_at + Order Date + + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.listing_filters + + + + + + + from + From + From + MM/dd/YYYY + + + + + + + to + To + To + MM/dd/YYYY + + + + + + + + shipping_name + Ship-to Name + + + + + + + total_qty + Total Quantity + + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.listing_filters + + + + + + + from + From + From + + + + + + + to + To + To + + + + + + + Magento\Sales\Ui\Component\Listing\Column\Status\Options + + + + Select... + order_status + Order Status + + + + + + Magento\Store\Ui\Component\Listing\Column\Store\Options + + + + Select... + store_id + Purchased From + + + + + + + customer_name + Customer Name + + + + + + + customer_email + Customer Email + + + + + + Magento\Customer\Ui\Component\Listing\Column\Group\Options + + + + Select... + customer_group_id + Customer Group + + + + + + + billing_address + Billing Address + + + + + + + shipping_address + Shipping Address + + + + + + Magento\Payment\Ui\Component\Listing\Column\Method\Options + + + + Select... + payment_method + Payment Method + + + + + + + shipping_information + Shipping Information + + + + + + + + sales_order_view_shipment_grid.sales_order_view_shipment_grid.sales_order_shipment_columns.ids + bottom + + + pdfshipments_order + PDF Shipments + sales/shipment/pdfshipments + + + entity_id + + + + + + + + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.bookmarks + current.paging + + sales_order_view_shipment_grid.sales_order_view_shipment_grid.sales_order_shipment_columns.ids + bottom + + + 20 + 20 + + + 30 + 30 + + + 50 + 50 + + + 100 + 100 + + + 200 + 200 + + + + + + + + + + + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.bookmarks + current + + + true + actions + view + + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.bookmarks + columns.${ $.index } + current.${ $.storageConfig.root} + + + + + + + + Magento_Ui/js/grid/columns/multiselect + + + false + entity_id + false + + + + + + + Magento_Ui/js/grid/columns/column + + + text + asc + left + Shipment + + + + + + + Magento_Ui/js/grid/columns/date + + + date + left + Ship Date + + + + + + + Magento_Ui/js/grid/columns/column + + + text + asc + left + Order + + + + + + + Magento_Ui/js/grid/columns/date + + + date + left + Order Date + + + + + + + Magento_Ui/js/grid/columns/column + + + text + left + Ship-to Name + + + + + + + Magento_Ui/js/grid/columns/column + + + text + left + Total Quantity + + + + + + + Magento_Ui/js/grid/columns/select + + + false + text + left + Order Status + + + + + + + Magento_Ui/js/grid/columns/column + + + ui/grid/cells/html + false + false + text + left + Purchased From + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Customer Name + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Email + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Customer Group + + + + + + + Magento_Ui/js/grid/columns/column + + + ui/grid/cells/html + false + text + left + Billing Address + + + + + + + Magento_Ui/js/grid/columns/column + + + ui/grid/cells/html + false + text + left + Shipping Address + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Payment Method + + + + + + + Magento_Ui/js/grid/columns/column + + + false + text + left + Shipping Information + + + + + + + false + actions + entity_id + left + Action + actions + false + false + + + + + diff --git a/app/code/Magento/Sales/view/frontend/templates/order/history.phtml b/app/code/Magento/Sales/view/frontend/templates/order/history.phtml index dafd6a2a61513..5b2b271ad8cb6 100644 --- a/app/code/Magento/Sales/view/frontend/templates/order/history.phtml +++ b/app/code/Magento/Sales/view/frontend/templates/order/history.phtml @@ -35,7 +35,7 @@ - helper('Magento\Sales\Helper\Reorder')->canReorder($_order)) : ?> + helper('Magento\Sales\Helper\Reorder')->canReorder($_order->getEntityId())) : ?> diff --git a/app/code/Magento/Sales/view/frontend/templates/order/info/buttons.phtml b/app/code/Magento/Sales/view/frontend/templates/order/info/buttons.phtml index c1c22775b2f65..10334a2909d8a 100644 --- a/app/code/Magento/Sales/view/frontend/templates/order/info/buttons.phtml +++ b/app/code/Magento/Sales/view/frontend/templates/order/info/buttons.phtml @@ -9,7 +9,7 @@ ?>
getOrder() ?> - helper('Magento\Sales\Helper\Reorder')->canReorder($_order)) : ?> + helper('Magento\Sales\Helper\Reorder')->canReorder($_order->getEntityId())) : ?> diff --git a/app/code/Magento/Sales/view/frontend/templates/order/recent.phtml b/app/code/Magento/Sales/view/frontend/templates/order/recent.phtml index b5004c174dce7..d38342f88661e 100644 --- a/app/code/Magento/Sales/view/frontend/templates/order/recent.phtml +++ b/app/code/Magento/Sales/view/frontend/templates/order/recent.phtml @@ -45,7 +45,7 @@ - helper('Magento\Sales\Helper\Reorder')->canReorder($_order)) : ?> + helper('Magento\Sales\Helper\Reorder')->canReorder($_order->getEntityId())) : ?> diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/MassPrintShippingLabel.php b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/MassPrintShippingLabel.php index 8c3b4d1115ab0..027d8eeec6e7d 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/MassPrintShippingLabel.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/MassPrintShippingLabel.php @@ -10,32 +10,61 @@ use Magento\Framework\App\ResponseInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; +use Magento\Ui\Component\MassAction\Filter; +use Magento\Backend\App\Action\Context; +use Magento\Shipping\Model\Shipping\LabelGenerator; +use Magento\Framework\App\Response\Http\FileFactory; +use Magento\Sales\Model\Resource\Order\Shipment\CollectionFactory as ShipmentCollectionFactory; +use Magento\Framework\Controller\ResultInterface; +use Magento\Sales\Model\Resource\Order\CollectionFactory; +/** + * Class MassPrintShippingLabel + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class MassPrintShippingLabel extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { /** - * @var \Magento\Shipping\Model\Shipping\LabelGenerator + * @var LabelGenerator */ protected $labelGenerator; /** - * @var \Magento\Framework\App\Response\Http\FileFactory + * @var FileFactory + */ + protected $fileFactory; + + /** + * @var CollectionFactory + */ + protected $collectionFactory; + + /** + * @var ShipmentCollectionFactory */ - protected $_fileFactory; + protected $shipmentCollectionFactory; /** - * @param Action\Context $context - * @param \Magento\Shipping\Model\Shipping\LabelGenerator $labelGenerator - * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @param Context $context + * @param Filter $filter + * @param CollectionFactory $collectionFactory + * @param FileFactory $fileFactory + * @param LabelGenerator $labelGenerator + * @param ShipmentCollectionFactory $shipmentCollectionFactory */ public function __construct( - Action\Context $context, - \Magento\Shipping\Model\Shipping\LabelGenerator $labelGenerator, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + Context $context, + Filter $filter, + CollectionFactory $collectionFactory, + FileFactory $fileFactory, + LabelGenerator $labelGenerator, + ShipmentCollectionFactory $shipmentCollectionFactory ) { + $this->fileFactory = $fileFactory; + $this->collectionFactory = $collectionFactory; + $this->shipmentCollectionFactory = $shipmentCollectionFactory; $this->labelGenerator = $labelGenerator; - $this->_fileFactory = $fileFactory; - parent::__construct($context); + parent::__construct($context, $filter); } /** @@ -51,43 +80,15 @@ protected function _isAllowed() * Push pdf document with shipping labels to user browser * * @param AbstractCollection $collection - * @return ResponseInterface|void - * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @return ResponseInterface|ResultInterface */ protected function massAction(AbstractCollection $collection) { - $request = $this->getRequest(); - $ids = $collection->getAllIds(); - $createdFromOrders = !empty($ids); - $shipments = null; $labelsContent = []; - switch ($request->getParam('massaction_prepare_key')) { - case 'shipment_ids': - $ids = $request->getParam('shipment_ids'); - array_filter($ids, 'intval'); - if (!empty($ids)) { - $shipments = $this->_objectManager->create( - 'Magento\Sales\Model\Resource\Order\Shipment\Collection' - )->addFieldToFilter( - 'entity_id', - ['in' => $ids] - ); - } - break; - case 'order_ids': - $ids = $request->getParam('order_ids'); - array_filter($ids, 'intval'); - if (!empty($ids)) { - $shipments = $this->_objectManager->create( - 'Magento\Sales\Model\Resource\Order\Shipment\Collection' - )->setOrderFilter( - ['in' => $ids] - ); - } - break; - } + $shipments = $this->shipmentCollectionFactory->create()->setOrderFilter(['in' => $collection->getAllIds()]); - if ($shipments && $shipments->getSize()) { + if ($shipments->getSize()) { + /** @var \Magento\Sales\Model\Order\Shipment $shipment */ foreach ($shipments as $shipment) { $labelContent = $shipment->getShippingLabel(); if ($labelContent) { @@ -98,7 +99,7 @@ protected function massAction(AbstractCollection $collection) if (!empty($labelsContent)) { $outputPdf = $this->labelGenerator->combineLabelsPdf($labelsContent); - return $this->_fileFactory->create( + return $this->fileFactory->create( 'ShippingLabels.pdf', $outputPdf->render(), DirectoryList::VAR_DIR, @@ -106,12 +107,7 @@ protected function massAction(AbstractCollection $collection) ); } - if ($createdFromOrders) { - $this->messageManager->addError(__('There are no shipping labels related to selected orders.')); - $this->_redirect('sales/order/index'); - } else { - $this->messageManager->addError(__('There are no shipping labels related to selected shipments.')); - $this->_redirect('sales/shipment/index'); - } + $this->messageManager->addError(__('There are no shipping labels related to selected orders.')); + return $this->resultRedirectFactory->create()->setPath('sales/order/'); } } diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php b/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php new file mode 100644 index 0000000000000..ab4dbf392617f --- /dev/null +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php @@ -0,0 +1,94 @@ +collectionFactory = $collectionFactory; + $this->fileFactory = $fileFactory; + $this->labelGenerator = $labelGenerator; + parent::__construct($context, $filter); + } + + /** + * @return bool + */ + protected function _isAllowed() + { + return $this->_authorization->isAllowed('Magento_Sales::shipment'); + } + + /** + * 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/'); + } +} diff --git a/app/code/Magento/Shipping/composer.json b/app/code/Magento/Shipping/composer.json index 8eac513f645b5..7bdccf85c3f30 100644 --- a/app/code/Magento/Shipping/composer.json +++ b/app/code/Magento/Shipping/composer.json @@ -14,6 +14,7 @@ "magento/module-tax": "1.0.0-beta", "magento/module-catalog-inventory": "1.0.0-beta", "magento/module-quote": "1.0.0-beta", + "magento/module-ui": "1.0.0-beta", "magento/framework": "1.0.0-beta", "ext-gd": "*", "magento/magento-composer-installer": "*" diff --git a/app/code/Magento/Shipping/etc/module.xml b/app/code/Magento/Shipping/etc/module.xml index ff4283ad84048..6fe825e8deeb3 100644 --- a/app/code/Magento/Shipping/etc/module.xml +++ b/app/code/Magento/Shipping/etc/module.xml @@ -10,6 +10,7 @@ + diff --git a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php index bc99c9d736313..b4381a4dbecde 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php +++ b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php @@ -8,12 +8,18 @@ use Magento\Ui\Component\AbstractComponent; use Magento\Framework\View\Element\UiComponentFactory; use Magento\Framework\View\Element\UiComponent\ContextInterface; +use Magento\Framework\Api\FilterBuilder; /** * Abstract class AbstractFilter */ abstract class AbstractFilter extends AbstractComponent { + /** + * Component name + */ + const NAME = 'filter'; + /** * Filter variable name */ @@ -32,22 +38,37 @@ abstract class AbstractFilter extends AbstractComponent protected $uiComponentFactory; /** - * Constructor - * + * @var \Magento\Framework\Api\FilterBuilder + */ + protected $filterBuilder; + + /** * @param ContextInterface $context * @param UiComponentFactory $uiComponentFactory + * @param FilterBuilder $filterBuilder * @param array $components * @param array $data */ public function __construct( ContextInterface $context, UiComponentFactory $uiComponentFactory, + FilterBuilder $filterBuilder, array $components = [], array $data = [] ) { $this->uiComponentFactory = $uiComponentFactory; + $this->filterBuilder = $filterBuilder; parent::__construct($context, $components, $data); - $this->filterData = $this->getContext()->getFiltersParams(); } + + /** + * Get component name + * + * @return string + */ + public function getComponentName() + { + return static::NAME; + } } diff --git a/app/code/Magento/Ui/Component/Filters/Type/Date.php b/app/code/Magento/Ui/Component/Filters/Type/Date.php index e38e2d056fbc6..f1689efa87af2 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Date.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Date.php @@ -23,16 +23,6 @@ class Date extends AbstractFilter */ protected $wrappedComponent; - /** - * Get component name - * - * @return string - */ - public function getComponentName() - { - return static::NAME; - } - /** * Prepare component configuration * @@ -73,45 +63,19 @@ public function prepare() */ protected function applyFilter() { - $condition = $this->getCondition(); - if ($condition !== null) { - $this->getContext()->getDataProvider()->addFilter($condition, $this->getName()); - } - } + if (isset($this->filterData[$this->getName()])) { + $value = $this->filterData[$this->getName()]; - /** - * Get condition - * - * @return array|null - */ - protected function getCondition() - { - $value = isset($this->filterData[$this->getName()]) ? $this->filterData[$this->getName()] : null; - if (!empty($value['from']) || !empty($value['to'])) { - if (!empty($value['from'])) { - $value['orig_from'] = $value['from']; - $value['from'] = $this->wrappedComponent->convertDate( - $value['from'], - $this->wrappedComponent->getLocale() - ); - } else { - unset($value['from']); - } - if (!empty($value['to'])) { - $value['orig_to'] = $value['to']; - $value['to'] = $this->wrappedComponent->convertDate( - $value['to'], - $this->wrappedComponent->getLocale() - ); - } else { - unset($value['to']); + if (!empty($value)) { + $value = $this->wrappedComponent->convertDate($value); + + $filter = $this->filterBuilder->setConditionType('eq') + ->setField($this->getName()) + ->setValue($value->format('Y-m-d H:i:s')) + ->create(); + + $this->getContext()->getDataProvider()->addFilter($filter); } - $value['datetime'] = true; - $value['locale'] = $this->wrappedComponent->getLocale(); - } else { - $value = null; } - - return $value; } } diff --git a/app/code/Magento/Ui/Component/Filters/Type/DateRange.php b/app/code/Magento/Ui/Component/Filters/Type/DateRange.php index a9628228fefbd..a367d53921265 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/DateRange.php +++ b/app/code/Magento/Ui/Component/Filters/Type/DateRange.php @@ -10,10 +10,8 @@ /** * Class DateRange */ -class DateRange extends AbstractFilter +class DateRange extends Range { - const NAME = 'filter_range'; - const COMPONENT = 'date'; /** @@ -23,16 +21,6 @@ class DateRange extends AbstractFilter */ protected $wrappedComponent; - /** - * Get component name - * - * @return string - */ - public function getComponentName() - { - return static::NAME; - } - /** * Prepare component configuration * @@ -45,59 +33,30 @@ public function prepare() static::COMPONENT, ['context' => $this->getContext()] ); - $this->wrappedComponent->prepare(); - $this->applyFilter(); + $this->wrappedComponent->prepare(); parent::prepare(); } /** - * Apply filter + * Apply filter by its type * + * @param string $type + * @param string $value * @return void */ - protected function applyFilter() + protected function applyFilterByType($type, $value) { - $condition = $this->getCondition(); - if ($condition !== null) { - $this->getContext()->getDataProvider()->addFilter($condition, $this->getName()); - } - } + if (!empty($value)) { + $value = $this->wrappedComponent->convertDate($value); - /** - * Get condition by data type - * - * @return array|null - */ - public function getCondition() - { - $value = isset($this->filterData[$this->getName()]) ? $this->filterData[$this->getName()] : null; - if (!empty($value['from']) || !empty($value['to'])) { - if (!empty($value['from'])) { - $value['orig_from'] = $value['from']; - $value['from'] = $this->wrappedComponent->convertDate( - $value['from'], - $this->wrappedComponent->getLocale() - ); - } else { - unset($value['from']); - } - if (!empty($value['to'])) { - $value['orig_to'] = $value['to']; - $value['to'] = $this->wrappedComponent->convertDate( - $value['to'], - $this->wrappedComponent->getLocale() - ); - } else { - unset($value['to']); - } - $value['datetime'] = true; - $value['locale'] = $this->wrappedComponent->getLocale(); - } else { - $value = null; - } + $filter = $this->filterBuilder->setConditionType($type) + ->setField($this->getName()) + ->setValue($value->format('Y-m-d H:i:s')) + ->create(); - return $value; + $this->getContext()->getDataProvider()->addFilter($filter); + } } } diff --git a/app/code/Magento/Ui/Component/Filters/Type/Input.php b/app/code/Magento/Ui/Component/Filters/Type/Input.php index a9ba7a317942c..7b7bb9b192827 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Input.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Input.php @@ -23,16 +23,6 @@ class Input extends AbstractFilter */ protected $wrappedComponent; - /** - * Get component name - * - * @return string - */ - public function getComponentName() - { - return static::NAME; - } - /** * Prepare component configuration * @@ -73,25 +63,17 @@ public function prepare() */ protected function applyFilter() { - $condition = $this->getCondition(); - if ($condition !== null) { - $this->getContext()->getDataProvider()->addFilter($condition, $this->getName()); - } - } + if (isset($this->filterData[$this->getName()])) { + $value = $this->filterData[$this->getName()]; - /** - * Get condition by data type - * - * @return array|null - */ - public function getCondition() - { - $value = isset($this->filterData[$this->getName()]) ? $this->filterData[$this->getName()] : null; - $condition = null; - if (!empty($value) || is_numeric($value)) { - $condition = ['like' => sprintf('%%%s%%', $value)]; - } + if (!empty($value)) { + $filter = $this->filterBuilder->setConditionType('like') + ->setField($this->getName()) + ->setValue(sprintf('%s%%', $value)) + ->create(); - return $condition; + $this->getContext()->getDataProvider()->addFilter($filter); + } + } } } diff --git a/app/code/Magento/Ui/Component/Filters/Type/Range.php b/app/code/Magento/Ui/Component/Filters/Type/Range.php index bfdf5116f5755..84781e1a39716 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Range.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Range.php @@ -12,16 +12,6 @@ class Range extends AbstractFilter { const NAME = 'filter_range'; - /** - * Get component name - * - * @return string - */ - public function getComponentName() - { - return static::NAME; - } - /** * Prepare component configuration * @@ -41,59 +31,35 @@ public function prepare() */ protected function applyFilter() { - $condition = $this->getCondition(); - if ($condition !== null) { - $this->getContext()->getDataProvider()->addFilter($condition, $this->getName()); - } - } + if (isset($this->filterData[$this->getName()])) { + $value = $this->filterData[$this->getName()]; - /** - * Get condition by data type - * - * @return array|null - */ - public function getCondition() - { - $value = isset($this->filterData[$this->getName()]) ? $this->filterData[$this->getName()] : null; - if (!empty($value['from']) || !empty($value['to'])) { - $value = $this->prepareFrom($value); - $value = $this->prepareTo($value); - } else { - $value = null; - } - - return $value; - } + if (isset($value['from'])) { + $this->applyFilterByType('gteq', $value['from']); + } - /** - * Prepare "from" value - * - * @param array $value - * @return array - */ - protected function prepareFrom(array $value) - { - if (isset($value['from']) && empty($value['from']) && $value['from'] !== '0') { - $value['orig_from'] = $value['from']; - $value['from'] = null; + if (isset($value['to'])) { + $this->applyFilterByType('lteq', $value['to']); + } } - - return $value; } /** - * Prepare "from" value + * Apply filter by its type * - * @param array $value - * @return array + * @param string $type + * @param string $value + * @return void */ - protected function prepareTo(array $value) + protected function applyFilterByType($type, $value) { - if (isset($value['to']) && empty($value['to']) && $value['to'] !== '0') { - $value['orig_to'] = $value['to']; - $value['to'] = null; - } + if (!empty($value) && $value !== '0') { + $filter = $this->filterBuilder->setConditionType($type) + ->setField($this->getName()) + ->setValue($value) + ->create(); - return $value; + $this->getContext()->getDataProvider()->addFilter($filter); + } } } diff --git a/app/code/Magento/Ui/Component/Filters/Type/Search.php b/app/code/Magento/Ui/Component/Filters/Type/Search.php index 1795b5ccaf5b0..942ec952bf554 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Search.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Search.php @@ -3,7 +3,6 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Ui\Component\Filters\Type; /** @@ -11,15 +10,7 @@ */ class Search extends \Magento\Ui\Component\Filters\Type\AbstractFilter { - /** - * Get component name - * - * @return string - */ - public function getComponentName() - { - return 'keyword_search'; - } + const NAME = 'keyword_search'; /** * Prepare component configuration @@ -40,10 +31,15 @@ public function prepare() */ protected function applyFilter() { - $keyword = $this->getContext()->getRequestParam('search'); - if ($keyword) { - $this->getContext()->getDataProvider()->addFilter($keyword, null, 'fulltext'); - } + $value = $this->getContext()->getRequestParam('search'); + if ($value) { + $filter = $this->filterBuilder->setConditionType('fulltext') + ->setField($this->getName()) + ->setValue($value) + ->create(); + + $this->getContext()->getDataProvider()->addFilter($filter); + } } } diff --git a/app/code/Magento/Ui/Component/Filters/Type/Select.php b/app/code/Magento/Ui/Component/Filters/Type/Select.php index f07f672f37e58..06b783861182e 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Select.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Select.php @@ -32,33 +32,23 @@ class Select extends AbstractFilter protected $optionsProvider; /** - * Constructor - * * @param ContextInterface $context * @param UiComponentFactory $uiComponentFactory - * @param OptionSourceInterface $optionsProvider + * @param \Magento\Framework\Api\FilterBuilder $filterBuilder + * @param OptionSourceInterface|null $optionsProvider * @param array $components * @param array $data */ public function __construct( ContextInterface $context, UiComponentFactory $uiComponentFactory, + \Magento\Framework\Api\FilterBuilder $filterBuilder, OptionSourceInterface $optionsProvider = null, array $components = [], array $data = [] ) { $this->optionsProvider = $optionsProvider; - parent::__construct($context, $uiComponentFactory, $components, $data); - } - - /** - * Get component name - * - * @return string - */ - public function getComponentName() - { - return static::NAME; + parent::__construct($context, $uiComponentFactory, $filterBuilder, $components, $data); } /** @@ -101,25 +91,27 @@ public function prepare() */ protected function applyFilter() { - $condition = $this->getCondition(); - if ($condition !== null) { - $this->getContext()->getDataProvider()->addFilter($condition, $this->getName()); + if (isset($this->filterData[$this->getName()])) { + $value = $this->filterData[$this->getName()]; + + if (!empty($value) || is_numeric($value)) { + $filter = $this->filterBuilder->setConditionType('eq') + ->setField($this->getName()) + ->setValue($value) + ->create(); + + $this->getContext()->getDataProvider()->addFilter($filter); + } } } /** - * Get condition by data type + * Returns options provider * - * @return array|null + * @return OptionSourceInterface */ - public function getCondition() + public function getOptionProvider() { - $value = isset($this->filterData[$this->getName()]) ? $this->filterData[$this->getName()] : null; - $condition = null; - if (!empty($value) || is_numeric($value)) { - $condition = ['eq' => $value]; - } - - return $condition; + return $this->optionsProvider; } } diff --git a/app/code/Magento/Ui/Component/Form.php b/app/code/Magento/Ui/Component/Form.php index ee1e32e30e07e..24f4f5ed60436 100644 --- a/app/code/Magento/Ui/Component/Form.php +++ b/app/code/Magento/Ui/Component/Form.php @@ -5,6 +5,10 @@ */ namespace Magento\Ui\Component; +use Magento\Framework\Api\FilterBuilder; +use Magento\Framework\View\Element\UiComponent\ContextInterface; +use Magento\Framework\View\Element\UiComponentInterface; + /** * Class Form */ @@ -12,6 +16,27 @@ class Form extends AbstractComponent { const NAME = 'form'; + /** + * @var FilterBuilder + */ + protected $filterBuilder; + + /** + * @param ContextInterface $context + * @param FilterBuilder $filterBuilder + * @param UiComponentInterface[] $components + * @param array $data + */ + public function __construct( + ContextInterface $context, + FilterBuilder $filterBuilder, + array $components = [], + array $data = [] + ) { + $this->filterBuilder = $filterBuilder; + parent::__construct($context, $components, $data); + } + /** * Get component name * @@ -31,8 +56,11 @@ public function getDataSourceData() $id = $this->getContext()->getRequestParam($this->getContext()->getDataProvider()->getRequestFieldName()); if ($id) { + $filter = $this->filterBuilder->setField($this->getContext()->getDataProvider()->getPrimaryFieldName()) + ->setValue($id) + ->create(); $this->getContext()->getDataProvider() - ->addFilter($this->getContext()->getDataProvider()->getPrimaryFieldName(), $id); + ->addFilter($filter); } $data = $this->getContext()->getDataProvider()->getData(); diff --git a/app/code/Magento/Ui/Component/Listing.php b/app/code/Magento/Ui/Component/Listing.php index 363144c10d29a..12c8cecc944ad 100644 --- a/app/code/Magento/Ui/Component/Listing.php +++ b/app/code/Magento/Ui/Component/Listing.php @@ -34,9 +34,6 @@ public function getComponentName() */ public function getDataSourceData() { - return [ - 'data' => $this->getContext()->getDataProvider()->getData(), - 'totalCount' => $this->getContext()->getDataProvider()->count() - ]; + return ['data' => $this->getContext()->getDataProvider()->getData()]; } } diff --git a/app/code/Magento/Ui/Component/MassAction/Filter.php b/app/code/Magento/Ui/Component/MassAction/Filter.php new file mode 100644 index 0000000000000..e64287c0978b8 --- /dev/null +++ b/app/code/Magento/Ui/Component/MassAction/Filter.php @@ -0,0 +1,178 @@ +factory = $factory; + $this->request = $request; + $this->filterBuilder = $filterBuilder; + } + + /** + * Returns component by namespace + * + * @return UiComponentInterface + * @throws LocalizedException + */ + public function getComponent() + { + $namespace = $this->request->getParam('namespace'); + if (!isset($this->components[$namespace])) { + $this->components[$namespace] = $this->factory->create($namespace); + } + return $this->components[$namespace]; + } + + /** + * @param AbstractDb $collection + * @return AbstractDb + * @throws LocalizedException + */ + public function getCollection(AbstractDb $collection) + { + $component = $this->getComponent(); + $this->prepareComponent($component); + $dataProvider = $component->getContext()->getDataProvider(); + $ids = []; + foreach ($dataProvider->getSearchResult()->getItems() as $document) { + $ids[] = $document->getId(); + } + + $collection->addFieldToFilter($collection->getIdFieldName(), ['in' => $ids]); + return $this->applySelection($collection); + } + + /** + * Apply selection by Excluded Included to Search Result + * + * @throws LocalizedException + * @return void + */ + public function applySelectionOnTargetProvider() + { + $selected = $this->request->getParam(static::SELECTED_PARAM); + $excluded = $this->request->getParam(static::EXCLUDED_PARAM); + if ('false' === $excluded) { + return; + } + $component = $this->getComponent(); + $this->prepareComponent($component); + $dataProvider = $component->getContext()->getDataProvider(); + try { + if (is_array($excluded) && !empty($excluded)) { + $this->filterBuilder->setConditionType('nin') + ->setField($dataProvider->getPrimaryFieldName()) + ->setValue($excluded); + $dataProvider->addFilter($this->filterBuilder->create()); + } elseif (is_array($selected) && !empty($selected)) { + $this->filterBuilder->setConditionType('in') + ->setField($dataProvider->getPrimaryFieldName()) + ->setValue($selected); + $dataProvider->addFilter($this->filterBuilder->create()); + } + } catch (\Exception $e) { + throw new LocalizedException(__($e->getMessage())); + } + } + + /** + * @param AbstractDb $collection + * @return AbstractDb + * @throws LocalizedException + */ + protected function applySelection(AbstractDb $collection) + { + $selected = $this->request->getParam(static::SELECTED_PARAM); + $excluded = $this->request->getParam(static::EXCLUDED_PARAM); + + if ('false' === $excluded) { + return $collection; + } + + try { + if (is_array($excluded) && !empty($excluded)) { + $collection->addFieldToFilter($collection->getIdFieldName(), ['nin' => $excluded]); + } elseif (is_array($selected) && !empty($selected)) { + $collection->addFieldToFilter($collection->getIdFieldName(), ['in' => $selected]); + } else { + throw new LocalizedException(__('Please select item(s).')); + } + } catch (\Exception $e) { + throw new LocalizedException(__($e->getMessage())); + } + return $collection; + } + + /** + * Call prepare method in the component UI + * + * @param UiComponentInterface $component + * @return void + */ + public function prepareComponent(UiComponentInterface $component) + { + foreach ($component->getChildComponents() as $child) { + $this->prepareComponent($child); + } + $component->prepare(); + } + + /** + * Returns RefererUrl + * + * @return string|null + */ + public function getComponentRefererUrl() + { + $data = $this->getComponent()->getContext()->getDataProvider()->getConfigData(); + return (isset($data['referer_url'])) ? $data['referer_url'] : null; + } +} diff --git a/app/code/Magento/Ui/Controller/Adminhtml/Export/GridToCsv.php b/app/code/Magento/Ui/Controller/Adminhtml/Export/GridToCsv.php new file mode 100644 index 0000000000000..93be6f46466ff --- /dev/null +++ b/app/code/Magento/Ui/Controller/Adminhtml/Export/GridToCsv.php @@ -0,0 +1,63 @@ +factory = $factory; + $this->converter = $converter; + $this->fileFactory = $fileFactory; + } + + /** + * Export data provider to CSV + * + * @throws \Magento\Framework\Exception\LocalizedException + * @return \Magento\Framework\App\ResponseInterface + */ + public function execute() + { + return $this->fileFactory->create('export.csv', $this->converter->getCsvFile(), 'var'); + + } +} diff --git a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php index 74fc177fe1cfb..9ecc7a903f771 100644 --- a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php +++ b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php @@ -6,6 +6,7 @@ namespace Magento\Ui\DataProvider; use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface; +use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; abstract class AbstractDataProvider implements DataProviderInterface { @@ -42,6 +43,11 @@ abstract class AbstractDataProvider implements DataProviderInterface */ protected $data = []; + /** + * @var AbstractCollection + */ + protected $collection; + /** * @param string $name * @param string $primaryFieldName @@ -64,10 +70,12 @@ public function __construct( } /** - * @return \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection + * @return AbstractCollection */ - abstract protected function getCollection(); - + public function getCollection() + { + return $this->collection; + } /** * Get Data Provider name * @@ -141,9 +149,33 @@ public function getFieldMetaInfo($fieldSetName, $fieldName) /** * @inheritdoc */ - public function addFilter($condition, $field = null, $type = 'regular') + public function addFilter(\Magento\Framework\Api\Filter $filter) + { + $this->getCollection()->addFieldToFilter( + $filter->getField(), + [$filter->getConditionType() => $filter->getValue()] + ); + } + /** + * Returns search criteria + * + * @return null + */ + public function getSearchCriteria() + { + //TODO: Technical dept, should be implemented as part of SearchAPI support for Catalog Grids + return null; + } + + /** + * Returns SearchResult + * + * @return null + */ + public function getSearchResult() { - $this->getCollection()->addFieldToFilter($field, $condition); + //TODO: Technical dept, should be implemented as part of SearchAPI support for Catalog Grids + return $this->getCollection(); } /** diff --git a/app/code/Magento/Ui/Model/Export/ConvertToCsv.php b/app/code/Magento/Ui/Model/Export/ConvertToCsv.php new file mode 100644 index 0000000000000..450ba515e3fc1 --- /dev/null +++ b/app/code/Magento/Ui/Model/Export/ConvertToCsv.php @@ -0,0 +1,237 @@ +filter = $filter; + $this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); + } + + /** + * Returns Columns component + * + * @param UiComponentInterface $component + * @return UiComponentInterface + * @throws \Exception + */ + protected function getColumnsComponent(UiComponentInterface $component) + { + foreach ($component->getChildComponents() as $childComponent) { + if ($childComponent instanceof \Magento\Ui\Component\Listing\Columns) { + return $childComponent; + } + } + throw new \Exception('No columns found'); + } + + /** + * Returns columns list + * + * @param UiComponentInterface $component + * @return UiComponentInterface[] + */ + protected function getColumns(UiComponentInterface $component) + { + if (!isset($this->columns[$component->getName()])) { + $columns = $this->getColumnsComponent($component); + foreach ($columns->getChildComponents() as $column) { + $this->columns[$component->getName()][$column->getName()] = $column; + } + } + return $this->columns[$component->getName()]; + } + + /** + * Retrieve Headers row array for Export + * + * @param UiComponentInterface $component + * @return string[] + */ + protected function getHeaders(UiComponentInterface $component) + { + $row = []; + foreach ($this->getColumns($component) as $column) { + if ($column->getData('config/label')) { + $row[] = $column->getData('config/label'); + } + } + return $row; + } + + /** + * Returns DB fields list + * + * @param UiComponentInterface $component + * @return array + */ + protected function getFields(UiComponentInterface $component) + { + $row = []; + foreach ($this->getColumns($component) as $column) { + if ($column->getData('config/label')) { + $row[] = $column->getName(); + } + } + return $row; + } + + /** + * Returns row data + * + * @param DocumentInterface $document + * @param array $fields + * @param array $options + * @return array + */ + protected function getRowData(DocumentInterface $document, $fields, $options) + { + $row = []; + foreach ($fields as $column) { + if (isset($options[$column])) { + $key = $document->getCustomAttribute($column)->getValue(); + if (isset($options[$column][$key])) { + $row[] = $options[$column][$key]; + } + $row[] = ''; + } else { + $row[] = $document->getCustomAttribute($column)->getValue(); + } + } + return $row; + } + + /** + * Returns complex option + * + * @param array $list + * @param string $label + * @param array $output + * @return void + */ + protected function getComplexLabel($list, $label, &$output) + { + foreach ($list as $item) { + if (!is_array($item['value'])) { + $output[$item['value']] = $label . $item['label']; + } else { + $this->getComplexLabel($item['value'], $label . $item['label'], $output); + } + } + } + + /** + * Returns array of Select options + * + * @param Select $filter + * @return array + */ + protected function getFilterOptions(Select $filter) + { + $options = []; + foreach ($filter->getOptionProvider()->toOptionArray() as $option) { + if (!is_array($option['value'])) { + $options[$option['value']] = $option['label']; + } else { + $this->getComplexLabel( + $option['value'], + $option['label'], + $options + ); + } + } + return $options; + } + /** + * Returns Filters with options + * + * @return array + */ + protected function getOptions() + { + $options = []; + $component = $this->filter->getComponent(); + $childComponents = $component->getChildComponents(); + $listingTop = $childComponents['listing_top']; + foreach ($listingTop->getChildComponents() as $child) { + if ($child instanceof \Magento\Ui\Component\Filters) { + foreach ($child->getChildComponents() as $filter) { + if ($filter instanceof Select) { + $options[$filter->getName()] = $this->getFilterOptions($filter); + } + } + } + } + return $options; + } + + /** + * Returns CSV file + * + * @return array + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function getCsvFile() + { + $options = $this->getOptions(); + $component = $this->filter->getComponent(); + $name = md5(microtime()); + $file = 'export/'. $component->getName() . $name . '.csv'; + $this->filter->prepareComponent($component); + $this->filter->applySelectionOnTargetProvider(); + $searchResult = $component->getContext()->getDataProvider()->getSearchResult(); + $this->directory->create('export'); + $stream = $this->directory->openFile($file, 'w+'); + + $fields = $this->getFields($component); + $stream->lock(); + $stream->writeCsv($this->getHeaders($component)); + foreach ($searchResult->getItems() as $document) { + $stream->writeCsv($this->getRowData($document, $fields, $options)); + } + $stream->unlock(); + $stream->close(); + + return [ + 'type' => 'filename', + 'value' => $file, + 'rm' => true // can delete file after use + ]; + } +} diff --git a/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php b/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php index bdd4e74ddd632..8060896296318 100644 --- a/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php +++ b/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php @@ -10,6 +10,7 @@ use Magento\Framework\View\TemplateEngine\Xhtml\Template; use Magento\Framework\View\TemplateEngine\Xhtml\ResultInterface; use Magento\Framework\View\TemplateEngine\Xhtml\CompilerInterface; +use Psr\Log\LoggerInterface; /** * Class Result @@ -37,23 +38,29 @@ class Result implements ResultInterface protected $structure; /** - * Constructor - * + * @var LoggerInterface + */ + protected $logger; + + /** * @param Template $template * @param CompilerInterface $compiler * @param UiComponentInterface $component * @param Structure $structure + * @param LoggerInterface $logger */ public function __construct( Template $template, CompilerInterface $compiler, UiComponentInterface $component, - Structure $structure + Structure $structure, + LoggerInterface $logger ) { $this->template = $template; $this->compiler = $compiler; $this->component = $component; $this->structure = $structure; + $this->logger = $logger; } /** @@ -97,7 +104,8 @@ public function __toString() $this->appendLayoutConfiguration(); $result = $this->compiler->postprocessing($this->template->__toString()); } catch (\Exception $e) { - $result = ''; + $this->logger->critical($e->getMessage()); + $result = $e->getMessage(); } return $result; } diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php index 1deea6a6a4729..36bc19158e970 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateRangeTest.php @@ -27,6 +27,11 @@ class DateRangeTest extends \PHPUnit_Framework_TestCase */ protected $uiComponentFactory; + /** + * @var \Magento\Framework\Api\FilterBuilder|\PHPUnit_Framework_MockObject_MockObject + */ + protected $filterBuilderMock; + /** * Set up */ @@ -38,7 +43,6 @@ public function setUp() '', false ); - $this->uiComponentFactory = $this->getMock( 'Magento\Framework\View\Element\UiComponentFactory', ['create'], @@ -46,6 +50,13 @@ public function setUp() '', false ); + $this->filterBuilderMock = $this->getMock( + 'Magento\Framework\Api\FilterBuilder', + [], + [], + '', + false + ); } /** @@ -55,8 +66,12 @@ public function setUp() */ public function testGetComponentName() { - $dateRange = new DateRange($this->contextMock, $this->uiComponentFactory, []); - + $dateRange = new DateRange( + $this->contextMock, + $this->uiComponentFactory, + $this->filterBuilderMock, + [] + ); $this->assertTrue($dateRange->getComponentName() === DateRange::NAME); } @@ -124,7 +139,13 @@ public function testPrepare($name, $filterData, $expectedCondition) ->with($name, DateRange::COMPONENT, ['context' => $this->contextMock]) ->willReturn($uiComponent); - $dateRange = new DateRange($this->contextMock, $this->uiComponentFactory, [], ['name' => $name]); + $dateRange = new DateRange( + $this->contextMock, + $this->uiComponentFactory, + $this->filterBuilderMock, + [], + ['name' => $name] + ); $dateRange->prepare(); } diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php index e9f22b8b072fd..3e76608a50743 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php @@ -27,6 +27,11 @@ class DateTest extends \PHPUnit_Framework_TestCase */ protected $uiComponentFactory; + /** + * @var \Magento\Framework\Api\FilterBuilder|\PHPUnit_Framework_MockObject_MockObject + */ + protected $filterBuilderMock; + /** * Set up */ @@ -38,7 +43,6 @@ public function setUp() '', false ); - $this->uiComponentFactory = $this->getMock( 'Magento\Framework\View\Element\UiComponentFactory', ['create'], @@ -46,6 +50,13 @@ public function setUp() '', false ); + $this->filterBuilderMock = $this->getMock( + 'Magento\Framework\Api\FilterBuilder', + [], + [], + '', + false + ); } /** @@ -55,7 +66,12 @@ public function setUp() */ public function testGetComponentName() { - $date = new Date($this->contextMock, $this->uiComponentFactory, []); + $date = new Date( + $this->contextMock, + $this->uiComponentFactory, + $this->filterBuilderMock, + [] + ); $this->assertTrue($date->getComponentName() === Date::NAME); } @@ -124,8 +140,13 @@ public function testPrepare($name, $filterData, $expectedCondition) ->with($name, Date::COMPONENT, ['context' => $this->contextMock]) ->willReturn($uiComponent); - $date = new Date($this->contextMock, $this->uiComponentFactory, [], ['name' => $name]); - + $date = new Date( + $this->contextMock, + $this->uiComponentFactory, + $this->filterBuilderMock, + [], + ['name' => $name] + ); $date->prepare(); } diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php index 1c02e34d7fa00..cf33a86653fd7 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/InputTest.php @@ -27,6 +27,11 @@ class InputTest extends \PHPUnit_Framework_TestCase */ protected $uiComponentFactory; + /** + * @var \Magento\Framework\Api\FilterBuilder|\PHPUnit_Framework_MockObject_MockObject + */ + protected $filterBuilderMock; + /** * Set up */ @@ -38,7 +43,6 @@ public function setUp() '', false ); - $this->uiComponentFactory = $this->getMock( 'Magento\Framework\View\Element\UiComponentFactory', ['create'], @@ -46,6 +50,13 @@ public function setUp() '', false ); + $this->filterBuilderMock = $this->getMock( + 'Magento\Framework\Api\FilterBuilder', + [], + [], + '', + false + ); } /** @@ -55,7 +66,12 @@ public function setUp() */ public function testGetComponentName() { - $date = new Input($this->contextMock, $this->uiComponentFactory, []); + $date = new Input( + $this->contextMock, + $this->uiComponentFactory, + $this->filterBuilderMock, + [] + ); $this->assertTrue($date->getComponentName() === Input::NAME); } @@ -116,7 +132,13 @@ public function testPrepare($name, $filterData, $expectedCondition) ->with($name, Input::COMPONENT, ['context' => $this->contextMock]) ->willReturn($uiComponent); - $date = new Input($this->contextMock, $this->uiComponentFactory, [], ['name' => $name]); + $date = new Input( + $this->contextMock, + $this->uiComponentFactory, + $this->filterBuilderMock, + [], + ['name' => $name] + ); $date->prepare(); } diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php index 353046436271d..b3da88e49eb4b 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/RangeTest.php @@ -26,6 +26,11 @@ class RangeTest extends \PHPUnit_Framework_TestCase */ protected $uiComponentFactory; + /** + * @var \Magento\Framework\Api\FilterBuilder|\PHPUnit_Framework_MockObject_MockObject + */ + protected $filterBuilderMock; + /** * Set up */ @@ -45,6 +50,13 @@ public function setUp() '', false ); + $this->filterBuilderMock = $this->getMock( + 'Magento\Framework\Api\FilterBuilder', + [], + [], + '', + false + ); } /** @@ -54,7 +66,12 @@ public function setUp() */ public function testGetComponentName() { - $range = new Range($this->contextMock, $this->uiComponentFactory, []); + $range = new Range( + $this->contextMock, + $this->uiComponentFactory, + $this->filterBuilderMock, + [] + ); $this->assertTrue($range->getComponentName() === Range::NAME); } @@ -98,7 +115,13 @@ public function testPrepare($name, $filterData, $expectedCondition) ->willReturn($dataProvider); } - $range = new Range($this->contextMock, $this->uiComponentFactory, [], ['name' => $name]); + $range = new Range( + $this->contextMock, + $this->uiComponentFactory, + $this->filterBuilderMock, + [], + ['name' => $name] + ); $range->prepare(); } diff --git a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php index 4ea56669f2d92..24237520a321b 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/Filters/Type/SelectTest.php @@ -27,6 +27,11 @@ class SelectTest extends \PHPUnit_Framework_TestCase */ protected $uiComponentFactory; + /** + * @var \Magento\Framework\Api\FilterBuilder|\PHPUnit_Framework_MockObject_MockObject + */ + protected $filterBuilderMock; + /** * Set up */ @@ -38,7 +43,6 @@ public function setUp() '', false ); - $this->uiComponentFactory = $this->getMock( 'Magento\Framework\View\Element\UiComponentFactory', ['create'], @@ -46,6 +50,13 @@ public function setUp() '', false ); + $this->filterBuilderMock = $this->getMock( + 'Magento\Framework\Api\FilterBuilder', + [], + [], + '', + false + ); } /** @@ -55,7 +66,13 @@ public function setUp() */ public function testGetComponentName() { - $date = new Select($this->contextMock, $this->uiComponentFactory, null, []); + $date = new Select( + $this->contextMock, + $this->uiComponentFactory, + $this->filterBuilderMock, + null, + [] + ); $this->assertTrue($date->getComponentName() === Select::NAME); } @@ -124,7 +141,14 @@ public function testPrepare($name, $filterData, $expectedCondition) ->with($name, Select::COMPONENT, ['context' => $this->contextMock, 'options' => $selectOptions]) ->willReturn($uiComponent); - $date = new Select($this->contextMock, $this->uiComponentFactory, $selectOptions, [], ['name' => $name]); + $date = new Select( + $this->contextMock, + $this->uiComponentFactory, + $this->filterBuilderMock, + $selectOptions, + [], + ['name' => $name] + ); $date->prepare(); } diff --git a/app/code/Magento/Ui/view/base/web/js/grid/columns/multiselect.js b/app/code/Magento/Ui/view/base/web/js/grid/columns/multiselect.js index 9d39cfc81297b..a915dd9a5dc73 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/columns/multiselect.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/columns/multiselect.js @@ -43,6 +43,10 @@ define([ '${ $.provider }:params.filters': 'deselectAll', selected: 'onSelectedChange', rows: 'onRowsChange' + }, + + modules: { + source: '${ $.provider }' } }, @@ -327,10 +331,27 @@ define([ excluded: this.excluded(), selected: this.selected(), total: this.totalSelected(), - excludeMode: this.excludeMode() + excludeMode: this.excludeMode(), + params: this.getFiltering() }; }, + /** + * Extracts filtering data from data provider. + * + * @returns {Object} Current filters state. + */ + getFiltering: function () { + var source = this.source(), + keys = ['filters', 'search', 'namespace']; + + if (!source) { + return {}; + } + + return _.pick(source.get('params'), keys); + }, + /** * Defines if provided select/deselect actions is relevant. * E.g. there is no need in a 'select page' action if only one diff --git a/app/code/Magento/Ui/view/base/web/js/grid/export.js b/app/code/Magento/Ui/view/base/web/js/grid/export.js index d94649e3cd1d1..0350d156f2656 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/export.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/export.js @@ -15,24 +15,23 @@ define([ defaults: { template: 'ui/grid/exportButton', checked: '', - params: { - filters: {} - }, - filtersConfig: { - provider: '${ $.provider }', - path: 'params.filters' - }, - imports: { - 'params.filters': '${ $.filtersConfig.provider }:${ $.filtersConfig.path }' + modules: { + selections: '${ $.selectProvider }' } }, initialize: function () { this._super() - .observe('checked') .initChecked(); }, + initObservable: function () { + this._super() + .observe('checked'); + + return this; + }, + initChecked: function () { if (!this.checked()) { this.checked( @@ -42,14 +41,40 @@ define([ return this; }, - applyOption: function () { - var option = _.filter(this.options, function (op) { - return op.value === this.checked(); - }, this)[0]; + getParams: function () { + var selections = this.selections(), + data = selections.getSelections(), + itemsType = data.excludeMode ? 'excluded' : 'selected', + result = {}; + + result['filters'] = data.params.filters; + result['search'] = data.params.search; + result['namespace'] = data.params.namespace; + result[itemsType] = data[itemsType]; - location.href = option.url + '?' + $.param({ - 'filters': this.params.filters + if (!result[itemsType].length) { + result[itemsType] = false; + } + return result; + }, + + getActiveOption: function () { + return _.findWhere(this.options, { + value: this.checked() }); + }, + + buildOptionUrl: function (option) { + var url = option.url + '?'; + + return url + $.param(this.getParams()); + }, + + applyOption: function () { + var option = this.getActiveOption(), + url = this.buildOptionUrl(option); + + location.href = url; } }); }); diff --git a/app/code/Magento/Ui/view/base/web/js/grid/massactions.js b/app/code/Magento/Ui/view/base/web/js/grid/massactions.js index 883ff1f018c31..871bbfbffc162 100644 --- a/app/code/Magento/Ui/view/base/web/js/grid/massactions.js +++ b/app/code/Magento/Ui/view/base/web/js/grid/massactions.js @@ -55,7 +55,7 @@ define([ return this; } - action = this.getAction(actionIndex), + action = this.getAction(actionIndex); callback = this._getCallback(action, data); action.confirm ? @@ -154,6 +154,8 @@ define([ selections[itemsType] = false; } + _.extend(selections, data.params || {}); + utils.submit({ url: action.url, data: selections diff --git a/app/etc/di.xml b/app/etc/di.xml index 0a4b7e8c042bd..7b8aea5446305 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -30,7 +30,7 @@ - + @@ -1124,4 +1124,6 @@ Magento\Framework\UrlInterface\Proxy + + diff --git a/dev/tests/api-functional/testsuite/Magento/Search/Api/SearchTest.php b/dev/tests/api-functional/testsuite/Magento/Search/Api/SearchTest.php index 16fe103381f31..3d19ef78b69ac 100644 --- a/dev/tests/api-functional/testsuite/Magento/Search/Api/SearchTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Search/Api/SearchTest.php @@ -28,10 +28,12 @@ public function testCatalogSearch() [ 'field' => 'search_term', 'value' => 'simple', + 'condition_type' => 'eq' ], [ 'field' => 'price_dynamic_algorithm', 'value' => 'auto', + 'condition_type' => 'eq' ] ] ] diff --git a/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/View/OrdersTest.php b/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/View/OrdersTest.php deleted file mode 100644 index 7579479f105be..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/View/OrdersTest.php +++ /dev/null @@ -1,113 +0,0 @@ -get('Magento\Framework\App\State')->setAreaCode('adminhtml'); - - $this->coreRegistry = $objectManager->get('Magento\Framework\Registry'); - $this->coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, 1); - - $this->block = $objectManager->get( - 'Magento\Framework\View\LayoutInterface' - )->createBlock( - 'Magento\Customer\Block\Adminhtml\Edit\Tab\View\Orders', - '', - ['coreRegistry' => $this->coreRegistry] - ); - $this->block->getPreparedCollection(); - } - - /** - * Execute post test cleanup. - */ - public function tearDown() - { - $this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID); - $this->block->setCollection(null); - } - - /** - * Verify that the correct Url is return for a row in the orders grid. - */ - public function testGetRowUrl() - { - $row = new \Magento\Framework\DataObject(['id' => 1]); - $this->assertContains('sales/order/view/order_id/1', $this->block->getRowUrl($row)); - } - - /** - * Verify that the grid headers are visible. - */ - public function testGetHeadersVisibility() - { - $this->assertTrue($this->block->getHeadersVisibility()); - } - - /** - * Verify the integrity of the orders collection. - */ - public function testGetCollection() - { - $collection = $this->block->getCollection(); - $this->assertEquals(0, $collection->getSize()); - $this->assertEquals(5, $collection->getPageSize()); - $this->assertEquals(1, $collection->getCurPage()); - } - - /** - * Check the empty grid Html. - */ - public function testToHtmlEmptyOrders() - { - $this->assertEquals(0, $this->block->getCollection()->getSize()); - $this->assertContains("We couldn't find any records.", $this->block->toHtml()); - } - - /** - * Verify the contents of the grid Html when there is a sales order. - * - * @magentoDataFixture Magento/Customer/_files/customer.php - * @magentoDataFixture Magento/Sales/_files/order.php - * @magentoDataFixture Magento/Customer/_files/sales_order.php - */ - public function testToHtmlWithOrders() - { - $html = $this->block->toHtml(); - $this->assertContains('100000001', $html); - $this->assertContains('firstname lastname', $html); - $this->assertEquals(1, $this->block->getCollection()->getSize()); - } -} diff --git a/lib/internal/Magento/Framework/Api/Filter.php b/lib/internal/Magento/Framework/Api/Filter.php index b803e5fe92624..47e0e501128dc 100644 --- a/lib/internal/Magento/Framework/Api/Filter.php +++ b/lib/internal/Magento/Framework/Api/Filter.php @@ -70,7 +70,7 @@ public function setValue($value) */ public function getConditionType() { - return $this->_get(self::KEY_CONDITION_TYPE); + return $this->_get(self::KEY_CONDITION_TYPE) ?: 'eq'; } /** diff --git a/lib/internal/Magento/Framework/Api/Search/ReportingInterface.php b/lib/internal/Magento/Framework/Api/Search/ReportingInterface.php new file mode 100644 index 0000000000000..8f618598d9699 --- /dev/null +++ b/lib/internal/Magento/Framework/Api/Search/ReportingInterface.php @@ -0,0 +1,18 @@ +sortOrderBuilder = $sortOrderBuilder; + $this->filterGroupBuilder = $filterGroupBuilder; + } + + /** + * Builds the SearchCriteria Data Object + * + * @return SearchCriteria + */ + public function create() + { + $this->data[SearchCriteria::FILTER_GROUPS] = [$this->filterGroupBuilder->create()]; + $this->data[SearchCriteria::SORT_ORDERS] = [$this->sortOrderBuilder->create()]; + return parent::create(); + } + + /** + * Create a filter group based on the filter array provided and add to the filter groups + * + * @param \Magento\Framework\Api\Filter $filter + * @return $this + */ + public function addFilter(\Magento\Framework\Api\Filter $filter) + { + $this->filterGroupBuilder->addFilter($filter); + return $this; + } + + /** + * @param string $field + * @param string $direction + * @return $this + */ + public function addSortOrder($field, $direction) + { + $this->sortOrderBuilder->setDirection($direction) + ->setField($field); + return $this; + } + + /** + * Set page size + * + * @param int $pageSize + * @return $this + */ + public function setPageSize($pageSize) + { + return $this->_set(SearchCriteria::PAGE_SIZE, $pageSize); + } + + /** + * Set current page + * + * @param int $currentPage + * @return $this + */ + public function setCurrentPage($currentPage) + { + return $this->_set(SearchCriteria::CURRENT_PAGE, $currentPage); + } +} diff --git a/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php b/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php new file mode 100644 index 0000000000000..b9d9ffb4a48ae --- /dev/null +++ b/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php @@ -0,0 +1,71 @@ +adapter = $resource->getConnection(); + $this->columns = $columns; + $this->separator = $separator; + } + + /** + * Returns SQL expression + * TRIM(CONCAT_WS(separator, IFNULL(str1,''), IFNULL(str2,''), ...)) + * + * @return string + */ + public function __toString() + { + $columns = []; + foreach ($this->columns as $key => $part) { + if (isset($part['columnName']) && $part['columnName'] instanceof \Zend_Db_Expr) { + $column = $part['columnName']; + } else { + $column = $this->adapter->quoteIdentifier( + (isset($part['tableAlias']) ? $part['tableAlias'] . '.' : '') + . (isset($part['columnName']) ? $part['columnName'] : $key) + ); + } + $columns[] = $this->adapter->getIfNullSql($column, "''"); + } + return sprintf( + 'TRIM(%s)', + $this->adapter->getConcatSql($columns, ' ') + ); + } +} diff --git a/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php b/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php new file mode 100644 index 0000000000000..30e208e3fcff0 --- /dev/null +++ b/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php @@ -0,0 +1,134 @@ +targetTable = $targetTable; + $this->targetColumn = $targetColumn; + $this->referenceColumns = $referenceColumns; + $this->sortOrder = $sortOrder; + $this->resource = $resource; + $this->adapter = $this->resource->getConnection(); + } + + /** + * Process WHERE clause + * + * @param Select $select + * @return void + */ + protected function processWhereCondition(Select $select) + { + foreach ($this->referenceColumns as $column => $referenceColumn) { + $identifier = ''; + if (isset($referenceColumn['tableAlias'])) { + $identifier = $referenceColumn['tableAlias'] . '.'; + } + $columnName = $column; + if (isset($referenceColumn['columnName'])) { + $columnName = $referenceColumn['columnName']; + } + $select->where( + sprintf( + '%s = %s', + $this->adapter->quoteIdentifier('lookup.' . $column), + $this->adapter->quoteIdentifier($identifier . $columnName) + ) + ); + } + } + + /** + * Process ORDER BY clause + * + * @param Select $select + * @return void + */ + protected function processSortOrder(Select $select) + { + foreach ($this->sortOrder as $direction => $column) { + if (!in_array($direction, [Select::SQL_ASC, Select::SQL_DESC])) { + $direction = ''; + } + $expr = new \Zend_Db_Expr( + sprintf( + '%s %s', + $this->adapter->quoteIdentifier('lookup.' . $column), + $direction + ) + ); + $select->order($expr); + } + } + + /** + * Returns lookup SQL + * + * @return string + */ + public function __toString() + { + $select = $this->adapter->select() + ->from(['lookup' => $this->resource->getTableName($this->targetTable)], [$this->targetColumn]) + ->limit(1); + $this->processWhereCondition($select); + $this->processSortOrder($select); + return sprintf('(%s)', $select->assemble()); + } +} diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionFactory.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionFactory.php new file mode 100644 index 0000000000000..19926466e4637 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionFactory.php @@ -0,0 +1,51 @@ +collections = $collections; + $this->objectManager = $objectManagerInterface; + } + + /** + * @param string $requestName + * @return AbstractCollection + * @throws \Exception + */ + public function getReport($requestName) + { + if (!isset($this->collections[$requestName])) { + throw new \Exception(sprintf('Not registered handle %s', $requestName)); + } + return $this->objectManager->create($this->collections[$requestName]); + } +} diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php index 12d7a1425850e..a006b56628d6d 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php @@ -3,10 +3,13 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Framework\View\Element\UiComponent\DataProvider; -use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection as Collection; +use Magento\Framework\Api\FilterBuilder; +use Magento\Framework\Api\Search\SearchCriteria; +use Magento\Framework\Api\Search\SearchCriteriaBuilder; +use Magento\Framework\Api\Search\SearchResultInterface; +use Magento\Framework\App\RequestInterface; /** * Class DataProvider @@ -34,11 +37,6 @@ class DataProvider implements DataProviderInterface */ protected $requestFieldName; - /** - * @var Collection - */ - protected $collection; - /** * @var array */ @@ -52,16 +50,38 @@ class DataProvider implements DataProviderInterface protected $data = []; /** - * @var FilterPool + * @var Reporting */ - protected $filterPool; + protected $reporting; + + /** + * @var FilterBuilder + */ + protected $filterBuilder; + + /** + * @var SearchCriteriaBuilder + */ + protected $searchCriteriaBuilder; + + /** + * @var RequestInterface + */ + protected $request; + + /** + * @var SearchCriteria + */ + protected $searchCriteria; /** * @param string $name * @param string $primaryFieldName * @param string $requestFieldName - * @param Collection $collection - * @param FilterPool $filterPool + * @param Reporting $reporting + * @param SearchCriteriaBuilder $searchCriteriaBuilder + * @param RequestInterface $request + * @param FilterBuilder $filterBuilder * @param array $meta * @param array $data */ @@ -69,26 +89,49 @@ public function __construct( $name, $primaryFieldName, $requestFieldName, - Collection $collection, - FilterPool $filterPool, + Reporting $reporting, + SearchCriteriaBuilder $searchCriteriaBuilder, + RequestInterface $request, + FilterBuilder $filterBuilder, array $meta = [], array $data = [] ) { + $this->request = $request; + $this->filterBuilder = $filterBuilder; $this->name = $name; $this->primaryFieldName = $primaryFieldName; $this->requestFieldName = $requestFieldName; - $this->filterPool = $filterPool; - $this->collection = $collection; + $this->reporting = $reporting; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->meta = $meta; $this->data = $data; + $this->prepareUpdateUrl(); } /** - * @return Collection + * @return void */ - public function getCollection() + protected function prepareUpdateUrl() { - return $this->collection; + if (!isset($this->data['config']['filter_url_params'])) { + return; + } + foreach ($this->data['config']['filter_url_params'] as $paramName => $paramValue) { + if ('*' == $paramValue) { + $paramValue = $this->request->getParam($paramName); + } + if ($paramValue) { + $this->data['config']['update_url'] = sprintf( + '%s%s/%s', + $this->data['config']['update_url'], + $paramName, + $paramValue + ); + $this->addFilter( + $this->filterBuilder->setField($paramName)->setValue($paramValue)->setConditionType('eq')->create() + ); + } + } } /** @@ -164,21 +207,9 @@ public function getFieldMetaInfo($fieldSetName, $fieldName) /** * @inheritdoc */ - public function addFilter($condition, $field = null, $type = 'regular') - { - $this->filterPool->registerNewFilter($condition, $field, $type); - } - - /** - * Add field to select - * - * @param string|array $field - * @param string|null $alias - * @return void - */ - public function addField($field, $alias = null) + public function addFilter(\Magento\Framework\Api\Filter $filter) { - $this->collection->addFieldToSelect($field, $alias); + $this->searchCriteriaBuilder->addFilter($filter); } /** @@ -190,7 +221,7 @@ public function addField($field, $alias = null) */ public function addOrder($field, $direction) { - $this->collection->addOrder($field, $direction); + $this->searchCriteriaBuilder->addSortOrder($field, $direction); } /** @@ -202,30 +233,42 @@ public function addOrder($field, $direction) */ public function setLimit($offset, $size) { - $this->collection->setPageSize($size); - $this->collection->setCurPage($offset); + $this->searchCriteriaBuilder->setPageSize($size); + $this->searchCriteriaBuilder->setCurrentPage($offset); } /** - * Removes field from select - * - * @param string|null $field - * @param bool $isAlias Alias identifier - * @return void + * @param SearchResultInterface $searchResult + * @return array */ - public function removeField($field, $isAlias = false) + protected function searchResultToOutput(SearchResultInterface $searchResult) { - $this->collection->removeFieldFromSelect($field, $isAlias); + $arrItems = []; + $arrItems['totalRecords'] = $searchResult->getTotalCount(); + + $arrItems['items'] = []; + foreach ($searchResult->getItems() as $item) { + $itemData = []; + foreach ($item->getCustomAttributes() as $attribute) { + $itemData[$attribute->getAttributeCode()] = $attribute->getValue(); + } + $arrItems['items'][] = $itemData; + } + return $arrItems; } /** - * Removes all fields from select + * Returns search criteria * - * @return void + * @return \Magento\Framework\Api\Search\SearchCriteria */ - public function removeAllFields() + public function getSearchCriteria() { - $this->collection->removeAllFieldsFromSelect(); + if (!$this->searchCriteria) { + $this->searchCriteria = $this->searchCriteriaBuilder->create(); + $this->searchCriteria->setRequestName($this->name); + } + return $this->searchCriteria; } /** @@ -235,25 +278,13 @@ public function removeAllFields() */ public function getData() { - $this->filterPool->applyFilters($this->collection); - return $this->collection->toArray(); - } - - /** - * Retrieve count of loaded items - * - * @return int - */ - public function count() - { - $this->filterPool->applyFilters($this->collection); - return $this->collection->count(); + return $this->searchResultToOutput($this->getSearchResult()); } /** * Get config data * - * @return mixed + * @return array */ public function getConfigData() { @@ -270,4 +301,14 @@ public function setConfigData($config) { $this->data['config'] = $config; } + + /** + * Returns Search result + * + * @return SearchResultInterface + */ + public function getSearchResult() + { + return $this->reporting->search($this->getSearchCriteria()); + } } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php index 0b4a9761eb907..1b7e5c7f841f4 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php @@ -5,6 +5,8 @@ */ namespace Magento\Framework\View\Element\UiComponent\DataProvider; +use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; + /** * Interface DataProviderInterface */ @@ -79,24 +81,13 @@ public function getRequestFieldName(); */ public function getData(); - /** - * Add field to select - * - * @param string|array $field - * @param string|null $alias - * @return void - */ - public function addField($field, $alias = null); - /** * Add field filter to collection * - * @param string|int|array|null $condition - * @param null|string|array $field - * @param string $type + * @param \Magento\Framework\Api\Filter $filter * @return mixed */ - public function addFilter($condition, $field = null, $type = 'regular'); + public function addFilter(\Magento\Framework\Api\Filter $filter); /** * Add ORDER BY to the end or to the beginning @@ -117,25 +108,14 @@ public function addOrder($field, $direction); public function setLimit($offset, $size); /** - * Removes field from select + * Returns search criteria * - * @param string|null $field - * @param bool $isAlias Alias identifier - * @return void + * @return \Magento\Framework\Api\Search\SearchCriteriaInterface */ - public function removeField($field, $isAlias = false); + public function getSearchCriteria(); /** - * Removes all fields from select - * - * @return void - */ - public function removeAllFields(); - - /** - * Retrieve count of loaded items - * - * @return int + * @return \Magento\Framework\Api\Search\SearchResultInterface */ - public function count(); + public function getSearchResult(); } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php new file mode 100644 index 0000000000000..89b625634eeb8 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php @@ -0,0 +1,116 @@ +attributeValueFactory = $attributeValueFactory; + } + + /** + * @return int|string + */ + public function getId() + { + if (!$this->id) { + $this->id = $this->getData($this->getIdFieldName()); + } + return $this->id; + } + + /** + * @param int $id + * @return void + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * Get an attribute value. + * + * @param string $attributeCode + * @return \Magento\Framework\Api\AttributeInterface|null + */ + public function getCustomAttribute($attributeCode) + { + /** @var \Magento\Framework\Api\AttributeInterface $attributeValue */ + $attributeValue = $this->attributeValueFactory->create(); + $attributeValue->setAttributeCode($attributeCode); + $attributeValue->setValue($this->getData($attributeCode)); + return $attributeValue; + } + + /** + * Set an attribute value for a given attribute code + * + * @param string $attributeCode + * @param mixed $attributeValue + * @return $this + */ + public function setCustomAttribute($attributeCode, $attributeValue) + { + $this->setData($attributeCode, $attributeValue); + return $this; + } + + /** + * Retrieve custom attributes values. + * + * @return \Magento\Framework\Api\AttributeInterface[]|null + */ + public function getCustomAttributes() + { + $output = []; + foreach ($this->getData() as $key => $value) { + $attribute = $this->attributeValueFactory->create(); + $output[] = $attribute->setAttributeCode($key)->setValue($value); + } + return $output; + } + + /** + * Set array of custom attributes + * + * @param \Magento\Framework\Api\AttributeInterface[] $attributes + * @return $this + * @throws \LogicException + */ + public function setCustomAttributes(array $attributes) + { + /** @var \Magento\Framework\Api\AttributeInterface $attribute */ + foreach ($attributes as $attribute) { + $this->setData( + $attribute->getAttributeCode(), + $attribute->getValue() + ); + } + return $this; + } +} diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FilterApplierInterface.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FilterApplierInterface.php index cb2ecf07a0b0f..4547683a6e3ed 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FilterApplierInterface.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FilterApplierInterface.php @@ -18,7 +18,7 @@ interface FilterApplierInterface * * @param AbstractDb $collection * @param array $filters - * @return mixed + * @return void */ - public function apply(AbstractDb $collection, $filters); + public function apply(AbstractDb $collection, \Magento\Framework\Api\Filter $filters); } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FilterPool.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FilterPool.php index 7ed363a5f98bd..8f6f7729d2373 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FilterPool.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FilterPool.php @@ -7,17 +7,13 @@ namespace Magento\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Api\Search\SearchCriteriaInterface; /** * Class FilterPool */ class FilterPool { - /** - * @var array - */ - protected $filters = []; - /** * @var array */ @@ -31,30 +27,21 @@ public function __construct(array $appliers = []) $this->appliers = $appliers; } - /** - * @param string|int|array|null $condition - * @param string|null|array $field - * @param string $type - * @return void - */ - public function registerNewFilter($condition, $field, $type) - { - $this->filters[$type][sha1($field . serialize($condition))] = [ - 'field' => $field, - 'condition' => $condition - ]; - } - /** * @param AbstractDb $collection + * @param SearchCriteriaInterface $criteria * @return void */ - public function applyFilters(AbstractDb $collection) + public function applyFilters(AbstractDb $collection, SearchCriteriaInterface $criteria) { - foreach ($this->filters as $type => $filter) { - if (isset($this->appliers[$type])) { + foreach ($criteria->getFilterGroups() as $filterGroup) { + foreach ($filterGroup->getFilters() as $filter) { /** @var $filterApplier FilterApplierInterface*/ - $filterApplier = $this->appliers[$type]; + if (isset($this->appliers[$filter->getConditionType()])) { + $filterApplier = $this->appliers[$filter->getConditionType()]; + } else { + $filterApplier = $this->appliers['regular']; + } $filterApplier->apply($collection, $filter); } } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FulltextFilter.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FulltextFilter.php index b75ebe913ddf7..847206787efe4 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FulltextFilter.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FulltextFilter.php @@ -7,24 +7,25 @@ namespace Magento\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Data\Collection\AbstractDb as DbCollection; -use \Magento\Framework\Model\Resource\Db\AbstractDb as DbResource; +use Magento\Framework\Model\Resource\Db\AbstractDb as DbResource; +use Magento\Framework\Api\Filter; /** * Class Fulltext */ class FulltextFilter implements FilterApplierInterface { + /** * Returns list of columns from fulltext index (doesn't support more then one FTI per table) * - * @param DbResource $resource + * @param DbCollection $collection * @param string $indexTable * @return array - * @throws \Magento\Framework\Exception\LocalizedException */ - protected function getFulltextIndexColumns(DbResource $resource, $indexTable) + protected function getFulltextIndexColumns(DbCollection $collection, $indexTable) { - $indexes = $resource->getConnection()->getIndexList($indexTable); + $indexes = $collection->getConnection()->getIndexList($indexTable); foreach ($indexes as $index) { if (strtoupper($index['INDEX_TYPE']) == 'FULLTEXT') { return $index['COLUMNS_LIST']; @@ -37,21 +38,19 @@ protected function getFulltextIndexColumns(DbResource $resource, $indexTable) * Apply fulltext filters * * @param DbCollection $collection - * @param array $filters + * @param Filter $filter * @return void */ - public function apply(DbCollection $collection, $filters) + public function apply(DbCollection $collection, Filter $filter) { - $columns = $this->getFulltextIndexColumns($collection->getResource(), $collection->getMainTable()); + $columns = $this->getFulltextIndexColumns($collection, $collection->getMainTable()); if (!$columns) { return; } - foreach ($filters as $filter) { - $collection->getSelect() - ->where( - 'MATCH(' . implode(',', $columns) . ') AGAINST(?)', - $filter['condition'] - ); - } + $collection->getSelect() + ->where( + 'MATCH(' . implode(',', $columns) . ') AGAINST(?)', + $filter->getValue() + ); } } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/RegularFilter.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/RegularFilter.php index 6104b805c32ef..5f23a1d8855d2 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/RegularFilter.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/RegularFilter.php @@ -7,6 +7,7 @@ namespace Magento\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Api\Filter; /** * Class RegularFilter @@ -17,13 +18,11 @@ class RegularFilter implements FilterApplierInterface * Apply regular filters like collection filters * * @param AbstractDb $collection - * @param array $filters + * @param Filter $filter * @return void */ - public function apply(AbstractDb $collection, $filters) + public function apply(AbstractDb $collection, Filter $filter) { - foreach ($filters as $filter) { - $collection->addFieldToFilter($filter['field'], $filter['condition']); - } + $collection->addFieldToFilter($filter->getField(), [$filter->getConditionType() => $filter->getValue()]); } } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php new file mode 100644 index 0000000000000..61d8695fad69a --- /dev/null +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php @@ -0,0 +1,56 @@ +collectionFactory = $collectionFactory; + $this->filterPool = $filterPool; + } + + /** + * @param SearchCriteriaInterface $searchCriteria + * @return SearchResultInterface + */ + public function search(SearchCriteriaInterface $searchCriteria) + { + $collection = $this->collectionFactory->getReport($searchCriteria->getRequestName()); + $collection->setPageSize($searchCriteria->getPageSize()); + $collection->setCurPage($searchCriteria->getCurrentPage()); + $this->filterPool->applyFilters($collection, $searchCriteria); + foreach ($searchCriteria->getSortOrders() as $sortOrder) { + if ($sortOrder->getField()) { + $collection->setOrder($sortOrder->getField(), $sortOrder->getDirection()); + } + } + return $collection; + } +} diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php new file mode 100644 index 0000000000000..9fa1308c4acbb --- /dev/null +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php @@ -0,0 +1,140 @@ +_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()); + } + + /** + * @return \Magento\Framework\Api\Search\AggregationInterface + */ + public function getAggregations() + { + return $this->aggregations; + } + + /** + * @param \Magento\Framework\Api\Search\AggregationInterface $aggregations + * @return void + */ + public function setAggregations($aggregations) + { + $this->aggregations = $aggregations; + } + + /** + * @return \Magento\Framework\Api\Search\SearchCriteriaInterface|null + */ + public function getSearchCriteria() + { + return $this->searchCriteria; + } + + /** + * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria + * @return $this + */ + public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) + { + $this->searchCriteria = $searchCriteria; + return $this; + } + + /** + * @return int + */ + public function getTotalCount() + { + if (!$this->totalCount) { + $this->totalCount = $this->getSize(); + } + return $this->totalCount; + } + + /** + * @param int $totalCount + * @return $this + */ + public function setTotalCount($totalCount) + { + $this->totalCount = $totalCount; + return $this; + } + + /** + * Set items list. + * + * @param Document[] $items + * @return $this + */ + public function setItems(array $items = null) + { + if ($items) { + foreach ($items as $item) { + $this->addItem($item); + } + unset($this->totalCount); + } + return $this; + } +} diff --git a/lib/internal/Magento/Framework/View/TemplateEngine/Xhtml/Template.php b/lib/internal/Magento/Framework/View/TemplateEngine/Xhtml/Template.php index 2ce37749a3d94..365c32a9f354c 100644 --- a/lib/internal/Magento/Framework/View/TemplateEngine/Xhtml/Template.php +++ b/lib/internal/Magento/Framework/View/TemplateEngine/Xhtml/Template.php @@ -14,18 +14,25 @@ class Template const XML_ENCODING = 'UTF-8'; + /** + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + /** * @var \DOMElement */ protected $templateNode; /** - * Constructor - * + * @param \Psr\Log\LoggerInterface $logger * @param string $content */ - public function __construct($content) - { + public function __construct( + \Psr\Log\LoggerInterface $logger, + $content + ) { + $this->logger = $logger; $document = new \DOMDocument(static::XML_VERSION, static::XML_ENCODING); $document->loadXML($content); $this->templateNode = $document->documentElement; @@ -65,6 +72,7 @@ public function __toString() $this->templateNode->ownerDocument->normalizeDocument(); $result = $this->templateNode->ownerDocument->saveHTML(); } catch (\Exception $e) { + $this->logger->critical($e->getMessage()); $result = ''; } return $result;