KANCART_MobileAPI - Version 2.0.9

Version Notes

Fix a bug blocks payment on 1.8.0.0

Download this release

Release Info

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


Code changes from version 2.0.8 to 2.0.9

app/code/community/Kancart/MobileApi/Model/Cart.php CHANGED
@@ -45,6 +45,7 @@ class Kancart_MobileApi_Model_Cart extends Kancart_MobileApi_Model_Abstract {
45
  $cartInfo['cart_items_count'] = Mage::helper('checkout/cart')->getSummaryCount();
46
  $cartInfo['price_infos'] = $this->getPriceInfos();
47
  $cartInfo['payment_methods'] = $this->getPaymentInfo();
 
48
 
49
  return array(true, '0x0000', $cartInfo);
50
  }
45
  $cartInfo['cart_items_count'] = Mage::helper('checkout/cart')->getSummaryCount();
46
  $cartInfo['price_infos'] = $this->getPriceInfos();
47
  $cartInfo['payment_methods'] = $this->getPaymentInfo();
48
+ $cartInfo['allow_guest_checkout'] = Mage::helper('checkout')->isAllowedGuestCheckout($cart->getQuote());
49
 
50
  return array(true, '0x0000', $cartInfo);
51
  }
app/code/community/Kancart/MobileApi/Model/Checkout.php CHANGED
@@ -35,7 +35,7 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
35
 
36
  if ($address) { // update or add address
37
  $address = json_decode(htmlspecialchars_decode($address, ENT_COMPAT), true);
38
- $_POST = $address;
39
  $_POST['address_book_id'] = $address_id;
40
  list($result, $code, $address_id) = Kancart::getModel('User')->kancart_user_address_update();
41
  if ($result === false) {
@@ -53,6 +53,10 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
53
  $this->getOnepage()->saveShipping($address, $address_id);
54
  }
55
 
 
 
 
 
56
  return $this->shoppingCartCheckoutDetail();
57
  }
58
 
@@ -60,7 +64,8 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
60
  if ($this->getRequest()->getParam('payment_method_id') == 'paypalwpp') {
61
  Kancart::getModel('PayPalEC')->kancart_shoppingcart_paypalec_detail();
62
  } else {
63
- if (!$this->isLoggedIn()) {
 
64
  return array(false, '0x0002', 'You need login first.');
65
  }
66
 
@@ -82,7 +87,7 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
82
  return array(true, '0x0000', $checkoutDetailArr);
83
  }
84
  }
85
- $this->getRequest()->setParam('discount_amount', 20);
86
  Mage::getSingleton('checkout/session')->setCartWasUpdated(false);
87
  $this->getOnepage()->initCheckout();
88
 
@@ -292,10 +297,6 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
292
 
