1
- <?php
1
+ <?php declare (strict_types= 1 );
2
2
/**
3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
8
8
use Magento \Framework \View \Element \UiComponentFactory ;
9
9
use Magento \Framework \View \Element \UiComponent \ContextInterface ;
10
10
use Magento \Store \Model \StoreManagerInterface ;
11
+ use \Magento \Framework \DB \Helper ;
11
12
12
13
/**
13
14
* @api
@@ -20,29 +21,42 @@ class Websites extends \Magento\Ui\Component\Listing\Columns\Column
20
21
*/
21
22
const NAME = 'websites ' ;
22
23
24
+ /**
25
+ * Data for concatenated website names value
26
+ */
27
+ const WEBSITE_NAMES = 'website_names ' ;
28
+
23
29
/**
24
30
* Store manager
25
31
*
26
32
* @var StoreManagerInterface
27
33
*/
28
34
protected $ storeManager ;
29
35
36
+ /**
37
+ * @var \Magento\Framework\DB\Helper
38
+ */
39
+ protected $ _resourceHelper ;
40
+
30
41
/**
31
42
* @param ContextInterface $context
32
43
* @param UiComponentFactory $uiComponentFactory
33
44
* @param StoreManagerInterface $storeManager
45
+ * @param Helper $resourceHelper
34
46
* @param array $components
35
47
* @param array $data
36
48
*/
37
49
public function __construct (
38
50
ContextInterface $ context ,
39
51
UiComponentFactory $ uiComponentFactory ,
40
52
StoreManagerInterface $ storeManager ,
53
+ Helper $ resourceHelper ,
41
54
array $ components = [],
42
55
array $ data = []
43
56
) {
44
57
parent ::__construct ($ context , $ uiComponentFactory , $ components , $ data );
45
58
$ this ->storeManager = $ storeManager ;
59
+ $ this ->_resourceHelper = $ resourceHelper ;
46
60
}
47
61
48
62
/**
@@ -83,4 +97,46 @@ public function prepare()
83
97
$ this ->_data ['config ' ]['componentDisabled ' ] = true ;
84
98
}
85
99
}
100
+
101
+ /**
102
+ * Apply sorting
103
+ *
104
+ * @return void
105
+ */
106
+ protected function applySorting ()
107
+ {
108
+ $ sorting = $ this ->getContext ()->getRequestParam ('sorting ' );
109
+ $ isSortable = $ this ->getData ('config/sortable ' );
110
+ if ($ isSortable !== false
111
+ && !empty ($ sorting ['field ' ])
112
+ && !empty ($ sorting ['direction ' ])
113
+ && $ sorting ['field ' ] === $ this ->getName ()
114
+ ) {
115
+ $ collection = $ this ->getContext ()->getDataProvider ()->getCollection ();
116
+ $ collection
117
+ ->joinField (
118
+ 'websites_ids ' ,
119
+ 'catalog_product_website ' ,
120
+ 'website_id ' ,
121
+ 'product_id=entity_id ' ,
122
+ null ,
123
+ 'left '
124
+ )
125
+ ->joinTable (
126
+ 'store_website ' ,
127
+ 'website_id = websites_ids ' ,
128
+ ['name ' ],
129
+ null ,
130
+ 'left '
131
+ )
132
+ ->groupByAttribute ('entity_id ' );
133
+ $ this ->_resourceHelper ->addGroupConcatColumn (
134
+ $ collection ->getSelect (),
135
+ self ::WEBSITE_NAMES ,
136
+ 'name '
137
+ );
138
+
139
+ $ collection ->getSelect ()->order (self ::WEBSITE_NAMES . ' ' . $ sorting ['direction ' ]);
140
+ }
141
+ }
86
142
}
0 commit comments