KANCART_MobileAPI - Version 2.1.2

Version Notes

Kancart supports guest checkout now;
We developed a promotion mechanism, you can add promotion rules for mobile user;
More details of improvements can be found on www.kancart.com

Download this release

Release Info

Developer Kancart.com
Extension KANCART_MobileAPI
Version 2.1.2
Comparing to
See all releases


Code changes from version 2.1.1 to 2.1.2

app/code/community/Kancart/MobileApi/Helper/Data.php CHANGED
@@ -27,27 +27,73 @@
27
  */
28
  class Kancart_MobileApi_Helper_Data extends Mage_Core_Helper_Abstract {
29
 
30
- /**
31
- * Convert Url link to file path for images
32
- *
33
- * @param string $icon
34
- * @return string
35
- */
36
- public function urlToPath($icon) {
37
- $baseUrl = Mage::getBaseUrl('media');
38
- $path = str_replace($baseUrl, '', $icon);
39
- $filePath = Mage::getBaseDir('media') . DS . str_replace('/', DS, $path);
40
- return $filePath;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  }
42
 
43
- /**
44
- * Format price for correct view inside xml strings
45
- *
46
- * @param float $price
47
- * @return string
48
- */
49
- public function formatPriceForXml($price) {
50
- return sprintf('%01.2F', $price);
51
  }
52
 
53
- }
27
  */
28
  class Kancart_MobileApi_Helper_Data extends Mage_Core_Helper_Abstract {
29
 
30
+ public function redirectMobile() {//controller_action_predispatch
31
+ if (Mage::getStoreConfig('Kancart/redirect/active') < 1) {
32
+ return;
33
+ } elseif (preg_match('/(admin|downloader|MobileApi)/i', $_SERVER['REQUEST_URI'])) {
34
+ return;
35
+ } elseif (isset($_REQUEST['view_full_site'])) {
36
+ Mage::getSingleton('customer/session')->setViewFullSite(true);
37
+ return;
38
+ } elseif (Mage::getSingleton('customer/session')->getViewFullSite()) {
39
+ return;
40
+ }
41
+
42
+ if ($this->isMobile()) {
43
+ $url = Mage::getStoreConfig('Kancart/redirect/url');
44
+ if (!strlen($url)) {
45
+ $parts = explode('.', $_SERVER['SERVER_NAME']);
46
+ if (checkdnsrr('m.' . $parts[1] . '.com')) {
47
+ $url = 'm.' . $parts[1] . '.com';
48
+ } else {
49
+ $url = $parts[1] . '.kancart.com';
50
+ }
51
+ }
52
+
53
+ if (strpos($url, 'http') === false) {
54
+ $url = 'http://' . $url;
55
+ }
56
+ $url = rtrim($url, '/');
57
+
58
+ $path = trim(Mage::app()->getRequest()->getPathInfo(), '/');
59
+ $parts = explode('/', $path);
60
+ if ($parts) {
61
+ if ($parts[0] == 'catalog') {
62
+ if ($parts[1] == 'category') {
63
+ $url .= '/categories/' . end($parts);
64
+ } elseif ($parts[1] == 'product') {
65
+ $url .= '/item_detail/' . $parts[4];
66
+ }
67
+ } elseif ($parts[0] == 'catalogsearch') {
68
+ $url .= '/item_search/?query=' . Mage::app()->getRequest()->getParam('q');
69
+ }
70
+ }
71
+
72
+ header('Location: ' . $url);
73
+ exit();
74
+ }
75
+ }
76
+
77
+ private function isMobile() {
78
+ if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
79
+ return true;
80
+ } else if (isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT']) {
81
+ if (preg_match('/(iphone|android|ipad|ipod).+mobile/i', $_SERVER['HTTP_USER_AGENT'])) {//ignore tablet
82
+ return true;
83
+ } else if (preg_match('/IEMobile|blackberry|mini|windows\sce|palm/i', $_SERVER['HTTP_USER_AGENT'])) {
84
+ return true;
85
+ }
86
+ }
87
+
88
+ return false;
89
+ }
90
+
91
+ public function isDiscountEnabled() {
92
+ return defined('KANCART_APP_KEY');
93
  }
94
 
95
+ public function getFrontConfig($name) {
96
+ return Mage::getStoreConfig('Kancart/general/' . $name, Mage::app()->getStore());
 
 
 
 
 
 
97
  }
98
 
99
+ }
app/code/community/Kancart/MobileApi/Model/Abstract.php CHANGED
@@ -24,7 +24,7 @@
24
  */
