From 79c0336b51f528ae113745c766d081c42edaa913 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Thu, 9 Jul 2015 15:00:23 +0300 Subject: [PATCH 01/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Sales/etc/di.xml | 38 +-- .../Component/Filters/Type/AbstractFilter.php | 13 +- .../Ui/Component/Filters/Type/Input.php | 24 +- .../Ui/Component/Filters/Type/Select.php | 4 +- .../Api/Search/DocumentInterface.php | 24 ++ .../Api/Search/ReportingInterface.php | 21 ++ .../Api/Search/SearchCriteriaInterface.php | 26 ++ .../Api/Search/SearchResultInterface.php | 48 +++ .../UiComponent/DataProvider/DataProvider.php | 4 +- .../DataProvider/DataProviderInterface.php | 3 +- .../UiComponent/DataProvider/Document.php | 31 ++ .../UiComponent/DataProvider/Reporting.php | 106 +++++++ .../DataProvider/SearchDataProvider.php | 297 ++++++++++++++++++ .../UiComponent/DataProvider/SearchResult.php | 83 +++++ 14 files changed, 677 insertions(+), 45 deletions(-) create mode 100644 lib/internal/Magento/Framework/Api/Search/DocumentInterface.php create mode 100644 lib/internal/Magento/Framework/Api/Search/ReportingInterface.php create mode 100644 lib/internal/Magento/Framework/Api/Search/SearchCriteriaInterface.php create mode 100644 lib/internal/Magento/Framework/Api/Search/SearchResultInterface.php create mode 100644 lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php create mode 100644 lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php create mode 100644 lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php create mode 100644 lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 2cb95358885dc..73c55642531d1 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -537,30 +537,30 @@ - + Magento\Sales\Model\Resource\Order\Grid\Collection SalesGirdFilterPool - - - Magento\Sales\Model\Resource\Order\Invoice\Grid\Collection - SalesGirdFilterPool - - - - - Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection - SalesGirdFilterPool - - - - - Magento\Sales\Model\Resource\Order\Creditmemo\Grid\Collection - SalesGirdFilterPool - - + + + + + + + + + + + + + + + + + + Magento\Framework\App\State\Proxy diff --git a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php index d2aa51c314a4b..3c2b4ac2cd901 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php +++ b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php @@ -8,7 +8,7 @@ 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 */ @@ -32,22 +32,27 @@ abstract class AbstractFilter extends AbstractComponent protected $uiComponentFactory; /** - * Constructor - * + * @var + */ + 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()->getRequestParam(static::FILTER_VAR); } } diff --git a/app/code/Magento/Ui/Component/Filters/Type/Input.php b/app/code/Magento/Ui/Component/Filters/Type/Input.php index a9ba7a317942c..675ea24a528bb 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Input.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Input.php @@ -72,26 +72,14 @@ public function prepare() * @return void */ protected function applyFilter() - { - $condition = $this->getCondition(); - if ($condition !== null) { - $this->getContext()->getDataProvider()->addFilter($condition, $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 ($value) { + $filter = $this->filterBuilder->setConditionType('eq') + ->setField($this->getName()) + ->setValue($value) + ->create(); + $this->getContext()->getDataProvider()->addFilter($filter); } - - return $condition; } } diff --git a/app/code/Magento/Ui/Component/Filters/Type/Select.php b/app/code/Magento/Ui/Component/Filters/Type/Select.php index f07f672f37e58..7fce762d7afc0 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Select.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Select.php @@ -44,11 +44,13 @@ public function __construct( ContextInterface $context, UiComponentFactory $uiComponentFactory, OptionSourceInterface $optionsProvider = null, + \Magento\Framework\Api\FilterBuilder $filterBuilder, + array $components = [], array $data = [] ) { $this->optionsProvider = $optionsProvider; - parent::__construct($context, $uiComponentFactory, $components, $data); + parent::__construct($context, $uiComponentFactory, $filterBuilder, $components, $data); } /** diff --git a/lib/internal/Magento/Framework/Api/Search/DocumentInterface.php b/lib/internal/Magento/Framework/Api/Search/DocumentInterface.php new file mode 100644 index 0000000000000..abd7b19cdef6f --- /dev/null +++ b/lib/internal/Magento/Framework/Api/Search/DocumentInterface.php @@ -0,0 +1,24 @@ +filterPool->registerNewFilter($condition, $field, $type); +// $this->filterPool->registerNewFilter($condition, $field, $type); } /** 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..214b4e9c2ca24 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php @@ -96,7 +96,8 @@ public function addField($field, $alias = null); * @param string $type * @return mixed */ - public function addFilter($condition, $field = null, $type = 'regular'); +// 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 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..0bdc37cd0cf40 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php @@ -0,0 +1,31 @@ +_get(self::ID); + } + + /** + * {@inheritdoc} + */ + public function setId($id) + { + return $this->setData(self::ID, $id); + } +} 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..ce58195dd7490 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php @@ -0,0 +1,106 @@ +regularFilter = $regularFilter; + $this->fulltextFilter = $fulltextFilter; + $this->searchResultFactory = $searchResultFactory; + $this->collections = $collections; + } + + /** + * @param SearchCriteriaInterface $searchCriteria + * @return SearchResultInterface + */ + public function search(SearchCriteriaInterface $searchCriteria) + { + if ( isset($this->collections[$searchCriteria->getRequestName()]) + && $this->collections[$searchCriteria->getRequestName()] instanceof AbstractCollection + ) { + /** @var AbstractCollection $collection */ + $collection = $this->collections[$searchCriteria->getRequestName()]; + if ($searchCriteria->getSearchTerm()) { + $this->filterPool->registerNewFilter($searchCriteria->getSearchTerm(), null, 'fulltext'); + } + /** @var \Magento\Framework\Api\Search\FilterGroup $group */ + foreach ($searchCriteria->getFilterGroups() as $group) { + foreach ($group->getFilters() as $filter) { + $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq'; + $this->filterPool->registerNewFilter( + [$condition => $filter->getValue()], + $filter->getField(), + 'regular' + ); + } + } + $this->filterPool->applyFilters($this->collections[$searchCriteria->getRequestName()]); + /** @var SearchResultInterface $searchResult */ + $searchResult = $this->searchResultFactory->create(); + $items = []; + /** @var \Magento\Framework\Model\AbstractModel $item */ + foreach ($collection as $item) { + $items[$item->getId()] = $item->getData(); + } + $searchResult->setItems($items); + $searchResult->setSearchCriteria($searchCriteria); + $searchResult->setTotalCount($collection->getSize()); + return $searchResult; + + } + } +} \ No newline at end of file diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php new file mode 100644 index 0000000000000..7cc696debbdbb --- /dev/null +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php @@ -0,0 +1,297 @@ +name = $name; + $this->primaryFieldName = $primaryFieldName; + $this->requestFieldName = $requestFieldName; + $this->filterPool = $filterPool; + $this->filterGroupBuilder = $filterGroupBuilder; + $this->collection = $collection; + $this->meta = $meta; + $this->data = $data; + } + + /** + * @return Collection + */ + public function getCollection() + { + return $this->collection; + } + + /** + * Get Data Provider name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Get primary field name + * + * @return string + */ + public function getPrimaryFieldName() + { + return $this->primaryFieldName; + } + + /** + * Get field name in request + * + * @return string + */ + public function getRequestFieldName() + { + return $this->requestFieldName; + } + + /** + * @return array + */ + public function getMeta() + { + return $this->meta; + } + + /** + * Get field Set meta info + * + * @param string $fieldSetName + * @return array + */ + public function getFieldSetMetaInfo($fieldSetName) + { + return isset($this->meta[$fieldSetName]) ? $this->meta[$fieldSetName] : []; + } + + /** + * @param string $fieldSetName + * @return array + */ + public function getFieldsMetaInfo($fieldSetName) + { + return isset($this->meta[$fieldSetName]['fields']) ? $this->meta[$fieldSetName]['fields'] : []; + } + + /** + * @param string $fieldSetName + * @param string $fieldName + * @return array + */ + public function getFieldMetaInfo($fieldSetName, $fieldName) + { + return isset($this->meta[$fieldSetName]['fields'][$fieldName]) + ? $this->meta[$fieldSetName]['fields'][$fieldName] + : []; + } + + /** + * @inheritdoc + */ + public function addFilter(\Magento\Framework\Api\Filter $filter) + { + $this->filterGroupBuilder->addFilter($filter); +// ->setFilters( +// array_merge($this->filterGroup->getFilters(), []) + } + + /** + * Add field to select + * + * @param string|array $field + * @param string|null $alias + * @return void + */ + public function addField($field, $alias = null) + { + $this->collection->addFieldToSelect($field, $alias); + } + + /** + * self::setOrder() alias + * + * @param string $field + * @param string $direction + * @return void + */ + public function addOrder($field, $direction) + { + $this->collection->addOrder($field, $direction); + } + + /** + * Set Query limit + * + * @param int $offset + * @param int $size + * @return void + */ + public function setLimit($offset, $size) + { + $this->collection->setPageSize($size); + $this->collection->setCurPage($offset); + } + + /** + * Removes field from select + * + * @param string|null $field + * @param bool $isAlias Alias identifier + * @return void + */ + public function removeField($field, $isAlias = false) + { + $this->collection->removeFieldFromSelect($field, $isAlias); + } + + /** + * Removes all fields from select + * + * @return void + */ + public function removeAllFields() + { + $this->collection->removeAllFieldsFromSelect(); + } + + /** + * Get data + * + * @return array + */ + public function getData() + { + $data = []; + $searchResult = $this->reporting->search($searchCriteria); + $documents = $searchResult->getItems(); + foreach ($documents as $document) { + $data[] = $document->getCustomAttribures(); + } + //$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(); + } + + /** + * Get config data + * + * @return mixed + */ + public function getConfigData() + { + return isset($this->data['config']) ? $this->data['config'] : []; + } + + /** + * Set data + * + * @param mixed $config + * @return void + */ + public function setConfigData($config) + { + $this->data['config'] = $config; + } +} 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..c24f7c04b6f5f --- /dev/null +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php @@ -0,0 +1,83 @@ +_get(self::AGGREGATIONS); + } + /** + * {@inheritdoc} + */ + public function setAggregations($aggregations) + { + return $this->setData(self::AGGREGATIONS, $aggregations); + } + /** + * {@inheritdoc} + */ + public function getItems() + { + return $this->_get(self::ITEMS); + } + /** + * {@inheritdoc} + */ + public function setItems(array $items = null) + { + return $this->setData(self::ITEMS, $items); + } + /** + * Get search criteria. + * + * @return SearchCriteriaInterface + */ + public function getSearchCriteria() + { + return $this->_get(self::SEARCH_CRITERIA); + } + /** + * Set search criteria. + * + * @param BaseSearchCriteriaInterface $searchCriteria + * @return $this + */ + public function setSearchCriteria(BaseSearchCriteriaInterface $searchCriteria = null) + { + return $this->setData(self::SEARCH_CRITERIA, $searchCriteria); + } + /** + * Get total count. + * + * @return int + */ + public function getTotalCount() + { + return $this->_get(self::TOTAL_COUNT); + } + /** + * Set total count. + * + * @param int $totalCount + * @return $this + */ + public function setTotalCount($totalCount) + { + return $this->setData(self::TOTAL_COUNT, $totalCount); + } +} From b0b6ff6b89dbe442aa1529aafc8810a001cbd0c6 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Thu, 9 Jul 2015 16:11:36 +0300 Subject: [PATCH 02/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Sales/etc/di.xml | 36 +++++++++---------- .../Ui/Component/Filters/Type/Search.php | 10 +++++- .../DataProvider/SearchDataProvider.php | 13 +++---- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 73c55642531d1..61db08803aadb 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -543,24 +543,24 @@ SalesGirdFilterPool - - - - - - - - - - - - - - - - - - + + + Magento\Sales\Model\Resource\Order\Invoice\Grid\Collection + SalesGirdFilterPool + + + + + Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection + SalesGirdFilterPool + + + + + Magento\Sales\Model\Resource\Order\Creditmemo\Grid\Collection + SalesGirdFilterPool + + Magento\Framework\App\State\Proxy diff --git a/app/code/Magento/Ui/Component/Filters/Type/Search.php b/app/code/Magento/Ui/Component/Filters/Type/Search.php index 1795b5ccaf5b0..a58f273ecf9e3 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Search.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Search.php @@ -42,7 +42,15 @@ protected function applyFilter() { $keyword = $this->getContext()->getRequestParam('search'); if ($keyword) { - $this->getContext()->getDataProvider()->addFilter($keyword, null, 'fulltext'); + $value = isset($this->filterData[$this->getName()]) ? $this->filterData[$this->getName()] : null; + if ($value) { + $filter = $this->filterBuilder->setConditionType('fulltext') + ->setField($this->getName()) + ->setValue($value) + ->create(); + $this->getContext()->getDataProvider()->addFilter($filter); + } +// $this->getContext()->getDataProvider()->addFilter($keyword, null, 'fulltext'); } } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php index 7cc696debbdbb..1be25573c82f1 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php @@ -253,13 +253,14 @@ public function removeAllFields() */ public function getData() { - $data = []; - $searchResult = $this->reporting->search($searchCriteria); - $documents = $searchResult->getItems(); - foreach ($documents as $document) { - $data[] = $document->getCustomAttribures(); - } +// $data = []; +// $searchResult = $this->reporting->search($searchCriteria); +// $documents = $searchResult->getItems(); +// foreach ($documents as $document) { +// $data[] = $document->getCustomAttribures(); +// } //$this->filterPool->applyFilters($this->collection); + $this->filterGroupBuilder->create(); return $this->collection->toArray(); } From 2ea4e4c3805f9785e635a446d4ecd0de9d4b5a6b Mon Sep 17 00:00:00 2001 From: Sergey Ivashchenko Date: Thu, 9 Jul 2015 17:38:01 +0300 Subject: [PATCH 03/73] MAGETWO-39894: UI components compatibility with Search API --- .../Sales/Model/Resource/Grid/Collection.php | 149 ++++++++++++++++++ .../Sales/Model/Resource/Grid/Document.php | 27 ++++ .../Order/Creditmemo/Grid/Collection.php | 39 ----- .../Creditmemo/Order/Grid/Collection.php | 23 ++- .../Model/Resource/Order/Grid/Collection.php | 31 +--- .../Order/Invoice/Grid/Collection.php | 39 ----- .../Order/Invoice/Orders/Grid/Collection.php | 24 ++- .../Order/Shipment/Grid/Collection.php | 39 ----- .../Order/Shipment/Order/Grid/Collection.php | 23 ++- app/code/Magento/Sales/etc/di.xml | 94 ++++++++--- 10 files changed, 305 insertions(+), 183 deletions(-) create mode 100644 app/code/Magento/Sales/Model/Resource/Grid/Collection.php create mode 100644 app/code/Magento/Sales/Model/Resource/Grid/Document.php delete mode 100644 app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Grid/Collection.php delete mode 100644 app/code/Magento/Sales/Model/Resource/Order/Invoice/Grid/Collection.php delete mode 100644 app/code/Magento/Sales/Model/Resource/Order/Shipment/Grid/Collection.php 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..5feb6d06364cf --- /dev/null +++ b/app/code/Magento/Sales/Model/Resource/Grid/Collection.php @@ -0,0 +1,149 @@ +_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/Grid/Document.php b/app/code/Magento/Sales/Model/Resource/Grid/Document.php new file mode 100644 index 0000000000000..5fba4100f6c26 --- /dev/null +++ b/app/code/Magento/Sales/Model/Resource/Grid/Document.php @@ -0,0 +1,27 @@ +id; + } + + public function setId($id) + { + $this->id = $id; + } +} 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 index 93ad0a20aedbd..ad647fcdd36d8 100644 --- 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 @@ -7,10 +7,8 @@ /** * Flat sales order creditmemo collection - * - * @author Magento Core Team */ -class Collection extends \Magento\Sales\Model\Resource\Order\Creditmemo\Grid\Collection +class Collection extends \Magento\Sales\Model\Resource\Grid\Collection { /** * @var \Magento\Framework\Registry @@ -23,8 +21,12 @@ class Collection extends \Magento\Sales\Model\Resource\Order\Creditmemo\Grid\Col * @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 null|\Zend_Db_Adapter_Abstract $mainTable + * @param \Magento\Framework\Model\Resource\Db\AbstractDb $eventPrefix + * @param string $eventObject + * @param string $resourceModel + * @param string $model + * @param string|null $connection * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource */ public function __construct( @@ -32,18 +34,25 @@ public function __construct( \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, + $mainTable, + $eventPrefix, + $eventObject, + $resourceModel, + $model = 'Magento\Sales\Model\Resource\Grid\Document', $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null ) { $this->registryManager = $registryManager; + $this->_eventPrefix = $eventPrefix; + $this->_eventObject = $eventObject; + $this->_init($model, $resourceModel); + $this->setMainTable($mainTable); parent::__construct( $entityFactory, $logger, $fetchStrategy, $eventManager, - $entitySnapshot, $connection, $resource ); diff --git a/app/code/Magento/Sales/Model/Resource/Order/Grid/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Grid/Collection.php index 5b673d4a23dc5..f432fc191c910 100644 --- a/app/code/Magento/Sales/Model/Resource/Order/Grid/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Order/Grid/Collection.php @@ -5,27 +5,13 @@ */ namespace Magento\Sales\Model\Resource\Order\Grid; +use Magento\Framework\Search\AggregationInterface; + /** * Flat sales order grid collection - * - * @author Magento Core Team */ -class Collection extends \Magento\Sales\Model\Resource\Order\Collection +class Collection extends \Magento\Sales\Model\Resource\Grid\Collection { - /** - * Event prefix - * - * @var string - */ - protected $_eventPrefix = 'sales_order_grid_collection'; - - /** - * Event object - * - * @var string - */ - protected $_eventObject = 'order_grid_collection'; - /** * Customer mode flag * @@ -33,17 +19,6 @@ class Collection extends \Magento\Sales\Model\Resource\Order\Collection */ protected $_customerModeFlag = false; - /** - * Model initialization - * - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->setMainTable('sales_order_grid'); - } - /** * Get SQL for get record count * 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 index c0d9c383cc8d7..dcb03a43ec59f 100644 --- 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 @@ -5,7 +5,10 @@ */ namespace Magento\Sales\Model\Resource\Order\Invoice\Orders\Grid; -class Collection extends \Magento\Sales\Model\Resource\Order\Invoice\Grid\Collection +/** + * Class Collection + */ +class Collection extends \Magento\Sales\Model\Resource\Grid\Collection { /** * @var \Magento\Framework\Registry @@ -17,9 +20,13 @@ class Collection extends \Magento\Sales\Model\Resource\Order\Invoice\Grid\Collec * @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 null|\Zend_Db_Adapter_Abstract $mainTable + * @param \Magento\Framework\Model\Resource\Db\AbstractDb $eventPrefix + * @param string $eventObject + * @param string $resourceModel + * @param string $model + * @param string|null $connection * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource */ public function __construct( @@ -27,18 +34,25 @@ public function __construct( \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, + $mainTable, + $eventPrefix, + $eventObject, + $resourceModel, + $model = 'Magento\Sales\Model\Resource\Grid\Document', $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null ) { $this->registryManager = $registryManager; + $this->_eventPrefix = $eventPrefix; + $this->_eventObject = $eventObject; + $this->_init($model, $resourceModel); + $this->setMainTable($mainTable); parent::__construct( $entityFactory, $logger, $fetchStrategy, $eventManager, - $entitySnapshot, $connection, $resource ); 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 index 6abb188c1b7ed..11d0ce6afe3ce 100644 --- 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 @@ -7,10 +7,8 @@ /** * Flat sales order shipment collection - * - * @author Magento Core Team */ -class Collection extends \Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection +class Collection extends \Magento\Sales\Model\Resource\Grid\Collection { /** * @var \Magento\Framework\Registry @@ -22,9 +20,13 @@ class Collection extends \Magento\Sales\Model\Resource\Order\Shipment\Grid\Colle * @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 null|\Zend_Db_Adapter_Abstract $mainTable + * @param \Magento\Framework\Model\Resource\Db\AbstractDb $eventPrefix + * @param string $eventObject + * @param string $resourceModel + * @param string $model + * @param string|null $connection * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource */ public function __construct( @@ -32,18 +34,25 @@ public function __construct( \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, + $mainTable, + $eventPrefix, + $eventObject, + $resourceModel, + $model = 'Magento\Sales\Model\Resource\Grid\Document', $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null ) { $this->registryManager = $registryManager; + $this->_eventPrefix = $eventPrefix; + $this->_eventObject = $eventObject; + $this->_init($model, $resourceModel); + $this->setMainTable($mainTable); parent::__construct( $entityFactory, $logger, $fetchStrategy, $eventManager, - $entitySnapshot, $connection, $resource ); diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 73c55642531d1..1de2611b6aa88 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -537,33 +537,89 @@ - + Magento\Sales\Model\Resource\Order\Grid\Collection SalesGirdFilterPool - - - - - - - - - - - - - - - - - - + + + Magento\Sales\Model\Resource\Order\Invoice\Grid\Collection + SalesGirdFilterPool + + + + + Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection + SalesGirdFilterPool + + + + + Magento\Sales\Model\Resource\Order\Creditmemo\Grid\Collection + SalesGirdFilterPool + + Magento\Framework\App\State\Proxy + + + sales_order_grid + sales_order_grid_collection + order_grid_collection + Magento\Sales\Model\Resource\Order + + + + + sales_invoice_grid + sales_order_invoice_grid_collection + order_invoice_grid_collection + Magento\Sales\Model\Resource\Order\Invoice + + + + + sales_shipment_grid + sales_order_shipment_grid_collection + order_shipment_grid_collection + Magento\Sales\Model\Resource\Order\Shipment + + + + + sales_creditmemo_grid + sales_order_creditmemo_grid_collection + order_creditmemo_grid_collection + Magento\Sales\Model\Resource\Order\Creditmemo + + + + + sales_invoice_grid + sales_order_invoice_grid_collection + order_invoice_grid_collection + Magento\Sales\Model\Resource\Order\Invoice + + + + + sales_shipment_grid + sales_order_shipment_grid_collection + order_shipment_grid_collection + Magento\Sales\Model\Resource\Order\Shipment + + + + + sales_creditmemo_grid + sales_order_creditmemo_grid_collection + order_creditmemo_grid_collection + Magento\Sales\Model\Resource\Order\Creditmemo + + From 258262b8f056c86d660ff90de99c0e50a6ac7960 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Thu, 9 Jul 2015 18:43:49 +0300 Subject: [PATCH 04/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Sales/etc/di.xml | 15 ++- .../Framework/Api/Search/SearchCriteria.php | 46 ++++++++ .../Api/Search/SearchCriteriaBuilder.php | 103 ++++++++++++++++++ .../DataProvider/CollectionPool.php | 38 +++++++ .../DataProvider/FilterApplierInterface.php | 4 +- .../UiComponent/DataProvider/FilterPool.php | 35 ++---- .../DataProvider/FulltextFilter.php | 19 ++-- .../DataProvider/RegularFilter.php | 10 +- .../UiComponent/DataProvider/Reporting.php | 86 +++------------ .../DataProvider/SearchDataProvider.php | 57 ++++------ 10 files changed, 257 insertions(+), 156 deletions(-) create mode 100644 lib/internal/Magento/Framework/Api/Search/SearchCriteria.php create mode 100644 lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php create mode 100644 lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionPool.php diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 61db08803aadb..f13ee04041af9 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -529,36 +529,32 @@ - + Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter - + Magento\Sales\Model\Resource\Order\Grid\Collection - SalesGirdFilterPool Magento\Sales\Model\Resource\Order\Invoice\Grid\Collection - SalesGirdFilterPool Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection - SalesGirdFilterPool Magento\Sales\Model\Resource\Order\Creditmemo\Grid\Collection - SalesGirdFilterPool @@ -566,4 +562,11 @@ Magento\Framework\App\State\Proxy + + + + Magento\Sales\Model\Resource\Order\Grid\Collection + + + diff --git a/lib/internal/Magento/Framework/Api/Search/SearchCriteria.php b/lib/internal/Magento/Framework/Api/Search/SearchCriteria.php new file mode 100644 index 0000000000000..338a98eb17199 --- /dev/null +++ b/lib/internal/Magento/Framework/Api/Search/SearchCriteria.php @@ -0,0 +1,46 @@ +_get(self::SEARCH_TERM); + } + /** + * {@inheritdoc} + */ + public function setSearchTerm($searchTerm) + { + return $this->setData(self::SEARCH_TERM, $searchTerm); + } + /** + * {@inheritdoc} + */ + public function getRequestName() + { + return $this->_get(self::REQUEST_NAME); + } + /** + * {@inheritdoc} + */ + public function setRequestName($requestName) + { + return $this->setData(self::REQUEST_NAME, $requestName); + } +} diff --git a/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php b/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php new file mode 100644 index 0000000000000..e81f2e4767029 --- /dev/null +++ b/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php @@ -0,0 +1,103 @@ +_filterGroupBuilder = $filterGroupBuilder; + $this->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 $field + * @param $direction + * @return $this + */ + public function addSortOrder($field, $direction) + { + $this->sortOrderBuilder->setDirection($direction) + ->setField($field) + ->create(); + 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/View/Element/UiComponent/DataProvider/CollectionPool.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionPool.php new file mode 100644 index 0000000000000..16457778159f8 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionPool.php @@ -0,0 +1,38 @@ +collections = $collections; + } + + /** + * @param $requestName + * @return AbstractCollection + * @throws \Exception + */ + public function getCollection($requestName) + { + if (!isset($this->collections[$requestName])) { + throw new \Exception('111111'); + } + return $this->collections[$requestName]; + } +} \ No newline at end of file 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..0f4df78442899 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,12 @@ 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 +26,20 @@ 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 - * @return void + * @param SearchCriteriaInterface $criteria */ - 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 a313e403aa61f..6ef83ab475ba3 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FulltextFilter.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FulltextFilter.php @@ -7,7 +7,8 @@ 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 @@ -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()); if (!$columns) { return; } - foreach ($filters as $filter) { - $collection->getSelect() - ->where( - 'MATCH(' . implode(',', $columns) . ') AGAINST(? IN BOOLEAN MODE)', - $filter['condition'] - ); - } + $collection->getSelect() + ->where( + 'MATCH(' . implode(',', $columns) . ') AGAINST(? IN BOOLEAN MODE)', + $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..3c7a57e603b7e 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/RegularFilter.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/RegularFilter.php @@ -7,7 +7,7 @@ namespace Magento\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Data\Collection\AbstractDb; - +use Magento\Framework\Api\Filter; /** * Class RegularFilter */ @@ -17,13 +17,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 index ce58195dd7490..9fefe7bd15452 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php @@ -1,9 +1,7 @@ regularFilter = $regularFilter; - $this->fulltextFilter = $fulltextFilter; - $this->searchResultFactory = $searchResultFactory; - $this->collections = $collections; + $this->collectionPool = $collectionPool; + $this->filterPool = $filterPool; } /** @@ -69,38 +41,10 @@ public function __construct( */ public function search(SearchCriteriaInterface $searchCriteria) { - if ( isset($this->collections[$searchCriteria->getRequestName()]) - && $this->collections[$searchCriteria->getRequestName()] instanceof AbstractCollection - ) { - /** @var AbstractCollection $collection */ - $collection = $this->collections[$searchCriteria->getRequestName()]; - if ($searchCriteria->getSearchTerm()) { - $this->filterPool->registerNewFilter($searchCriteria->getSearchTerm(), null, 'fulltext'); - } - /** @var \Magento\Framework\Api\Search\FilterGroup $group */ - foreach ($searchCriteria->getFilterGroups() as $group) { - foreach ($group->getFilters() as $filter) { - $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq'; - $this->filterPool->registerNewFilter( - [$condition => $filter->getValue()], - $filter->getField(), - 'regular' - ); - } - } - $this->filterPool->applyFilters($this->collections[$searchCriteria->getRequestName()]); - /** @var SearchResultInterface $searchResult */ - $searchResult = $this->searchResultFactory->create(); - $items = []; - /** @var \Magento\Framework\Model\AbstractModel $item */ - foreach ($collection as $item) { - $items[$item->getId()] = $item->getData(); - } - $searchResult->setItems($items); - $searchResult->setSearchCriteria($searchCriteria); - $searchResult->setTotalCount($collection->getSize()); - return $searchResult; - - } + $collection = $this->collectionPool->getCollection($searchCriteria->getRequestName()); + $collection->setPageSize($searchCriteria->getPageSize()); + $collection->setCurPage($searchCriteria->getCurrentPage()); + $this->filterPool->applyFilters($collection, $searchCriteria); + return $collection; } } \ No newline at end of file diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php index 1be25573c82f1..3400073340994 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php @@ -52,21 +52,19 @@ class SearchDataProvider implements DataProviderInterface protected $data = []; /** - * @var FilterPool + * @var Reporting */ - protected $filterPool; - - /** - * @var \Magento\Framework\Api\Search\FilterGroupBuilder - */ - protected $filterGroup; + protected $reporting; /** * @var */ protected $filterBuilder; - protected $searchCriteria; + /** + * @var \Magento\Framework\Api\Search\SearchCriteriaBuilder + */ + protected $searchCriteriaBuilder; /** * @param $name @@ -74,7 +72,6 @@ class SearchDataProvider implements DataProviderInterface * @param $requestFieldName * @param Collection $collection * @param FilterPool $filterPool - * @param \Magento\Framework\Api\Search\FilterGroupBuilder $filterGroupBuilder * @param array $meta * @param array $data */ @@ -82,19 +79,16 @@ public function __construct( $name, $primaryFieldName, $requestFieldName, - Collection $collection, - FilterPool $filterPool, - \Magento\Framework\Api\Search\FilterGroupBuilder $filterGroupBuilder, -// \Magento\Framework\Api\Search\SearchCriteriaInterface $filterGroupBuilder, + Reporting $reporting, + \Magento\Framework\Api\Search\SearchCriteriaBuilder $searchCriteriaBuilder, array $meta = [], array $data = [] ) { $this->name = $name; $this->primaryFieldName = $primaryFieldName; $this->requestFieldName = $requestFieldName; - $this->filterPool = $filterPool; - $this->filterGroupBuilder = $filterGroupBuilder; - $this->collection = $collection; + $this->reporting= $reporting; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->meta = $meta; $this->data = $data; } @@ -182,9 +176,7 @@ public function getFieldMetaInfo($fieldSetName, $fieldName) */ public function addFilter(\Magento\Framework\Api\Filter $filter) { - $this->filterGroupBuilder->addFilter($filter); -// ->setFilters( -// array_merge($this->filterGroup->getFilters(), []) + $this->searchCriteriaBuilder->addFilter($filter); } /** @@ -196,7 +188,7 @@ public function addFilter(\Magento\Framework\Api\Filter $filter) */ public function addField($field, $alias = null) { - $this->collection->addFieldToSelect($field, $alias); +// $this->collection->addFieldToSelect($field, $alias); } /** @@ -208,7 +200,7 @@ public function addField($field, $alias = null) */ public function addOrder($field, $direction) { - $this->collection->addOrder($field, $direction); + $this->searchCriteriaBuilder->addSortOrder($field, $direction); } /** @@ -220,8 +212,8 @@ 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); } /** @@ -233,7 +225,7 @@ public function setLimit($offset, $size) */ public function removeField($field, $isAlias = false) { - $this->collection->removeFieldFromSelect($field, $isAlias); +// $this->collection->removeFieldFromSelect($field, $isAlias); } /** @@ -243,7 +235,7 @@ public function removeField($field, $isAlias = false) */ public function removeAllFields() { - $this->collection->removeAllFieldsFromSelect(); +// $this->collection->removeAllFieldsFromSelect(); } /** @@ -253,15 +245,9 @@ public function removeAllFields() */ public function getData() { -// $data = []; -// $searchResult = $this->reporting->search($searchCriteria); -// $documents = $searchResult->getItems(); -// foreach ($documents as $document) { -// $data[] = $document->getCustomAttribures(); -// } - //$this->filterPool->applyFilters($this->collection); - $this->filterGroupBuilder->create(); - return $this->collection->toArray(); + $searchCriteria = $this->searchCriteriaBuilder->create(); + $searchCriteria->setRequestName($this->name); + return $this->reporting->search($searchCriteria)->toArray(); } /** @@ -271,8 +257,7 @@ public function getData() */ public function count() { - $this->filterPool->applyFilters($this->collection); - return $this->collection->count(); + return 10; } /** From 89f2cada3f582682e2a392588201e9b90c677174 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Thu, 9 Jul 2015 18:48:15 +0300 Subject: [PATCH 05/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Sales/etc/di.xml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 1de2611b6aa88..d5e3b7a1f4e4c 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -529,36 +529,42 @@ - + 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\Grid\Collection - SalesGirdFilterPool Magento\Sales\Model\Resource\Order\Invoice\Grid\Collection - SalesGirdFilterPool Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection - SalesGirdFilterPool Magento\Sales\Model\Resource\Order\Creditmemo\Grid\Collection - SalesGirdFilterPool From 7996cc43574e692a1f7f3b496020387f71629674 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Thu, 9 Jul 2015 18:50:39 +0300 Subject: [PATCH 06/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Sales/etc/di.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index d5e3b7a1f4e4c..60dd1146352a8 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -543,7 +543,7 @@ 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\Creditmemo\Grid\Collection From aa997a3d40045a162f77255b8c33c8d14b9e61b4 Mon Sep 17 00:00:00 2001 From: Sergey Ivashchenko Date: Thu, 9 Jul 2015 18:52:18 +0300 Subject: [PATCH 07/73] MAGETWO-39894: UI components compatibility with Search API --- .../Customer/Model/Customer/DataProvider.php | 4 +- .../Sales/Model/Resource/Grid/Collection.php | 1 + .../Orders/Grid => Grid/Order}/Collection.php | 31 +- .../Creditmemo/Order/Grid/Collection.php | 81 -- .../Order/Shipment/Order/Grid/Collection.php | 82 -- app/code/Magento/Sales/etc/di.xml | 30 +- .../adminhtml/layout/sales_order_view.xml | 12 +- .../sales_order_view_creditmemo_grid.xml | 782 ++++++++++++++++++ .../sales_order_view_invoice_grid.xml | 733 ++++++++++++++++ .../sales_order_view_shipment_grid.xml | 650 +++++++++++++++ 10 files changed, 2216 insertions(+), 190 deletions(-) rename app/code/Magento/Sales/Model/Resource/{Order/Invoice/Orders/Grid => Grid/Order}/Collection.php (81%) delete mode 100644 app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Order/Grid/Collection.php delete mode 100644 app/code/Magento/Sales/Model/Resource/Order/Shipment/Order/Grid/Collection.php create mode 100644 app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_creditmemo_grid.xml create mode 100644 app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_invoice_grid.xml create mode 100644 app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_shipment_grid.xml diff --git a/app/code/Magento/Customer/Model/Customer/DataProvider.php b/app/code/Magento/Customer/Model/Customer/DataProvider.php index ef9437174edc3..74a38020a14dc 100644 --- a/app/code/Magento/Customer/Model/Customer/DataProvider.php +++ b/app/code/Magento/Customer/Model/Customer/DataProvider.php @@ -221,9 +221,9 @@ public function getFieldSetMetaInfo($fieldSetName) /** * @inheritdoc */ - public function addFilter($condition, $field = null, $type = 'regular') + public function addFilter(\Magento\Framework\Api\Filter $filter) { - $this->filterPool->registerNewFilter($condition, $field, $type); + //@todo implement this method } /** diff --git a/app/code/Magento/Sales/Model/Resource/Grid/Collection.php b/app/code/Magento/Sales/Model/Resource/Grid/Collection.php index 5feb6d06364cf..32e49c7a6486e 100644 --- a/app/code/Magento/Sales/Model/Resource/Grid/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Grid/Collection.php @@ -11,6 +11,7 @@ /** * Class Collection + * Collection for displaying grid of sales documents */ class Collection extends AbstractCollection implements SearchResultInterface { diff --git a/app/code/Magento/Sales/Model/Resource/Order/Invoice/Orders/Grid/Collection.php b/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php similarity index 81% rename from app/code/Magento/Sales/Model/Resource/Order/Invoice/Orders/Grid/Collection.php rename to app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php index dcb03a43ec59f..24470e5e4cd3b 100644 --- a/app/code/Magento/Sales/Model/Resource/Order/Invoice/Orders/Grid/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php @@ -3,10 +3,11 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sales\Model\Resource\Order\Invoice\Orders\Grid; +namespace Magento\Sales\Model\Resource\Grid\Order; /** * Class Collection + * Collection for order related documents to display grids on order view page */ class Collection extends \Magento\Sales\Model\Resource\Grid\Collection { @@ -15,6 +16,13 @@ class Collection extends \Magento\Sales\Model\Resource\Grid\Collection */ protected $registryManager; + /** + * Order field for setOrderFilter + * + * @var string + */ + protected $_orderField = 'order_id'; + /** * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory * @param \Psr\Log\LoggerInterface $logger @@ -44,30 +52,21 @@ public function __construct( \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null ) { $this->registryManager = $registryManager; - $this->_eventPrefix = $eventPrefix; - $this->_eventObject = $eventObject; - $this->_init($model, $resourceModel); - $this->setMainTable($mainTable); parent::__construct( $entityFactory, $logger, $fetchStrategy, $eventManager, + $mainTable, + $eventPrefix, + $eventObject, + $resourceModel, + $model, $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 * @@ -76,7 +75,7 @@ public function getOrder() protected function _initSelect() { parent::_initSelect(); - $this->setOrderFilter($this->getOrder()); + $this->addFieldToFilter($this->_orderField, $this->registryManager->registry('current_order')->getId()); return $this; } } 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 ad647fcdd36d8..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Order/Grid/Collection.php +++ /dev/null @@ -1,81 +0,0 @@ -registryManager = $registryManager; - $this->_eventPrefix = $eventPrefix; - $this->_eventObject = $eventObject; - $this->_init($model, $resourceModel); - $this->setMainTable($mainTable); - parent::__construct( - $entityFactory, - $logger, - $fetchStrategy, - $eventManager, - $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/Shipment/Order/Grid/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Shipment/Order/Grid/Collection.php deleted file mode 100644 index 11d0ce6afe3ce..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Order/Shipment/Order/Grid/Collection.php +++ /dev/null @@ -1,82 +0,0 @@ -registryManager = $registryManager; - $this->_eventPrefix = $eventPrefix; - $this->_eventObject = $eventObject; - $this->_init($model, $resourceModel); - $this->setMainTable($mainTable); - parent::__construct( - $entityFactory, - $logger, - $fetchStrategy, - $eventManager, - $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/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 1de2611b6aa88..3414d3c531be4 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -561,6 +561,24 @@ SalesGirdFilterPool + + + Magento\Sales\Model\Resource\Order\Invoice\Orders\Grid\Collection + SalesGirdFilterPool + + + + + Magento\Sales\Model\Resource\Order\Shipment\Order\Grid\Collection + SalesGirdFilterPool + + + + + Magento\Sales\Model\Resource\Order\Creditmemo\Order\Grid\Collection + SalesGirdFilterPool + + Magento\Framework\App\State\Proxy @@ -598,28 +616,28 @@ Magento\Sales\Model\Resource\Order\Creditmemo - + sales_invoice_grid sales_order_invoice_grid_collection order_invoice_grid_collection Magento\Sales\Model\Resource\Order\Invoice - - + + sales_shipment_grid sales_order_shipment_grid_collection order_shipment_grid_collection Magento\Sales\Model\Resource\Order\Shipment - - + + sales_creditmemo_grid sales_order_creditmemo_grid_collection order_creditmemo_grid_collection Magento\Sales\Model\Resource\Order\Creditmemo - + 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/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..21d8a414e1d1f --- /dev/null +++ b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_creditmemo_grid.xml @@ -0,0 +1,782 @@ + + ++ + + 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 + + + + OrderViewCreditmemoGridDataProvider + sales_order_view_creditmemo_grid_data_source + increment_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 + + + + + + + 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..5de51590a4a13 --- /dev/null +++ b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_invoice_grid.xml @@ -0,0 +1,733 @@ + + ++ + + 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 + + + + OrderViewInvoiceGridDataProvider + sales_order_view_invoice_grid_data_source + increment_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 + + + + + + + dataGridActions + + + csv + CSV + sales/invoice/exportCsv + + + xml + Excel XML + sales/invoice/exportExcel + + + + + + + + + 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 + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + + + + + + + from + From + From + + + + + + + to + To + To + + + + + + + + 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 # + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + + + + + + + from + From + From + + + + + + + to + To + To + + + + + + + + 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..ae01965ffcc2c --- /dev/null +++ b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_shipment_grid.xml @@ -0,0 +1,650 @@ + + ++ + + 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_shipment_columns + + + + OrderViewShipmentGridDataProvider + sales_order_view_invoice_grid_data_source + increment_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_shipment_columns + + Magento_Ui/js/grid/controls/columns + dataGridActions + + + + + + + dataGridActions + + + csv + CSV + sales/shipment/exportCsv + + + xml + Excel XML + sales/shipment/exportExcel + + + + + + + + + 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 + Shipment + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + + + + + + + from + From + From + + + + + + + to + To + To + + + + + + + + created_at + Ship 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 + + sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + + + + + + + from + From + From + + + + + + + to + To + To + + + + + + + + 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 + + + + + + + + shipping_name + Ship-to Name + + + + + + + total_qty + Total Quantity + + sales_order_view_invoice_grid.sales_order_view_invoice_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_invoice_grid.sales_order_view_invoice_grid.sales_order_shipment_columns.ids + bottom + + + pdfshipments_order + PDF Shipments + sales/shipment/pdfshipments + + + 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_shipment_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 + 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 + + + + + From 7e179784e7b327942f3620509afbe8b45a259461 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Thu, 9 Jul 2015 18:56:09 +0300 Subject: [PATCH 08/73] MAGETWO-39905: UI components compatibility with Search API --- .../UiComponent/DataProvider/DataProvider.php | 50 ++-- .../DataProvider/SearchDataProvider.php | 283 ------------------ 2 files changed, 30 insertions(+), 303 deletions(-) delete mode 100644 lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php 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 1d458e29ec767..64db6b2fa2890 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php @@ -52,14 +52,24 @@ class DataProvider implements DataProviderInterface protected $data = []; /** - * @var FilterPool + * @var Reporting */ - protected $filterPool; + protected $reporting; /** - * @param string $name - * @param string $primaryFieldName - * @param string $requestFieldName + * @var + */ + protected $filterBuilder; + + /** + * @var \Magento\Framework\Api\Search\SearchCriteriaBuilder + */ + protected $searchCriteriaBuilder; + + /** + * @param $name + * @param $primaryFieldName + * @param $requestFieldName * @param Collection $collection * @param FilterPool $filterPool * @param array $meta @@ -69,16 +79,16 @@ public function __construct( $name, $primaryFieldName, $requestFieldName, - Collection $collection, - FilterPool $filterPool, + Reporting $reporting, + \Magento\Framework\Api\Search\SearchCriteriaBuilder $searchCriteriaBuilder, array $meta = [], array $data = [] ) { $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; } @@ -166,7 +176,7 @@ public function getFieldMetaInfo($fieldSetName, $fieldName) */ public function addFilter(\Magento\Framework\Api\Filter $filter) { -// $this->filterPool->registerNewFilter($condition, $field, $type); + $this->searchCriteriaBuilder->addFilter($filter); } /** @@ -178,7 +188,7 @@ public function addFilter(\Magento\Framework\Api\Filter $filter) */ public function addField($field, $alias = null) { - $this->collection->addFieldToSelect($field, $alias); +// $this->collection->addFieldToSelect($field, $alias); } /** @@ -190,7 +200,7 @@ public function addField($field, $alias = null) */ public function addOrder($field, $direction) { - $this->collection->addOrder($field, $direction); + $this->searchCriteriaBuilder->addSortOrder($field, $direction); } /** @@ -202,8 +212,8 @@ 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); } /** @@ -215,7 +225,7 @@ public function setLimit($offset, $size) */ public function removeField($field, $isAlias = false) { - $this->collection->removeFieldFromSelect($field, $isAlias); +// $this->collection->removeFieldFromSelect($field, $isAlias); } /** @@ -225,7 +235,7 @@ public function removeField($field, $isAlias = false) */ public function removeAllFields() { - $this->collection->removeAllFieldsFromSelect(); +// $this->collection->removeAllFieldsFromSelect(); } /** @@ -235,8 +245,9 @@ public function removeAllFields() */ public function getData() { - $this->filterPool->applyFilters($this->collection); - return $this->collection->toArray(); + $searchCriteria = $this->searchCriteriaBuilder->create(); + $searchCriteria->setRequestName($this->name); + return $this->reporting->search($searchCriteria)->toArray(); } /** @@ -246,8 +257,7 @@ public function getData() */ public function count() { - $this->filterPool->applyFilters($this->collection); - return $this->collection->count(); + return 10; } /** diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php deleted file mode 100644 index 3400073340994..0000000000000 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchDataProvider.php +++ /dev/null @@ -1,283 +0,0 @@ -name = $name; - $this->primaryFieldName = $primaryFieldName; - $this->requestFieldName = $requestFieldName; - $this->reporting= $reporting; - $this->searchCriteriaBuilder = $searchCriteriaBuilder; - $this->meta = $meta; - $this->data = $data; - } - - /** - * @return Collection - */ - public function getCollection() - { - return $this->collection; - } - - /** - * Get Data Provider name - * - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Get primary field name - * - * @return string - */ - public function getPrimaryFieldName() - { - return $this->primaryFieldName; - } - - /** - * Get field name in request - * - * @return string - */ - public function getRequestFieldName() - { - return $this->requestFieldName; - } - - /** - * @return array - */ - public function getMeta() - { - return $this->meta; - } - - /** - * Get field Set meta info - * - * @param string $fieldSetName - * @return array - */ - public function getFieldSetMetaInfo($fieldSetName) - { - return isset($this->meta[$fieldSetName]) ? $this->meta[$fieldSetName] : []; - } - - /** - * @param string $fieldSetName - * @return array - */ - public function getFieldsMetaInfo($fieldSetName) - { - return isset($this->meta[$fieldSetName]['fields']) ? $this->meta[$fieldSetName]['fields'] : []; - } - - /** - * @param string $fieldSetName - * @param string $fieldName - * @return array - */ - public function getFieldMetaInfo($fieldSetName, $fieldName) - { - return isset($this->meta[$fieldSetName]['fields'][$fieldName]) - ? $this->meta[$fieldSetName]['fields'][$fieldName] - : []; - } - - /** - * @inheritdoc - */ - public function addFilter(\Magento\Framework\Api\Filter $filter) - { - $this->searchCriteriaBuilder->addFilter($filter); - } - - /** - * Add field to select - * - * @param string|array $field - * @param string|null $alias - * @return void - */ - public function addField($field, $alias = null) - { -// $this->collection->addFieldToSelect($field, $alias); - } - - /** - * self::setOrder() alias - * - * @param string $field - * @param string $direction - * @return void - */ - public function addOrder($field, $direction) - { - $this->searchCriteriaBuilder->addSortOrder($field, $direction); - } - - /** - * Set Query limit - * - * @param int $offset - * @param int $size - * @return void - */ - public function setLimit($offset, $size) - { - $this->searchCriteriaBuilder->setPageSize($size); - $this->searchCriteriaBuilder->setCurrentPage($offset); - } - - /** - * Removes field from select - * - * @param string|null $field - * @param bool $isAlias Alias identifier - * @return void - */ - public function removeField($field, $isAlias = false) - { -// $this->collection->removeFieldFromSelect($field, $isAlias); - } - - /** - * Removes all fields from select - * - * @return void - */ - public function removeAllFields() - { -// $this->collection->removeAllFieldsFromSelect(); - } - - /** - * Get data - * - * @return array - */ - public function getData() - { - $searchCriteria = $this->searchCriteriaBuilder->create(); - $searchCriteria->setRequestName($this->name); - return $this->reporting->search($searchCriteria)->toArray(); - } - - /** - * Retrieve count of loaded items - * - * @return int - */ - public function count() - { - return 10; - } - - /** - * Get config data - * - * @return mixed - */ - public function getConfigData() - { - return isset($this->data['config']) ? $this->data['config'] : []; - } - - /** - * Set data - * - * @param mixed $config - * @return void - */ - public function setConfigData($config) - { - $this->data['config'] = $config; - } -} From 38237ec4b5f00c7ad05a54aff53ec2c4abfd4387 Mon Sep 17 00:00:00 2001 From: Sergey Ivashchenko Date: Thu, 9 Jul 2015 19:13:16 +0300 Subject: [PATCH 09/73] MAGETWO-39894: UI components compatibility with Search API --- .../Model/Resource/Grid/Order/Collection.php | 2 +- app/code/Magento/Sales/etc/di.xml | 41 ++--------------- .../sales_order_creditmemo_grid.xml | 2 +- .../ui_component/sales_order_grid.xml | 2 +- .../ui_component/sales_order_invoice_grid.xml | 2 +- .../sales_order_shipment_grid.xml | 2 +- .../sales_order_view_creditmemo_grid.xml | 2 +- .../sales_order_view_invoice_grid.xml | 2 +- .../sales_order_view_shipment_grid.xml | 46 +++++++++---------- .../Ui/TemplateEngine/Xhtml/Result.php | 2 +- 10 files changed, 34 insertions(+), 69 deletions(-) diff --git a/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php b/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php index 24470e5e4cd3b..dc18d7795fcca 100644 --- a/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php @@ -75,7 +75,7 @@ public function __construct( protected function _initSelect() { parent::_initSelect(); - $this->addFieldToFilter($this->_orderField, $this->registryManager->registry('current_order')->getId()); + //$this->addFieldToFilter($this->_orderField, $this->registryManager->registry('current_order')->getId()); return $this; } } diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 5c7f13c552999..a4518a7d4549e 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -544,47 +544,12 @@ 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\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 - SalesGirdFilterPool - - - - - Magento\Sales\Model\Resource\Order\Shipment\Order\Grid\Collection - SalesGirdFilterPool - - - - - Magento\Sales\Model\Resource\Order\Creditmemo\Order\Grid\Collection - SalesGirdFilterPool - - Magento\Framework\App\State\Proxy 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 99b86384d7c8c..692331a6fc2cb 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,7 +15,7 @@ - CreditmemoGridDataProvider + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_creditmemo_grid_data_source increment_id id 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 788f556036cfb..1082430c04189 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,7 +23,7 @@ - OrderGridDataProvider + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_grid_data_source increment_id id 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 7b39dd42a49ea..1af1c10a4817c 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,7 +15,7 @@ - InvoiceGridDataProvider + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_invoice_grid_data_source increment_id id 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 b1c51a0d34848..250e59d56da97 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,7 +15,7 @@ - ShipmentGridDataProvider + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_shipment_grid_data_source increment_id 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 index 21d8a414e1d1f..feab933c6c87c 100644 --- 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 @@ -15,7 +15,7 @@ - OrderViewCreditmemoGridDataProvider + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_view_creditmemo_grid_data_source increment_id id 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 index 5de51590a4a13..ceabd9fd5ccc0 100644 --- 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 @@ -15,7 +15,7 @@ - OrderViewInvoiceGridDataProvider + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_view_invoice_grid_data_source increment_id id 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 index ae01965ffcc2c..2306b4faca06c 100644 --- 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 @@ -8,15 +8,15 @@ - 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_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 - + - OrderViewShipmentGridDataProvider - sales_order_view_invoice_grid_data_source + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider + sales_order_view_shipment_grid_data_source increment_id id @@ -45,7 +45,7 @@ - sales_order_view_invoice_grid + sales_order_view_shipment_grid @@ -54,7 +54,7 @@ - sales_order_view_invoice_grid.sales_order_view_invoice_grid.sales_order_shipment_columns + sales_order_view_shipment_grid.sales_order_view_shipment_grid.sales_order_shipment_columns Magento_Ui/js/grid/controls/columns dataGridActions @@ -83,10 +83,10 @@ - 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_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_invoice_grid.sales_order_view_invoice_grid.listing_top.bookmarks + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.bookmarks current.search @@ -98,13 +98,13 @@ dataGridFilters filters - sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.bookmarks + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.bookmarks current.filters - sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.listing_filters - sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.bookmarks:current.columns.${ $.index }.visible + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.bookmarks:current.columns.${ $.index }.visible @@ -115,7 +115,7 @@ increment_id Shipment - sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.listing_filters @@ -144,7 +144,7 @@ created_at Ship Date - sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.listing_filters @@ -175,7 +175,7 @@ order_increment_id Order - sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.listing_filters @@ -204,7 +204,7 @@ order_created_at Order Date - sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.listing_filters @@ -243,7 +243,7 @@ total_qty Total Quantity - sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.listing_filters @@ -358,7 +358,7 @@ - sales_order_view_invoice_grid.sales_order_view_invoice_grid.sales_order_shipment_columns.ids + sales_order_view_shipment_grid.sales_order_view_shipment_grid.sales_order_shipment_columns.ids bottom @@ -375,10 +375,10 @@ - sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.bookmarks + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.bookmarks current.paging - sales_order_view_invoice_grid.sales_order_view_invoice_grid.sales_order_shipment_columns.ids + sales_order_view_shipment_grid.sales_order_view_shipment_grid.sales_order_shipment_columns.ids bottom @@ -410,7 +410,7 @@ - sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.bookmarks + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.bookmarks current @@ -418,7 +418,7 @@ actions view - sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.bookmarks + sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.bookmarks columns.${ $.index } current.${ $.storageConfig.root} diff --git a/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php b/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php index bdd4e74ddd632..c948fcacdcd3d 100644 --- a/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php +++ b/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php @@ -97,7 +97,7 @@ public function __toString() $this->appendLayoutConfiguration(); $result = $this->compiler->postprocessing($this->template->__toString()); } catch (\Exception $e) { - $result = ''; + $result = $e->getMessage(); } return $result; } From 2fc99617d39adcfab2a419943e839b75b89de6d2 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Thu, 9 Jul 2015 20:46:03 +0300 Subject: [PATCH 10/73] MAGETWO-39905: UI components compatibility with Search API --- .../Model/Resource/Grid/Order/Collection.php | 7 +++++- app/code/Magento/Sales/etc/di.xml | 16 ++++++------- .../Ui/Component/Filters/Type/Input.php | 4 ++-- .../Ui/Component/Filters/Type/Search.php | 19 ++++++--------- .../Ui/TemplateEngine/Xhtml/Result.php | 15 ++++++++---- ...llectionPool.php => CollectionFactory.php} | 23 +++++++++++++------ .../UiComponent/DataProvider/Reporting.php | 12 +++++----- .../View/TemplateEngine/Xhtml/Template.php | 13 +++++++++-- 8 files changed, 67 insertions(+), 42 deletions(-) rename lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/{CollectionPool.php => CollectionFactory.php} (51%) diff --git a/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php b/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php index dc18d7795fcca..86016c9123830 100644 --- a/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php @@ -71,11 +71,16 @@ public function __construct( * Apply sorting and filtering to collection * * @return $this + * @throws \Exception */ protected function _initSelect() { parent::_initSelect(); - //$this->addFieldToFilter($this->_orderField, $this->registryManager->registry('current_order')->getId()); + $order = $this->registryManager->registry('current_order'); + if (!$order) { + throw new \Exception('Cannot perform operation without order filter'); + } + $this->addFieldToFilter($this->_orderField, $this->registryManager->registry('current_order')->getId()); return $this; } } diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index a4518a7d4549e..4b464da64e5f9 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -537,16 +537,16 @@ - + - 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\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 diff --git a/app/code/Magento/Ui/Component/Filters/Type/Input.php b/app/code/Magento/Ui/Component/Filters/Type/Input.php index 675ea24a528bb..35040ddbb0bfb 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Input.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Input.php @@ -75,9 +75,9 @@ protected function applyFilter() { $value = isset($this->filterData[$this->getName()]) ? $this->filterData[$this->getName()] : null; if ($value) { - $filter = $this->filterBuilder->setConditionType('eq') + $filter = $this->filterBuilder->setConditionType('like') ->setField($this->getName()) - ->setValue($value) + ->setValue(sprintf('%s%%', $value)) ->create(); $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 a58f273ecf9e3..2a3f3d402543b 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Search.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Search.php @@ -40,18 +40,13 @@ public function prepare() */ protected function applyFilter() { - $keyword = $this->getContext()->getRequestParam('search'); - if ($keyword) { - $value = isset($this->filterData[$this->getName()]) ? $this->filterData[$this->getName()] : null; - if ($value) { - $filter = $this->filterBuilder->setConditionType('fulltext') - ->setField($this->getName()) - ->setValue($value) - ->create(); - $this->getContext()->getDataProvider()->addFilter($filter); - } -// $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/TemplateEngine/Xhtml/Result.php b/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php index c948fcacdcd3d..c9a73f5eab7db 100644 --- a/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php +++ b/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php @@ -10,7 +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 +37,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,6 +103,7 @@ public function __toString() $this->appendLayoutConfiguration(); $result = $this->compiler->postprocessing($this->template->__toString()); } catch (\Exception $e) { + $this->logger->critical($e->getMessage()); $result = $e->getMessage(); } return $result; diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionPool.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionFactory.php similarity index 51% rename from lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionPool.php rename to lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionFactory.php index 16457778159f8..cf6592d4b7002 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionPool.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionFactory.php @@ -7,20 +7,29 @@ namespace Magento\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; +use Magento\Framework\ObjectManagerInterface; /** * Class CollectionPool */ -class CollectionPool +class CollectionFactory { /** * @var AbstractCollection[] */ protected $collections; - public function __construct(array $collections = []) - { + /** + * @var ObjectManagerInterface + */ + protected $objectManager; + + public function __construct( + ObjectManagerInterface $objectManagerInterface, + array $collections = [] + ) { $this->collections = $collections; + $this->objectManager = $objectManagerInterface; } /** @@ -28,11 +37,11 @@ public function __construct(array $collections = []) * @return AbstractCollection * @throws \Exception */ - public function getCollection($requestName) + public function getReport($requestName) { if (!isset($this->collections[$requestName])) { - throw new \Exception('111111'); + throw new \Exception(sprintf('Not registered handle %s', $requestName)); } - return $this->collections[$requestName]; + return $this->objectManager->create($this->collections[$requestName]); } -} \ No newline at end of file +} diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php index 9fefe7bd15452..f2a7db1c87c8e 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php @@ -16,9 +16,9 @@ class Reporting implements ReportingInterface { /** - * @var CollectionPool + * @var CollectionFactory */ - protected $collectionPool; + protected $collectionFactory; /** * @var array */ @@ -28,10 +28,10 @@ class Reporting implements ReportingInterface * @param array $appliers */ public function __construct( - CollectionPool $collectionPool, + CollectionFactory $collectionFactory, FilterPool $filterPool ) { - $this->collectionPool = $collectionPool; + $this->collectionFactory = $collectionFactory; $this->filterPool = $filterPool; } @@ -41,10 +41,10 @@ public function __construct( */ public function search(SearchCriteriaInterface $searchCriteria) { - $collection = $this->collectionPool->getCollection($searchCriteria->getRequestName()); + $collection = $this->collectionFactory->getReport($searchCriteria->getRequestName()); $collection->setPageSize($searchCriteria->getPageSize()); $collection->setCurPage($searchCriteria->getCurrentPage()); $this->filterPool->applyFilters($collection, $searchCriteria); return $collection; } -} \ No newline at end of file +} diff --git a/lib/internal/Magento/Framework/View/TemplateEngine/Xhtml/Template.php b/lib/internal/Magento/Framework/View/TemplateEngine/Xhtml/Template.php index 2ce37749a3d94..b6840fab7865b 100644 --- a/lib/internal/Magento/Framework/View/TemplateEngine/Xhtml/Template.php +++ b/lib/internal/Magento/Framework/View/TemplateEngine/Xhtml/Template.php @@ -14,6 +14,11 @@ class Template const XML_ENCODING = 'UTF-8'; + /** + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + /** * @var \DOMElement */ @@ -24,8 +29,11 @@ class Template * * @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 +73,7 @@ public function __toString() $this->templateNode->ownerDocument->normalizeDocument(); $result = $this->templateNode->ownerDocument->saveHTML(); } catch (\Exception $e) { + $this->logger->critical($e->getMessage()); $result = ''; } return $result; From 72e50975bf8d41b863fa689efb6b8b484045a5ba Mon Sep 17 00:00:00 2001 From: Dmytro Voskoboinikov Date: Fri, 10 Jul 2015 11:51:52 +0300 Subject: [PATCH 11/73] MAGETWO-39905: UI components compatibility with Search API --- .../Ui/Component/Filters/Type/Date.php | 48 ++++---------- .../Ui/Component/Filters/Type/DateRange.php | 56 +++++++--------- .../Ui/Component/Filters/Type/Input.php | 18 ++++-- .../Ui/Component/Filters/Type/Range.php | 64 ++++++------------- .../Ui/Component/Filters/Type/Select.php | 28 +++----- 5 files changed, 76 insertions(+), 138 deletions(-) diff --git a/app/code/Magento/Ui/Component/Filters/Type/Date.php b/app/code/Magento/Ui/Component/Filters/Type/Date.php index e38e2d056fbc6..9dfb4de93dd6a 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Date.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Date.php @@ -73,45 +73,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..a46cd3d648a5c 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/DateRange.php +++ b/app/code/Magento/Ui/Component/Filters/Type/DateRange.php @@ -59,45 +59,37 @@ 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 (isset($value['from'])) { + $this->applyFilterByType('gteq', $value['from']); + } + + if (isset($value['to'])) { + $this->applyFilterByType('lteq', $value['to']); + } } } /** - * Get condition by data type + * Apply filter by its type * - * @return array|null + * @param string $type + * @param string $value + * @return void */ - public function getCondition() + protected function applyFilterByType($type, $value) { - $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; - } + if (!empty($value)) { + $value = $this->wrappedComponent->convertDate($value); - return $value; + $filter = $this->filterBuilder->setConditionType($type) + ->setField($this->getName()) + ->setValue($value->format('Y-m-d H:i:s')) + ->create(); + + $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 675ea24a528bb..289a57c368e56 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Input.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Input.php @@ -73,13 +73,17 @@ public function prepare() */ protected function applyFilter() { - $value = isset($this->filterData[$this->getName()]) ? $this->filterData[$this->getName()] : null; - if ($value) { - $filter = $this->filterBuilder->setConditionType('eq') - ->setField($this->getName()) - ->setValue($value) - ->create(); - $this->getContext()->getDataProvider()->addFilter($filter); + if (isset($this->filterData[$this->getName()])) { + $value = $this->filterData[$this->getName()]; + + if (!empty($value)) { + $filter = $this->filterBuilder->setConditionType('eq') + ->setField($this->getName()) + ->setValue($value) + ->create(); + + $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..75ccdd6997ae3 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Range.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Range.php @@ -41,59 +41,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/Select.php b/app/code/Magento/Ui/Component/Filters/Type/Select.php index 7fce762d7afc0..20eb483746ab5 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Select.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Select.php @@ -103,25 +103,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 = ['eq' => $value]; - } + if (!empty($value) || is_numeric($value)) { + $filter = $this->filterBuilder->setConditionType('eq') + ->setField($this->getName()) + ->setValue($value) + ->create(); - return $condition; + $this->getContext()->getDataProvider()->addFilter($filter); + } + } } } From 722fc9489cc2b168065e5d2cddd2e8e706b32e62 Mon Sep 17 00:00:00 2001 From: Dmytro Voskoboinikov Date: Fri, 10 Jul 2015 14:13:31 +0300 Subject: [PATCH 12/73] MAGETWO-39905: UI components compatibility with Search API --- .../Sales/Model/Resource/Grid/Document.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/app/code/Magento/Sales/Model/Resource/Grid/Document.php b/app/code/Magento/Sales/Model/Resource/Grid/Document.php index 5fba4100f6c26..818d254668121 100644 --- a/app/code/Magento/Sales/Model/Resource/Grid/Document.php +++ b/app/code/Magento/Sales/Model/Resource/Grid/Document.php @@ -13,6 +13,12 @@ */ class Document extends Object implements DocumentInterface { + protected $attributeValueFactory; + public function __construct( + \Magento\Framework\Api\AttributeValueFactory $attributeValueFactory + ) { + $this->attributeValueFactory = $attributeValueFactory; + } protected $id; public function getId() @@ -24,4 +30,65 @@ 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->setValue($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; + } } From e35ea446cdc6a3e32e801a501a621947f9d24a4e Mon Sep 17 00:00:00 2001 From: Dmytro Voskoboinikov Date: Fri, 10 Jul 2015 15:07:51 +0300 Subject: [PATCH 13/73] MAGETWO-39905: UI components compatibility with Search API --- .../Sales/Model/Resource/Grid/Document.php | 24 +++++++++++- .../ui_component/sales_order_grid.xml | 2 +- .../Component/Filters/Type/AbstractFilter.php | 16 ++++++++ .../Ui/Component/Filters/Type/Date.php | 10 ----- .../Ui/Component/Filters/Type/DateRange.php | 37 +------------------ .../Ui/Component/Filters/Type/Input.php | 10 ----- .../Ui/Component/Filters/Type/Range.php | 10 ----- .../Ui/Component/Filters/Type/Search.php | 13 ++----- .../Ui/Component/Filters/Type/Select.php | 10 ----- 9 files changed, 45 insertions(+), 87 deletions(-) diff --git a/app/code/Magento/Sales/Model/Resource/Grid/Document.php b/app/code/Magento/Sales/Model/Resource/Grid/Document.php index 818d254668121..0dfaa89c33b4d 100644 --- a/app/code/Magento/Sales/Model/Resource/Grid/Document.php +++ b/app/code/Magento/Sales/Model/Resource/Grid/Document.php @@ -13,22 +13,44 @@ */ class Document extends Object implements DocumentInterface { + /** + * @var int + */ + protected $id; + + /** + * @var \Magento\Framework\Api\AttributeValueFactory + */ protected $attributeValueFactory; + + /** + * Constructor + * + * @param \Magento\Framework\Api\AttributeValueFactory $attributeValueFactory + */ public function __construct( \Magento\Framework\Api\AttributeValueFactory $attributeValueFactory ) { $this->attributeValueFactory = $attributeValueFactory; } - protected $id; + /** + * @return int + */ public function getId() { return $this->id; } + /** + * @param int $id + * @return $this + */ public function setId($id) { $this->id = $id; + + return $this; } /** 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 1082430c04189..59a0b7aa4f66e 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 @@ -143,7 +143,7 @@ created_at Purchase Date - cms_block_listing.cms_block_listing.listing_top.listing_filters + sales_order_grid.sales_order_grid.listing_top.listing_filters diff --git a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php index 3c2b4ac2cd901..ec321d9e133e4 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php +++ b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php @@ -9,11 +9,17 @@ 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 */ @@ -55,4 +61,14 @@ public function __construct( parent::__construct($context, $components, $data); $this->filterData = $this->getContext()->getRequestParam(static::FILTER_VAR); } + + /** + * 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 9dfb4de93dd6a..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 * diff --git a/app/code/Magento/Ui/Component/Filters/Type/DateRange.php b/app/code/Magento/Ui/Component/Filters/Type/DateRange.php index a46cd3d648a5c..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,33 +33,12 @@ public function prepare() static::COMPONENT, ['context' => $this->getContext()] ); - $this->wrappedComponent->prepare(); - $this->applyFilter(); + $this->wrappedComponent->prepare(); parent::prepare(); } - /** - * Apply filter - * - * @return void - */ - protected function applyFilter() - { - if (isset($this->filterData[$this->getName()])) { - $value = $this->filterData[$this->getName()]; - - if (isset($value['from'])) { - $this->applyFilterByType('gteq', $value['from']); - } - - if (isset($value['to'])) { - $this->applyFilterByType('lteq', $value['to']); - } - } - } - /** * Apply filter by its type * diff --git a/app/code/Magento/Ui/Component/Filters/Type/Input.php b/app/code/Magento/Ui/Component/Filters/Type/Input.php index a132fddefca09..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 * diff --git a/app/code/Magento/Ui/Component/Filters/Type/Range.php b/app/code/Magento/Ui/Component/Filters/Type/Range.php index 75ccdd6997ae3..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 * diff --git a/app/code/Magento/Ui/Component/Filters/Type/Search.php b/app/code/Magento/Ui/Component/Filters/Type/Search.php index 2a3f3d402543b..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 @@ -41,11 +32,13 @@ public function prepare() protected function applyFilter() { $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 20eb483746ab5..71ebcf6483796 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Select.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Select.php @@ -53,16 +53,6 @@ public function __construct( parent::__construct($context, $uiComponentFactory, $filterBuilder, $components, $data); } - /** - * Get component name - * - * @return string - */ - public function getComponentName() - { - return static::NAME; - } - /** * Prepare component configuration * From 05a51430a7d98abfadb799cdfbe8a778baa7e7a5 Mon Sep 17 00:00:00 2001 From: Sergey Ivashchenko Date: Fri, 10 Jul 2015 16:28:02 +0300 Subject: [PATCH 14/73] MAGETWO-39905: UI components compatibility with Search API --- .../Sales/Model/Resource/Grid/Document.php | 23 ++++++-- .../Model/Resource/Grid/Order/Collection.php | 18 +++--- .../ui_component/sales_order_invoice_grid.xml | 52 ++--------------- .../sales_order_shipment_grid.xml | 54 ++---------------- .../sales_order_view_creditmemo_grid.xml | 3 + .../sales_order_view_invoice_grid.xml | 55 +++--------------- .../sales_order_view_shipment_grid.xml | 57 +++---------------- app/etc/di.xml | 4 +- .../Api/Search/SearchCriteriaBuilder.php | 18 +++--- .../UiComponent/DataProvider/DataProvider.php | 52 ++++++++++++++--- 10 files changed, 115 insertions(+), 221 deletions(-) diff --git a/app/code/Magento/Sales/Model/Resource/Grid/Document.php b/app/code/Magento/Sales/Model/Resource/Grid/Document.php index 818d254668121..03ae875f5689c 100644 --- a/app/code/Magento/Sales/Model/Resource/Grid/Document.php +++ b/app/code/Magento/Sales/Model/Resource/Grid/Document.php @@ -7,25 +7,40 @@ use Magento\Framework\Api\Search\DocumentInterface; use Magento\Framework\Object; +use Magento\Framework\Api\AttributeValueFactory; /** * Class Document */ class Document extends Object implements DocumentInterface { + /** + * @var string|int + */ + protected $id; + + /** + * @var AttributeValueFactory + */ protected $attributeValueFactory; - public function __construct( - \Magento\Framework\Api\AttributeValueFactory $attributeValueFactory - ) { + + public function __construct(AttributeValueFactory $attributeValueFactory) + { $this->attributeValueFactory = $attributeValueFactory; } - protected $id; + /** + * @return int|string + */ public function getId() { return $this->id; } + /** + * @param int $id + * @return void + */ public function setId($id) { $this->id = $id; diff --git a/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php b/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php index 86016c9123830..8b9f9ad8bb721 100644 --- a/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Sales\Model\Resource\Grid\Order; +use Magento\Framework\App\RequestInterface; /** * Class Collection @@ -12,9 +13,9 @@ class Collection extends \Magento\Sales\Model\Resource\Grid\Collection { /** - * @var \Magento\Framework\Registry + * @var RequestInterface */ - protected $registryManager; + protected $request; /** * Order field for setOrderFilter @@ -28,7 +29,7 @@ class Collection extends \Magento\Sales\Model\Resource\Grid\Collection * @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 RequestInterface $request * @param null|\Zend_Db_Adapter_Abstract $mainTable * @param \Magento\Framework\Model\Resource\Db\AbstractDb $eventPrefix * @param string $eventObject @@ -42,7 +43,7 @@ public function __construct( \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Framework\Registry $registryManager, + RequestInterface $request, $mainTable, $eventPrefix, $eventObject, @@ -51,7 +52,7 @@ public function __construct( $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null ) { - $this->registryManager = $registryManager; + $this->request = $request; parent::__construct( $entityFactory, $logger, @@ -76,11 +77,10 @@ public function __construct( protected function _initSelect() { parent::_initSelect(); - $order = $this->registryManager->registry('current_order'); - if (!$order) { - throw new \Exception('Cannot perform operation without order filter'); + $order = $this->request->getParam('current_order'); + if ($order) { + $this->addFieldToFilter($this->_orderField, $order->getId()); } - $this->addFieldToFilter($this->_orderField, $this->registryManager->registry('current_order')->getId()); return $this; } } 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 1af1c10a4817c..994e19d1648f8 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 @@ -109,35 +109,14 @@ - + increment_id - Invoice - - sales_order_invoice_grid.sales_order_invoice_grid.listing_top.listing_filters - + Invoice # - - - - from - From - From - - - - - - - to - To - To - - - - + @@ -169,35 +148,14 @@ - + order_increment_id Order # - - sales_order_invoice_grid.sales_order_invoice_grid.listing_top.listing_filters - - - - - from - From - From - - - - - - - to - To - To - - - - + 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 250e59d56da97..38365d91499a7 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 @@ -109,35 +109,14 @@ - + increment_id - Shipment - - sales_order_shipment_grid.sales_order_shipment_grid.listing_top.listing_filters - + Shipment # - - - - from - From - From - - - - - - - to - To - To - - - - + @@ -169,35 +148,14 @@ - + order_increment_id - Order - - sales_order_shipment_grid.sales_order_shipment_grid.listing_top.listing_filters - + Order # - - - - from - From - From - - - - - - - to - To - To - - - - + 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 index feab933c6c87c..dd3d7f9e3b413 100644 --- 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 @@ -22,6 +22,9 @@ + + * + 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 index ceabd9fd5ccc0..26bb45ff375b3 100644 --- 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 @@ -22,6 +22,9 @@ + + * + @@ -109,35 +112,14 @@ - + increment_id - Invoice - - sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters - + Invoice # - - - - from - From - From - - - - - - - to - To - To - - - - + @@ -169,35 +151,14 @@ - + order_increment_id Order # - - sales_order_view_invoice_grid.sales_order_view_invoice_grid.listing_top.listing_filters - - - - - from - From - From - - - - - - - to - To - To - - - - + 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 index 2306b4faca06c..1a2d23fab74c3 100644 --- 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 @@ -22,6 +22,9 @@ + + * + @@ -109,35 +112,14 @@ - + increment_id - Shipment - - sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.listing_filters - + Shipment # - - - - from - From - From - - - - - - - to - To - To - - - - + @@ -169,35 +151,14 @@ - + order_increment_id - Order - - sales_order_view_shipment_grid.sales_order_view_shipment_grid.listing_top.listing_filters - + Order # - - - - from - From - From - - - - - - - to - To - To - - - - + diff --git a/app/etc/di.xml b/app/etc/di.xml index 18e52f6b117b2..eec0b35b80670 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -30,7 +30,7 @@ - + @@ -1131,4 +1131,6 @@ Magento\Framework\UrlInterface\Proxy + + diff --git a/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php b/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php index e81f2e4767029..9bd427aeceb36 100644 --- a/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php +++ b/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php @@ -18,26 +18,26 @@ class SearchCriteriaBuilder extends AbstractSimpleObjectBuilder { /** - * @var FilterGroupBuilder + * @var SortOrderBuilder */ - protected $_filterGroupBuilder; protected $sortOrderBuilder; + + /** + * @var FilterGroupBuilder + */ protected $filterGroupBuilder; - protected $searchGroup; + /** * @param ObjectFactory $objectFactory * @param FilterGroupBuilder $filterGroupBuilder + * @param SortOrderBuilder $sortOrderBuilder */ public function __construct( ObjectFactory $objectFactory, FilterGroupBuilder $filterGroupBuilder, - SortOrderBuilder $sortOrderBuilder, - FilterGroupBuilder $filterGroupBuilder + SortOrderBuilder $sortOrderBuilder ) { - parent::__construct( - $objectFactory - ); - $this->_filterGroupBuilder = $filterGroupBuilder; + parent::__construct($objectFactory); $this->sortOrderBuilder = $sortOrderBuilder; $this->filterGroupBuilder = $filterGroupBuilder; } 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 64db6b2fa2890..be717962dc2c2 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php @@ -6,7 +6,10 @@ namespace Magento\Framework\View\Element\UiComponent\DataProvider; +use Magento\Framework\Api\FilterBuilder; +use Magento\Framework\App\RequestInterface; use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection as Collection; +use Magento\Framework\Api\Search\SearchCriteriaBuilder; /** * Class DataProvider @@ -57,21 +60,26 @@ class DataProvider implements DataProviderInterface protected $reporting; /** - * @var + * @var FilterBuilder */ protected $filterBuilder; /** - * @var \Magento\Framework\Api\Search\SearchCriteriaBuilder + * @var SearchCriteriaBuilder */ protected $searchCriteriaBuilder; /** - * @param $name - * @param $primaryFieldName - * @param $requestFieldName - * @param Collection $collection - * @param FilterPool $filterPool + * @var RequestInterface + */ + protected $resuest; + + /** + * @param string $name + * @param string $primaryFieldName + * @param string $requestFieldName + * @param Reporting $reporting + * @param SearchCriteriaBuilder $searchCriteriaBuilder * @param array $meta * @param array $data */ @@ -80,10 +88,14 @@ public function __construct( $primaryFieldName, $requestFieldName, Reporting $reporting, - \Magento\Framework\Api\Search\SearchCriteriaBuilder $searchCriteriaBuilder, + SearchCriteriaBuilder $searchCriteriaBuilder, + RequestInterface $request, + FilterBuilder $filterBuilder, array $meta = [], array $data = [] ) { + $this->resuest = $request; + $this->filterBuilder = $filterBuilder; $this->name = $name; $this->primaryFieldName = $primaryFieldName; $this->requestFieldName = $requestFieldName; @@ -91,6 +103,30 @@ public function __construct( $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->meta = $meta; $this->data = $data; + $this->prepareUpdateUrl(); + } + + protected function prepareUpdateUrl() + { + if (!isset($this->data['config']['filter_url_params'])) { + return; + } + foreach ($this->data['config']['filter_url_params'] as $paramName => $paramValue) { + if ('*' == $paramValue) { + $paramValue = $this->resuest->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() + ); + } + } } /** From 5d1b1abeb1b3769f0f3d6ee175f9efd99e63eb0b Mon Sep 17 00:00:00 2001 From: Sergey Ivashchenko Date: Fri, 10 Jul 2015 16:36:21 +0300 Subject: [PATCH 15/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Ui/Component/Filters/Type/Select.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/Component/Filters/Type/Select.php b/app/code/Magento/Ui/Component/Filters/Type/Select.php index 71ebcf6483796..d8f771cb48c6c 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Select.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Select.php @@ -43,9 +43,8 @@ class Select extends AbstractFilter public function __construct( ContextInterface $context, UiComponentFactory $uiComponentFactory, - OptionSourceInterface $optionsProvider = null, \Magento\Framework\Api\FilterBuilder $filterBuilder, - + OptionSourceInterface $optionsProvider = null, array $components = [], array $data = [] ) { From 48aa225ff9c2cf4075bf056c31f8d32d3d345741 Mon Sep 17 00:00:00 2001 From: nsyvokonenko Date: Fri, 10 Jul 2015 18:06:17 +0300 Subject: [PATCH 16/73] MAGETWO-39905: UI components compatibility with Search API - CMS grids were changed --- .../Model/Resource/Block/Grid/Collection.php | 149 +++++++++++++++++ .../Model/Resource/Page/Grid/Collection.php | 151 ++++++++++++++++++ app/code/Magento/Cms/etc/di.xml | 24 +++ .../ui_component/cms_page_listing.xml | 2 +- 4 files changed, 325 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php create mode 100644 app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php 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..155d1b9362fa3 --- /dev/null +++ b/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php @@ -0,0 +1,149 @@ +_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; + } +} \ No newline at end of file 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..348338458b3b3 --- /dev/null +++ b/app/code/Magento/Cms/Model/Resource/Page/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, + $storeManager, + $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; + } +} \ No newline at end of file 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 06396855cc8ea..f346c5c0f4b28 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 From 83b8dcca346bde46ed6642ad050d9c91bc84dded Mon Sep 17 00:00:00 2001 From: Dmytro Voskoboinikov Date: Fri, 10 Jul 2015 19:23:07 +0300 Subject: [PATCH 17/73] MAGETWO-39905: UI components compatibility with Search API --- .../Sales/Block/Adminhtml/Order/Grid.php | 47 ------------------- .../UiComponent/DataProvider/DataProvider.php | 32 ++++++++----- .../DataProvider/DataProviderInterface.php | 5 +- .../UiComponent/DataProvider/Reporting.php | 5 +- 4 files changed, 23 insertions(+), 66 deletions(-) diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php index ca83df2fe053b..f3b8531f03bb6 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php @@ -12,51 +12,4 @@ */ class Grid extends \Magento\Backend\Block\Widget\Grid { - /** - * @var \Magento\Framework\View\Element\UiComponentFactory - */ - protected $componentFactory; - - /** - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Backend\Helper\Data $backendHelper - * @param \Magento\Framework\View\Element\UiComponentFactory $componentFactory - * @param array $data - */ - public function __construct( - \Magento\Backend\Block\Template\Context $context, - \Magento\Backend\Helper\Data $backendHelper, - \Magento\Framework\View\Element\UiComponentFactory $componentFactory, - array $data = [] - ) { - $this->componentFactory = $componentFactory; - parent::__construct($context, $backendHelper, $data); - } - - /** - * @return $this - * @throws \Magento\Framework\Exception\LocalizedException - */ - protected function _prepareCollection() - { - $component = $this->componentFactory->create('sales_order_grid'); - $this->prepareComponent($component); - $component->render(); - $collection = $component->getContext()->getDataProvider()->getCollection(); - $this->setData('dataSource', $collection); - - return parent::_prepareCollection(); - } - - /** - * @param \Magento\Framework\View\Element\UiComponentInterface $componentElement - * @return void - */ - protected function prepareComponent(\Magento\Framework\View\Element\UiComponentInterface $componentElement) - { - foreach ($componentElement->getChildComponents() as $childComponent) { - $this->prepareComponent($childComponent); - } - $componentElement->prepare(); - } } 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 64db6b2fa2890..95d54a6eafebb 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php @@ -6,7 +6,7 @@ namespace Magento\Framework\View\Element\UiComponent\DataProvider; -use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection as Collection; +use Magento\Framework\Api\Search\SearchCriteriaBuilder; /** * Class DataProvider @@ -34,11 +34,6 @@ class DataProvider implements DataProviderInterface */ protected $requestFieldName; - /** - * @var Collection - */ - protected $collection; - /** * @var array */ @@ -70,8 +65,8 @@ class DataProvider implements DataProviderInterface * @param $name * @param $primaryFieldName * @param $requestFieldName - * @param Collection $collection - * @param FilterPool $filterPool + * @param Reporting $reporting + * @param SearchCriteriaBuilder $searchCriteriaBuilder * @param array $meta * @param array $data */ @@ -80,25 +75,25 @@ public function __construct( $primaryFieldName, $requestFieldName, Reporting $reporting, - \Magento\Framework\Api\Search\SearchCriteriaBuilder $searchCriteriaBuilder, + SearchCriteriaBuilder $searchCriteriaBuilder, array $meta = [], array $data = [] ) { $this->name = $name; $this->primaryFieldName = $primaryFieldName; $this->requestFieldName = $requestFieldName; - $this->reporting= $reporting; + $this->reporting = $reporting; $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->meta = $meta; $this->data = $data; } /** - * @return Collection + * @return \Magento\Framework\Api\Search\SearchResultInterface */ public function getCollection() { - return $this->collection; + return $this->searchData(); } /** @@ -244,10 +239,21 @@ public function removeAllFields() * @return array */ public function getData() + { + return $this->searchData()->toArray(); + } + + /** + * Search data + * + * @return \Magento\Framework\Api\Search\SearchResultInterface + */ + protected function searchData() { $searchCriteria = $this->searchCriteriaBuilder->create(); $searchCriteria->setRequestName($this->name); - return $this->reporting->search($searchCriteria)->toArray(); + + return $this->reporting->search($searchCriteria); } /** 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 214b4e9c2ca24..7c6057b74dd9b 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php @@ -91,12 +91,9 @@ 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); /** diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php index f2a7db1c87c8e..417a156eca412 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php @@ -3,7 +3,6 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Api\Search\ReportingInterface; @@ -19,13 +18,15 @@ class Reporting implements ReportingInterface * @var CollectionFactory */ protected $collectionFactory; + /** * @var array */ protected $filterPool; /** - * @param array $appliers + * @param CollectionFactory $collectionFactory + * @param FilterPool $filterPool */ public function __construct( CollectionFactory $collectionFactory, From d1d23ef8541d0d4765f017dc7f93cab2c01f82e7 Mon Sep 17 00:00:00 2001 From: Dmytro Voskoboinikov Date: Fri, 10 Jul 2015 19:29:41 +0300 Subject: [PATCH 18/73] MAGETWO-39905: UI components compatibility with Search API --- .../View/Element/UiComponent/DataProvider/DataProvider.php | 1 - 1 file changed, 1 deletion(-) 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 2bda123b25dde..8a022d9ca1f5f 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php @@ -8,7 +8,6 @@ use Magento\Framework\Api\FilterBuilder; use Magento\Framework\App\RequestInterface; -use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection as Collection; use Magento\Framework\Api\Search\SearchCriteriaBuilder; /** From 97489c25d88c8498ef54a046c743ed04066aec9d Mon Sep 17 00:00:00 2001 From: Dmytro Voskoboinikov Date: Mon, 13 Jul 2015 15:34:32 +0300 Subject: [PATCH 19/73] MAGETWO-39905: UI components compatibility with Search API --- .../Sales/Block/Adminhtml/Order/Grid.php | 46 +++++++++++++++++++ .../UiComponent/DataProvider/DataProvider.php | 3 +- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php index f3b8531f03bb6..93462dcb02856 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php @@ -12,4 +12,50 @@ */ class Grid extends \Magento\Backend\Block\Widget\Grid { + /** + * @var \Magento\Framework\View\Element\UiComponentFactory + */ + protected $componentFactory; + + /** + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\Backend\Helper\Data $backendHelper + * @param \Magento\Framework\View\Element\UiComponentFactory $componentFactory + * @param array $data + */ + public function __construct( + \Magento\Backend\Block\Template\Context $context, + \Magento\Backend\Helper\Data $backendHelper, + \Magento\Framework\View\Element\UiComponentFactory $componentFactory, + array $data = [] + ) { + $this->componentFactory = $componentFactory; + parent::__construct($context, $backendHelper, $data); + } + + /** + * @return $this + * @throws \Magento\Framework\Exception\LocalizedException + */ + protected function _prepareCollection() + { + $component = $this->componentFactory->create('sales_order_grid'); + $this->prepareComponent($component); + $collection = $component->getContext()->getDataProvider()->getCollection(); + $this->setData('dataSource', $collection); + + return parent::_prepareCollection(); + } + + /** + * @param \Magento\Framework\View\Element\UiComponentInterface $componentElement + * @return void + */ + protected function prepareComponent(\Magento\Framework\View\Element\UiComponentInterface $componentElement) + { + foreach ($componentElement->getChildComponents() as $childComponent) { + $this->prepareComponent($childComponent); + } + $componentElement->prepare(); + } } 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 8a022d9ca1f5f..3f54e2ce105ca 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php @@ -3,7 +3,6 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Api\FilterBuilder; @@ -74,6 +73,8 @@ class DataProvider implements DataProviderInterface * @param string $requestFieldName * @param Reporting $reporting * @param SearchCriteriaBuilder $searchCriteriaBuilder + * @param RequestInterface $request + * @param FilterBuilder $filterBuilder * @param array $meta * @param array $data */ From bdbd2aab6919dc5e3f7f1da0de0d686abade2dfa Mon Sep 17 00:00:00 2001 From: Dmytro Voskoboinikov Date: Mon, 13 Jul 2015 18:46:11 +0300 Subject: [PATCH 20/73] MAGETWO-39905: UI components compatibility with Search API --- .../Magento/Sales/Block/Adminhtml/Order/Grid.php | 11 ++++++++++- app/code/Magento/Sales/etc/di.xml | 15 +++++++++++++++ .../layout/sales_creditmemo_grid_block.xml | 2 +- .../adminhtml/layout/sales_invoice_grid_block.xml | 2 +- .../layout/sales_shipment_grid_block.xml | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php index 93462dcb02856..92251a5a14a0b 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php @@ -12,6 +12,11 @@ */ class Grid extends \Magento\Backend\Block\Widget\Grid { + /** + * @var string + */ + protected $componentName; + /** * @var \Magento\Framework\View\Element\UiComponentFactory */ @@ -21,15 +26,19 @@ class Grid extends \Magento\Backend\Block\Widget\Grid * @param \Magento\Backend\Block\Template\Context $context * @param \Magento\Backend\Helper\Data $backendHelper * @param \Magento\Framework\View\Element\UiComponentFactory $componentFactory + * @param string $componentName * @param array $data */ public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Backend\Helper\Data $backendHelper, \Magento\Framework\View\Element\UiComponentFactory $componentFactory, + $componentName = 'sales_order_grid', array $data = [] ) { + $this->componentName = $componentName; $this->componentFactory = $componentFactory; + parent::__construct($context, $backendHelper, $data); } @@ -39,7 +48,7 @@ public function __construct( */ protected function _prepareCollection() { - $component = $this->componentFactory->create('sales_order_grid'); + $component = $this->componentFactory->create($this->componentName); $this->prepareComponent($component); $collection = $component->getContext()->getDataProvider()->getCollection(); $this->setData('dataSource', $collection); diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 4b464da64e5f9..df4d30575c8ad 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -611,4 +611,19 @@ Magento\Sales\Model\Resource\Order\Creditmemo + + + sales_order_invoice_grid + + + + + sales_order_shipment_grid + + + + + sales_order_creditmemo_grid + + 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 index e4cb20d646cbe..b1c52f72aa15a 100644 --- 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 @@ -8,7 +8,7 @@ - + sales_creditmemo_grid Magento\Sales\Model\Resource\Order\Creditmemo\Grid\Collection 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 index 2525c2c4c1430..f108bb6bbba93 100644 --- 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 @@ -8,7 +8,7 @@ - + sales_invoice_grid Magento\Sales\Model\Resource\Order\Invoice\Grid\Collection 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 index f8e567d12027e..0c392a2870afd 100644 --- 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 @@ -8,7 +8,7 @@ - + sales_shipment_grid Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection From 5d8334281c6da68bd43f58ff182fe26f5af9e48d Mon Sep 17 00:00:00 2001 From: Sergey Ivashchenko Date: Wed, 22 Jul 2015 15:27:15 +0300 Subject: [PATCH 21/73] MAGETWO-40131: New ui grids massactions ignore filters --- .../Product/AddStoreFieldToCollection.php | 1 + .../Product/ProductDataProvider.php | 10 -- .../Magento/Cms/Model/Block/DataProvider.php | 8 - .../Magento/Cms/Model/Page/DataProvider.php | 8 - .../Customer/Model/Customer/DataProvider.php | 8 - .../AbstractCreditmemo/Pdfcreditmemos.php | 5 +- .../Invoice/AbstractInvoice/Pdfinvoices.php | 55 +++--- .../Adminhtml/Order/AbstractMassAction.php | 47 +++-- .../Adminhtml/Order/Pdfcreditmemos.php | 92 ++++++---- .../Controller/Adminhtml/Order/Pdfdocs.php | 165 +++++++++++------- .../Adminhtml/Order/Pdfinvoices.php | 86 +++++---- .../Adminhtml/Order/Pdfshipments.php | 88 +++++++--- .../AbstractShipment/Pdfshipments.php | 48 +++-- .../Magento/Sales/Model/Order/Pdf/Invoice.php | 4 +- .../Sales/Model/Order/Pdf/Shipment.php | 2 +- .../Sales/Model/Resource/Order/Collection.php | 5 + .../Order/Collection/AbstractCollection.php | 2 +- .../Listing/Column/CustomerGroup.php | 8 +- .../sales_order_shipment_grid.xml | 5 + .../Order/Shipment/MassPrintShippingLabel.php | 87 ++++----- .../Shipment/MassPrintShippingLabel.php | 90 ++++++++++ .../Ui/Component/MassAction/Filter.php | 102 +++++++++++ .../Ui/DataProvider/AbstractDataProvider.php | 14 +- .../base/web/js/grid/columns/multiselect.js | 23 ++- .../Ui/view/base/web/js/grid/massactions.js | 4 +- .../UiComponent/DataProvider/DataProvider.php | 5 + .../DataProvider/DataProviderInterface.php | 7 + 27 files changed, 660 insertions(+), 319 deletions(-) create mode 100644 app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php create mode 100644 app/code/Magento/Ui/Component/MassAction/Filter.php 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..ea3635d1aba3a 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 * diff --git a/app/code/Magento/Cms/Model/Block/DataProvider.php b/app/code/Magento/Cms/Model/Block/DataProvider.php index a1aed9394efe9..47f2a14495569 100644 --- a/app/code/Magento/Cms/Model/Block/DataProvider.php +++ b/app/code/Magento/Cms/Model/Block/DataProvider.php @@ -47,14 +47,6 @@ public function __construct( $this->filterPool = $filterPool; } - /** - * @return \Magento\Cms\Model\Resource\Block\Collection - */ - protected function getCollection() - { - return $this->collection; - } - /** * @inheritdoc */ diff --git a/app/code/Magento/Cms/Model/Page/DataProvider.php b/app/code/Magento/Cms/Model/Page/DataProvider.php index f3d4d61303bd1..523c1c03d769e 100644 --- a/app/code/Magento/Cms/Model/Page/DataProvider.php +++ b/app/code/Magento/Cms/Model/Page/DataProvider.php @@ -48,14 +48,6 @@ public function __construct( $this->collection->setFirstStoreFlag(true); } - /** - * @return \Magento\Cms\Model\Resource\Page\Collection - */ - protected function getCollection() - { - return $this->collection; - } - /** * @inheritdoc */ diff --git a/app/code/Magento/Customer/Model/Customer/DataProvider.php b/app/code/Magento/Customer/Model/Customer/DataProvider.php index 23fe67286f29a..61fe81a21848a 100644 --- a/app/code/Magento/Customer/Model/Customer/DataProvider.php +++ b/app/code/Magento/Customer/Model/Customer/DataProvider.php @@ -108,14 +108,6 @@ public function __construct( ); } - /** - * @return Collection|\Magento\Framework\Model\Resource\Db\Collection\AbstractCollection - */ - protected function getCollection() - { - return $this->collection; - } - /** * @inheritdoc */ 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..589a2be5ba6f7 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php @@ -28,10 +28,11 @@ class Pdfcreditmemos extends \Magento\Sales\Controller\Adminhtml\Order\AbstractM */ public function __construct( \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + \Magento\Framework\App\Response\Http\FileFactory $fileFactory, + \Magento\Ui\Component\MassAction\Filter $filter ) { $this->_fileFactory = $fileFactory; - parent::__construct($context); + parent::__construct($context, $filter); } /** 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..90b60147fadf6 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,48 @@ 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\Collection as OrderCollection; 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 DateTime $dateTime + * @param FileFactory $fileFactory + * @param Filter $filter + * @param Invoice $pdfInvoice */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + Context $context, + DateTime $dateTime, + FileFactory $fileFactory, + Filter $filter, + Invoice $pdfInvoice ) { - $this->_fileFactory = $fileFactory; - parent::__construct($context); + $this->fileFactory = $fileFactory; + $this->dateTime = $dateTime; + $this->pdfInvoice = $pdfInvoice; + parent::__construct($context, $filter); } /** @@ -53,17 +70,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/Order/AbstractMassAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php index fe4f2aeb163b6..e8815b2eff326 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,24 @@ abstract class AbstractMassAction extends \Magento\Backend\App\Action { /** - * Field id + * @var string */ - const ID_FIELD = 'entity_id'; + protected $redirectUrl = 'sales/order/'; /** - * Redirect url + * @var \Magento\Ui\Component\MassAction\Filter */ - const REDIRECT_URL = 'sales/order/'; + protected $filter; /** - * Resource collection - * - * @var string + * @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 +45,22 @@ 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(); + 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); } /** * 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/Pdfcreditmemos.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php index 24d9f9d69a654..90bba02c60b70 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php @@ -8,47 +8,79 @@ 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 extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { + /** + * @var FileFactory + */ + protected $fileFactory; + + /** + * @var DateTime + */ + protected $dateTime; + + /** + * @var Creditmemo + */ + protected $pdfCreditmemo; + + /** + * @var CollectionFactory + */ + protected $collectionFactory; + + /** + * @param CollectionFactory $collectionFactory + * @param Context $context + * @param DateTime $dateTime + * @param FileFactory $fileFactory + * @param Filter $filter + * @param Creditmemo $pdfCreditmemo + */ + public function __construct( + CollectionFactory $collectionFactory, + Context $context, + DateTime $dateTime, + FileFactory $fileFactory, + Filter $filter, + 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('sales/*/'); } + 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..2d24cecc50d5e 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php @@ -8,7 +8,20 @@ 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\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 + */ class Pdfdocs extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { /** @@ -17,15 +30,73 @@ 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 FileFactory $fileFactory + * @param Filter $filter + * @param Invoice $pdfInvoice + * @param Shipment $pdfShipment + * @param Creditmemo $pdfCreditmemo + * @param DateTime $dateTime + * @param ShipmentCollectionFactory $shipmentCollectionFactory + * @param InvoiceCollectionFactory $invoiceCollectionFactory + * @param CreditmemoCollectionFactory $creditmemoCollectionFactory */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + Context $context, + FileFactory $fileFactory, + Filter $filter, + Invoice $pdfInvoice, + Shipment $pdfShipment, + Creditmemo $pdfCreditmemo, + DateTime $dateTime, + ShipmentCollectionFactory $shipmentCollectionFactory, + InvoiceCollectionFactory $invoiceCollectionFactory, + CreditmemoCollectionFactory $creditmemoCollectionFactory ) { + $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; + parent::__construct($context, $filter); } /** @@ -38,62 +109,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('sales/*/'); } + + $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..b871f79f24a32 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 CollectionFactory $collectionFactory + * @param Context $context + * @param DateTime $dateTime + * @param FileFactory $fileFactory + * @param Filter $filter + * @param Invoice $pdfInvoice */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + CollectionFactory $collectionFactory, + Context $context, + DateTime $dateTime, + FileFactory $fileFactory, + Filter $filter, + 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('sales/*/'); } + 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..a76076b70ee27 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php @@ -8,9 +8,59 @@ 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; +use Magento\Sales\Model\Resource\Order\Collection as OrderCollection; class Pdfshipments extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { + /** + * @var FileFactory + */ + protected $fileFactory; + + /** + * @var DateTime + */ + protected $dateTime; + + /** + * @var Shipment + */ + protected $pdfShipment; + + /** + * @var CollectionFactory + */ + protected $collectionFactory; + + /** + * @param CollectionFactory $collectionFactory + * @param Context $context + * @param DateTime $dateTime + * @param FileFactory $fileFactory + * @param Filter $filter + * @param Shipment $shipment + */ + public function __construct( + CollectionFactory $collectionFactory, + Context $context, + DateTime $dateTime, + FileFactory $fileFactory, + Filter $filter, + Shipment $shipment + ) { + $this->fileFactory = $fileFactory; + $this->dateTime = $dateTime; + $this->pdfShipment = $shipment; + $this->collectionFactory = $collectionFactory; + parent::__construct($context, $filter); + } + /** * Print shipments for selected orders * @@ -19,36 +69,16 @@ 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->collectionFactory->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('sales/*/'); } + 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/Shipment/AbstractShipment/Pdfshipments.php b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php index 8c0b9baa42114..b118da9c7a3b5 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,45 @@ 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; 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 DateTime $dateTime * @param FileFactory $fileFactory + * @param Filter $filter + * @param Shipment $shipment */ - public function __construct(Context $context, FileFactory $fileFactory) - { - $this->_fileFactory = $fileFactory; - parent::__construct($context); + public function __construct( + Context $context, + DateTime $dateTime, + FileFactory $fileFactory, + Filter $filter, + Shipment $shipment + ) { + $this->fileFactory = $fileFactory; + $this->dateTime = $dateTime; + $this->pdfShipment = $shipment; + parent::__construct($context, $filter); } /** @@ -50,16 +67,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/Model/Order/Pdf/Invoice.php b/app/code/Magento/Sales/Model/Order/Pdf/Invoice.php index a69597674acee..cb5fea88af59a 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 f630bf25543fe..2e7b5a0908d5c 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/Resource/Order/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Collection.php index 2e68417ba67ee..41274ccbe12c6 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/Ui/Component/Listing/Column/CustomerGroup.php b/app/code/Magento/Sales/Ui/Component/Listing/Column/CustomerGroup.php index d33d301d3311b..fe82f4d12a80d 100644 --- a/app/code/Magento/Sales/Ui/Component/Listing/Column/CustomerGroup.php +++ b/app/code/Magento/Sales/Ui/Component/Listing/Column/CustomerGroup.php @@ -50,8 +50,12 @@ public function prepareDataSource(array & $dataSource) { if (isset($dataSource['data']['items'])) { foreach ($dataSource['data']['items'] as & $item) { - $item[$this->getData('name')] = $this->groupRepository->getById($item[$this->getData('name')]) - ->getCode(); + try { + $item[$this->getData('name')] = $this->groupRepository->getById($item[$this->getData('name')]) + ->getCode(); + } catch (\Exception $e) { + + } } } } 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..ccf3cf41d7587 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 @@ -324,6 +324,11 @@ PDF Shipments sales/shipment/pdfshipments + + print_shipping_label + Print Shipping Labels + adminhtml/shipment/massPrintShippingLabel + entity_id 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..7cbfb67274da3 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,50 @@ 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\Order\Pdf\Shipment; +use Magento\Framework\Stdlib\DateTime\DateTime; +use Magento\Sales\Model\Resource\Order\Shipment\CollectionFactory; +use Magento\Sales\Model\Resource\Order\Collection as OrderCollection; +use Magento\Framework\Controller\ResultInterface; 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; + protected $fileFactory; /** - * @param Action\Context $context - * @param \Magento\Shipping\Model\Shipping\LabelGenerator $labelGenerator - * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @var CollectionFactory + */ + protected $collectionFactory; + + /** + * @param CollectionFactory $collectionFactory + * @param Context $context + * @param FileFactory $fileFactory + * @param Filter $filter */ public function __construct( - Action\Context $context, - \Magento\Shipping\Model\Shipping\LabelGenerator $labelGenerator, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory + CollectionFactory $collectionFactory, + Context $context, + FileFactory $fileFactory, + Filter $filter, + LabelGenerator $labelGenerator ) { + $this->fileFactory = $fileFactory; + $this->collectionFactory = $collectionFactory; $this->labelGenerator = $labelGenerator; - $this->_fileFactory = $fileFactory; - parent::__construct($context); + parent::__construct($context, $filter); } /** @@ -51,43 +69,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->collectionFactory->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 +88,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 +96,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..a13f0521ec16e --- /dev/null +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php @@ -0,0 +1,90 @@ +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/Ui/Component/MassAction/Filter.php b/app/code/Magento/Ui/Component/MassAction/Filter.php new file mode 100644 index 0000000000000..5530678eb2ddc --- /dev/null +++ b/app/code/Magento/Ui/Component/MassAction/Filter.php @@ -0,0 +1,102 @@ +factory = $factory; + $this->request = $request; + } + + /** + * @return AbstractCollection + * @throws LocalizedException + */ + public function getCollection() + { + $component = $this->factory->create($this->request->getParam('namespace')); + $this->prepareComponent($component); + + + $dataProvider = $component->getContext()->getDataProvider(); + + $dataProvider->getData(); + return $this->applySelection($dataProvider->getCollection()); + } + + /** + * @param AbstractCollection $collection + * @return AbstractCollection + * @throws LocalizedException + */ + protected function applySelection(AbstractCollection $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 + */ + protected function prepareComponent(UiComponentInterface $component) + { + foreach ($component->getChildComponents() as $child) { + $this->prepareComponent($child); + } + $component->prepare(); + } +} diff --git a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php index 74fc177fe1cfb..310e7773bd71a 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 * 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/massactions.js b/app/code/Magento/Ui/view/base/web/js/grid/massactions.js index b6ba29dfb9f43..5d80cf75321ba 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/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php index 12d7a1425850e..9a8b471916276 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php @@ -228,6 +228,11 @@ public function removeAllFields() $this->collection->removeAllFieldsFromSelect(); } + public function getFilters() + { + return $this->filterPool; + } + /** * Get data * 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..7f64852d78e77 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 */ @@ -138,4 +140,9 @@ public function removeAllFields(); * @return int */ public function count(); + + /** + * @return AbstractCollection + */ + public function getCollection(); } From adb0b810b84d5dc7493918b6b13e846f64ffbd75 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Wed, 22 Jul 2015 15:38:26 +0300 Subject: [PATCH 22/73] MAGETWO-39905: UI components compatibility with Search API --- .../Product/ProductDataProvider.php | 13 ++- .../Sales/Model/Resource/Grid/Document.php | 109 ------------------ app/code/Magento/Sales/etc/di.xml | 12 -- .../Ui/DataProvider/AbstractDataProvider.php | 7 +- .../UiComponent/DataProvider/Document.php | 90 ++++++++++++++- 5 files changed, 98 insertions(+), 133 deletions(-) delete mode 100644 app/code/Magento/Sales/Model/Resource/Grid/Document.php diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/ProductDataProvider.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/ProductDataProvider.php index c26416b4a2ac5..626b00f61d005 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/ProductDataProvider.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/ProductDataProvider.php @@ -104,12 +104,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/Sales/Model/Resource/Grid/Document.php b/app/code/Magento/Sales/Model/Resource/Grid/Document.php deleted file mode 100644 index 03ae875f5689c..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Grid/Document.php +++ /dev/null @@ -1,109 +0,0 @@ -attributeValueFactory = $attributeValueFactory; - } - - /** - * @return int|string - */ - public function getId() - { - 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->setValue($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/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 274035098ce65..c130e99af712a 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -567,48 +567,36 @@ sales_invoice_grid - sales_order_invoice_grid_collection - order_invoice_grid_collection Magento\Sales\Model\Resource\Order\Invoice sales_shipment_grid - sales_order_shipment_grid_collection - order_shipment_grid_collection Magento\Sales\Model\Resource\Order\Shipment sales_creditmemo_grid - sales_order_creditmemo_grid_collection - order_creditmemo_grid_collection Magento\Sales\Model\Resource\Order\Creditmemo sales_invoice_grid - sales_order_invoice_grid_collection - order_invoice_grid_collection Magento\Sales\Model\Resource\Order\Invoice sales_shipment_grid - sales_order_shipment_grid_collection - order_shipment_grid_collection Magento\Sales\Model\Resource\Order\Shipment sales_creditmemo_grid - sales_order_creditmemo_grid_collection - order_creditmemo_grid_collection Magento\Sales\Model\Resource\Order\Creditmemo diff --git a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php index 74fc177fe1cfb..da5b5290f4bd5 100644 --- a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php +++ b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php @@ -141,9 +141,12 @@ 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($field, $condition); + $this->getCollection()->addFieldToFilter( + $filter->getField(), + [$filter->getConditionType() => $filter->getValue()] + ); } /** diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php index 0bdc37cd0cf40..8bcf470c21e73 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php @@ -6,26 +6,104 @@ namespace Magento\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Api\Search\DocumentInterface; -use Magento\Framework\Api\AbstractSimpleObject; +use Magento\Framework\Object; +use Magento\Framework\Api\AttributeValueFactory; /** * Class Document */ -class Document extends AbstractSimpleObject implements DocumentInterface +class Document extends Object implements DocumentInterface { /** - * {@inheritdoc} + * @var string|int + */ + protected $id; + + /** + * @var AttributeValueFactory + */ + protected $attributeValueFactory; + + public function __construct(AttributeValueFactory $attributeValueFactory) + { + $this->attributeValueFactory = $attributeValueFactory; + } + + /** + * @return int|string */ public function getId() { - return $this->_get(self::ID); + return $this->id; } /** - * {@inheritdoc} + * @param int $id + * @return void */ public function setId($id) { - return $this->setData(self::ID, $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->setValue($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; } } From 62e0ea2f89c17dedda50e9ed8bcfbf2d61f53d64 Mon Sep 17 00:00:00 2001 From: Sergey Ivashchenko Date: Wed, 22 Jul 2015 15:59:43 +0300 Subject: [PATCH 23/73] MAGETWO-40131: New ui grids massactions ignore filters --- .../Adminhtml/Product/MassDelete.php | 66 +++----- .../Model/Resource/Product/Collection.php | 5 + .../Adminhtml/AbstractMassDelete.php | 145 ------------------ .../Adminhtml/AbstractMassStatus.php | 137 ----------------- .../Controller/Adminhtml/Block/MassDelete.php | 41 +++-- .../Controller/Adminhtml/Page/MassDelete.php | 41 +++-- .../Controller/Adminhtml/Page/MassDisable.php | 47 ++++-- .../Controller/Adminhtml/Page/MassEnable.php | 47 ++++-- .../Cms/Model/Resource/Block/Collection.php | 5 + .../Cms/Model/Resource/Page/Collection.php | 5 + 10 files changed, 156 insertions(+), 383 deletions(-) delete mode 100644 app/code/Magento/Cms/Controller/Adminhtml/AbstractMassDelete.php delete mode 100644 app/code/Magento/Cms/Controller/Adminhtml/AbstractMassStatus.php diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php index 4a312adfb6366..d070c9ec0cd30 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php @@ -6,69 +6,45 @@ */ 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; class MassDelete extends \Magento\Catalog\Controller\Adminhtml\Product { /** - * Field id + * @var Filter */ - const ID_FIELD = 'entity_id'; + protected $filter; /** - * Redirect url + * @param Context $context + * @param Filter $filter */ - const REDIRECT_URL = 'catalog/*/index'; - - /** - * Resource collection - * - * @var string - */ - protected $collection = 'Magento\Catalog\Model\Resource\Product\Collection'; + public function __construct( + Builder $productBuilder, + Context $context, + Filter $filter + ) { + $this->filter = $filter; + 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()); - } + $collection = $this->filter->getCollection(); - /** @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; foreach ($collection->getItems() as $product) { $product->delete(); - ++$count; } - $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.', $collection->getSize()) + ); + + 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 96b2597121705..bb84fc2056493 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/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..bf3e2a951576b 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Block/MassDelete.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Block/MassDelete.php @@ -6,29 +6,48 @@ */ 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; /** * 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 + * @param Context $context + * @param Filter $filter */ - protected $collection = 'Magento\Cms\Model\Resource\Block\Collection'; + public function __construct(Context $context, Filter $filter) + { + $this->filter = $filter; + 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(); + + 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..54666abf3c295 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDelete.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDelete.php @@ -5,29 +5,48 @@ */ 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; /** * 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 + * @param Context $context + * @param Filter $filter */ - protected $collection = 'Magento\Cms\Model\Resource\Page\Collection'; + public function __construct(Context $context, Filter $filter) + { + $this->filter = $filter; + 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(); + + 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..f47505ac2af8f 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php @@ -5,36 +5,49 @@ */ 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; /** * 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 + * @param Context $context + * @param Filter $filter */ - protected $collection = 'Magento\Cms\Model\Resource\Page\Collection'; + public function __construct(Context $context, Filter $filter) + { + $this->filter = $filter; + 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(); - /** - * Page disable status - * - * @var boolean - */ - protected $status = false; + 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..476272d1ea522 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassEnable.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassEnable.php @@ -5,36 +5,49 @@ */ 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; /** * 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 + * @param Context $context + * @param Filter $filter */ - protected $collection = 'Magento\Cms\Model\Resource\Page\Collection'; + public function __construct(Context $context, Filter $filter) + { + $this->filter = $filter; + 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(); - /** - * Page enable status - * - * @var boolean - */ - protected $status = true; + 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/Resource/Block/Collection.php b/app/code/Magento/Cms/Model/Resource/Block/Collection.php index 3898607f31ed8..15713d344c544 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/Page/Collection.php b/app/code/Magento/Cms/Model/Resource/Page/Collection.php index 2b8943acb57a5..0a4c456190e91 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 * From 38849a8f27e1a13fb8f16eec38bacf271746f7ba Mon Sep 17 00:00:00 2001 From: Sergey Ivashchenko Date: Wed, 22 Jul 2015 18:18:01 +0300 Subject: [PATCH 24/73] MAGETWO-40131: New ui grids massactions ignore filters --- .../Ui/DataProvider/Attributes.php | 2 +- .../Adminhtml/Order/AbstractMassAction.php | 2 +- .../Controller/Adminhtml/Order/MassUnhold.php | 2 ++ .../Resource/Order/Creditmemo/Collection.php | 5 +++++ .../Model/Resource/Order/Invoice/Collection.php | 5 +++++ .../Model/Resource/Order/Shipment/Collection.php | 5 +++++ .../Magento/Ui/Component/MassAction/Filter.php | 15 ++++++++------- .../UiComponent/DataProvider/DataProvider.php | 5 ----- 8 files changed, 27 insertions(+), 14 deletions(-) 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/Sales/Controller/Adminhtml/Order/AbstractMassAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php index e8815b2eff326..be2564459b7c6 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php @@ -20,7 +20,7 @@ abstract class AbstractMassAction extends \Magento\Backend\App\Action /** * @var string */ - protected $redirectUrl = 'sales/order/'; + protected $redirectUrl = '*/*/'; /** * @var \Magento\Ui\Component\MassAction\Filter diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php index 80107a9f4ad8e..7abce33db8fc5 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php @@ -19,7 +19,9 @@ protected function massAction(AbstractCollection $collection) { $countUnHoldOrder = 0; + /** @var \Magento\Sales\Model\Order $order */ foreach ($collection->getItems() as $order) { + $order->load($order->getId()); if (!$order->canUnhold()) { continue; } 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..531469a1b8391 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,11 @@ */ class Collection extends AbstractCollection implements CreditmemoSearchResultInterface { + /** + * @var + */ + protected $_idFieldName = 'entity_id'; + /** * Event prefix * 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..c952047a3b07e 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,11 @@ */ class Collection extends AbstractCollection implements InvoiceSearchResultInterface { + /** + * @var + */ + protected $_idFieldName = 'entity_id'; + /** * Event prefix * 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..6c419193b85ce 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 + */ + protected $_idFieldName = 'entity_id'; + /** * Event prefix * diff --git a/app/code/Magento/Ui/Component/MassAction/Filter.php b/app/code/Magento/Ui/Component/MassAction/Filter.php index 5530678eb2ddc..1b26ff0f3e5b1 100644 --- a/app/code/Magento/Ui/Component/MassAction/Filter.php +++ b/app/code/Magento/Ui/Component/MassAction/Filter.php @@ -9,7 +9,7 @@ use Magento\Framework\View\Element\UiComponentFactory; use Magento\Framework\App\RequestInterface; use Magento\Framework\View\Element\UiComponentInterface; -use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; +use Magento\Framework\Data\Collection\AbstractDb; /** * Class Filter @@ -43,7 +43,7 @@ public function __construct( } /** - * @return AbstractCollection + * @return AbstractDb * @throws LocalizedException */ public function getCollection() @@ -54,16 +54,17 @@ public function getCollection() $dataProvider = $component->getContext()->getDataProvider(); - $dataProvider->getData(); - return $this->applySelection($dataProvider->getCollection()); + $collection = $this->applySelection($dataProvider->getCollection()); + $data = $dataProvider->getData(); + return $collection; } /** - * @param AbstractCollection $collection - * @return AbstractCollection + * @param AbstractDb $collection + * @return AbstractDb * @throws LocalizedException */ - protected function applySelection(AbstractCollection $collection) + protected function applySelection(AbstractDb $collection) { $selected = $this->request->getParam(static::SELECTED_PARAM); $excluded = $this->request->getParam(static::EXCLUDED_PARAM); 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 9a8b471916276..12d7a1425850e 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php @@ -228,11 +228,6 @@ public function removeAllFields() $this->collection->removeAllFieldsFromSelect(); } - public function getFilters() - { - return $this->filterPool; - } - /** * Get data * From b40a2576c22421a5a9e2879194db72d0a8a7edcb Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Wed, 22 Jul 2015 18:35:47 +0300 Subject: [PATCH 25/73] MAGETWO-39905: UI components compatibility with Search API --- .../Model/Resource/Grid/Order/Collection.php | 86 ------------ .../Model/Resource/Order/Grid/Collection.php | 70 ---------- app/code/Magento/Sales/etc/di.xml | 18 ++- .../UiComponent/DataProvider/SearchResult.php | 125 +++++++++++++----- 4 files changed, 97 insertions(+), 202 deletions(-) delete mode 100644 app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php delete mode 100644 app/code/Magento/Sales/Model/Resource/Order/Grid/Collection.php diff --git a/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php b/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php deleted file mode 100644 index 8b9f9ad8bb721..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Grid/Order/Collection.php +++ /dev/null @@ -1,86 +0,0 @@ -request = $request; - parent::__construct( - $entityFactory, - $logger, - $fetchStrategy, - $eventManager, - $mainTable, - $eventPrefix, - $eventObject, - $resourceModel, - $model, - $connection, - $resource - ); - } - - /** - * Apply sorting and filtering to collection - * - * @return $this - * @throws \Exception - */ - protected function _initSelect() - { - parent::_initSelect(); - $order = $this->request->getParam('current_order'); - if ($order) { - $this->addFieldToFilter($this->_orderField, $order->getId()); - } - 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 f432fc191c910..0000000000000 --- a/app/code/Magento/Sales/Model/Resource/Order/Grid/Collection.php +++ /dev/null @@ -1,70 +0,0 @@ -getIsCustomerMode()) { - $this->_renderFilters(); - - $unionSelect = clone $this->getSelect(); - - $unionSelect->reset(\Zend_Db_Select::ORDER); - $unionSelect->reset(\Zend_Db_Select::LIMIT_COUNT); - $unionSelect->reset(\Zend_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/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index c130e99af712a..5489d2451a928 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -556,45 +556,43 @@ Magento\Framework\App\State\Proxy - + sales_order_grid - sales_order_grid_collection - order_grid_collection Magento\Sales\Model\Resource\Order - - + + sales_invoice_grid Magento\Sales\Model\Resource\Order\Invoice - + sales_shipment_grid Magento\Sales\Model\Resource\Order\Shipment - + sales_creditmemo_grid Magento\Sales\Model\Resource\Order\Creditmemo - + sales_invoice_grid Magento\Sales\Model\Resource\Order\Invoice - + sales_shipment_grid Magento\Sales\Model\Resource\Order\Shipment - + sales_creditmemo_grid Magento\Sales\Model\Resource\Order\Creditmemo diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php index c24f7c04b6f5f..b651455dada84 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php @@ -4,80 +4,133 @@ * See COPYING.txt for license details. */ -namespace Magento\Framework\Api\Search; - -use Magento\Framework\Api\AbstractSimpleObject; -use Magento\Framework\Api\SearchCriteriaInterface as BaseSearchCriteriaInterface; +namespace Magento\Framework\View\Element\UiComponent\DataProvider; +use Magento\Framework\Api; +use Magento\Framework\Model\Resource\Db\Collection\AbstractCollection; +use Magento\Framework\Event\ManagerInterface as EventManager; +use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy; +use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory; +use Psr\Log\LoggerInterface as Logger; /** - * Class SearchResult + * Class Collection + * Collection for order related documents to display grids on order view page */ -class SearchResult extends AbstractSimpleObject implements SearchResultInterface +class SearchResult extends AbstractCollection implements Api\Search\SearchResultInterface { /** - * {@inheritdoc} + * @var Api\Search\AggregationInterface */ - public function getAggregations() - { - return $this->_get(self::AGGREGATIONS); - } + protected $aggregations; + /** - * {@inheritdoc} + * @var Api\Search\SearchCriteriaInterface */ - public function setAggregations($aggregations) - { - return $this->setData(self::AGGREGATIONS, $aggregations); + protected $searchCriteria; + + /** + * @var int + */ + protected $totalCount; + + /** + * @param EntityFactory $entityFactory + * @param Logger $logger + * @param FetchStrategy $fetchStrategy + * @param EventManager $eventManager + * @param string $model + * @param $mainTable + * @param $resourceModel + */ + public function __construct( + EntityFactory $entityFactory, + Logger $logger, + FetchStrategy $fetchStrategy, + EventManager $eventManager, + $mainTable, + $resourceModel + ) { + $this->_init('Magento\Framework\View\Element\UiComponent\DataProvider\Document', $resourceModel); + $this->setMainTable($mainTable); + parent::__construct( + $entityFactory, + $logger, + $fetchStrategy, + $eventManager, + null, + null + ); } + /** - * {@inheritdoc} + * @return Api\Search\AggregationInterface */ - public function getItems() + public function getAggregations() { - return $this->_get(self::ITEMS); + return $this->aggregations; } + /** - * {@inheritdoc} + * @param Api\Search\AggregationInterface $aggregations + * @return $this */ - public function setItems(array $items = null) + public function setAggregations($aggregations) { - return $this->setData(self::ITEMS, $items); + $this->aggregations = $aggregations; } + /** - * Get search criteria. - * - * @return SearchCriteriaInterface + * @return Api\Search\SearchCriteriaInterface|null */ public function getSearchCriteria() { - return $this->_get(self::SEARCH_CRITERIA); + return $this->searchCriteria; } + /** - * Set search criteria. - * - * @param BaseSearchCriteriaInterface $searchCriteria + * @param Api\SearchCriteriaInterface $searchCriteria * @return $this */ - public function setSearchCriteria(BaseSearchCriteriaInterface $searchCriteria = null) + public function setSearchCriteria(Api\SearchCriteriaInterface $searchCriteria) { - return $this->setData(self::SEARCH_CRITERIA, $searchCriteria); + return $this; } + /** - * Get total count. - * * @return int */ public function getTotalCount() { - return $this->_get(self::TOTAL_COUNT); + if (!$this->totalCount) { + $this->totalCount = $this->getSize(); + } + return $this->totalCount; } + /** - * Set total count. - * * @param int $totalCount * @return $this */ public function setTotalCount($totalCount) { - return $this->setData(self::TOTAL_COUNT, $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; } } From 82a9b3e37998b9f6508d6e18cb3f11a1d154aa64 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Thu, 23 Jul 2015 11:24:27 +0300 Subject: [PATCH 26/73] MAGETWO-39905: UI components compatibility with Search API --- .../UiComponent/DataProvider/FulltextFilter.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 ec5b91fe9f005..760742faa5f40 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FulltextFilter.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FulltextFilter.php @@ -15,17 +15,17 @@ */ class FulltextFilter implements FilterApplierInterface { + /** * Returns list of columns from fulltext index (doesn't support more then one FTI per table) * - * @param DbResource $resource - * @param string $indexTable + * @param DbCollection $collection + * @param $indexTable * @return array - * @throws \Magento\Framework\Exception\LocalizedException */ - protected function getFulltextIndexColumns(DbResource $resource, $indexTable) + protected function getFulltextIndexColumns(DbCollection $collection, $indexTable) { - $indexes = $resource->getReadConnection()->getIndexList($indexTable); + $indexes = $collection->getConnection()->getIndexList($indexTable); foreach ($indexes as $index) { if (strtoupper($index['INDEX_TYPE']) == 'FULLTEXT') { return $index['COLUMNS_LIST']; @@ -43,7 +43,7 @@ protected function getFulltextIndexColumns(DbResource $resource, $indexTable) */ public function apply(DbCollection $collection, Filter $filter) { - $columns = $this->getFulltextIndexColumns($collection->getResource(), $collection->getMainTable()); + $columns = $this->getFulltextIndexColumns($collection, $collection->getMainTable()); if (!$columns) { return; } From bf0b48e1b083ebf67c3712ac6f8a9b64977b49bf Mon Sep 17 00:00:00 2001 From: Sergey Ivashchenko Date: Thu, 23 Jul 2015 12:22:54 +0300 Subject: [PATCH 27/73] MAGETWO-40131: New ui grids massactions ignore filters --- .../Adminhtml/Product/MassDelete.php | 3 + .../AbstractCreditmemo/Pdfcreditmemos.php | 55 +++++++++++-------- .../Controller/Adminhtml/Order/Pdfdocs.php | 3 + .../AbstractShipment/Pdfshipments.php | 4 +- .../Resource/Order/Creditmemo/Collection.php | 4 +- .../Resource/Order/Invoice/Collection.php | 4 +- .../Resource/Order/Shipment/Collection.php | 2 +- .../Order/Shipment/MassPrintShippingLabel.php | 1 + .../Shipment/MassPrintShippingLabel.php | 2 +- app/code/Magento/Shipping/composer.json | 1 + app/code/Magento/Shipping/etc/module.xml | 1 + 11 files changed, 51 insertions(+), 29 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php index d070c9ec0cd30..d7a27b4d15f87 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php @@ -14,11 +14,14 @@ class MassDelete extends \Magento\Catalog\Controller\Adminhtml\Product { /** + * Massactions filter + * * @var Filter */ protected $filter; /** + * @param Builder $productBuilder * @param Context $context * @param Filter $filter */ 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 589a2be5ba6f7..e9c8074dbe91e 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,47 @@ 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; 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 Creditmemo $pdfCreditmemo + * @param Filter $filter + * @param DateTime $dateTime + * @param FileFactory $fileFactory */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\App\Response\Http\FileFactory $fileFactory, - \Magento\Ui\Component\MassAction\Filter $filter + Context $context, + Creditmemo $pdfCreditmemo, + Filter $filter, + DateTime $dateTime, + FileFactory $fileFactory ) { - $this->_fileFactory = $fileFactory; + $this->pdfCreditmemo = $pdfCreditmemo; + $this->fileFactory = $fileFactory; + $this->dateTime = $dateTime; parent::__construct($context, $filter); } @@ -45,22 +61,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/Order/Pdfdocs.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php index 2d24cecc50d5e..b40c7a10f5fe2 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php @@ -21,6 +21,7 @@ /** * Class Pdfdocs + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Pdfdocs extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { @@ -75,6 +76,8 @@ class Pdfdocs extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassActi * @param ShipmentCollectionFactory $shipmentCollectionFactory * @param InvoiceCollectionFactory $invoiceCollectionFactory * @param CreditmemoCollectionFactory $creditmemoCollectionFactory + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( Context $context, 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 b118da9c7a3b5..fc7241dff1ca8 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php @@ -34,16 +34,16 @@ abstract class Pdfshipments extends \Magento\Sales\Controller\Adminhtml\Order\Ab /** * @param Context $context + * @param Filter $filter * @param DateTime $dateTime * @param FileFactory $fileFactory - * @param Filter $filter * @param Shipment $shipment */ public function __construct( Context $context, + Filter $filter, DateTime $dateTime, FileFactory $fileFactory, - Filter $filter, Shipment $shipment ) { $this->fileFactory = $fileFactory; 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 531469a1b8391..ca6a64f6ae482 100644 --- a/app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Order/Creditmemo/Collection.php @@ -16,7 +16,9 @@ class Collection extends AbstractCollection implements CreditmemoSearchResultInterface { /** - * @var + * Id field name + * + * @var string */ protected $_idFieldName = 'entity_id'; 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 c952047a3b07e..a8bb205da49af 100644 --- a/app/code/Magento/Sales/Model/Resource/Order/Invoice/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Order/Invoice/Collection.php @@ -16,7 +16,9 @@ class Collection extends AbstractCollection implements InvoiceSearchResultInterface { /** - * @var + * Id field name + * + * @var string */ protected $_idFieldName = 'entity_id'; 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 6c419193b85ce..63744b59dca9f 100644 --- a/app/code/Magento/Sales/Model/Resource/Order/Shipment/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Order/Shipment/Collection.php @@ -16,7 +16,7 @@ class Collection extends AbstractCollection implements ShipmentSearchResultInterface { /** - * @var + * @var string */ protected $_idFieldName = 'entity_id'; 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 7cbfb67274da3..318ce5b636108 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/MassPrintShippingLabel.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/MassPrintShippingLabel.php @@ -42,6 +42,7 @@ class MassPrintShippingLabel extends \Magento\Sales\Controller\Adminhtml\Order\A * @param Context $context * @param FileFactory $fileFactory * @param Filter $filter + * @param LabelGenerator $labelGenerator */ public function __construct( CollectionFactory $collectionFactory, diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php b/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php index a13f0521ec16e..2859b02d1e052 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php @@ -16,7 +16,6 @@ use Magento\Framework\App\Response\Http\FileFactory; use Magento\Framework\Controller\ResultInterface; - class MassPrintShippingLabel extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { /** @@ -33,6 +32,7 @@ class MassPrintShippingLabel extends \Magento\Sales\Controller\Adminhtml\Order\A * @param Context $context * @param FileFactory $fileFactory * @param Filter $filter + * @param LabelGenerator $labelGenerator */ public function __construct( Context $context, 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 @@ + From a8afd7f19cb7a26657cca1bd66720daf050cb164 Mon Sep 17 00:00:00 2001 From: Sergey Ivashchenko Date: Thu, 23 Jul 2015 19:03:32 +0300 Subject: [PATCH 28/73] MAGETWO-40131: New ui grids massactions ignore filters --- .../AbstractCreditmemo/Pdfcreditmemos.php | 8 +- .../Adminhtml/Order/Pdfcreditmemos.php | 4 + .../Adminhtml/Order/MassCancelTest.php | 92 ++++--------------- .../Adminhtml/Order/MassHoldTest.php | 57 ++++-------- .../Adminhtml/Order/MassUnholdTest.php | 57 ++++-------- .../Ui/Component/MassAction/Filter.php | 2 +- 6 files changed, 63 insertions(+), 157 deletions(-) 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 e9c8074dbe91e..a235dad8539b4 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php @@ -14,6 +14,10 @@ use Magento\Framework\App\Response\Http\FileFactory; use Magento\Ui\Component\MassAction\Filter; +/** + * Class Pdfcreditmemos + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class Pdfcreditmemos extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { /** @@ -33,15 +37,15 @@ class Pdfcreditmemos extends \Magento\Sales\Controller\Adminhtml\Order\AbstractM /** * @param Context $context - * @param Creditmemo $pdfCreditmemo * @param Filter $filter + * @param Creditmemo $pdfCreditmemo * @param DateTime $dateTime * @param FileFactory $fileFactory */ public function __construct( Context $context, - Creditmemo $pdfCreditmemo, Filter $filter, + Creditmemo $pdfCreditmemo, DateTime $dateTime, FileFactory $fileFactory ) { diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php index 90bba02c60b70..ca3afbece4d2a 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php @@ -17,6 +17,10 @@ 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 { /** 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 69b02f1522b24..cee52020a20f3 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 @@ -75,6 +75,11 @@ class MassCancelTest extends \PHPUnit_Framework_TestCase */ protected $orderCollectionMock; + /** + * @var \Magento\Ui\Component\MassAction\Filter|\PHPUnit_Framework_MockObject_MockObject + */ + protected $filterMock; + public function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); @@ -156,18 +161,22 @@ 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->filterMock = $this->getMock('Magento\Ui\Component\MassAction\Filter', [], [], '', false); + $this->filterMock->expects($this->once()) + ->method('getCollection') + ->willReturn($this->orderCollectionMock); $this->massAction = $objectManagerHelper->getObject( 'Magento\Sales\Controller\Adminhtml\Order\MassCancel', [ - 'context' => $this->contextMock + 'context' => $this->contextMock, + 'filter' => $this->filterMock ] ); } @@ -178,9 +187,6 @@ public function setUp() */ public function testExecuteTwoOrderCanceled() { - $selected = [1, 2]; - $countOrders = count($selected); - $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); @@ -188,26 +194,12 @@ public function testExecuteTwoOrderCanceled() ->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); $order1->expects($this->once()) ->method('canCancel') @@ -247,9 +239,6 @@ public function testExecuteTwoOrderCanceled() */ public function testExcludedOrderCannotBeCanceled() { - $excluded = [1, 2]; - $countOrders = count($excluded); - $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); @@ -257,23 +246,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]); @@ -302,49 +277,16 @@ public function testExcludedOrderCannotBeCanceled() $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->massAction->execute(); - } - /** * Order throws exception while canceling */ 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]); 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 bb25130c4171d..f98497e29ce95 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 @@ -75,6 +75,11 @@ class MassHoldTest extends \PHPUnit_Framework_TestCase */ protected $orderCollectionMock; + /** + * @var \Magento\Ui\Component\MassAction\Filter|\PHPUnit_Framework_MockObject_MockObject + */ + protected $filterMock; + public function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); @@ -163,19 +168,22 @@ public function setUp() ->method('getResultFactory') ->willReturn($resultFactoryMock); + $this->filterMock = $this->getMock('Magento\Ui\Component\MassAction\Filter', [], [], '', false); + $this->filterMock->expects($this->once()) + ->method('getCollection') + ->willReturn($this->orderCollectionMock); + $this->massAction = $objectManagerHelper->getObject( 'Magento\Sales\Controller\Adminhtml\Order\MassHold', [ 'context' => $this->contextMock, + 'filter' => $this->filterMock ] ); } public function testExecuteTwoOrdersPutOnHold() { - $selected = [1, 2]; - $countOrders = count($selected); - $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); @@ -183,26 +191,12 @@ public function testExecuteTwoOrdersPutOnHold() ->disableOriginalConstructor() ->getMock(); - $this->requestMock->expects($this->at(0)) - ->method('getParam') - ->with('selected') - ->willReturn($selected); + $orders = [$order1, $order2]; + $countOrders = count($orders); - $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); $order1->expects($this->once()) ->method('canHold') @@ -238,9 +232,6 @@ public function testExecuteTwoOrdersPutOnHold() public function testExecuteOneOrderCannotBePutOnHold() { - $excluded = [1, 2]; - $countOrders = count($excluded); - $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); @@ -248,26 +239,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 9b3175ab6d7e5..1f1f9ad20676c 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 @@ -75,6 +75,11 @@ class MassUnholdTest extends \PHPUnit_Framework_TestCase */ protected $orderCollectionMock; + /** + * @var \Magento\Ui\Component\MassAction\Filter|\PHPUnit_Framework_MockObject_MockObject + */ + protected $filterMock; + public function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); @@ -164,10 +169,16 @@ public function setUp() ->method('getResultFactory') ->willReturn($resultFactoryMock); + $this->filterMock = $this->getMock('Magento\Ui\Component\MassAction\Filter', [], [], '', false); + $this->filterMock->expects($this->once()) + ->method('getCollection') + ->willReturn($this->orderCollectionMock); + $this->massAction = $objectManagerHelper->getObject( 'Magento\Sales\Controller\Adminhtml\Order\MassUnhold', [ 'context' => $this->contextMock, + 'filter' => $this->filterMock ] ); } @@ -176,6 +187,7 @@ public function testExecuteTwoOrdersReleasedFromHold() { $selected = [1, 2]; $countOrders = count($selected); + $idFieldName = 'entity_id'; $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() @@ -184,26 +196,11 @@ 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\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); $order1->expects($this->once()) ->method('canUnhold') @@ -215,7 +212,7 @@ public function testExecuteTwoOrdersReleasedFromHold() $this->orderCollectionMock->expects($this->once()) ->method('count') - ->willReturn($countOrders); + ->willReturn(count($orders)); $order2->expects($this->once()) ->method('canUnhold') @@ -239,9 +236,6 @@ public function testExecuteTwoOrdersReleasedFromHold() public function testExecuteOneOrderWhereNotReleasedFromHold() { - $excluded = [1, 2]; - $countOrders = count($excluded); - $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); @@ -249,26 +243,11 @@ public function testExecuteOneOrderWhereNotReleasedFromHold() ->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]; - $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('canUnhold') @@ -276,7 +255,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/Ui/Component/MassAction/Filter.php b/app/code/Magento/Ui/Component/MassAction/Filter.php index 1b26ff0f3e5b1..2afe8ba76b3a0 100644 --- a/app/code/Magento/Ui/Component/MassAction/Filter.php +++ b/app/code/Magento/Ui/Component/MassAction/Filter.php @@ -55,7 +55,7 @@ public function getCollection() $dataProvider = $component->getContext()->getDataProvider(); $collection = $this->applySelection($dataProvider->getCollection()); - $data = $dataProvider->getData(); + $dataProvider->getData(); return $collection; } From 33d76272ee7fd593c24920db0656c9e05ac273d8 Mon Sep 17 00:00:00 2001 From: Sergey Ivashchenko Date: Fri, 24 Jul 2015 11:20:56 +0300 Subject: [PATCH 29/73] MAGETWO-40131: New ui grids massactions ignore filters --- .../Adminhtml/Product/MassDelete.php | 4 +- .../Invoice/AbstractInvoice/Pdfinvoices.php | 4 +- .../Adminhtml/Order/MassCancelTest.php | 45 ++++--------------- .../Adminhtml/Order/MassHoldTest.php | 35 ++------------- .../Adminhtml/Order/MassUnholdTest.php | 39 ++-------------- 5 files changed, 18 insertions(+), 109 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php index d7a27b4d15f87..4c13941384fc9 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php @@ -21,13 +21,13 @@ class MassDelete extends \Magento\Catalog\Controller\Adminhtml\Product protected $filter; /** - * @param Builder $productBuilder * @param Context $context + * @param Builder $productBuilder * @param Filter $filter */ public function __construct( - Builder $productBuilder, Context $context, + Builder $productBuilder, Filter $filter ) { $this->filter = $filter; 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 90b60147fadf6..e6d5457ce1b88 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php @@ -35,16 +35,16 @@ abstract class Pdfinvoices extends \Magento\Sales\Controller\Adminhtml\Order\Abs /** * @param Context $context + * @param Filter $filter * @param DateTime $dateTime * @param FileFactory $fileFactory - * @param Filter $filter * @param Invoice $pdfInvoice */ public function __construct( Context $context, + Filter $filter, DateTime $dateTime, FileFactory $fileFactory, - Filter $filter, Invoice $pdfInvoice ) { $this->fileFactory = $fileFactory; 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 cee52020a20f3..de0251c07fe3b 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 @@ -83,50 +83,21 @@ class MassCancelTest extends \PHPUnit_Framework_TestCase 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' - ], + $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', + [], [], '', 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->objectManagerMock = $this->getMock( - 'Magento\Framework\ObjectManager\ObjectManager', - ['create'], - [], - '', - false - ); - $this->messageManagerMock = $this->getMock( - 'Magento\Framework\Message\Manager', - ['addSuccess', 'addError'], [], '', false 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 f98497e29ce95..b92e60c26d338 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 @@ -83,38 +83,15 @@ class MassHoldTest extends \PHPUnit_Framework_TestCase 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( @@ -124,13 +101,7 @@ 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(); 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 1f1f9ad20676c..6999e325b2707 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 @@ -83,54 +83,25 @@ class MassUnholdTest extends \PHPUnit_Framework_TestCase 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( 'Magento\Framework\ObjectManager\ObjectManager', - ['create'], [], - '', - 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() @@ -185,10 +156,6 @@ public function setUp() public function testExecuteTwoOrdersReleasedFromHold() { - $selected = [1, 2]; - $countOrders = count($selected); - $idFieldName = 'entity_id'; - $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); From 0541fffc3c95cee59ba254e9cbffdc2ebe1dfb1a Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Fri, 24 Jul 2015 12:31:02 +0300 Subject: [PATCH 30/73] MAGETWO-39905: UI components compatibility with Search API --- .../Model/Resource/Block/Grid/Collection.php | 10 +-- .../Model/Resource/Page/Grid/Collection.php | 10 +-- app/code/Magento/Ui/Component/Form.php | 30 ++++++- app/code/Magento/Ui/Component/Listing.php | 5 +- .../UiComponent/DataProvider/DataProvider.php | 78 +++++-------------- .../DataProvider/DataProviderInterface.php | 32 -------- .../UiComponent/DataProvider/Document.php | 2 +- .../UiComponent/DataProvider/SearchResult.php | 2 +- 8 files changed, 60 insertions(+), 109 deletions(-) diff --git a/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php b/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php index 155d1b9362fa3..c0fa0f45f6fe9 100644 --- a/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php +++ b/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php @@ -42,14 +42,10 @@ public function __construct( $eventPrefix, $eventObject, $resourceModel, - $model = 'Magento\Framework\Api\Search\Document', + $model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document', $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null ) { - $this->_eventPrefix = $eventPrefix; - $this->_eventObject = $eventObject; - $this->_init($model, $resourceModel); - $this->setMainTable($mainTable); parent::__construct( $entityFactory, $logger, @@ -58,6 +54,10 @@ public function __construct( $connection, $resource ); + $this->_eventPrefix = $eventPrefix; + $this->_eventObject = $eventObject; + $this->_init($model, $resourceModel); + $this->setMainTable($mainTable); } /** diff --git a/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php b/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php index 348338458b3b3..c6c38c9402b5b 100644 --- a/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php +++ b/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php @@ -43,14 +43,10 @@ public function __construct( $eventPrefix, $eventObject, $resourceModel, - $model = 'Magento\Framework\Api\Search\Document', + $model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document', $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null ) { - $this->_eventPrefix = $eventPrefix; - $this->_eventObject = $eventObject; - $this->_init($model, $resourceModel); - $this->setMainTable($mainTable); parent::__construct( $entityFactory, $logger, @@ -60,6 +56,10 @@ public function __construct( $connection, $resource ); + $this->_eventPrefix = $eventPrefix; + $this->_eventObject = $eventObject; + $this->_init($model, $resourceModel); + $this->setMainTable($mainTable); } /** 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/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php index 3f54e2ce105ca..2f38b45a017f4 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php @@ -6,8 +6,9 @@ namespace Magento\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Api\FilterBuilder; -use Magento\Framework\App\RequestInterface; use Magento\Framework\Api\Search\SearchCriteriaBuilder; +use Magento\Framework\Api\Search\SearchResultInterface; +use Magento\Framework\App\RequestInterface; /** * Class DataProvider @@ -124,14 +125,6 @@ protected function prepareUpdateUrl() } } - /** - * @return \Magento\Framework\Api\Search\SearchResultInterface - */ - public function getCollection() - { - return $this->searchData(); - } - /** * Get Data Provider name * @@ -210,18 +203,6 @@ public function addFilter(\Magento\Framework\Api\Filter $filter) $this->searchCriteriaBuilder->addFilter($filter); } - /** - * Add field to select - * - * @param string|array $field - * @param string|null $alias - * @return void - */ - public function addField($field, $alias = null) - { -// $this->collection->addFieldToSelect($field, $alias); - } - /** * self::setOrder() alias * @@ -248,25 +229,23 @@ public function setLimit($offset, $size) } /** - * Removes field from select - * - * @param string|null $field - * @param bool $isAlias Alias identifier - * @return void - */ - public function removeField($field, $isAlias = false) - { -// $this->collection->removeFieldFromSelect($field, $isAlias); - } - - /** - * Removes all fields from select - * - * @return void + * @param SearchResultInterface $searchResult + * @return array */ - public function removeAllFields() + protected function searchResultToOutput(SearchResultInterface $searchResult) { -// $this->collection->removeAllFieldsFromSelect(); + $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; } /** @@ -275,31 +254,10 @@ public function removeAllFields() * @return array */ public function getData() - { - return $this->searchData()->toArray(); - } - - /** - * Search data - * - * @return \Magento\Framework\Api\Search\SearchResultInterface - */ - protected function searchData() { $searchCriteria = $this->searchCriteriaBuilder->create(); $searchCriteria->setRequestName($this->name); - - return $this->reporting->search($searchCriteria); - } - - /** - * Retrieve count of loaded items - * - * @return int - */ - public function count() - { - return 10; + return $this->searchResultToOutput($this->reporting->search($searchCriteria)); } /** 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 7c6057b74dd9b..e3533e69c1064 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php @@ -79,15 +79,6 @@ 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 * @@ -113,27 +104,4 @@ public function addOrder($field, $direction); * @return void */ public function setLimit($offset, $size); - - /** - * Removes field from select - * - * @param string|null $field - * @param bool $isAlias Alias identifier - * @return void - */ - public function removeField($field, $isAlias = false); - - /** - * Removes all fields from select - * - * @return void - */ - public function removeAllFields(); - - /** - * Retrieve count of loaded items - * - * @return int - */ - public function count(); } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php index 8bcf470c21e73..ac548b991d1a2 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php @@ -84,7 +84,7 @@ public function getCustomAttributes() $output = []; foreach ($this->getData() as $key => $value) { $attribute = $this->attributeValueFactory->create(); - $output[] = $attribute->setValue($key)->setValue($value); + $output[] = $attribute->setAttributeCode($key)->setValue($value); } return $output; } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php index b651455dada84..a041bf56466db 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php @@ -51,7 +51,6 @@ public function __construct( $resourceModel ) { $this->_init('Magento\Framework\View\Element\UiComponent\DataProvider\Document', $resourceModel); - $this->setMainTable($mainTable); parent::__construct( $entityFactory, $logger, @@ -60,6 +59,7 @@ public function __construct( null, null ); + $this->setMainTable($this->_resource->getTable($mainTable)); } /** From a8d0add3b5c5ea1c15930f75088c85b4dc17f864 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Fri, 24 Jul 2015 15:00:53 +0300 Subject: [PATCH 31/73] MAGETWO-39905: UI components compatibility with Search API --- .../Magento/Cms/Model/Block/DataProvider.php | 87 ------------------ .../Magento/Cms/Model/Page/DataProvider.php | 88 ------------------- .../Block/Adminhtml/Edit/Tab/Orders.php | 14 ++- .../Customer/Model/Customer/DataProvider.php | 20 ----- .../Adminhtml/Reorder/Renderer/Action.php | 3 +- app/code/Magento/Sales/Helper/Reorder.php | 21 +++-- 6 files changed, 22 insertions(+), 211 deletions(-) delete mode 100644 app/code/Magento/Cms/Model/Block/DataProvider.php delete mode 100644 app/code/Magento/Cms/Model/Page/DataProvider.php 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/Customer/Block/Adminhtml/Edit/Tab/Orders.php b/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Orders.php index 8387043fc1541..b06a0a0a5bd89 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/Model/Customer/DataProvider.php b/app/code/Magento/Customer/Model/Customer/DataProvider.php index 248306e129b36..fe079a26c01c1 100644 --- a/app/code/Magento/Customer/Model/Customer/DataProvider.php +++ b/app/code/Magento/Customer/Model/Customer/DataProvider.php @@ -116,14 +116,6 @@ protected function getCollection() return $this->collection; } - /** - * @inheritdoc - */ - public function addFilter(\Magento\Framework\Api\Filter $filter) - { - //@todo implement this method - } - /** * Get data * @@ -134,7 +126,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 +149,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/Sales/Block/Adminhtml/Reorder/Renderer/Action.php b/app/code/Magento/Sales/Block/Adminhtml/Reorder/Renderer/Action.php index 0e664f928847f..d1378860c611e 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,8 @@ public function __construct( public function render(\Magento\Framework\Object $row) { $this->_actions = []; - if ($this->_salesReorder->canReorder($row)) { + /** */ + if ($this->_salesReorder->canReorder($row->getCustomAttribute('entity_id'))) { $reorderAction = [ '@' => [ 'href' => $this->getUrl('sales/order_create/reorder', ['order_id' => $row->getId()]), diff --git a/app/code/Magento/Sales/Helper/Reorder.php b/app/code/Magento/Sales/Helper/Reorder.php index 56ee37c0e0891..ae4ab41c38b46 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,16 @@ public function isAllowed($store = null) } /** - * @param \Magento\Sales\Model\Order $order + * @param $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; From fc3830204c742e1c126e9aea61ef62fdf5214a1c Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Fri, 24 Jul 2015 15:47:36 +0300 Subject: [PATCH 32/73] MAGETWO-39905: UI components compatibility with Search API --- .../Magento/Sales/Block/Adminhtml/Reorder/Renderer/Action.php | 2 +- .../View/Element/UiComponent/DataProvider/Document.php | 3 +++ .../View/Element/UiComponent/DataProvider/SearchResult.php | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) 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 d1378860c611e..07b65563d80e4 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Reorder/Renderer/Action.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Reorder/Renderer/Action.php @@ -48,7 +48,7 @@ public function render(\Magento\Framework\Object $row) { $this->_actions = []; /** */ - if ($this->_salesReorder->canReorder($row->getCustomAttribute('entity_id'))) { + if ($this->_salesReorder->canReorder($row->getId())) { $reorderAction = [ '@' => [ 'href' => $this->getUrl('sales/order_create/reorder', ['order_id' => $row->getId()]), diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php index ac548b991d1a2..2700c3112af9f 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php @@ -34,6 +34,9 @@ public function __construct(AttributeValueFactory $attributeValueFactory) */ public function getId() { + if (!$this->id) { + $this->id = $this->getData($this->getIdFieldName()); + } return $this->id; } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php index a041bf56466db..c3c0d016b26ed 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php @@ -60,6 +60,7 @@ public function __construct( null ); $this->setMainTable($this->_resource->getTable($mainTable)); + $this->_setIdFieldName($this->getResource()->getIdFieldName()); } /** From b67f353329b9fd0de53845c2d836f5cde235f598 Mon Sep 17 00:00:00 2001 From: Sergey Ivashchenko Date: Fri, 24 Jul 2015 16:01:25 +0300 Subject: [PATCH 33/73] MAGETWO-40131: New ui grids massactions ignore filters --- .../Controller/Adminhtml/Product/MassDelete.php | 12 ++++++++++-- .../Controller/Adminhtml/Block/MassDelete.php | 11 +++++++++-- .../Controller/Adminhtml/Page/MassDelete.php | 11 +++++++++-- .../Controller/Adminhtml/Page/MassDisable.php | 11 +++++++++-- .../Controller/Adminhtml/Page/MassEnable.php | 11 +++++++++-- .../AbstractCreditmemo/Pdfcreditmemos.php | 5 ++++- .../Invoice/AbstractInvoice/Pdfinvoices.php | 6 ++++-- .../Adminhtml/Order/AbstractMassAction.php | 7 ++++++- .../Controller/Adminhtml/Order/MassCancel.php | 13 +++++++++++++ .../Controller/Adminhtml/Order/MassHold.php | 13 +++++++++++++ .../Controller/Adminhtml/Order/MassUnhold.php | 15 ++++++++++++++- .../Controller/Adminhtml/Order/Pdfdocs.php | 5 ++++- .../Controller/Adminhtml/Order/Pdfshipments.php | 16 ++++++++++------ .../Shipment/AbstractShipment/Pdfshipments.php | 5 ++++- .../Order/Shipment/MassPrintShippingLabel.php | 17 +++++++++++------ .../Shipment/MassPrintShippingLabel.php | 5 ++++- .../Magento/Ui/Component/MassAction/Filter.php | 16 ++++++++++++---- 17 files changed, 145 insertions(+), 34 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php index 4c13941384fc9..1a7d4baec4c4f 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php @@ -10,6 +10,7 @@ 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 { @@ -20,6 +21,11 @@ class MassDelete extends \Magento\Catalog\Controller\Adminhtml\Product */ protected $filter; + /** + * @var CollectionFactory + */ + protected $collectionFactory; + /** * @param Context $context * @param Builder $productBuilder @@ -28,9 +34,11 @@ class MassDelete extends \Magento\Catalog\Controller\Adminhtml\Product public function __construct( Context $context, Builder $productBuilder, - Filter $filter + Filter $filter, + CollectionFactory $collectionFactory ) { $this->filter = $filter; + $this->collectionFactory = $collectionFactory; parent::__construct($context, $productBuilder); } @@ -39,7 +47,7 @@ public function __construct( */ public function execute() { - $collection = $this->filter->getCollection(); + $collection = $this->filter->getCollection($this->collectionFactory->create()); foreach ($collection->getItems() as $product) { $product->delete(); diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Block/MassDelete.php b/app/code/Magento/Cms/Controller/Adminhtml/Block/MassDelete.php index bf3e2a951576b..d502f6ae96638 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Block/MassDelete.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Block/MassDelete.php @@ -9,6 +9,7 @@ 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 @@ -20,13 +21,19 @@ class MassDelete extends \Magento\Backend\App\Action */ protected $filter; + /** + * @var CollectionFactory + */ + protected $collectionFactory; + /** * @param Context $context * @param Filter $filter */ - public function __construct(Context $context, Filter $filter) + public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) { $this->filter = $filter; + $this->collectionFactory = $collectionFactory; parent::__construct($context); } @@ -38,7 +45,7 @@ public function __construct(Context $context, Filter $filter) */ public function execute() { - $collection = $this->filter->getCollection(); + $collection = $this->filter->getCollection($this->collectionFactory->create()); foreach ($collection as $item) { $item->delete(); diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDelete.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDelete.php index 54666abf3c295..03c3e9a79a225 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDelete.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDelete.php @@ -8,6 +8,7 @@ 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 @@ -19,13 +20,19 @@ class MassDelete extends \Magento\Backend\App\Action */ protected $filter; + /** + * @var CollectionFactory + */ + protected $collectionFactory; + /** * @param Context $context * @param Filter $filter */ - public function __construct(Context $context, Filter $filter) + public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) { $this->filter = $filter; + $this->collectionFactory = $collectionFactory; parent::__construct($context); } @@ -37,7 +44,7 @@ public function __construct(Context $context, Filter $filter) */ public function execute() { - $collection = $this->filter->getCollection(); + $collection = $this->filter->getCollection($this->collectionFactory->create()); foreach ($collection as $item) { $item->delete(); diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php index f47505ac2af8f..8cdd58baced6c 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php @@ -8,6 +8,7 @@ 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 @@ -19,13 +20,19 @@ class MassDisable extends \Magento\Backend\App\Action */ protected $filter; + /** + * @var CollectionFactory + */ + protected $collectionFactory; + /** * @param Context $context * @param Filter $filter */ - public function __construct(Context $context, Filter $filter) + public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) { $this->filter = $filter; + $this->collectionFactory = $collectionFactory; parent::__construct($context); } @@ -37,7 +44,7 @@ public function __construct(Context $context, Filter $filter) */ public function execute() { - $collection = $this->filter->getCollection(); + $collection = $this->filter->getCollection($this->collectionFactory->create()); foreach ($collection as $item) { $item->setIsActive(false); diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassEnable.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassEnable.php index 476272d1ea522..be925c94768f9 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassEnable.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassEnable.php @@ -8,6 +8,7 @@ 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 @@ -19,13 +20,19 @@ class MassEnable extends \Magento\Backend\App\Action */ protected $filter; + /** + * @var CollectionFactory + */ + protected $collectionFactory; + /** * @param Context $context * @param Filter $filter */ - public function __construct(Context $context, Filter $filter) + public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) { $this->filter = $filter; + $this->collectionFactory = $collectionFactory; parent::__construct($context); } @@ -37,7 +44,7 @@ public function __construct(Context $context, Filter $filter) */ public function execute() { - $collection = $this->filter->getCollection(); + $collection = $this->filter->getCollection($this->collectionFactory->create()); foreach ($collection as $item) { $item->setIsActive(true); 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 a235dad8539b4..f42578c29d405 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php @@ -13,6 +13,7 @@ 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 @@ -47,11 +48,13 @@ public function __construct( Filter $filter, Creditmemo $pdfCreditmemo, DateTime $dateTime, - FileFactory $fileFactory + FileFactory $fileFactory, + CollectionFactory $collectionFactory ) { $this->pdfCreditmemo = $pdfCreditmemo; $this->fileFactory = $fileFactory; $this->dateTime = $dateTime; + $this->collectionFactory = $collectionFactory; parent::__construct($context, $filter); } 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 e6d5457ce1b88..f320f23149736 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php @@ -14,7 +14,7 @@ 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\Collection as OrderCollection; +use Magento\Sales\Model\Resource\Order\Invoice\CollectionFactory; abstract class Pdfinvoices extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { @@ -45,11 +45,13 @@ public function __construct( Filter $filter, DateTime $dateTime, FileFactory $fileFactory, - Invoice $pdfInvoice + Invoice $pdfInvoice, + CollectionFactory $collectionFactory ) { $this->fileFactory = $fileFactory; $this->dateTime = $dateTime; $this->pdfInvoice = $pdfInvoice; + $this->collectionFactory = $collectionFactory; parent::__construct($context, $filter); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php index be2564459b7c6..71d39c60c43a6 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php @@ -27,6 +27,11 @@ abstract class AbstractMassAction extends \Magento\Backend\App\Action */ protected $filter; + /** + * @var object + */ + protected $collectionFactory; + /** * @param Context $context * @param Filter $filter @@ -46,7 +51,7 @@ public function __construct(Context $context, Filter $filter) public function execute() { try { - $collection = $this->filter->getCollection(); + $collection = $this->filter->getCollection($this->collectionFactory->create()); return $this->massAction($collection); } catch (\Exception $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 731363167b016..971581ac35bef 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php @@ -6,9 +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 MassCancel extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { + /** + * @param Context $context + * @param Filter $filter + */ + public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) + { + parent::__construct($context, $filter); + $this->collectionFactory = $collectionFactory; + } + /** * Cancel selected orders * diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php index c10ab68f62078..b5c3985d9d496 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php @@ -6,9 +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 MassHold extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { + /** + * @param Context $context + * @param Filter $filter + */ + public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) + { + parent::__construct($context, $filter); + $this->collectionFactory = $collectionFactory; + } + /** * Hold selected orders * diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php index 7abce33db8fc5..7390b579ce0f3 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php @@ -6,9 +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 { + /** + * @param Context $context + * @param Filter $filter + */ + public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) + { + parent::__construct($context, $filter); + $this->collectionFactory = $collectionFactory; + } + /** * Unhold selected orders * diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php index b40c7a10f5fe2..f6c91da08ea2e 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php @@ -15,6 +15,7 @@ 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; @@ -89,7 +90,8 @@ public function __construct( DateTime $dateTime, ShipmentCollectionFactory $shipmentCollectionFactory, InvoiceCollectionFactory $invoiceCollectionFactory, - CreditmemoCollectionFactory $creditmemoCollectionFactory + CreditmemoCollectionFactory $creditmemoCollectionFactory, + OrderCollectionFactory $orderCollectionFactory ) { $this->pdfInvoice = $pdfInvoice; $this->pdfShipment = $pdfShipment; @@ -99,6 +101,7 @@ public function __construct( $this->shipmentCollectionFactory = $shipmentCollectionFactory; $this->invoiceCollectionFactory = $invoiceCollectionFactory; $this->creditmemoCollectionFactory = $creditmemoCollectionFactory; + $this->collectionFactory = $orderCollectionFactory; parent::__construct($context, $filter); } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php index a76076b70ee27..4e3ac81d834e4 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php @@ -13,8 +13,8 @@ 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; -use Magento\Sales\Model\Resource\Order\Collection as OrderCollection; +use Magento\Sales\Model\Resource\Order\Shipment\CollectionFactory as ShipmentCollectionFactory; +use Magento\Sales\Model\Resource\Order\CollectionFactory; class Pdfshipments extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { @@ -34,9 +34,9 @@ class Pdfshipments extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMas protected $pdfShipment; /** - * @var CollectionFactory + * @var ShipmentCollectionFactory */ - protected $collectionFactory; + protected $shipmentCollectionFactotory; /** * @param CollectionFactory $collectionFactory @@ -52,12 +52,14 @@ public function __construct( DateTime $dateTime, FileFactory $fileFactory, Filter $filter, - Shipment $shipment + Shipment $shipment, + ShipmentCollectionFactory $shipmentCollectionFactory ) { $this->fileFactory = $fileFactory; $this->dateTime = $dateTime; $this->pdfShipment = $shipment; $this->collectionFactory = $collectionFactory; + $this->shipmentCollectionFactotory = $shipmentCollectionFactory; parent::__construct($context, $filter); } @@ -69,7 +71,9 @@ public function __construct( */ protected function massAction(AbstractCollection $collection) { - $shipmentsCollection = $this->collectionFactory->create()->setOrderFilter(['in' => $collection->getAllIds()]); + $shipmentsCollection = $this->shipmentCollectionFactotory + ->create() + ->setOrderFilter(['in' => $collection->getAllIds()]); if (!$shipmentsCollection->getSize()) { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); return $this->resultRedirectFactory->create()->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 fc7241dff1ca8..87186f2f2eb92 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php @@ -14,6 +14,7 @@ use Magento\Ui\Component\MassAction\Filter; use Magento\Sales\Model\Order\Pdf\Shipment; use Magento\Framework\Stdlib\DateTime\DateTime; +use Magento\Sales\Model\Resource\Shipment\CollectionFactory; abstract class Pdfshipments extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { @@ -44,11 +45,13 @@ public function __construct( Filter $filter, DateTime $dateTime, FileFactory $fileFactory, - Shipment $shipment + Shipment $shipment, + CollectionFactory $collectionFactory ) { $this->fileFactory = $fileFactory; $this->dateTime = $dateTime; $this->pdfShipment = $shipment; + $this->collectionFactory = $collectionFactory; parent::__construct($context, $filter); } 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 318ce5b636108..e61246895b6c2 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/MassPrintShippingLabel.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/MassPrintShippingLabel.php @@ -14,11 +14,9 @@ use Magento\Backend\App\Action\Context; use Magento\Shipping\Model\Shipping\LabelGenerator; use Magento\Framework\App\Response\Http\FileFactory; -use Magento\Sales\Model\Order\Pdf\Shipment; -use Magento\Framework\Stdlib\DateTime\DateTime; -use Magento\Sales\Model\Resource\Order\Shipment\CollectionFactory; -use Magento\Sales\Model\Resource\Order\Collection as OrderCollection; +use Magento\Sales\Model\Resource\Order\Shipment\CollectionFactory as ShipmentCollectionFactory; use Magento\Framework\Controller\ResultInterface; +use Magento\Sales\Model\Resource\Order\CollectionFactory; class MassPrintShippingLabel extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { @@ -37,6 +35,11 @@ class MassPrintShippingLabel extends \Magento\Sales\Controller\Adminhtml\Order\A */ protected $collectionFactory; + /** + * @var ShipmentCollectionFactory + */ + protected $shipmentCollectionFactory; + /** * @param CollectionFactory $collectionFactory * @param Context $context @@ -49,10 +52,12 @@ public function __construct( Context $context, FileFactory $fileFactory, Filter $filter, - LabelGenerator $labelGenerator + LabelGenerator $labelGenerator, + ShipmentCollectionFactory $shipmentCollectionFactory ) { $this->fileFactory = $fileFactory; $this->collectionFactory = $collectionFactory; + $this->shipmentCollectionFactory = $shipmentCollectionFactory; $this->labelGenerator = $labelGenerator; parent::__construct($context, $filter); } @@ -75,7 +80,7 @@ protected function _isAllowed() protected function massAction(AbstractCollection $collection) { $labelsContent = []; - $shipments = $this->collectionFactory->create()->setOrderFilter(['in' => $collection->getAllIds()]); + $shipments = $this->shipmentCollectionFactory->create()->setOrderFilter(['in' => $collection->getAllIds()]); if ($shipments->getSize()) { /** @var \Magento\Sales\Model\Order\Shipment $shipment */ diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php b/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php index 2859b02d1e052..73e3c4658e39c 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php @@ -15,6 +15,7 @@ use Magento\Shipping\Model\Shipping\LabelGenerator; use Magento\Framework\App\Response\Http\FileFactory; use Magento\Framework\Controller\ResultInterface; +use Magento\Sales\Model\Resource\Shipment\CollectionFactory; class MassPrintShippingLabel extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { @@ -38,8 +39,10 @@ public function __construct( Context $context, FileFactory $fileFactory, Filter $filter, - LabelGenerator $labelGenerator + LabelGenerator $labelGenerator, + CollectionFactory $collectionFactory ) { + $this->collectionFactory = $collectionFactory; $this->fileFactory = $fileFactory; $this->labelGenerator = $labelGenerator; parent::__construct($context, $filter); diff --git a/app/code/Magento/Ui/Component/MassAction/Filter.php b/app/code/Magento/Ui/Component/MassAction/Filter.php index 2afe8ba76b3a0..90316bbc53dc6 100644 --- a/app/code/Magento/Ui/Component/MassAction/Filter.php +++ b/app/code/Magento/Ui/Component/MassAction/Filter.php @@ -43,10 +43,11 @@ public function __construct( } /** + * @param AbstractDb $collection * @return AbstractDb * @throws LocalizedException */ - public function getCollection() + public function getCollection(AbstractDb $collection) { $component = $this->factory->create($this->request->getParam('namespace')); $this->prepareComponent($component); @@ -54,9 +55,16 @@ public function getCollection() $dataProvider = $component->getContext()->getDataProvider(); - $collection = $this->applySelection($dataProvider->getCollection()); - $dataProvider->getData(); - return $collection; + /** @var \Magento\Framework\Api\Search\SearchResultInterface $searchResult */ + $searchResult = $dataProvider->getData(); + + $ids = []; + foreach ($searchResult->getItems() as $document) { + $ids[] = $document->getId(); + } + + $collection->addFieldToFilter($collection->getIdFieldName(), ['in' => $ids]); + return $this->applySelection($collection); } /** From 252ca0617a7f014e1565276f83354bc9290a5494 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 27 Jul 2015 16:14:13 +0300 Subject: [PATCH 34/73] MAGETWO-39186: Error if change order id in order view url --- .../Adminhtml/Order/Create/Reorder.php | 2 +- app/code/Magento/Sales/etc/di.xml | 15 --------- .../frontend/templates/order/history.phtml | 2 +- .../templates/order/info/buttons.phtml | 2 +- .../frontend/templates/order/recent.phtml | 2 +- .../Ui/DataProvider/AbstractDataProvider.php | 10 ++++++ lib/internal/Magento/Framework/Api/Filter.php | 2 +- .../UiComponent/DataProvider/DataProvider.php | 32 +++++++++++++++---- .../DataProvider/DataProviderInterface.php | 7 ++++ 9 files changed, 47 insertions(+), 27 deletions(-) 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/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 5489d2451a928..335b7e14317ec 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -598,19 +598,4 @@ Magento\Sales\Model\Resource\Order\Creditmemo - - - sales_order_invoice_grid - - - - - sales_order_shipment_grid - - - - - sales_order_creditmemo_grid - - 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/Ui/DataProvider/AbstractDataProvider.php b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php index 0759c573e1d04..a081b895ebe3e 100644 --- a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php +++ b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php @@ -156,6 +156,16 @@ public function addFilter(\Magento\Framework\Api\Filter $filter) [$filter->getConditionType() => $filter->getValue()] ); } + /** + * Returns search criteria + * + * @return void + */ + public function getSearchCriteria() + { + //TODO: Technical dept, should be implemented as part of SearchAPI support for Catalog Grids + return null; + } /** * Add field to select 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/View/Element/UiComponent/DataProvider/DataProvider.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php index 2f38b45a017f4..d77de715e7bb4 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php @@ -6,6 +6,7 @@ namespace Magento\Framework\View\Element\UiComponent\DataProvider; 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; @@ -66,7 +67,12 @@ class DataProvider implements DataProviderInterface /** * @var RequestInterface */ - protected $resuest; + protected $request; + + /** + * @var SearchCriteria + */ + protected $searchCriteria; /** * @param string $name @@ -90,7 +96,7 @@ public function __construct( array $meta = [], array $data = [] ) { - $this->resuest = $request; + $this->request = $request; $this->filterBuilder = $filterBuilder; $this->name = $name; $this->primaryFieldName = $primaryFieldName; @@ -109,7 +115,7 @@ protected function prepareUpdateUrl() } foreach ($this->data['config']['filter_url_params'] as $paramName => $paramValue) { if ('*' == $paramValue) { - $paramValue = $this->resuest->getParam($paramName); + $paramValue = $this->request->getParam($paramName); } if ($paramValue) { $this->data['config']['update_url'] = sprintf( @@ -248,6 +254,20 @@ protected function searchResultToOutput(SearchResultInterface $searchResult) return $arrItems; } + /** + * Returns search criteria + * + * @return \Magento\Framework\Api\Search\SearchCriteria + */ + public function getSearchCriteria() + { + if (!$this->searchCriteria) { + $this->searchCriteria = $this->searchCriteriaBuilder->create(); + $this->searchCriteria->setRequestName($this->name); + } + return $this->searchCriteria; + } + /** * Get data * @@ -255,15 +275,13 @@ protected function searchResultToOutput(SearchResultInterface $searchResult) */ public function getData() { - $searchCriteria = $this->searchCriteriaBuilder->create(); - $searchCriteria->setRequestName($this->name); - return $this->searchResultToOutput($this->reporting->search($searchCriteria)); + return $this->searchResultToOutput($this->reporting->search($this->getSearchCriteria())); } /** * Get config data * - * @return mixed + * @return array */ public function getConfigData() { 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 d222bd05946c5..150f268373661 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php @@ -106,4 +106,11 @@ public function addOrder($field, $direction); * @return void */ public function setLimit($offset, $size); + + /** + * Returns search criteria + * + * @return \Magento\Framework\Api\Search\SearchCriteriaInterface + */ + public function getSearchCriteria(); } From c7ba4603e4c71ff19aaf2e82704fcebde1204afb Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 27 Jul 2015 17:27:41 +0300 Subject: [PATCH 35/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Ui/Component/MassAction/Filter.php | 8 +------- .../Ui/DataProvider/AbstractDataProvider.php | 13 ++++++++++++- .../UiComponent/DataProvider/DataProvider.php | 12 +++++++++++- .../DataProvider/DataProviderInterface.php | 5 +++++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Ui/Component/MassAction/Filter.php b/app/code/Magento/Ui/Component/MassAction/Filter.php index 90316bbc53dc6..fe321d194bfd7 100644 --- a/app/code/Magento/Ui/Component/MassAction/Filter.php +++ b/app/code/Magento/Ui/Component/MassAction/Filter.php @@ -51,15 +51,9 @@ public function getCollection(AbstractDb $collection) { $component = $this->factory->create($this->request->getParam('namespace')); $this->prepareComponent($component); - - $dataProvider = $component->getContext()->getDataProvider(); - - /** @var \Magento\Framework\Api\Search\SearchResultInterface $searchResult */ - $searchResult = $dataProvider->getData(); - $ids = []; - foreach ($searchResult->getItems() as $document) { + foreach ($dataProvider->getSearchResult()->getItems() as $document) { $ids[] = $document->getId(); } diff --git a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php index a081b895ebe3e..46deec35c0804 100644 --- a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php +++ b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php @@ -159,7 +159,7 @@ public function addFilter(\Magento\Framework\Api\Filter $filter) /** * Returns search criteria * - * @return void + * @return null */ public function getSearchCriteria() { @@ -167,6 +167,17 @@ public function getSearchCriteria() return null; } + /** + * Returns SearchResult + * + * @return null + */ + public function getSearchResult() + { + //TODO: Technical dept, should be implemented as part of SearchAPI support for Catalog Grids + return null; + } + /** * Add field to select * 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 d77de715e7bb4..35ea8a5dfc59d 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php @@ -275,7 +275,7 @@ public function getSearchCriteria() */ public function getData() { - return $this->searchResultToOutput($this->reporting->search($this->getSearchCriteria())); + return $this->searchResultToOutput($this->getSearchResult()); } /** @@ -298,4 +298,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 150f268373661..1b7e5c7f841f4 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProviderInterface.php @@ -113,4 +113,9 @@ public function setLimit($offset, $size); * @return \Magento\Framework\Api\Search\SearchCriteriaInterface */ public function getSearchCriteria(); + + /** + * @return \Magento\Framework\Api\Search\SearchResultInterface + */ + public function getSearchResult(); } From b8c995d4820732b6bd9a9e164a4226fefdbe1f57 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 27 Jul 2015 18:23:12 +0300 Subject: [PATCH 36/73] MAGETWO-39905: UI components compatibility with Search API --- .../Magento/Sales/Model/Resource/Grid.php | 6 +- .../Model/Resource/Order/Grid/Sql/Concat.php | 50 ----------- app/code/Magento/Sales/etc/di.xml | 43 +++++----- .../Magento/Framework/DB/ConcatExpression.php | 84 +++++++++++++++++++ 4 files changed, 113 insertions(+), 70 deletions(-) delete mode 100644 app/code/Magento/Sales/Model/Resource/Order/Grid/Sql/Concat.php create mode 100644 lib/internal/Magento/Framework/DB/ConcatExpression.php diff --git a/app/code/Magento/Sales/Model/Resource/Grid.php b/app/code/Magento/Sales/Model/Resource/Grid.php index afccd93b2e046..12d29e5d53780 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/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/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 335b7e14317ec..627ff893b3430 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -463,48 +463,53 @@ - + + sales_order - sales_order.customer_firstname - sales_order.customer_lastname + customer_firstname + customer_lastname - + + sales_shipping_address - sales_shipping_address.firstname - sales_shipping_address.lastname + firstname + lastname - + + sales_billing_address - sales_billing_address.firstname - sales_billing_address.lastname + firstname + lastname - + + sales_shipping_address - sales_shipping_address.street - sales_shipping_address.city - sales_shipping_address.region - sales_shipping_address.postcode + street + city + region + postcode , - + + sales_billing_address - sales_billing_address.street - sales_billing_address.city - sales_billing_address.region - sales_billing_address.postcode + street + city + region + postcode , diff --git a/lib/internal/Magento/Framework/DB/ConcatExpression.php b/lib/internal/Magento/Framework/DB/ConcatExpression.php new file mode 100644 index 0000000000000..abdab6a803f53 --- /dev/null +++ b/lib/internal/Magento/Framework/DB/ConcatExpression.php @@ -0,0 +1,84 @@ +resource = $resource; + $this->columns = $columns; + $this->tableName = $tableName; + $this->isTableAlias = $isTableAlias; + $this->separator = $separator; + } + + /** + * @return string + */ + public function __toString() + { + $columns = []; + $tableName = !$this->isTableAlias ? $this->resource->getTableName($this->tableName) : $this->tableName; + foreach ($this->columns as $key => $column) { + $columns[$key] = sprintf( + "ifnull(%s, '')", + $this->resource->getConnection(Resource::DEFAULT_READ_RESOURCE) + ->quoteIdentifier($tableName . '.' .$column) + ); + } + return sprintf( + 'trim(concat(%s))', + implode( + sprintf(", '%s' ,", $this->separator), + $columns + ) + ); + } +} From e42adfbf35f64c83ce9ca1b9e1943a93da35679f Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 27 Jul 2015 20:33:46 +0300 Subject: [PATCH 37/73] MAGETWO-39905: UI components compatibility with Search API --- .../Block/Adminhtml/Edit/Tab/View/Orders.php | 151 ------------------ .../layout/customer_index_lastorders.xml | 12 -- .../AbstractShipment/Pdfshipments.php | 2 +- .../Shipment/MassPrintShippingLabel.php | 2 +- 4 files changed, 2 insertions(+), 165 deletions(-) delete mode 100644 app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/View/Orders.php delete mode 100644 app/code/Magento/Customer/view/adminhtml/layout/customer_index_lastorders.xml 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/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/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php index 87186f2f2eb92..78c13ffce3c7a 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php @@ -14,7 +14,7 @@ use Magento\Ui\Component\MassAction\Filter; use Magento\Sales\Model\Order\Pdf\Shipment; use Magento\Framework\Stdlib\DateTime\DateTime; -use Magento\Sales\Model\Resource\Shipment\CollectionFactory; +use Magento\Sales\Model\Resource\Order\Shipment\CollectionFactory; abstract class Pdfshipments extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php b/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php index 73e3c4658e39c..af2afc9b89320 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php @@ -15,7 +15,7 @@ use Magento\Shipping\Model\Shipping\LabelGenerator; use Magento\Framework\App\Response\Http\FileFactory; use Magento\Framework\Controller\ResultInterface; -use Magento\Sales\Model\Resource\Shipment\CollectionFactory; +use Magento\Sales\Model\Resource\Order\Shipment\CollectionFactory; class MassPrintShippingLabel extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction { From d8b3675b464dfee6a0ee27af3f57863ec4abf15b Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 27 Jul 2015 20:55:06 +0300 Subject: [PATCH 38/73] MAGETWO-39905: UI components compatibility with Search API --- .../Sales/Block/Adminhtml/Order/Grid.php | 15 -- .../Unit/Block/Adminhtml/Order/GridTest.php | 81 ------- .../layout/sales_order_grid_block.xml | 206 ------------------ 3 files changed, 302 deletions(-) delete mode 100644 app/code/Magento/Sales/Block/Adminhtml/Order/Grid.php delete mode 100644 app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/GridTest.php delete mode 100644 app/code/Magento/Sales/view/adminhtml/layout/sales_order_grid_block.xml 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/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/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 - - - - - - - - - - From 676312c62657f8a8085d1fa9ec1078bac384ad82 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 27 Jul 2015 21:34:59 +0300 Subject: [PATCH 39/73] MAGETWO-39905: UI components compatibility with Search API --- .../Adminhtml/Order/MassCancelTest.php | 25 ++++++++++++---- .../Adminhtml/Order/MassHoldTest.php | 23 ++++++++++---- .../Adminhtml/Order/MassUnholdTest.php | 23 ++++++++++---- .../Sales/Test/Unit/Helper/ReorderTest.php | 30 +++++++++++++++---- .../Component/Filters/Type/DateRangeTest.php | 29 +++++++++++++++--- .../Unit/Component/Filters/Type/DateTest.php | 29 +++++++++++++++--- .../Unit/Component/Filters/Type/InputTest.php | 28 +++++++++++++++-- .../Unit/Component/Filters/Type/RangeTest.php | 27 +++++++++++++++-- .../Component/Filters/Type/SelectTest.php | 30 +++++++++++++++++-- 9 files changed, 206 insertions(+), 38 deletions(-) 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 de0251c07fe3b..f53bdc71e0e89 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,10 +71,15 @@ 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 \Magento\Sales\Model\Resource\Order\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderCollectionFactoryMock; + /** * @var \Magento\Ui\Component\MassAction\Filter|\PHPUnit_Framework_MockObject_MockObject */ @@ -107,6 +112,11 @@ public function setUp() ->disableOriginalConstructor() ->getMock(); + $this->orderCollectionFactoryMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\CollectionFactory') + ->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); @@ -141,13 +151,17 @@ public function setUp() $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, - 'filter' => $this->filterMock + 'filter' => $this->filterMock, + 'collectionFactory' => $this->orderCollectionFactoryMock ] ); } @@ -156,7 +170,7 @@ public function setUp() * Test for selected orders * Two orders, only $order1 can be canceled */ - public function testExecuteTwoOrderCanceled() + public function testExecuteCanCancelOneOrder() { $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() @@ -164,7 +178,6 @@ public function testExecuteTwoOrderCanceled() $order2 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() ->getMock(); - $orders = [$order1, $order2]; $countOrders = count($orders); @@ -208,7 +221,7 @@ public function testExecuteTwoOrderCanceled() * Test for excluded orders * Two orders could't be canceled */ - public function testExcludedOrderCannotBeCanceled() + public function testExcludedCannotCancelOrders() { $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() 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 b92e60c26d338..f1d4e88e3f597 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,10 +71,15 @@ 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 \Magento\Sales\Model\Resource\Order\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderCollectionFactoryMock; + /** * @var \Magento\Ui\Component\MassAction\Filter|\PHPUnit_Framework_MockObject_MockObject */ @@ -105,7 +110,10 @@ public function setUp() $this->orderCollectionMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\Collection') ->disableOriginalConstructor() ->getMock(); - + $this->orderCollectionFactoryMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\CollectionFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); $redirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') ->disableOriginalConstructor() ->getMock(); @@ -142,18 +150,23 @@ public function setUp() $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 + 'filter' => $this->filterMock, + 'collectionFactory' => $this->orderCollectionFactoryMock ] ); } - public function testExecuteTwoOrdersPutOnHold() + public function testExecuteOneOrderPutOnHold() { $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() @@ -201,7 +214,7 @@ public function testExecuteTwoOrdersPutOnHold() $this->massAction->execute(); } - public function testExecuteOneOrderCannotBePutOnHold() + public function testExecuteNoOrdersPutOnHold() { $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() 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 6999e325b2707..2f55e00c5bc11 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,10 +71,15 @@ 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 \Magento\Sales\Model\Resource\Order\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderCollectionFactoryMock; + /** * @var \Magento\Ui\Component\MassAction\Filter|\PHPUnit_Framework_MockObject_MockObject */ @@ -106,7 +111,10 @@ public function setUp() $this->orderCollectionMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\Collection') ->disableOriginalConstructor() ->getMock(); - + $this->orderCollectionFactoryMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\CollectionFactory') + ->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); @@ -143,18 +151,23 @@ public function setUp() $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 + 'filter' => $this->filterMock, + 'collectionFactory' => $this->orderCollectionFactoryMock ] ); } - public function testExecuteTwoOrdersReleasedFromHold() + public function testExecuteOneOrdersReleasedFromHold() { $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() @@ -201,7 +214,7 @@ public function testExecuteTwoOrdersReleasedFromHold() $this->massAction->execute(); } - public function testExecuteOneOrderWhereNotReleasedFromHold() + public function testExecuteNoReleasedOrderFromHold() { $order1 = $this->getMockBuilder('Magento\Sales\Model\Order') ->disableOriginalConstructor() 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/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(); } From 1ec6138bdf902cbe7c7c813bfcf37d1433cbfca9 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 27 Jul 2015 22:17:52 +0300 Subject: [PATCH 40/73] MAGETWO-39905: UI components compatibility with Search API --- lib/internal/Magento/Framework/DB/ConcatExpression.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/DB/ConcatExpression.php b/lib/internal/Magento/Framework/DB/ConcatExpression.php index abdab6a803f53..4e8c622cb1245 100644 --- a/lib/internal/Magento/Framework/DB/ConcatExpression.php +++ b/lib/internal/Magento/Framework/DB/ConcatExpression.php @@ -65,12 +65,11 @@ public function __construct( public function __toString() { $columns = []; - $tableName = !$this->isTableAlias ? $this->resource->getTableName($this->tableName) : $this->tableName; foreach ($this->columns as $key => $column) { $columns[$key] = sprintf( "ifnull(%s, '')", $this->resource->getConnection(Resource::DEFAULT_READ_RESOURCE) - ->quoteIdentifier($tableName . '.' .$column) + ->quoteIdentifier($this->tableName . '.' .$column) ); } return sprintf( From f93a95430b5bd9d73783e3d0611044c782376873 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 27 Jul 2015 22:38:32 +0300 Subject: [PATCH 41/73] MAGETWO-39905: UI components compatibility with Search API --- .../api-functional/testsuite/Magento/Search/Api/SearchTest.php | 2 ++ 1 file changed, 2 insertions(+) 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 ae6fd1cfc39eb..2715a71fed468 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' ] ] ] From a60d043982a1f7c7b5f533cfa09ea0b72bbb6997 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Tue, 28 Jul 2015 11:56:35 +0300 Subject: [PATCH 42/73] MAGETWO-39186: Error if change order id in order view url --- app/code/Magento/Sales/etc/di.xml | 13 +++- .../Framework/DB/Sql/ConcatExpression.php | 76 +++++++++++++++++++ 2 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 627ff893b3430..32e595735c860 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -463,12 +463,17 @@ - + - sales_order - customer_firstname - customer_lastname + + sales_order + customer_firstname + + + sales_order + customer_lastname + 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..623dcbe1abacd --- /dev/null +++ b/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php @@ -0,0 +1,76 @@ +adapter = $resource->getConnection(Resource::DEFAULT_READ_RESOURCE); + $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, ' ') + ); + } +} From 74761d09b93015884840c8f6fa1d9e86ff952d6f Mon Sep 17 00:00:00 2001 From: Michael Logvin Date: Tue, 28 Jul 2015 14:08:54 +0300 Subject: [PATCH 43/73] MAGETWO-39905: UI components compatibility with Search API --- .../Magento/Framework/Api/Search/ReportingInterface.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/internal/Magento/Framework/Api/Search/ReportingInterface.php b/lib/internal/Magento/Framework/Api/Search/ReportingInterface.php index 988c325326835..2a1869d2c94a0 100644 --- a/lib/internal/Magento/Framework/Api/Search/ReportingInterface.php +++ b/lib/internal/Magento/Framework/Api/Search/ReportingInterface.php @@ -1,11 +1,8 @@ Date: Tue, 28 Jul 2015 16:01:41 +0300 Subject: [PATCH 44/73] MAGETWO-39905: UI components compatibility with Search API --- .../Controller/Adminhtml/Product/MassDelete.php | 1 + .../Cms/Controller/Adminhtml/Block/MassDelete.php | 1 + .../Cms/Controller/Adminhtml/Page/MassDelete.php | 1 + .../Cms/Controller/Adminhtml/Page/MassDisable.php | 1 + .../Cms/Controller/Adminhtml/Page/MassEnable.php | 1 + .../Cms/Model/Resource/Block/Grid/Collection.php | 5 +++-- .../Cms/Model/Resource/Page/Grid/Collection.php | 14 ++++++++------ .../AbstractCreditmemo/Pdfcreditmemos.php | 1 + .../Invoice/AbstractInvoice/Pdfinvoices.php | 1 + .../Controller/Adminhtml/Order/MassCancel.php | 1 + .../Sales/Controller/Adminhtml/Order/MassHold.php | 1 + .../Controller/Adminhtml/Order/MassUnhold.php | 1 + .../Sales/Controller/Adminhtml/Order/Pdfdocs.php | 2 +- .../Controller/Adminhtml/Order/Pdfshipments.php | 5 +++++ .../Shipment/AbstractShipment/Pdfshipments.php | 1 + .../Sales/Model/Resource/Grid/Collection.php | 1 + .../Order/Shipment/MassPrintShippingLabel.php | 5 +++++ .../Adminhtml/Shipment/MassPrintShippingLabel.php | 1 + .../Ui/Component/Filters/Type/AbstractFilter.php | 2 +- .../Magento/Ui/Component/Filters/Type/Select.php | 5 ++--- .../Magento/Ui/TemplateEngine/Xhtml/Result.php | 1 + .../Framework/Api/Search/ReportingInterface.php | 2 +- .../Framework/Api/Search/SearchCriteriaBuilder.php | 7 +++---- .../Magento/Framework/DB/ConcatExpression.php | 3 +-- .../UiComponent/DataProvider/CollectionFactory.php | 8 ++++++-- .../UiComponent/DataProvider/DataProvider.php | 3 +++ .../Element/UiComponent/DataProvider/Document.php | 6 +++++- .../UiComponent/DataProvider/FilterPool.php | 2 ++ .../UiComponent/DataProvider/FulltextFilter.php | 2 +- .../UiComponent/DataProvider/RegularFilter.php | 1 + .../UiComponent/DataProvider/SearchResult.php | 3 ++- .../View/TemplateEngine/Xhtml/Template.php | 3 +-- 32 files changed, 65 insertions(+), 27 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php index 1a7d4baec4c4f..92cc11f159c93 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php @@ -30,6 +30,7 @@ class MassDelete extends \Magento\Catalog\Controller\Adminhtml\Product * @param Context $context * @param Builder $productBuilder * @param Filter $filter + * @param CollectionFactory $collectionFactory */ public function __construct( Context $context, diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Block/MassDelete.php b/app/code/Magento/Cms/Controller/Adminhtml/Block/MassDelete.php index d502f6ae96638..d9a8c044873cf 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Block/MassDelete.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Block/MassDelete.php @@ -29,6 +29,7 @@ class MassDelete extends \Magento\Backend\App\Action /** * @param Context $context * @param Filter $filter + * @param CollectionFactory $collectionFactory */ public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) { diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDelete.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDelete.php index 03c3e9a79a225..e5cfcf22966f5 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDelete.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDelete.php @@ -28,6 +28,7 @@ class MassDelete extends \Magento\Backend\App\Action /** * @param Context $context * @param Filter $filter + * @param CollectionFactory $collectionFactory */ public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) { diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php index 8cdd58baced6c..9f2ec91e4bd64 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php @@ -28,6 +28,7 @@ class MassDisable extends \Magento\Backend\App\Action /** * @param Context $context * @param Filter $filter + * @pram CollectionFactory $collectionFactory */ public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) { diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassEnable.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassEnable.php index be925c94768f9..fff1f58a5b1c0 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassEnable.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassEnable.php @@ -28,6 +28,7 @@ class MassEnable extends \Magento\Backend\App\Action /** * @param Context $context * @param Filter $filter + * @param CollectionFactory $collectionFactory */ public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) { diff --git a/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php b/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php index c0fa0f45f6fe9..427dbe5f1b67a 100644 --- a/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php +++ b/app/code/Magento/Cms/Model/Resource/Block/Grid/Collection.php @@ -31,7 +31,8 @@ class Collection extends BlockCollection implements SearchResultInterface * @param string $resourceModel * @param string $model * @param string|null $connection - * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource + * @param \Magento\Framework\Model\Resource\Db\AbstractDb|null $resource + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, @@ -146,4 +147,4 @@ public function setItems(array $items = null) { return $this; } -} \ No newline at end of file +} diff --git a/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php b/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php index c6c38c9402b5b..8e4e681c823cc 100644 --- a/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php +++ b/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php @@ -25,13 +25,15 @@ class Collection extends PageCollection implements SearchResultInterface * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param null|\Zend_Db_Adapter_Abstract $mainTable + * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param mixed|null $mainTable * @param \Magento\Framework\Model\Resource\Db\AbstractDb $eventPrefix - * @param string $eventObject - * @param string $resourceModel + * @param $eventObject + * @param $resourceModel * @param string $model - * @param string|null $connection - * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource + * @param null $connection + * @param \Magento\Framework\Model\Resource\Db\AbstractDb|null $resource + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, @@ -148,4 +150,4 @@ public function setItems(array $items = null) { return $this; } -} \ No newline at end of file +} 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 f42578c29d405..920be7c4c242a 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php @@ -42,6 +42,7 @@ class Pdfcreditmemos extends \Magento\Sales\Controller\Adminhtml\Order\AbstractM * @param Creditmemo $pdfCreditmemo * @param DateTime $dateTime * @param FileFactory $fileFactory + * @param CollectionFactory $collectionFactory */ public function __construct( Context $context, 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 f320f23149736..8753a3f8a4c15 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php @@ -39,6 +39,7 @@ abstract class Pdfinvoices extends \Magento\Sales\Controller\Adminhtml\Order\Abs * @param DateTime $dateTime * @param FileFactory $fileFactory * @param Invoice $pdfInvoice + * @param CollectionFactory $collectionFactory */ public function __construct( Context $context, diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php index 971581ac35bef..9b8300e8b21fe 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php @@ -15,6 +15,7 @@ class MassCancel extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassA /** * @param Context $context * @param Filter $filter + * @param CollectionFactory $collectionFactory */ public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) { diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php index b5c3985d9d496..95579da36edb9 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php @@ -15,6 +15,7 @@ class MassHold extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAct /** * @param Context $context * @param Filter $filter + * @param CollectionFactory $collectionFactory */ public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) { diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php index 7390b579ce0f3..55800f687e946 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php @@ -15,6 +15,7 @@ class MassUnhold extends AbstractMassAction /** * @param Context $context * @param Filter $filter + * @param CollectionFactory $collectionFactory */ public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) { diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php index f6c91da08ea2e..971a94a7269c0 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php @@ -77,7 +77,7 @@ class Pdfdocs extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassActi * @param ShipmentCollectionFactory $shipmentCollectionFactory * @param InvoiceCollectionFactory $invoiceCollectionFactory * @param CreditmemoCollectionFactory $creditmemoCollectionFactory - * + * @param OrderCollectionFactory $orderCollectionFactory * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php index 4e3ac81d834e4..e2bdfd0ed3023 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php @@ -16,6 +16,10 @@ 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 { /** @@ -45,6 +49,7 @@ class Pdfshipments extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMas * @param FileFactory $fileFactory * @param Filter $filter * @param Shipment $shipment + * @param ShipmentCollectionFactory $shipmentCollectionFactory */ public function __construct( CollectionFactory $collectionFactory, 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 78c13ffce3c7a..7a0ee9b827cc0 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php @@ -39,6 +39,7 @@ abstract class Pdfshipments extends \Magento\Sales\Controller\Adminhtml\Order\Ab * @param DateTime $dateTime * @param FileFactory $fileFactory * @param Shipment $shipment + * @param CollectionFactory $collectionFactory */ public function __construct( Context $context, diff --git a/app/code/Magento/Sales/Model/Resource/Grid/Collection.php b/app/code/Magento/Sales/Model/Resource/Grid/Collection.php index 32e49c7a6486e..57d2d31060dcf 100644 --- a/app/code/Magento/Sales/Model/Resource/Grid/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Grid/Collection.php @@ -33,6 +33,7 @@ class Collection extends AbstractCollection implements SearchResultInterface * @param string $model * @param string|null $connection * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, 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 e61246895b6c2..7d3a8da8fbeeb 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/MassPrintShippingLabel.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/MassPrintShippingLabel.php @@ -18,6 +18,10 @@ 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 { /** @@ -46,6 +50,7 @@ class MassPrintShippingLabel extends \Magento\Sales\Controller\Adminhtml\Order\A * @param FileFactory $fileFactory * @param Filter $filter * @param LabelGenerator $labelGenerator + * @param ShipmentCollectionFactory $shipmentCollectionFactory */ public function __construct( CollectionFactory $collectionFactory, diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php b/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php index af2afc9b89320..d1614161a192a 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php @@ -34,6 +34,7 @@ class MassPrintShippingLabel extends \Magento\Sales\Controller\Adminhtml\Order\A * @param FileFactory $fileFactory * @param Filter $filter * @param LabelGenerator $labelGenerator + * @param CollectionFactory $collectionFactory */ public function __construct( Context $context, diff --git a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php index c37a8a2e2c0f5..b4381a4dbecde 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php +++ b/app/code/Magento/Ui/Component/Filters/Type/AbstractFilter.php @@ -38,7 +38,7 @@ abstract class AbstractFilter extends AbstractComponent protected $uiComponentFactory; /** - * @var + * @var \Magento\Framework\Api\FilterBuilder */ protected $filterBuilder; diff --git a/app/code/Magento/Ui/Component/Filters/Type/Select.php b/app/code/Magento/Ui/Component/Filters/Type/Select.php index d8f771cb48c6c..06d53562a5c74 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Select.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Select.php @@ -32,11 +32,10 @@ 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 */ diff --git a/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php b/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php index c9a73f5eab7db..8060896296318 100644 --- a/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php +++ b/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php @@ -11,6 +11,7 @@ use Magento\Framework\View\TemplateEngine\Xhtml\ResultInterface; use Magento\Framework\View\TemplateEngine\Xhtml\CompilerInterface; use Psr\Log\LoggerInterface; + /** * Class Result */ diff --git a/lib/internal/Magento/Framework/Api/Search/ReportingInterface.php b/lib/internal/Magento/Framework/Api/Search/ReportingInterface.php index 2a1869d2c94a0..8f618598d9699 100644 --- a/lib/internal/Magento/Framework/Api/Search/ReportingInterface.php +++ b/lib/internal/Magento/Framework/Api/Search/ReportingInterface.php @@ -15,4 +15,4 @@ interface ReportingInterface * @return SearchResultInterface */ public function search(SearchCriteriaInterface $searchCriteria); -} \ No newline at end of file +} diff --git a/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php b/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php index 9bd427aeceb36..dbf5d56032a3d 100644 --- a/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php +++ b/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php @@ -10,7 +10,6 @@ use Magento\Framework\Api\ObjectFactory; use Magento\Framework\Api\SortOrder; use Magento\Framework\Api\SortOrderBuilder; -//use Magento\Framework\Api\Search\FilterGroupBuilder; /** * Builder for SearchCriteria Service Data Object @@ -57,7 +56,7 @@ public function create() /** * Create a filter group based on the filter array provided and add to the filter groups * - * @param \Magento\Framework\Api\Filter[] $filter + * @param \Magento\Framework\Api\Filter $filter * @return $this */ public function addFilter(\Magento\Framework\Api\Filter $filter) @@ -67,8 +66,8 @@ public function addFilter(\Magento\Framework\Api\Filter $filter) } /** - * @param $field - * @param $direction + * @param string $field + * @param string $direction * @return $this */ public function addSortOrder($field, $direction) diff --git a/lib/internal/Magento/Framework/DB/ConcatExpression.php b/lib/internal/Magento/Framework/DB/ConcatExpression.php index 4e8c622cb1245..12ce1eb50cacc 100644 --- a/lib/internal/Magento/Framework/DB/ConcatExpression.php +++ b/lib/internal/Magento/Framework/DB/ConcatExpression.php @@ -6,7 +6,6 @@ namespace Magento\Framework\DB; use Magento\Framework\App\Resource; -use Magento\Framework\DB\Adapter\AdapterInterface; /** * Class Concat @@ -41,7 +40,7 @@ class ConcatExpression extends \Zend_Db_Expr /** * @param \Magento\Framework\App\Resource $resource * @param array $columns - * @param $tableName + * @param string $tableName * @param bool|false $isTableAlias * @param string $separator */ diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionFactory.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionFactory.php index cf6592d4b7002..19926466e4637 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionFactory.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/CollectionFactory.php @@ -24,16 +24,20 @@ class CollectionFactory */ protected $objectManager; + /** + * @param ObjectManagerInterface $objectManagerInterface + * @param array $collections + */ public function __construct( ObjectManagerInterface $objectManagerInterface, - array $collections = [] + array $collections = [] ) { $this->collections = $collections; $this->objectManager = $objectManagerInterface; } /** - * @param $requestName + * @param string $requestName * @return AbstractCollection * @throws \Exception */ 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 35ea8a5dfc59d..a006b56628d6d 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/DataProvider.php @@ -108,6 +108,9 @@ public function __construct( $this->prepareUpdateUrl(); } + /** + * @return void + */ protected function prepareUpdateUrl() { if (!isset($this->data['config']['filter_url_params'])) { diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php index 2700c3112af9f..cf72a130467dd 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php @@ -24,6 +24,9 @@ class Document extends Object implements DocumentInterface */ protected $attributeValueFactory; + /** + * @param AttributeValueFactory $attributeValueFactory + */ public function __construct(AttributeValueFactory $attributeValueFactory) { $this->attributeValueFactory = $attributeValueFactory; @@ -104,7 +107,8 @@ public function setCustomAttributes(array $attributes) /** @var \Magento\Framework\Api\AttributeInterface $attribute */ foreach ($attributes as $attribute) { $this->setData( - $attribute->getAttributeCode(),$attribute->getValue() + $attribute->getAttributeCode(), + $attribute->getValue() ); } return $this; 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 0f4df78442899..8f6f7729d2373 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FilterPool.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FilterPool.php @@ -8,6 +8,7 @@ use Magento\Framework\Data\Collection\AbstractDb; use Magento\Framework\Api\Search\SearchCriteriaInterface; + /** * Class FilterPool */ @@ -29,6 +30,7 @@ public function __construct(array $appliers = []) /** * @param AbstractDb $collection * @param SearchCriteriaInterface $criteria + * @return void */ public function applyFilters(AbstractDb $collection, SearchCriteriaInterface $criteria) { 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 760742faa5f40..847206787efe4 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FulltextFilter.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/FulltextFilter.php @@ -20,7 +20,7 @@ class FulltextFilter implements FilterApplierInterface * Returns list of columns from fulltext index (doesn't support more then one FTI per table) * * @param DbCollection $collection - * @param $indexTable + * @param string $indexTable * @return array */ protected function getFulltextIndexColumns(DbCollection $collection, $indexTable) 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 3c7a57e603b7e..5f23a1d8855d2 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/RegularFilter.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/RegularFilter.php @@ -8,6 +8,7 @@ use Magento\Framework\Data\Collection\AbstractDb; use Magento\Framework\Api\Filter; + /** * Class RegularFilter */ diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php index c3c0d016b26ed..989428bb88563 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php @@ -12,6 +12,7 @@ use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy; use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory; use Psr\Log\LoggerInterface as Logger; + /** * Class Collection * Collection for order related documents to display grids on order view page @@ -38,7 +39,6 @@ class SearchResult extends AbstractCollection implements Api\Search\SearchResult * @param Logger $logger * @param FetchStrategy $fetchStrategy * @param EventManager $eventManager - * @param string $model * @param $mainTable * @param $resourceModel */ @@ -94,6 +94,7 @@ public function getSearchCriteria() */ public function setSearchCriteria(Api\SearchCriteriaInterface $searchCriteria) { + $this->searchCriteria = $searchCriteria; 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 b6840fab7865b..365c32a9f354c 100644 --- a/lib/internal/Magento/Framework/View/TemplateEngine/Xhtml/Template.php +++ b/lib/internal/Magento/Framework/View/TemplateEngine/Xhtml/Template.php @@ -25,8 +25,7 @@ class Template protected $templateNode; /** - * Constructor - * + * @param \Psr\Log\LoggerInterface $logger * @param string $content */ public function __construct( From 0577c26d9997d5b6a919a49b0362939b2a6e048a Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Tue, 28 Jul 2015 16:18:57 +0300 Subject: [PATCH 45/73] MAGETWO-39905: UI components compatibility with Search API --- .../Magento/Sales/Model/Order/Builder.php | 387 ------------------ .../Magento/Sales/Model/Order/Customer.php | 241 ----------- .../Sales/Model/Order/Customer/Builder.php | 260 ------------ .../Management.php => CustomerManagement.php} | 7 +- .../Resource/Order/Grid/Sql/SubSelect.php | 101 ----- .../Resource/Order/Grid/StatusesArray.php | 36 -- .../Unit/Model/Order/Customer/BuilderTest.php | 160 -------- ...entTest.php => CustomerManagementTest.php} | 4 +- .../Test/Unit/Model/Order/CustomerTest.php | 247 ----------- app/code/Magento/Sales/etc/di.xml | 89 ++-- .../layout/sales_creditmemo_grid_block.xml | 158 ------- .../layout/sales_invoice_grid_block.xml | 159 ------- .../layout/sales_shipment_grid_block.xml | 148 ------- .../Framework/DB/Sql/ConcatExpression.php | 1 + .../Framework/DB/Sql/LookupExpression.php | 121 ++++++ 15 files changed, 190 insertions(+), 1929 deletions(-) delete mode 100644 app/code/Magento/Sales/Model/Order/Builder.php delete mode 100644 app/code/Magento/Sales/Model/Order/Customer.php delete mode 100644 app/code/Magento/Sales/Model/Order/Customer/Builder.php rename app/code/Magento/Sales/Model/Order/{Customer/Management.php => CustomerManagement.php} (96%) delete mode 100644 app/code/Magento/Sales/Model/Resource/Order/Grid/Sql/SubSelect.php delete mode 100644 app/code/Magento/Sales/Model/Resource/Order/Grid/StatusesArray.php delete mode 100644 app/code/Magento/Sales/Test/Unit/Model/Order/Customer/BuilderTest.php rename app/code/Magento/Sales/Test/Unit/Model/Order/{Customer/ManagementTest.php => CustomerManagementTest.php} (98%) delete mode 100644 app/code/Magento/Sales/Test/Unit/Model/Order/CustomerTest.php delete mode 100644 app/code/Magento/Sales/view/adminhtml/layout/sales_creditmemo_grid_block.xml delete mode 100644 app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_grid_block.xml delete mode 100644 app/code/Magento/Sales/view/adminhtml/layout/sales_shipment_grid_block.xml create mode 100644 lib/internal/Magento/Framework/DB/Sql/LookupExpression.php 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 2fd0890b7fd15..305050bfba77f 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/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/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 98% 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 a837fd66e86b9..8419a2cf92049 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Customer/ManagementTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php @@ -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/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 32e595735c860..326a6ed1e599c 100755 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -58,7 +58,7 @@ - + @@ -477,57 +477,90 @@ - + - sales_shipping_address - firstname - lastname + + sales_shipping_address + firstname + + + sales_shipping_address + lastname + - + - sales_billing_address - firstname - lastname + + sales_billing_address + firstname + + + sales_billing_address + lastname + - + - sales_shipping_address - street - city - region - postcode + + sales_shipping_address + street + + + sales_shipping_address + city + + + sales_shipping_address + region + + + sales_shipping_address + postcode + , - + - sales_billing_address - street - city - region - 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 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 b1c52f72aa15a..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 f108bb6bbba93..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_shipment_grid_block.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_shipment_grid_block.xml deleted file mode 100644 index 0c392a2870afd..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/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php b/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php index 623dcbe1abacd..609e68a6be216 100644 --- a/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php +++ b/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php @@ -52,6 +52,7 @@ public function __construct( /** * Returns SQL expression * TRIM(CONCAT_WS(separator, IFNULL(str1,''), IFNULL(str2,''), ...)) + * * @return string */ public function __toString() 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..ddd3ff1a68343 --- /dev/null +++ b/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php @@ -0,0 +1,121 @@ +targetTable = $targetTable; + $this->targetColumn = $targetColumn; + $this->referenceColumns = $referenceColumns; + $this->sortOrder = $sortOrder; + $this->resource = $resource; + $this->adapter = $this->resource->getConnection(Resource::DEFAULT_READ_RESOURCE); + } + + /** + * Process WHERE clause + * + * @param Select $select + */ + protected function processWhereCondition(Select $select) + { + foreach ($this->referenceColumns as $column => $referenceColumn) { + $select->where( + sprintf('%s = %s', + $this->adapter->quoteIdentifier('lookup.' . $column), + $this->adapter->quoteIdentifier( + (isset($referenceColumn['tableAlias']) ? $referenceColumn['tableAlias'] . '.' : '') + . (isset($referenceColumn['columnName']) ? $referenceColumn['columnName'] : $column) + ) + ) + ); + } + } + + /** + * Process ORDER BY clause + * + * @param Select $select + */ + protected function processSortOrder(Select $select) + { + foreach ($this->sortOrder as $direction => $column) { + if (!in_array($direction, [Select::SQL_ASC, Select::SQL_DESC])) { + $direction = ''; + } + $select->order(new \Zend_Db_Expr( + sprintf('%s %s', $this->adapter->quoteIdentifier('lookup.' . $column)), $direction) + ); + } + } + + /** + * 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()); + } +} From fe96f1cf7cf503186c7d66d997814802d717eccc Mon Sep 17 00:00:00 2001 From: Michael Logvin Date: Tue, 28 Jul 2015 16:36:28 +0300 Subject: [PATCH 46/73] MAGETWO-39905: UI components compatibility with Search API --- .../UiComponent/DataProvider/SearchResult.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php index 989428bb88563..013ae0f529a5d 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php @@ -40,7 +40,7 @@ class SearchResult extends AbstractCollection implements Api\Search\SearchResult * @param FetchStrategy $fetchStrategy * @param EventManager $eventManager * @param $mainTable - * @param $resourceModel + * @param string $resourceModel */ public function __construct( EntityFactory $entityFactory, @@ -64,7 +64,7 @@ public function __construct( } /** - * @return Api\Search\AggregationInterface + * @return \Magento\Framework\Api\Search\AggregationInterface */ public function getAggregations() { @@ -72,7 +72,7 @@ public function getAggregations() } /** - * @param Api\Search\AggregationInterface $aggregations + * @param \Magento\Framework\Api\Search\AggregationInterface $aggregations * @return $this */ public function setAggregations($aggregations) @@ -81,7 +81,7 @@ public function setAggregations($aggregations) } /** - * @return Api\Search\SearchCriteriaInterface|null + * @return \Magento\Framework\Api\Search\SearchCriteriaInterface|null */ public function getSearchCriteria() { @@ -89,10 +89,10 @@ public function getSearchCriteria() } /** - * @param Api\SearchCriteriaInterface $searchCriteria + * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria * @return $this */ - public function setSearchCriteria(Api\SearchCriteriaInterface $searchCriteria) + public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { $this->searchCriteria = $searchCriteria; return $this; From 91dfe310b922c5770b4031373ee55011760188e1 Mon Sep 17 00:00:00 2001 From: Michael Logvin Date: Tue, 28 Jul 2015 17:26:14 +0300 Subject: [PATCH 47/73] MAGETWO-39905: UI components compatibility with Search API --- .../Magento/Cms/Controller/Adminhtml/Page/MassDisable.php | 2 +- .../Magento/Cms/Model/Resource/Page/Grid/Collection.php | 4 ++-- .../Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php | 8 ++++---- .../Unit/Controller/Adminhtml/Order/MassCancelTest.php | 3 ++- .../Test/Unit/Controller/Adminhtml/Order/MassHoldTest.php | 3 ++- .../Unit/Controller/Adminhtml/Order/MassUnholdTest.php | 3 ++- .../Adminhtml/Shipment/MassPrintShippingLabel.php | 4 ++-- .../Element/UiComponent/DataProvider/SearchResult.php | 5 +++-- 8 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php index 9f2ec91e4bd64..a3c5b07513f1e 100644 --- a/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php +++ b/app/code/Magento/Cms/Controller/Adminhtml/Page/MassDisable.php @@ -28,7 +28,7 @@ class MassDisable extends \Magento\Backend\App\Action /** * @param Context $context * @param Filter $filter - * @pram CollectionFactory $collectionFactory + * @param CollectionFactory $collectionFactory */ public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) { diff --git a/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php b/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php index 8e4e681c823cc..f2df536005439 100644 --- a/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php +++ b/app/code/Magento/Cms/Model/Resource/Page/Grid/Collection.php @@ -28,8 +28,8 @@ class Collection extends PageCollection implements SearchResultInterface * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param mixed|null $mainTable * @param \Magento\Framework\Model\Resource\Db\AbstractDb $eventPrefix - * @param $eventObject - * @param $resourceModel + * @param mixed $eventObject + * @param mixed $resourceModel * @param string $model * @param null $connection * @param \Magento\Framework\Model\Resource\Db\AbstractDb|null $resource diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php index ca3afbece4d2a..2dff66baba418 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php @@ -44,19 +44,19 @@ class Pdfcreditmemos extends \Magento\Sales\Controller\Adminhtml\Order\AbstractM protected $collectionFactory; /** - * @param CollectionFactory $collectionFactory * @param Context $context + * @param Filter $filter + * @param CollectionFactory $collectionFactory * @param DateTime $dateTime * @param FileFactory $fileFactory - * @param Filter $filter * @param Creditmemo $pdfCreditmemo */ public function __construct( - CollectionFactory $collectionFactory, Context $context, + Filter $filter, + CollectionFactory $collectionFactory, DateTime $dateTime, FileFactory $fileFactory, - Filter $filter, Creditmemo $pdfCreditmemo ) { $this->fileFactory = $fileFactory; 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 f53bdc71e0e89..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 @@ -112,7 +112,8 @@ public function setUp() ->disableOriginalConstructor() ->getMock(); - $this->orderCollectionFactoryMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\CollectionFactory') + $resourceCollection = 'Magento\Sales\Model\Resource\Order\CollectionFactory'; + $this->orderCollectionFactoryMock = $this->getMockBuilder($resourceCollection) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); 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 f1d4e88e3f597..ed08d860f3999 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 @@ -110,7 +110,8 @@ public function setUp() $this->orderCollectionMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\Collection') ->disableOriginalConstructor() ->getMock(); - $this->orderCollectionFactoryMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\CollectionFactory') + $orderCollection = 'Magento\Sales\Model\Resource\Order\CollectionFactory'; + $this->orderCollectionFactoryMock = $this->getMockBuilder($orderCollection) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); 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 2f55e00c5bc11..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 @@ -111,7 +111,8 @@ public function setUp() $this->orderCollectionMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\Collection') ->disableOriginalConstructor() ->getMock(); - $this->orderCollectionFactoryMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\CollectionFactory') + $orderCollection = 'Magento\Sales\Model\Resource\Order\CollectionFactory'; + $this->orderCollectionFactoryMock = $this->getMockBuilder($orderCollection) ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); diff --git a/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php b/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php index d1614161a192a..ab4dbf392617f 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Shipment/MassPrintShippingLabel.php @@ -31,15 +31,15 @@ class MassPrintShippingLabel extends \Magento\Sales\Controller\Adminhtml\Order\A /** * @param Context $context - * @param FileFactory $fileFactory * @param Filter $filter + * @param FileFactory $fileFactory * @param LabelGenerator $labelGenerator * @param CollectionFactory $collectionFactory */ public function __construct( Context $context, - FileFactory $fileFactory, Filter $filter, + FileFactory $fileFactory, LabelGenerator $labelGenerator, CollectionFactory $collectionFactory ) { diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php index 013ae0f529a5d..c10378b368bd8 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php @@ -39,8 +39,9 @@ class SearchResult extends AbstractCollection implements Api\Search\SearchResult * @param Logger $logger * @param FetchStrategy $fetchStrategy * @param EventManager $eventManager - * @param $mainTable - * @param string $resourceModel + * @param null|\Zend_Db_Adapter_Abstract $mainTable + * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resourceModel + * @throws \Magento\Framework\Exception\LocalizedException */ public function __construct( EntityFactory $entityFactory, From 88e82e588585bba4d68041816985f761c438b533 Mon Sep 17 00:00:00 2001 From: Michael Logvin Date: Tue, 28 Jul 2015 18:35:32 +0300 Subject: [PATCH 48/73] MAGETWO-39905: UI components compatibility with Search API --- .../Adminhtml/Order/Pdfinvoices.php | 8 +- .../Model/Order/CustomerManagementTest.php | 2 +- .../Unit/Model/Order/DataProviderTest,php | 206 ------------------ .../Order/Shipment/MassPrintShippingLabel.php | 8 +- .../Framework/DB/Sql/LookupExpression.php | 22 +- 5 files changed, 24 insertions(+), 222 deletions(-) delete mode 100644 app/code/Magento/Sales/Test/Unit/Model/Order/DataProviderTest,php diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php index b871f79f24a32..7d66fb576fb36 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php @@ -40,19 +40,19 @@ class Pdfinvoices extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMass protected $collectionFactory; /** - * @param CollectionFactory $collectionFactory * @param Context $context + * @param Filter $filter + * @param CollectionFactory $collectionFactory * @param DateTime $dateTime * @param FileFactory $fileFactory - * @param Filter $filter * @param Invoice $pdfInvoice */ public function __construct( - CollectionFactory $collectionFactory, Context $context, + Filter $filter, + CollectionFactory $collectionFactory, DateTime $dateTime, FileFactory $fileFactory, - Filter $filter, Invoice $pdfInvoice ) { $this->fileFactory = $fileFactory; diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php index 8419a2cf92049..114de0556ae2f 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php @@ -3,7 +3,7 @@ * 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 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/Shipping/Controller/Adminhtml/Order/Shipment/MassPrintShippingLabel.php b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/MassPrintShippingLabel.php index 7d3a8da8fbeeb..027d8eeec6e7d 100644 --- a/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/MassPrintShippingLabel.php +++ b/app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/MassPrintShippingLabel.php @@ -45,18 +45,18 @@ class MassPrintShippingLabel extends \Magento\Sales\Controller\Adminhtml\Order\A protected $shipmentCollectionFactory; /** - * @param CollectionFactory $collectionFactory * @param Context $context - * @param FileFactory $fileFactory * @param Filter $filter + * @param CollectionFactory $collectionFactory + * @param FileFactory $fileFactory * @param LabelGenerator $labelGenerator * @param ShipmentCollectionFactory $shipmentCollectionFactory */ public function __construct( - CollectionFactory $collectionFactory, Context $context, - FileFactory $fileFactory, Filter $filter, + CollectionFactory $collectionFactory, + FileFactory $fileFactory, LabelGenerator $labelGenerator, ShipmentCollectionFactory $shipmentCollectionFactory ) { diff --git a/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php b/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php index ddd3ff1a68343..c2e57e3adce4c 100644 --- a/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php +++ b/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php @@ -47,8 +47,8 @@ class LookupExpression extends \Zend_Db_Expr /** * @param Resource $resource - * @param $targetColumn - * @param $targetTable + * @param string $targetColumn + * @param string $targetTable * @param array $referenceColumns * @param array $sortOrder */ @@ -71,17 +71,24 @@ public function __construct( * 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', + sprintf( + '%s = %s', $this->adapter->quoteIdentifier('lookup.' . $column), - $this->adapter->quoteIdentifier( - (isset($referenceColumn['tableAlias']) ? $referenceColumn['tableAlias'] . '.' : '') - . (isset($referenceColumn['columnName']) ? $referenceColumn['columnName'] : $column) - ) + $this->adapter->quoteIdentifier($identifier . $columnName) ) ); } @@ -91,6 +98,7 @@ protected function processWhereCondition(Select $select) * Process ORDER BY clause * * @param Select $select + * @return void */ protected function processSortOrder(Select $select) { From 0a2d4de9d9b0b4d1b4913f4815e6e42e8dc6098d Mon Sep 17 00:00:00 2001 From: Michael Logvin Date: Tue, 28 Jul 2015 18:52:11 +0300 Subject: [PATCH 49/73] MAGETWO-39905: UI components compatibility with Search API --- .../Sales/Controller/Adminhtml/Order/Pdfshipments.php | 8 ++++---- .../Test/Unit/Model/Order/CustomerManagementTest.php | 2 +- .../Magento/Framework/DB/Sql/LookupExpression.php | 9 +++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php index e2bdfd0ed3023..d3363f27d19b9 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php @@ -43,20 +43,20 @@ class Pdfshipments extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMas protected $shipmentCollectionFactotory; /** - * @param CollectionFactory $collectionFactory * @param Context $context + * @param Filter $filter + * @param CollectionFactory $collectionFactory * @param DateTime $dateTime * @param FileFactory $fileFactory - * @param Filter $filter * @param Shipment $shipment * @param ShipmentCollectionFactory $shipmentCollectionFactory */ public function __construct( - CollectionFactory $collectionFactory, Context $context, + Filter $filter, + CollectionFactory $collectionFactory, DateTime $dateTime, FileFactory $fileFactory, - Filter $filter, Shipment $shipment, ShipmentCollectionFactory $shipmentCollectionFactory ) { diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php index 114de0556ae2f..44f72415df80d 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/CustomerManagementTest.php @@ -8,7 +8,7 @@ /** * Class BuilderTest */ -class ManagementTest extends \PHPUnit_Framework_TestCase +class CustomerManagementTest extends \PHPUnit_Framework_TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject diff --git a/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php b/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php index c2e57e3adce4c..e942a1586fe17 100644 --- a/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php +++ b/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php @@ -106,9 +106,14 @@ protected function processSortOrder(Select $select) if (!in_array($direction, [Select::SQL_ASC, Select::SQL_DESC])) { $direction = ''; } - $select->order(new \Zend_Db_Expr( - sprintf('%s %s', $this->adapter->quoteIdentifier('lookup.' . $column)), $direction) + $expr = new \Zend_Db_Expr( + sprintf( + '%s %s', + $this->adapter->quoteIdentifier('lookup.' . $column) + ), + $direction ); + $select->order($expr); } } From b397c46f54170dd78b35be029a57280b2ca4663a Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Tue, 28 Jul 2015 19:06:32 +0300 Subject: [PATCH 50/73] MAGETWO-39905: UI components compatibility with Search API --- .../Customer/Block/Adminhtml/Edit/Tab/View/OrdersTest.php | 1 - 1 file changed, 1 deletion(-) 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 index c922438d6052e..d42dda0fc40ee 100644 --- 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 @@ -56,7 +56,6 @@ public function setUp() public function tearDown() { $this->coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID); - $this->block->setCollection(null); } /** From 15e6fd2c7d9506d56058ab9c69bb806e19cf47a7 Mon Sep 17 00:00:00 2001 From: Michael Logvin Date: Tue, 28 Jul 2015 19:38:11 +0300 Subject: [PATCH 51/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php index 971a94a7269c0..f1226b82cb7bf 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php @@ -68,8 +68,8 @@ class Pdfdocs extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassActi /** * @param Context $context - * @param FileFactory $fileFactory * @param Filter $filter + * @param FileFactory $fileFactory * @param Invoice $pdfInvoice * @param Shipment $pdfShipment * @param Creditmemo $pdfCreditmemo @@ -82,8 +82,8 @@ class Pdfdocs extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassActi */ public function __construct( Context $context, - FileFactory $fileFactory, Filter $filter, + FileFactory $fileFactory, Invoice $pdfInvoice, Shipment $pdfShipment, Creditmemo $pdfCreditmemo, From 49f9bd3c7c5bdbccb3f0e6131f7dae7be5190d72 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Wed, 29 Jul 2015 18:31:28 +0300 Subject: [PATCH 52/73] MAGETWO-39905: UI components compatibility with Search API --- .../Adminhtml/Order/AbstractMassAction.php | 10 +++++++ .../Controller/Adminhtml/Order/MassCancel.php | 2 +- .../Controller/Adminhtml/Order/MassHold.php | 2 +- .../Controller/Adminhtml/Order/MassUnhold.php | 2 +- .../Adminhtml/Order/Pdfcreditmemos.php | 2 +- .../Controller/Adminhtml/Order/Pdfdocs.php | 2 +- .../Adminhtml/Order/Pdfinvoices.php | 2 +- .../Adminhtml/Order/Pdfshipments.php | 2 +- .../Ui/Component/MassAction/Filter.php | 27 ++++++++++++++++++- .../Framework/DB/Sql/LookupExpression.php | 2 +- 10 files changed, 44 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php index 71d39c60c43a6..08fbda748c577 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/AbstractMassAction.php @@ -61,6 +61,16 @@ public function execute() } } + /** + * 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 * diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php index 9b8300e8b21fe..46a83b9afb198 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassCancel.php @@ -52,7 +52,7 @@ protected function massAction(AbstractCollection $collection) $this->messageManager->addSuccess(__('We canceled %1 order(s).', $countCancelOrder)); } $resultRedirect = $this->resultRedirectFactory->create(); - $resultRedirect->setPath('sales/*/'); + $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 95579da36edb9..52b2ce3797a97 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php @@ -53,7 +53,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 55800f687e946..cdbdf98f37eb0 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassUnhold.php @@ -60,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 2dff66baba418..81da53f4b9f8e 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php @@ -78,7 +78,7 @@ protected function massAction(AbstractCollection $collection) $creditmemoCollection = $this->collectionFactory->create()->setOrderFilter(['in' => $collection->getAllIds()]); if (!$creditmemoCollection->getSize()) { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); - return $this->resultRedirectFactory->create()->setPath('sales/*/'); + return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl()); } return $this->fileFactory->create( sprintf('creditmemo%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php index 971a94a7269c0..b77855981384d 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php @@ -134,7 +134,7 @@ protected function massAction(AbstractCollection $collection) if (empty($documents)) { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); - return $this->resultRedirectFactory->create()->setPath('sales/*/'); + return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl()); } $pdf = array_shift($documents); diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php index 7d66fb576fb36..1eb43a64759a7 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php @@ -73,7 +73,7 @@ protected function massAction(AbstractCollection $collection) $invoicesCollection = $this->collectionFactory->create()->setOrderFilter(['in' => $collection->getAllIds()]); if (!$invoicesCollection->getSize()) { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); - return $this->resultRedirectFactory->create()->setPath('sales/*/'); + return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl()); } return $this->fileFactory->create( sprintf('packingslip%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php index d3363f27d19b9..4c9b57a55558a 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php @@ -81,7 +81,7 @@ protected function massAction(AbstractCollection $collection) ->setOrderFilter(['in' => $collection->getAllIds()]); if (!$shipmentsCollection->getSize()) { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); - return $this->resultRedirectFactory->create()->setPath('sales/*/'); + return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl()); } return $this->fileFactory->create( sprintf('packingslip%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), diff --git a/app/code/Magento/Ui/Component/MassAction/Filter.php b/app/code/Magento/Ui/Component/MassAction/Filter.php index fe321d194bfd7..98703a1947129 100644 --- a/app/code/Magento/Ui/Component/MassAction/Filter.php +++ b/app/code/Magento/Ui/Component/MassAction/Filter.php @@ -30,6 +30,11 @@ class Filter */ protected $request; + /** + * @var UiComponentInterface[] + */ + protected $components = []; + /** * @param UiComponentFactory $factory * @param RequestInterface $request @@ -42,6 +47,15 @@ public function __construct( $this->request = $request; } + protected 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 @@ -49,7 +63,7 @@ public function __construct( */ public function getCollection(AbstractDb $collection) { - $component = $this->factory->create($this->request->getParam('namespace')); + $component = $this->getComponent(); $this->prepareComponent($component); $dataProvider = $component->getContext()->getDataProvider(); $ids = []; @@ -102,4 +116,15 @@ protected function prepareComponent(UiComponentInterface $component) } $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/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php b/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php index e942a1586fe17..2b850111bd7de 100644 --- a/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php +++ b/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php @@ -82,7 +82,7 @@ protected function processWhereCondition(Select $select) } $columnName = $column; if (isset($referenceColumn['columnName'])) { - $columnName = $referenceColumn['columnName'] . '.'; + $columnName = $referenceColumn['columnName']; } $select->where( sprintf( From e5901a841d627e592958caa8245ab62b8f18c396 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Wed, 29 Jul 2015 19:17:54 +0300 Subject: [PATCH 53/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Ui/Component/MassAction/Filter.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/code/Magento/Ui/Component/MassAction/Filter.php b/app/code/Magento/Ui/Component/MassAction/Filter.php index 98703a1947129..b64cbb8a03fae 100644 --- a/app/code/Magento/Ui/Component/MassAction/Filter.php +++ b/app/code/Magento/Ui/Component/MassAction/Filter.php @@ -47,6 +47,12 @@ public function __construct( $this->request = $request; } + /** + * Returns component by namespace + * + * @return UiComponentInterface + * @throws LocalizedException + */ protected function getComponent() { $namespace = $this->request->getParam('namespace'); From 1e6b02fb3e93ac758a2750904e7cefd2367bade2 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Wed, 29 Jul 2015 21:57:19 +0300 Subject: [PATCH 54/73] MAGETWO-39905: UI components compatibility with Search API --- .../Adminhtml/Edit/Tab/View/OrdersTest.php | 112 ------------------ 1 file changed, 112 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/View/OrdersTest.php 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 d42dda0fc40ee..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/View/OrdersTest.php +++ /dev/null @@ -1,112 +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); - } - - /** - * Verify that the correct Url is return for a row in the orders grid. - */ - public function testGetRowUrl() - { - $row = new \Magento\Framework\Object(['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()); - } -} From 21ead020976660dc844cb89abc8b856ad75699af Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Fri, 31 Jul 2015 13:53:20 +0300 Subject: [PATCH 55/73] MAGETWO-39905: UI components compatibility with Search API --- .../Catalog/Controller/Adminhtml/Product/MassDelete.php | 5 +++-- app/code/Magento/Ui/DataProvider/AbstractDataProvider.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php index 92cc11f159c93..945e80c93e44c 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php @@ -49,12 +49,13 @@ public function __construct( public function execute() { $collection = $this->filter->getCollection($this->collectionFactory->create()); - + $productDeleted = 0; foreach ($collection->getItems() as $product) { $product->delete(); + $productDeleted++; } $this->messageManager->addSuccess( - __('A total of %1 record(s) have been deleted.', $collection->getSize()) + __('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/Ui/DataProvider/AbstractDataProvider.php b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php index 46deec35c0804..9ecc7a903f771 100644 --- a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php +++ b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php @@ -175,7 +175,7 @@ public function getSearchCriteria() public function getSearchResult() { //TODO: Technical dept, should be implemented as part of SearchAPI support for Catalog Grids - return null; + return $this->getCollection(); } /** From 0663efa449d4beafaab9f85d995af21456c6963b Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 3 Aug 2015 16:56:04 +0300 Subject: [PATCH 56/73] MAGETWO-39905: UI components compatibility with Search API --- .../sales_order_creditmemo_grid.xml | 6 +- .../ui_component/sales_order_grid.xml | 9 +- .../ui_component/sales_order_invoice_grid.xml | 6 +- .../sales_order_shipment_grid.xml | 6 +- .../sales_order_view_creditmemo_grid.xml | 2 +- .../sales_order_view_invoice_grid.xml | 6 +- .../sales_order_view_shipment_grid.xml | 6 +- .../Ui/Component/MassAction/Filter.php | 47 ++++- .../Controller/Adminhtml/Export/GridToCsv.php | 61 +++++++ .../Magento/Ui/Model/Export/ConvertToCsv.php | 160 ++++++++++++++++++ .../Ui/view/base/web/js/grid/export.js | 57 +++++-- 11 files changed, 327 insertions(+), 39 deletions(-) create mode 100644 app/code/Magento/Ui/Controller/Adminhtml/Export/GridToCsv.php create mode 100644 app/code/Magento/Ui/Model/Export/ConvertToCsv.php 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 afcd821481f69..95affbeec277d 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 @@ -17,7 +17,7 @@ Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_creditmemo_grid_data_source - increment_id + entity_id id @@ -69,12 +69,12 @@ 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 a16cf3ee0ab38..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 @@ -25,7 +25,7 @@ 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 994e19d1648f8..1b42c914b483f 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 @@ -17,7 +17,7 @@ Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_invoice_grid_data_source - increment_id + entity_id id @@ -69,12 +69,12 @@ 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 23b9d3fb7509f..9f2066c88e6ea 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 @@ -17,7 +17,7 @@ Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_shipment_grid_data_source - increment_id + entity_id id @@ -69,12 +69,12 @@ csv CSV - sales/shipment/exportCsv + mui/export/gridToCsv xml Excel XML - sales/shipment/exportExcel + mui/export/gridToCsv 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 index dd3d7f9e3b413..4fe956c107596 100644 --- 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 @@ -17,7 +17,7 @@ Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_view_creditmemo_grid_data_source - increment_id + entity_id id 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 index 26bb45ff375b3..296a9566badf1 100644 --- 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 @@ -17,7 +17,7 @@ Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_view_invoice_grid_data_source - increment_id + entity_id id @@ -72,12 +72,12 @@ 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_view_shipment_grid.xml b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_shipment_grid.xml index 1a2d23fab74c3..0928569484c34 100644 --- 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 @@ -17,7 +17,7 @@ Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider sales_order_view_shipment_grid_data_source - increment_id + entity_id id @@ -72,12 +72,12 @@ csv CSV - sales/shipment/exportCsv + mui/export/gridToCsv xml Excel XML - sales/shipment/exportExcel + mui/export/gridToCsv diff --git a/app/code/Magento/Ui/Component/MassAction/Filter.php b/app/code/Magento/Ui/Component/MassAction/Filter.php index b64cbb8a03fae..7364754ccbbce 100644 --- a/app/code/Magento/Ui/Component/MassAction/Filter.php +++ b/app/code/Magento/Ui/Component/MassAction/Filter.php @@ -5,6 +5,7 @@ */ namespace Magento\Ui\Component\MassAction; +use Magento\Framework\Api\FilterBuilder; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\View\Element\UiComponentFactory; use Magento\Framework\App\RequestInterface; @@ -35,16 +36,24 @@ class Filter */ protected $components = []; + /** + * @var FilterBuilder + */ + protected $filterBuilder; + /** * @param UiComponentFactory $factory * @param RequestInterface $request + * @param FilterBuilder $filterBuilder */ public function __construct( UiComponentFactory $factory, - RequestInterface $request + RequestInterface $request, + FilterBuilder $filterBuilder ) { $this->factory = $factory; $this->request = $request; + $this->filterBuilder = $filterBuilder; } /** @@ -53,7 +62,7 @@ public function __construct( * @return UiComponentInterface * @throws LocalizedException */ - protected function getComponent() + public function getComponent() { $namespace = $this->request->getParam('namespace'); if (!isset($this->components[$namespace])) { @@ -81,6 +90,38 @@ public function getCollection(AbstractDb $collection) return $this->applySelection($collection); } + /** + * Apply selection by Excluded Included to Search Result + * + * @throws LocalizedException + */ + 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 @@ -115,7 +156,7 @@ protected function applySelection(AbstractDb $collection) * @param UiComponentInterface $component * @return void */ - protected function prepareComponent(UiComponentInterface $component) + public function prepareComponent(UiComponentInterface $component) { foreach ($component->getChildComponents() as $child) { $this->prepareComponent($child); 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..0d78efb508d00 --- /dev/null +++ b/app/code/Magento/Ui/Controller/Adminhtml/Export/GridToCsv.php @@ -0,0 +1,61 @@ +factory = $factory; + $this->converter = $converter; + $this->fileFactory = $fileFactory; + } + + /** + * Export data provider to CSV + * + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function execute() + { + return $this->fileFactory->create('export.csv', $this->converter->getCsvFile(), 'var'); + + } +} 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..c6fc2294b19e8 --- /dev/null +++ b/app/code/Magento/Ui/Model/Export/ConvertToCsv.php @@ -0,0 +1,160 @@ +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 + * + * @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 $fields + * @return array + */ + protected function getRowData(DocumentInterface $document, $fields) + { + $row = []; + foreach ($fields as $column) { + $row[] = $document->getCustomAttribute($column)->getValue(); + } + return $row; + } + + /** + * Returns CSV file + * + * @return array + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function getCsvFile() + { + $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)); + } + $stream->unlock(); + $stream->close(); + + return [ + 'type' => 'filename', + 'value' => $file, + 'rm' => true // can delete file after use + ]; + } +} 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; } }); }); From e292bed9b6b4cb225b6a9296d5a7c378ca21b98e Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 3 Aug 2015 17:06:40 +0300 Subject: [PATCH 57/73] MAGETWO-39905: UI components compatibility with Search API --- .../Adminhtml/Creditmemo/ExportCsv.php | 59 ---------------- .../Adminhtml/Creditmemo/ExportExcel.php | 59 ---------------- .../Adminhtml/Invoice/ExportCsv.php | 65 ------------------ .../Adminhtml/Invoice/ExportExcel.php | 64 ------------------ .../Controller/Adminhtml/Order/ExportCsv.php | 28 -------- .../Adminhtml/Order/ExportExcel.php | 28 -------- .../Adminhtml/Shipment/ExportCsv.php | 67 ------------------- .../Adminhtml/Shipment/ExportExcel.php | 67 ------------------- 8 files changed, 437 deletions(-) delete mode 100644 app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/ExportCsv.php delete mode 100644 app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/ExportExcel.php delete mode 100644 app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportCsv.php delete mode 100644 app/code/Magento/Sales/Controller/Adminhtml/Invoice/ExportExcel.php delete mode 100644 app/code/Magento/Sales/Controller/Adminhtml/Order/ExportCsv.php delete mode 100644 app/code/Magento/Sales/Controller/Adminhtml/Order/ExportExcel.php delete mode 100644 app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportCsv.php delete mode 100644 app/code/Magento/Sales/Controller/Adminhtml/Shipment/ExportExcel.php 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/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/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/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 - ); - } -} From 4b09ce4613e37e5916ea8260bd0618db7d720aa1 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 3 Aug 2015 17:27:58 +0300 Subject: [PATCH 58/73] MAGETWO-39905: UI components compatibility with Search API --- .../Magento/Framework/DB/ConcatExpression.php | 82 ------------------- .../Framework/DB/Sql/LookupExpression.php | 6 +- .../UiComponent/DataProvider/SearchResult.php | 1 + 3 files changed, 4 insertions(+), 85 deletions(-) delete mode 100644 lib/internal/Magento/Framework/DB/ConcatExpression.php diff --git a/lib/internal/Magento/Framework/DB/ConcatExpression.php b/lib/internal/Magento/Framework/DB/ConcatExpression.php deleted file mode 100644 index 12ce1eb50cacc..0000000000000 --- a/lib/internal/Magento/Framework/DB/ConcatExpression.php +++ /dev/null @@ -1,82 +0,0 @@ -resource = $resource; - $this->columns = $columns; - $this->tableName = $tableName; - $this->isTableAlias = $isTableAlias; - $this->separator = $separator; - } - - /** - * @return string - */ - public function __toString() - { - $columns = []; - foreach ($this->columns as $key => $column) { - $columns[$key] = sprintf( - "ifnull(%s, '')", - $this->resource->getConnection(Resource::DEFAULT_READ_RESOURCE) - ->quoteIdentifier($this->tableName . '.' .$column) - ); - } - return sprintf( - 'trim(concat(%s))', - implode( - sprintf(", '%s' ,", $this->separator), - $columns - ) - ); - } -} diff --git a/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php b/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php index 2b850111bd7de..66668c935a724 100644 --- a/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php +++ b/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php @@ -109,9 +109,9 @@ protected function processSortOrder(Select $select) $expr = new \Zend_Db_Expr( sprintf( '%s %s', - $this->adapter->quoteIdentifier('lookup.' . $column) - ), - $direction + $this->adapter->quoteIdentifier('lookup.' . $column), + $direction + ) ); $select->order($expr); } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php index c10378b368bd8..def2e0c0d6235 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php @@ -51,6 +51,7 @@ public function __construct( $mainTable, $resourceModel ) { + $this->setMainTable(true); $this->_init('Magento\Framework\View\Element\UiComponent\DataProvider\Document', $resourceModel); parent::__construct( $entityFactory, From 3e06b925f71de215c99a4a87266dde1fb035de71 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 3 Aug 2015 17:35:09 +0300 Subject: [PATCH 59/73] MAGETWO-39905: UI components compatibility with Search API --- .../Ui/Component/MassAction/Filter.php | 1 + .../Controller/Adminhtml/Export/GridToCsv.php | 2 ++ .../Magento/Ui/Model/Export/ConvertToCsv.php | 22 ++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/Component/MassAction/Filter.php b/app/code/Magento/Ui/Component/MassAction/Filter.php index 7364754ccbbce..e64287c0978b8 100644 --- a/app/code/Magento/Ui/Component/MassAction/Filter.php +++ b/app/code/Magento/Ui/Component/MassAction/Filter.php @@ -94,6 +94,7 @@ public function getCollection(AbstractDb $collection) * Apply selection by Excluded Included to Search Result * * @throws LocalizedException + * @return void */ public function applySelectionOnTargetProvider() { diff --git a/app/code/Magento/Ui/Controller/Adminhtml/Export/GridToCsv.php b/app/code/Magento/Ui/Controller/Adminhtml/Export/GridToCsv.php index 0d78efb508d00..93be6f46466ff 100644 --- a/app/code/Magento/Ui/Controller/Adminhtml/Export/GridToCsv.php +++ b/app/code/Magento/Ui/Controller/Adminhtml/Export/GridToCsv.php @@ -35,6 +35,7 @@ class GridToCsv extends Action * @param Context $context * @param UiComponentFactory $factory * @param ConvertToCsv $converter + * @param FileFactory $fileFactory */ public function __construct( Context $context, @@ -52,6 +53,7 @@ public function __construct( * Export data provider to CSV * * @throws \Magento\Framework\Exception\LocalizedException + * @return \Magento\Framework\App\ResponseInterface */ public function execute() { diff --git a/app/code/Magento/Ui/Model/Export/ConvertToCsv.php b/app/code/Magento/Ui/Model/Export/ConvertToCsv.php index c6fc2294b19e8..54efa66cd361c 100644 --- a/app/code/Magento/Ui/Model/Export/ConvertToCsv.php +++ b/app/code/Magento/Ui/Model/Export/ConvertToCsv.php @@ -79,6 +79,7 @@ protected function getColumns(UiComponentInterface $component) /** * Retrieve Headers row array for Export * + * @param UiComponentInterface $component * @return string[] */ protected function getHeaders(UiComponentInterface $component) @@ -113,7 +114,7 @@ protected function getFields(UiComponentInterface $component) * Returns row data * * @param DocumentInterface $document - * @param $fields + * @param array $fields * @return array */ protected function getRowData(DocumentInterface $document, $fields) @@ -125,6 +126,25 @@ protected function getRowData(DocumentInterface $document, $fields) return $row; } + /** + * Returns Filters with options + * + * @param UiComponentInterface $component + * @return \Magento\Ui\Component\Filters + * @throws \Exception + */ + protected function getFieldOptions(UiComponentInterface $component) + { + $childComponents = $component->getChildComponents(); + $listingTop = $childComponents['listing_top']; + foreach($listingTop as $child) { + if ($child instanceof \Magento\Ui\Component\Filters) { + return $child; + } + } + throw new \Exception('No filters found'); + } + /** * Returns CSV file * From 4cc1aba154a86851d92226fdb174426581ba300c Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 3 Aug 2015 19:11:21 +0300 Subject: [PATCH 60/73] MAGETWO-39905: UI components compatibility with Search API --- .../View/Element/UiComponent/DataProvider/SearchResult.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php index def2e0c0d6235..ec65b025f8a48 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php @@ -51,8 +51,8 @@ public function __construct( $mainTable, $resourceModel ) { - $this->setMainTable(true); $this->_init('Magento\Framework\View\Element\UiComponent\DataProvider\Document', $resourceModel); + $this->setMainTable(true); parent::__construct( $entityFactory, $logger, From 5a5f746ff8f777438338265440cb8f6ada3c8c46 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 3 Aug 2015 21:41:53 +0300 Subject: [PATCH 61/73] MAGETWO-39905: UI components compatibility with Search API --- .../sales_order_creditmemo_grid.xml | 1 + .../ui_component/sales_order_invoice_grid.xml | 1 + .../sales_order_shipment_grid.xml | 1 + .../sales_order_view_creditmemo_grid.xml | 1 + .../sales_order_view_invoice_grid.xml | 1 + .../sales_order_view_shipment_grid.xml | 1 + .../Ui/Component/Filters/Type/Select.php | 10 +++ .../Magento/Ui/Model/Export/ConvertToCsv.php | 77 ++++++++++++++++--- .../Framework/DB/Sql/ConcatExpression.php | 2 +- .../Framework/DB/Sql/LookupExpression.php | 2 +- 10 files changed, 85 insertions(+), 12 deletions(-) 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 95affbeec277d..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 @@ -64,6 +64,7 @@ + sales_order_creditmemo_grid.sales_order_creditmemo_grid.sales_order_creditmemo_columns.ids dataGridActions 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 1b42c914b483f..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 @@ -64,6 +64,7 @@ + sales_order_invoice_grid.sales_order_invoice_grid.sales_order_invoice_columns.ids dataGridActions 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 9f2066c88e6ea..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 @@ -64,6 +64,7 @@ + sales_order_shipment_grid.sales_order_shipment_grid.sales_order_shipment_columns.ids dataGridActions 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 index 4fe956c107596..15b85280df3aa 100644 --- 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 @@ -67,6 +67,7 @@ + sales_order_view_creditmemo_grid.sales_order_view_creditmemo_grid.sales_order_view_creditmemo_columns.ids dataGridActions 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 index 296a9566badf1..a194c0b37dc5e 100644 --- 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 @@ -67,6 +67,7 @@ + sales_order_view_invoice_grid.sales_order_view_invoice_grid.sales_order_view_invoice_columns.ids dataGridActions 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 index 0928569484c34..46fa0fc448aaa 100644 --- 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 @@ -67,6 +67,7 @@ + sales_order_view_shipment_grid.sales_order_view_shipment_grid.sales_order_view_shipment_columns.ids dataGridActions diff --git a/app/code/Magento/Ui/Component/Filters/Type/Select.php b/app/code/Magento/Ui/Component/Filters/Type/Select.php index 06d53562a5c74..06b783861182e 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Select.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Select.php @@ -104,4 +104,14 @@ protected function applyFilter() } } } + + /** + * Returns options provider + * + * @return OptionSourceInterface + */ + public function getOptionProvider() + { + return $this->optionsProvider; + } } diff --git a/app/code/Magento/Ui/Model/Export/ConvertToCsv.php b/app/code/Magento/Ui/Model/Export/ConvertToCsv.php index 54efa66cd361c..b67472cfd7ad3 100644 --- a/app/code/Magento/Ui/Model/Export/ConvertToCsv.php +++ b/app/code/Magento/Ui/Model/Export/ConvertToCsv.php @@ -9,6 +9,8 @@ use Magento\Ui\Component\MassAction\Filter; use Magento\Framework\View\Element\UiComponentInterface; use Magento\Framework\Api\Search\DocumentInterface; +use Magento\Framework\Data\OptionSourceInterface; +use Magento\Ui\Component\Filters\Type\Select; /** * Class ConvertToCsv @@ -115,34 +117,88 @@ protected function getFields(UiComponentInterface $component) * * @param DocumentInterface $document * @param array $fields + * @param array $options * @return array */ - protected function getRowData(DocumentInterface $document, $fields) + protected function getRowData(DocumentInterface $document, $fields, $options) { $row = []; foreach ($fields as $column) { - $row[] = $document->getCustomAttribute($column)->getValue(); + 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 + * @return array + */ + 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 { + $complexOption = []; + $this->getComplexLabel( + $option['value'], + $option['label'], + $options + ); + } + } + return $options; + } /** * Returns Filters with options * - * @param UiComponentInterface $component - * @return \Magento\Ui\Component\Filters - * @throws \Exception + * @return array */ - protected function getFieldOptions(UiComponentInterface $component) + protected function getOptions() { + $options = []; + $component = $this->filter->getComponent(); $childComponents = $component->getChildComponents(); $listingTop = $childComponents['listing_top']; - foreach($listingTop as $child) { + foreach($listingTop->getChildComponents() as $child) { if ($child instanceof \Magento\Ui\Component\Filters) { - return $child; + foreach($child->getChildComponents() as $filter) { + if ($filter instanceof Select) { + $options[$filter->getName()] = $this->getFilterOptions($filter); + } + } } } - throw new \Exception('No filters found'); + return $options; } /** @@ -153,6 +209,7 @@ protected function getFieldOptions(UiComponentInterface $component) */ public function getCsvFile() { + $options = $this->getOptions(); $component = $this->filter->getComponent(); $name = md5(microtime()); $file = 'export/'. $component->getName() . $name . '.csv'; @@ -166,7 +223,7 @@ public function getCsvFile() $stream->lock(); $stream->writeCsv($this->getHeaders($component)); foreach ($searchResult->getItems() as $document) { - $stream->writeCsv($this->getRowData($document, $fields)); + $stream->writeCsv($this->getRowData($document, $fields, $options)); } $stream->unlock(); $stream->close(); diff --git a/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php b/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php index 609e68a6be216..f73c30d9b3e5b 100644 --- a/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php +++ b/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php @@ -44,7 +44,7 @@ public function __construct( array $columns, $separator = ' ' ) { - $this->adapter = $resource->getConnection(Resource::DEFAULT_READ_RESOURCE); + $this->adapter = $resource->getConnection(); $this->columns = $columns; $this->separator = $separator; } diff --git a/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php b/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php index 66668c935a724..30e208e3fcff0 100644 --- a/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php +++ b/lib/internal/Magento/Framework/DB/Sql/LookupExpression.php @@ -64,7 +64,7 @@ public function __construct( $this->referenceColumns = $referenceColumns; $this->sortOrder = $sortOrder; $this->resource = $resource; - $this->adapter = $this->resource->getConnection(Resource::DEFAULT_READ_RESOURCE); + $this->adapter = $this->resource->getConnection(); } /** From ea4e379c12bd00bd6079b50392cbac906c9c6033 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 3 Aug 2015 22:16:46 +0300 Subject: [PATCH 62/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Ui/Model/Export/ConvertToCsv.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Ui/Model/Export/ConvertToCsv.php b/app/code/Magento/Ui/Model/Export/ConvertToCsv.php index b67472cfd7ad3..a74fd10ae7ed6 100644 --- a/app/code/Magento/Ui/Model/Export/ConvertToCsv.php +++ b/app/code/Magento/Ui/Model/Export/ConvertToCsv.php @@ -142,7 +142,8 @@ protected function getRowData(DocumentInterface $document, $fields, $options) * * @param array $list * @param string $label - * @return array + * @param array $output + * @return void */ protected function getComplexLabel($list, $label, &$output) { @@ -189,9 +190,9 @@ protected function getOptions() $component = $this->filter->getComponent(); $childComponents = $component->getChildComponents(); $listingTop = $childComponents['listing_top']; - foreach($listingTop->getChildComponents() as $child) { + foreach ($listingTop->getChildComponents() as $child) { if ($child instanceof \Magento\Ui\Component\Filters) { - foreach($child->getChildComponents() as $filter) { + foreach ($child->getChildComponents() as $filter) { if ($filter instanceof Select) { $options[$filter->getName()] = $this->getFilterOptions($filter); } From 72c0c92dcd239199008fa7bf2c3cde757584b108 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 3 Aug 2015 22:28:58 +0300 Subject: [PATCH 63/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Ui/Model/Export/ConvertToCsv.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Ui/Model/Export/ConvertToCsv.php b/app/code/Magento/Ui/Model/Export/ConvertToCsv.php index a74fd10ae7ed6..450ba515e3fc1 100644 --- a/app/code/Magento/Ui/Model/Export/ConvertToCsv.php +++ b/app/code/Magento/Ui/Model/Export/ConvertToCsv.php @@ -169,7 +169,6 @@ protected function getFilterOptions(Select $filter) if (!is_array($option['value'])) { $options[$option['value']] = $option['label']; } else { - $complexOption = []; $this->getComplexLabel( $option['value'], $option['label'], From 8a4824c395ebec8d2fd7093e264d7ae50db21b87 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Tue, 4 Aug 2015 18:18:19 +0300 Subject: [PATCH 64/73] MAGETWO-39905: UI components compatibility with Search API --- .../Sales/Block/Adminhtml/Reorder/Renderer/Action.php | 1 - app/code/Magento/Sales/Helper/Reorder.php | 4 +++- lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php | 6 ------ .../View/Element/UiComponent/DataProvider/SearchResult.php | 4 ++-- 4 files changed, 5 insertions(+), 10 deletions(-) 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 07b65563d80e4..132bd5d0be4c4 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,6 @@ public function __construct( public function render(\Magento\Framework\Object $row) { $this->_actions = []; - /** */ if ($this->_salesReorder->canReorder($row->getId())) { $reorderAction = [ '@' => [ diff --git a/app/code/Magento/Sales/Helper/Reorder.php b/app/code/Magento/Sales/Helper/Reorder.php index ae4ab41c38b46..6c735c919ad00 100644 --- a/app/code/Magento/Sales/Helper/Reorder.php +++ b/app/code/Magento/Sales/Helper/Reorder.php @@ -65,7 +65,9 @@ public function isAllowed($store = null) } /** - * @param $orderId + * Check is it possible to reorder + * + * @param int $orderId * @return bool */ public function canReorder($orderId) diff --git a/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php b/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php index f73c30d9b3e5b..b9d9ffb4a48ae 100644 --- a/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php +++ b/lib/internal/Magento/Framework/DB/Sql/ConcatExpression.php @@ -23,11 +23,6 @@ class ConcatExpression extends \Zend_Db_Expr */ protected $columns; - /** - * @var string - */ - protected $alias; - /** * @var string */ @@ -36,7 +31,6 @@ class ConcatExpression extends \Zend_Db_Expr /** * @param Resource $resource * @param array $columns - * @param string $alias * @param string $separator */ public function __construct( diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php index ec65b025f8a48..614b4b7f1dd05 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php @@ -39,8 +39,8 @@ class SearchResult extends AbstractCollection implements Api\Search\SearchResult * @param Logger $logger * @param FetchStrategy $fetchStrategy * @param EventManager $eventManager - * @param null|\Zend_Db_Adapter_Abstract $mainTable - * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resourceModel + * @param string $mainTable + * @param string $resourceModel * @throws \Magento\Framework\Exception\LocalizedException */ public function __construct( From b184b0a3cb8ed954da7db9c62f1d1b6bccb82f3d Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Tue, 4 Aug 2015 18:22:49 +0300 Subject: [PATCH 65/73] MAGETWO-39905: UI components compatibility with Search API --- .../View/Element/UiComponent/DataProvider/SearchResult.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php index 614b4b7f1dd05..9fa1308c4acbb 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php @@ -75,7 +75,7 @@ public function getAggregations() /** * @param \Magento\Framework\Api\Search\AggregationInterface $aggregations - * @return $this + * @return void */ public function setAggregations($aggregations) { From bf82901c80f167786dd626f3c806c9d9e3fbe005 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Tue, 4 Aug 2015 21:13:33 +0300 Subject: [PATCH 66/73] MAGETWO-39905: UI components compatibility with Search API --- .../View/Element/UiComponent/DataProvider/Document.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php index cf72a130467dd..89b625634eeb8 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Document.php @@ -6,13 +6,13 @@ namespace Magento\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Api\Search\DocumentInterface; -use Magento\Framework\Object; +use Magento\Framework\DataObject; use Magento\Framework\Api\AttributeValueFactory; /** * Class Document */ -class Document extends Object implements DocumentInterface +class Document extends DataObject implements DocumentInterface { /** * @var string|int From 6a9ffe8b30dcd6c3568bf822c59ac7ef07e3752b Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Fri, 7 Aug 2015 11:53:16 +0300 Subject: [PATCH 67/73] MAGETWO-39905: UI components compatibility with Search API --- .../Magento/Sales/Api/Data/OrderInterface.php | 15 ++++ .../Sales/Controller/Adminhtml/Order.php | 37 ++++++-- .../Controller/Adminhtml/Order/Cancel.php | 3 +- .../Adminhtml/Order/CommentsHistory.php | 14 ++- .../Controller/Adminhtml/Order/Email.php | 12 ++- .../Sales/Controller/Adminhtml/Order/Hold.php | 3 +- .../Controller/Adminhtml/Order/MassHold.php | 21 ++++- .../Adminhtml/Order/ReviewPayment.php | 6 +- .../Controller/Adminhtml/Order/Unhold.php | 3 +- .../Sales/Controller/Adminhtml/Order/View.php | 4 +- app/code/Magento/Sales/Model/Order.php | 8 +- .../Controller/Adminhtml/Order/EmailTest.php | 86 ++++++++++--------- .../Adminhtml/Order/MassHoldTest.php | 15 ++-- .../Adminhtml/Order/ReviewPaymentTest.php | 66 +++++++------- .../Controller/Adminhtml/Order/ViewTest.php | 58 ++++++++----- .../Api/Search/SearchCriteriaBuilder.php | 3 +- .../UiComponent/DataProvider/Reporting.php | 5 ++ 17 files changed, 231 insertions(+), 128 deletions(-) diff --git a/app/code/Magento/Sales/Api/Data/OrderInterface.php b/app/code/Magento/Sales/Api/Data/OrderInterface.php index a4376b9eb81a7..e307ea19b1401 100644 --- a/app/code/Magento/Sales/Api/Data/OrderInterface.php +++ b/app/code/Magento/Sales/Api/Data/OrderInterface.php @@ -1588,6 +1588,21 @@ public function setShippingAddress(\Magento\Sales\Api\Data\OrderAddressInterface */ public function getPayments(); + /** + * Gets actual payment for the order it it exists, false if not + * + * @return \Magento\Sales\Api\Data\OrderPaymentInterface|false + */ + public function getPayment(); + + /** + * Set actual payment for the order + * + * @param \Magento\Sales\Api\Data\OrderPaymentInterface $payment + * @return $this + */ + public function setPayment(\Magento\Sales\Api\Data\OrderPaymentInterface $payment); + /** * Sets the payments for the order. * diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order.php b/app/code/Magento/Sales/Controller/Adminhtml/Order.php index 4232fc9173aba..82c20141c31c8 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order.php @@ -6,6 +6,10 @@ 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 Psr\Log\LoggerInterface; /** * Adminhtml sales orders controller @@ -59,6 +63,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 +87,8 @@ 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 + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( Action\Context $context, @@ -77,7 +98,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 +110,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 +133,14 @@ 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; 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..e48079b1faa3c 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php @@ -7,6 +7,9 @@ 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 extends \Magento\Sales\Controller\Adminhtml\Order { @@ -24,6 +27,9 @@ 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) @@ -37,6 +43,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 +57,10 @@ public function __construct( $resultPageFactory, $resultJsonFactory, $resultLayoutFactory, - $resultRawFactory + $resultRawFactory, + $orderManagement, + $orderRepository, + $logger ); } 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/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/MassHold.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php index 9eaeddf9a2ce7..bbb377bef9045 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php @@ -9,18 +9,32 @@ 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 */ - public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) - { + public function __construct( + Context $context, + Filter $filter, + CollectionFactory $collectionFactory, + OrderManagementInterface $orderManagement + ) { parent::__construct($context, $filter); $this->collectionFactory = $collectionFactory; + $this->orderManagement = $orderManagement; } /** @@ -32,12 +46,11 @@ public function __construct(Context $context, Filter $filter, CollectionFactory 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; 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/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/Test/Unit/Controller/Adminhtml/Order/EmailTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/EmailTest.php index fe36332d13983..394a4934c67ce 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 @@ -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/MassHoldTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/MassHoldTest.php index ed08d860f3999..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 @@ -85,9 +85,16 @@ class MassHoldTest extends \PHPUnit_Framework_TestCase */ protected $filterMock; + /** + * @var \Magento\Sales\Api\OrderManagementInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderManagementMock; + public function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); + $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', @@ -162,7 +169,8 @@ public function setUp() [ 'context' => $this->contextMock, 'filter' => $this->filterMock, - 'collectionFactory' => $this->orderCollectionFactoryMock + 'collectionFactory' => $this->orderCollectionFactoryMock, + 'orderManagement' => $this->orderManagementMock ] ); } @@ -186,11 +194,8 @@ public function testExecuteOneOrderPutOnHold() $order1->expects($this->once()) ->method('canHold') ->willReturn(true); - $order1->expects($this->once()) + $this->orderManagementMock->expects($this->once()) ->method('hold'); - $order1->expects($this->once()) - ->method('save'); - $this->orderCollectionMock->expects($this->once()) ->method('count') ->willReturn($countOrders); 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..eb3e51ad180f4 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,14 @@ 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') + ->getMockForAbstractClass(); $this->messageManagerMock = $this->getMock( 'Magento\Framework\Message\Manager', ['addSuccess', 'addError'], @@ -83,23 +102,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 +113,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 +122,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 +140,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..8968f887d15c7 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 @@ -86,8 +86,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 +139,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 +157,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 +184,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 +205,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 +241,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,14 +264,10 @@ 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); } /** @@ -255,9 +275,6 @@ protected function initOrder() */ protected function initOrderSuccess($orderId) { - $this->orderMock->expects($this->atLeastOnce()) - ->method('getId') - ->willReturn($orderId); $this->coreRegistryMock->expects($this->exactly(2)) ->method('register') ->withConsecutive( @@ -268,9 +285,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/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php b/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php index dbf5d56032a3d..7d7d1f5bd2baf 100644 --- a/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php +++ b/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php @@ -73,8 +73,7 @@ public function addFilter(\Magento\Framework\Api\Filter $filter) public function addSortOrder($field, $direction) { $this->sortOrderBuilder->setDirection($direction) - ->setField($field) - ->create(); + ->setField($field); return $this; } diff --git a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php index 417a156eca412..61d8695fad69a 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/Reporting.php @@ -46,6 +46,11 @@ public function search(SearchCriteriaInterface $searchCriteria) $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; } } From 479f664d75d4e94ad4328aaffdc9e6e2395bdecd Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Fri, 7 Aug 2015 13:57:08 +0300 Subject: [PATCH 68/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Sales/Controller/Adminhtml/Order.php | 4 ++++ .../Sales/Controller/Adminhtml/Order/CommentsHistory.php | 1 + .../Magento/Sales/Controller/Adminhtml/Order/MassHold.php | 1 + .../Sales/Test/Unit/Controller/Adminhtml/Order/EmailTest.php | 2 +- .../Sales/Test/Unit/Controller/Adminhtml/Order/ViewTest.php | 5 +++-- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order.php b/app/code/Magento/Sales/Controller/Adminhtml/Order.php index 82c20141c31c8..4d9a4594bd19e 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order.php @@ -87,8 +87,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, diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php index e48079b1faa3c..daaecb7f7d7a6 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php @@ -33,6 +33,7 @@ class CommentsHistory extends \Magento\Sales\Controller\Adminhtml\Order * @param \Magento\Framework\View\LayoutFactory $layoutFactory * * @SuppressWarnings(PHPMD.ExcessiveParameterList) + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ public function __construct( Action\Context $context, diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php index bbb377bef9045..9f660fd61f6cd 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/MassHold.php @@ -25,6 +25,7 @@ class MassHold extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAct * @param Context $context * @param Filter $filter * @param CollectionFactory $collectionFactory + * @param OrderManagementInterface $orderManagement */ public function __construct( Context $context, 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 394a4934c67ce..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 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 8968f887d15c7..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 { @@ -271,9 +272,9 @@ protected function initOrder() } /** - * @param int $orderId + * init Order Success */ - protected function initOrderSuccess($orderId) + protected function initOrderSuccess() { $this->coreRegistryMock->expects($this->exactly(2)) ->method('register') From b160b508169c10b6367327bf546c7ada3d8bba3e Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Fri, 7 Aug 2015 13:59:53 +0300 Subject: [PATCH 69/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Sales/Api/Data/OrderInterface.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/code/Magento/Sales/Api/Data/OrderInterface.php b/app/code/Magento/Sales/Api/Data/OrderInterface.php index e307ea19b1401..f77102b27e462 100644 --- a/app/code/Magento/Sales/Api/Data/OrderInterface.php +++ b/app/code/Magento/Sales/Api/Data/OrderInterface.php @@ -1595,14 +1595,6 @@ public function getPayments(); */ public function getPayment(); - /** - * Set actual payment for the order - * - * @param \Magento\Sales\Api\Data\OrderPaymentInterface $payment - * @return $this - */ - public function setPayment(\Magento\Sales\Api\Data\OrderPaymentInterface $payment); - /** * Sets the payments for the order. * From e46a3897220b762228add4160e91219703d7394e Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Fri, 7 Aug 2015 14:16:05 +0300 Subject: [PATCH 70/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Sales/Controller/Adminhtml/Order.php | 1 + .../Sales/Controller/Adminhtml/Order/CommentsHistory.php | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order.php b/app/code/Magento/Sales/Controller/Adminhtml/Order.php index 4d9a4594bd19e..e01a90268b62f 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order.php @@ -16,6 +16,7 @@ * * @author Magento Core Team * @SuppressWarnings(PHPMD.NumberOfChildren) + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ abstract class Order extends \Magento\Backend\App\Action { diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php index daaecb7f7d7a6..54774ec719e7d 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/CommentsHistory.php @@ -11,6 +11,10 @@ use Magento\Sales\Api\OrderRepositoryInterface; use Psr\Log\LoggerInterface; +/** + * Class CommentsHistory + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class CommentsHistory extends \Magento\Sales\Controller\Adminhtml\Order { /** From f01956dfe9b0945f53e0f804a39b50a6922e3c46 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Fri, 7 Aug 2015 17:21:03 +0300 Subject: [PATCH 71/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Sales/Api/Data/OrderInterface.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/code/Magento/Sales/Api/Data/OrderInterface.php b/app/code/Magento/Sales/Api/Data/OrderInterface.php index f77102b27e462..a4376b9eb81a7 100644 --- a/app/code/Magento/Sales/Api/Data/OrderInterface.php +++ b/app/code/Magento/Sales/Api/Data/OrderInterface.php @@ -1588,13 +1588,6 @@ public function setShippingAddress(\Magento\Sales\Api\Data\OrderAddressInterface */ public function getPayments(); - /** - * Gets actual payment for the order it it exists, false if not - * - * @return \Magento\Sales\Api\Data\OrderPaymentInterface|false - */ - public function getPayment(); - /** * Sets the payments for the order. * From ec44a35de0932f3a82ba0264c12078ecec9a4e20 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Fri, 7 Aug 2015 17:34:24 +0300 Subject: [PATCH 72/73] MAGETWO-39905: UI components compatibility with Search API --- .../Test/Unit/Controller/Adminhtml/Order/ReviewPaymentTest.php | 1 + 1 file changed, 1 insertion(+) 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 eb3e51ad180f4..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 @@ -77,6 +77,7 @@ protected function setUp() $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', From 7987275bc52e0098e25aa4566a09811bde089929 Mon Sep 17 00:00:00 2001 From: Anton Kaplya Date: Mon, 10 Aug 2015 12:28:45 +0300 Subject: [PATCH 73/73] MAGETWO-39905: UI components compatibility with Search API --- app/code/Magento/Sales/Controller/Adminhtml/Order.php | 5 +++++ app/code/Magento/Sales/Model/OrderRepository.php | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order.php b/app/code/Magento/Sales/Controller/Adminhtml/Order.php index e01a90268b62f..32e3e51051881 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Order.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Order.php @@ -9,6 +9,7 @@ use Magento\Sales\Api\OrderManagementInterface; use Magento\Sales\Api\OrderRepositoryInterface; use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Exception\InputException; use Psr\Log\LoggerInterface; /** @@ -149,6 +150,10 @@ protected function _initOrder() $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; } $this->_coreRegistry->register('sales_order', $order); $this->_coreRegistry->register('current_order', $order); 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; }