293
  public function kancart_shoppingcart_checkout() {
294
  $payment_id = $this->getRequest()->getParam('payment_method_id', null);
295
- if (!$this->isLoggedIn()) {
296
- return array(false, '0x0002', 'You need login first.');
297
- }
298
-
299
  try {
300
  if ($this->getQuote()->getGrandTotal() == 0) {
301
  $payment_id = 'free';
@@ -330,7 +331,7 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
330
  return KANCART_PAYMENT_CODE;
331
  } else {
332
  $priorsPayments = array(
333
- 'bankpayment' => 0,
334
  'cashondelivery' => 1,
335
  'checkmo' => 2,
336
  'purchaseorder' => 3
35
 
36
  if ($address) { // update or add address
37
  $address = json_decode(htmlspecialchars_decode($address, ENT_COMPAT), true);
38
+ $_POST = array_merge($_POST, $address);
39
  $_POST['address_book_id'] = $address_id;
40
  list($result, $code, $address_id) = Kancart::getModel('User')->kancart_user_address_update();
41
  if ($result === false) {
53
  $this->getOnepage()->saveShipping($address, $address_id);
54
  }
55
 
56
+ if (!$this->isLoggedIn()) {
57
+ $this->getOnepage()->saveBilling($address, $address_id);
58
+ }
59
+
60
  return $this->shoppingCartCheckoutDetail();
61
  }
62
 
64
  if ($this->getRequest()->getParam('payment_method_id') == 'paypalwpp') {
65
  Kancart::getModel('PayPalEC')->kancart_shoppingcart_paypalec_detail();
66
  } else {
67
+ if (!$this->isLoggedIn() || (isset($_POST['guestcheckout']) && $_POST['guestcheckout'] > 0 &&
68
+ !Mage::helper('checkout')->isAllowedGuestCheckout($this->getOnepage()->getQuote()))) {
69
  return array(false, '0x0002', 'You need login first.');
70
  }
71
 
87
  return array(true, '0x0000', $checkoutDetailArr);
88
  }
89
  }
90
+
91
  Mage::getSingleton('checkout/session')->setCartWasUpdated(false);
92
  $this->getOnepage()->initCheckout();
93
 
297
 
298
  public function kancart_shoppingcart_checkout() {
299
  $payment_id = $this->getRequest()->getParam('payment_method_id', null);
 
 
 
 
300
  try {
301
  if ($this->getQuote()->getGrandTotal() == 0) {
302
  $payment_id = 'free';
331
  return KANCART_PAYMENT_CODE;
332
  } else {
333
  $priorsPayments = array(
334
+ 'banktransfer' => 0,
335
  'cashondelivery' => 1,
336
  'checkmo' => 2,
337
  'purchaseorder' => 3
app/code/community/Kancart/MobileApi/Model/Discount.php CHANGED
@@ -33,8 +33,11 @@ class Kancart_MobileApi_Model_Discount extends Mage_SalesRule_Model_Quote_Discou
33
  $address->setBaseSubtotalWithDiscount(0);
34
 
35
  parent::collect($address);
 
 
 
36
 
37
- $totalDiscountAmount = $this->getRequest()->getParam('discount_amount', 0);
38
  if ($totalDiscountAmount && !is_numeric($totalDiscountAmount)) {
39
  $totalDiscountAmount = $address->getBaseSubtotal() * floatval($totalDiscountAmount) / 100;
40
  }
@@ -58,8 +61,8 @@ class Kancart_MobileApi_Model_Discount extends Mage_SalesRule_Model_Quote_Discou
58
  $address->setBaseDiscountAmount($baseTotalDiscountAmount);
59
  $address->setBaseSubtotalWithDiscount($baseSubtotalWithDiscount);
60
 
61
- $address->setGrandTotal($address->getGrandTotal() - $address->getDiscountAmount());
62
- $address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getBaseDiscountAmount());
63
  return $this;
64
  }
65
 
@@ -73,3 +76,4 @@ class Kancart_MobileApi_Model_Discount extends Mage_SalesRule_Model_Quote_Discou
73
  }
74
 
75
  }
 
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
  }
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
 
76
  }
77
 
78
  }
79
+
app/code/community/Kancart/MobileApi/Model/Invoice.php ADDED
@@ -0,0 +1,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_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
+
app/code/community/Kancart/MobileApi/Model/Items.php CHANGED
@@ -41,7 +41,7 @@ class Kancart_MobileApi_Model_Items extends Kancart_MobileApi_Model_Abstract {
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'])) {
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'])) {
@@ -72,13 +72,17 @@ class Kancart_MobileApi_Model_Items extends Kancart_MobileApi_Model_Abstract {
72
  ->setCurPage($pageNo)
73
  ->setPageSize($pageSize);
74
 
75
- if ($ids) {
76
  is_string($ids) && $ids = explode(',', $ids);
77
- $collection->addIdFilter($ids);
 
 
 
 
 
78
  }
79
 
80
  $collection->load();
81
- $size = $collection->getSize();
82
  $productList = $collection->getItems();
83
 
84
  $items = array();
@@ -92,14 +96,16 @@ class Kancart_MobileApi_Model_Items extends Kancart_MobileApi_Model_Abstract {
92
  $itemObject->clear();
93
  }
94
  }
 
 
95
  $products = array();
96
  $products['items'] = $items;
97
- $products['total_results'] = $size;
98
  return $products;
99
  }
100
 
101
  private function getSpecialProducts($pageNo, $pageSize, $order, $direction) {
102
- return $this->getAllProducts($pageNo, $pageSize, $order, $direction, true);
103
  }
104
 
105
  private function getAllProducts($pageNo, $pageSize, $order, $direction, $specials = false) {
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'])) {
72
  ->setCurPage($pageNo)
73
  ->setPageSize($pageSize);
74
 
75
+ if (strlen($ids)) {
76
  is_string($ids) && $ids = explode(',', $ids);
77
+ $count = count($ids);
78
+ $start = max($pageNo - 1, 0) * $pageSize;
79
+ $itemIds = array_splice($ids, $start, $pageSize);
80
+ $collection->addIdFilter($itemIds);
81
+ } else {
82
+ return array('items' => array(), 'total_results' => 0);
83
  }
84
 
85
  $collection->load();
 
86
  $productList = $collection->getItems();
87
 
88
  $items = array();
96
  $itemObject->clear();
97
  }
