forked from integer-net/M2E
/
Grid.php
319 lines (270 loc) · 11.2 KB
/
Grid.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
/*
* @copyright Copyright (c) 2013 by ESS-UA.
*/
class Ess_M2ePro_Block_Adminhtml_Common_Play_Listing_Grid extends Ess_M2ePro_Block_Adminhtml_Listing_Grid
{
// ########################################
public function __construct()
{
parent::__construct();
// Initialization block
//------------------------------
$this->setId('playListingGrid');
//------------------------------
}
protected function _prepareCollection()
{
// Update statistic table values
Mage::getResourceModel('M2ePro/Listing')->updateStatisticColumns();
// Get collection of listings
$collection = Mage::helper('M2ePro/Component_Play')->getCollection('Listing');
// Set global filters
//--------------------------
$filterSellingFormatTemplate = $this->getRequest()->getParam('filter_play_selling_format_template');
$filterSynchronizationTemplate = $this->getRequest()->getParam('filter_play_synchronization_template');
if ($filterSellingFormatTemplate != 0) {
$collection->addFieldToFilter(
'second_table.template_selling_format_id', (int)$filterSellingFormatTemplate
);
}
if ($filterSynchronizationTemplate != 0) {
$collection->addFieldToFilter(
'second_table.template_synchronization_id', (int)$filterSynchronizationTemplate
);
}
//--------------------------
// join accounts
//--------------------------
$collection->getSelect()
->join(array('a'=>Mage::getResourceModel('M2ePro/Account')->getMainTable()),
'(`a`.`id` = `main_table`.`account_id`)',
array('account_title'=>'title'));
//--------------------------
// exit($collection->getSelect()->__toString());
// Set collection to grid
$this->setCollection($collection);
return parent::_prepareCollection();
}
// ####################################
protected function _prepareMassaction()
{
// Set massaction identifiers
//--------------------------------
$this->setMassactionIdField('main_table.id');
$this->getMassactionBlock()->setFormFieldName('ids');
//--------------------------------
// Set clear log action
//--------------------------------
$backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
'*/adminhtml_common_listing/index',
array(
'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_PLAY
)
);
$this->getMassactionBlock()->addItem('clear_logs', array(
'label' => Mage::helper('M2ePro')->__('Clear Log(s)'),
'url' => $this->getUrl('*/adminhtml_listing/clearLog', array('back' => $backUrl)),
'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
));
//--------------------------------
// Set remove listings action
//--------------------------------
$this->getMassactionBlock()->addItem('delete_listings', array(
'label' => Mage::helper('M2ePro')->__('Delete Listing(s)'),
'url' => $this->getUrl('*/adminhtml_common_play_listing/delete'),
'confirm' => Mage::helper('M2ePro')->__('Are you sure?')
));
//--------------------------------
return parent::_prepareMassaction();
}
// ####################################
protected function getColumnActionsItems()
{
$helper = Mage::helper('M2ePro');
$backUrl = $helper->makeBackUrlParam(
'*/adminhtml_common_listing/index',
array(
'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_PLAY
)
);
$actions = array(
'manageProducts' => array(
'caption' => $helper->__('Manage'),
'group' => 'products_actions',
'field' => 'id',
'url' => array(
'base' => '*/adminhtml_common_play_listing/view',
'params' => array('back' => $backUrl)
)
),
'addProductsFromProductsList' => array(
'caption' => $helper->__('Add From Products List'),
'group' => 'products_actions',
'field' => 'id',
'url' => array(
'base' => '*/adminhtml_common_listing_productAdd/index',
'params' => array(
'back' => $backUrl,
'component' => Ess_M2ePro_Helper_Component_Play::NICK,
'step' => 2,
'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_LIST
)
)
),
'addProductsFromCategories' => array(
'caption' => $helper->__('Add From Categories'),
'group' => 'products_actions',
'field' => 'id',
'url' => array(
'base' => '*/adminhtml_common_listing_productAdd/index',
'params' => array(
'back' => $backUrl,
'component' => Ess_M2ePro_Helper_Component_Play::NICK,
'step' => 2,
'source' => Ess_M2ePro_Block_Adminhtml_Common_Listing_Add_SourceMode::SOURCE_CATEGORIES
)
)
),
'automaticActions' => array(
'caption' => $helper->__('Auto Add/Remove Rules'),
'group' => 'products_actions',
'field' => 'id',
'url' => array(
'base' => '*/adminhtml_common_play_listing/view',
'params' => array(
'back' => $backUrl,
'auto_actions' => 1
)
)
),
'viewLog' => array(
'caption' => $helper->__('View Log'),
'group' => 'other',
'field' => 'id',
'url' => array(
'base' => '*/adminhtml_common_log/listing',
'params' => array(
'back' => $backUrl,
'channel' => Ess_M2ePro_Block_Adminhtml_Common_Log_Tabs::TAB_ID_PLAY
)
)
),
'clearLogs' => array(
'caption' => $helper->__('Clear Log'),
'confirm' => $helper->__('Are you sure?'),
'group' => 'other',
'field' => 'id',
'url' => array(
'base' => '*/adminhtml_listing/clearLog',
'params' => array(
'back' => $backUrl
)
)
),
'deleteListing' => array(
'caption' => $helper->__('Delete Listing'),
'confirm' => $helper->__('Are you sure?'),
'group' => 'other',
'field' => 'id',
'url' => array(
'base' => '*/adminhtml_common_play_listing/delete',
)
),
'editListingTitle' => array(
'caption' => $helper->__('Title'),
'confirm' => $helper->__('Are you sure?'),
'group' => 'edit_actions',
'field' => 'id',
'onclick_action' => 'editListingTitle'
),
'sellingSettings' => array(
'caption' => $helper->__('Selling'),
'group' => 'edit_actions',
'field' => 'id',
'url' => array(
'base' => '*/adminhtml_common_play_listing/edit',
'params' => array(
'back' => $backUrl,
'tab' => 'selling'
)
)
),
'searchSettings' => array(
'caption' => $helper->__('Search'),
'group' => 'edit_actions',
'field' => 'id',
'url' => array(
'base' => '*/adminhtml_common_play_listing/edit',
'params' => array(
'back' => $backUrl,
'tab' => 'search'
)
)
)
);
return $actions;
}
// ####################################
public function callbackColumnSoldProducts($value, $row, $column, $isExport)
{
return $this->getColumnValue($value);
}
public function callbackColumnTitle($value, $row, $column, $isExport)
{
$value = '<span id="listing_title_'.$row->getId().'">' .
Mage::helper('M2ePro')->escapeHtml($value) .
'</span>';
/* @var $row Ess_M2ePro_Model_Listing */
$accountTitle = $row->getData('account_title');
$storeModel = Mage::getModel('core/store')->load($row->getStoreId());
$storeView = $storeModel->getWebsite()->getName();
if (strtolower($storeView) != 'admin') {
$storeView .= ' > '.$storeModel->getGroup()->getName();
$storeView .= ' > '.$storeModel->getName();
} else {
$storeView = Mage::helper('M2ePro')->__('Admin (Default Values)');
}
$account = Mage::helper('M2ePro')->__('Account');
$store = Mage::helper('M2ePro')->__('Magento Store View');
$value .= <<<HTML
<div>
<span style="font-weight: bold">{$account}</span>: <span style="color: #505050">{$accountTitle}</span><br/>
<span style="font-weight: bold">{$store}</span>: <span style="color: #505050">{$storeView}</span>
</div>
HTML;
return $value;
}
// ####################################
protected function callbackFilterTitle($collection, $column)
{
$value = $column->getFilter()->getValue();
if ($value == null) {
return;
}
$where = "main_table.title LIKE '%{$value}%' OR a.title LIKE '%{$value}%'";
$collection->getSelect()->where($where);
}
// ####################################
public function getGridUrl()
{
return $this->getUrl('*/adminhtml_common_play_listing/listingGrid', array('_current'=>true));
}
public function getRowUrl($row)
{
$backUrl = Mage::helper('M2ePro')->makeBackUrlParam(
'*/adminhtml_common_listing/index',
array(
'tab' => Ess_M2ePro_Block_Adminhtml_Common_Component_Abstract::TAB_ID_PLAY
)
);
return $this->getUrl(
'*/adminhtml_common_play_listing/view',
array(
'id' => $row->getId(),
'back' => $backUrl
)
);
}
// ####################################
}