Version Notes
Fixes:
- Image sync running perpetually when not permitted.
- Image sync single API call for all EANs to sync instead of 1 call per EAN
- Some code refactoring.
Download this release
Release Info
Developer | Divide BV |
Extension | Stockbase |
Version | 1.1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0.3 to 1.1.1
- app/code/local/Divide/Stockbase/Block/Config.php +15 -15
- app/code/local/Divide/Stockbase/Helper/Data.php +72 -29
- app/code/local/Divide/Stockbase/Helper/HTTP.php +458 -474
- app/code/local/Divide/Stockbase/Model/Crons.php +89 -71
- app/code/local/Divide/Stockbase/Model/Enviroment.php +26 -26
- app/code/local/Divide/Stockbase/Model/Observer.php +67 -67
- app/code/local/Divide/Stockbase/Model/Options.php +33 -33
- app/code/local/Divide/Stockbase/controllers/Adminhtml/ConfigController.php +66 -66
- app/code/local/Divide/Stockbase/etc/config.xml +149 -149
- app/code/local/Divide/Stockbase/etc/system.xml +1 -1
- app/code/local/Divide/Stockbase/sql/stock_setup/mysql4-upgrade-1.0.4-1.1.0.php +108 -0
- app/design/adminhtml/default/default/layout/stockbase.xml +0 -8
- package.xml +17 -18
app/code/local/Divide/Stockbase/Block/Config.php
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Divide_Stockbase_Block_Config extends Mage_Adminhtml_Block_Template
|
4 |
-
{
|
5 |
-
/**
|
6 |
-
* Config Block constructor
|
7 |
-
* Constructs the page and loads the phtml-template
|
8 |
-
* See app/design/default/default/layout & /template for these files.
|
9 |
-
*/
|
10 |
-
public function __construct()
|
11 |
-
{
|
12 |
-
parent::__construct();
|
13 |
-
$this->setTemplate('stockbase/config.phtml');
|
14 |
-
}
|
15 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Divide_Stockbase_Block_Config extends Mage_Adminhtml_Block_Template
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Config Block constructor
|
7 |
+
* Constructs the page and loads the phtml-template
|
8 |
+
* See app/design/default/default/layout & /template for these files.
|
9 |
+
*/
|
10 |
+
public function __construct()
|
11 |
+
{
|
12 |
+
parent::__construct();
|
13 |
+
$this->setTemplate('stockbase/config.phtml');
|
14 |
+
}
|
15 |
+
}
|
app/code/local/Divide/Stockbase/Helper/Data.php
CHANGED
@@ -1,29 +1,72 @@
|
|
1 |
-
<?php
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @property Divide_Stockbase_Helper_HTTP _requestHelper
|
5 |
+
*/
|
6 |
+
class Divide_Stockbase_Helper_Data extends Mage_Core_Helper_Abstract
|
7 |
+
{
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Holds the request helper HTTP for calls to Stockbase
|
11 |
+
*
|
12 |
+
* @var Divide_Stockbase_Helper_HTTP
|
13 |
+
*/
|
14 |
+
protected $_requestHelper;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Divide_Stockbase_Helper_Data constructor.
|
18 |
+
*/
|
19 |
+
public function __construct()
|
20 |
+
{
|
21 |
+
$this->_requestHelper = Mage::getSingleton('Divide_Stockbase_Helper_HTTP');
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Returns array with all product eans from this shop. Uses
|
26 |
+
* the configured field in Stockbase settings to retrieve the ean values.
|
27 |
+
*
|
28 |
+
* @return array
|
29 |
+
*/
|
30 |
+
public function getAllEans()
|
31 |
+
{
|
32 |
+
$attribute = Mage::getStoreConfig('stockbase_options/login/stockbase_ean_field');
|
33 |
+
$collection = Mage::getModel('catalog/product')->getCollection();
|
34 |
+
$storeId = Mage::app()->getStore()->getStoreId();
|
35 |
+
|
36 |
+
$eans = array();
|
37 |
+
foreach ($collection as $product) {
|
38 |
+
$value = Mage::getResourceModel('catalog/product')
|
39 |
+
->getAttributeRawValue($product->getId(), $attribute, $storeId);
|
40 |
+
|
41 |
+
if ($value) {
|
42 |
+
$eans[] = $value;
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
return $eans;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Collect all EANS from user Stockbase account in a array.
|
51 |
+
*
|
52 |
+
* @return type
|
53 |
+
*/
|
54 |
+
public function getAllEansFromStockbase()
|
55 |
+
{
|
56 |
+
$stockbaseStock = $this->getStock();
|
57 |
+
$eans = array();
|
58 |
+
|
59 |
+
foreach ($stockbaseStock->{'Groups'} as $group) {
|
60 |
+
foreach ($group->{'Items'} as $brand) {
|
61 |
+
$eans[] = $brand->EAN;
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
return $eans;
|
66 |
+
}
|
67 |
+
|
68 |
+
public function getStock()
|
69 |
+
{
|
70 |
+
return $this->_requestHelper->getStock();
|
71 |
+
}
|
72 |
+
}
|
app/code/local/Divide/Stockbase/Helper/HTTP.php
CHANGED
@@ -1,474 +1,458 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
*
|
10 |
-
*
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
const
|
15 |
-
const
|
16 |
-
const
|
17 |
-
const
|
18 |
-
const
|
19 |
-
const
|
20 |
-
const
|
21 |
-
const
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
protected $
|
26 |
-
protected $
|
27 |
-
protected $
|
28 |
-
protected $
|
29 |
-
protected $
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
$this->
|
50 |
-
$this->
|
51 |
-
$this->
|
52 |
-
$this->
|
53 |
-
$this->
|
54 |
-
$this->
|
55 |
-
$this->
|
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 |
-
$response
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
Mage::getModel('core/config')
|
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 |
-
$result = json_decode($loginClient->request('GET')->getBody());
|
145 |
-
$response = $result->{'nl.divide.iq'};
|
146 |
-
|
147 |
-
if ($response->answer == self::ANSWER_SUCCESS) {
|
148 |
-
Mage::getModel('core/config')
|
149 |
-
|
150 |
-
Mage::getModel('core/config')
|
151 |
-
|
152 |
-
|
153 |
-
return $response->authentication_token;
|
154 |
-
}
|
155 |
-
|
156 |
-
return false;
|
157 |
-
}
|
158 |
-
|
159 |
-
/**
|
160 |
-
* Sends order to Stockbase if ordered quantity
|
161 |
-
* is not met by own stocklevels.
|
162 |
-
*
|
163 |
-
* @param Mage_Sales_Model_Order $mageOrder
|
164 |
-
*
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
$
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
$parsedAddress['
|
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 |
-
if
|
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 |
-
if
|
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 |
-
return $
|
319 |
-
}
|
320 |
-
|
321 |
-
/**
|
322 |
-
*
|
323 |
-
*
|
324 |
-
*
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
*
|
352 |
-
*
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
$
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
if ($product->getMediaGallery() == null) {
|
460 |
-
$product->setMediaGallery(['images' => [], 'values' => []]);
|
461 |
-
}
|
462 |
-
$product->addImageToMediaGallery(
|
463 |
-
$filePath,
|
464 |
-
['image', 'small_image', 'thumbnail'],
|
465 |
-
false,
|
466 |
-
false
|
467 |
-
);
|
468 |
-
$product->save();
|
469 |
-
}
|
470 |
-
}
|
471 |
-
|
472 |
-
return true;
|
473 |
-
}
|
474 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class Divide_Stockbase_Helper_HTTP
|
5 |
+
*/
|
6 |
+
class Divide_Stockbase_Helper_HTTP extends Mage_Core_Helper_Abstract
|
7 |
+
{
|
8 |
+
/**
|
9 |
+
* Webservice ENDPOINTS, & ANSWERS
|
10 |
+
* Live: https://iqservice.divide.nl/
|
11 |
+
* Dev: http://server.divide.nl/divide.api/
|
12 |
+
* Docs: http://server.divide.nl/divide.api/docs
|
13 |
+
*/
|
14 |
+
const ENDPOINT_LOGIN = 'services/login';
|
15 |
+
const ENDPOINT_AUTH = 'authenticate';
|
16 |
+
const ENDPOINT_STOCKBASE_STOCK = 'stockbase/stock';
|
17 |
+
const ENDPOINT_STOCKBASE_ORDER = 'stockbase/orderRequest';
|
18 |
+
const ENDPOINT_STOCKBASE_IMAGES = 'stockbase/images';
|
19 |
+
const ANSWER_INVALID_CREDENTIALS = 'LoginCredentialsNotValid';
|
20 |
+
const ANSWER_EMPTY_CREDENTIALS = 'CredentialsEmpty';
|
21 |
+
const ANSWER_SUCCESS = 'Success';
|
22 |
+
const ANSWER_UNKNOWN = 'UnknownError';
|
23 |
+
const ANSWER_TOKEN_EXPIRED = 'TokenExpired';
|
24 |
+
|
25 |
+
protected $_authToken;
|
26 |
+
protected $_authTokenExpiration;
|
27 |
+
protected $_refreshToken;
|
28 |
+
protected $_accessToken;
|
29 |
+
protected $_client;
|
30 |
+
protected $_env;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Divide_Stockbase_Helper_HTTP constructor.
|
34 |
+
*/
|
35 |
+
public function __construct()
|
36 |
+
{
|
37 |
+
// Set mage storeview to default admin
|
38 |
+
Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
|
39 |
+
// Using UTC standards
|
40 |
+
$now = new DateTime('NOW', new DateTimeZone('UTC'));
|
41 |
+
// Varien HTTP Client for making request
|
42 |
+
$this->_client = new Varien_Http_Client();
|
43 |
+
// Varien File IO for write/read actions to filesystem
|
44 |
+
$this->file = new Varien_Io_File();
|
45 |
+
|
46 |
+
// Server configured to use (production or development)
|
47 |
+
$this->_env = Mage::getStoreConfig('stockbase_options/login/stockbase_enviroment');
|
48 |
+
// Client uses the REST Interface, set to be application/json for all calls.
|
49 |
+
$this->_client->setHeaders('Content-Type', 'application/json');
|
50 |
+
$this->_accessToken = Mage::getStoreConfig('stockbase_options/token/access');
|
51 |
+
$this->_authToken = Mage::getStoreConfig('stockbase_options/token/auth');
|
52 |
+
$this->_authTokenExpiration = Mage::getStoreConfig('stockbase_options/token/auth_expiration_date');
|
53 |
+
$this->accessTokenExpiration = Mage::getStoreConfig('stockbase_options/token/access_expiration_date');
|
54 |
+
$this->_refreshToken = Mage::getStoreConfig('stockbase_options/token/refresh');
|
55 |
+
$this->username = Mage::getStoreConfig('stockbase_options/login/username');
|
56 |
+
$this->password = Mage::getStoreConfig('stockbase_options/login/password');
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Authenticate with the authentication token
|
61 |
+
* for access and refresh tokens. refresh parameter
|
62 |
+
* forces to refresh tokens, otherwise accesstoken will
|
63 |
+
* be used by default.
|
64 |
+
*
|
65 |
+
* @param bool $refresh
|
66 |
+
*
|
67 |
+
* @return bool
|
68 |
+
*/
|
69 |
+
public function authenticate($refresh = false)
|
70 |
+
{
|
71 |
+
$authClient = new Zend_Http_Client($this->_env . self::ENDPOINT_AUTH);
|
72 |
+
$token = null;
|
73 |
+
|
74 |
+
// if refresh true, use refresh, but if not set, use auth instead
|
75 |
+
if ($refresh) {
|
76 |
+
$token = Mage::getStoreConfig('stockbase_options/token/refresh');
|
77 |
+
}
|
78 |
+
|
79 |
+
// Possible that we dont have refresh token yet, then fallback on the auth token to present
|
80 |
+
if (!$token) {
|
81 |
+
$token = Mage::getStoreConfig('stockbase_options/token/auth');
|
82 |
+
}
|
83 |
+
|
84 |
+
// If we still dont have token, login first then.
|
85 |
+
if ($token == null) {
|
86 |
+
$token = $this->login();
|
87 |
+
}
|
88 |
+
|
89 |
+
$headers = array(
|
90 |
+
'Content-Type' => 'application/json',
|
91 |
+
'Authentication' => $token,
|
92 |
+
);
|
93 |
+
$authClient->setHeaders($headers);
|
94 |
+
|
95 |
+
$result = json_decode($authClient->request('GET')->getBody());
|
96 |
+
$response = $result->{'nl.divide.iq'};
|
97 |
+
|
98 |
+
if ($response->answer == self::ANSWER_TOKEN_EXPIRED) {
|
99 |
+
$this->login($this->username, $this->password);
|
100 |
+
}
|
101 |
+
|
102 |
+
if ($response->answer == self::ANSWER_SUCCESS) {
|
103 |
+
if (isset($response->{'refresh_token'})) {
|
104 |
+
Mage::getModel('core/config')
|
105 |
+
->saveConfig('stockbase_options/token/refresh', $response->{'refresh_token'});
|
106 |
+
}
|
107 |
+
Mage::getModel('core/config')
|
108 |
+
->saveConfig('stockbase_options/token/access', $response->{'access_token'});
|
109 |
+
Mage::getModel('core/config')
|
110 |
+
->saveConfig('stockbase_options/token/access_expiration_date', $response->{'expiration_date'});
|
111 |
+
|
112 |
+
|
113 |
+
return true;
|
114 |
+
}
|
115 |
+
|
116 |
+
return false;
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Array with username & password for getting
|
121 |
+
* the authentication token and expiration date
|
122 |
+
*
|
123 |
+
* @param $username
|
124 |
+
* @param $password
|
125 |
+
*
|
126 |
+
* @return bool
|
127 |
+
*/
|
128 |
+
public function login($username = false, $password = false)
|
129 |
+
{
|
130 |
+
$loginClient = new Zend_Http_Client($this->_env . self::ENDPOINT_LOGIN);
|
131 |
+
|
132 |
+
if ($username == false || $password == false) {
|
133 |
+
$username = Mage::getStoreConfig('stockbase_options/login/username');
|
134 |
+
$password = Mage::getStoreConfig('stockbase_options/login/password');
|
135 |
+
}
|
136 |
+
|
137 |
+
$headers = array(
|
138 |
+
'Content-Type' => 'application/json',
|
139 |
+
'Username' => $username,
|
140 |
+
'Password' => $password,
|
141 |
+
);
|
142 |
+
$loginClient->setHeaders($headers);
|
143 |
+
|
144 |
+
$result = json_decode($loginClient->request('GET')->getBody());
|
145 |
+
$response = $result->{'nl.divide.iq'};
|
146 |
+
|
147 |
+
if ($response->answer == self::ANSWER_SUCCESS) {
|
148 |
+
Mage::getModel('core/config')
|
149 |
+
->saveConfig('stockbase_options/token/auth', $response->{'authentication_token'});
|
150 |
+
Mage::getModel('core/config')
|
151 |
+
->saveConfig('stockbase_options/token/auth_expiration_date', $response->{'expiration_date'});
|
152 |
+
|
153 |
+
return $response->{'authentication_token'};
|
154 |
+
}
|
155 |
+
|
156 |
+
return false;
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Sends order to Stockbase if ordered quantity
|
161 |
+
* is not met by own stocklevels.
|
162 |
+
*
|
163 |
+
* @param Mage_Sales_Model_Order $mageOrder
|
164 |
+
*
|
165 |
+
* @return bool
|
166 |
+
*/
|
167 |
+
public function sendMageOrder(Mage_Sales_Model_Order $mageOrder)
|
168 |
+
{
|
169 |
+
// Configured orderPrefix for keeping ordernumbers unique for merchant.
|
170 |
+
$orderPrefix = Mage::getStoreConfig('stockbase_options/login/order_prefix');
|
171 |
+
// Configured EAN field from stockbase configuration
|
172 |
+
$configuredEan = Mage::getStoreConfig('stockbase_options/login/stockbase_ean_field');
|
173 |
+
$shippingAddress = $mageOrder->getShippingAddress();
|
174 |
+
// Parsing street for seperation of street, number, and additional
|
175 |
+
$parsedAddress = $this->splitStreet($shippingAddress->getStreet1());
|
176 |
+
// StockbaseEANs from users Stockbase account
|
177 |
+
$sbEans = Mage::getSingleton('Divide_Stockbase_Helper_Data')->getAllEansFromStockbase();
|
178 |
+
// Using UTC TimeZone as standard
|
179 |
+
$now = new DateTime('now', new DateTimeZone('UTC'));
|
180 |
+
// Used for collecting items from order to send
|
181 |
+
$orderLines = array();
|
182 |
+
|
183 |
+
// If splitStreet fails, fallback to fullstreet.
|
184 |
+
if (!$parsedAddress['street'] || !$parsedAddress['number']) {
|
185 |
+
$parsedAddress['street'] = $shippingAddress->getStreetFull();
|
186 |
+
$parsedAddress['number'] = '-';
|
187 |
+
}
|
188 |
+
|
189 |
+
// Parsing Address fields from the Magento Order
|
190 |
+
$address = array(
|
191 |
+
'Street' => $parsedAddress['street'],
|
192 |
+
'StreetNumber' => (int)$parsedAddress['number'],
|
193 |
+
'StreetNumberAddition' => $parsedAddress['numberAddition'],
|
194 |
+
'ZipCode' => $shippingAddress->getPostcode(),
|
195 |
+
'City' => $shippingAddress->getCity(),
|
196 |
+
'CountryCode' => $shippingAddress->getCountryModel()->getIso3Code(),
|
197 |
+
);
|
198 |
+
|
199 |
+
// Filling Person details
|
200 |
+
$person = array(
|
201 |
+
'Gender' => $mageOrder->getCustomerGender() ? 'Female' : 'Male',
|
202 |
+
'Initials' => strtoupper($mageOrder->getCustomerFirstname()[0]),
|
203 |
+
'FirstName' => $mageOrder->getCustomerFirstname(),
|
204 |
+
'SurnamePrefix' => $mageOrder->getCustomerPrefix() ?: ' ',
|
205 |
+
'Surname' => $mageOrder->getCustomerLastname(),
|
206 |
+
'Company' => $mageOrder->getShippingAddress()->getCompany() ?: " ",
|
207 |
+
);
|
208 |
+
|
209 |
+
// Put the person and Adres in OrderDelivery Array
|
210 |
+
$orderDelivery = array(
|
211 |
+
'Person' => $person,
|
212 |
+
'Address' => $address,
|
213 |
+
);
|
214 |
+
|
215 |
+
// Loop over ordered items and check if there is a shortage on own stock
|
216 |
+
foreach ($mageOrder->getAllItems() as $key => $item) {
|
217 |
+
// Get stockitem from the orderedProduct to check with.
|
218 |
+
$stock = $item->getProduct()->getStockItem()->getQty();
|
219 |
+
|
220 |
+
// If out of stock && known by Stockbase,
|
221 |
+
// TypeCasting it into integer cuz Magento uses decimals for qty.
|
222 |
+
if ($stock < (int)$item->getQtyOrdered()) {
|
223 |
+
// Find the configured EAN for the product so we can identify it.
|
224 |
+
$ean = $item->getProduct()->getData($configuredEan);
|
225 |
+
// Now check if the ordered shortage exsists in your stockbase account.
|
226 |
+
if (in_array($ean, $sbEans)) {
|
227 |
+
// Finally fill up the orderlines to be send to stockbase.
|
228 |
+
$orderLines[] = array(
|
229 |
+
'Number' => $key + 1, // orderLineNumber starting from 1
|
230 |
+
'EAN' => $ean,
|
231 |
+
'Amount' => (int)$item->getQtyOrdered(),
|
232 |
+
);
|
233 |
+
}
|
234 |
+
}
|
235 |
+
}
|
236 |
+
|
237 |
+
// Compose the OrderHeader with the filled up data
|
238 |
+
$orderHeader = array(
|
239 |
+
'OrderNumber' => $orderPrefix . '#' . $mageOrder->getRealOrderId(),
|
240 |
+
'TimeStamp' => $now->format('Y-m-d h:i:s'),
|
241 |
+
'Attention' => $mageOrder->getCustomerNote() ? $mageOrder->getCustomerNote() : ' ',
|
242 |
+
);
|
243 |
+
|
244 |
+
// Compose the OrderRequest in final form for Stockbase
|
245 |
+
$orderRequest = array(
|
246 |
+
'OrderHeader' => $orderHeader,
|
247 |
+
'OrderLines' => $orderLines,
|
248 |
+
'OrderDelivery' => $orderDelivery,
|
249 |
+
);
|
250 |
+
|
251 |
+
// Only send the order if we have collected items to be ordered.
|
252 |
+
if (count($orderLines) > 1) {
|
253 |
+
$posted = $this->post(self::ENDPOINT_STOCKBASE_ORDER, $orderRequest)->{'nl.divide.iq'};
|
254 |
+
}
|
255 |
+
|
256 |
+
// If failure, we log request and response for debugging.
|
257 |
+
if (!$posted->response->content->StatusCode == 1) {
|
258 |
+
// We log errors to stockbase-failure.txt in the /var/log/ folder of Magento
|
259 |
+
Mage::log(var_export($posted, true), false, 'stockbase-failure.txt');
|
260 |
+
|
261 |
+
return false;
|
262 |
+
}
|
263 |
+
|
264 |
+
return true;
|
265 |
+
}
|
266 |
+
|
267 |
+
/**
|
268 |
+
* Magento street comes with housenumber attached to it, this
|
269 |
+
* method tries to seperate the Street, housnumber, and additions.
|
270 |
+
*
|
271 |
+
* @param string $street
|
272 |
+
*
|
273 |
+
* @return array
|
274 |
+
*/
|
275 |
+
protected function splitStreet($street)
|
276 |
+
{
|
277 |
+
$aMatch = array();
|
278 |
+
$pattern = '#^([\w[:punct:] ]+) ([0-9]{1,5})([\w[:punct:]\-/]*)$#';
|
279 |
+
$matchResult = preg_match($pattern, $street, $aMatch);
|
280 |
+
|
281 |
+
$street = (isset($aMatch[1])) ? $aMatch[1] : '';
|
282 |
+
$number = (isset($aMatch[2])) ? $aMatch[2] : '';
|
283 |
+
$numberAddition = (isset($aMatch[3])) ? $aMatch[3] : '';
|
284 |
+
|
285 |
+
return array(
|
286 |
+
'street' => $street,
|
287 |
+
'number' => $number,
|
288 |
+
'numberAddition' => $numberAddition,
|
289 |
+
);
|
290 |
+
}
|
291 |
+
|
292 |
+
/**
|
293 |
+
* Post a payload to a endpoint. See
|
294 |
+
* defined ENDPOINT constants in HTTP Helper.
|
295 |
+
*
|
296 |
+
* @param $endpoint
|
297 |
+
* @param array $payload
|
298 |
+
*
|
299 |
+
* @return mixed
|
300 |
+
*/
|
301 |
+
protected function post($endpoint, $payload = array())
|
302 |
+
{
|
303 |
+
if (!$this->hasAccessToken()) {
|
304 |
+
$this->authenticate(true);
|
305 |
+
}
|
306 |
+
|
307 |
+
$this->_client->setUri($this->_env . $endpoint);
|
308 |
+
$this->_client->setHeaders('Authentication', $this->_accessToken);
|
309 |
+
$result = $this->_client->setRawData(json_encode($payload), "application/json;charset=UTF-8")->request('POST');
|
310 |
+
$response = json_decode($result->getBody());
|
311 |
+
|
312 |
+
if (!$response) {
|
313 |
+
Mage::log(var_export($result->getBody(), true), false, 'stockbase-curl-failure.txt');
|
314 |
+
|
315 |
+
return $result;
|
316 |
+
}
|
317 |
+
|
318 |
+
return $response;
|
319 |
+
}
|
320 |
+
|
321 |
+
/**
|
322 |
+
* Check if accesstoken is set from magento's config.
|
323 |
+
*
|
324 |
+
* @return bool
|
325 |
+
*/
|
326 |
+
protected function hasAccessToken()
|
327 |
+
{
|
328 |
+
return (bool)$this->_accessToken;
|
329 |
+
}
|
330 |
+
|
331 |
+
/**
|
332 |
+
* Returns simpleXMLElement with Stock (beginning from group)
|
333 |
+
* Debug param defaults to false, gives debug info about request if true.
|
334 |
+
*
|
335 |
+
* @param bool $debug
|
336 |
+
*
|
337 |
+
* @return SimpleXMLElement
|
338 |
+
*/
|
339 |
+
public function getStock($debug = false)
|
340 |
+
{
|
341 |
+
return $this->call(self::ENDPOINT_STOCKBASE_STOCK, $debug);
|
342 |
+
}
|
343 |
+
|
344 |
+
/**
|
345 |
+
* Makes the final call (the request)to the
|
346 |
+
* given webservice endpoint. Should only be
|
347 |
+
* used internally by this class.
|
348 |
+
*
|
349 |
+
* @param $endpoint
|
350 |
+
* @param bool $debug
|
351 |
+
*
|
352 |
+
* @return $response (json_decoded body)
|
353 |
+
*/
|
354 |
+
protected function call($endpoint, $debug = false)
|
355 |
+
{
|
356 |
+
if (!$this->hasAccessToken()) {
|
357 |
+
$this->authenticate(true);
|
358 |
+
}
|
359 |
+
|
360 |
+
$this->_client->setUri($this->_env . $endpoint);
|
361 |
+
$this->_client->setHeaders('Authentication', $this->_accessToken);
|
362 |
+
|
363 |
+
$result = json_decode($this->_client->request()->getBody());
|
364 |
+
|
365 |
+
if ($result->{'nl.divide.iq'}->response->answer == self::ANSWER_SUCCESS) {
|
366 |
+
if (!$debug) {
|
367 |
+
return $result->{'nl.divide.iq'}->response->content;
|
368 |
+
}
|
369 |
+
|
370 |
+
return $result->{'nl.divide.iq'};
|
371 |
+
}
|
372 |
+
}
|
373 |
+
|
374 |
+
/**
|
375 |
+
* Will return image if available at stockbase for given EAN.
|
376 |
+
*
|
377 |
+
* @param string|array $eans
|
378 |
+
*
|
379 |
+
* @return array
|
380 |
+
*/
|
381 |
+
public function getImageForEan($eans)
|
382 |
+
{
|
383 |
+
// Make sure `$eans` is an array.
|
384 |
+
$eans = is_array($eans) ? $eans : array($eans);
|
385 |
+
|
386 |
+
// Create the HTTP client.
|
387 |
+
$url = $this->_env . self::ENDPOINT_STOCKBASE_IMAGES;
|
388 |
+
$imageClient = new Zend_Http_Client("{$url}?ean=" . implode(',', $eans));
|
389 |
+
|
390 |
+
// Add the required headers.
|
391 |
+
$headers = array(
|
392 |
+
'Content-Type' => 'application/json',
|
393 |
+
'Authentication' => Mage::getStoreConfig('stockbase_options/token/access'),
|
394 |
+
);
|
395 |
+
$imageClient->setHeaders($headers);
|
396 |
+
|
397 |
+
$result = json_decode($imageClient->request()->getBody())->{'nl.divide.iq'};
|
398 |
+
|
399 |
+
if ($result->response->answer == self::ANSWER_SUCCESS) {
|
400 |
+
return $result->response->content->Items;
|
401 |
+
}
|
402 |
+
|
403 |
+
return array();
|
404 |
+
}
|
405 |
+
|
406 |
+
/**
|
407 |
+
* Saves images array from stockbase for given $ean
|
408 |
+
*
|
409 |
+
* @param array $images
|
410 |
+
*
|
411 |
+
* @return bool
|
412 |
+
*/
|
413 |
+
public function saveImageForProduct($images)
|
414 |
+
{
|
415 |
+
$productModel = Mage::getModel('catalog/product');
|
416 |
+
$eanField = Mage::getStoreConfig('stockbase_options/login/stockbase_ean_field');
|
417 |
+
$accessToken = Mage::getStoreConfig('stockbase_options/token/access');
|
418 |
+
$tempFolder = Mage::getBaseDir('media') . DS . 'tmp';
|
419 |
+
$io = new Varien_Io_File();
|
420 |
+
$addedProducts = array();
|
421 |
+
|
422 |
+
foreach ($images as $image) {
|
423 |
+
$product = $productModel->loadByAttribute($eanField, $image->EAN);
|
424 |
+
$io->checkAndCreateFolder($tempFolder);
|
425 |
+
$filePath = $tempFolder . Mage::getSingleton('core/url')->parseUrl($image->{'Url'})->getPath();
|
426 |
+
|
427 |
+
// Continue looping, if we dont have product, we have nothing.
|
428 |
+
if (!$product) {
|
429 |
+
continue;
|
430 |
+
}
|
431 |
+
|
432 |
+
$client = new Varien_Http_Client($image->{'Url'});
|
433 |
+
$client->setMethod(Varien_Http_Client::GET);
|
434 |
+
$client->setHeaders('Authentication', $accessToken);
|
435 |
+
$protectedImage = $client->request()->getBody();
|
436 |
+
|
437 |
+
if ($io->isWriteable($tempFolder)) {
|
438 |
+
$io->write($filePath, $protectedImage);
|
439 |
+
}
|
440 |
+
|
441 |
+
// Verify written file exsist
|
442 |
+
if ($io->fileExists($filePath)) {
|
443 |
+
if ($product->getMediaGallery() == null) {
|
444 |
+
$product->setMediaGallery(array('images' => array(), 'values' => array()));
|
445 |
+
}
|
446 |
+
$product->addImageToMediaGallery(
|
447 |
+
$filePath,
|
448 |
+
array('image', 'small_image', 'thumbnail'),
|
449 |
+
false,
|
450 |
+
false
|
451 |
+
);
|
452 |
+
$product->{'save'}();
|
453 |
+
}
|
454 |
+
}
|
455 |
+
|
456 |
+
return true;
|
457 |
+
}
|
458 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/Divide/Stockbase/Model/Crons.php
CHANGED
@@ -1,71 +1,89 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Divide_Stockbase_Model_Crons
|
4 |
-
{
|
5 |
-
/**
|
6 |
-
* Method to be called by cron in config.xml
|
7 |
-
*
|
8 |
-
* @return boolean
|
9 |
-
*/
|
10 |
-
public function runNoos()
|
11 |
-
{
|
12 |
-
if (Mage::getStoreConfig('stockbase_options/login/stockbase_noos_active', Mage::app()->getStore())) {
|
13 |
-
$
|
14 |
-
$
|
15 |
-
$productModel = Mage::getModel('catalog/product');
|
16 |
-
$stockModel = Mage::getModel('cataloginventory/stock_item');
|
17 |
-
$noosEnabled = Mage::getStoreConfig('stockbase_options/login/stockbase_noos_active');
|
18 |
-
$fieldSet = Mage::getStoreConfig('stockbase_options/login/stockbase_ean_field');
|
19 |
-
Mage::
|
20 |
-
|
21 |
-
$
|
22 |
-
$
|
23 |
-
|
24 |
-
foreach ($
|
25 |
-
foreach ($group->Items as $brand) {
|
26 |
-
if (in_array($brand->EAN, $skus)) {
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Divide_Stockbase_Model_Crons
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Method to be called by cron in config.xml
|
7 |
+
*
|
8 |
+
* @return boolean
|
9 |
+
*/
|
10 |
+
public function runNoos()
|
11 |
+
{
|
12 |
+
if (Mage::getStoreConfig('stockbase_options/login/stockbase_noos_active', Mage::app()->getStore())) {
|
13 |
+
$httpHelper = Mage::getSingleton('Divide_Stockbase_Helper_HTTP');
|
14 |
+
$dataHelper = Mage::getSingleton('Divide_Stockbase_Helper_Data');
|
15 |
+
$productModel = Mage::getModel('catalog/product');
|
16 |
+
$stockModel = Mage::getModel('cataloginventory/stock_item');
|
17 |
+
$noosEnabled = Mage::getStoreConfig('stockbase_options/login/stockbase_noos_active');
|
18 |
+
$fieldSet = Mage::getStoreConfig('stockbase_options/login/stockbase_ean_field');
|
19 |
+
$lastNoos = Mage::getSingleton('core/date')->{'date'}();
|
20 |
+
Mage::getModel('core/config')->saveConfig('stockbase_options/cron/last_noos', $lastNoos);
|
21 |
+
$httpHelper->authenticate(true);
|
22 |
+
$skus = $dataHelper->getAllEans();
|
23 |
+
$stockbaseEans = array();
|
24 |
+
foreach ($httpHelper->getStock()->Groups as $group) {
|
25 |
+
foreach ($group->{'Items'} as $brand) {
|
26 |
+
if (in_array($brand->EAN, $skus)) {
|
27 |
+
$product = $productModel->loadByAttribute($fieldSet, $brand->EAN);
|
28 |
+
|
29 |
+
// Product information adding by custom attributes
|
30 |
+
if ($product) {
|
31 |
+
$product->setData('stockbase_product', 1);
|
32 |
+
$product->setData('stockbase_ean', $brand->EAN);
|
33 |
+
$product->setData('stockbase_stock', $brand->{'Amount'});
|
34 |
+
$product->setData('stockbase_noos', (bool)$brand->NOOS);
|
35 |
+
$product->{'save'}();
|
36 |
+
}
|
37 |
+
|
38 |
+
// Product stock information update
|
39 |
+
$stockItem = $stockModel->loadByProduct($product);
|
40 |
+
if ($stockItem && ($brand->{'Amount'} >= 1 || $brand->NOOS == true) && $noosEnabled) {
|
41 |
+
$stockItem
|
42 |
+
->setData('use_config_backorders', 0)
|
43 |
+
->setData('is_in_stock', 1)
|
44 |
+
->setData('backorders', 1);
|
45 |
+
$stockItem->{'save'}();
|
46 |
+
}
|
47 |
+
}
|
48 |
+
}
|
49 |
+
}
|
50 |
+
Mage::log('done running never out of stock');
|
51 |
+
|
52 |
+
return true;
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Sync images with stockbase if configured.
|
58 |
+
*
|
59 |
+
* @return void
|
60 |
+
*/
|
61 |
+
public function runImageImport()
|
62 |
+
{
|
63 |
+
if (Mage::getStoreConfig('stockbase_options/login/stockbase_image_import', Mage::app()->getStore())) {
|
64 |
+
$dataHelper = Mage::getSingleton('Divide_Stockbase_Helper_Data');
|
65 |
+
$httpHelper = Mage::getSingleton('Divide_Stockbase_Helper_HTTP');
|
66 |
+
$allEans = $dataHelper->getAllEans();
|
67 |
+
$processedEans = json_decode(Mage::getStoreConfig('stockbase_options/images/processed')) ?: array();
|
68 |
+
|
69 |
+
// Process 100 unprocessed EANs at a time.
|
70 |
+
$eans = array_slice(array_diff($allEans, $processedEans), 0, 100);
|
71 |
+
|
72 |
+
try {
|
73 |
+
$images = $httpHelper->getImageForEan($eans);
|
74 |
+
} catch (Exception $e) {
|
75 |
+
// Error connecting to Stockbase. Stop processing.
|
76 |
+
return;
|
77 |
+
}
|
78 |
+
|
79 |
+
// Download and save the images locally.
|
80 |
+
$httpHelper->saveImageForProduct($images);
|
81 |
+
|
82 |
+
// Update the `processed images` configuration.
|
83 |
+
$processedEans = array_merge($processedEans, $eans);
|
84 |
+
Mage::getConfig()->saveConfig('stockbase_options/images/processed', json_encode($processedEans));
|
85 |
+
}
|
86 |
+
|
87 |
+
return true;
|
88 |
+
}
|
89 |
+
}
|
app/code/local/Divide/Stockbase/Model/Enviroment.php
CHANGED
@@ -1,26 +1,26 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Enviroment options selection for in admin panel.
|
5 |
-
* Switching production/development server by setting it in the MageAdmin.
|
6 |
-
*/
|
7 |
-
class Divide_Stockbase_Model_Enviroment
|
8 |
-
{
|
9 |
-
const DEVELOPMENT = 'http://server.divide.nl/divide.api/';
|
10 |
-
const PRODUCTION = 'https://iqservice.divide.nl/';
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Returns option array for server selection in admin configuration.
|
14 |
-
*
|
15 |
-
* @return array
|
16 |
-
*/
|
17 |
-
public function toOptionArray()
|
18 |
-
{
|
19 |
-
$options =
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
return $options;
|
25 |
-
}
|
26 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Enviroment options selection for in admin panel.
|
5 |
+
* Switching production/development server by setting it in the MageAdmin.
|
6 |
+
*/
|
7 |
+
class Divide_Stockbase_Model_Enviroment
|
8 |
+
{
|
9 |
+
const DEVELOPMENT = 'http://server.divide.nl/divide.api/';
|
10 |
+
const PRODUCTION = 'https://iqservice.divide.nl/';
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Returns option array for server selection in admin configuration.
|
14 |
+
*
|
15 |
+
* @return array
|
16 |
+
*/
|
17 |
+
public function toOptionArray()
|
18 |
+
{
|
19 |
+
$options = array(
|
20 |
+
array('value' => self::PRODUCTION, 'label' => 'Production'),
|
21 |
+
array('value' => self::DEVELOPMENT, 'label' => 'Development'),
|
22 |
+
);
|
23 |
+
|
24 |
+
return $options;
|
25 |
+
}
|
26 |
+
}
|
app/code/local/Divide/Stockbase/Model/Observer.php
CHANGED
@@ -1,67 +1,67 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Divide_Stockbase_Model_Observer
|
4 |
-
{
|
5 |
-
/**
|
6 |
-
* Event catch after sale has successfully been paid for. We check your
|
7 |
-
* own stock levels against the ordered amount and if your stock has shortage
|
8 |
-
* we order the products for you at stockbase. Please login to your Stockbase
|
9 |
-
* account to see these orders.
|
10 |
-
*
|
11 |
-
* @param Varien_Event_Observer $observerObserver
|
12 |
-
*/
|
13 |
-
public function afterPayment(Varien_Event_Observer $observer)
|
14 |
-
{
|
15 |
-
/**
|
16 |
-
* @var $order Mage_Sales_Model_Order
|
17 |
-
* @var $_product Mage_Sales_Model_Order_Item
|
18 |
-
* @var $_stock Mage_CatalogInventory_Model_Stock_Item
|
19 |
-
* @var $oStock Mage_CatalogInventory_Model_Stock_Item
|
20 |
-
* @var $orderedItem Mage_Sales_Model_Order_Item
|
21 |
-
* @var $shipment Mage_Sales_Model_Order_Shipment
|
22 |
-
* @var $observer Varien_Event_Observer
|
23 |
-
*
|
24 |
-
* After invoicing and payment this method will be used to
|
25 |
-
* check if your own stock will be enough to fulfill the requested amount.
|
26 |
-
* If not, we will take the product and send a order to Stockbase for the
|
27 |
-
* amount needed, and the order will be placed @Stockbase. This method
|
28 |
-
* is using the sales_order_payment_pay event and will only be activated
|
29 |
-
* after payment completes and the order is payed for by the customer.
|
30 |
-
*/
|
31 |
-
$http = Mage::getSingleton('Divide_Stockbase_Helper_HTTP');
|
32 |
-
$invoice = $observer->getInvoice();
|
33 |
-
$order = $invoice->getOrder();
|
34 |
-
$orderedProducts = $order->getAllItems();
|
35 |
-
$moduleEnabled = Mage::getStoreConfig('stockbase_options/login/stockbase_active');
|
36 |
-
|
37 |
-
if ($order && $moduleEnabled) {
|
38 |
-
// Always rely on own stock first, so stockbase does not always get triggerd.
|
39 |
-
$sendItToStockbase = false;
|
40 |
-
foreach ($orderedProducts as $orderedProduct) {
|
41 |
-
$baseQty = 0;
|
42 |
-
$productId = $orderedProduct->getId();
|
43 |
-
$baseQty = $orderedProduct->getQtyOrdered()
|
44 |
-
- $orderedProduct->getQtyShipped()
|
45 |
-
- $orderedProduct->getQtyRefunded()
|
46 |
-
- $orderedProduct->getQtyCanceled();
|
47 |
-
$finalQty[$productId] = $baseQty;
|
48 |
-
$ownStockQty = $orderedProduct->getProduct()->getStockItem()->getQty();
|
49 |
-
|
50 |
-
if ($ownStockQty <= 0 || $ownStockQty <= $baseQty) {
|
51 |
-
$sendItToStockbase = true;
|
52 |
-
}
|
53 |
-
}
|
54 |
-
|
55 |
-
// Only send if own stock is too low
|
56 |
-
if ($sendItToStockbase == true) {
|
57 |
-
$send = $http->sendMageOrder($order);
|
58 |
-
|
59 |
-
// Add status history to order to identify Stockbase orders
|
60 |
-
if ($send) {
|
61 |
-
$order->addStatusHistoryComment('This order was send to stockbase.');
|
62 |
-
$order->save();
|
63 |
-
}
|
64 |
-
}
|
65 |
-
}
|
66 |
-
}
|
67 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Divide_Stockbase_Model_Observer
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Event catch after sale has successfully been paid for. We check your
|
7 |
+
* own stock levels against the ordered amount and if your stock has shortage
|
8 |
+
* we order the products for you at stockbase. Please login to your Stockbase
|
9 |
+
* account to see these orders.
|
10 |
+
*
|
11 |
+
* @param Varien_Event_Observer $observerObserver
|
12 |
+
*/
|
13 |
+
public function afterPayment(Varien_Event_Observer $observer)
|
14 |
+
{
|
15 |
+
/**
|
16 |
+
* @var $order Mage_Sales_Model_Order
|
17 |
+
* @var $_product Mage_Sales_Model_Order_Item
|
18 |
+
* @var $_stock Mage_CatalogInventory_Model_Stock_Item
|
19 |
+
* @var $oStock Mage_CatalogInventory_Model_Stock_Item
|
20 |
+
* @var $orderedItem Mage_Sales_Model_Order_Item
|
21 |
+
* @var $shipment Mage_Sales_Model_Order_Shipment
|
22 |
+
* @var $observer Varien_Event_Observer
|
23 |
+
*
|
24 |
+
* After invoicing and payment this method will be used to
|
25 |
+
* check if your own stock will be enough to fulfill the requested amount.
|
26 |
+
* If not, we will take the product and send a order to Stockbase for the
|
27 |
+
* amount needed, and the order will be placed @Stockbase. This method
|
28 |
+
* is using the sales_order_payment_pay event and will only be activated
|
29 |
+
* after payment completes and the order is payed for by the customer.
|
30 |
+
*/
|
31 |
+
$http = Mage::getSingleton('Divide_Stockbase_Helper_HTTP');
|
32 |
+
$invoice = $observer->getInvoice();
|
33 |
+
$order = $invoice->getOrder();
|
34 |
+
$orderedProducts = $order->getAllItems();
|
35 |
+
$moduleEnabled = Mage::getStoreConfig('stockbase_options/login/stockbase_active');
|
36 |
+
|
37 |
+
if ($order && $moduleEnabled) {
|
38 |
+
// Always rely on own stock first, so stockbase does not always get triggerd.
|
39 |
+
$sendItToStockbase = false;
|
40 |
+
foreach ($orderedProducts as $orderedProduct) {
|
41 |
+
$baseQty = 0;
|
42 |
+
$productId = $orderedProduct->getId();
|
43 |
+
$baseQty = $orderedProduct->getQtyOrdered()
|
44 |
+
- $orderedProduct->getQtyShipped()
|
45 |
+
- $orderedProduct->getQtyRefunded()
|
46 |
+
- $orderedProduct->getQtyCanceled();
|
47 |
+
$finalQty[$productId] = $baseQty;
|
48 |
+
$ownStockQty = $orderedProduct->getProduct()->getStockItem()->getQty();
|
49 |
+
|
50 |
+
if ($ownStockQty <= 0 || $ownStockQty <= $baseQty) {
|
51 |
+
$sendItToStockbase = true;
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
// Only send if own stock is too low
|
56 |
+
if ($sendItToStockbase == true) {
|
57 |
+
$send = $http->sendMageOrder($order);
|
58 |
+
|
59 |
+
// Add status history to order to identify Stockbase orders
|
60 |
+
if ($send) {
|
61 |
+
$order->addStatusHistoryComment('This order was send to stockbase.');
|
62 |
+
$order->save();
|
63 |
+
}
|
64 |
+
}
|
65 |
+
}
|
66 |
+
}
|
67 |
+
}
|
app/code/local/Divide/Stockbase/Model/Options.php
CHANGED
@@ -1,33 +1,33 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Divide_Stockbase_Model_Options
|
4 |
-
{
|
5 |
-
/**
|
6 |
-
* Return options for EAN selection from all the created
|
7 |
-
* attributes in magento. When user adds new fields to productattributes
|
8 |
-
* this will fetch them and display them to be used as custom EAN field.
|
9 |
-
* We default to 'sku' field
|
10 |
-
*
|
11 |
-
* @return array
|
12 |
-
*/
|
13 |
-
public function toOptionArray()
|
14 |
-
{
|
15 |
-
$productAttrs = Mage::getResourceModel('catalog/product_attribute_collection');
|
16 |
-
$options =
|
17 |
-
|
18 |
-
foreach ($productAttrs as $productAttr) {
|
19 |
-
$code = $productAttr->getAttributeCode();
|
20 |
-
$label = $productAttr->getFrontendLabel();
|
21 |
-
if (!$label) {
|
22 |
-
$label = $productAttr->getAttributeCode();
|
23 |
-
}
|
24 |
-
|
25 |
-
$options[] =
|
26 |
-
'value' => $code,
|
27 |
-
'label' => $label
|
28 |
-
|
29 |
-
}
|
30 |
-
|
31 |
-
return $options;
|
32 |
-
}
|
33 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Divide_Stockbase_Model_Options
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Return options for EAN selection from all the created
|
7 |
+
* attributes in magento. When user adds new fields to productattributes
|
8 |
+
* this will fetch them and display them to be used as custom EAN field.
|
9 |
+
* We default to 'sku' field
|
10 |
+
*
|
11 |
+
* @return array
|
12 |
+
*/
|
13 |
+
public function toOptionArray()
|
14 |
+
{
|
15 |
+
$productAttrs = Mage::getResourceModel('catalog/product_attribute_collection');
|
16 |
+
$options = array();
|
17 |
+
|
18 |
+
foreach ($productAttrs as $productAttr) {
|
19 |
+
$code = $productAttr->getAttributeCode();
|
20 |
+
$label = $productAttr->getFrontendLabel();
|
21 |
+
if (!$label) {
|
22 |
+
$label = $productAttr->getAttributeCode();
|
23 |
+
}
|
24 |
+
|
25 |
+
$options[] = array(
|
26 |
+
'value' => $code,
|
27 |
+
'label' => $label,
|
28 |
+
);
|
29 |
+
}
|
30 |
+
|
31 |
+
return $options;
|
32 |
+
}
|
33 |
+
}
|
app/code/local/Divide/Stockbase/controllers/Adminhtml/ConfigController.php
CHANGED
@@ -1,66 +1,66 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Divide_Stockbase_Adminhtml_ConfigController extends Mage_Adminhtml_Controller_Action
|
4 |
-
{
|
5 |
-
/**
|
6 |
-
* indexAction for config page of Stockbase
|
7 |
-
*
|
8 |
-
* First loads a block and then adds the block with data to the layout.
|
9 |
-
* Loads the given stockbase phtml template and fills it up
|
10 |
-
* with the configured configuration found in the mage core config.
|
11 |
-
*
|
12 |
-
* @return void
|
13 |
-
*/
|
14 |
-
public function indexAction()
|
15 |
-
{
|
16 |
-
// First start loading the default adminhtml layout
|
17 |
-
$this->loadLayout();
|
18 |
-
|
19 |
-
// Fetch array with key-value pair Stockbase configuration
|
20 |
-
$configuration = $this->getCurrentConfigurationForStockbase();
|
21 |
-
|
22 |
-
// Make the block with the retrieved configuration for rendering
|
23 |
-
$configBlock = $this->getLayout()->createBlock('Mage_Core_Block_Template')
|
24 |
-
->setTemplate('stockbase/config.phtml')
|
25 |
-
->setStockbaseConfiguration($configuration);
|
26 |
-
|
27 |
-
// Using the Mage_Core_Block_Template now get the
|
28 |
-
// content Block and append it with our block.
|
29 |
-
$this->getLayout()->getBlock('content')->append($configBlock);
|
30 |
-
|
31 |
-
// Render the total Mage_Core_Block_Template with our given config.
|
32 |
-
$this->renderLayout();
|
33 |
-
}
|
34 |
-
|
35 |
-
/**
|
36 |
-
* Returns array with set configuration for stockbase.
|
37 |
-
*
|
38 |
-
* @return array
|
39 |
-
*/
|
40 |
-
|
41 |
-
{
|
42 |
-
$configuration =
|
43 |
-
$processedImages = Mage::getStoreConfig('stockbase_options/images/processed') ?:
|
44 |
-
$configuration['module_version'] = Mage::getConfig()->getModuleConfig("Divide_Stockbase")->version;
|
45 |
-
$configuration['enabled_module'] = Mage::getStoreConfig('stockbase_options/login/stockbase_active');
|
46 |
-
$configuration['enabled_noos'] = Mage::getStoreConfig('stockbase_options/login/stockbase_noos_active');
|
47 |
-
$configuration['enabled_image'] = Mage::getStoreConfig('stockbase_options/login/stockbase_image_import');
|
48 |
-
$configuration['processed_images'] = count(json_decode($processedImages));
|
49 |
-
$configuration['order_prefix'] = Mage::getStoreConfig('stockbase_options/login/order_prefix');
|
50 |
-
$configuration['username'] = Mage::getStoreConfig('stockbase_options/login/username');
|
51 |
-
$configuration['enviroment'] = Mage::getStoreConfig('stockbase_options/login/stockbase_enviroment');
|
52 |
-
$configuration['last_cron'] = Mage::getStoreConfig('stockbase_options/cron/last_noos');
|
53 |
-
|
54 |
-
return $configuration;
|
55 |
-
}
|
56 |
-
|
57 |
-
/**
|
58 |
-
* Mage ACL rules for adminhtml
|
59 |
-
*
|
60 |
-
* @return boolean
|
61 |
-
*/
|
62 |
-
protected function _isAllowed()
|
63 |
-
{
|
64 |
-
return true;
|
65 |
-
}
|
66 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Divide_Stockbase_Adminhtml_ConfigController extends Mage_Adminhtml_Controller_Action
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* indexAction for config page of Stockbase
|
7 |
+
*
|
8 |
+
* First loads a block and then adds the block with data to the layout.
|
9 |
+
* Loads the given stockbase phtml template and fills it up
|
10 |
+
* with the configured configuration found in the mage core config.
|
11 |
+
*
|
12 |
+
* @return void
|
13 |
+
*/
|
14 |
+
public function indexAction()
|
15 |
+
{
|
16 |
+
// First start loading the default adminhtml layout
|
17 |
+
$this->loadLayout();
|
18 |
+
|
19 |
+
// Fetch array with key-value pair Stockbase configuration
|
20 |
+
$configuration = $this->getCurrentConfigurationForStockbase();
|
21 |
+
|
22 |
+
// Make the block with the retrieved configuration for rendering
|
23 |
+
$configBlock = $this->getLayout()->createBlock('Mage_Core_Block_Template')
|
24 |
+
->setTemplate('stockbase/config.phtml')
|
25 |
+
->setStockbaseConfiguration($configuration);
|
26 |
+
|
27 |
+
// Using the Mage_Core_Block_Template now get the
|
28 |
+
// content Block and append it with our block.
|
29 |
+
$this->getLayout()->getBlock('content')->append($configBlock);
|
30 |
+
|
31 |
+
// Render the total Mage_Core_Block_Template with our given config.
|
32 |
+
$this->renderLayout();
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Returns array with set configuration for stockbase.
|
37 |
+
*
|
38 |
+
* @return array
|
39 |
+
*/
|
40 |
+
protected function getCurrentConfigurationForStockbase()
|
41 |
+
{
|
42 |
+
$configuration = array();
|
43 |
+
$processedImages = Mage::getStoreConfig('stockbase_options/images/processed') ?: array();
|
44 |
+
$configuration['module_version'] = Mage::getConfig()->getModuleConfig("Divide_Stockbase")->version;
|
45 |
+
$configuration['enabled_module'] = Mage::getStoreConfig('stockbase_options/login/stockbase_active');
|
46 |
+
$configuration['enabled_noos'] = Mage::getStoreConfig('stockbase_options/login/stockbase_noos_active');
|
47 |
+
$configuration['enabled_image'] = Mage::getStoreConfig('stockbase_options/login/stockbase_image_import');
|
48 |
+
$configuration['processed_images'] = count(json_decode($processedImages));
|
49 |
+
$configuration['order_prefix'] = Mage::getStoreConfig('stockbase_options/login/order_prefix');
|
50 |
+
$configuration['username'] = Mage::getStoreConfig('stockbase_options/login/username');
|
51 |
+
$configuration['enviroment'] = Mage::getStoreConfig('stockbase_options/login/stockbase_enviroment');
|
52 |
+
$configuration['last_cron'] = Mage::getStoreConfig('stockbase_options/cron/last_noos');
|
53 |
+
|
54 |
+
return $configuration;
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Mage ACL rules for adminhtml
|
59 |
+
*
|
60 |
+
* @return boolean
|
61 |
+
*/
|
62 |
+
protected function _isAllowed()
|
63 |
+
{
|
64 |
+
return true;
|
65 |
+
}
|
66 |
+
}
|
app/code/local/Divide/Stockbase/etc/config.xml
CHANGED
@@ -1,149 +1,149 @@
|
|
1 |
-
<?xml version="1.0"?>
|
2 |
-
<config>
|
3 |
-
<modules>
|
4 |
-
<Divide_Stockbase>
|
5 |
-
<version>1.0
|
6 |
-
</Divide_Stockbase>
|
7 |
-
</modules>
|
8 |
-
<global>
|
9 |
-
<helpers>
|
10 |
-
<Divide_Stockbase>
|
11 |
-
<class>Divide_Stockbase_Helper</class>
|
12 |
-
</Divide_Stockbase>
|
13 |
-
</helpers>
|
14 |
-
<models>
|
15 |
-
<stock>
|
16 |
-
<class>Divide_Stockbase_Model</class>
|
17 |
-
<resourceModel>stock_mysql4</resourceModel>
|
18 |
-
</stock>
|
19 |
-
<stock_mysql4>
|
20 |
-
<class>Divide_Stockbase_Model_Mysql4</class>
|
21 |
-
<entities>
|
22 |
-
<stock>
|
23 |
-
<table>stock</table>
|
24 |
-
</stock>
|
25 |
-
</entities>
|
26 |
-
</stock_mysql4>
|
27 |
-
</models>
|
28 |
-
<resources>
|
29 |
-
<stock_setup>
|
30 |
-
<setup>
|
31 |
-
<module>Divide_Stockbase</module>
|
32 |
-
</setup>
|
33 |
-
<connection>
|
34 |
-
<use>core_setup</use>
|
35 |
-
</connection>
|
36 |
-
</stock_setup>
|
37 |
-
<stock_write>
|
38 |
-
<connection>
|
39 |
-
<use>core_write</use>
|
40 |
-
</connection>
|
41 |
-
</stock_write>
|
42 |
-
<stock_read>
|
43 |
-
<connection>
|
44 |
-
<use>core_read</use>
|
45 |
-
</connection>
|
46 |
-
</stock_read>
|
47 |
-
</resources>
|
48 |
-
<blocks>
|
49 |
-
<stockbase>
|
50 |
-
<class>Divide_Stockbase_Block</class>
|
51 |
-
</stockbase>
|
52 |
-
</blocks>
|
53 |
-
<events>
|
54 |
-
<sales_order_payment_pay>
|
55 |
-
<observers>
|
56 |
-
<Divide_Stockbase_Model_Observer>
|
57 |
-
<type>singleton</type>
|
58 |
-
<class>Divide_Stockbase_Model_Observer</class>
|
59 |
-
<method>afterPayment</method>
|
60 |
-
</Divide_Stockbase_Model_Observer>
|
61 |
-
</observers>
|
62 |
-
</sales_order_payment_pay>
|
63 |
-
</events>
|
64 |
-
</global>
|
65 |
-
<admin>
|
66 |
-
<routers>
|
67 |
-
<adminhtml>
|
68 |
-
<args>
|
69 |
-
<modules>
|
70 |
-
<Divide_Stockbase before="Mage_Adminhtml">Divide_Stockbase_Adminhtml</Divide_Stockbase>
|
71 |
-
</modules>
|
72 |
-
</args>
|
73 |
-
</adminhtml>
|
74 |
-
</routers>
|
75 |
-
</admin>
|
76 |
-
<adminhtml>
|
77 |
-
<menu>
|
78 |
-
<stockbase module="Divide_Stockbase" translate="title">
|
79 |
-
<title>Stockbase</title>
|
80 |
-
<sort_order>200</sort_order>
|
81 |
-
<children>
|
82 |
-
<stock>
|
83 |
-
<title>Module Status</title>
|
84 |
-
<action>adminhtml/config/index</action>
|
85 |
-
</stock>
|
86 |
-
<configuration>
|
87 |
-
<title>Configuration</title>
|
88 |
-
<action>adminhtml/system_config/edit/section/stockbase_options</action>
|
89 |
-
</configuration>
|
90 |
-
</children>
|
91 |
-
</stockbase>
|
92 |
-
</menu>
|
93 |
-
<acl>
|
94 |
-
<resources>
|
95 |
-
<admin>
|
96 |
-
<children>
|
97 |
-
<system>
|
98 |
-
<children>
|
99 |
-
<config>
|
100 |
-
<children>
|
101 |
-
<stockbase_options>
|
102 |
-
<title>Stockbase Module Section</title>
|
103 |
-
</stockbase_options>
|
104 |
-
</children>
|
105 |
-
</config>
|
106 |
-
</children>
|
107 |
-
</system>
|
108 |
-
</children>
|
109 |
-
</admin>
|
110 |
-
</resources>
|
111 |
-
</acl>
|
112 |
-
<translate>
|
113 |
-
<modules>
|
114 |
-
<translations>
|
115 |
-
<files>
|
116 |
-
<default>Divide_Stockbase.csv</default>
|
117 |
-
</files>
|
118 |
-
</translations>
|
119 |
-
</modules>
|
120 |
-
</translate>
|
121 |
-
<layout>
|
122 |
-
<updates>
|
123 |
-
<stockbase>
|
124 |
-
<file>stockbase.xml</file>
|
125 |
-
</stockbase>
|
126 |
-
</updates>
|
127 |
-
</layout>
|
128 |
-
</adminhtml>
|
129 |
-
<crontab>
|
130 |
-
<jobs>
|
131 |
-
<stockbase_noos_cron>
|
132 |
-
<schedule>
|
133 |
-
<cron_expr>0 * * * *</cron_expr>
|
134 |
-
</schedule>
|
135 |
-
<run>
|
136 |
-
<model>stock/crons::runNoos</model>
|
137 |
-
</run>
|
138 |
-
</stockbase_noos_cron>
|
139 |
-
<stockbase_image_cron>
|
140 |
-
<schedule>
|
141 |
-
<cron_expr>*/30 * * * *</cron_expr>
|
142 |
-
</schedule>
|
143 |
-
<run>
|
144 |
-
<model>stock/crons::runImageImport</model>
|
145 |
-
</run>
|
146 |
-
</stockbase_image_cron>
|
147 |
-
</jobs>
|
148 |
-
</crontab>
|
149 |
-
</config>
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Divide_Stockbase>
|
5 |
+
<version>1.1.0</version>
|
6 |
+
</Divide_Stockbase>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<helpers>
|
10 |
+
<Divide_Stockbase>
|
11 |
+
<class>Divide_Stockbase_Helper</class>
|
12 |
+
</Divide_Stockbase>
|
13 |
+
</helpers>
|
14 |
+
<models>
|
15 |
+
<stock>
|
16 |
+
<class>Divide_Stockbase_Model</class>
|
17 |
+
<resourceModel>stock_mysql4</resourceModel>
|
18 |
+
</stock>
|
19 |
+
<stock_mysql4>
|
20 |
+
<class>Divide_Stockbase_Model_Mysql4</class>
|
21 |
+
<entities>
|
22 |
+
<stock>
|
23 |
+
<table>stock</table>
|
24 |
+
</stock>
|
25 |
+
</entities>
|
26 |
+
</stock_mysql4>
|
27 |
+
</models>
|
28 |
+
<resources>
|
29 |
+
<stock_setup>
|
30 |
+
<setup>
|
31 |
+
<module>Divide_Stockbase</module>
|
32 |
+
</setup>
|
33 |
+
<connection>
|
34 |
+
<use>core_setup</use>
|
35 |
+
</connection>
|
36 |
+
</stock_setup>
|
37 |
+
<stock_write>
|
38 |
+
<connection>
|
39 |
+
<use>core_write</use>
|
40 |
+
</connection>
|
41 |
+
</stock_write>
|
42 |
+
<stock_read>
|
43 |
+
<connection>
|
44 |
+
<use>core_read</use>
|
45 |
+
</connection>
|
46 |
+
</stock_read>
|
47 |
+
</resources>
|
48 |
+
<blocks>
|
49 |
+
<stockbase>
|
50 |
+
<class>Divide_Stockbase_Block</class>
|
51 |
+
</stockbase>
|
52 |
+
</blocks>
|
53 |
+
<events>
|
54 |
+
<sales_order_payment_pay>
|
55 |
+
<observers>
|
56 |
+
<Divide_Stockbase_Model_Observer>
|
57 |
+
<type>singleton</type>
|
58 |
+
<class>Divide_Stockbase_Model_Observer</class>
|
59 |
+
<method>afterPayment</method>
|
60 |
+
</Divide_Stockbase_Model_Observer>
|
61 |
+
</observers>
|
62 |
+
</sales_order_payment_pay>
|
63 |
+
</events>
|
64 |
+
</global>
|
65 |
+
<admin>
|
66 |
+
<routers>
|
67 |
+
<adminhtml>
|
68 |
+
<args>
|
69 |
+
<modules>
|
70 |
+
<Divide_Stockbase before="Mage_Adminhtml">Divide_Stockbase_Adminhtml</Divide_Stockbase>
|
71 |
+
</modules>
|
72 |
+
</args>
|
73 |
+
</adminhtml>
|
74 |
+
</routers>
|
75 |
+
</admin>
|
76 |
+
<adminhtml>
|
77 |
+
<menu>
|
78 |
+
<stockbase module="Divide_Stockbase" translate="title">
|
79 |
+
<title>Stockbase</title>
|
80 |
+
<sort_order>200</sort_order>
|
81 |
+
<children>
|
82 |
+
<stock>
|
83 |
+
<title>Module Status</title>
|
84 |
+
<action>adminhtml/config/index</action>
|
85 |
+
</stock>
|
86 |
+
<configuration>
|
87 |
+
<title>Configuration</title>
|
88 |
+
<action>adminhtml/system_config/edit/section/stockbase_options</action>
|
89 |
+
</configuration>
|
90 |
+
</children>
|
91 |
+
</stockbase>
|
92 |
+
</menu>
|
93 |
+
<acl>
|
94 |
+
<resources>
|
95 |
+
<admin>
|
96 |
+
<children>
|
97 |
+
<system>
|
98 |
+
<children>
|
99 |
+
<config>
|
100 |
+
<children>
|
101 |
+
<stockbase_options>
|
102 |
+
<title>Stockbase Module Section</title>
|
103 |
+
</stockbase_options>
|
104 |
+
</children>
|
105 |
+
</config>
|
106 |
+
</children>
|
107 |
+
</system>
|
108 |
+
</children>
|
109 |
+
</admin>
|
110 |
+
</resources>
|
111 |
+
</acl>
|
112 |
+
<translate>
|
113 |
+
<modules>
|
114 |
+
<translations>
|
115 |
+
<files>
|
116 |
+
<default>Divide_Stockbase.csv</default>
|
117 |
+
</files>
|
118 |
+
</translations>
|
119 |
+
</modules>
|
120 |
+
</translate>
|
121 |
+
<layout>
|
122 |
+
<updates>
|
123 |
+
<stockbase>
|
124 |
+
<file>stockbase.xml</file>
|
125 |
+
</stockbase>
|
126 |
+
</updates>
|
127 |
+
</layout>
|
128 |
+
</adminhtml>
|
129 |
+
<crontab>
|
130 |
+
<jobs>
|
131 |
+
<stockbase_noos_cron>
|
132 |
+
<schedule>
|
133 |
+
<cron_expr>0 * * * *</cron_expr>
|
134 |
+
</schedule>
|
135 |
+
<run>
|
136 |
+
<model>stock/crons::runNoos</model>
|
137 |
+
</run>
|
138 |
+
</stockbase_noos_cron>
|
139 |
+
<stockbase_image_cron>
|
140 |
+
<schedule>
|
141 |
+
<cron_expr>*/30 * * * *</cron_expr>
|
142 |
+
</schedule>
|
143 |
+
<run>
|
144 |
+
<model>stock/crons::runImageImport</model>
|
145 |
+
</run>
|
146 |
+
</stockbase_image_cron>
|
147 |
+
</jobs>
|
148 |
+
</crontab>
|
149 |
+
</config>
|
app/code/local/Divide/Stockbase/etc/system.xml
CHANGED
@@ -109,4 +109,4 @@
|
|
109 |
</groups>
|
110 |
</stockbase_options>
|
111 |
</sections>
|
112 |
-
</config>
|
109 |
</groups>
|
110 |
</stockbase_options>
|
111 |
</sections>
|
112 |
+
</config>
|
app/code/local/Divide/Stockbase/sql/stock_setup/mysql4-upgrade-1.0.4-1.1.0.php
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by PhpStorm.
|
4 |
+
* User: nav.appaiya
|
5 |
+
* Date: 14-10-2016
|
6 |
+
* Time: 16:55
|
7 |
+
*/
|
8 |
+
// Set data:
|
9 |
+
$attributeGroup = 'General';
|
10 |
+
$attributeSetIds = array(4);
|
11 |
+
|
12 |
+
$attributeName = 'Stockbase Product'; // Is Stockbase product => stockbase_product
|
13 |
+
$attributeCode = 'stockbase_product'; // Label stockbase product
|
14 |
+
|
15 |
+
$attributeNoosName = 'Stockbase NOOS'; // Is NOOS => stockbase_noos
|
16 |
+
$attributeNoosCode = 'stockbase_noos'; // Noos Label
|
17 |
+
|
18 |
+
$attributeStockName = 'Stockbase Stock'; // Stocklevel stockbase => stockbase_stock
|
19 |
+
$attributeStockCode = 'stockbase_stock'; // label stocklevel
|
20 |
+
|
21 |
+
$attributeEANName = 'Stockbase EAN'; // Stocklevel stockbase => stockbase_stock
|
22 |
+
$attributeEANCode = 'stockbase_ean'; // label stocklevel
|
23 |
+
|
24 |
+
// Configuration for stockbase_product:
|
25 |
+
$data = array(
|
26 |
+
'type' => 'int', // Attribute type
|
27 |
+
'input' => 'boolean', // Input type
|
28 |
+
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // Attribute scope
|
29 |
+
'required' => false, // Is this attribute required?
|
30 |
+
'user_defined' => false,
|
31 |
+
'searchable' => false,
|
32 |
+
'filterable' => false,
|
33 |
+
'comparable' => false,
|
34 |
+
'visible_on_front' => false,
|
35 |
+
'unique' => false,
|
36 |
+
'used_in_product_listing' => true,
|
37 |
+
// Filled from above:
|
38 |
+
'label' => $attributeName,
|
39 |
+
);
|
40 |
+
|
41 |
+
// Configuration for stockbase noos
|
42 |
+
$dataNoos = array(
|
43 |
+
'type' => 'int', // Attribute type
|
44 |
+
'input' => 'boolean', // Input type
|
45 |
+
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // Attribute scope
|
46 |
+
'required' => false, // Is this attribute required?
|
47 |
+
'user_defined' => false,
|
48 |
+
'searchable' => false,
|
49 |
+
'filterable' => false,
|
50 |
+
'comparable' => false,
|
51 |
+
'visible_on_front' => false,
|
52 |
+
'unique' => false,
|
53 |
+
'used_in_product_listing' => true,
|
54 |
+
// Filled from above:
|
55 |
+
'label' => $attributeNoosName,
|
56 |
+
);
|
57 |
+
|
58 |
+
// Configuration for stockbase stock
|
59 |
+
$dataStock = array(
|
60 |
+
'type' => 'text', // Attribute type
|
61 |
+
'input' => 'text', // Input type
|
62 |
+
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // Attribute scope
|
63 |
+
'required' => false, // Is this attribute required?
|
64 |
+
'user_defined' => false,
|
65 |
+
'searchable' => false,
|
66 |
+
'filterable' => false,
|
67 |
+
'comparable' => false,
|
68 |
+
'visible_on_front' => false,
|
69 |
+
'unique' => false,
|
70 |
+
'used_in_product_listing' => true,
|
71 |
+
// Filled from above:
|
72 |
+
'label' => $attributeStockName,
|
73 |
+
);
|
74 |
+
|
75 |
+
// Configuration for stockbase stock
|
76 |
+
$dataEAN = array(
|
77 |
+
'type' => 'text', // Attribute type
|
78 |
+
'input' => 'text', // Input type
|
79 |
+
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // Attribute scope
|
80 |
+
'required' => false, // Is this attribute required?
|
81 |
+
'user_defined' => false,
|
82 |
+
'searchable' => false,
|
83 |
+
'filterable' => false,
|
84 |
+
'comparable' => false,
|
85 |
+
'visible_on_front' => false,
|
86 |
+
'unique' => false,
|
87 |
+
'used_in_product_listing' => true,
|
88 |
+
// Filled from above:
|
89 |
+
'label' => $attributeEANName,
|
90 |
+
);
|
91 |
+
|
92 |
+
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
|
93 |
+
$installer->startSetup();
|
94 |
+
$installer->addAttribute('catalog_product', $attributeCode, $data);
|
95 |
+
$installer->addAttribute('catalog_product', $attributeNoosCode, $dataNoos);
|
96 |
+
$installer->addAttribute('catalog_product', $attributeStockCode, $dataStock);
|
97 |
+
$installer->addAttribute('catalog_product', $attributeEANCode, $dataEAN);
|
98 |
+
|
99 |
+
// Add the attribute to the proper sets/groups:
|
100 |
+
foreach ($attributeSetIds as $attributeSetId) {
|
101 |
+
$installer->addAttributeToGroup('catalog_product', $attributeSetId, $attributeGroup, $attributeCode);
|
102 |
+
$installer->addAttributeToGroup('catalog_product', $attributeSetId, $attributeGroup, $attributeNoosCode);
|
103 |
+
$installer->addAttributeToGroup('catalog_product', $attributeSetId, $attributeGroup, $attributeStockCode);
|
104 |
+
$installer->addAttributeToGroup('catalog_product', $attributeSetId, $attributeGroup, $attributeEANCode);
|
105 |
+
}
|
106 |
+
|
107 |
+
// Done:
|
108 |
+
$installer->endSetup();
|
app/design/adminhtml/default/default/layout/stockbase.xml
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
<?xml version="1.0"?>
|
2 |
-
<layout version="0.1.6">
|
3 |
-
<stockbase_config_index>
|
4 |
-
<reference name="content">
|
5 |
-
<block type="stockbase/config" name="config" />
|
6 |
-
</reference>
|
7 |
-
</stockbase_config_index>
|
8 |
-
</layout>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package.xml
CHANGED
@@ -1,33 +1,32 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Stockbase</name>
|
4 |
-
<version>1.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="https://opensource.org/licenses/GPL-3.0">GPL-3.0</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>This module allows connecting your Stockbase account with your Magento webshop, allowing it to make use of the extra inventory offered by Stockbase.</summary>
|
10 |
<description>This module requires you to have a Stockbase account with username and password. After installing the module you have to connect it to your Stockbase account using the configuration page in the Magento administration. After configuration you can make use of the following features:
|
11 |
-

|
12 |
-
Products never-out-of-stock:
|
13 |
-
The connected suppliers and brands in your Stockbase account will be checked when receiving an order with an out-of-stock product. The order will be forwarded to Stockbase when applicable
|
14 |
-

|
15 |
-
Sending orders to stockbase
|
16 |
-
When the products are out-of-stock, the order will be forwarded to Stockbase's order handling service. Your own stock is not sufficient enough to fullfill the order. Products on your webshop can continue to be ordered, even when they are out of stock. Stockbase will take the order and deliver the desired quantity.
|
17 |
-

|
18 |
-
Product image import
|
19 |
-
The module will compare your webshop's product inventory to your Stockbase account's inventory, based on EAN. If a match is found, the module will download any images from Stockbase to your webshop and add them to the product.
|
20 |
</description>
|
21 |
-
<notes>
|
22 |

|
23 |
-
-
|
24 |
-
-
|
25 |
-
-
|
26 |
-
</notes>
|
27 |
<authors><author><name>Divide BV</name><user>Stockbase</user><email>support@stockbase.nl</email></author></authors>
|
28 |
-
<date>2016-
|
29 |
-
<time>
|
30 |
-
<contents><target name="magelocal"><dir name="Divide"><dir name="Stockbase"><dir name="Block"><file name="Config.php" hash="
|
31 |
<compatible/>
|
32 |
<dependencies><required><php><min>5.4.0</min><max>6.0.0</max></php></required></dependencies>
|
33 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Stockbase</name>
|
4 |
+
<version>1.1.1</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="https://opensource.org/licenses/GPL-3.0">GPL-3.0</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>This module allows connecting your Stockbase account with your Magento webshop, allowing it to make use of the extra inventory offered by Stockbase.</summary>
|
10 |
<description>This module requires you to have a Stockbase account with username and password. After installing the module you have to connect it to your Stockbase account using the configuration page in the Magento administration. After configuration you can make use of the following features:
|
11 |
+

|
12 |
+
Products never-out-of-stock:
|
13 |
+
The connected suppliers and brands in your Stockbase account will be checked when receiving an order with an out-of-stock product. The order will be forwarded to Stockbase when applicable
|
14 |
+

|
15 |
+
Sending orders to stockbase
|
16 |
+
When the products are out-of-stock, the order will be forwarded to Stockbase's order handling service. Your own stock is not sufficient enough to fullfill the order. Products on your webshop can continue to be ordered, even when they are out of stock. Stockbase will take the order and deliver the desired quantity.
|
17 |
+

|
18 |
+
Product image import
|
19 |
+
The module will compare your webshop's product inventory to your Stockbase account's inventory, based on EAN. If a match is found, the module will download any images from Stockbase to your webshop and add them to the product.
|
20 |
</description>
|
21 |
+
<notes>Fixes:
|
22 |

|
23 |
+
- Image sync running perpetually when not permitted.
|
24 |
+
- Image sync single API call for all EANs to sync instead of 1 call per EAN
|
25 |
+
- Some code refactoring.</notes>
|
|
|
26 |
<authors><author><name>Divide BV</name><user>Stockbase</user><email>support@stockbase.nl</email></author></authors>
|
27 |
+
<date>2016-11-25</date>
|
28 |
+
<time>16:21:13</time>
|
29 |
+
<contents><target name="magelocal"><dir name="Divide"><dir name="Stockbase"><dir name="Block"><file name="Config.php" hash="c3034e9095c4f81cc0c84e46ad8f1a33"/></dir><dir name="Helper"><file name="Data.php" hash="1b85819a6e5e77047ea1f577149fc464"/><file name="HTTP.php" hash="d4ed6cb86589e99fa339b294085be1c1"/></dir><dir name="Model"><file name="Crons.php" hash="d2aac7af7592c87718c6ca5c3f61ef6c"/><file name="Enviroment.php" hash="ffa4fe690896a16b025073c835ddf21b"/><file name="Observer.php" hash="0ba698231b1be6a96100c29b1973693e"/><file name="Options.php" hash="de03b037088ae67717fa50c7d5c9d853"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="ConfigController.php" hash="9613fab861af4e60420dc09c299fb605"/></dir></dir><dir name="etc"><file name="config.xml" hash="6d49e166859a0bba238b03137b0f1f73"/><file name="system.xml" hash="139d172df653dd92eee3941757638d32"/></dir><dir name="sql"><dir name="stock_setup"><file name="mysql4-upgrade-1.0.4-1.1.0.php" hash="87e0b37603c2906edc6fb905f59d6c4e"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="stockbase"><file name="config.phtml" hash="62a961154f59879c7b5ee84921408db6"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Divide_Stockbase.xml" hash="57143df3ed1cd2598bf5c928f625da91"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Divide_Stockbase.csv" hash="148597a20354efcd0e9b4c6e2c951467"/></dir><dir name="nl_NL"><file name="Divide_Stockbase.csv" hash="c5fdf87abc7957bb5145df6432cda7fc"/></dir></target></contents>
|
30 |
<compatible/>
|
31 |
<dependencies><required><php><min>5.4.0</min><max>6.0.0</max></php></required></dependencies>
|
32 |
</package>
|