98
  }
99
+ array_multisort($items, SORT_ASC, $itemIds);
100
+
101
  $products = array();
102
  $products['items'] = $items;
103
+ $products['total_results'] = $count;
104
  return $products;
105
  }
106
 
107
  private function getSpecialProducts($pageNo, $pageSize, $order, $direction) {
108
+ return $this->getAllProducts($pageNo, $pageSize, $order, $direction, true);
109
  }
110
 
111
  private function getAllProducts($pageNo, $pageSize, $order, $direction, $specials = false) {
app/code/community/Kancart/MobileApi/Model/Order.php CHANGED
@@ -370,6 +370,30 @@ class Kancart_MobileApi_Model_Order extends Kancart_MobileApi_Model_Abstract {
370
  public function getPaymentOrderInfo($order, $orderId = false, $tx = '') {
371
  $orderItem = array();
372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
  if ($order) {
374
  $orderItem['display_id'] = $orderId;
375
  $orderItem['shipping_address'] = $this->getPaymentAddress($order);
@@ -400,21 +424,7 @@ class Kancart_MobileApi_Model_Order extends Kancart_MobileApi_Model_Abstract {
400
  $address = $order->getShippingAddress();
401
  }
402
 
403
- if (!$address) {
404
- return array();
405
- }
406
-
407
- $addr = array(
408
- 'city' => $address->getCity(),
409
- 'country_id' => $address->getCountryId(),
410
- 'zone_id' => $address->getRegionId(), //1
411
- 'zone_name' => '', //2
412
- 'state' => $address->getRegion(), //3
413
- 'address1' => $address->getStreet(1),
414
- 'address2' => $address->getStreet(2),
415
- );
416
-
417
- return $addr;
418
  }
419
 
420
  public function getPaymentPriceInfos($order) {
@@ -449,6 +459,7 @@ class Kancart_MobileApi_Model_Order extends Kancart_MobileApi_Model_Abstract {
449
  foreach ($products as $product) {
450
  $items[] = array(
451
  'order_item_key' => $product->getId(),
 
452
  'item_title' => $product->getName(),
453
  'category_name' => '',
454
  'home_currency_price' => $product->getPrice(),
370
  public function getPaymentOrderInfo($order, $orderId = false, $tx = '') {
371
  $orderItem = array();
372
 
373
+ if (!$this->isLoggedIn() && $order && $order->getId()) { //for guest checkout
374
+ $session = Mage::getSingleton('customer/session');
375
+ $orderIds = $session->getOrderIds();
376
+ $new = true;
377
+ if (!$orderIds) {
378
+ $orderIds = array($order->getId());
379
+ } elseif (!in_array($order->getId(), $orderIds)) {
380
+ $orderIds[] = $order->getId();
381
+ } else {
382
+ $new = false;
383
+ }
384
+
385
+ if ($new) {
386
+ $session->setOrderIds($orderIds);
387
+
388
+ if ($order->getIsVirtual()) {
389
+ $address = $order->getBillingAddress();
390
+ } else {
391
+ $address = $order->getShippingAddress();
392
+ }
393
+ $session->setGuestAddress($address->getData());
394
+ }
395
+ }
396
+
397
  if ($order) {
398
  $orderItem['display_id'] = $orderId;
399
  $orderItem['shipping_address'] = $this->getPaymentAddress($order);
424
  $address = $order->getShippingAddress();
425
  }
426
 
427
+ return $this->toAddressData($address);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428
  }
429
 
430
  public function getPaymentPriceInfos($order) {
459
  foreach ($products as $product) {
460
  $items[] = array(
461
  'order_item_key' => $product->getId(),
462
+ 'item_id' => $product->getProductId(),
463
  'item_title' => $product->getName(),
464
  'category_name' => '',
465
  'home_currency_price' => $product->getPrice(),
app/code/community/Kancart/MobileApi/Model/PayPalWPS.php CHANGED
@@ -56,24 +56,20 @@ class Kancart_MobileApi_Model_PayPalWPS extends Kancart_MobileApi_Model_Abstract
56
  }
57
 
58
  public function kancart_shoppingcart_paypalwps_done() {
59
- if (!$this->isLoggedIn()) {
60
- return array(false, '0x0002', 'You need login first.');
61
- } else {
62
- try {
63
- $session = Mage::getSingleton('checkout/session');
64
- $session->setQuoteId($session->getPaypalStandardQuoteId(true));
65
- $session->getQuote()->setIsActive(false)->save();
66
-
67
- $order = $this->_initOrder(Mage::getSingleton('checkout/type_onepage')->getLastOrderID());
68
- $info = Kancart::getModel('Order')->getPaymentOrderInfo($order, $order->getIncrementId(), $order->getPayment()->getLastTransId());
69
- $session->clear();
70
- $cart = Mage::getSingleton('checkout/cart');
71
- $cart->getQuote()->setItemsCount(0);
72
- } catch (Mage_Core_Exception $e) {
73
- return array(false, '0x9000', $e->getMessage());
74
- } catch (Exception $e) {
75
- return array(false, '0x9000', $e->getMessage());
76
- }
77
  }
78
  return array(true, '0x0000', $info);
79
  }
@@ -88,6 +84,14 @@ class Kancart_MobileApi_Model_PayPalWPS extends Kancart_MobileApi_Model_Abstract
88
  ->setActionName('index')
89
  ->setPost('agreement', Mage::helper('checkout')->getRequiredAgreementIds()); //skip agreements
90
 
 
 
 
 
 
 
 
 
91
  try {
92
  $response = Mage::app()->getResponse();
93
  $fileName = Mage::getModuleDir('controllers', 'Mage_Checkout') . DIRECTORY_SEPARATOR . 'OnepageController.php';
@@ -101,6 +105,7 @@ class Kancart_MobileApi_Model_PayPalWPS extends Kancart_MobileApi_Model_Abstract
101
  $newOrderIncrementId = $this->getOnepage()->getCheckout()->getLastRealOrderId();
102
  $newOrder = Mage::getModel('sales/order');
103
  $newOrder->loadByIncrementId($newOrderIncrementId);
 
104
  $newOrder->addStatusToHistory(false, $comment, false);
105
  $newOrder->save();
106
 
@@ -109,111 +114,11 @@ class Kancart_MobileApi_Model_PayPalWPS extends Kancart_MobileApi_Model_Abstract
109
  return array(false, $result['error_messages']);
110
  }
111
  } else {
112
- return $this->saveOrder($payment, $comment);
113
  }
114
  } catch (Exception $e) {
115
  return array(false, $e->getMessage());
116
  }
117
  }
118
 
119
- public function saveOrder($payment, $comment = 'from mobile') {
120
- $result = FALSE;
121
- $mesg = NULL;
122
- try {
123
- if (defined('NEED_AGREE_AGREEMENT') && NEED_AGREE_AGREEMENT == TRUE) {
124
- if ($requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds()) {
125
- $postedAgreements = array_keys($this->getRequest()->getPost('agreement', array()));
126
- if ($diff = array_diff($requiredAgreements, $postedAgreements)) {
127
- $result['error_messages'] = $this->__('Please agree to all the terms and conditions before placing the order.');
128
- return array(false, $result['error_messages']);
129
- }
130
- }
131
- }
132
- $this->getOnepage()->getQuote()->getPayment()->importData($payment);
133
- $this->getOnepage()->saveOrder();
134
-
135
- $storeId = Mage::app()->getStore()->getId();
136
- $paymentHelper = Mage::helper("payment");
137
- $zeroSubTotalPaymentAction = $paymentHelper->getZeroSubTotalPaymentAutomaticInvoice($storeId);
138
- if ($paymentHelper->isZeroSubTotal($storeId)
139
- && $this->_getOrder()->getGrandTotal() == 0
140
- && $zeroSubTotalPaymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE
141
- && $paymentHelper->getZeroSubTotalOrderStatus($storeId) == 'pending') {
142
- $invoice = $this->_initInvoice();
143
- $invoice->getOrder()->setIsInProcess(true);
144
- $invoice->save();
145
- }
146
-
147
- $newOrderIncrementId = $this->getOnepage()->getCheckout()->getLastRealOrderId();
148
- $newOrder = Mage::getModel('sales/order');
149
- $newOrder->loadByIncrementId($newOrderIncrementId);
150
- $newOrder->addStatusToHistory(false, $comment, false);
151
- $newOrder->save();
152
-
153
- $result = TRUE;
154
- $mesg = $newOrder;
155
- } catch (Mage_Payment_Model_Info_Exception $e) {
156
- $mesg = $e->getMessage();
157
- } catch (Mage_Core_Exception $e) {
158
- Mage::logException($e);
159
- Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
160
- if ($gotoSection = $this->getOnepage()->getCheckout()->getGotoSection()) {
161
- $this->getOnepage()->getCheckout()->setGotoSection(null);
162
- }
163
-
164
- if ($updateSection = $this->getOnepage()->getCheckout()->getUpdateSection()) {
165
- $this->getOnepage()->getCheckout()->setUpdateSection(null);
166
- }
167
- $mesg = $e->getMessage();
168
- } catch (Exception $e) {
169
- Mage::logException($e);
170
- Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
171
- $mesg = $e->getMessage();
172
- }
173
- $this->getOnepage()->getQuote()->save();
174
- return array($result, $mesg);
175
- }
176
-
177
- protected function _initOrder($orderIncrementId) {
178
- $order = Mage::getModel('sales/order');
179
- $order->loadByIncrementId($orderIncrementId);
180
- if (!$order->getId()) {
181
- $this->_fault('Invalid OrderID (Order)');
182
- }
183
- return $order;
184
- }
185
-
186
- /**
187
- * Get Order by quoteId
188
- *
189
- * @return Mage_Sales_Model_Order
190
- */
191
- protected function _getOrder() {
192
- if (is_null($this->_order)) {
193
- $this->_order = Mage::getModel('sales/order')->load($this->getOnepage()->getQuote()->getId(), 'quote_id');
194
- if (!$this->_order->getId()) {
195
- throw new Mage_Payment_Model_Info_Exception(Mage::helper('core')->__("Can not create invoice. Order was not found."));
196
- }
197
- }
198
- return $this->_order;
199
- }
200
-
201
- /**
202
- * Create invoice
203
- *
204
- * @return Mage_Sales_Model_Order_Invoice
205
- */
206
- protected function _initInvoice() {
207
- $items = array();
208
- foreach ($this->getOnepage()->getQuote()->getAllItems() as $item) {
209
- $items[$item->getId()] = $item->getQty();
210
- }
211
- /* @var $invoice Mage_Sales_Model_Service_Order */
212
- $invoice = Mage::getModel('sales/service_order', $this->_getOrder())->prepareInvoice($items);
213
- $invoice->setEmailSent(true);
214
-
215
- Mage::register('current_invoice', $invoice);
216
- return $invoice;
217
- }
218
-
219
  }
56
  }
57
 
58
  public function kancart_shoppingcart_paypalwps_done() {
59
+ try {
60
+ $session = Mage::getSingleton('checkout/session');
61
+ $session->setQuoteId($session->getPaypalStandardQuoteId(true));
62
+ $session->getQuote()->setIsActive(false)->save();
63
+
64
+ $order = Mage::getModel('sales/order')->loadByIncrementId($this->getOnepage()->getCheckout()->getLastRealOrderId());
65
+ $info = Kancart::getModel('Order')->getPaymentOrderInfo($order, $order->getIncrementId(), $order->getPayment()->getLastTransId());
66
+ $session->clear();
67
+ $cart = Mage::getSingleton('checkout/cart');
68
+ $cart->getQuote()->setItemsCount(0);
69
+ } catch (Mage_Core_Exception $e) {
70
+ return array(false, '0x9000', $e->getMessage());
71
+ } catch (Exception $e) {
72
+ return array(false, '0x9000', $e->getMessage());
 
 
 
 
73
  }
74
  return array(true, '0x0000', $info);
75
  }
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);
89
+ } else {
90
+ $formKey = time();
91
+ Mage::getSingleton('core/session')->setFormKey($formKey);
92
+ $this->getRequest()->setParam('form_key', $formKey);
93
+ }
94
+
95
  try {
96
  $response = Mage::app()->getResponse();
97
  $fileName = Mage::getModuleDir('controllers', 'Mage_Checkout') . DIRECTORY_SEPARATOR . 'OnepageController.php';
105
  $newOrderIncrementId = $this->getOnepage()->getCheckout()->getLastRealOrderId();
106
  $newOrder = Mage::getModel('sales/order');
107
  $newOrder->loadByIncrementId($newOrderIncrementId);
108
+ $newOrder->setQuote($this->getOnepage()->getQuote());
109
  $newOrder->addStatusToHistory(false, $comment, false);
110
  $newOrder->save();
111
 
114
  return array(false, $result['error_messages']);
115
  }
116
  } else {
117
+ return array(false, 'File ' . $fileName . ' is not exist and Can\'t include OnepageController.php');
118
  }
119
  } catch (Exception $e) {
120
  return array(false, $e->getMessage());
121
  }
