Version Notes
- Improve handle of orders
- Add import of data when init the plugin
Download this release
Release Info
Developer | Maxime Pruvost |
Extension | cartsguru |
Version | 1.2.6 |
Comparing to | |
See all releases |
Code changes from version 1.2.5 to 1.2.6
- app/code/local/Cartsguru/Model/Observer.php +35 -21
- app/code/local/Cartsguru/Model/Webservice.php +166 -35
- app/code/local/Cartsguru/controllers/RecovercartController.php +10 -7
- app/code/local/Cartsguru/etc/config.xml +11 -48
- app/code/local/Cartsguru/sql/cartsguru_setup/upgrade-1.2.5-1.2.6.php +6 -0
- package.xml +6 -5
app/code/local/Cartsguru/Model/Observer.php
CHANGED
@@ -7,29 +7,39 @@
|
|
7 |
class Cartsguru_Model_Observer
|
8 |
{
|
9 |
/**
|
10 |
-
*
|
11 |
* @param $observer
|
12 |
*/
|
13 |
public function configSaveAfter($observer)
|
14 |
{
|
15 |
$session = Mage::getSingleton('core/session');
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
}
|
20 |
|
21 |
/**
|
22 |
-
*
|
23 |
* @param $observer
|
24 |
*/
|
25 |
-
public function
|
26 |
{
|
27 |
-
$
|
28 |
-
Mage::getModel('cartsguru/webservice')->
|
29 |
-
}
|
30 |
-
|
31 |
/**
|
32 |
-
*
|
33 |
* @param $observer
|
34 |
*/
|
35 |
public function quoteSaveBefore($observer)
|
@@ -42,22 +52,26 @@ class Cartsguru_Model_Observer
|
|
42 |
}
|
43 |
|
44 |
/**
|
45 |
-
*
|
46 |
* @param $observer
|
47 |
*/
|
48 |
-
public function
|
49 |
{
|
50 |
-
$
|
51 |
-
Mage::getModel('cartsguru/webservice')->
|
52 |
}
|
53 |
|
54 |
/**
|
55 |
-
*
|
56 |
* @param $observer
|
57 |
*/
|
58 |
-
public function
|
59 |
-
|
60 |
-
$
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
63 |
}
|
7 |
class Cartsguru_Model_Observer
|
8 |
{
|
9 |
/**
|
10 |
+
* Check api is available after save config in admin
|
11 |
* @param $observer
|
12 |
*/
|
13 |
public function configSaveAfter($observer)
|
14 |
{
|
15 |
$session = Mage::getSingleton('core/session');
|
16 |
+
$webservice = Mage::getModel('cartsguru/webservice');
|
17 |
+
|
18 |
+
$result = $webservice->checkAddress();
|
19 |
+
|
20 |
+
if ($result == false){
|
21 |
+
return $session->addError('Error check connection');
|
22 |
+
}
|
23 |
+
|
24 |
+
$session->addSuccess('Connection checked');
|
25 |
+
|
26 |
+
if ($result->isNew){
|
27 |
+
$webservice->sendHistory();
|
28 |
+
}
|
29 |
}
|
30 |
|
31 |
/**
|
32 |
+
* Handle customer data change, and push it to carts guuru
|
33 |
* @param $observer
|
34 |
*/
|
35 |
+
public function customerSaveAfter($observer)
|
36 |
{
|
37 |
+
$customer = $observer->getCustomer();
|
38 |
+
Mage::getModel('cartsguru/webservice')->sendAccount($customer);
|
39 |
+
}
|
40 |
+
|
41 |
/**
|
42 |
+
* Set token before quote is save
|
43 |
* @param $observer
|
44 |
*/
|
45 |
public function quoteSaveBefore($observer)
|
52 |
}
|
53 |
|
54 |
/**
|
55 |
+
* Handle quote is saved, and push it to carts guru
|
56 |
* @param $observer
|
57 |
*/
|
58 |
+
public function quoteSaveAfter($observer)
|
59 |
{
|
60 |
+
$quote = $observer->getEvent()->getQuote();
|
61 |
+
Mage::getModel('cartsguru/webservice')->sendAbadonnedCart($quote);
|
62 |
}
|
63 |
|
64 |
/**
|
65 |
+
* Handle order updated, and push it to carts guru
|
66 |
* @param $observer
|
67 |
*/
|
68 |
+
public function orderSaveAfter($observer) {
|
69 |
+
/* @var Mage_Sales_Model_Order $order */
|
70 |
+
$order = $observer->getOrder();
|
71 |
+
|
72 |
+
// Only trigger when order status change
|
73 |
+
if ($order->getStatus() != $order->getOrigData('status')) {
|
74 |
+
Mage::getModel('cartsguru/webservice')->sendOrder($order);
|
75 |
+
}
|
76 |
+
}
|
77 |
}
|
app/code/local/Cartsguru/Model/Webservice.php
CHANGED
@@ -8,6 +8,7 @@ class Cartsguru_Model_Webservice
|
|
8 |
{
|
9 |
private $apiBaseUrl = 'https://api.carts.guru';
|
10 |
private $configBasePath = 'cartsguru/cartsguru_group/';
|
|
|
11 |
|
12 |
protected function getStoreFromAdmin(){
|
13 |
$store_id;
|
@@ -20,12 +21,16 @@ class Cartsguru_Model_Webservice
|
|
20 |
$website_id = Mage::getModel('core/website')->load($code)->getId();
|
21 |
$store_id = Mage::app()->getWebsite($website_id)->getDefaultStore()->getId();
|
22 |
}
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
if ($store_id){
|
25 |
return Mage::app()->getStore($store_id);
|
26 |
}
|
27 |
else {
|
28 |
-
return
|
29 |
}
|
30 |
}
|
31 |
|
@@ -157,7 +162,7 @@ class Cartsguru_Model_Webservice
|
|
157 |
* @param $order
|
158 |
* @return array
|
159 |
*/
|
160 |
-
public function getOrderData($order)
|
161 |
{
|
162 |
//Order must have a status
|
163 |
if (!$order->getStatus()){
|
@@ -175,14 +180,16 @@ class Cartsguru_Model_Webservice
|
|
175 |
$items = $this->getItemsData($order);
|
176 |
|
177 |
return array(
|
178 |
-
'siteId' => $this->getStoreConfig('siteid'),
|
179 |
'id' => $order->getIncrementId(), // Order reference, the same display to the buyer
|
180 |
'creationDate' => $this->formatDate($order->getCreatedAt()), // Date of the order as string in json format
|
181 |
'cartId' => $order->getQuoteId(), // Cart identifier, source of the order
|
182 |
'totalET' => (float)$order->getSubtotal(), // Amount excluded taxes and excluded shipping
|
183 |
-
'totalATI' => (float)$order->getGrandTotal(),
|
|
|
|
|
184 |
'state' => $order->getStatus(), // raw order status
|
185 |
-
'accountId' => $email,
|
186 |
'ip' => $order->getRemoteIp(), // User IP
|
187 |
'civility' => $this->notEmpty($gender), // Use string in this list : 'mister','madam','miss'
|
188 |
'lastname' => $this->notEmpty($address->getLastname()), // Lastname of the buyer
|
@@ -205,11 +212,21 @@ class Cartsguru_Model_Webservice
|
|
205 |
return;
|
206 |
}
|
207 |
|
|
|
208 |
$orderData = $this->getOrderData($order);
|
209 |
-
if (
|
210 |
-
|
211 |
}
|
212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
public function genderMapping($gender){
|
214 |
switch((int)$gender){
|
215 |
case 1:
|
@@ -220,12 +237,13 @@ class Cartsguru_Model_Webservice
|
|
220 |
return '';
|
221 |
}
|
222 |
}
|
|
|
223 |
/**
|
224 |
* This method return abounded cart data in cartsguru api format
|
225 |
* @param $quote
|
226 |
* @return array|void
|
227 |
*/
|
228 |
-
public function getAbadonnedCartData($quote)
|
229 |
{
|
230 |
//Customer data
|
231 |
$gender = $this->genderMapping($quote->getCustomerGender());
|
@@ -285,13 +303,14 @@ class Cartsguru_Model_Webservice
|
|
285 |
}
|
286 |
|
287 |
return array(
|
288 |
-
'siteId' => $this->getStoreConfig('siteid'),
|
289 |
'id' => $quote->getId(), // Order reference, the same display to the buyer
|
290 |
'creationDate' => $this->formatDate($quote->getCreatedAt()), // Date of the order as string in json format
|
291 |
'totalET' => (float)$quote->getSubtotal(), // Amount excluded taxes and excluded shipping
|
292 |
'totalATI' => $this->getTotalATI($items), // Amount included taxes and excluded shipping
|
|
|
293 |
'ip' => $quote->getRemoteIp(), // User IP
|
294 |
-
'accountId' => $email,
|
295 |
'civility' => $gender, // Use string in this list : 'mister','madam','miss'
|
296 |
'lastname' => $this->notEmpty($lastname), // Lastname of the buyer
|
297 |
'firstname' => $this->notEmpty($firstname), // Firstname of the buyer
|
@@ -307,7 +326,7 @@ class Cartsguru_Model_Webservice
|
|
307 |
* This method send abounded cart data
|
308 |
* @param $quote
|
309 |
*/
|
310 |
-
public function sendAbadonnedCart($quote)
|
311 |
{
|
312 |
//Check is well configured
|
313 |
if (!$this->isStoreConfigured()){
|
@@ -320,15 +339,24 @@ class Cartsguru_Model_Webservice
|
|
320 |
return;
|
321 |
}
|
322 |
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
$cache->
|
328 |
-
|
329 |
-
|
|
|
|
|
330 |
}
|
|
|
|
|
331 |
}
|
|
|
|
|
|
|
|
|
|
|
332 |
}
|
333 |
|
334 |
/**
|
@@ -366,7 +394,7 @@ class Cartsguru_Model_Webservice
|
|
366 |
* @param $customer
|
367 |
* @return array
|
368 |
*/
|
369 |
-
public function getCustomerData($customer)
|
370 |
{
|
371 |
$address = $customer->getDefaultBillingAddress();
|
372 |
|
@@ -381,13 +409,13 @@ class Cartsguru_Model_Webservice
|
|
381 |
}
|
382 |
|
383 |
return array(
|
384 |
-
'siteId' => $this->getStoreConfig('siteid'),
|
385 |
-
'accountId' => $customer->getId(),
|
386 |
-
'civility' => $gender,
|
387 |
-
'lastname' => $this->notEmpty($lastname),
|
388 |
-
'firstname' => $this->notEmpty($firstname),
|
389 |
-
'email' => $this->notEmpty($customer->getEmail()),
|
390 |
-
'phoneNumber' => $this->notEmpty($phone),
|
391 |
'countryCode' => $this->notEmpty($country)
|
392 |
);
|
393 |
}
|
@@ -419,26 +447,129 @@ class Cartsguru_Model_Webservice
|
|
419 |
$requestUrl = '/sites/' . $this->getStoreConfig('siteid', $store) . '/register-plugin';
|
420 |
$fields = array(
|
421 |
'plugin' => 'magento',
|
422 |
-
'pluginVersion' => '1.2.
|
423 |
'storeVersion' => Mage::getVersion()
|
424 |
);
|
425 |
|
426 |
$response = $this->doPostRequest($requestUrl, $fields, $store);
|
427 |
-
$isSuccess = ($response)?
|
428 |
-
($response->getStatus() == 200)
|
429 |
-
: false;
|
430 |
|
431 |
-
|
432 |
-
|
|
|
|
|
|
|
433 |
}
|
434 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
435 |
/**
|
436 |
* This method send data on api path
|
437 |
* @param $apiPath
|
438 |
* @param $fields
|
439 |
* @return Zend_Http_Response
|
440 |
*/
|
441 |
-
|
442 |
{
|
443 |
try {
|
444 |
$url = $this->apiBaseUrl . $apiPath;
|
8 |
{
|
9 |
private $apiBaseUrl = 'https://api.carts.guru';
|
10 |
private $configBasePath = 'cartsguru/cartsguru_group/';
|
11 |
+
private $historySize = 150;
|
12 |
|
13 |
protected function getStoreFromAdmin(){
|
14 |
$store_id;
|
21 |
$website_id = Mage::getModel('core/website')->load($code)->getId();
|
22 |
$store_id = Mage::app()->getWebsite($website_id)->getDefaultStore()->getId();
|
23 |
}
|
24 |
+
elseif (strlen($code = Mage::app()->getRequest()->getParam('website'))) {
|
25 |
+
$website_id = Mage::getModel('core/website')->load($code)->getId();
|
26 |
+
$store_id = Mage::app()->getWebsite($website_id)->getDefaultStore()->getId();
|
27 |
+
}
|
28 |
+
|
29 |
if ($store_id){
|
30 |
return Mage::app()->getStore($store_id);
|
31 |
}
|
32 |
else {
|
33 |
+
return Mage::app()->getStore();
|
34 |
}
|
35 |
}
|
36 |
|
162 |
* @param $order
|
163 |
* @return array
|
164 |
*/
|
165 |
+
public function getOrderData($order, $store = null)
|
166 |
{
|
167 |
//Order must have a status
|
168 |
if (!$order->getStatus()){
|
180 |
$items = $this->getItemsData($order);
|
181 |
|
182 |
return array(
|
183 |
+
'siteId' => $this->getStoreConfig('siteid', $store), // SiteId is part of plugin configuration
|
184 |
'id' => $order->getIncrementId(), // Order reference, the same display to the buyer
|
185 |
'creationDate' => $this->formatDate($order->getCreatedAt()), // Date of the order as string in json format
|
186 |
'cartId' => $order->getQuoteId(), // Cart identifier, source of the order
|
187 |
'totalET' => (float)$order->getSubtotal(), // Amount excluded taxes and excluded shipping
|
188 |
+
'totalATI' => (float)$order->getGrandTotal(), // Paid amount
|
189 |
+
'currency' => $order->getOrderCurrencyCode(), // Currency as USD, EUR
|
190 |
+
'paymentMethod' => $order->getPayment()->getMethodInstance()->getTitle(), // Payment method label
|
191 |
'state' => $order->getStatus(), // raw order status
|
192 |
+
'accountId' => $email, // Account id of the buyer
|
193 |
'ip' => $order->getRemoteIp(), // User IP
|
194 |
'civility' => $this->notEmpty($gender), // Use string in this list : 'mister','madam','miss'
|
195 |
'lastname' => $this->notEmpty($address->getLastname()), // Lastname of the buyer
|
212 |
return;
|
213 |
}
|
214 |
|
215 |
+
//Get data, stop if none
|
216 |
$orderData = $this->getOrderData($order);
|
217 |
+
if (empty($orderData)) {
|
218 |
+
return;
|
219 |
}
|
220 |
+
|
221 |
+
//Push data to api
|
222 |
+
$this->doPostRequest('/orders', $orderData);
|
223 |
+
}
|
224 |
+
|
225 |
+
/**
|
226 |
+
* Map int of geder to string
|
227 |
+
* @param $gender
|
228 |
+
* @return string
|
229 |
+
*/
|
230 |
public function genderMapping($gender){
|
231 |
switch((int)$gender){
|
232 |
case 1:
|
237 |
return '';
|
238 |
}
|
239 |
}
|
240 |
+
|
241 |
/**
|
242 |
* This method return abounded cart data in cartsguru api format
|
243 |
* @param $quote
|
244 |
* @return array|void
|
245 |
*/
|
246 |
+
public function getAbadonnedCartData($quote, $store = null)
|
247 |
{
|
248 |
//Customer data
|
249 |
$gender = $this->genderMapping($quote->getCustomerGender());
|
303 |
}
|
304 |
|
305 |
return array(
|
306 |
+
'siteId' => $this->getStoreConfig('siteid', $store), // SiteId is part of plugin configuration
|
307 |
'id' => $quote->getId(), // Order reference, the same display to the buyer
|
308 |
'creationDate' => $this->formatDate($quote->getCreatedAt()), // Date of the order as string in json format
|
309 |
'totalET' => (float)$quote->getSubtotal(), // Amount excluded taxes and excluded shipping
|
310 |
'totalATI' => $this->getTotalATI($items), // Amount included taxes and excluded shipping
|
311 |
+
'currency' => $quote->getQuoteCurrencyCode(), // Currency as USD, EUR
|
312 |
'ip' => $quote->getRemoteIp(), // User IP
|
313 |
+
'accountId' => $email, // Account id of the buyer
|
314 |
'civility' => $gender, // Use string in this list : 'mister','madam','miss'
|
315 |
'lastname' => $this->notEmpty($lastname), // Lastname of the buyer
|
316 |
'firstname' => $this->notEmpty($firstname), // Firstname of the buyer
|
326 |
* This method send abounded cart data
|
327 |
* @param $quote
|
328 |
*/
|
329 |
+
public function sendAbadonnedCart($quote, $isImport = false)
|
330 |
{
|
331 |
//Check is well configured
|
332 |
if (!$this->isStoreConfigured()){
|
339 |
return;
|
340 |
}
|
341 |
|
342 |
+
if (!$isImport){
|
343 |
+
//Check not already sent
|
344 |
+
$cache = Mage::app()->getCache();
|
345 |
+
$cacheId = 'cg-quote-' . $quote->getId();
|
346 |
+
$cachedMd5 = $cache->load($cacheId);
|
347 |
+
$dataMd5 = md5(json_encode($cartData));
|
348 |
+
|
349 |
+
if ($dataMd5 == $cachedMd5) {
|
350 |
+
return;
|
351 |
}
|
352 |
+
|
353 |
+
$cache->save($dataMd5, $cacheId);
|
354 |
}
|
355 |
+
|
356 |
+
//Set special if import
|
357 |
+
$route = $isImport ? '/import/carts' : '/carts';
|
358 |
+
|
359 |
+
$this->doPostRequest($route, $cartData);
|
360 |
}
|
361 |
|
362 |
/**
|
394 |
* @param $customer
|
395 |
* @return array
|
396 |
*/
|
397 |
+
public function getCustomerData($customer, $store = null)
|
398 |
{
|
399 |
$address = $customer->getDefaultBillingAddress();
|
400 |
|
409 |
}
|
410 |
|
411 |
return array(
|
412 |
+
'siteId' => $this->getStoreConfig('siteid', $store), // SiteId is part of plugin configuration
|
413 |
+
'accountId' => $customer->getId(), // Account id of the customer
|
414 |
+
'civility' => $gender, // Use string in this list : 'mister','madam','miss'
|
415 |
+
'lastname' => $this->notEmpty($lastname), // Lastname of the buyer
|
416 |
+
'firstname' => $this->notEmpty($firstname), // Firstname of the buyer
|
417 |
+
'email' => $this->notEmpty($customer->getEmail()), // Email of the customer
|
418 |
+
'phoneNumber' => $this->notEmpty($phone), // Landline phone number of buyer (internationnal format)
|
419 |
'countryCode' => $this->notEmpty($country)
|
420 |
);
|
421 |
}
|
447 |
$requestUrl = '/sites/' . $this->getStoreConfig('siteid', $store) . '/register-plugin';
|
448 |
$fields = array(
|
449 |
'plugin' => 'magento',
|
450 |
+
'pluginVersion' => '1.2.6',
|
451 |
'storeVersion' => Mage::getVersion()
|
452 |
);
|
453 |
|
454 |
$response = $this->doPostRequest($requestUrl, $fields, $store);
|
|
|
|
|
|
|
455 |
|
456 |
+
if (!$response || $response->getStatus() != 200){
|
457 |
+
return false;
|
458 |
+
}
|
459 |
+
|
460 |
+
return json_decode($response->getBody());
|
461 |
}
|
462 |
|
463 |
+
|
464 |
+
/* Send quote and order history
|
465 |
+
*
|
466 |
+
* @param int $quoteId
|
467 |
+
* @param string|int $store
|
468 |
+
* @return Mage_Sales_Model_Quote
|
469 |
+
*/
|
470 |
+
public function sendHistory()
|
471 |
+
{
|
472 |
+
$store = $this->getStoreFromAdmin();
|
473 |
+
|
474 |
+
$lastOrder = $this->sendLastOrders($store);
|
475 |
+
if ($lastOrder){
|
476 |
+
$this->sendLastQuotes($store, $lastOrder->getCreatedAt());
|
477 |
+
}
|
478 |
+
}
|
479 |
+
|
480 |
+
private function sendLastOrders($store){
|
481 |
+
$orders = [];
|
482 |
+
$last = null;
|
483 |
+
$items = Mage::getModel('sales/order')
|
484 |
+
->getCollection()
|
485 |
+
->setOrder('created_at', 'desc')
|
486 |
+
->setPageSize($this->historySize)
|
487 |
+
->join(array('stores' => 'core/store'), 'main_table.store_id=stores.store_id')
|
488 |
+
->addFieldToFilter('stores.website_id', $store->getWebsiteId())
|
489 |
+
->addFieldToFilter('created_at', array('gt' => date("Y-m-d H:i:s", strtotime('-1 month'))));
|
490 |
+
|
491 |
+
//Check count of items
|
492 |
+
if (count($items) > $this->historySize){
|
493 |
+
$items = Mage::getModel('sales/order')
|
494 |
+
->getCollection()
|
495 |
+
->setOrder('created_at', 'desc')
|
496 |
+
->join(array('stores' => 'core/store'), 'main_table.store_id=stores.store_id')
|
497 |
+
->addFieldToFilter('stores.website_id', $store->getWebsiteId())
|
498 |
+
->addFieldToFilter('created_at', array('gt' => date("Y-m-d H:i:s", strtotime('-1 month'))))
|
499 |
+
->setPageSize($this->historySize);
|
500 |
+
}
|
501 |
+
else {
|
502 |
+
$items = Mage::getModel('sales/order')
|
503 |
+
->getCollection()
|
504 |
+
->setOrder('created_at', 'desc')
|
505 |
+
->join(array('stores' => 'core/store'), 'main_table.store_id=stores.store_id')
|
506 |
+
->addFieldToFilter('stores.website_id', $store->getWebsiteId())
|
507 |
+
->addFieldToFilter('created_at', array('gt' => date("Y-m-d H:i:s", strtotime('-12 month'))))
|
508 |
+
->setPageSize($this->historySize);
|
509 |
+
}
|
510 |
+
|
511 |
+
foreach($items as $item){
|
512 |
+
$order = Mage::getModel("sales/order")->load($item->getId());
|
513 |
+
$last = $order;
|
514 |
+
|
515 |
+
//Get order data
|
516 |
+
$orderData = $this->getOrderData($order, $store);
|
517 |
+
|
518 |
+
//Append only if we get it
|
519 |
+
if (!empty($orderData)){
|
520 |
+
$orders[] = $orderData;
|
521 |
+
}
|
522 |
+
}
|
523 |
+
|
524 |
+
//Push orders to api
|
525 |
+
if (!empty($orders)){
|
526 |
+
$this->doPostRequest('/import/orders', $orders, $store);
|
527 |
+
}
|
528 |
+
|
529 |
+
return $last;
|
530 |
+
}
|
531 |
+
|
532 |
+
private function sendLastQuotes($store, $since){
|
533 |
+
$quotes = [];
|
534 |
+
$last = null;
|
535 |
+
$items = Mage::getModel('sales/quote')
|
536 |
+
->getCollection()
|
537 |
+
->setOrder('created_at', 'asc')
|
538 |
+
->join(array('stores' => 'core/store'), 'main_table.store_id=stores.store_id')
|
539 |
+
->addFieldToFilter('stores.website_id', $store->getWebsiteId())
|
540 |
+
->addFieldToFilter('created_at', array('gt' => $since));
|
541 |
+
|
542 |
+
foreach($items as $item){
|
543 |
+
$quote = Mage::getModel("sales/quote")->loadByIdWithoutStore($item->getId());
|
544 |
+
$last = $quote;
|
545 |
+
|
546 |
+
if ($quote){
|
547 |
+
//Get quote data
|
548 |
+
$quoteData = $this->getAbadonnedCartData($quote, $store);
|
549 |
+
|
550 |
+
//Append only if we get it
|
551 |
+
if ($quoteData){
|
552 |
+
$quotes[] = $quoteData;
|
553 |
+
}
|
554 |
+
}
|
555 |
+
}
|
556 |
+
|
557 |
+
//Push quotes to api
|
558 |
+
if (!empty($quotes)){
|
559 |
+
$this->doPostRequest('/import/carts', $quotes, $store);
|
560 |
+
}
|
561 |
+
|
562 |
+
return $last;
|
563 |
+
}
|
564 |
+
|
565 |
+
|
566 |
/**
|
567 |
* This method send data on api path
|
568 |
* @param $apiPath
|
569 |
* @param $fields
|
570 |
* @return Zend_Http_Response
|
571 |
*/
|
572 |
+
private function doPostRequest($apiPath, $fields, $store=null)
|
573 |
{
|
574 |
try {
|
575 |
$url = $this->apiBaseUrl . $apiPath;
|
app/code/local/Cartsguru/controllers/RecovercartController.php
CHANGED
@@ -2,13 +2,18 @@
|
|
2 |
|
3 |
class Cartsguru_RecovercartController extends Mage_Core_Controller_Front_Action {
|
4 |
|
|
|
|
|
|
|
|
|
|
|
5 |
public function indexAction(){
|
6 |
// Get request params
|
7 |
$params = $this->getRequest()->getParams();
|
8 |
|
9 |
// Stop if no enoguth params
|
10 |
if (!isset($params['cart_id']) || !isset($params['cart_token'])){
|
11 |
-
return;
|
12 |
}
|
13 |
|
14 |
// Load quote by id
|
@@ -16,13 +21,13 @@ class Cartsguru_RecovercartController extends Mage_Core_Controller_Front_Action
|
|
16 |
|
17 |
// Stop if quote does not exist
|
18 |
if (!$quote->getId()){
|
19 |
-
return;
|
20 |
}
|
21 |
|
22 |
// Check quote token
|
23 |
$token = $quote->getData('cartsguru_token');
|
24 |
if (!$token || $token != $params['cart_token']){
|
25 |
-
return;
|
26 |
}
|
27 |
|
28 |
// Auto log customer if we can
|
@@ -59,16 +64,14 @@ class Cartsguru_RecovercartController extends Mage_Core_Controller_Front_Action
|
|
59 |
}
|
60 |
}
|
61 |
}
|
62 |
-
|
63 |
-
|
64 |
|
65 |
$quote->save();
|
66 |
$cart->setQuote($quote);
|
67 |
$cart->init();
|
68 |
$cart->save();
|
69 |
}
|
|
|
70 |
// Redirect to checkout
|
71 |
-
|
72 |
-
$this->getResponse()->setRedirect($url)->sendResponse();
|
73 |
}
|
74 |
}
|
2 |
|
3 |
class Cartsguru_RecovercartController extends Mage_Core_Controller_Front_Action {
|
4 |
|
5 |
+
private function redirectToCart() {
|
6 |
+
$url = Mage::helper('checkout/cart')->getCartUrl();
|
7 |
+
$this->getResponse()->setRedirect($url)->sendResponse();
|
8 |
+
}
|
9 |
+
|
10 |
public function indexAction(){
|
11 |
// Get request params
|
12 |
$params = $this->getRequest()->getParams();
|
13 |
|
14 |
// Stop if no enoguth params
|
15 |
if (!isset($params['cart_id']) || !isset($params['cart_token'])){
|
16 |
+
return redirectToCart();
|
17 |
}
|
18 |
|
19 |
// Load quote by id
|
21 |
|
22 |
// Stop if quote does not exist
|
23 |
if (!$quote->getId()){
|
24 |
+
return redirectToCart();
|
25 |
}
|
26 |
|
27 |
// Check quote token
|
28 |
$token = $quote->getData('cartsguru_token');
|
29 |
if (!$token || $token != $params['cart_token']){
|
30 |
+
return redirectToCart();
|
31 |
}
|
32 |
|
33 |
// Auto log customer if we can
|
64 |
}
|
65 |
}
|
66 |
}
|
|
|
|
|
67 |
|
68 |
$quote->save();
|
69 |
$cart->setQuote($quote);
|
70 |
$cart->init();
|
71 |
$cart->save();
|
72 |
}
|
73 |
+
|
74 |
// Redirect to checkout
|
75 |
+
return redirectToCart();
|
|
|
76 |
}
|
77 |
}
|
app/code/local/Cartsguru/etc/config.xml
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
<!-- plugin name -->
|
4 |
<modules>
|
5 |
<Cartsguru>
|
6 |
-
<version>1.2.
|
7 |
</Cartsguru>
|
8 |
</modules>
|
9 |
<global>
|
@@ -44,25 +44,6 @@
|
|
44 |
</cartsguru_admin_system_config_changed_section_cartsguru>
|
45 |
</observers>
|
46 |
</admin_system_config_changed_section_cartsguru>
|
47 |
-
<sales_order_place_after>
|
48 |
-
<observers>
|
49 |
-
<cartsguru_sales_order_save_after>
|
50 |
-
<type>singleton</type>
|
51 |
-
<class>cartsguru/observer</class>
|
52 |
-
<method>orderSaveAfter</method>
|
53 |
-
</cartsguru_sales_order_save_after>
|
54 |
-
</observers>
|
55 |
-
</sales_order_place_after>
|
56 |
-
<sales_order_save_after>
|
57 |
-
<observers>
|
58 |
-
<cartsguru_sales_order_save_after>
|
59 |
-
<type>singleton</type>
|
60 |
-
<class>cartsguru/observer</class>
|
61 |
-
<method>orderSaveAfter</method>
|
62 |
-
</cartsguru_sales_order_save_after>
|
63 |
-
</observers>
|
64 |
-
</sales_order_save_after>
|
65 |
-
<!-- when customer register this hooks call two times-->
|
66 |
<customer_save_after>
|
67 |
<observers>
|
68 |
<cartsguru_customer_save_after>
|
@@ -72,33 +53,6 @@
|
|
72 |
</cartsguru_customer_save_after>
|
73 |
</observers>
|
74 |
</customer_save_after>
|
75 |
-
<customer_register_success>
|
76 |
-
<observers>
|
77 |
-
<cartsguru_customer_register_success>
|
78 |
-
<type>singleton</type>
|
79 |
-
<class>cartsguru/observer</class>
|
80 |
-
<method>customerSaveAfter</method>
|
81 |
-
</cartsguru_customer_register_success>
|
82 |
-
</observers>
|
83 |
-
</customer_register_success>
|
84 |
-
<sales_quote_remove_item>
|
85 |
-
<observers>
|
86 |
-
<cartsguru_sales_quote_remove_item>
|
87 |
-
<type>singleton</type>
|
88 |
-
<class>cartsguru/observer</class>
|
89 |
-
<method>productAddAfter</method>
|
90 |
-
</cartsguru_sales_quote_remove_item>
|
91 |
-
</observers>
|
92 |
-
</sales_quote_remove_item>
|
93 |
-
<checkout_cart_product_add_after>
|
94 |
-
<observers>
|
95 |
-
<cartsguru_cart_product_add_after>
|
96 |
-
<type>singleton</type>
|
97 |
-
<class>cartsguru/observer</class>
|
98 |
-
<method>productAddAfter</method>
|
99 |
-
</cartsguru_cart_product_add_after>
|
100 |
-
</observers>
|
101 |
-
</checkout_cart_product_add_after>
|
102 |
<sales_quote_save_before>
|
103 |
<observers>
|
104 |
<cartsguru_sales_quote_save_before>
|
@@ -113,10 +67,19 @@
|
|
113 |
<cartsguru_sales_quote_save_after>
|
114 |
<type>singleton</type>
|
115 |
<class>cartsguru/observer</class>
|
116 |
-
<method>
|
117 |
</cartsguru_sales_quote_save_after>
|
118 |
</observers>
|
119 |
</sales_quote_save_after>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
</events>
|
121 |
</global>
|
122 |
<adminhtml>
|
3 |
<!-- plugin name -->
|
4 |
<modules>
|
5 |
<Cartsguru>
|
6 |
+
<version>1.2.6</version>
|
7 |
</Cartsguru>
|
8 |
</modules>
|
9 |
<global>
|
44 |
</cartsguru_admin_system_config_changed_section_cartsguru>
|
45 |
</observers>
|
46 |
</admin_system_config_changed_section_cartsguru>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
<customer_save_after>
|
48 |
<observers>
|
49 |
<cartsguru_customer_save_after>
|
53 |
</cartsguru_customer_save_after>
|
54 |
</observers>
|
55 |
</customer_save_after>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
<sales_quote_save_before>
|
57 |
<observers>
|
58 |
<cartsguru_sales_quote_save_before>
|
67 |
<cartsguru_sales_quote_save_after>
|
68 |
<type>singleton</type>
|
69 |
<class>cartsguru/observer</class>
|
70 |
+
<method>quoteSaveAfter</method>
|
71 |
</cartsguru_sales_quote_save_after>
|
72 |
</observers>
|
73 |
</sales_quote_save_after>
|
74 |
+
<sales_order_save_after>
|
75 |
+
<observers>
|
76 |
+
<cartsguru_sales_order_save_after>
|
77 |
+
<type>singleton</type>
|
78 |
+
<class>cartsguru/observer</class>
|
79 |
+
<method>orderSaveAfter</method>
|
80 |
+
</cartsguru_sales_order_save_after>
|
81 |
+
</observers>
|
82 |
+
</sales_order_save_after>
|
83 |
</events>
|
84 |
</global>
|
85 |
<adminhtml>
|
app/code/local/Cartsguru/sql/cartsguru_setup/upgrade-1.2.5-1.2.6.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/* @var $installer Mage_Core_Model_Resource_Setup */
|
3 |
+
$installer = $this;
|
4 |
+
|
5 |
+
$installer->startSetup();
|
6 |
+
$installer->endSetup();
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>cartsguru</name>
|
4 |
-
<version>1.2.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/gpl-license.php">GPL</license>
|
7 |
<channel>community</channel>
|
@@ -18,11 +18,12 @@ Effortlessly reduce the number of abandoned shopping carts by automating telepho
|
|
18 |

