forked from samir86mca09/magento
/
Templates.php
181 lines (145 loc) · 7.07 KB
/
Templates.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
<?php
/*
* @copyright Copyright (c) 2013 by ESS-UA.
*/
class Ess_M2ePro_Model_Ebay_Synchronization_Tasks_Templates extends Ess_M2ePro_Model_Ebay_Synchronization_Tasks
{
// ->__('Task "Inventory Synchronization" has completed with errors. View %sl%listings log%el% for details.');
// ->__('Task "Inventory Synchronization" has completed with warnings. View %sl%listings log%el% for details.');
//####################################
const PERCENTS_START = 0;
const PERCENTS_END = 100;
const PERCENTS_INTERVAL = 100;
//####################################
public function process()
{
// Check tasks config mode
//-----------------------------
$config = Mage::helper('M2ePro/Module')->getSynchronizationConfig();
$listMode = (bool)(int)$config->getGroupValue('/ebay/templates/list/','mode');
$reviseMode = (bool)(int)$config->getGroupValue('/ebay/templates/revise/','mode');
$relistMode = (bool)(int)$config->getGroupValue('/ebay/templates/relist/','mode');
$stopMode = (bool)(int)$config->getGroupValue('/ebay/templates/stop/','mode');
if (!$listMode && !$reviseMode && !$relistMode && !$stopMode) {
return false;
}
//-----------------------------
// PREPARE SYNCH
//---------------------------
$this->prepareSynch();
$this->createRunnerActions();
//---------------------------
// GET TEMPLATES
//---------------------------
$this->_profiler->addEol();
$this->_lockItem->setPercents(self::PERCENTS_START + 5);
$this->_lockItem->activate();
//---------------------------
// RUN CHILD SYNCH
//---------------------------
if ($listMode) {
$tempSynch = new Ess_M2ePro_Model_Ebay_Synchronization_Tasks_Templates_List();
$tempSynch->process();
}
if ($reviseMode) {
$tempSynch = new Ess_M2ePro_Model_Ebay_Synchronization_Tasks_Templates_Revise();
$tempSynch->process();
}
if ($relistMode) {
$tempSynch = new Ess_M2ePro_Model_Ebay_Synchronization_Tasks_Templates_Relist();
$tempSynch->process();
}
if ($stopMode) {
$tempSynch = new Ess_M2ePro_Model_Ebay_Synchronization_Tasks_Templates_Stop();
$tempSynch->process();
}
//---------------------------
// UNSET TEMPLATES
//---------------------------
Ess_M2ePro_Model_Ebay_Synchronization_Tasks_Templates_Abstract::clearCache();
//---------------------------
// CANCEL SYNCH
//---------------------------
$this->executeRunnerActions();
$this->cancelSynch();
//---------------------------
}
//####################################
private function prepareSynch()
{
$this->_lockItem->activate();
$this->_logs->setSynchronizationTask(Ess_M2ePro_Model_Synchronization_Log::SYNCH_TASK_TEMPLATES);
if (count(Mage::helper('M2ePro/Component')->getActiveComponents()) > 1) {
$componentName = Ess_M2ePro_Helper_Component_Ebay::TITLE.' ';
} else {
$componentName = '';
}
$this->_profiler->addEol();
$this->_profiler->addTitle($componentName.'Inventory Synchronization');
$this->_profiler->addTitle('--------------------------');
$this->_profiler->addTimePoint(__CLASS__,'Total time');
$this->_profiler->increaseLeftPadding(5);
$this->_lockItem->setTitle(Mage::helper('M2ePro')->__($componentName.'Inventory Synchronization'));
$this->_lockItem->setPercents(self::PERCENTS_START);
$this->_lockItem->setStatus(
Mage::helper('M2ePro')->__('Task "Inventory Synchronization" is started. Please wait...')
);
}
private function cancelSynch()
{
$this->_lockItem->setPercents(self::PERCENTS_END);
$this->_lockItem->setStatus(
Mage::helper('M2ePro')->__('Task "Inventory Synchronization" is finished. Please wait...')
);
$this->_profiler->decreaseLeftPadding(5);
$this->_profiler->addEol();
$this->_profiler->addTitle('--------------------------');
$this->_profiler->saveTimePoint(__CLASS__);
$this->_logs->setSynchronizationTask(Ess_M2ePro_Model_Synchronization_Log::SYNCH_TASK_UNKNOWN);
$this->_lockItem->activate();
}
//####################################
private function createRunnerActions()
{
$runnerActionsModel = Mage::getModel('M2ePro/Ebay_Template_Synchronization_RunnerActions');
$runnerActionsModel->removeAllProducts();
Mage::helper('M2ePro/Data_Global')->setValue('synchRunnerActions',$runnerActionsModel);
$this->_runnerActions = $runnerActionsModel;
}
private function executeRunnerActions()
{
$this->_profiler->addEol();
$this->_profiler->addTimePoint(__METHOD__,'Apply products changes on eBay');
$result = $this->_runnerActions->execute($this->_lockItem,
self::PERCENTS_START + 60,
self::PERCENTS_END);
$startLink = '<a target="_blank" href="route:*/adminhtml_ebay_log/listing/;';
$startLink .= 'back:*/adminhtml_ebay_log/synchronization/;">';
$endLink = '</a>';
if ($result == Ess_M2ePro_Helper_Data::STATUS_ERROR) {
$tempString = Mage::getModel('M2ePro/Log_Abstract')->encodeDescription(
'Task "Inventory Synchronization" has completed with errors. View %sl%listings log%el% for details.',
array('!sl'=>$startLink,'!el'=>$endLink)
);
$this->_logs->addMessage($tempString,
Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR,
Ess_M2ePro_Model_Log_Abstract::PRIORITY_HIGH);
$this->_profiler->addTitle('Updating products on eBay ended with errors.');
}
if ($result == Ess_M2ePro_Helper_Data::STATUS_WARNING) {
$tempString = Mage::getModel('M2ePro/Log_Abstract')->encodeDescription(
'Task "Inventory Synchronization" has completed with warnings. View %sl%listings log%el% for details.',
array('!sl'=>$startLink,'!el'=>$endLink)
);
$this->_logs->addMessage($tempString,
Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING,
Ess_M2ePro_Model_Log_Abstract::PRIORITY_MEDIUM);
$this->_profiler->addTitle('Updating products on eBay ended with warnings.');
}
$this->_runnerActions->removeAllProducts();
Mage::helper('M2ePro/Data_Global')->unsetValue('synchRunnerActions');
$this->_runnerActions = NULL;
$this->_profiler->saveTimePoint(__METHOD__);
}
//####################################
}