122
  }
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  }
app/code/community/Kancart/MobileApi/Model/Store.php CHANGED
@@ -276,7 +276,7 @@ class Kancart_MobileApi_Model_Store extends Kancart_MobileApi_Model_Abstract {
276
  'cart_version' => Mage::getVersion(),
277
  'plugin_version' => KANCART_PLUGIN_VERSION,
278
  'support_kancart_payment' => true,
279
- // 'support_promotion' => true,
280
  'login_by_mail' => true
281
  );
282
  }
276
  'cart_version' => Mage::getVersion(),
277
  'plugin_version' => KANCART_PLUGIN_VERSION,
278
  'support_kancart_payment' => true,
279
+ 'support_promotion' => true,
280
  'login_by_mail' => true
281
  );
282
  }
app/code/community/Kancart/MobileApi/Model/User.php CHANGED
@@ -53,6 +53,16 @@ class Kancart_MobileApi_Model_User extends Kancart_MobileApi_Model_Abstract {
53
  $session->setCustomerAsLoggedIn($customer);
54
  $customer->sendNewAccountEmail('registered', '', Mage::app()->getStore()->getId());
55
  }
 
 
 
 
 
 
 
 
 
 
56
  return array(true, '0x0000', array());
57
  } else {
58
  return array(false, '0x1000', $errors);
@@ -118,6 +128,18 @@ class Kancart_MobileApi_Model_User extends Kancart_MobileApi_Model_Abstract {
118
  if ($session->getCustomer()->getIsJustConfirmed()) {
119
  $session->getCustomer()->sendNewAccountEmail('confirmed');
120
  }
 
 
 
 
 
 
 
 
 
 
 
 
121
  $customerGroupId = $session->getCustomer()->getGroupId();
122
  $cachekey = $defaultGroupId == $customerGroupId ? NULL : 'group_id_' . $customerGroupId;
123
  return array(true, '0x0000', array('sessionkey' => md5(time()), 'cachekey' => $cachekey));
53
  $session->setCustomerAsLoggedIn($customer);
54
  $customer->sendNewAccountEmail('registered', '', Mage::app()->getStore()->getId());
55
  }
56
+
57
+ $addressData = $session->getGuestAddress();
58
+ if ($addressData && $customer->getId()) {
59
+ $address = Mage::getModel('customer/address');
60
+ $address->setData($addressData);
61
+ $address->setCustomerId($customer->getId());
62
+ $address->save();
63
+ $session->unsGuestAddress();
64
+ }
65
+
66
  return array(true, '0x0000', array());
67
  } else {
68
  return array(false, '0x1000', $errors);
128
  if ($session->getCustomer()->getIsJustConfirmed()) {
129
  $session->getCustomer()->sendNewAccountEmail('confirmed');
130
  }
131
+
132
+ if (($orderIds = $session->getOrderIds())) {
133
+ $order = Mage::getModel('sales/order');
134
+ $order->setCustomerId($session->getCustomer()->getId());
135
+ $resource = $order->getResource();
136
+ foreach ($orderIds as $orderId) {
137
+ $order->setId($orderId);
138
+ $resource->saveAttribute($order, 'customer_id');
139
+ }
140
+ $session->unsOrderIds();
141
+ }
142
+
143
  $customerGroupId = $session->getCustomer()->getGroupId();
144
  $cachekey = $defaultGroupId == $customerGroupId ? NULL : 'group_id_' . $customerGroupId;
145
  return array(true, '0x0000', array('sessionkey' => md5(time()), 'cachekey' => $cachekey));
app/code/community/Kancart/MobileApi/controllers/IndexController.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  error_reporting(E_ALL ^ E_NOTICE);
4
- define('KANCART_PLUGIN_VERSION', '2.0.8');
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_appsecrect', Mage::app()->getStore()));
7
  define('MOBILE_API_ROOT', dirname(dirname(__FILE__)));
@@ -69,7 +69,10 @@ class Kancart_MobileApi_IndexController extends Mage_Core_Controller_Front_Actio
69
  Mage::app()->getStore()->setCurrentCurrencyCode($curency);
70
  }
