Version Notes
- Add recovery cart link
- Fix send gender in some cases
Download this release
Release Info
| Developer | Maxime Pruvost |
| Extension | cartsguru |
| Version | 1.2.0 |
| Comparing to | |
| See all releases | |
Code changes from version 1.1.5 to 1.2.0
- app/code/local/Cartsguru/Helper/Tools.php +34 -0
- app/code/local/Cartsguru/Model/Observer.php +6 -1
- app/code/local/Cartsguru/Model/Sales/Order/Api/V2.php +0 -42
- app/code/local/Cartsguru/Model/Webservice.php +74 -25
- app/code/local/Cartsguru/controllers/IndexController.php +8 -0
- app/code/local/Cartsguru/controllers/RecovercartController.php +74 -0
- app/code/local/Cartsguru/etc/config.xml +12 -53
- app/code/local/Cartsguru/sql/cartsguru_setup/install-1.2.0.php +24 -0
- app/code/local/Cartsguru/sql/cartsguru_setup/upgrade-1.0.0-1.2.0.php +24 -0
- package.xml +6 -5
app/code/local/Cartsguru/Helper/Tools.php
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Cartsguru_Helper_Tools
|
| 5 |
+
*/
|
| 6 |
+
class Cartsguru_Helper_Tools {
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* This method generate a random uuid v4
|
| 10 |
+
* @param $customer
|
| 11 |
+
*/
|
| 12 |
+
public static function generateUUID() {
|
| 13 |
+
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
| 14 |
+
|
| 15 |
+
// 32 bits for "time_low"
|
| 16 |
+
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
| 17 |
+
|
| 18 |
+
// 16 bits for "time_mid"
|
| 19 |
+
mt_rand(0, 0xffff),
|
| 20 |
+
|
| 21 |
+
// 16 bits for "time_hi_and_version",
|
| 22 |
+
// four most significant bits holds version number 4
|
| 23 |
+
mt_rand(0, 0x0fff) | 0x4000,
|
| 24 |
+
|
| 25 |
+
// 16 bits, 8 bits for "clk_seq_hi_res",
|
| 26 |
+
// 8 bits for "clk_seq_low",
|
| 27 |
+
// two most significant bits holds zero and one for variant DCE1.1
|
| 28 |
+
mt_rand(0, 0x3fff) | 0x8000,
|
| 29 |
+
|
| 30 |
+
// 48 bits for "node"
|
| 31 |
+
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
| 32 |
+
);
|
| 33 |
+
}
|
| 34 |
+
}
|
app/code/local/Cartsguru/Model/Observer.php
CHANGED
|
@@ -29,11 +29,16 @@ class Cartsguru_Model_Observer
|
|
| 29 |
}
|
| 30 |
|
| 31 |
/**
|
| 32 |
-
* This method add
|
| 33 |
* @param $observer
|
| 34 |
*/
|
| 35 |
public function quoteSaveBefore($observer)
|
| 36 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
|
| 39 |
/**
|
| 29 |
}
|
| 30 |
|
| 31 |
/**
|
| 32 |
+
* This method add token to quote
|
| 33 |
* @param $observer
|
| 34 |
*/
|
| 35 |
public function quoteSaveBefore($observer)
|
| 36 |
{
|
| 37 |
+
$quote = $observer->getEvent()->getQuote();
|
| 38 |
+
if (!$quote->getData('cartsguru_token')){
|
| 39 |
+
$tools = Mage::helper('cartsguru/tools');
|
| 40 |
+
$quote->setData('cartsguru_token',$tools::generateUUID());
|
| 41 |
+
}
|
| 42 |
}
|
| 43 |
|
| 44 |
/**
|
app/code/local/Cartsguru/Model/Sales/Order/Api/V2.php
DELETED
|
@@ -1,42 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
|
| 3 |
-
class Cartsguru_Model_Sales_Order_Api_V2 extends Mage_Sales_Model_Order_Api_V2 {
|
| 4 |
-
|
| 5 |
-
/**
|
| 6 |
-
* Retrieve full order information
|
| 7 |
-
*
|
| 8 |
-
* @param string $orderIncrementId
|
| 9 |
-
* @return array
|
| 10 |
-
*/
|
| 11 |
-
public function info($orderIncrementId)
|
| 12 |
-
{
|
| 13 |
-
$order = $this->_initOrder($orderIncrementId);
|
| 14 |
-
|
| 15 |
-
if ($order->getGiftMessageId() > 0) {
|
| 16 |
-
$message = Mage::getSingleton('giftmessage/message')->load($order->getGiftMessageId());
|
| 17 |
-
$order->setGiftMessage($message->getMessage());
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
$attributes = $this->_getAttributes($order, 'order');
|
| 21 |
-
$attributes['shipping_address'] = $this->_getAttributes($order->getShippingAddress(), 'order_address');
|
| 22 |
-
$attributes['billing_address'] = $this->_getAttributes($order->getBillingAddress(), 'order_address');
|
| 23 |
-
$attributes['payment'] = $this->_getAttributes($order->getPayment(), 'order_payment');
|
| 24 |
-
|
| 25 |
-
$attributes['items'] = array();
|
| 26 |
-
foreach ($order->getAllItems() as $item) {
|
| 27 |
-
if ($item->getGiftMessageId() > 0) {
|
| 28 |
-
$message = Mage::getSingleton('giftmessage/message')->load($item->getGiftMessageId());
|
| 29 |
-
$item->setGiftMessage($message->getMessage());
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
$attributes['items'][] = $this->_getAttributes($item, 'order_item');
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
$attributes['status_history'] = array();
|
| 36 |
-
foreach ($order->getAllStatusHistory() as $history) {
|
| 37 |
-
$attributes['status_history'][] = $this->_getAttributes($history, 'order_status_history');
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
return $attributes;
|
| 41 |
-
}
|
| 42 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/local/Cartsguru/Model/Webservice.php
CHANGED
|
@@ -7,13 +7,35 @@
|
|
| 7 |
class Cartsguru_Model_Webservice
|
| 8 |
{
|
| 9 |
private $apiBaseUrl = 'https://api.carts.guru';
|
|
|
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
/**
|
| 12 |
* If value is empty return ''
|
| 13 |
* @param $value
|
| 14 |
* @return string
|
| 15 |
*/
|
| 16 |
-
|
| 17 |
{
|
| 18 |
return ($value)? $value : '';
|
| 19 |
}
|
|
@@ -107,8 +129,8 @@ class Cartsguru_Model_Webservice
|
|
| 107 |
'totalATI' => (float)$item->getPriceInclTax()*$quantity, // Subtotal of item, taxe included
|
| 108 |
'url' => $item->getProduct()->getProductUrl(), // URL of product sheet
|
| 109 |
'imageUrl' => $imageUrl,
|
| 110 |
-
'universe' => $categoryNames[1],
|
| 111 |
-
'category' => end($categoryNames)
|
| 112 |
);
|
| 113 |
}
|
| 114 |
return $items;
|
|
@@ -122,7 +144,7 @@ class Cartsguru_Model_Webservice
|
|
| 122 |
public function getOrderData($order)
|
| 123 |
{
|
| 124 |
//Customer data
|
| 125 |
-
$gender =
|
| 126 |
$email = $order->getCustomerEmail();
|
| 127 |
|
| 128 |
//Address
|
|
@@ -132,19 +154,19 @@ class Cartsguru_Model_Webservice
|
|
| 132 |
$items = $this->getItemsData($order);
|
| 133 |
|
| 134 |
return array(
|
| 135 |
-
'siteId' =>
|
| 136 |
-
'id' => $order->getIncrementId(), //Order reference, the same display to the buyer
|
| 137 |
'creationDate' => $this->formatDate($order->getCreatedAt()), // Date of the order as string in json format
|
| 138 |
'cartId' => $order->getQuoteId(), // Cart identifier, source of the order
|
| 139 |
'totalET' => (float)$order->getSubtotal(), // Amount excluded taxes and excluded shipping
|
| 140 |
-
'totalATI' =>
|
| 141 |
'state' => $order->getStatus(), // raw order status
|
| 142 |
'accountId' => $email, // Account id of the buyer
|
| 143 |
'ip' => $order->getRemoteIp(), // User IP
|
| 144 |
'civility' => $this->notEmpty($gender), // Use string in this list : 'mister','madam','miss'
|
| 145 |
'lastname' => $this->notEmpty($address->getLastname()), // Lastname of the buyer
|
| 146 |
'firstname' => $this->notEmpty($address->getFirstname()), // Firstname of the buyer
|
| 147 |
-
'email' => $this->notEmpty($email),
|
| 148 |
'phoneNumber' => $this->notEmpty($address->getTelephone()), // Landline phone number of buyer (internationnal format)
|
| 149 |
'countryCode' => $this->notEmpty($address->getCountryId()), // Country code of buyer
|
| 150 |
'items' => $items // Details
|
|
@@ -157,12 +179,26 @@ class Cartsguru_Model_Webservice
|
|
| 157 |
*/
|
| 158 |
public function sendOrder($order)
|
| 159 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
$orderData = $this->getOrderData($order);
|
| 161 |
if (!empty($orderData)) {
|
| 162 |
$this->doPostRequest('/orders', $orderData);
|
| 163 |
}
|
| 164 |
}
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
/**
|
| 167 |
* This method return abounded cart data in cartsguru api format
|
| 168 |
* @param $quote
|
|
@@ -171,7 +207,8 @@ class Cartsguru_Model_Webservice
|
|
| 171 |
public function getAbadonnedCartData($quote)
|
| 172 |
{
|
| 173 |
//Customer data
|
| 174 |
-
$gender =
|
|
|
|
| 175 |
$lastname = $quote->getCustomerLastname();
|
| 176 |
$firstname = $quote->getCustomerFirstname();
|
| 177 |
$email = $quote->getCustomerEmail();
|
|
@@ -180,7 +217,6 @@ class Cartsguru_Model_Webservice
|
|
| 180 |
$customer = $quote->getCustomer();
|
| 181 |
$address = $quote->getBillingAddress();
|
| 182 |
$request = Mage::app()->getRequest()->getParams();
|
| 183 |
-
|
| 184 |
$phone = '';
|
| 185 |
$country = '';
|
| 186 |
|
|
@@ -214,19 +250,21 @@ class Cartsguru_Model_Webservice
|
|
| 214 |
}
|
| 215 |
}
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
//Items details
|
| 218 |
$items = $this->getItemsData($quote);
|
| 219 |
|
| 220 |
//Check is valid
|
| 221 |
-
if (!$items) {
|
| 222 |
return;
|
| 223 |
}
|
| 224 |
-
|
| 225 |
-
$siteId = Mage::getStoreConfig('cartsguru/cartsguru_group/siteid', Mage::app()->getStore());
|
| 226 |
|
| 227 |
return array(
|
| 228 |
-
'siteId' => $
|
| 229 |
-
'id' => $quote->getId(), //Order reference, the same display to the buyer
|
| 230 |
'creationDate' => $this->formatDate($quote->getCreatedAt()), // Date of the order as string in json format
|
| 231 |
'totalET' => (float)$quote->getSubtotal(), // Amount excluded taxes and excluded shipping
|
| 232 |
'totalATI' => $this->getTotalATI($items), // Amount included taxes and excluded shipping
|
|
@@ -238,6 +276,7 @@ class Cartsguru_Model_Webservice
|
|
| 238 |
'email' => $this->notEmpty($email), // Email of the buyer
|
| 239 |
'phoneNumber' => $this->notEmpty($phone), // Landline phone number of buyer (internationnal format)
|
| 240 |
'countryCode' => $this->notEmpty($country), // Country code of the buyer
|
|
|
|
| 241 |
'items' => $items // Details
|
| 242 |
);
|
| 243 |
}
|
|
@@ -248,6 +287,11 @@ class Cartsguru_Model_Webservice
|
|
| 248 |
*/
|
| 249 |
public function sendAbadonnedCart($quote)
|
| 250 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
//Get data and continue only if exist
|
| 252 |
$cartData = $this->getAbadonnedCartData($quote);
|
| 253 |
if (!$cartData){
|
|
@@ -304,7 +348,7 @@ class Cartsguru_Model_Webservice
|
|
| 304 |
{
|
| 305 |
$address = $customer->getDefaultBillingAddress();
|
| 306 |
|
| 307 |
-
$gender =
|
| 308 |
$lastname = $this->getLastname($customer, $address);
|
| 309 |
$firstname = $this->getFirstname($customer, $address);
|
| 310 |
$phone = '';
|
|
@@ -314,9 +358,8 @@ class Cartsguru_Model_Webservice
|
|
| 314 |
$country = $address->getCountryId();
|
| 315 |
}
|
| 316 |
|
| 317 |
-
$siteId = Mage::getStoreConfig('cartsguru/cartsguru_group/siteid', Mage::app()->getStore());
|
| 318 |
return array(
|
| 319 |
-
'siteId' => $
|
| 320 |
'accountId' => $customer->getId(), // Account id of the customer
|
| 321 |
'civility' => $gender, // Use string in this list : 'mister','madam','miss'
|
| 322 |
'lastname' => $this->notEmpty($lastname), // Lastname of the buyer
|
|
@@ -333,6 +376,11 @@ class Cartsguru_Model_Webservice
|
|
| 333 |
*/
|
| 334 |
public function sendAccount($customer)
|
| 335 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
$customerData = $this->getCustomerData($customer);
|
| 337 |
$this->doPostRequest('/accounts', $customerData);
|
| 338 |
}
|
|
@@ -344,19 +392,20 @@ class Cartsguru_Model_Webservice
|
|
| 344 |
*/
|
| 345 |
public function checkAddress()
|
| 346 |
{
|
| 347 |
-
$
|
| 348 |
$fields = array(
|
| 349 |
'plugin' => 'magento',
|
| 350 |
-
'pluginVersion' => '1.
|
| 351 |
'storeVersion' => Mage::getVersion()
|
| 352 |
);
|
| 353 |
-
$siteId = Mage::getStoreConfig('cartsguru/cartsguru_group/siteid', Mage::app()->getStore());
|
| 354 |
-
$requestUrl = '/sites/' . $siteId . '/register-plugin';
|
| 355 |
|
| 356 |
$response = $this->doPostRequest($requestUrl, $fields);
|
| 357 |
-
|
| 358 |
($response->getStatus() == 200)
|
| 359 |
: false;
|
|
|
|
|
|
|
|
|
|
| 360 |
}
|
| 361 |
|
| 362 |
/**
|
|
@@ -370,7 +419,7 @@ class Cartsguru_Model_Webservice
|
|
| 370 |
try {
|
| 371 |
$url = $this->apiBaseUrl . $apiPath;
|
| 372 |
$client = new Zend_Http_Client($url);
|
| 373 |
-
$client->setHeaders('x-auth-key',
|
| 374 |
$client->setUri($url);
|
| 375 |
$client->setRawData(json_encode($fields), 'application/json');
|
| 376 |
$response = $client->request(Zend_Http_Client::POST);
|
| 7 |
class Cartsguru_Model_Webservice
|
| 8 |
{
|
| 9 |
private $apiBaseUrl = 'https://api.carts.guru';
|
| 10 |
+
private $configBasePath = 'cartsguru/cartsguru_group/';
|
| 11 |
|
| 12 |
+
public function setStoreConfig($key, $value, $store = null)
|
| 13 |
+
{
|
| 14 |
+
if (!$store){
|
| 15 |
+
$store = Mage::app()->getStore();
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
$store->setConfig($this->configBasePath . $key, $value);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
protected function getStoreConfig($key, $store = null){
|
| 22 |
+
if (!$store){
|
| 23 |
+
$store = Mage::app()->getStore();
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
return $store->getConfig($this->configBasePath . $key);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
protected function isStoreConfigured(){
|
| 30 |
+
return $this->getStoreConfig('siteid') && $this->getStoreConfig('auth');
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
/**
|
| 34 |
* If value is empty return ''
|
| 35 |
* @param $value
|
| 36 |
* @return string
|
| 37 |
*/
|
| 38 |
+
protected function notEmpty($value)
|
| 39 |
{
|
| 40 |
return ($value)? $value : '';
|
| 41 |
}
|
| 129 |
'totalATI' => (float)$item->getPriceInclTax()*$quantity, // Subtotal of item, taxe included
|
| 130 |
'url' => $item->getProduct()->getProductUrl(), // URL of product sheet
|
| 131 |
'imageUrl' => $imageUrl,
|
| 132 |
+
'universe' => $this->notEmpty($categoryNames[1]),
|
| 133 |
+
'category' => $this->notEmpty(end($categoryNames))
|
| 134 |
);
|
| 135 |
}
|
| 136 |
return $items;
|
| 144 |
public function getOrderData($order)
|
| 145 |
{
|
| 146 |
//Customer data
|
| 147 |
+
$gender = $this->genderMapping($order->getCustomerGender());
|
| 148 |
$email = $order->getCustomerEmail();
|
| 149 |
|
| 150 |
//Address
|
| 154 |
$items = $this->getItemsData($order);
|
| 155 |
|
| 156 |
return array(
|
| 157 |
+
'siteId' => $this->getStoreConfig('siteid'), // SiteId is part of plugin configuration
|
| 158 |
+
'id' => $order->getIncrementId(), // Order reference, the same display to the buyer
|
| 159 |
'creationDate' => $this->formatDate($order->getCreatedAt()), // Date of the order as string in json format
|
| 160 |
'cartId' => $order->getQuoteId(), // Cart identifier, source of the order
|
| 161 |
'totalET' => (float)$order->getSubtotal(), // Amount excluded taxes and excluded shipping
|
| 162 |
+
'totalATI' => $this->getTotalATI($items), // Amount included taxes and excluded shipping
|
| 163 |
'state' => $order->getStatus(), // raw order status
|
| 164 |
'accountId' => $email, // Account id of the buyer
|
| 165 |
'ip' => $order->getRemoteIp(), // User IP
|
| 166 |
'civility' => $this->notEmpty($gender), // Use string in this list : 'mister','madam','miss'
|
| 167 |
'lastname' => $this->notEmpty($address->getLastname()), // Lastname of the buyer
|
| 168 |
'firstname' => $this->notEmpty($address->getFirstname()), // Firstname of the buyer
|
| 169 |
+
'email' => $this->notEmpty($email), // Email of the buye
|
| 170 |
'phoneNumber' => $this->notEmpty($address->getTelephone()), // Landline phone number of buyer (internationnal format)
|
| 171 |
'countryCode' => $this->notEmpty($address->getCountryId()), // Country code of buyer
|
| 172 |
'items' => $items // Details
|
| 179 |
*/
|
| 180 |
public function sendOrder($order)
|
| 181 |
{
|
| 182 |
+
//Check is well configured
|
| 183 |
+
if (!$this->isStoreConfigured()){
|
| 184 |
+
return;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
$orderData = $this->getOrderData($order);
|
| 188 |
if (!empty($orderData)) {
|
| 189 |
$this->doPostRequest('/orders', $orderData);
|
| 190 |
}
|
| 191 |
}
|
| 192 |
+
public function genderMapping($gender){
|
| 193 |
+
switch((int)$gender){
|
| 194 |
+
case 1:
|
| 195 |
+
return 'mister';
|
| 196 |
+
case 2:
|
| 197 |
+
return 'madam';
|
| 198 |
+
default:
|
| 199 |
+
return '';
|
| 200 |
+
}
|
| 201 |
+
}
|
| 202 |
/**
|
| 203 |
* This method return abounded cart data in cartsguru api format
|
| 204 |
* @param $quote
|
| 207 |
public function getAbadonnedCartData($quote)
|
| 208 |
{
|
| 209 |
//Customer data
|
| 210 |
+
$gender = $this->genderMapping($quote->getCustomerGender());
|
| 211 |
+
|
| 212 |
$lastname = $quote->getCustomerLastname();
|
| 213 |
$firstname = $quote->getCustomerFirstname();
|
| 214 |
$email = $quote->getCustomerEmail();
|
| 217 |
$customer = $quote->getCustomer();
|
| 218 |
$address = $quote->getBillingAddress();
|
| 219 |
$request = Mage::app()->getRequest()->getParams();
|
|
|
|
| 220 |
$phone = '';
|
| 221 |
$country = '';
|
| 222 |
|
| 250 |
}
|
| 251 |
}
|
| 252 |
|
| 253 |
+
//Recover link
|
| 254 |
+
$recoverUrl = Mage::getBaseUrl() . 'cartsguru/recovercart?cart_id=' . $quote->getId() . '&cart_token=' . $quote->getData('cartsguru_token');
|
| 255 |
+
|
| 256 |
+
|
| 257 |
//Items details
|
| 258 |
$items = $this->getItemsData($quote);
|
| 259 |
|
| 260 |
//Check is valid
|
| 261 |
+
if (!$items || (!$phone || !$email)) {
|
| 262 |
return;
|
| 263 |
}
|
|
|
|
|
|
|
| 264 |
|
| 265 |
return array(
|
| 266 |
+
'siteId' => $this->getStoreConfig('siteid'), // SiteId is part of plugin configuration
|
| 267 |
+
'id' => $quote->getId(), // Order reference, the same display to the buyer
|
| 268 |
'creationDate' => $this->formatDate($quote->getCreatedAt()), // Date of the order as string in json format
|
| 269 |
'totalET' => (float)$quote->getSubtotal(), // Amount excluded taxes and excluded shipping
|
| 270 |
'totalATI' => $this->getTotalATI($items), // Amount included taxes and excluded shipping
|
| 276 |
'email' => $this->notEmpty($email), // Email of the buyer
|
| 277 |
'phoneNumber' => $this->notEmpty($phone), // Landline phone number of buyer (internationnal format)
|
| 278 |
'countryCode' => $this->notEmpty($country), // Country code of the buyer
|
| 279 |
+
'recoverUrl' => $recoverUrl, // Direct link to recover the cart
|
| 280 |
'items' => $items // Details
|
| 281 |
);
|
| 282 |
}
|
| 287 |
*/
|
| 288 |
public function sendAbadonnedCart($quote)
|
| 289 |
{
|
| 290 |
+
//Check is well configured
|
| 291 |
+
if (!$this->isStoreConfigured()){
|
| 292 |
+
return;
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
//Get data and continue only if exist
|
| 296 |
$cartData = $this->getAbadonnedCartData($quote);
|
| 297 |
if (!$cartData){
|
| 348 |
{
|
| 349 |
$address = $customer->getDefaultBillingAddress();
|
| 350 |
|
| 351 |
+
$gender = $this->genderMapping($customer->getGender());
|
| 352 |
$lastname = $this->getLastname($customer, $address);
|
| 353 |
$firstname = $this->getFirstname($customer, $address);
|
| 354 |
$phone = '';
|
| 358 |
$country = $address->getCountryId();
|
| 359 |
}
|
| 360 |
|
|
|
|
| 361 |
return array(
|
| 362 |
+
'siteId' => $this->getStoreConfig('siteid'), // SiteId is part of plugin configuration
|
| 363 |
'accountId' => $customer->getId(), // Account id of the customer
|
| 364 |
'civility' => $gender, // Use string in this list : 'mister','madam','miss'
|
| 365 |
'lastname' => $this->notEmpty($lastname), // Lastname of the buyer
|
| 376 |
*/
|
| 377 |
public function sendAccount($customer)
|
| 378 |
{
|
| 379 |
+
//Check is well configured
|
| 380 |
+
if (!$this->isStoreConfigured()){
|
| 381 |
+
return;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
$customerData = $this->getCustomerData($customer);
|
| 385 |
$this->doPostRequest('/accounts', $customerData);
|
| 386 |
}
|
| 392 |
*/
|
| 393 |
public function checkAddress()
|
| 394 |
{
|
| 395 |
+
$requestUrl = '/sites/' . $this->getStoreConfig('siteid') . '/register-plugin';
|
| 396 |
$fields = array(
|
| 397 |
'plugin' => 'magento',
|
| 398 |
+
'pluginVersion' => '1.2.0',
|
| 399 |
'storeVersion' => Mage::getVersion()
|
| 400 |
);
|
|
|
|
|
|
|
| 401 |
|
| 402 |
$response = $this->doPostRequest($requestUrl, $fields);
|
| 403 |
+
$isSuccess = ($response)?
|
| 404 |
($response->getStatus() == 200)
|
| 405 |
: false;
|
| 406 |
+
|
| 407 |
+
//Set is well configurerd
|
| 408 |
+
return $isSuccess;
|
| 409 |
}
|
| 410 |
|
| 411 |
/**
|
| 419 |
try {
|
| 420 |
$url = $this->apiBaseUrl . $apiPath;
|
| 421 |
$client = new Zend_Http_Client($url);
|
| 422 |
+
$client->setHeaders('x-auth-key', $this->getStoreConfig('auth'));
|
| 423 |
$client->setUri($url);
|
| 424 |
$client->setRawData(json_encode($fields), 'application/json');
|
| 425 |
$response = $client->request(Zend_Http_Client::POST);
|
app/code/local/Cartsguru/controllers/IndexController.php
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Cartsguru_IndexController extends Mage_Core_Controller_Front_Action {
|
| 4 |
+
|
| 5 |
+
public function indexAction(){
|
| 6 |
+
echo 'Visit https://carts.guru';
|
| 7 |
+
}
|
| 8 |
+
}
|
app/code/local/Cartsguru/controllers/RecovercartController.php
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 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
|
| 15 |
+
$quote = Mage::getModel('sales/quote')->load($params['cart_id']);
|
| 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
|
| 29 |
+
if ($quote->getCustomerId()){
|
| 30 |
+
//Gest customer
|
| 31 |
+
$customer = Mage::getModel('customer/customer')->load($quote->getCustomerId());
|
| 32 |
+
|
| 33 |
+
Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
|
| 34 |
+
}
|
| 35 |
+
else {
|
| 36 |
+
// Get current cart
|
| 37 |
+
$cart = Mage::getSingleton('checkout/cart');
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
foreach ($cart->getQuote()->getAllVisibleItems() as $item) {
|
| 41 |
+
$found = false;
|
| 42 |
+
foreach ($quote->getAllItems() as $quoteItem) {
|
| 43 |
+
if ($quoteItem->compare($item)) {
|
| 44 |
+
// $quoteItem->setQty($item->getQty());
|
| 45 |
+
$found = true;
|
| 46 |
+
break;
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
if (!$found) {
|
| 51 |
+
$newItem = clone $item;
|
| 52 |
+
$quote->addItem($newItem);
|
| 53 |
+
if ($quote->getHasChildren()) {
|
| 54 |
+
foreach ($item->getChildren() as $child) {
|
| 55 |
+
$newChild = clone $child;
|
| 56 |
+
$newChild->setParentItem($newItem);
|
| 57 |
+
$quote->addItem($newChild);
|
| 58 |
+
}
|
| 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 |
+
$url = Mage::helper('checkout/cart')->getCartUrl();
|
| 72 |
+
$this->getResponse()->setRedirect($url)->sendResponse();
|
| 73 |
+
}
|
| 74 |
+
}
|
app/code/local/Cartsguru/etc/config.xml
CHANGED
|
@@ -3,45 +3,10 @@
|
|
| 3 |
<!-- plugin name -->
|
| 4 |
<modules>
|
| 5 |
<Cartsguru>
|
| 6 |
-
<version>1.
|
| 7 |
</Cartsguru>
|
| 8 |
</modules>
|
| 9 |
<global>
|
| 10 |
-
<!--add some attributes for easy send it throw api -->
|
| 11 |
-
<sales>
|
| 12 |
-
<quote>
|
| 13 |
-
<customer_attributes>
|
| 14 |
-
<telephone />
|
| 15 |
-
<country />
|
| 16 |
-
</customer_attributes>
|
| 17 |
-
</quote>
|
| 18 |
-
</sales>
|
| 19 |
-
<fieldsets>
|
| 20 |
-
<sales_convert_quote>
|
| 21 |
-
<country>
|
| 22 |
-
<to_order>*</to_order>
|
| 23 |
-
</country>
|
| 24 |
-
<telephone>
|
| 25 |
-
<to_order>*</to_order>
|
| 26 |
-
</telephone>
|
| 27 |
-
</sales_convert_quote>
|
| 28 |
-
<sales_convert_quote>
|
| 29 |
-
<country>
|
| 30 |
-
<to_order>*</to_order>
|
| 31 |
-
</country>
|
| 32 |
-
<telephone>
|
| 33 |
-
<to_order>*</to_order>
|
| 34 |
-
</telephone>
|
| 35 |
-
</sales_convert_quote>
|
| 36 |
-
<sales_convert_order>
|
| 37 |
-
<country>
|
| 38 |
-
<to_order>*</to_order>
|
| 39 |
-
</country>
|
| 40 |
-
<telephone>
|
| 41 |
-
<to_quote>*</to_quote>
|
| 42 |
-
</telephone>
|
| 43 |
-
</sales_convert_order>
|
| 44 |
-
</fieldsets>
|
| 45 |
<models>
|
| 46 |
<cartsguru>
|
| 47 |
<class>Cartsguru_Model</class>
|
|
@@ -50,12 +15,6 @@
|
|
| 50 |
<cartsguru_resource>
|
| 51 |
<class>Cartsguru_Model_Resource</class>
|
| 52 |
</cartsguru_resource>
|
| 53 |
-
<!--add rewrite base class for extend it -->
|
| 54 |
-
<sales>
|
| 55 |
-
<rewrite>
|
| 56 |
-
<order_api_v2>Cartsguru_Model_Sales_Order_Api_V2</order_api_v2>
|
| 57 |
-
</rewrite>
|
| 58 |
-
</sales>
|
| 59 |
</models>
|
| 60 |
<blocks>
|
| 61 |
<cartsguru>
|
|
@@ -169,17 +128,6 @@
|
|
| 169 |
</customer_login>
|
| 170 |
</events>
|
| 171 |
</global>
|
| 172 |
-
<frontend>
|
| 173 |
-
<routers>
|
| 174 |
-
<webservice>
|
| 175 |
-
<use>standard</use>
|
| 176 |
-
<args>
|
| 177 |
-
<frontName>webservice</frontName>
|
| 178 |
-
<module>Cartsguru</module>
|
| 179 |
-
</args>
|
| 180 |
-
</webservice>
|
| 181 |
-
</routers>
|
| 182 |
-
</frontend>
|
| 183 |
<adminhtml>
|
| 184 |
<translate>
|
| 185 |
<modules>
|
|
@@ -214,4 +162,15 @@
|
|
| 214 |
</resources>
|
| 215 |
</acl>
|
| 216 |
</adminhtml>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
</config>
|
| 3 |
<!-- plugin name -->
|
| 4 |
<modules>
|
| 5 |
<Cartsguru>
|
| 6 |
+
<version>1.2.0</version>
|
| 7 |
</Cartsguru>
|
| 8 |
</modules>
|
| 9 |
<global>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
<models>
|
| 11 |
<cartsguru>
|
| 12 |
<class>Cartsguru_Model</class>
|
| 15 |
<cartsguru_resource>
|
| 16 |
<class>Cartsguru_Model_Resource</class>
|
| 17 |
</cartsguru_resource>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
</models>
|
| 19 |
<blocks>
|
| 20 |
<cartsguru>
|
| 128 |
</customer_login>
|
| 129 |
</events>
|
| 130 |
</global>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
<adminhtml>
|
| 132 |
<translate>
|
| 133 |
<modules>
|
| 162 |
</resources>
|
| 163 |
</acl>
|
| 164 |
</adminhtml>
|
| 165 |
+
<frontend>
|
| 166 |
+
<routers>
|
| 167 |
+
<cartsguru>
|
| 168 |
+
<use>standard</use>
|
| 169 |
+
<args>
|
| 170 |
+
<module>Cartsguru</module>
|
| 171 |
+
<frontName>cartsguru</frontName>
|
| 172 |
+
</args>
|
| 173 |
+
</cartsguru>
|
| 174 |
+
</routers>
|
| 175 |
+
</frontend>
|
| 176 |
</config>
|
app/code/local/Cartsguru/sql/cartsguru_setup/install-1.2.0.php
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/* @var $installer Mage_Core_Model_Resource_Setup */
|
| 3 |
+
$installer = $this;
|
| 4 |
+
|
| 5 |
+
$installer->startSetup();
|
| 6 |
+
$connection = $installer->getConnection();
|
| 7 |
+
|
| 8 |
+
$connection->addColumn($this->getTable('sales/quote'), 'cartsguru_token', 'varchar(255) NOT NULL');
|
| 9 |
+
|
| 10 |
+
$setup = Mage::getModel('customer/entity_setup', 'core_setup');
|
| 11 |
+
|
| 12 |
+
$installer_core= new Mage_Sales_Model_Resource_Setup('core_setup');
|
| 13 |
+
|
| 14 |
+
$options = array(
|
| 15 |
+
'type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
|
| 16 |
+
'visible' => false,
|
| 17 |
+
'required' => false
|
| 18 |
+
);
|
| 19 |
+
foreach ($entities as $entity) {
|
| 20 |
+
$installer_core->addAttribute('quote', 'cartsguru_token', $options);
|
| 21 |
+
}
|
| 22 |
+
$setup->endSetup();
|
| 23 |
+
$installer_core->endSetup();
|
| 24 |
+
$installer->endSetup();
|
app/code/local/Cartsguru/sql/cartsguru_setup/upgrade-1.0.0-1.2.0.php
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/* @var $installer Mage_Core_Model_Resource_Setup */
|
| 3 |
+
$installer = $this;
|
| 4 |
+
|
| 5 |
+
$installer->startSetup();
|
| 6 |
+
$connection = $installer->getConnection();
|
| 7 |
+
|
| 8 |
+
$connection->addColumn($this->getTable('sales/quote'), 'cartsguru_token', 'varchar(255) NOT NULL');
|
| 9 |
+
|
| 10 |
+
$setup = Mage::getModel('customer/entity_setup', 'core_setup');
|
| 11 |
+
|
| 12 |
+
$installer_core= new Mage_Sales_Model_Resource_Setup('core_setup');
|
| 13 |
+
|
| 14 |
+
$options = array(
|
| 15 |
+
'type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
|
| 16 |
+
'visible' => false,
|
| 17 |
+
'required' => false
|
| 18 |
+
);
|
| 19 |
+
foreach ($entities as $entity) {
|
| 20 |
+
$installer_core->addAttribute('quote', 'cartsguru_token', $options);
|
| 21 |
+
}
|
| 22 |
+
$setup->endSetup();
|
| 23 |
+
$installer_core->endSetup();
|
| 24 |
+
$installer->endSetup();
|
package.xml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>cartsguru</name>
|
| 4 |
-
<version>1.
|
| 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-04-
|
| 24 |
-
<time>
|
| 25 |
-
<contents><target name="magelocal"><dir name="Cartsguru"><dir name="Helper"><file name="Data.php" hash="f6590d08ba862a169ce43459ddb1193c"/></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.0</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>- Add recovery cart link
|
| 22 |
+
- Fix send gender in some cases</notes>
|
| 23 |
<authors><author><name>Maxime Pruvost</name><user>cgmaximepruvost</user><email>maxime@carts.guru</email></author></authors>
|
| 24 |
+
<date>2016-04-26</date>
|
| 25 |
+
<time>10:17:24</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="7b3b398b86a9b8e044f7d00f6b72e196"/><file name="Webservice.php" hash="93ff6cdb037cb3f31d0a85f0a97e7a64"/></dir><dir name="controllers"><file name="IndexController.php" hash="108acaab218e2a5e79a12677f83ebc29"/><file name="RecovercartController.php" hash="c5272eaae6eba7658155a83c27b94139"/></dir><dir name="etc"><file name="config.xml" hash="6ed9edede663e2400ac8fd5f2706179e"/><file name="system.xml" hash="cb0fbf86d2be47dbd719739ee79c4cba"/></dir><dir name="sql"><dir name="cartsguru_setup"><file name="install-1.0.0.php" hash="c46126ce8ce549d525fb25bddc5090b5"/><file name="install-1.2.0.php" hash="112bd2a1d4e02dd1f296ef47e54e0485"/><file name="upgrade-1.0.0-1.2.0.php" hash="112bd2a1d4e02dd1f296ef47e54e0485"/></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>
|