|
19 |
- SMS Callback &amp; Push SMS
|
20 |
Send to your prospective customers having abandoned a cart, an SMS suggesting a free call back from your customer relations service, a straightforward SMS reminder or an SMS offering a personalized discount</description>
|
21 |
-
<notes>-
|
|
|
22 |
<authors><author><name>Maxime Pruvost</name><user>cgmaximepruvost</user><email>maxime@carts.guru</email></author></authors>
|
23 |
-
<date>2016-
|
24 |
-
<time>
|
25 |
-
<contents><target name="magelocal"><dir name="Cartsguru"><dir name="Helper"><file name="Data.php" hash="f6590d08ba862a169ce43459ddb1193c"/><file name="Tools.php" hash="612133db113c08e7de7ab94a86d23e34"/></dir><dir name="Model"><file name="Observer.php" hash="
|
26 |
<compatible/>
|
27 |
<dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
|
28 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>cartsguru</name>
|
4 |
+
<version>1.2.6</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/gpl-license.php">GPL</license>
|
7 |
<channel>community</channel>
|
18 |

|
19 |
- SMS Callback &amp; Push SMS
|
20 |
Send to your prospective customers having abandoned a cart, an SMS suggesting a free call back from your customer relations service, a straightforward SMS reminder or an SMS offering a personalized discount</description>
|
21 |
+
<notes>- Improve handle of orders
|
22 |
+
- Add import of data when init the plugin</notes>
|
23 |
<authors><author><name>Maxime Pruvost</name><user>cgmaximepruvost</user><email>maxime@carts.guru</email></author></authors>
|
24 |
+
<date>2016-07-08</date>
|
25 |
+
<time>11:55:11</time>
|
26 |
+
<contents><target name="magelocal"><dir name="Cartsguru"><dir name="Helper"><file name="Data.php" hash="f6590d08ba862a169ce43459ddb1193c"/><file name="Tools.php" hash="612133db113c08e7de7ab94a86d23e34"/></dir><dir name="Model"><file name="Observer.php" hash="d729fe51e4430b0becdefc239ecce351"/><file name="Webservice.php" hash="dad7e2bbf1016976bc1a7a8914a24925"/></dir><dir name="controllers"><file name="IndexController.php" hash="108acaab218e2a5e79a12677f83ebc29"/><file name="RecovercartController.php" hash="07319f26b2a2ec238ffe7fb32288a3a9"/></dir><dir name="etc"><file name="config.xml" hash="1b497e6441153c7fb37fdb34a81b5df6"/><file name="system.xml" hash="cb0fbf86d2be47dbd719739ee79c4cba"/></dir><dir name="sql"><dir name="cartsguru_setup"><file name="install-1.0.0.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.0.0-1.0.1.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.0.1-1.0.2.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.0.2-1.1.0.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.1.0-1.1.1.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.1.1-1.1.2.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.1.2-1.1.3.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.1.3-1.1.4 .php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.1.4-1.1.5.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.1.5-1.2.0.php" hash="066c5cfb9870c04737cba2d2edb30a40"/><file name="upgrade-1.2.0-1.2.1.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.2.1-1.2.2.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.2.2-1.2.3.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.2.3-1.2.4.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.2.4-1.2.5.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.2.5-1.2.6.php" hash="381716ae5001678f8bcc6680bad68015"/></dir></dir></dir></target><target name="magelocale"><dir name="fr_FR"><file name="CartsGuru.csv" hash="b6d51893c33ddef1d53372d3a23b036c"/></dir><dir name="en_US"><file name="CartsGuru.csv" hash="921cb4133db47471456759443bb269f5"/></dir></target><target name="mageetc"><dir name="modules"><file name="Cartsguru.xml" hash="32bfa7d63b1a5b6b8f7977bf31af4e28"/></dir></target></contents>
|
27 |
<compatible/>
|
28 |
<dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
|
29 |
</package>
|