71
 
72
- // Mage::app()->getConfig()->setNode('global/sales/quote/totals/discount/class', 'mobileapi/discount');
 
 
 
73
 
74
  $this->compilerPlugin(); //To prevent user backstage collapse after compiled
75
  }
@@ -153,6 +156,14 @@ class Kancart_MobileApi_IndexController extends Mage_Core_Controller_Front_Actio
153
  $fileName = MOBILE_API_ROOT . DIRECTORY_SEPARATOR . 'Helper' . DIRECTORY_SEPARATOR . 'Data.php';
154
  $dest = COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . 'Kancart_MobileApi_Helper_Data.php';
155
  file_exists($fileName) && copy($fileName, $dest);
 
 
 
 
 
 
 
 
156
  }
157
  }
158
 
1
  <?php
2
 
3
  error_reporting(E_ALL ^ E_NOTICE);
4
+ define('KANCART_PLUGIN_VERSION', '2.0.9');
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_appsecrect', Mage::app()->getStore()));
7
  define('MOBILE_API_ROOT', dirname(dirname(__FILE__)));
69
  Mage::app()->getStore()->setCurrentCurrencyCode($curency);
70
  }
71
 
72
+ if ($this->getRequest()->getParam('discount_amount') || $this->getRequest()->getParam('coupon_free_ship', 0) > 0) {
73
+ Mage::app()->getConfig()->setNode('global/sales/quote/totals/discount/class', 'mobileapi/discount');
74
+ Mage::app()->getConfig()->setNode('global/sales/order_invoice/totals/discount/class', 'mobileapi/invoice');
75
+ }
76
 