25
  abstract class Kancart_MobileApi_Model_Abstract {
26
 
27
- public function _construct() {
28
 
29
  }
30
 
@@ -112,6 +112,12 @@ abstract class Kancart_MobileApi_Model_Abstract {
112
  }
113
 
114
  protected function getAvailablePayment() {
 
 
 
 
 
 
115
  $block = Mage::getBlockSingleton('Checkout/Onepage_Payment_Methods');
116
  if ($block) {
117
  return $block->getMethods();
@@ -127,6 +133,9 @@ abstract class Kancart_MobileApi_Model_Abstract {
127
  $block = Mage::getBlockSingleton('Checkout/Cart_Totals');
128
  method_exists($block, 'canApplyMsrp') && $block->canApplyMsrp();
129
  foreach ($block->getTotals() as $item) {
 
 
 
130
  if ($item->getAs()) {
131
  $type = $item->getAs();
132
  } else {
24
  */
25
  abstract class Kancart_MobileApi_Model_Abstract {
26
 
27
+ public function __construct() {
28
 
29
  }
30
 
112
  }
113
 
114
  protected function getAvailablePayment() {
115
+ if (Mage::getStoreConfig('payment/paypal_standard/active') < 1 && Kancart::helper('Data')->getFrontConfig('paypal_standard') > 0) {
116
+ Mage::app()->getStore()->setConfig('payment/paypal_standard/active', true);
117
+ }
118
+ if (Mage::getStoreConfig('payment/paypal_express/active') < 1 && Kancart::helper('Data')->getFrontConfig('paypal_express') > 0) {
119
+ Mage::app()->getStore()->setConfig('payment/paypal_express/active', true);
120
+ }
121
  $block = Mage::getBlockSingleton('Checkout/Onepage_Payment_Methods');
122
  if ($block) {
123
  return $block->getMethods();
133
  $block = Mage::getBlockSingleton('Checkout/Cart_Totals');
134
  method_exists($block, 'canApplyMsrp') && $block->canApplyMsrp();
135
  foreach ($block->getTotals() as $item) {
136
+ if (strlen($item->getTitle()) < 1) {
137
+ continue;
138
+ }
139
  if ($item->getAs()) {
140
  $type = $item->getAs();
141
  } else {
app/code/community/Kancart/MobileApi/Model/Category.php CHANGED
@@ -38,6 +38,7 @@ class Kancart_MobileApi_Model_Category extends Kancart_MobileApi_Model_Abstract
38
  'parent_cid' => $parent_cid == $rootCategoryId ? -1 : $parent_cid,
39
  'name' => $category->getName(),
40
  'is_parent' => $category->hasChildren(),
 
41
  'count' => $category->getProductCount(),
42
  'position' => $category->getPosition()
43
  );
@@ -86,6 +87,37 @@ class Kancart_MobileApi_Model_Category extends Kancart_MobileApi_Model_Abstract
86
  return $categories;
87
  }
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  }
90
 
91
  ?>
38
  'parent_cid' => $parent_cid == $rootCategoryId ? -1 : $parent_cid,
39
  'name' => $category->getName(),
40
  'is_parent' => $category->hasChildren(),
41
+ 'filter_options' => $this->getFilterOptions($category),
42
  'count' => $category->getProductCount(),
43
  'position' => $category->getPosition()
44
  );
87
  return $categories;
88
  }
89
 
90
+ private function getFilterOptions($category) {
91
+ Mage::getSingleton('catalog/layer')->setCurrentCategory($category);
92
+ $block = Mage::getBlockSingleton('catalog/layer_view');
93
+
94
+ $filters = array();
95
+ if ($block->canShowBlock() && $block->canShowOptions()) {
96
+ $_filters = $block->getFilters();
97
+ foreach ($_filters as $_filter) {
98
+ $options = array();
99
+ if ($_filter->getItemsCount()) {
100
+ foreach ($_filter->getItems() as $_item) {
101
+ $options[] = array(
102
+ 'option_id' => $_item->getValue(),
103
+ 'title' => strip_tags($_item->getLabel()),
104
+ 'count' => $_item->getCount()
105
+ );
106
+ }
107
+ if ($_filter->getAttributeModel()) {
108
+ $filters[] = array(
109
+ 'title' => $block->__($_filter->getName()),
110
+ 'filter_id' => $_filter->getAttributeModel()->getAttributeCode(),
111
+ 'options' => $options
112
+ );
113
+ }
114
+ }
115
+ }
116
+ }
117
+
118
+ return $filters;
119
+ }
120
+
121
  }
122
 
123
  ?>
app/code/community/Kancart/MobileApi/Model/Checkout.php CHANGED
@@ -192,6 +192,7 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
192
  $params = $this->getRequest()->getParams();
193
  $ShippingRateCode = $params['shipping_method_id'];
194
  $shippingMethodResult = $this->getOnepage()->saveShippingMethod($ShippingRateCode);
 
195
  $this->getOnepage()->getQuote()->collectTotals()->save();
196
  if (isset($shippingMethodResult['error'])) {
197
  $_SESSION['checkout_messages'][] = $shippingMethodResult['message'];
@@ -229,6 +230,7 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
229
  }
230
  if (!$this->getQuote()->getShippingAddress()->getShippingMethod()) {
231
  $this->getOnepage()->saveShippingMethod($shippingMethods[0]['sm_id']);
 
232
  }
233
  $this->getOnepage()->getQuote()->collectTotals()->save();
234
  $this->getQuote()->setTotalsCollectedFlag(false)->collectTotals()->save();
@@ -309,15 +311,16 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
309
  } else {
310
  $real_payment_id = $this->getRealKancartPaymentId($payment_id); //money order
311
  }
312
- $payment = array('method' => $real_payment_id);
313
- $this->getOnepage()->savePayment($payment);
 
314
 
315
  if ($payment_id === 'paypal') {
316
  return Kancart::getModel('PayPalWPS')->buildPaypalWPSParams();
317
  } else if ($payment_id === 'paypalwpp') {
318
  return Kancart::getModel('PayPalEC')->kancart_shoppingcart_paypalec_start('commit');
319
  } else {
320
- return Kancart::getModel('Payment')->placeOrder($payment, $payment_id);
321
  }
322
  } catch (Mage_Core_Exception $e) {
323
  return array(false, '0x9000', $e->getMessage());
@@ -327,41 +330,39 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
327
  }
328
 
329
  private function getRealKancartPaymentId($payment_id) {
330
- if (defined('KANCART_PAYMENT_CODE')) {
331
- return KANCART_PAYMENT_CODE;
332
- } else {
333
- $priorsPayments = array(
334
- 'banktransfer' => 0,
335
- 'cashondelivery' => 1,
336
- 'checkmo' => 2,
337
- 'purchaseorder' => 3
338
- );
339
-
340
- $kcode = str_replace('kancart_', '', $payment_id);
341
- $kcode = str_replace('magePay-', '', $kcode);
342
- $payments = array();
343
- $methods = $this->getAvailablePayment();
344
- if ($methods) {
345
- foreach ($methods as $method) {
346
- $code = $method->getCode();
347
- if ($kcode == $code) {
348
- return $code;
349
- }
350
- if (isset($priorsPayments[$code])) {
351
- $payments[$priorsPayments[$code]] = $code;
352
- }
353
  }
354
  }
 
355
 
356
- if (sizeof($payments) < 1) {
357
- Mage::throwException('No available offline payment method configured on Magento backend.');
358
- }
359
 
360
- ksort($payments);
361
- reset($payments);
362
 
363
- return current($payments);
364
- }
365
  }
366
 
367
  /**
@@ -370,6 +371,12 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
370
  public function kancart_checkout_start() {
371
  $payment_id = $this->getRequest()->getParam('payment_method_id', null);
372
  $checkout_type = $this->getRequest()->getParam('checkout_type');
 
 
 
 
 
 
373
  switch ($checkout_type) {
374
  case 'cart':
375
  if ($payment_id == 'paypalec') {
192
  $params = $this->getRequest()->getParams();
193
  $ShippingRateCode = $params['shipping_method_id'];
194
  $shippingMethodResult = $this->getOnepage()->saveShippingMethod($ShippingRateCode);
195
+ Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array('request' => $this->getRequest(), 'quote' => $this->getOnepage()->getQuote()));
196
  $this->getOnepage()->getQuote()->collectTotals()->save();
197
  if (isset($shippingMethodResult['error'])) {
198
  $_SESSION['checkout_messages'][] = $shippingMethodResult['message'];
230
  }
231
  if (!$this->getQuote()->getShippingAddress()->getShippingMethod()) {
232
  $this->getOnepage()->saveShippingMethod($shippingMethods[0]['sm_id']);
233
+ Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array('request' => $this->getRequest(), 'quote' => $this->getOnepage()->getQuote()));
234
  }
235
  $this->getOnepage()->getQuote()->collectTotals()->save();
236
  $this->getQuote()->setTotalsCollectedFlag(false)->collectTotals()->save();
311
  } else {
312
  $real_payment_id = $this->getRealKancartPaymentId($payment_id); //money order
313
  }
314
+ $data = $this->getRequest()->getPost('payment', array());
315
+ $data['method'] = $real_payment_id;
316
+ $this->getOnepage()->savePayment($data);
317
 
318
  if ($payment_id === 'paypal') {
319
  return Kancart::getModel('PayPalWPS')->buildPaypalWPSParams();
320
  } else if ($payment_id === 'paypalwpp') {
321
  return Kancart::getModel('PayPalEC')->kancart_shoppingcart_paypalec_start('commit');
322
  } else {
323
+ return Kancart::getModel('Payment')->placeOrder($data, $payment_id);
324
  }
325
  } catch (Mage_Core_Exception $e) {
326
  return array(false, '0x9000', $e->getMessage());
330
  }
331
 
332
  private function getRealKancartPaymentId($payment_id) {
333
+ $priorsPayments = array(
334
+ 'banktransfer' => 0,
335
+ 'cashondelivery' => 1,
336
+ 'checkmo' => 2,
337
+ 'purchaseorder' => 3
338
+ );
339
+
340
+ $kcode = str_replace('kancart_', '', $payment_id);
341
+ $kcode = str_replace('magePay-', '', $kcode);
342
+ Mage::app()->getStore()->setConfig('payment/' . $kcode . '/active', true);
343
+ Mage::app()->getStore()->setConfig('payment/checkmo/active', true); //Activation checkout Money payment
344
+ $payments = array();
345
+ $methods = $this->getAvailablePayment();
346
+ if ($methods) {
347
+ foreach ($methods as $method) {
348
+ $code = $method->getCode();
349
+ if ($kcode == $code) {
350
+ return $code;
351
+ }
352
+ if (isset($priorsPayments[$code])) {
353
+ $payments[$priorsPayments[$code]] = $code;
 
 
354
  }
355
  }
356
+ }
357
 
358
+ if (sizeof($payments) < 1) {
359
+ Mage::throwException('No available offline payment method configured on Magento backend.');
360
+ }
361
 
362
+ ksort($payments);
363
+ reset($payments);
364
 
365
+ return current($payments);
 
366
  }
367
 
368
  /**
371
  public function kancart_checkout_start() {
372
  $payment_id = $this->getRequest()->getParam('payment_method_id', null);
373
  $checkout_type = $this->getRequest()->getParam('checkout_type');
374
+ if (Mage::getStoreConfig('payment/paypal_standard/active') < 1 && Kancart::helper('Data')->getFrontConfig('paypal_standard') > 0) {
375
+ Mage::app()->getStore()->setConfig('payment/paypal_standard/active', true);
376
+ }
377
+ if (Mage::getStoreConfig('payment/paypal_express/active') < 1 && Kancart::helper('Data')->getFrontConfig('paypal_express') > 0) {
378
+ Mage::app()->getStore()->setConfig('payment/paypal_express/active', true);
379
+ }
380
  switch ($checkout_type) {
381
  case 'cart':
382
  if ($payment_id == 'paypalec') {
app/code/community/Kancart/MobileApi/Model/Discount.php DELETED
@@ -1,79 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Magento
5
- *
6
- * NOTICE OF LICENSE
7
- *
8
- * This source file is subject to the Open Software License (OSL 3.0)
9
- * that is bundled with this package in the file LICENSE.txt.
10
- * It is also available through the world-wide-web at this URL:
11
- * http://opensource.org/licenses/osl-3.0.php
12
- * If you did not receive a copy of the license and are unable to
13
- * obtain it through the world-wide-web, please send an email
14
- * to license@magentocommerce.com so we can send you a copy immediately.
15
- *
16
- * DISCLAIMER
17
- *
18
- * Do not edit or add to this file if you wish to upgrade Magento to newer
19
- * versions in the future. If you wish to customize Magento for your
20
- * needs please refer to http://www.magentocommerce.com for more information.
21
- *
22
- * @category Mage
23
- * @package Mage_Sales
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- */
27
- class Kancart_MobileApi_Model_Discount extends Mage_SalesRule_Model_Quote_Discount {
28
-
29
- public function collect(Mage_Sales_Model_Quote_Address $address) {
30
- $address->setDiscountAmount(0);
31
- $address->setSubtotalWithDiscount(0);
32
- $address->setBaseDiscountAmount(0);
33
- $address->setBaseSubtotalWithDiscount(0);
34
-
35
- parent::collect($address);
36
- if ($address->getAddressType() == Mage_Sales_Model_Quote_Address::TYPE_BILLING) {
37
- return $this;
38
- }
39
-
40
- $totalDiscountAmount = $this->getRequest()->getParam('discount_amount');
41
- if ($totalDiscountAmount && !is_numeric($totalDiscountAmount)) {
42
- $totalDiscountAmount = $address->getBaseSubtotal() * floatval($totalDiscountAmount) / 100;
43
- }
44
-
45
- $freeShipping = $this->getRequest()->getParam('coupon_free_ship');
46
- if ($freeShipping && $freeShipping > 0 && $address->getShippingAmount()) {
47
- $totalDiscountAmount+=$address->getShippingAmount();
48
- }
49
-
50
- if ($totalDiscountAmount <= 0) {
51
- return $this;
52
- }
53
-
54
- $totalDiscountAmount += $address->getDiscountAmount();
55
- $subtotalWithDiscount = $totalDiscountAmount + $address->getSubtotalWithDiscount();
56
- $baseTotalDiscountAmount = $totalDiscountAmount + $address->getBaseDiscountAmount();
57
- $baseSubtotalWithDiscount = $totalDiscountAmount + $address->getBaseSubtotalWithDiscount();
58
-
59
- $address->setDiscountAmount($totalDiscountAmount);
60
- $address->setSubtotalWithDiscount($subtotalWithDiscount);
61
- $address->setBaseDiscountAmount($baseTotalDiscountAmount);
62
- $address->setBaseSubtotalWithDiscount($baseSubtotalWithDiscount);
63
-
64
- $address->setGrandTotal($address->getGrandTotal() - $totalDiscountAmount);
65
- $address->setBaseGrandTotal($address->getBaseGrandTotal() - $totalDiscountAmount);
66
- return $this;
67
- }
68
-
69
- /**
70
- * Retrieve request object
71
- *
72
- * @return Mage_Core_Controller_Request_Http
73
- */
74
- public function getRequest() {
75
- return Mage::app()->getRequest();
76
- }
77
-
78
- }
79
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Kancart/MobileApi/Model/Invoice/Total/Discount.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Kancart MobileApi extension
5
+ *
6
+ * @category kancart
7
+ * @package Kancart_MobileApi
8
+ * @author kancart <support@kancart.com>
9
+ */
10
+ class Kancart_MobileApi_Model_Invoice_Total_Discount extends Mage_Sales_Model_Order_Invoice_Total_Abstract {
11
+
12
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice) {
13
+ if (!Mage::helper('mobileapi')->isDiscountEnabled()) {
14
+ return $this;
15
+ }
16
+ $order = $invoice->getOrder();
17
+ if (!$order->getBaseMobileDiscount()) {
18
+ return $this;
19
+ }
20
+
21
+ $invoiceBaseRemainder = $order->getBaseMobileDiscount() - $order->getBaseMobileInvoiced();
22
+ $invoiceRemainder = $order->getMobileDiscount() - $order->getMobileInvoiced();
23
+ $used = $baseUsed = 0;
24
+ if ($invoiceBaseRemainder < $invoice->getBaseGrandTotal()) {
25
+ $used = $invoiceRemainder;
26
+ $baseUsed = $invoiceBaseRemainder;
27
+ $invoice->setGrandTotal($invoice->getGrandTotal() - $used);
28
+ $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseUsed);
29
+ } else {
30
+ $used = $invoice->getGrandTotal();
31
+ $baseUsed = $invoice->getBaseGrandTotal();
32
+
33
+ $invoice->setBaseGrandTotal(0);
34
+ $invoice->setGrandTotal(0);
35
+ }
36
+
37
+ $order->setBaseDiscountAmount($order->getBaseDiscountAmount() + $baseUsed);
38
+ $order->setDiscountAmount($order->getDiscountAmount() + $used);
39
+
40
+ $invoice->setMobileDiscount($used);
41
+ $invoice->setBaseMobileDiscount($baseUsed);
42
+
43
+ return $this;
44
+ }
45
+
46
+ }
app/code/community/Kancart/MobileApi/Model/Item.php CHANGED
@@ -29,6 +29,12 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
29
  * @var Mage_Catalog_Model_Product
