cartsguru - Version 1.3.3

Version Notes

- New catalog query
- Fix multistore issues
- Correct customer group when not logged in

Download this release

Release Info

Developer Maxime Pruvost
Extension cartsguru
Version 1.3.3
Comparing to
See all releases


Code changes from version 1.3.2 to 1.3.3

app/code/local/Cartsguru/Block/Pixel.php CHANGED
@@ -7,7 +7,7 @@ class Cartsguru_Block_Pixel extends Mage_Core_Block_Template
7
*/
8
protected function isFacebookEnabled()
9
{
10
- return Mage::getStoreConfig("cartsguru/cartsguru_group/feature_facebook");
11
}
12
13
/**
@@ -15,7 +15,7 @@ class Cartsguru_Block_Pixel extends Mage_Core_Block_Template
15
*/
16
protected function getPixel()
17
{
18
- return Mage::getStoreConfig("cartsguru/cartsguru_group/facebook_pixel");
19
}
20
21
/**
@@ -23,7 +23,7 @@ class Cartsguru_Block_Pixel extends Mage_Core_Block_Template
23
*/
24
protected function getCatalogId()
25
{
26
- return Mage::getStoreConfig("cartsguru/cartsguru_group/facebook_catalogId");
27
}
28
29
/**
7
*/
8
protected function isFacebookEnabled()
9
{
10
+ return Mage::helper('cartsguru')->getStoreConfig("feature_facebook");
11
}
12
13
/**
15
*/
16
protected function getPixel()
17
{
18
+ return Mage::helper('cartsguru')->getStoreConfig("facebook_pixel");
19
}
20
21
/**
23
*/
24
protected function getCatalogId()
25
{
26
+ return Mage::helper('cartsguru')->getStoreConfig("facebook_catalogId");
27
}
28
29
/**
app/code/local/Cartsguru/Helper/Data.php CHANGED
@@ -1,49 +1,105 @@
1
<?php
2
3
/**
4
- * Class of Magento core helper abstraction
5
- * Class Cartsguru_Helper_Data
6
- */
7
- class Cartsguru_Helper_Data extends Mage_Core_Helper_Abstract
8
- {
9
- // Get customer language from browser
10
- public function getBrowserLanguage()
11
- {
12
- if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
13
- foreach (explode(",", strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])) as $accept) {
14
- if (preg_match("!([a-z-]+)(;q=([0-9\\.]+))?!", trim($accept), $found)) {
15
- $langs[] = $found[1];
16
- $quality[] = (isset($found[3]) ? (float) $found[3] : 1.0);
17
- }
18
- }
19
- // Order the codes by quality
20
- array_multisort($quality, SORT_NUMERIC, SORT_DESC, $langs);
21
- // get list of stores and use the store code for the key
22
- $stores = Mage::app()->getStores(false, true);
23
- // iterate through languages found in the accept-language header
24
- foreach ($langs as $lang) {
25
- $lang = substr($lang, 0, 2);
26
- return $lang;
27
- }
28
- }
29
- return null;
30
- }
31
-
32
- // Get customer group name
33
- public function getCustomerGroupName()
34
- {
35
- $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
36
- $groupName = Mage::getSingleton('customer/group')->load($groupId)->getData('customer_group_code');
37
- return strtolower($groupName);
38
- }
39
-
40
- // Check if customer has orders
41
- public function isNewCustomer($email)
42
- {
43
if ($email && $email !== '') {
44
$orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_email', $email);
45
return $orders->count() === 0;
46
}
47
return false;
48
- }
49
}
1
<?php
2
3
/**
4
+ * Class of Magento core helper abstraction
5
+ * Class Cartsguru_Helper_Data
6
+ */
7
+ class Cartsguru_Helper_Data extends Mage_Core_Helper_Abstract
8
+ {
9
+ private $configBasePath = 'cartsguru/cartsguru_group/';
10
+
11
+ // Get customer language from browser
12
+ public function getBrowserLanguage()
13
+ {
14
+ if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
15
+ foreach (explode(",", strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])) as $accept) {
16
+ if (preg_match("!([a-z-]+)(;q=([0-9\\.]+))?!", trim($accept), $found)) {
17
+ $langs[] = $found[1];
18
+ $quality[] = (isset($found[3]) ? (float) $found[3] : 1.0);
19
+ }
20
+ }
21
+ // Order the codes by quality
22
+ array_multisort($quality, SORT_NUMERIC, SORT_DESC, $langs);
23
+ // get list of stores and use the store code for the key
24
+ $stores = Mage::app()->getStores(false, true);
25
+ // iterate through languages found in the accept-language header
26
+ foreach ($langs as $lang) {
27
+ $lang = substr($lang, 0, 2);
28
+ return $lang;
29
+ }
30
+ }
31
+ return null;
32
+ }
33
+
34
+ // Get customer group name
35
+ public function getCustomerGroupName($email)
36
+ {
37
+ $groupName = 'not logged in';
38
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
39
+ $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
40
+ $groupName = Mage::getSingleton('customer/group')->load($groupId)->getData('customer_group_code');
41
+ } elseif ($email && $email !== '') {
42
+ $customer = Mage::getModel("customer/customer");
43
+ $customer->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
44
+ $customer->loadByEmail($email);
45
+ if ($customer) {
46
+ $groupId = $customer->getGroupId();
47
+ $groupName = Mage::getSingleton('customer/group')->load($groupId)->getData('customer_group_code');
48
+ }
49
+ }
50
+ return strtolower($groupName);
51
+ }
52
+
53
+ // Check if customer has orders
54
+ public function isNewCustomer($email)
55
+ {
56
if ($email && $email !== '') {
57
$orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_email', $email);
58
return $orders->count() === 0;
59
}
60
return false;
61
+ }
62
+
63
+ // Get store from admin
64
+ public function getStoreFromAdmin(){
65
+ $store_id = null;
66
+ if (strlen($code = Mage::getSingleton('adminhtml/config_data')->getStore())) // store level
67
+ {
68
+ $store_id = Mage::getModel('core/store')->load($code)->getId();
69
+ }
70
+ elseif (strlen($code = Mage::getSingleton('adminhtml/config_data')->getWebsite())) // website level
71
+ {
72
+ $website_id = Mage::getModel('core/website')->load($code)->getId();
73
+ $store_id = Mage::app()->getWebsite($website_id)->getDefaultStore()->getId();
74
+ }
75
+ elseif (strlen($code = Mage::app()->getRequest()->getParam('website'))) {
76
+ $website_id = Mage::getModel('core/website')->load($code)->getId();
77
+ $store_id = Mage::app()->getWebsite($website_id)->getDefaultStore()->getId();
78
+ }
79
+
80
+ if ($store_id){
81
+ return Mage::app()->getStore($store_id);
82
+ }
83
+ else {
84
+ return Mage::app()->getStore();
85
+ }
86
+ }
87
+
88
+ // Save config in store
89
+ public function setStoreConfig($key, $value, $store = null)
90
+ {
91
+ if (!$store){
92
+ $store = Mage::app()->getStore();
93
+ }
94
+
95
+ Mage::getConfig()->saveConfig($this->configBasePath . $key, $value, 'stores', $store->getStoreId());
96
+ }
97
+ // Get store config
98
+ public function getStoreConfig($key, $store = null){
99
+ if (!$store){
100
+ $store = Mage::app()->getStore();
101
+ }
102
+
103
+ return $store->getConfig($this->configBasePath . $key);
104
+ }
105
}
app/code/local/Cartsguru/Model/Catalog.php CHANGED
@@ -6,11 +6,6 @@
6
*/
7
class Cartsguru_Model_Catalog {
8
9
- /**
10
- * @var XMLWriter
11
- */
12
- protected $doc;
13
-
14
/**
15
* The fields to be put into the feed.
16
* @var array
@@ -18,43 +13,43 @@ class Cartsguru_Model_Catalog {
18
protected $_requiredFields = array(
19
array(
20
'magento' => 'id',
21
- 'feed' => 'g:id',
22
'type' => 'id',
23
),
24
array(
25
'magento' => 'availability_google',
26
- 'feed' => 'g:availability',
27
'type' => 'computed',
28
),
29
// condition here
30
array(
31
'magento' => 'description',
32
- 'feed' => 'g:description',
33
'type' => 'product_attribute',
34
),
35
array(
36
'magento' => 'image_url',
37
- 'feed' => 'g:image_link',
38
'type' => 'computed',
39
),
40
array(
41
'magento' => 'product_link',
42
- 'feed' => 'g:link',
43
'type' => 'computed',
44
),
45
array(
46
'magento' => 'name',
47
- 'feed' => 'g:title',
48
'type' => 'product_attribute',
49
),
50
array(
51
'magento' => 'manufacturer',
52
- 'feed' => 'g:brand',
53
'type' => 'product_attribute',
54
),
55
array(
56
'magento' => 'price',
57
- 'feed' => 'g:price',
58
'type' => 'computed',
59
)
60
);
@@ -62,24 +57,30 @@ class Cartsguru_Model_Catalog {
62
/*
63
* Generate XML product feed
64
*/
65
- public function generateFeed()
66
{
67
// setup attribute mapping
68
$this->_attributes = array();
69
foreach ($this->_requiredFields as $requiredField) {
70
$this->_attributes[$requiredField['feed']] = $requiredField;
71
}
72
73
- $this->setupHeader(Mage::app()->getStore());
74
$productCollection = Mage::getResourceModel('catalog/product_collection');
75
$productCollection->addStoreFilter();
76
77
$this->_products = array();
78
- Mage::getSingleton('core/resource_iterator')->walk($productCollection->getSelect(), array(array($this, 'processProduct')));
79
80
- $this->setupFooter();
81
-
82
- return $this->doc->flush();
83
}
84
85
/*
@@ -134,42 +135,39 @@ class Cartsguru_Model_Catalog {
134
$product_data[$attribute['feed']] = $value;
135
}
136
137
- $price = floatval($product_data['g:price']);
138
// Price is required
139
if (empty($price)) {
140
return;
141
}
142
143
// If manufacturer not set use mpn === sku
144
- if ($product_data['g:brand'] === '') {
145
- unset($product_data['g:brand']);
146
- $product_data['g:mpn'] = $product_data['g:id'];
147
}
148
149
// All products are new
150
- $product_data['g:condition'] = 'new';
151
-
152
- // Sart new feed entry
153
- $this->doc->startElement('entry');
154
155
foreach ($product_data as $feedTag => $value) {
156
$safeString = null;
157
switch ($feedTag) {
158
- case 'g:link':
159
$safeString = $value;
160
break;
161
162
- case 'g:price':
163
$safeString = sprintf('%.2f', $store->convertPrice($value, false, false)).' '.Mage::getStoreConfig('currency/options/default', $store->getStoreId());
164
break;
165
166
- case 'g:sale_price':
167
if($value && $value != ''){
168
$safeString = sprintf('%.2f', $store->convertPrice($value, false, false)).' '.Mage::getStoreConfig('currency/options/default', $store->getStoreId());
169
}
170
break;
171
172
- case 'g:image_link':
173
if ($value == 'no_selection') {
174
$safeString = '';
175
} else {
@@ -186,38 +184,9 @@ class Cartsguru_Model_Catalog {
186
break;
187
}
188
if ($safeString !== null) {
189
- $this->doc->writeElement($feedTag, $safeString);
190
}
191
}
192
- $this->doc->endElement();
193
- }
194
-
195
- /*
196
- * Instantiate the XML object
197
- */
198
- protected function setupHeader($store)
199
- {
200
- $this->doc = new XMLWriter();
201
- $this->doc->openMemory();
202
- $this->doc->setIndent(true);
203
- $this->doc->setIndentString(' ');
204
- $this->doc->startDocument('1.0', 'UTF-8');
205
- $this->doc->startElement('feed');
206
- $this->doc->writeAttribute('xmlns', 'http://www.w3.org/2005/Atom');
207
- $this->doc->writeAttribute('xmlns:g', 'http://base.google.com/ns/1.0');
208
- $this->doc->writeElement('title', $store->getName());
209
- $this->doc->startElement('link');
210
- $this->doc->writeAttribute('rel', 'self');
211
- $this->doc->writeAttribute('href', $store->getBaseUrl());
212
- $this->doc->endElement();
213
- }
214
-
215
- /*
216
- * Close the XML object
217
- */
218
- protected function setupFooter()
219
- {
220
- $this->doc->endElement();
221
- $this->doc->endDocument();
222
}
223
}
6
*/
7
class Cartsguru_Model_Catalog {
8
9
/**
10
* The fields to be put into the feed.
11
* @var array
13
protected $_requiredFields = array(
14
array(
15
'magento' => 'id',
16
+ 'feed' => 'id',
17
'type' => 'id',
18
),
19
array(
20
'magento' => 'availability_google',
21
+ 'feed' => 'availability',
22
'type' => 'computed',
23
),
24
// condition here
25
array(
26
'magento' => 'description',
27
+ 'feed' => 'description',
28
'type' => 'product_attribute',
29
),
30
array(
31
'magento' => 'image_url',
32
+ 'feed' => 'image_link',
33
'type' => 'computed',
34
),
35
array(
36
'magento' => 'product_link',
37
+ 'feed' => 'link',
38
'type' => 'computed',
39
),
40
array(
41
'magento' => 'name',
42
+ 'feed' => 'title',
43
'type' => 'product_attribute',
44
),
45
array(
46
'magento' => 'manufacturer',
47
+ 'feed' => 'brand',
48
'type' => 'product_attribute',
49
),
50
array(
51
'magento' => 'price',
52
+ 'feed' => 'price',
53
'type' => 'computed',
54
)
55
);
57
/*
58
* Generate XML product feed
59
*/
60
+ public function generateFeed($store, $offset, $limit)
61
{
62
// setup attribute mapping
63
$this->_attributes = array();
64
+
65
foreach ($this->_requiredFields as $requiredField) {
66
$this->_attributes[$requiredField['feed']] = $requiredField;
67
}
68
69
+ $result = array(
70
+ 'url' => $store->getBaseUrl(),
71
+ 'store_name' => $store->getFrontendName(),
72
+ 'total' => Mage::getModel('catalog/product')->getCollection()->addStoreFilter()->addFieldToFilter('status', '1')->getSize()
73
+ );
74
+
75
$productCollection = Mage::getResourceModel('catalog/product_collection');
76
$productCollection->addStoreFilter();
77
+ $productCollection->addFieldToFilter('status', '1');
78
79
$this->_products = array();
80
+ Mage::getSingleton('core/resource_iterator')->walk($productCollection->getSelect()->limit($limit, $offset), array(array($this, 'processProduct')));
81
+ $result['products'] = $this->_products;
82
83
+ return $result;
84
}
85
86
/*
135
$product_data[$attribute['feed']] = $value;
136
}
137
138
+ $price = floatval($product_data['price']);
139
// Price is required
140
if (empty($price)) {
141
return;
142
}
143
144
// If manufacturer not set use mpn === sku
145
+ if ($product_data['brand'] === '') {
146
+ unset($product_data['brand']);
147
+ $product_data['mpn'] = $product_data['id'];
148
}
149
150
// All products are new
151
+ $product_data['condition'] = 'new';
152
153
foreach ($product_data as $feedTag => $value) {
154
$safeString = null;
155
switch ($feedTag) {
156
+ case 'link':
157
$safeString = $value;
158
break;
159
160
+ case 'price':
161
$safeString = sprintf('%.2f', $store->convertPrice($value, false, false)).' '.Mage::getStoreConfig('currency/options/default', $store->getStoreId());
162
break;
163
164
+ case 'sale_price':
165
if($value && $value != ''){
166
$safeString = sprintf('%.2f', $store->convertPrice($value, false, false)).' '.Mage::getStoreConfig('currency/options/default', $store->getStoreId());
167
}
168
break;
169
170
+ case 'image_link':
171
if ($value == 'no_selection') {
172
$safeString = '';
173
} else {
184
break;
185
}
186
if ($safeString !== null) {
187
+ $product_data[$feedTag] = $safeString;
188
}
189
}
190
+ $this->_products[] = $product_data;
191
}
192
}
app/code/local/Cartsguru/Model/Observer.php CHANGED
@@ -105,7 +105,8 @@ class Cartsguru_Model_Observer
105
* @param $observer
106
*/
107
public function checkoutCartAdd($observer) {
108
- $facebook_enabled = Mage::getStoreConfig("cartsguru/cartsguru_group/feature_facebook");
109
if ($facebook_enabled) {
110
// Laod product
111
$product = Mage::getModel('catalog/product')
105
* @param $observer
106
*/
107
public function checkoutCartAdd($observer) {
108
+ $helper = Mage::helper('cartsguru');
109
+ $facebook_enabled = $helper->getStoreConfig("feature_facebook");
110
if ($facebook_enabled) {
111
// Laod product
112
$product = Mage::getModel('catalog/product')
app/code/local/Cartsguru/Model/Webservice.php CHANGED
@@ -7,7 +7,6 @@
7
class Cartsguru_Model_Webservice
8
{
9
private $apiBaseUrl = 'https://api.carts.guru';
10
- private $configBasePath = 'cartsguru/cartsguru_group/';
11
private $historySize = 250;
12
13
/* Main cache tag constant */
@@ -17,55 +16,14 @@ class Cartsguru_Model_Webservice
17
const QUOTES_CACHE_TAG = 'cartsguru_carts';
18
const QUOTES_CACHE_TTL = 1800; // 30min in seconds
19
20
- const _CARTSGURU_VERSION_ = '1.3.2';
21
-
22
- protected function getStoreFromAdmin(){
23
- $store_id = null;
24
- if (strlen($code = Mage::getSingleton('adminhtml/config_data')->getStore())) // store level
25
- {
26
- $store_id = Mage::getModel('core/store')->load($code)->getId();
27
- }
28
- elseif (strlen($code = Mage::getSingleton('adminhtml/config_data')->getWebsite())) // website level
29
- {
30
- $website_id = Mage::getModel('core/website')->load($code)->getId();
31
- $store_id = Mage::app()->getWebsite($website_id)->getDefaultStore()->getId();
32
- }
33
- elseif (strlen($code = Mage::app()->getRequest()->getParam('website'))) {
34
- $website_id = Mage::getModel('core/website')->load($code)->getId();
35
- $store_id = Mage::app()->getWebsite($website_id)->getDefaultStore()->getId();
36
- }
37
-
38
- if ($store_id){
39
- return Mage::app()->getStore($store_id);
40
- }
41
- else {
42
- return Mage::app()->getStore();
43
- }
44
- }
45
-
46
- public function setStoreConfig($key, $value, $store = null)
47
- {
48
- if (!$store){
49
- $store = Mage::app()->getStore();
50
- }
51
-
52
- $store->setConfig($this->configBasePath . $key, $value);
53
- }
54
-
55
- public function getStoreConfig($key, $store = null){
56
- if (!$store){
57
- $store = Mage::app()->getStore();
58
- }
59
-
60
- return $store->getConfig($this->configBasePath . $key);
61
- }
62
63
public function isStoreConfigured($store = null){
64
if (!$store){
65
$store = Mage::app()->getStore();
66
}
67
-
68
- return $this->getStoreConfig('siteid',$store) && $this->getStoreConfig('auth',$store);
69
}
70
71
/**
@@ -238,14 +196,14 @@ class Cartsguru_Model_Webservice
238
// Custom fields
239
$custom = array(
240
'language' => $helper->getBrowserLanguage(),
241
- 'customerGroup' => $helper->getCustomerGroupName(),
242
'isNewCustomer' => $helper->isNewCustomer($email)
243
);
244
// We do this to include the discounts in the totalET
245
$totalET = number_format((float)($order->getGrandTotal() - $order->getShippingAmount() - $order->getTaxAmount()), 2);
246
247
return array(
248
- 'siteId' => $this->getStoreConfig('siteid', $store), // SiteId is part of plugin configuration
249
'id' => $order->getIncrementId(), // Order reference, the same display to the buyer
250
'creationDate' => $this->formatDate($order->getCreatedAt()), // Date of the order as string in json format
251
'cartId' => $order->getQuoteId(), // Cart identifier, source of the order
@@ -368,7 +326,7 @@ class Cartsguru_Model_Webservice
368
// Custom fields
369
$custom = array(
370
'language' => $helper->getBrowserLanguage(),
371
- 'customerGroup' => $helper->getCustomerGroupName(),
372
'isNewCustomer' => $helper->isNewCustomer($email)
373
);
374
@@ -386,7 +344,7 @@ class Cartsguru_Model_Webservice
386
}
387
388
return array(
389
- 'siteId' => $this->getStoreConfig('siteid', $store), // SiteId is part of plugin configuration
390
'id' => $quote->getId(), // Order reference, the same display to the buyer
391
'creationDate' => $this->formatDate($quote->getCreatedAt()), // Date of the order as string in json format
392
'totalET' => (float)$quote->getSubtotal(), // Amount excluded taxes and excluded shipping
@@ -479,6 +437,7 @@ class Cartsguru_Model_Webservice
479
*/
480
public function getCustomerData($customer, $store = null)
481
{
482
$address = $customer->getDefaultBillingAddress();
483
484
$gender = $this->genderMapping($customer->getGender());
@@ -492,7 +451,7 @@ class Cartsguru_Model_Webservice
492
}
493
494
return array(
495
- 'siteId' => $this->getStoreConfig('siteid', $store), // SiteId is part of plugin configuration
496
'accountId' => $customer->getEmail(), // Account id of the customer
497
'civility' => $gender, // Use string in this list : 'mister','madam','miss'
498
'lastname' => $this->notEmpty($lastname), // Lastname of the buyer
@@ -525,13 +484,13 @@ class Cartsguru_Model_Webservice
525
*/
526
public function checkAddress()
527
{
528
- $store = $this->getStoreFromAdmin();
529
-
530
- $requestUrl = '/sites/' . $this->getStoreConfig('siteid', $store) . '/register-plugin';
531
$fields = array(
532
'plugin' => 'magento',
533
'pluginVersion' => Cartsguru_Model_Webservice::_CARTSGURU_VERSION_,
534
- 'adminUrl' => Mage::getBaseUrl() . 'cartsguru/admin?cartsguru_admin_action='
535
);
536
537
$response = $this->doPostRequest($requestUrl, $fields, $store, true);
@@ -632,6 +591,7 @@ class Cartsguru_Model_Webservice
632
private function doPostRequest($apiPath, $fields, $store=null, $isSync=false)
633
{
634
$response = null;
635
636
try {
637
$url = $this->apiBaseUrl . $apiPath;
@@ -640,7 +600,7 @@ class Cartsguru_Model_Webservice
640
'timeout' => $isSync ? 10 : 1 //We need only wait if is sync, seconds as integer
641
);
642
$client = new Zend_Http_Client($url, $options);
643
- $client->setHeaders('x-auth-key', $this->getStoreConfig('auth', $store));
644
$client->setHeaders('x-plugin-version', Cartsguru_Model_Webservice::_CARTSGURU_VERSION_);
645
$client->setUri($url);
646
$client->setRawData(json_encode($fields), 'application/json');
7
class Cartsguru_Model_Webservice
8
{
9
private $apiBaseUrl = 'https://api.carts.guru';
10
private $historySize = 250;
11
12
/* Main cache tag constant */
16
const QUOTES_CACHE_TAG = 'cartsguru_carts';
17
const QUOTES_CACHE_TTL = 1800; // 30min in seconds
18
19
+ const _CARTSGURU_VERSION_ = '1.3.3';
20
21
public function isStoreConfigured($store = null){
22
if (!$store){
23
$store = Mage::app()->getStore();
24
}
25
+ $helper = Mage::helper('cartsguru');
26
+ return $helper->getStoreConfig('siteid', $store) && $helper->getStoreConfig('auth', $store);
27
}
28
29
/**
196
// Custom fields
197
$custom = array(
198
'language' => $helper->getBrowserLanguage(),
199
+ 'customerGroup' => $helper->getCustomerGroupName($email),
200
'isNewCustomer' => $helper->isNewCustomer($email)
201
);
202
// We do this to include the discounts in the totalET
203
$totalET = number_format((float)($order->getGrandTotal() - $order->getShippingAmount() - $order->getTaxAmount()), 2);
204
205
return array(
206
+ 'siteId' => $helper->getStoreConfig('siteid', $store), // SiteId is part of plugin configuration
207
'id' => $order->getIncrementId(), // Order reference, the same display to the buyer
208
'creationDate' => $this->formatDate($order->getCreatedAt()), // Date of the order as string in json format
209
'cartId' => $order->getQuoteId(), // Cart identifier, source of the order
326
// Custom fields
327
$custom = array(
328
'language' => $helper->getBrowserLanguage(),
329
+ 'customerGroup' => $helper->getCustomerGroupName($email),
330
'isNewCustomer' => $helper->isNewCustomer($email)
331
);
332
344
}
345
346
return array(
347
+ 'siteId' => $helper->getStoreConfig('siteid', $store), // SiteId is part of plugin configuration
348
'id' => $quote->getId(), // Order reference, the same display to the buyer
349
'creationDate' => $this->formatDate($quote->getCreatedAt()), // Date of the order as string in json format
350
'totalET' => (float)$quote->getSubtotal(), // Amount excluded taxes and excluded shipping
437
*/
438
public function getCustomerData($customer, $store = null)
439
{
440
+ $helper = Mage::helper('cartsguru');
441
$address = $customer->getDefaultBillingAddress();
442
443
$gender = $this->genderMapping($customer->getGender());
451
}
452
453
return array(
454
+ 'siteId' => $helper->getStoreConfig('siteid', $store), // SiteId is part of plugin configuration
455
'accountId' => $customer->getEmail(), // Account id of the customer
456
'civility' => $gender, // Use string in this list : 'mister','madam','miss'
457
'lastname' => $this->notEmpty($lastname), // Lastname of the buyer
484
*/
485
public function checkAddress()
486
{
487
+ $helper = Mage::helper('cartsguru');
488
+ $store = $helper->getStoreFromAdmin();
489
+ $requestUrl = '/sites/' . $helper->getStoreConfig('siteid', $store) . '/register-plugin';
490
$fields = array(
491
'plugin' => 'magento',
492
'pluginVersion' => Cartsguru_Model_Webservice::_CARTSGURU_VERSION_,
493
+ 'adminUrl' => Mage::app()->getStore($store)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . 'cartsguru/admin?cartsguru_admin_action='
494
);
495
496
$response = $this->doPostRequest($requestUrl, $fields, $store, true);
591
private function doPostRequest($apiPath, $fields, $store=null, $isSync=false)
592
{
593
$response = null;
594
+ $helper = Mage::helper('cartsguru');
595
596
try {
597
$url = $this->apiBaseUrl . $apiPath;
600
'timeout' => $isSync ? 10 : 1 //We need only wait if is sync, seconds as integer
601
);
602
$client = new Zend_Http_Client($url, $options);
603
+ $client->setHeaders('x-auth-key', $helper->getStoreConfig('auth', $store));
604
$client->setHeaders('x-plugin-version', Cartsguru_Model_Webservice::_CARTSGURU_VERSION_);
605
$client->setUri($url);
606
$client->setRawData(json_encode($fields), 'application/json');
app/code/local/Cartsguru/controllers/AdminController.php CHANGED
@@ -2,11 +2,10 @@
2
3
class Cartsguru_AdminController extends Mage_Core_Controller_Front_Action {
4
5
- public function indexAction(){
6
$params = $this->getRequest()->getParams();
7
- $webservice = Mage::getModel('cartsguru/webservice');
8
- $store = Mage::app()->getWebsite(true)->getDefaultGroup()->getDefaultStore();
9
- $auth_key = $webservice->getStoreConfig('auth', $store);
10
// Stop if no enoguth params
11
if (!isset($params['cartsguru_admin_action']) || !isset($params['cartsguru_auth_key']) || $auth_key !== $params['cartsguru_auth_key']){
12
die;
@@ -18,17 +17,30 @@ class Cartsguru_AdminController extends Mage_Core_Controller_Front_Action {
18
// Enable facebook
19
if ($data['facebook'] && $data['catalogId'] && $data['pixel']) {
20
// Save facebook pixel
21
- Mage::getConfig()->saveConfig('cartsguru/cartsguru_group/feature_facebook', true);
22
- Mage::getConfig()->saveConfig('cartsguru/cartsguru_group/facebook_pixel', $data['pixel']);
23
- Mage::getConfig()->saveConfig('cartsguru/cartsguru_group/facebook_catalogId', $data['catalogId']);
24
// return catalogUrl
25
header('Content-Type: application/json; charset=utf-8');
26
- echo json_encode(array('catalogUrl' => Mage::getBaseUrl() . 'cartsguru/catalog'));
27
- die;
28
} elseif ($data['facebook'] == false) {
29
- Mage::getConfig()->saveConfig('cartsguru/cartsguru_group/feature_facebook', false);
30
}
31
}
32
}
33
}
34
}
2
3
class Cartsguru_AdminController extends Mage_Core_Controller_Front_Action {
4
5
+ public function indexAction() {
6
+ $helper = Mage::helper('cartsguru');
7
$params = $this->getRequest()->getParams();
8
+ $auth_key = $helper->getStoreConfig('auth');
9
// Stop if no enoguth params
10
if (!isset($params['cartsguru_admin_action']) || !isset($params['cartsguru_auth_key']) || $auth_key !== $params['cartsguru_auth_key']){
11
die;
17
// Enable facebook
18
if ($data['facebook'] && $data['catalogId'] && $data['pixel']) {
19
// Save facebook pixel
20
+ $helper->setStoreConfig('feature_facebook', true);
21
+ $helper->setStoreConfig('facebook_pixel', $data['pixel']);
22
+ $helper->setStoreConfig('facebook_catalogId', $data['catalogId']);
23
// return catalogUrl
24
header('Content-Type: application/json; charset=utf-8');
25
+ echo json_encode(array(
26
+ 'catalogUrl' => Mage::app()->getStore($store)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . 'cartsguru/catalog'
27
+ ));
28
} elseif ($data['facebook'] == false) {
29
+ $helper->setStoreConfig('feature_facebook', false);
30
}
31
}
32
}
33
+ // Get config
34
+ if ($params['cartsguru_admin_action'] === 'displayConfig') {
35
+ header('Content-Type: application/json; charset=utf-8');
36
+ echo json_encode(array(
37
+ 'CARTSG_SITE_ID' => $helper->getStoreConfig('siteid'),
38
+ 'CARTSG_FEATURE_FB' => $helper->getStoreConfig('feature_facebook'),
39
+ 'CARTSG_FB_PIXEL' => $helper->getStoreConfig('facebook_pixel'),
40
+ 'CARTSG_FB_CATALOGID' => $helper->getStoreConfig('facebook_catalogId'),
41
+ 'PLUGIN_VERSION'=> (string) Mage::getConfig()->getNode()->modules->Cartsguru->version
42
+ ));
43
+ }
44
+ die;
45
}
46
}
app/code/local/Cartsguru/controllers/CatalogController.php CHANGED
@@ -2,9 +2,23 @@
2
3
class Cartsguru_CatalogController extends Mage_Core_Controller_Front_Action {
4
5
- public function indexAction(){
6
$catalog = Mage::getModel('cartsguru/catalog');
7
- header('Content-Type: application/xml; charset=utf-8');
8
- echo $catalog->generateFeed();
9
}
10
}
2
3
class Cartsguru_CatalogController extends Mage_Core_Controller_Front_Action {
4
5
+ public function indexAction()
6
+ {
7
+ $helper = Mage::helper('cartsguru');
8
+ $params = $this->getRequest()->getParams();
9
+ $auth_key = $helper->getStoreConfig('auth');
10
+ // Stop if not authenticated
11
+ if (!isset($params['cartsguru_auth_key']) || $auth_key !== $params['cartsguru_auth_key']) {
12
+ die;
13
+ }
14
+ // Get input values
15
+ $offset = isset($params['cartsguru_catalog_offset']) ? $params['cartsguru_catalog_offset'] : 0;
16
+ $limit = isset($params['cartsguru_catalog_limit']) ? $params['cartsguru_catalog_limit'] : 50;
17
+
18
+ $store = Mage::app()->getStore();
19
$catalog = Mage::getModel('cartsguru/catalog');
20
+
21
+ $this->getResponse()->setHeader('Content-type', 'application/json');
22
+ $this->getResponse()->setBody(json_encode($catalog->generateFeed($store, $offset, $limit)));
23
}
24
}
app/code/local/Cartsguru/etc/config.xml CHANGED
@@ -3,7 +3,7 @@
3
<!-- plugin name -->
4
<modules>
5
<Cartsguru>
6
- <version>1.3.2</version>
7
</Cartsguru>
8
</modules>
9
<global>
3
<!-- plugin name -->
4
<modules>
5
<Cartsguru>
6
+ <version>1.3.3</version>
7
</Cartsguru>
8
</modules>
9
<global>
app/code/local/Cartsguru/sql/cartsguru_setup/upgrade-1.3.1-1.3.2.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();
app/code/local/Cartsguru/sql/cartsguru_setup/upgrade-1.3.2-1.3.3.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.3.2</version>
5
<stability>stable</stability>
6
<license uri="http://opensource.org/licenses/gpl-license.php">GPL</license>
7
<channel>community</channel>
@@ -16,11 +16,13 @@ Effortlessly reduce the number of abandoned shopping carts by automating telepho
16
&#xD;
17
- SMS Callback &amp; Push SMS&#xD;
18
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>
19
- <notes>- Fix totalET bug</notes>
20
<authors><author><name>Maxime Pruvost</name><user>cgmaximepruvost</user><email>maxime@carts.guru</email></author></authors>
21
- <date>2017-01-17</date>
22
- <time>12:14:43</time>
23
- <contents><target name="magelocal"><dir name="Cartsguru"><dir name="Block"><file name="Pixel.php" hash="1b0cce98dd02499a94534201329033b0"/></dir><dir name="Helper"><file name="Data.php" hash="bfdd570b0b1398578bd50354acfaee50"/><file name="Tools.php" hash="e2f56c3387eb0b0650aa5f49f8207618"/></dir><dir name="Model"><file name="Catalog.php" hash="93b42e79b4350978aa6da15e6305835c"/><file name="Observer.php" hash="6fbedb182fee9f8d52d8f86b9608c92a"/><file name="Webservice.php" hash="0dd0d5e94e640433b8798e69308de4f3"/></dir><dir name="controllers"><file name="AdminController.php" hash="35691c3127363c623e5c0c1a83a5c951"/><file name="CatalogController.php" hash="ce0b4523b20b094f1d0b438f0b8b1d42"/><file name="IndexController.php" hash="21147a5de4f498b13e9f402100a868e9"/><file name="RecovercartController.php" hash="4b0d7b3c0d18f5c451932caee9daac5b"/><file name="SaveaccountController.php" hash="6b490eca17f516a4f95bba9d4c45d30b"/></dir><dir name="etc"><file name="config.xml" hash="694ebbbeb76685506e1501cb12384b91"/><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.10-1.2.11.php" hash="84cb92331d31afda4f06aca50dbd597e"/><file name="upgrade-1.2.11-1.2.12.php" hash="84cb92331d31afda4f06aca50dbd597e"/><file name="upgrade-1.2.12-1.2.13.php" hash="84cb92331d31afda4f06aca50dbd597e"/><file name="upgrade-1.2.13-1.2.14.php" hash="84cb92331d31afda4f06aca50dbd597e"/><file name="upgrade-1.2.14-1.2.15.php" hash="c96e44a4737e1d8b0f4915c55a67c048"/><file name="upgrade-1.2.15-1.2.16.php" hash="c96e44a4737e1d8b0f4915c55a67c048"/><file name="upgrade-1.2.16-1.3.0.php" hash="c96e44a4737e1d8b0f4915c55a67c048"/><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"/><file name="upgrade-1.2.6-1.2.7.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.2.7-1.2.8.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.2.8-1.2.9.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.2.9-1.2.10.php" hash="84cb92331d31afda4f06aca50dbd597e"/><file name="upgrade-1.3.0-1.3.1.php" hash="c96e44a4737e1d8b0f4915c55a67c048"/></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><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="cartsguru.xml" hash="a886b0c3b06fdc08d1602c3f1fa0eff0"/></dir><dir name="template"><dir name="cartsguru"><dir name="checkout"><file name="purchase.phtml" hash="1035c7fed71153aa4c9f5e2d765deb7a"/></dir><file name="pixel.phtml" hash="58cbe4af75828b12325251cb4cf1d594"/><dir name="product"><file name="view.phtml" hash="9ab2487a583615c61e85a96ee0795ad3"/></dir></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="cartsguru"><file name="checkout.js" hash="f80f26b465eac6f702e87e05687c4bdd"/></dir></dir></target></contents>
24
<compatible/>
25
<dependencies><required><php><min>5.3.0</min><max>7.1.0</max></php></required></dependencies>
26
</package>
1
<?xml version="1.0"?>
2
<package>
3
<name>cartsguru</name>
4
+ <version>1.3.3</version>
5
<stability>stable</stability>
6
<license uri="http://opensource.org/licenses/gpl-license.php">GPL</license>
7
<channel>community</channel>
16
&#xD;
17
- SMS Callback &amp; Push SMS&#xD;
18
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>
19
+ <notes>- New catalog query&#xD;
20
+ - Fix multistore issues&#xD;
21
+ - Correct customer group when not logged in</notes>
22
<authors><author><name>Maxime Pruvost</name><user>cgmaximepruvost</user><email>maxime@carts.guru</email></author></authors>
23
+ <date>2017-01-27</date>
24
+ <time>16:39:37</time>
25
+ <contents><target name="magelocal"><dir name="Cartsguru"><dir name="Block"><file name="Pixel.php" hash="563040d205bc6df655eab430e11520e1"/></dir><dir name="Helper"><file name="Data.php" hash="c825db75bd11a56fedfde22902f4b460"/><file name="Tools.php" hash="e2f56c3387eb0b0650aa5f49f8207618"/></dir><dir name="Model"><file name="Catalog.php" hash="56e89f13ea6c6100aea153012a49a4ae"/><file name="Observer.php" hash="9415fc8971636a4ca7c01ee9d9b2445d"/><file name="Webservice.php" hash="e1155455f7e1ee141e2c8caf95ff8027"/></dir><dir name="controllers"><file name="AdminController.php" hash="0de2c651976d77601e020c3d14a119a3"/><file name="CatalogController.php" hash="97066bb7b960b548e45941875f2a477c"/><file name="IndexController.php" hash="21147a5de4f498b13e9f402100a868e9"/><file name="RecovercartController.php" hash="4b0d7b3c0d18f5c451932caee9daac5b"/><file name="SaveaccountController.php" hash="6b490eca17f516a4f95bba9d4c45d30b"/></dir><dir name="etc"><file name="config.xml" hash="da7e37d118c609baaea24f1140bf3db8"/><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.10-1.2.11.php" hash="84cb92331d31afda4f06aca50dbd597e"/><file name="upgrade-1.2.11-1.2.12.php" hash="84cb92331d31afda4f06aca50dbd597e"/><file name="upgrade-1.2.12-1.2.13.php" hash="84cb92331d31afda4f06aca50dbd597e"/><file name="upgrade-1.2.13-1.2.14.php" hash="84cb92331d31afda4f06aca50dbd597e"/><file name="upgrade-1.2.14-1.2.15.php" hash="c96e44a4737e1d8b0f4915c55a67c048"/><file name="upgrade-1.2.15-1.2.16.php" hash="c96e44a4737e1d8b0f4915c55a67c048"/><file name="upgrade-1.2.16-1.3.0.php" hash="c96e44a4737e1d8b0f4915c55a67c048"/><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"/><file name="upgrade-1.2.6-1.2.7.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.2.7-1.2.8.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.2.8-1.2.9.php" hash="381716ae5001678f8bcc6680bad68015"/><file name="upgrade-1.2.9-1.2.10.php" hash="84cb92331d31afda4f06aca50dbd597e"/><file name="upgrade-1.3.0-1.3.1.php" hash="c96e44a4737e1d8b0f4915c55a67c048"/><file name="upgrade-1.3.1-1.3.2.php" hash="c96e44a4737e1d8b0f4915c55a67c048"/><file name="upgrade-1.3.2-1.3.3.php" hash="c96e44a4737e1d8b0f4915c55a67c048"/></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><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="cartsguru.xml" hash="a886b0c3b06fdc08d1602c3f1fa0eff0"/></dir><dir name="template"><dir name="cartsguru"><dir name="checkout"><file name="purchase.phtml" hash="1035c7fed71153aa4c9f5e2d765deb7a"/></dir><file name="pixel.phtml" hash="58cbe4af75828b12325251cb4cf1d594"/><dir name="product"><file name="view.phtml" hash="9ab2487a583615c61e85a96ee0795ad3"/></dir></dir></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="cartsguru"><file name="checkout.js" hash="f80f26b465eac6f702e87e05687c4bdd"/></dir></dir></target></contents>
26
<compatible/>
27
<dependencies><required><php><min>5.3.0</min><max>7.1.0</max></php></required></dependencies>
28
</package>