77
  $this->compilerPlugin(); //To prevent user backstage collapse after compiled
78
  }
156
  $fileName = MOBILE_API_ROOT . DIRECTORY_SEPARATOR . 'Helper' . DIRECTORY_SEPARATOR . 'Data.php';
157
  $dest = COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . 'Kancart_MobileApi_Helper_Data.php';
158
  file_exists($fileName) && copy($fileName, $dest);
159
+
160
+ $fileName = MOBILE_API_ROOT . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR . 'Discount.php';
161
+ $dest = COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . 'Kancart_MobileApi_Model_Discount.php';
162
+ file_exists($fileName) && copy($fileName, $dest);
163
+
164
+ $fileName = MOBILE_API_ROOT . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR . 'Invoice.php';
165
+ $dest = COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . 'Kancart_MobileApi_Model_Invoice.php';
166
+ file_exists($fileName) && copy($fileName, $dest);
167
  }
168
  }
169
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>KANCART_MobileAPI</name>
4
- <version>2.0.8</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
@@ -9,19 +9,11 @@
9
  <summary>Kancart Mobile API Service</summary>
10
  <description>Kancart.com provides a fast on boarding iOS, Android native app and mobile web site solution.&amp;amp;&#xD;
11
  This is the Magento server side extension to provide API service for all Kancart mobile clients.</description>