30
  */
31
  protected $product;
 
 
 
 
 
 
32
 
33
  /**
34
  * the item converted by the current product
@@ -38,13 +44,36 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
38
  private $detail = false;
39
 
40
  const OPTION_TYPE_SELECT = 'select';
41
- const OPTION_TYPE_CHECKBOX = 'select';
42
  const OPTION_TYPE_MULTIPLE_SELECT = 'multiselect';
43
  const OPTION_TYPE_TEXT = 'text';
44
  const OPTION_TYPE_DATE = 'date';
45
  const OPTION_TYPE_TIME = 'time';
46
  const OPTION_TYPE_DATE_TIME = 'datetime';
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  /**
49
  * the API interface function
50
  * @param type $apidata
@@ -68,19 +97,19 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
68
 
69
  public function getItemBaseInfo() {
70
  $helper = Mage::helper('catalog/image');
71
- $helper->init($this->product, $this->getProductImageType())->keepFrame(true); //true
 
72
  $this->item['item_id'] = $this->product->getId();
73
  $this->item['item_title'] = $this->product->getName();
74
  $this->item['item_url'] = $this->product->getProductUrl();
75
  $this->item['cid'] = $this->product->getCategoryIds();
76
  $this->item['qty'] = $this->product->getStockItem()->getQty();
77
- $this->item['thumbnail_pic_url'] = (string) $helper->resize(320);
78
- $this->item['main_pic_url'] = (string) $helper->resize(640);
79
  $this->item['is_virtual'] = $this->product->isVirtual();
80
  $this->item['item_status'] = $this->product->isSaleable() ? 'instock' : 'outofstock';
81
  if (!$this->product->getRatingSummary()) {
82
- Mage::getModel('review/review')
83
- ->getEntitySummary($this->product, Mage::app()->getStore()->getId());
84
  }
85
  $this->item['allow_add_to_cart'] = !$this->HasOptions();
86
  $this->item['rating_score'] = round((int) $this->product->getRatingSummary()->getRatingSummary() / 20);
@@ -209,11 +238,12 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
209
  public function getProductDescription() {
210
  $_helper = Mage::helper('catalog/output');
211
  $this->item['short_description'] = $_helper->productAttribute($this->product, nl2br($this->product->getShortDescription()), 'short_description');
 
212
  $this->item['detail_description'] = $_helper->productAttribute($this->product, $this->product->getDescription(), 'description');
213
  if (preg_match('/{{(.+)}}/i', $this->item['detail_description'])) {
214
- $this->item['detail_description'] = preg_replace('/(\<img[^\<\>]+src\s*=\s*"){{(\w+)\s*url="(.+)}}/i', '$1' . Mage::getBaseUrl() . '/$2/$3', $this->item['detail_description']);
215
  }
216
- $this->item['detail_description'] = preg_replace('/(<img[^<^>]+?src\s*=\s*(\"|\'))([^:\"\']+\2)/i', '$1' . Mage::getBaseUrl() . '$3', $this->item['detail_description']);
217
  $this->item['specifications'] = $this->getProductFeature();
218
  }
219
 
@@ -249,7 +279,10 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
249
  private function getItemImageUrl($imageFile = null) {
250
  $imageType = $this->getProductImageType();
251
  $helper = Mage::helper('catalog/image');
252
- return (string) $helper->init($this->product, $imageType, $imageFile)->keepFrame(true)->resize(640);
 
 
 
253
  }
254
 
255
  public function getItemImages() {
@@ -421,7 +454,7 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
421
  $attribute['input'] = $this->_getOptionTypeForKanCartByRealType($_option->getType());
422
  $attribute['title'] = $_option->getTitle();
423
  $attribute['options'] = array();
424
- if (!$attribute['required'] && $attribute['input'] != self::OPTION_TYPE_MULTIPLE_SELECT) {
425
  $none = array(
426
  'attribute_id' => 'none',
427
  'option_id' => '',
@@ -575,7 +608,7 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
575
  $optionObj['price'] = null;
576
  }
577
  $optionObj['options'] = array();
578
- if (!$optionObj['required'] && $optionObj['input'] != self::OPTION_TYPE_MULTIPLE_SELECT) {
579
  $none = array(
580
  'attribute_id' => 'none',
581
  'option_id' => '',
@@ -716,7 +749,7 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
716
  $DisplayMinimalPrice = true;
717
  $UseLinkForAsLowAs = false;
718
  $prices = array();
719
- $prices['currency'] = Mage::getModel('core/store')->load(Mage::app()->getStore()->getId())->getCurrentCurrencyCode();
720
  $display_prices = array();
721
  $prices['tier_prices'] = $this->getItemTierPrice($product);
722
 
29
  * @var Mage_Catalog_Model_Product
30
  */
31
  protected $product;
32
+ protected $_keepFrame = true;
33
+ protected $_keepAspectRatio = true; //false stretch the image
34
+ protected $thumbnail_with = 320;
35
+ protected $thumbnail_height = null;
36
+ protected $main_with = 640;
37
+ protected $main_height = null;
38
 
39
  /**
40
  * the item converted by the current product
44
  private $detail = false;
45
 
46
  const OPTION_TYPE_SELECT = 'select';
47
+ const OPTION_TYPE_CHECKBOX = 'multiselect';
48
  const OPTION_TYPE_MULTIPLE_SELECT = 'multiselect';
49
  const OPTION_TYPE_TEXT = 'text';
50
  const OPTION_TYPE_DATE = 'date';
51
  const OPTION_TYPE_TIME = 'time';
52
  const OPTION_TYPE_DATE_TIME = 'datetime';
53
 
54
+ public function __construct() {
55
+ parent::__construct();
56
+ $this->_keepFrame = Kancart::helper('Data')->getFrontConfig('image_frame') < 1;
57
+ $thumbnailSize = Kancart::helper('Data')->getFrontConfig('thumbnail_image');
58
+ $mainSize = Kancart::helper('Data')->getFrontConfig('main_image');
59
+ if (intval($thumbnailSize) > 80) {
60
+ $this->thumbnail_with = intval($thumbnailSize);
61
+ if (($index = stripos($thumbnailSize, 'x'))) {
62
+ $height = intval(trim(substr($thumbnailSize, $index + 1)));
63
+ $this->thumbnail_height = $height > 80 ? $height : null;
64
+ }
65
+ }
66
+ if (intval($mainSize) > 160) {
67
+ $this->main_with = intval($mainSize);
68
+ if (($index = stripos($mainSize, 'x'))) {
69
+ $height = intval(trim(substr($mainSize, $index + 1)));
70
+ $this->main_height = $height > 160 ? $height : null;
71
+ }
72
+ }
73
+
74
+ $this->_keepAspectRatio = $this->main_height < 1;
75
+ }
76
+
77
  /**
78
  * the API interface function
79
  * @param type $apidata
97
 
98
  public function getItemBaseInfo() {
99
  $helper = Mage::helper('catalog/image');
100
+ $helper->init($this->product, $this->getProductImageType())
101
+ ->keepAspectRatio($this->_keepAspectRatio)->keepFrame($this->_keepFrame);
102
  $this->item['item_id'] = $this->product->getId();
103
  $this->item['item_title'] = $this->product->getName();
104
  $this->item['item_url'] = $this->product->getProductUrl();
105
  $this->item['cid'] = $this->product->getCategoryIds();
106
  $this->item['qty'] = $this->product->getStockItem()->getQty();
107
+ $this->item['thumbnail_pic_url'] = (string) $helper->resize($this->thumbnail_with, $this->thumbnail_height);
108
+ $this->item['main_pic_url'] = (string) $helper->resize($this->main_with, $this->main_height);
109
  $this->item['is_virtual'] = $this->product->isVirtual();
110
  $this->item['item_status'] = $this->product->isSaleable() ? 'instock' : 'outofstock';
111
  if (!$this->product->getRatingSummary()) {
112
+ Mage::getModel('review/review')->getEntitySummary($this->product, Mage::app()->getStore()->getId());
 
113
  }
114
  $this->item['allow_add_to_cart'] = !$this->HasOptions();
115
  $this->item['rating_score'] = round((int) $this->product->getRatingSummary()->getRatingSummary() / 20);
238
  public function getProductDescription() {
239
  $_helper = Mage::helper('catalog/output');
240
  $this->item['short_description'] = $_helper->productAttribute($this->product, nl2br($this->product->getShortDescription()), 'short_description');
241
+ $this->item['short_description'] = preg_replace('/(<img[^<>]+?src\s*=\s*\")([^:\"]+\")/i', '$1' . Mage::getBaseUrl() . '$2', $this->item['short_description']);
242
  $this->item['detail_description'] = $_helper->productAttribute($this->product, $this->product->getDescription(), 'description');
243
  if (preg_match('/{{(.+)}}/i', $this->item['detail_description'])) {
244
+ $this->item['detail_description'] = preg_replace('/(\<img[^<>]+src\s*=\s*"){{(\w+)\s*url="(.+)}}/i', '$1' . Mage::getBaseUrl() . '/$2/$3', $this->item['detail_description']);
245
  }
246
+ $this->item['detail_description'] = preg_replace('/(<img[^<>]+?src\s*=\s*\")([^:\"]+\")/i', '$1' . Mage::getBaseUrl() . '$2', $this->item['detail_description']);
247
  $this->item['specifications'] = $this->getProductFeature();
248
  }
249
 
279
  private function getItemImageUrl($imageFile = null) {
280
  $imageType = $this->getProductImageType();
281
  $helper = Mage::helper('catalog/image');
282
+ return (string) $helper->init($this->product, $imageType, $imageFile)
283
+ ->keepAspectRatio($this->_keepAspectRatio)
284
+ ->keepFrame($this->_keepFrame)
285
+ ->resize($this->main_with, $this->main_height);
286
  }
287
 
288
  public function getItemImages() {
454
  $attribute['input'] = $this->_getOptionTypeForKanCartByRealType($_option->getType());
455
  $attribute['title'] = $_option->getTitle();
456
  $attribute['options'] = array();
457
+ if (!$attribute['required'] && $attribute['input'] == self::OPTION_TYPE_SELECT) {
458
  $none = array(
459
  'attribute_id' => 'none',
460
  'option_id' => '',
608
  $optionObj['price'] = null;
609
  }
610
  $optionObj['options'] = array();
611
+ if (!$optionObj['required'] && $optionObj['input'] == self::OPTION_TYPE_SELECT) {
612
  $none = array(
613
  'attribute_id' => 'none',
614
  'option_id' => '',
749
  $DisplayMinimalPrice = true;
750
  $UseLinkForAsLowAs = false;
751
  $prices = array();
752
+ $prices['currency'] = Mage::app()->getStore()->getCurrentCurrencyCode();
753
  $display_prices = array();
754
  $prices['tier_prices'] = $this->getItemTierPrice($product);
755
 
app/code/community/Kancart/MobileApi/Model/Items.php CHANGED
@@ -30,24 +30,22 @@ class Kancart_MobileApi_Model_Items extends Kancart_MobileApi_Model_Abstract {
30
  * @return type
31
  */
32
  public function kancart_items_get() {
33
- if (isset($_REQUEST['query']) && $_REQUEST['query']) {
34
- $_REQUEST['query'] = str_replace('%20', ' ', $_REQUEST['query']);
35
- }
36
- $params = $this->getRequest()->getParams();
37
  try {
38
- $cid = $params['cid'];
39
- $query = isset($params['query']) ? $params['query'] : false;
40
- $pageNo = isset($params['page_no']) ? $params['page_no'] : 1;
41
- $pageSize = isset($params['page_size']) ? $params['page_size'] : 20;
42
- $orderBy = isset($params['order_by']) && strpos($params['order_by'], ':') > 0 ? $params['order_by'] : 'postion:desc';
 
 
43
  list($order, $direction) = explode(':', $orderBy, 2);
44
- if (isset($params['item_ids']) && trim($params['item_ids'])) {
45
  // get by item ids
46
- $products = $this->getSpecifiedProducts($params['item_ids'], $pageNo, $pageSize, $order, $direction);
47
- } else if (isset($params['is_specials']) && intval($params['is_specials'])) {
48
  // get Special Products
49
  $products = $this->getSpecialProducts($pageNo, $pageSize, $order, $direction);
50
- } else if (strlen($query)) {
51
  // get by query
52
  $products = $this->getProductsByQuery($query, $pageNo, $pageSize, $order, $direction);
53
  } else if ($cid == -1) {
@@ -111,20 +109,24 @@ class Kancart_MobileApi_Model_Items extends Kancart_MobileApi_Model_Abstract {
111
  }
112
 
113
  private function getAllProducts($pageNo, $pageSize, $order, $direction, $specials = false) {
114
- $layer = Mage::getSingleton('catalog/layer')
115
- ->setCurrentCategory(Mage::app()->getStore()->getRootCategoryId());
116
- $collection = Mage::getResourceModel('catalog/product_collection');
117
- $layer->prepareProductCollection($collection);
118
- $collection->setCurPage($pageNo)
119
  ->setPageSize($pageSize)
120
  ->setOrder($order, $direction);
 
 
 
 
 
121
 
122
  if ($specials) {
123
  $collection->getSelect()->where('`price` > `final_price`');
124
  }
125
-
126
- $collection->load();
127
  $size = $collection->getSize();
 
 
128
  $productList = $collection->getItems();
129
 
130
  $items = array();
@@ -206,6 +208,15 @@ class Kancart_MobileApi_Model_Items extends Kancart_MobileApi_Model_Abstract {
206
 
207
  private function getProductsByCategory($cid = false, $pageNo = 1, $pageSize = 20, $order = 'entity_id', $direction = 'desc') {
208
  $layer = Mage::getSingleton('catalog/layer')->setCurrentCategory($cid);
 
 
 
 
 
 
 
 
 
209
  $collection = $layer->getProductCollection()
210
  ->setCurPage($pageNo)
211
  ->setPageSize($pageSize)
30
  * @return type
31
  */
32
  public function kancart_items_get() {
 
 
 
 
33
  try {
34
+ $cid = $this->getRequest()->getParam('cid', false);
35
+ $query = str_replace('%20', ' ', $this->getRequest()->getParam('query', ''));
36
+ $pageNo = $this->getRequest()->getParam('page_no', 1);
37
+ $pageSize = $this->getRequest()->getParam('page_size', 20);
38
+ $itemIds = $this->getRequest()->getParam('item_ids', false);
39
+ $orderBy = $this->getRequest()->getParam('order_by', false);
40
+ $orderBy = $orderBy && strpos($orderBy, ':') > 0 ? $orderBy : 'postion:desc';
41
  list($order, $direction) = explode(':', $orderBy, 2);
42
+ if ($itemIds && trim($itemIds)) {
43
  // get by item ids
44
+ $products = $this->getSpecifiedProducts($itemIds, $pageNo, $pageSize, $order, $direction);
45
+ } else if ((int) $this->getRequest()->getParam('is_specials', 0)) {
46
  // get Special Products
47
  $products = $this->getSpecialProducts($pageNo, $pageSize, $order, $direction);
48
+ } else if (strlen($query) || (isset($_POST['query']) && !$cid)) {
49
  // get by query
50
  $products = $this->getProductsByQuery($query, $pageNo, $pageSize, $order, $direction);
51
  } else if ($cid == -1) {
109
  }
110
 
111
  private function getAllProducts($pageNo, $pageSize, $order, $direction, $specials = false) {
112
+ $collection = Mage::getSingleton('catalog/layer')
113
+ ->setCurrentCategory(Mage::app()->getStore()->getRootCategoryId())
114
+ ->getProductCollection()
115
+ ->setCurPage($pageNo)
 
116
  ->setPageSize($pageSize)
117
  ->setOrder($order, $direction);
118
+ $fromPart = $collection->getSelect()->getPart(Zend_Db_Select::FROM);
119
+ if (isset($fromPart['cat_index'])) {
120
+ $fromPart['cat_index']['joinCondition'] = preg_replace('/category_id\s*=\s*\'\d+\'/', 'category_id > \'0\'', $fromPart['cat_index']['joinCondition']);
121
+ $collection->getSelect()->setPart(Zend_Db_Select::FROM, $fromPart);
122
+ }
123
 
124
  if ($specials) {
125
  $collection->getSelect()->where('`price` > `final_price`');
126
  }
 
 
127
  $size = $collection->getSize();
128
+ $collection->getSelect()->group('e.entity_id');
129
+ $collection->load();
130
  $productList = $collection->getItems();
131
 
132
  $items = array();
208
 
209
  private function getProductsByCategory($cid = false, $pageNo = 1, $pageSize = 20, $order = 'entity_id', $direction = 'desc') {
210
  $layer = Mage::getSingleton('catalog/layer')->setCurrentCategory($cid);
211
+
212
+ $filter = $this->getRequest()->getParam('filter', array());
213
+ if ($filter && is_array($filter)) {
214
+ foreach ($filter as $key => $value) {
215
+ $this->getRequest()->setParam($key, $value);
216
+ }
217
+ Mage::getBlockSingleton('catalog/layer_view');
218
+ }
219
+
220
  $collection = $layer->getProductCollection()
221
  ->setCurPage($pageNo)
222
  ->setPageSize($pageSize)
app/code/community/Kancart/MobileApi/Model/Order.php CHANGED
@@ -126,7 +126,7 @@ class Kancart_MobileApi_Model_Order extends Kancart_MobileApi_Model_Abstract {
126
  $ordersCounts = array(
127
  'order_counts' => array(
128
  array('status_ids' => 'all',
129
- 'status_name' =>Mage::helper('Sales')->__('My Orders'),
130
  'count' => $collection->getSize())
131
  )
132
  );
126
  $ordersCounts = array(
127
  'order_counts' => array(
128
  array('status_ids' => 'all',
129
+ 'status_name' => Mage::helper('Sales')->__('My Orders'),
130
  'count' => $collection->getSize())
131
  )
132
  );
app/code/community/Kancart/MobileApi/Model/PayPalWPS.php CHANGED
@@ -79,10 +79,11 @@ class Kancart_MobileApi_Model_PayPalWPS extends Kancart_MobileApi_Model_Abstract
79
  * @return bool
80
  */
81
  public function placeOrder($payment, $comment = 'from mobile') {
 
82
  $request = $this->getRequest()
83
  ->setPost('payment', $payment)
84
  ->setActionName('index')
85
- ->setPost('agreement', Mage::helper('checkout')->getRequiredAgreementIds()); //skip agreements
86
 
87
  if (($formKey = Mage::getSingleton('core/session')->getFormKey())) {
88
  $this->getRequest()->setParam('form_key', $formKey);
79
  * @return bool
80
  */
81
  public function placeOrder($payment, $comment = 'from mobile') {
82
+ $agreements = Mage::helper('checkout')->getRequiredAgreementIds();
83
  $request = $this->getRequest()
84
  ->setPost('payment', $payment)
85
  ->setActionName('index')
86
+ ->setPost('agreement', array_fill_keys($agreements, true)); //skip agreements
87
 
88
  if (($formKey = Mage::getSingleton('core/session')->getFormKey())) {
89
  $this->getRequest()->setParam('form_key', $formKey);
app/code/community/Kancart/MobileApi/Model/Quote/Total/Discount.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Kancart MobileApi extension
5
+ *
6
+ * @category kancart
7
+ * @package Kancart_MobileApi
8
+ * @author kancart <support@kancart.com>
9
+ */
10
+ class Kancart_MobileApi_Model_Quote_Total_Discount extends Mage_Sales_Model_Quote_Address_Total_Abstract {
11
+
12
+ public function __construct() {
13
+ $this->setCode('mobileapi');
14
+ }
15
+
16
+ public function collect(Mage_Sales_Model_Quote_Address $address) {
17
+ if (!Mage::helper('mobileapi')->isDiscountEnabled()) {
18
+ return $this;
19
+ }
20
+
21
+ $address->setMobileDiscount(0);
22
+ $address->setBaseMobileDiscount(0);
23
+
24
+ if (Mage::helper('checkout/cart')->getIsVirtualQuote()) {
25
+ $addressType = Mage_Sales_Model_Quote_Address::TYPE_BILLING;
26
+ } else {
27
+ $addressType = Mage_Sales_Model_Quote_Address::TYPE_SHIPPING;
28
+ }
29
+ if ($address->getAddressType() != $addressType) {
30
+ return $this;
31
+ }
32
+
33
+ $totalDiscountAmount = $this->getRequest()->getParam('discount_amount');
34
+ if ($totalDiscountAmount && !is_numeric($totalDiscountAmount)) {
35
+ $totalDiscountAmount = $address->getBaseSubtotal() * floatval($totalDiscountAmount) / 100;
36
+ }
37
+
38
+ $freeShipping = $this->getRequest()->getParam('coupon_free_ship');
39
+ if ($freeShipping && $freeShipping > 0 && $address->getShippingAmount()) {
40
+ $totalDiscountAmount+=$address->getShippingAmount();
41
+ }
42
+
43
+ if ($totalDiscountAmount <= 0) {
44
+ return $this;
45
+ }
46
+
47
+ $address->setMobileDiscount($totalDiscountAmount);
48
+ $address->setBaseMobileDiscount($totalDiscountAmount);
49
+
50
+ if (!strcasecmp($this->getRequest()->getParam('method'), 'Kancart.Checkout.Start')) {
51
+ $address->setBaseDiscountAmount($address->getBaseDiscountAmount() + $totalDiscountAmount);
52
+ $address->setDiscountAmount($address->getDiscountAmount() + $totalDiscountAmount);
53
+ }
54
+
55
+ $address->setGrandTotal($address->getGrandTotal() - $totalDiscountAmount);
56
+ $address->setBaseGrandTotal($address->getBaseGrandTotal() - $totalDiscountAmount);
57
+
58
+ return $this;
59
+ }
60
+
61
+ /**
62
+ * Retrieve request object
63
+ *
64
+ * @return Mage_Core_Controller_Request_Http
65
+ */
66
+ public function getRequest() {
67
+ return Mage::app()->getRequest();
68
+ }
69
+
70
+ public function fetch(Mage_Sales_Model_Quote_Address $address) {
71
+ if (!Mage::helper('mobileapi')->isDiscountEnabled())
72
+ return $this;
73
+
74
+ if ($address->getMobileDiscount() > 0) {
75
+ $address->addTotal(array(
76
+ 'code' => $this->getCode(),
77
+ 'title' => Mage::helper('sales')->__('Discount'),
78
+ 'value' => -$address->getMobileDiscount(),
79
+ ));
80
+ }
81
+ return $this;
82
+ }
83
+
84
+ }
app/code/community/Kancart/MobileApi/Model/Store.php CHANGED
@@ -119,8 +119,9 @@ class Kancart_MobileApi_Model_Store extends Kancart_MobileApi_Model_Abstract {
119
  */
120
  public function getCurrencies() {
121
  $Curencies = array();
122
- $defaultCurrencyCode = Mage::app()->getStore()->getDefaultCurrencyCode();
123
- $allowedCurrencies = Mage::getBlockSingleton('Directory/Currency')->getCurrencies();
 
124
  if (empty($allowedCurrencies)) {
125
  $allowedCurrencies[$defaultCurrencyCode] = 'default';
126
  }
@@ -146,15 +147,18 @@ class Kancart_MobileApi_Model_Store extends Kancart_MobileApi_Model_Abstract {
146
  public function getLanguages() {
147
  $languages = array();
148
  $stores = Mage::app()->getStores(false, true);
 
 
149
  foreach ($stores as $store) {
150
- if ($store->getIsActive() && $store->getWebsite()->getIsDefault()) {
151
- if ($store->getGroup()->getId() == $store->getWebsite()->getDefaultGroupId()) {
152
- $locale = Mage::getStoreConfig('general/locale/code', $store->getCode());
153
  $languages[] = array(
154
  'language_id' => $store->getCode(),
155
- 'language_code' => $locale,
156
  'language_name' => $store->getName(),
157
- 'position' => $store->getSortOrder());
 
158
  }
159
  }
160
  }
@@ -272,6 +276,7 @@ class Kancart_MobileApi_Model_Store extends Kancart_MobileApi_Model_Abstract {
272
  'cart_version' => Mage::getVersion(),
273
  'plugin_version' => KANCART_PLUGIN_VERSION,
274
  'support_kancart_payment' => true,
 
275
  'support_promotion' => true,
276
  'login_by_mail' => true
277
  );
119
  */
120
  public function getCurrencies() {
121
  $Curencies = array();
122
+ $block = Mage::getBlockSingleton('Directory/Currency');
123
+ $defaultCurrencyCode = $block->getCurrentCurrencyCode();
124
+ $allowedCurrencies = $block->getCurrencies();
125
  if (empty($allowedCurrencies)) {
126
  $allowedCurrencies[$defaultCurrencyCode] = 'default';
127
  }
147
  public function getLanguages() {
148
  $languages = array();
149
  $stores = Mage::app()->getStores(false, true);
150
+ $allowspecific = Kancart::helper('Data')->getFrontConfig('allowspecific') > 0;
151
+ $annlowStores = explode(',', Kancart::helper('Data')->getFrontConfig('stores'));
152
  foreach ($stores as $store) {
153
+ if ($store->getIsActive()) {
154
+ $allow = !$allowspecific && $store->getWebsite()->getIsDefault() && $store->getGroup()->getId() == $store->getWebsite()->getDefaultGroupId();
155
+ if ($allow || ($allowspecific && in_array($store->getCode(), $annlowStores))) {
156
  $languages[] = array(
157
  'language_id' => $store->getCode(),
158
+ 'language_code' => Mage::getStoreConfig('general/locale/code', $store->getCode()),
159
  'language_name' => $store->getName(),
160
+ 'position' => $store->getSortOrder()
161
+ );
162
  }
163
  }
164
  }
276
  'cart_version' => Mage::getVersion(),
277
  'plugin_version' => KANCART_PLUGIN_VERSION,
278
  'support_kancart_payment' => true,
279
+ 'support_facebook_login' => true,
280
  'support_promotion' => true,
281
  'login_by_mail' => true
282
  );
app/code/community/Kancart/MobileApi/Model/System/Config/Source/Allspecificstore.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_Paypal
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+
28
+ /**
29
+ * Source model for merchant countries supported by PayPal
30
+ */
31
+ class Kancart_MobileApi_Model_System_Config_Source_Allspecificstore {
32
+
33
+ public function toOptionArray() {
34
+ return array(
35
+ array('value' => 0, 'label' => Mage::helper('adminhtml')->__('Default')),
36
+ array('value' => 1, 'label' => Mage::helper('adminhtml')->__('Specific Stores')),
37
+ );
38
+ }
39
+
40
+ }
app/code/community/Kancart/MobileApi/Model/{Invoice.php → System/Config/Source/Store.php} RENAMED
@@ -1,48 +1,43 @@
1
- <?php
2
-
3
- /**
4
- * Magento
5
- *
6
- * NOTICE OF LICENSE
7
- *
8
- * This source file is subject to the Open Software License (OSL 3.0)
9
- * that is bundled with this package in the file LICENSE.txt.
10
- * It is also available through the world-wide-web at this URL:
11
- * http://opensource.org/licenses/osl-3.0.php
12
- * If you did not receive a copy of the license and are unable to
13
- * obtain it through the world-wide-web, please send an email
14
- * to license@magentocommerce.com so we can send you a copy immediately.
15
- *
16
- * DISCLAIMER
17
- *
18
- * Do not edit or add to this file if you wish to upgrade Magento to newer
19
- * versions in the future. If you wish to customize Magento for your
20
- * needs please refer to http://www.magentocommerce.com for more information.
21
- *
22
- * @category Mage
23
- * @package Mage_Sales
24
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- */
27
- class Kancart_MobileApi_Model_Invoice extends Mage_Sales_Model_Order_Invoice_Total_Discount {
28
-
29
- public function collect(Mage_Sales_Model_Order_Invoice $invoice) {
30
- parent::collect($invoice);
31
-
32
- $totalDiscountAmount = $invoice->getOrder()->getDiscountAmount();
33
- $baseTotalDiscountAmount = $invoice->getOrder()->getBaseDiscountAmount();
34
-
35
- if ($totalDiscountAmount <= 0) {
36
- return $this;
37
- }
38
-
39
- $invoice->setDiscountAmount($totalDiscountAmount);
40
- $invoice->setBaseDiscountAmount($baseTotalDiscountAmount);
41
-
42
- $invoice->setGrandTotal($invoice->getGrandTotal() - $totalDiscountAmount);
43
- $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseTotalDiscountAmount);
44
- return $this;
45
- }
46
-
47
- }
48
-
1
+ <?php
2
+
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_Adminhtml
24
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ class Kancart_MobileApi_Model_System_Config_Source_Store {
28
+
29
+ protected $_options;
30
+
31
+ public function toOptionArray() {
32
+ if (!$this->_options) {
33
+ $stores = Mage::app()->getStores(false, true);
34
+ foreach ($stores as $store) {
35
+ if ($store->getIsActive()) {
36
+ $this->_options[] = array('value' => $store->getCode(), 'label' => $store->getName());
37
+ }
38
+ }
39
+ }
40
+ return $this->_options;
41
+ }
42
+
43
+ }
 
 
 
 
 
app/code/community/Kancart/MobileApi/Model/User.php CHANGED
@@ -38,7 +38,7 @@ class Kancart_MobileApi_Model_User extends Kancart_MobileApi_Model_Abstract {
38
  }
39
  $customer->getGroupId();
40
  try {
41
- $desPassword = Kancart::helper('CryptoUtil')->Crypto($userData['pwd'], 'AES-256', KANCART_APP_SECRECT, false);
42
  $customer->setPassword($desPassword);
43
  $customer->setConfirmation($this->getRequest()->getPost('confirmation', $desPassword));
44
  $customer->setData('email', $userData['email']);
@@ -116,15 +116,15 @@ class Kancart_MobileApi_Model_User extends Kancart_MobileApi_Model_Abstract {
116
  }
117
 
118
  public function kancart_user_login() {
119
- $userLoginData = $this->getRequest()->getParams();
120
- $uname = $userLoginData['uname'];
121
- $pwd = $userLoginData['pwd'];
 
122
  $session = $this->_getSession();
123
  $defaultGroupId = $session->getCustomer()->getGroupId();
124
- $desPassword = Kancart::helper('CryptoUtil')->Crypto($pwd, 'AES-256', KANCART_APP_SECRECT, false);
125
- if ($uname != null && $pwd != null) {
126
  try {
127
- if ($session->login($uname, $desPassword)) {
128
  if ($session->getCustomer()->getIsJustConfirmed()) {
129
  $session->getCustomer()->sendNewAccountEmail('confirmed');
130
  }
@@ -167,30 +167,52 @@ class Kancart_MobileApi_Model_User extends Kancart_MobileApi_Model_Abstract {
167
  }
168
  }
169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  public function kancart_user_get() {
171
- $userData = $this->getRequest()->getParams();
172
  if (!$this->isLoggedIn()) {
173
  return array(false, '0x0002', 'You need login first.');
174
  }
175
- $fields = $userData['fields'];
176
  $session = $this->_getSession();
177
- return array(true, '0x0000', $this->_toUserData($session->getCustomer()), $fields);
178
  }
179
 
180
  public function kancart_user_isexists() {
181
- $userData = $this->getRequest()->getParams();
182
- $info = array(
183
- 'uname_is_exist' => true
184
- );
185
- $customer = Mage::getModel('customer/customer');
186
- $customer->setStoreId(1);
187
- $customer->setWebsiteId(1);
188
- $customer->loadByEmail($userData['email']);
189
- if ($customer->getData('entity_id')) {
190
- $info['uname_is_exist'] = true;
191
- } else {
192
- $info['uname_is_exist'] = false;
193
- }
194
  return array(true, '0x0000', $info);
195
  }
196
 
@@ -320,25 +342,13 @@ class Kancart_MobileApi_Model_User extends Kancart_MobileApi_Model_Abstract {
320
  }
321
  }
322
 
 
 
 
 
323
  protected function _getSession() {
324
  return Mage::getSingleton('customer/session');
325
  }
326
 
327
- protected function _toUserData($customerData) {
328
- $userData = array(
329
- 'uname' => $customerData->email,
330
- 'nick' => $customerData->firstname . $customerData->lastname,
331
- 'email' => $customerData->email,
332
- 'fax' => null,
333
- 'telephone' => null,
334
- 'default_address_id' => null,
335
- 'dob' => null,
336
- 'lastname' => $customerData->lastname,
337
- 'firstname' => $customerData->firstname,
338
- 'gender' => null,
339
- 'mobile' => null
340
- );
341
- return $userData;
342
- }
343
 
344
  }
38
  }
39
  $customer->getGroupId();
40
  try {
41
+ $desPassword = Kancart::helper('CryptoUtil')->Crypto($userData['pwd'], 'AES-256', KANCART_APP_SECRET, false);
42
  $customer->setPassword($desPassword);
43
  $customer->setConfirmation($this->getRequest()->getPost('confirmation', $desPassword));
44
  $customer->setData('email', $userData['email']);
116
  }
117
 
118
  public function kancart_user_login() {
119
+ $uname = $this->getRequest()->getParam('uname');
120
+ $pwd = $this->getRequest()->getParam('pwd');
121
+ $type = $this->getRequest()->getParam('type', 'normal');
122
+
123
  $session = $this->_getSession();
124
  $defaultGroupId = $session->getCustomer()->getGroupId();
125
+ if ($uname != null && ($pwd != null || $type != 'normal')) {
 
126
  try {
127
+ if ($this->login($uname, $pwd)) {
128
  if ($session->getCustomer()->getIsJustConfirmed()) {
129
  $session->getCustomer()->sendNewAccountEmail('confirmed');
130
  }
167
  }
168
  }
169
 
170
+ public function login($uname, $pwd) {
171
+ $session = $this->_getSession();
172
+ $type = $this->getRequest()->getParam('type', 'normal');
173
+ if ($type == 'normal') {
174
+ $desPassword = Kancart::helper('CryptoUtil')->Crypto($pwd, 'AES-256', KANCART_APP_SECRET, false);
175
+ return $session->login($uname, $desPassword);
176
+ } elseif ($type == 'oauth') {
177
+ if (!preg_match('/^.+@\w+\.\w+$/', $uname)) {
178
+ Mage::throwException('Invalid E-mail.');
179
+ }
180
+ $customer = Mage::getModel('customer/customer')
181
+ ->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
182
+ $customer->loadByEmail($uname);
183
+ if (!$customer->getId()) {
184
+ Mage::register('current_customer', $customer);
185
+ $password = strtoupper(dechex(crc32(KANCART_APP_KEY . $uname)));
186
+ $password = Kancart::helper('CryptoUtil')->Crypto($password, 'AES-256', KANCART_APP_SECRET, true);
187
+ $this->getRequest()->setPost('pwd', $password);
188
+ $this->getRequest()->setPost('email', $uname);
189
+ list($result, $code, $message) = $this->kancart_user_register();
190
+ if (!$result) {
191
+ Mage::throwException(is_array($message) ? join(PHP_EOL, $message) : $message);
192
+ }
193
+ }
194
+ $session->setCustomerAsLoggedIn($customer);
195
+ $session->renewSession();
196
+ return true;
197
+ }
198
+
199
+ return false;
200
+ }
201
+
202
  public function kancart_user_get() {
 
203
  if (!$this->isLoggedIn()) {
204
  return array(false, '0x0002', 'You need login first.');
205
  }
 
206
  $session = $this->_getSession();
207
+ return array(true, '0x0000', array());
208
  }
209
 
210
  public function kancart_user_isexists() {
211
+ $info = array();
212
+ $customer = Mage::getModel('customer/customer')
213
+ ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
214
+ ->loadByEmail($this->getRequest()->getParam('email'));
215
+ $info['uname_is_exist'] = $customer->getId() > 0;
 
 
 
 
 
 
 
 
216
  return array(true, '0x0000', $info);
217
  }
218
 
342
  }
343
  }
344
 
345
+ /**
346
+ *
347
+ * @return Mage_Customer_Model_Session
348
+ */
349
  protected function _getSession() {
350
  return Mage::getSingleton('customer/session');
351
  }
352
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
 
354
  }
app/code/community/Kancart/MobileApi/controllers/IndexController.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
 
3
  error_reporting(E_ALL ^ E_NOTICE);
4
- define('KANCART_PLUGIN_VERSION', '2.1.1');
5
  define('KANCART_APP_KEY', Mage::getStoreConfig('Kancart/Kancart_group/Kancart_appkey', Mage::app()->getStore()));
6
- define('KANCART_APP_SECRECT', Mage::getStoreConfig('Kancart/Kancart_group/Kancart_appsecret', Mage::app()->getStore()));
7
- define('PRICE_INCLUDE_TAX', (boolean) Mage::getStoreConfig('Kancart/Kancart_general/price_tax', Mage::app()->getStore()));
8
  define('MOBILE_API_ROOT', dirname(dirname(__FILE__)));
9
  include(MOBILE_API_ROOT . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR . 'ErrorHandler.php');
10
  include(MOBILE_API_ROOT . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR . 'Abstract.php');
@@ -40,7 +40,7 @@ class Kancart_MobileApi_IndexController extends Mage_Core_Controller_Front_Actio
40
  try {
41
  if ($this->validate()) {
42
  $this->init();
43
- list($result, $code, $response) = $this->getResponse();
44
  if ($result === true) {
45
  $this->response->setSuccess($response);
46
  } else {
@@ -54,7 +54,7 @@ class Kancart_MobileApi_IndexController extends Mage_Core_Controller_Front_Actio
54
  }
55
  }
56
 
57
- public function init() {
58
  $currentStoreCode = Mage::app()->getStore()->getCode();
59
  $switchTo = (string) $this->getRequest()->getParam('language');
60
  if (isset($switchTo) && !empty($switchTo)) {
@@ -65,16 +65,10 @@ class Kancart_MobileApi_IndexController extends Mage_Core_Controller_Front_Actio
65
  }
66
  }
67
  }
68
-
69
  if (($curency = (string) $this->getRequest()->getParam('currency'))) {
70
  Mage::app()->getStore()->setCurrentCurrencyCode($curency);
71
  }
72
 
73
- if ($this->getRequest()->getParam('discount_amount') || $this->getRequest()->getParam('coupon_free_ship', 0) > 0) {
74
- Mage::app()->getConfig()->setNode('global/sales/quote/totals/discount/class', 'mobileapi/discount');
75
- Mage::app()->getConfig()->setNode('global/sales/order_invoice/totals/discount/class', 'mobileapi/invoice');
76
- }
77
-
78
  $this->compilerPlugin(); //To prevent user backstage collapse after compiled
79
  }
80
 
@@ -90,7 +84,7 @@ class Kancart_MobileApi_IndexController extends Mage_Core_Controller_Front_Actio
90
  date_default_timezone_set($timezone);
91
  }
92
 
93
- $appkey = isset($_REQUEST['app_key']) ? Kancart::helper('CryptoUtil')->Crypto($_REQUEST['app_key'], 'AES-256', KANCART_APP_SECRECT, false) : false;
94
  $_POST['app_key'] = $appkey;
95
  if ($_POST['app_key'] != KANCART_APP_KEY) {
96
  die('KanCart OpenAPI v1.1 is installed on Magento v' . Mage::getVersion() . '. Magento Plugin v' . KANCART_PLUGIN_VERSION);
@@ -114,7 +108,7 @@ class Kancart_MobileApi_IndexController extends Mage_Core_Controller_Front_Actio
114
  return true;
115
  }
116
 
117
- public function getResponse() {
118
  $arr = explode('.', strtolower($_REQUEST['method']));
119
  $map = array('orders' => 'Order', 'reviews' => 'Review');
120
  if ($arr[1] == 'shoppingcart') {
@@ -146,9 +140,15 @@ class Kancart_MobileApi_IndexController extends Mage_Core_Controller_Front_Actio
146
  reset($requestParams);
147
  $tempStr = "";
148
  foreach ($requestParams as $key => $value) {
149
- $tempStr = $tempStr . $key . $value;
 
 
 
 
 
 
150
  }
151
- $tempStr = $tempStr . KANCART_APP_SECRECT;
152
  return strtoupper(md5($tempStr)) === $sign;
153
  }
154
 
@@ -158,12 +158,12 @@ class Kancart_MobileApi_IndexController extends Mage_Core_Controller_Front_Actio
158
  $dest = COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . 'Kancart_MobileApi_Helper_Data.php';
159
  file_exists($fileName) && copy($fileName, $dest);
160
 
161
- $fileName = MOBILE_API_ROOT . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR . 'Discount.php';
162
- $dest = COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . 'Kancart_MobileApi_Model_Discount.php';
163
  file_exists($fileName) && copy($fileName, $dest);
164
 
165
- $fileName = MOBILE_API_ROOT . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR . 'Invoice.php';
166
- $dest = COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . 'Kancart_MobileApi_Model_Invoice.php';
167
  file_exists($fileName) && copy($fileName, $dest);
168
  }
169
  }
@@ -173,7 +173,7 @@ class Kancart_MobileApi_IndexController extends Mage_Core_Controller_Front_Actio
173
  class Kancart {
174
 
175
  public static function getModel($fileName) {
176
- $path = MOBILE_API_ROOT . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR . ucfirst($fileName) . '.php';
177
  if (file_exists($path)) {
178
  include_once($path);
179
  $className = 'Kancart_MobileApi_Model_' . uc_words($fileName);
1
  <?php
2
 
3
  error_reporting(E_ALL ^ E_NOTICE);
4
+ define('KANCART_PLUGIN_VERSION', '2.1.2');
5
  define('KANCART_APP_KEY', Mage::getStoreConfig('Kancart/Kancart_group/Kancart_appkey', Mage::app()->getStore()));
6
+ define('KANCART_APP_SECRET', Mage::getStoreConfig('Kancart/Kancart_group/Kancart_appsecret', Mage::app()->getStore()));
7
+ define('PRICE_INCLUDE_TAX', (boolean) Mage::getStoreConfig('Kancart/general/price_tax', Mage::app()->getStore()));
8
  define('MOBILE_API_ROOT', dirname(dirname(__FILE__)));
9
  include(MOBILE_API_ROOT . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR . 'ErrorHandler.php');
10
  include(MOBILE_API_ROOT . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR . 'Abstract.php');
40
  try {
41
  if ($this->validate()) {
42
  $this->init();
43
+ list($result, $code, $response) = $this->getMobileResponse();
44
  if ($result === true) {
45
  $this->response->setSuccess($response);
46
  } else {
54
  }
55
  }
56
 
57
+ public function init() {
58
  $currentStoreCode = Mage::app()->getStore()->getCode();
59
  $switchTo = (string) $this->getRequest()->getParam('language');
60
  if (isset($switchTo) && !empty($switchTo)) {
65
  }
66
  }
67
  }
 
68
  if (($curency = (string) $this->getRequest()->getParam('currency'))) {
69
  Mage::app()->getStore()->setCurrentCurrencyCode($curency);
70
  }
71
 
 
 
 
 
 
72
  $this->compilerPlugin(); //To prevent user backstage collapse after compiled
73
  }
74
 
84
  date_default_timezone_set($timezone);
85
  }
86
 
87
+ $appkey = isset($_REQUEST['app_key']) ? Kancart::helper('CryptoUtil')->Crypto($_REQUEST['app_key'], 'AES-256', KANCART_APP_SECRET, false) : false;
88
  $_POST['app_key'] = $appkey;
89
  if ($_POST['app_key'] != KANCART_APP_KEY) {
90
  die('KanCart OpenAPI v1.1 is installed on Magento v' . Mage::getVersion() . '. Magento Plugin v' . KANCART_PLUGIN_VERSION);
108
  return true;
109
  }
110
 
111
+ public function getMobileResponse() {
112
  $arr = explode('.', strtolower($_REQUEST['method']));
113
  $map = array('orders' => 'Order', 'reviews' => 'Review');
114
  if ($arr[1] == 'shoppingcart') {
140
  reset($requestParams);
141
  $tempStr = "";
142
  foreach ($requestParams as $key => $value) {
143
+ if (is_array($value)) {
144
+ foreach ($value as $k => $v) {
145
+ $tempStr = $tempStr . $key . '[' . $k . ']' . $v;
146
+ }
147
+ } else {
148
+ $tempStr = $tempStr . $key . $value;
149
+ }
150
  }
151
+ $tempStr = $tempStr . KANCART_APP_SECRET;
152
  return strtoupper(md5($tempStr)) === $sign;
153
  }
154
 
158
  $dest = COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . 'Kancart_MobileApi_Helper_Data.php';
159
  file_exists($fileName) && copy($fileName, $dest);
160
 
161
+ $fileName = MOBILE_API_ROOT . DIRECTORY_SEPARATOR . uc_words('Model_Quote_Total_Discount', DIRECTORY_SEPARATOR) . '.php';
162
+ $dest = COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . 'Kancart_MobileApi_Model_Quote_Total_Discount.php';
163
  file_exists($fileName) && copy($fileName, $dest);
164
 
165
+ $fileName = MOBILE_API_ROOT . DIRECTORY_SEPARATOR . uc_words('Model_Invoice_Total_Discount', DIRECTORY_SEPARATOR) . '.php';
166
+ $dest = COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . 'Kancart_MobileApi_Model_Invoice_Total_Discount.php';
167
  file_exists($fileName) && copy($fileName, $dest);
168
  }
169
  }
173
  class Kancart {
174
 
175
  public static function getModel($fileName) {
176
+ $path = MOBILE_API_ROOT . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR . uc_words($fileName, DIRECTORY_SEPARATOR) . '.php';
177
  if (file_exists($path)) {
178
  include_once($path);
179
  $className = 'Kancart_MobileApi_Model_' . uc_words($fileName);
app/code/community/Kancart/MobileApi/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Kancart_MobileApi>
5
- <version>0.1.0</version>
6
  </Kancart_MobileApi>
7
  </modules>
8
  <frontend>
@@ -27,13 +27,57 @@
27
  <class>Kancart_MobileApi_Helper</class>
28
  </mobileapi>
29
  </helpers>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  </global>
31
  <default>
32
  <Kancart>
33
  <Kancart_group>
34
  <Kancart_appkey>KANCART_APP_KEY</Kancart_appkey>
35
- <Kancart_appsecrect>KANCART_APP_SECRET</Kancart_appsecrect>
36
  </Kancart_group>
 
 
 
 
 
 
37
  </Kancart>
38
  </default>
39
  </config>
2
  <config>
3
  <modules>
4
  <Kancart_MobileApi>
5
+ <version>0.2.0</version>
6
  </Kancart_MobileApi>
7
  </modules>
8
  <frontend>
27
  <class>Kancart_MobileApi_Helper</class>
28
  </mobileapi>
29
  </helpers>
30
+ <events>
31
+ <controller_action_predispatch>
32
+ <observers>
33
+ <mobile_observer>
34
+ <class>Kancart_MobileApi_Helper_Data</class>
35
+ <method>redirectMobile</method>
36
+ </mobile_observer>
37
+ </observers>
38
+ </controller_action_predispatch>
39
+ </events>
40
+ <sales>
41
+ <quote>
42
+ <totals>
43
+ <mobileapi>
44
+ <class>mobileapi/quote_total_discount</class>
45
+ <after>grand_total</after>
46
+ </mobileapi>
47
+ </totals>
48
+ </quote>
49
+ <order_invoice>
50
+ <totals>
51
+ <mobileapi>
52
+ <class>mobileapi/invoice_total_discount</class>
53
+ <after>grand_total</after>
54
+ </mobileapi>
55
+ </totals>
56
+ </order_invoice>
57
+ </sales>
58
+ <fieldsets>
59
+ <sales_convert_quote_address>
60
+ <mobile_discount>
61
+ <to_order>*</to_order>
62
+ </mobile_discount>
63
+ <base_mobile_discount>
64
+ <to_order>*</to_order>
65
+ </base_mobile_discount>
66
+ </sales_convert_quote_address>
67
+ </fieldsets>
68
  </global>
69
  <default>
70
  <Kancart>
71
  <Kancart_group>
72
  <Kancart_appkey>KANCART_APP_KEY</Kancart_appkey>
73
+ <Kancart_appsecret>KANCART_APP_SECRET</Kancart_appsecret>
74
  </Kancart_group>
75
+ <general>
76
+ <price_tax>1</price_tax>
77
+ <thumbnail_image>320</thumbnail_image>
78
+ <main_image>640</main_image>
79
+ <allowspecific>0</allowspecific>
80
+ </general>
81
  </Kancart>
82
  </default>
83
  </config>
app/code/community/Kancart/MobileApi/etc/system.xml CHANGED
@@ -18,14 +18,13 @@
18
  <Kancart_group translate="label">
19
  <label>Authorization</label>
20
  <frontend_type>text</frontend_type>
21
- <sort_order>100</sort_order>
22
  <show_in_default>1</show_in_default>
23
  <show_in_website>1</show_in_website>
24
  <show_in_store>1</show_in_store>
25
  <comment><![CDATA[<a href="http://www.kancart.com" target="_blank">Sign up for an Kancart account to get your key and secret</a>]]>
26
  </comment>
27
  <fields>
28
- <!-- New fields go here -->
29
  <Kancart_appkey translate="label">
30
  <label>Kancart APP Key</label>
31
  <comment>This is the Key Kancart.com assigned to you to identify yourself.</comment>
@@ -46,10 +45,10 @@
46
  </Kancart_appsecret>
47
  </fields>
48
  </Kancart_group>
49
- <Kancart_general translate="label">
50
  <label>Frontend</label>
51
  <frontend_type>text</frontend_type>
52
- <sort_order>100</sort_order>
53
  <show_in_default>1</show_in_default>
54
  <show_in_website>1</show_in_website>
55
  <show_in_store>1</show_in_store>
@@ -59,12 +58,107 @@
59
  <comment>Choose Yes if all price listed on mobile client should include tax.</comment>
60
  <frontend_type>select</frontend_type>
61
  <source_model>adminhtml/system_config_source_yesno</source_model>
62
- <sort_order>50</sort_order>
63
  <show_in_default>1</show_in_default>
64
  <show_in_website>1</show_in_website>
65
- </price_tax>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  </fields>
67
- </Kancart_general>
68
  </groups>
69
  </Kancart>
70
  </sections>
18
  <Kancart_group translate="label">
19
  <label>Authorization</label>
20
  <frontend_type>text</frontend_type>
21
+ <sort_order>10</sort_order>
22
  <show_in_default>1</show_in_default>
23
  <show_in_website>1</show_in_website>
24
  <show_in_store>1</show_in_store>
25
  <comment><![CDATA[<a href="http://www.kancart.com" target="_blank">Sign up for an Kancart account to get your key and secret</a>]]>
26
  </comment>
27
  <fields>
 
28
  <Kancart_appkey translate="label">
29
  <label>Kancart APP Key</label>
30
  <comment>This is the Key Kancart.com assigned to you to identify yourself.</comment>
45
  </Kancart_appsecret>
46
  </fields>
47
  </Kancart_group>
48
+ <general translate="label">
49
  <label>Frontend</label>
50
  <frontend_type>text</frontend_type>
51
+ <sort_order>50</sort_order>
52
  <show_in_default>1</show_in_default>
53
  <show_in_website>1</show_in_website>
54
  <show_in_store>1</show_in_store>
58
  <comment>Choose Yes if all price listed on mobile client should include tax.</comment>
59
  <frontend_type>select</frontend_type>
60
  <source_model>adminhtml/system_config_source_yesno</source_model>
61
+ <sort_order>5</sort_order>
62
  <show_in_default>1</show_in_default>
63
  <show_in_website>1</show_in_website>
64
+ <show_in_store>1</show_in_store>
65
+ </price_tax>
66
+ <image_frame translate="label">
67
+ <label>Image Keep Frame</label>
68
+ <comment>Choose Yes keep the original image proportions, otherwise stretch the image.</comment>
69
+ <frontend_type>select</frontend_type>
70
+ <source_model>adminhtml/system_config_source_yesno</source_model>
71
+ <sort_order>10</sort_order>
72
+ <show_in_default>1</show_in_default>
73
+ <show_in_website>1</show_in_website>
74
+ <show_in_store>1</show_in_store>
75
+ </image_frame>
76
+ <thumbnail_image translate="label">
77
+ <label>Thumbnail Image Size</label>
78
+ <comment>Set the product list thumbnail image size, example 320 x 320 or 320.</comment>
79
+ <frontend_type>text</frontend_type>
80
+ <sort_order>12</sort_order>
81
+ <show_in_default>1</show_in_default>
82
+ <show_in_website>1</show_in_website>
83
+ <show_in_store>1</show_in_store>
84
+ </thumbnail_image>
85
+ <main_image translate="label">
86
+ <label>Main Image Size</label>
87
+ <comment>Set the Main image size, example 640 x 640 or 640.</comment>
88
+ <frontend_type>text</frontend_type>
89
+ <sort_order>14</sort_order>
90
+ <show_in_default>1</show_in_default>
91
+ <show_in_website>1</show_in_website>
92
+ <show_in_store>1</show_in_store>
93
+ </main_image>
94
+ <allowspecific translate="label">
95
+ <label>Display Store Views</label>
96
+ <comment>Choose store views display on mobile site.</comment>
97
+ <frontend_type>select</frontend_type>
98
+ <source_model>mobileapi/system_config_source_allspecificstore</source_model>
99
+ <sort_order>20</sort_order>
100
+ <show_in_default>1</show_in_default>
101
+ <show_in_website>1</show_in_website>
102
+ </allowspecific>
103
+ <stores translate="label">
104
+ <label>Available stores From</label>
105
+ <frontend_type>multiselect</frontend_type>
106
+ <source_model>mobileapi/system_config_source_store</source_model>
107
+ <sort_order>25</sort_order>
108
+ <show_in_default>1</show_in_default>
109
+ <show_in_website>1</show_in_website>
110
+ <depends>
111
+ <allowspecific>1</allowspecific>
112
+ </depends>
113
+ </stores>
114
+ <paypal_standard translate="label">
115
+ <label>PayPal Payments Standard</label>
116
+ <comment>If you just want to mobile site to use paypal standard you can enable this.</comment>
117
+ <frontend_type>select</frontend_type>
118
+ <source_model>adminhtml/system_config_source_yesno</source_model>
119
+ <sort_order>35</sort_order>
120
+ <show_in_default>1</show_in_default>
121
+ <show_in_website>1</show_in_website>
122
+ <show_in_store>1</show_in_store>
123
+ </paypal_standard>
124
+ <paypal_express translate="label">
125
+ <label>PayPal Express Checkout</label>
126
+ <comment>If you just want to mobile site to use paypal express checkout you can enable this.</comment>
127
+ <frontend_type>select</frontend_type>
128
+ <source_model>adminhtml/system_config_source_yesno</source_model>
129
+ <sort_order>60</sort_order>
130
+ <show_in_default>1</show_in_default>
131
+ <show_in_website>1</show_in_website>
132
+ <show_in_store>1</show_in_store>
133
+ </paypal_express>
134
+ </fields>
135
+ </general>
136
+ <redirect translate="label">
137
+ <label>Redirect Options</label>
138
+ <frontend_type>text</frontend_type>
139
+ <comment>Here you can configure your web site redirect options.</comment>
140
+ <sort_order>80</sort_order>
141
+ <show_in_default>1</show_in_default>
142
+ <show_in_website>1</show_in_website>
143
+ <fields>
144
+ <active translate="label">
145
+ <label>Enabled</label>
146
+ <frontend_type>select</frontend_type>
147
+ <source_model>adminhtml/system_config_source_yesno</source_model>
148
+ <sort_order>10</sort_order>
149
+ <show_in_default>1</show_in_default>
150
+ <show_in_website>1</show_in_website>
151
+ </active>
152
+ <url translate="label">
153
+ <label>Mobile Url</label>
154
+ <comment>Please configure your mobile site url that registered in kancart.</comment>
155
+ <frontend_type>text</frontend_type>
156
+ <sort_order>20</sort_order>
157
+ <show_in_default>1</show_in_default>
158
+ <show_in_website>1</show_in_website>
159
+ </url>
160
  </fields>
161
+ </redirect>
162
  </groups>
163
  </Kancart>
164
  </sections>
app/etc/modules/Kancart_MobileApi.xml CHANGED
@@ -1,9 +1,9 @@
1
  <?xml version="1.0"?>
2
  <config>
3
  <modules>
4
- <Kancart_MobileApi> <!-- 注意大小写 -->
5
- <active>true</active> <!-- 插件默认激活的 -->
6
- <codePool>community</codePool> <!--插件文件路径是app\code\local -->
7
- </Kancart_MobileApi> <!--注意大小写 -->
8
  </modules>
9
  </config>
1
  <?xml version="1.0"?>
2
  <config>
3
  <modules>
4
+ <Kancart_MobileApi>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Kancart_MobileApi>
8
  </modules>
9
  </config>
package.xml CHANGED
@@ -1,24 +1,22 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>KANCART_MobileAPI</name>
4
- <version>2.1.1</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Kancart Mobile API Service</summary>
10
- <description>1)Fix some bug about guest checkout.&#xD;
11
- 2)Fix some text were not well localized issue.&#xD;
12
- 3)Add switch to plugin configure page to control if the price on mobile site should includes tax.&#xD;
13
  </description>
14
  <notes>Kancart supports guest checkout now;&#xD;
15
  We developed a promotion mechanism, you can add promotion rules for mobile user;&#xD;
16
  More details of improvements can be found on www.kancart.com&#xD;
17
  </notes>
18
  <authors><author><name>Kancart.com</name><user>Kancarter</user><email>support@kancart.com</email></author></authors>
19
- <date>2013-12-20</date>
20
- <time>09:42:35</time>
21
- <contents><target name="magecommunity"><dir name="Kancart"><dir name="MobileApi"><dir name="Helper"><file name="CryptoUtil.php" hash="2db9a53cbaed6e8bc5f2dae4ed2ec334"/><file name="DES.php" hash="f038974cc0cf453373a52e6d4770ffdb"/><file name="Data.php" hash="ce8f291eec3277eb01b1f00225e5cbd8"/><file name="Rijndael.php" hash="be7c805f21086f7c26f785d0c0e73afd"/></dir><dir name="Model"><file name="Abstract.php" hash="ece61ca6a4697510071a14eb936a8853"/><file name="Cart.php" hash="9fc7f8a3c4f28703b565fee710250b68"/><file name="Category.php" hash="4993c1f1b5c03dccd5b50a8159f4880a"/><file name="Checkout.php" hash="5d7c607c7c20993d9bde207537dec1d1"/><file name="Discount.php" hash="b3f29b73768931a041703a0c7df3db53"/><file name="ErrorHandler.php" hash="6d62e02c4ce592a41b242e781fe2c28a"/><file name="Invoice.php" hash="cf16e5e8429b438d6e929d36e205f60b"/><file name="Item.php" hash="ec9dc4d48dbce01fb2a8e8e4bbe20d3a"/><file name="Items.php" hash="1468b2fa60afe0476b0d10b9b12be182"/><file name="Order.php" hash="2f5fc3ed2959ffcdabe331ec9b364d04"/><file name="PayPalEC.php" hash="936af8c18938954caf8a196f48b9fc5a"/><file name="PayPalWPS.php" hash="50e29c8a8f405cff32267de91adc1e5a"/><file name="Payment.php" hash="337b55ba40a0dbf3214c1b9461cce882"/><file name="Result.php" hash="64759b5dcb022186f12c0cb043877af0"/><file name="Review.php" hash="cd3b705fb6894c36824094f562acc869"/><file name="Store.php" hash="2115e661f8a2c702383a89725aa2b2ed"/><file name="User.php" hash="05200f849e09346bf662ac1157217406"/></dir><dir name="controllers"><file name="IndexController.php" hash="0107661bb0160e45010a2106ae00d17c"/></dir><dir name="etc"><file name="adminhtml.xml" hash="3364317d05e33ac33f067aed7a9f6a58"/><file name="config.xml" hash="2f9d3466e651ac2b2b1f387b1a2356ad"/><file name="system.xml" hash="b66fd59298227a3f38e6ea9f1e5f1138"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Kancart_MobileApi.xml" hash="17ceeb976f959fc6365da95b532dd616"/></dir></target></contents>
22
  <compatible/>
23
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
24
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>KANCART_MobileAPI</name>
4
+ <version>2.1.2</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Kancart Mobile API Service</summary>
10
+ <description>support facebook login.&#xD;
 
 
11
  </description>
12
  <notes>Kancart supports guest checkout now;&#xD;
13
  We developed a promotion mechanism, you can add promotion rules for mobile user;&#xD;
14
  More details of improvements can be found on www.kancart.com&#xD;
15
  </notes>
16
  <authors><author><name>Kancart.com</name><user>Kancarter</user><email>support@kancart.com</email></author></authors>
17
+ <date>2014-02-19</date>
18
+ <time>09:34:13</time>
19
+ <contents><target name="magecommunity"><dir name="Kancart"><dir name="MobileApi"><dir name="Helper"><file name="CryptoUtil.php" hash="2db9a53cbaed6e8bc5f2dae4ed2ec334"/><file name="DES.php" hash="f038974cc0cf453373a52e6d4770ffdb"/><file name="Data.php" hash="1b254135bbfbcfdfd9f7ff826c1dd196"/><file name="Rijndael.php" hash="be7c805f21086f7c26f785d0c0e73afd"/></dir><dir name="Model"><file name="Abstract.php" hash="d459ecc3f3e6c6bda1a3deb988f94bc3"/><file name="Cart.php" hash="9fc7f8a3c4f28703b565fee710250b68"/><file name="Category.php" hash="f58947db89b3244411da36052836029a"/><file name="Checkout.php" hash="7f7bffd91eeff343f7aab04a97d7467d"/><file name="ErrorHandler.php" hash="6d62e02c4ce592a41b242e781fe2c28a"/><dir name="Invoice"><dir name="Total"><file name="Discount.php" hash="d6f8d914e6447a8b4af54aea212c9551"/></dir></dir><file name="Item.php" hash="d34bfc4b6ed06f9a848799f522f39d2a"/><file name="Items.php" hash="48271a42517906d3a33bc6339c97b7dd"/><file name="Order.php" hash="ab793baf5fd85110730e90c7363f0e9a"/><file name="PayPalEC.php" hash="936af8c18938954caf8a196f48b9fc5a"/><file name="PayPalWPS.php" hash="0e87844cf4bee5db1e9c885de21372ba"/><file name="Payment.php" hash="337b55ba40a0dbf3214c1b9461cce882"/><dir name="Quote"><dir name="Total"><file name="Discount.php" hash="790326803517c509a752aae54622f469"/></dir></dir><file name="Result.php" hash="64759b5dcb022186f12c0cb043877af0"/><file name="Review.php" hash="cd3b705fb6894c36824094f562acc869"/><file name="Store.php" hash="ec9f6b9a4eb6b4c7d6c3b5beb82c40cf"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Allspecificstore.php" hash="3b3b39fd653f6c6600762ec9ca373e03"/><file name="Store.php" hash="31bde96aaa434639e90d760e1b847907"/></dir></dir></dir><file name="User.php" hash="9c41438cc779e83b57b17d28e6a90e77"/></dir><dir name="controllers"><file name="IndexController.php" hash="7c31859c673d65b90154112d9397f19f"/></dir><dir name="etc"><file name="adminhtml.xml" hash="3364317d05e33ac33f067aed7a9f6a58"/><file name="config.xml" hash="6d0cca0578ec73b497fb91a75031537d"/><file name="system.xml" hash="2495a7d0b94595163993791aeddf0ea7"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Kancart_MobileApi.xml" hash="efdda31d392fe3c30f461bb2a86e8b14"/></dir></target></contents>
20
  <compatible/>
21
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
22
  </package>