12
- <notes>Improve: Add related items and recommended items for Items.&#xD;
13
- Improve: Static block only categories will not be fetched.&#xD;
14
- Improve: Item's main image will be displayed as first image.&#xD;
15
- Bug Fix: Categories is not sorted by sort order.&#xD;
16
- Bug Fix: Custom shipping plugin compatibility issue.&#xD;
17
- Bug Fix: Can not fetch review on Magento 1.8.&#xD;
18
- Bug Fix: No quotes are available error occurred when new user first time checkout.&#xD;
19
- Bug Fix: Call to undefined method error occurred on Magento 1.5.&#xD;
20
- </notes>
21
  <authors><author><name>Kancart.com</name><user>Kancarter</user><email>support@kancart.com</email></author></authors>
22
- <date>2013-11-19</date>
23
- <time>09:32:55</time>
24
- <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="4800d10f05ccb9e0aff5a3acf7985498"/><file name="Cart.php" hash="0a27bc879f150a3bf6692de55a2e1152"/><file name="Category.php" hash="4993c1f1b5c03dccd5b50a8159f4880a"/><file name="Checkout.php" hash="73b533582e1343b5bc0964f626db19d7"/><file name="Discount.php" hash="5b543ed028c49abb3f42deaeebdb72bd"/><file name="ErrorHandler.php" hash="6d62e02c4ce592a41b242e781fe2c28a"/><file name="Item.php" hash="041757ba6cf6c2d6225478305dfdc6b6"/><file name="Items.php" hash="db233f56edd33139227ec8cb84bf6cbf"/><file name="Order.php" hash="c130f62e60a52feee620193f2aa14d0b"/><file name="PayPalEC.php" hash="936af8c18938954caf8a196f48b9fc5a"/><file name="PayPalWPS.php" hash="2fcaae5f64ed2ce3f2701e2ceab5299a"/><file name="Payment.php" hash="258e8c42fb2ee84fa0619dcc2db54eee"/><file name="Result.php" hash="64759b5dcb022186f12c0cb043877af0"/><file name="Review.php" hash="cd3b705fb6894c36824094f562acc869"/><file name="Store.php" hash="bb46fd16d3a864efbb4cfed04d882a62"/><file name="User.php" hash="76a6bb66aa098090fd5b25af7546569c"/></dir><dir name="controllers"><file name="IndexController.php" hash="02133e4e2f4ca086eeee43058cc4c7b3"/></dir><dir name="etc"><file name="adminhtml.xml" hash="3364317d05e33ac33f067aed7a9f6a58"/><file name="config.xml" hash="2f9d3466e651ac2b2b1f387b1a2356ad"/><file name="system.xml" hash="79209320204981af35bdb4bdcba8fe76"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Kancart_MobileApi.xml" hash="17ceeb976f959fc6365da95b532dd616"/></dir></target></contents>
25
  <compatible/>
26
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
27
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>KANCART_MobileAPI</name>
4
+ <version>2.0.9</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
9
  <summary>Kancart Mobile API Service</summary>
10
  <description>Kancart.com provides a fast on boarding iOS, Android native app and mobile web site solution.&amp;amp;&#xD;
11
  This is the Magento server side extension to provide API service for all Kancart mobile clients.</description>
12
+ <notes>Fix a bug blocks payment on 1.8.0.0</notes>
 
 
 
 
 
 
 
 
13
  <authors><author><name>Kancart.com</name><user>Kancarter</user><email>support@kancart.com</email></author></authors>
14
+ <date>2013-11-29</date>
15
+ <time>11:49:46</time>
16
+ <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="4800d10f05ccb9e0aff5a3acf7985498"/><file name="Cart.php" hash="40b2c19efb8dd4422c0ad6da6d3ef7ad"/><file name="Category.php" hash="4993c1f1b5c03dccd5b50a8159f4880a"/><file name="Checkout.php" hash="7779673bd1c96c426d9d10be7fee54af"/><file name="Discount.php" hash="b3f29b73768931a041703a0c7df3db53"/><file name="ErrorHandler.php" hash="6d62e02c4ce592a41b242e781fe2c28a"/><file name="Invoice.php" hash="cf16e5e8429b438d6e929d36e205f60b"/><file name="Item.php" hash="041757ba6cf6c2d6225478305dfdc6b6"/><file name="Items.php" hash="2d551bf7d80a0d7fe186cb3180ce8da6"/><file name="Order.php" hash="cf42edc1c4eb4df67b1740f58b080278"/><file name="PayPalEC.php" hash="936af8c18938954caf8a196f48b9fc5a"/><file name="PayPalWPS.php" hash="50e29c8a8f405cff32267de91adc1e5a"/><file name="Payment.php" hash="258e8c42fb2ee84fa0619dcc2db54eee"/><file name="Result.php" hash="64759b5dcb022186f12c0cb043877af0"/><file name="Review.php" hash="cd3b705fb6894c36824094f562acc869"/><file name="Store.php" hash="51cff0df2113a0cd7080ccbcdcb9ea75"/><file name="User.php" hash="05200f849e09346bf662ac1157217406"/></dir><dir name="controllers"><file name="IndexController.php" hash="26b59cff7fb05b19dfbff911631cab11"/></dir><dir name="etc"><file name="adminhtml.xml" hash="3364317d05e33ac33f067aed7a9f6a58"/><file name="config.xml" hash="2f9d3466e651ac2b2b1f387b1a2356ad"/><file name="system.xml" hash="79209320204981af35bdb4bdcba8fe76"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Kancart_MobileApi.xml" hash="17ceeb976f959fc6365da95b532dd616"/></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>