KANCART_MobileAPI - Version 2.0.7

Version Notes

Improved support for downloadable products; Solve a conflict with Amasty extension;

Download this release

Release Info

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


Code changes from version 2.0.6 to 2.0.7

app/code/community/Kancart/MobileApi/Model/Abstract.php CHANGED
@@ -33,6 +33,15 @@ abstract class Kancart_MobileApi_Model_Abstract {
33
  return Mage::app()->getTranslator()->translate($args);
34
  }
35
 
 
 
 
 
 
 
 
 
 
36
  public function toAddressData($address) {
37
  if (!$address) {
38
  return array();
33
  return Mage::app()->getTranslator()->translate($args);
34
  }
35
 
36
+ /**
37
+ * Retrieve current layout object
38
+ *
39
+ * @return Mage_Core_Model_Layout
40
+ */
41
+ public function getLayout() {
42
+ return Mage::getSingleton('core/layout');
43
+ }
44
+
45
  public function toAddressData($address) {
46
  if (!$address) {
47
  return array();
app/code/community/Kancart/MobileApi/Model/Checkout.php CHANGED
@@ -99,6 +99,7 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
99
  $checkoutDetailArr['need_shipping_address'] = !Kancart::getModel('Store')->checkAddressIntegrity($checkoutDetailArr['shipping_address']);
100
  $checkoutDetailArr['billing_address_valid'] = Kancart::getModel('Store')->checkAddressIntegrity($checkoutDetailArr['billing_address']);
101
  $checkoutDetailArr['review_orders'] = array($this->getOrderReview());
 
102
  $checkoutDetailArr['price_infos'] = $this->getPriceInfos();
103
  $checkoutDetailArr['payment_methods'] = $this->getPaymentMethods();
104
 
@@ -200,7 +201,12 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
200
  $this->getOnepage()->getQuote()->getShippingAddress()->setCollectShippingRates(true);
201
  $this->getOnepage()->getQuote()->collectTotals()->save();
202
  $shippingMethods = array();
203
- $block = Mage::getBlockSingleton('Checkout/Onepage_Shipping_Method_Available');
 
 
 
 
 
204
  if (($_shippingRateGroups = $block->getShippingRates())) {
205
  foreach ($_shippingRateGroups as $code => $_rates) {
206
  foreach ($_rates as $_rate) {
@@ -291,6 +297,12 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
291
  }
292
 
293
  try {
 
 
 
 
 
 
294
  if ($payment_id === 'paypal') {
295
  $real_payment_id = 'paypal_standard';
296
  } else if ($payment_id === 'paypalwpp') {
@@ -326,29 +338,21 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
326
  'purchaseorder' => 3
327
  );
328
 
 
329
  $payments = array();
330
- $availablePayments = array();
331
  $methods = $this->getAvailablePayment();
332
  if ($methods) {
333
  foreach ($methods as $method) {
334
  $code = $method->getCode();
 
 
 
335
  if (isset($priorsPayments[$code])) {
336
  $payments[$priorsPayments[$code]] = $code;
337
  }
338
- $availablePayments[] = $code;
339
  }
340
  }
341
 
342
- if (sizeof($availablePayments) > 0) {
343
- $arr = explode('_', $payment_id);
344
- $code = end($arr);
345
- if (in_array($code, $availablePayments)) {
346
- return $code;
347
- }
348
- } else {
349
- Mage::throwException('No available offline payment method configured on Magento backend.');
350
- }
351
-
352
  if (sizeof($payments) < 1) {
353
  Mage::throwException('No available offline payment method configured on Magento backend.');
354
  }
99
  $checkoutDetailArr['need_shipping_address'] = !Kancart::getModel('Store')->checkAddressIntegrity($checkoutDetailArr['shipping_address']);
100
  $checkoutDetailArr['billing_address_valid'] = Kancart::getModel('Store')->checkAddressIntegrity($checkoutDetailArr['billing_address']);
101
  $checkoutDetailArr['review_orders'] = array($this->getOrderReview());
102
+ $checkoutDetailArr['need_select_shipping_method'] = !$is_virtual && empty($checkoutDetailArr['review_orders'][0]['selected_shipping_method_id']);
103
  $checkoutDetailArr['price_infos'] = $this->getPriceInfos();
104
  $checkoutDetailArr['payment_methods'] = $this->getPaymentMethods();
105
 
201
  $this->getOnepage()->getQuote()->getShippingAddress()->setCollectShippingRates(true);
202
  $this->getOnepage()->getQuote()->collectTotals()->save();
203
  $shippingMethods = array();
204
+
205
+ $layout = $this->getLayout();
206
+ $layout->getUpdate()->load('checkout_onepage_shippingmethod');
207
+ $layout->generateXml()->generateBlocks();
208
+ $block = $layout->getBlock('root');
209
+
210
  if (($_shippingRateGroups = $block->getShippingRates())) {
211
  foreach ($_shippingRateGroups as $code => $_rates) {
212
  foreach ($_rates as $_rate) {
297
  }
298
 
299
  try {
300
+ Kancart::getModel('Coupon')->applyPromotion(); //apply mobile Promotion
301
+
302
+ if ($this->getQuote()->getGrandTotal() == 0) {
303
+ $payment_id = 'free';
304
+ }
305
+
306
  if ($payment_id === 'paypal') {
307
  $real_payment_id = 'paypal_standard';
308
  } else if ($payment_id === 'paypalwpp') {
338
  'purchaseorder' => 3
339
  );
340
 
341
+ $kcode = end(explode('_', $payment_id));
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
  }
app/code/community/Kancart/MobileApi/Model/Coupon.php ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Kancart_MobileApi_Model_Coupon extends Kancart_MobileApi_Model_Abstract {
4
+
5
+ public function promotionalCouponGenerator($discountAmount) {
6
+ try {
7
+ $model = Mage::getModel('salesrule/rule');
8
+ if (!($data = $this->initData($discountAmount))) {
9
+ return array(false, '0xEEEE', NULL);
10
+ }
11
+
12
+ $collection = $model->getResourceCollection();
13
+ $collection->addFieldToSelect(array('from_date', 'to_date', 'rule_id'))
14
+ ->addFieldToFilter('name', 'Kancart')
15
+ ->addFieldToFilter('simple_action', $this->getRequest()->getParam('simple_action'))
16
+ ->addFieldToFilter('apply_to_shipping', $this->getRequest()->getParam('apply_to_shipping'))
17
+ ->addFieldToFilter('discount_amount', $this->getRequest()->getParam('discount_amount'));
18
+
19
+ $collection->load();
20
+ $item = current($collection->getItems());
21
+ if ($item) {
22
+ return array(true, '', $item->getCode());
23
+ }
24
+
25
+ $collection = Mage::helper('Customer')->getGroups();
26
+ foreach ($collection->getItems() as $group) {
27
+ $data['customer_group_ids'][] = $group->getId();
28
+ }
29
+
30
+ //filter HTML tags
31
+ /** @var $helper Mage_Adminhtml_Helper_Data */
32
+ $helper = Mage::helper('adminhtml');
33
+ $data['name'] = $helper->stripTags($data['name']);
34
+ $data['description'] = $helper->stripTags($data['description']);
35
+ foreach ($data['store_labels'] as &$label) {
36
+ $label = $helper->stripTags($label);
37
+ }
38
+
39
+ $id = $this->getRequest()->getParam('promotion_id');
40
+ if ($id) {
41
+ $model->load($id);
42
+ if ($id != $model->getId()) {
43
+ Mage::throwException(Mage::helper('salesrule')->__('Wrong rule specified.'));
44
+ }
45
+ }
46
+
47
+ $session = Mage::getSingleton('adminhtml/session');
48
+
49
+ $validateResult = $model->validateData(new Varien_Object($data));
50
+ if ($validateResult !== true) {
51
+ return array(false, '0xEEEE', $validateResult);
52
+ }
53
+
54
+ if (isset($data['simple_action']) && $data['simple_action'] == 'by_percent'
55
+ && isset($data['discount_amount'])) {
56
+ $data['discount_amount'] = min(100, $data['discount_amount']);
57
+ }
58
+ if (isset($data['rule']['conditions'])) {
59
+ $data['conditions'] = $data['rule']['conditions'];
60
+ }
61
+ if (isset($data['rule']['actions'])) {
62
+ $data['actions'] = $data['rule']['actions'];
63
+ }
64
+ unset($data['rule']);
65
+ $model->loadPost($data);
66
+
67
+ $session->setPageData($model->getData());
68
+
69
+ $model->save();
70
+ return array(true, '0x0000', $data['coupon_code']);
71
+ } catch (Mage_Core_Exception $e) {
72
+ $mesg = array($e->getMessage());
73
+ } catch (Exception $e) {
74
+ Mage::logException($e);
75
+ $mesg = array($e->getMessage());
76
+ }
77
+
78
+ return array(false, '0xEEEE', $mesg);
79
+ }
80
+
81
+ public function applyPromotion() {
82
+ $discountAmount = $this->getRequest()->getParam('discount_amount');
83
+ $freeShipping = $this->getRequest()->getParam('coupon_free_ship', false);
84
+ if ($discountAmount || ($freeShipping && $freeShipping > 0)) {
85
+ list($result, $code, $coupon) = $this->promotionalCouponGenerator($discountAmount);
86
+ if ($result) {
87
+ try {
88
+ $this->getQuote()->setCouponCode($coupon)->collectTotals()->save();
89
+ } catch (Exception $e) {
90
+ Mage::logException($e);
91
+ }
92
+ }
93
+ }
94
+ }
95
+
96
+ public function getQuote() {
97
+ if (empty($this->_quote)) {
98
+ $this->_quote = Mage::getSingleton('checkout/cart')->getQuote();
99
+ }
100
+ return $this->_quote;
101
+ }
102
+
103
+ private function initData($discountAmount) {
104
+ $now = time();
105
+ $couponCode = 'KM' . strtoupper(dechex($now));
106
+ $couponName = 'Kancart';
107
+ $couponDesc = 'From mobile coupon';
108
+ $fromDate = date('Y-m-d', $now);
109
+ $toDate = date('Y-m-d', $now + 24 * 3600);
110
+ $freeShipping = (bool) $this->getRequest()->getParam('coupon_free_ship', false);
111
+
112
+ if (empty($discountAmount) && !$freeShipping) {
113
+ return false;
114
+ }
115
+
116
+ $conditions = array();
117
+ $conditions[1] = array(
118
+ 'type' => 'salesrule/rule_condition_combine',
119
+ 'aggregator' => 'all',
120
+ 'value' => '1',
121
+ 'new_child' => ''
122
+ );
123
+
124
+ $actions = array();
125
+ $actions[1] = array(
126
+ 'type' => 'salesrule/rule_condition_product_combine',
127
+ 'aggregator' => 'all',
128
+ 'value' => '1',
129
+ 'new_child' => ''
130
+ );
131
+
132
+ $data = array(
133
+ 'description' => $couponDesc,
134
+ 'name' => $couponName,
135
+ 'is_active' => '1',
136
+ 'rule_id' => $this->getRequest()->getParam('promotion_id', null),
137
+ 'website_ids' => array(Mage::app()->getStore()->getWebsiteId()),
138
+ 'coupon_type' => Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC,
139
+ 'rule' => array('conditions' => $conditions, 'actions' => $actions),
140
+ 'store_labels' => array('0' => 'Kancart Coupon'),
141
+ 'customer_group_ids' => array(),
142
+ 'coupon_code' => $couponCode,
143
+ 'uses_per_coupon' => 0,
144
+ 'uses_per_customer' => 0,
145
+ 'from_date' => $fromDate,
146
+ 'to_date' => $toDate,
147
+ 'sort_order' => 1,
148
+ 'is_rss' => 1,
149
+ 'discount_qty' => '0',
150
+ 'discount_step' => '0',
151
+ 'apply_to_shipping' => $this->getRequest()->getParam('discount_for_shipping', false),
152
+ 'simple_free_shipping' => $freeShipping,
153
+ 'stop_rules_processing' => '0'
154
+ );
155
+
156
+ if (substr($discountAmount, -1) == '%') {
157
+ $data['simple_action'] = Mage_SalesRule_Model_Rule::BY_PERCENT_ACTION;
158
+ $data['discount_amount'] = substr($discountAmount, 0, -1);
159
+ } elseif (is_numeric($discountAmount) && $discountAmount > 0) {
160
+ $data['simple_action'] = Mage_SalesRule_Model_Rule::CART_FIXED_ACTION;
161
+ $data['discount_amount'] = $discountAmount;
162
+ }
163
+
164
+ return $data;
165
+ }
166
+
167
+ }
168
+
169
+ // end
app/code/community/Kancart/MobileApi/Model/ErrorHandler.php CHANGED
@@ -5,6 +5,7 @@ class KancartErrorHandler {
5
  // CATCHABLE ERRORS
6
  public static function captureNormal($number, $message, $file, $line) {
7
  $errormsg = "ERROR #$number: $message in $file on line $line ";
 
8
  die(json_encode(array('result' => 'fail', 'code' => '0xFFFF', 'info' => $errormsg)));
9
  return true;
10
  }
@@ -13,25 +14,29 @@ class KancartErrorHandler {
13
  public static function captureException($exception) {
14
  // Display content $exception variable
15
  $errormsg = "Uncaught Exception: #{$exception->getCode()} {$exception->getMessage()} in {$exception->getFile()} on line {$exception->getLine()} ";
 
16
  die(json_encode(array('result' => 'fail', 'code' => '0xFFFF', 'info' => $errormsg)));
17
  }
18
 
19
  // UNCATCHABLE ERRORS
20
  public static function captureFatalError() {
21
  $error = error_get_last();
22
- if ($error) {
23
- if(!defined('REQUEST_NORMAL_COMPLETE')){
24
- $errormsg = "FATAL ERROR: {$error['message']} in {$error['file']} on line {$error['line']} ";
25
- die(json_encode(array('result' => 'fail', 'code' => '0xFFFF', 'info' => $errormsg)));
 
 
 
26
  }
27
  }
28
  }
29
 
30
  }
31
 
32
- if(!defined('E_DEPRECATED'))define ('E_DEPRECATED', 8192);
33
 
34
- set_error_handler(array('KancartErrorHandler', 'captureNormal'), E_ALL ^ E_WARNING ^ E_NOTICE ^ E_DEPRECATED);
35
  set_exception_handler(array('KancartErrorHandler', 'captureException'));
36
  register_shutdown_function(array('KancartErrorHandler', 'captureFatalError'));
37
  ?>
5
  // CATCHABLE ERRORS
6
  public static function captureNormal($number, $message, $file, $line) {
7
  $errormsg = "ERROR #$number: $message in $file on line $line ";
8
+ header("HTTP/1.0 200 OK",true);
9
  die(json_encode(array('result' => 'fail', 'code' => '0xFFFF', 'info' => $errormsg)));
10
  return true;
11
  }
14
  public static function captureException($exception) {
15
  // Display content $exception variable
16
  $errormsg = "Uncaught Exception: #{$exception->getCode()} {$exception->getMessage()} in {$exception->getFile()} on line {$exception->getLine()} ";
17
+ header("HTTP/1.0 200 OK",true);
18
  die(json_encode(array('result' => 'fail', 'code' => '0xFFFF', 'info' => $errormsg)));
19
  }
20
 
21
  // UNCATCHABLE ERRORS
22
  public static function captureFatalError() {
23
  $error = error_get_last();
24
+ if ($error) {
25
+ if (!defined('REQUEST_NORMAL_COMPLETE') && isset($_REQUEST['method'])) {
26
+ if ($error['type'] == E_COMPILE_ERROR || $error['type'] == E_RECOVERABLE_ERROR || $error['type'] == E_ERROR || $error['type'] == E_CORE_ERROR || $error['type'] == E_USER_ERROR) {
27
+ $errormsg = "FATAL ERROR #{$error['type']}: {$error['message']} in {$error['file']} on line {$error['line']} ";
28
+ header("HTTP/1.0 200 OK",true);
29
+ die(json_encode(array('result' => 'fail', 'code' => '0xFFFF', 'info' => $errormsg)));
30
+ }
31
  }
32
  }
33
  }
34
 
35
  }
36
 
37
+ if(!defined('E_DEPRECATED')){define ('E_DEPRECATED', 8192);}
38
 
39
+ set_error_handler(array('KancartErrorHandler', 'captureNormal'), E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR|E_USER_ERROR);
40
  set_exception_handler(array('KancartErrorHandler', 'captureException'));
41
  register_shutdown_function(array('KancartErrorHandler', 'captureFatalError'));
42
  ?>
app/code/community/Kancart/MobileApi/Model/Item.php CHANGED
@@ -60,8 +60,8 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
60
  $this->getItemPrices();
61
  $this->getItemImages();
62
  $this->getProductDescription();
63
- // $this->getRecommendedItems();
64
- // $this->getRelatedItems();
65
  }
66
  return array(true, '0x0000', array('item' => $this->item));
67
  }
@@ -364,7 +364,7 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
364
  $productPrice = $_item->getPrice();
365
  }
366
  if ($productPrice > 0.00) {
367
- //add
368
  $attribute['price'] = $this->getCurrencyPrice($productPrice);
369
  }
370
  $attribute['options'] = array();
@@ -500,15 +500,10 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
500
  foreach ($_attributes as $attribute) {
501
  $productAttribute = $attribute->getProductAttribute();
502
  $attributeValue = $_item->getData($productAttribute->getAttributeCode());
503
- if (!isset($options[$productAttribute->getId()])) {
504
- $options[$productAttribute->getId()] = array();
505
- }
506
- if (!isset($options[$productAttribute->getId()][$attributeValue])) {
507
- $options[$productAttribute->getId()][$attributeValue] = array();
508
- }
509
- $options[$productAttribute->getId()][$attributeValue][] = $_productId;
510
  }
511
  }
 
512
  foreach ($_attributes as $attribute) {
513
  $productAttribute = $attribute->getProductAttribute();
514
  $attributeId = $productAttribute->getId();
@@ -521,19 +516,13 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
521
  $prices = $attribute->getPrices();
522
  if (is_array($prices)) {
523
  foreach ($prices as $value) {
524
- if (!isset($options[$attributeId][$value['value_index']])) {
525
  continue;
526
  }
527
- $price = $this->_preparePrice($product, $value['pricing_value'], $value['is_percent']);
528
- $optionProducts = array();
529
- if (isset($options[$attributeId][$value['value_index']])) {
530
- $optionProducts = $options[$attributeId][$value['value_index']];
531
- }
532
  $info['options'][] = array(
533
  'id' => $value['value_index'],
534
  'label' => $value['label'],
535
- 'price' => $price,
536
- 'products' => $optionProducts,
537
  );
538
  }
539
  }
@@ -658,6 +647,48 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
658
  return $attributes;
659
  }
660
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
661
  private function _preparePrice($product, $price, $isPercent = false) {
662
  if ($isPercent && !empty($price)) {
663
  $price = $product->getFinalPrice() * $price / 100;
@@ -739,7 +770,7 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
739
  $this->addtoDisplayPrices($display_prices, $this->__('From:'), $this->getCurrencyPrice($_minimalPrice), 'from');
740
  $this->addtoDisplayPrices($display_prices, $this->__('To:'), $this->getCurrencyPrice($_maximalPrice), 'to');
741
  } else {
742
- $this->addtoDisplayPrices($display_prices, $this->getCurrencyPrice($_minimalPrice), 'normal');
743
  }
744
  }
745
  $prices['base_price'] = array('price' => $this->getCurrencyPrice($_finalPrice));
60
  $this->getItemPrices();
61
  $this->getItemImages();
62
  $this->getProductDescription();
63
+ // $this->getRecommendedItems();
64
+ // $this->getRelatedItems();
65
  }
66
  return array(true, '0x0000', array('item' => $this->item));
67
  }
364
  $productPrice = $_item->getPrice();
365
  }
366
  if ($productPrice > 0.00) {
367
+ //add
368
  $attribute['price'] = $this->getCurrencyPrice($productPrice);
369
  }
370
  $attribute['options'] = array();
500
  foreach ($_attributes as $attribute) {
501
  $productAttribute = $attribute->getProductAttribute();
502
  $attributeValue = $_item->getData($productAttribute->getAttributeCode());
503
+ $options[$productAttribute->getId()][$_productId] = $attributeValue;
 
 
 
 
 
 
504
  }
505
  }
506
+ $this->item['attribute_relation'] = $this->getAttributeRelation($options);
507
  foreach ($_attributes as $attribute) {
508
  $productAttribute = $attribute->getProductAttribute();
509
  $attributeId = $productAttribute->getId();
516
  $prices = $attribute->getPrices();
517
  if (is_array($prices)) {
518
  foreach ($prices as $value) {
519
+ if (!in_array($value['value_index'], $options[$attributeId])) {
520
  continue;
521
  }
 
 
 
 
 
522
  $info['options'][] = array(
523
  'id' => $value['value_index'],
524
  'label' => $value['label'],
525
+ 'price' => $this->_preparePrice($product, $value['pricing_value'], $value['is_percent']),
 
526
  );
527
  }
528
  }
647
  return $attributes;
648
  }
649
 
650
+ private function getAttributeRelation($options, $type = 'associate') {
651
+ $attributeRelation = array();
652
+
653
+ if ($type == 'associate') {
654
+ if ($options && sizeof($options) > 1) {
655
+ $min = 100;
656
+ $parentAttributeId = 0;
657
+ $parentOption = array();
658
+ foreach ($options as $attributeId => $option) {
659
+ $optionSize = sizeof(array_flip($option));
660
+ if ($optionSize < $min) {
661
+ $min = $optionSize;
662
+ $parentAttributeId = $attributeId;
663
+ $parentOption = $option;
664
+ }
665
+ }
666
+
667
+ foreach ($options as $attributeId => $option) {
668
+ if ($parentAttributeId == $attributeId) {
669
+ continue;
670
+ }
671
+ $relations = array();
672
+ foreach ($option as $key => $value) {
673
+ $parentOptionId = $parentOption[$key];
674
+ $relations[$parentOptionId]['parent_option_id'] = $parentOptionId;
675
+ $relations[$parentOptionId]['child_option_id'][] = $value;
676
+ }
677
+ $attributeRelation[] = array(
678
+ 'parent_attribute_id' => 'super_attribute_' . $parentAttributeId,
679
+ 'child_attribute_id' => 'super_attribute_' . $attributeId,
680
+ 'type' => $type,
681
+ 'value' => array_values($relations)
682
+ );
683
+ }
684
+ }
685
+ } elseif ($type == 'display') {
686
+
687
+ }
688
+
689
+ return $attributeRelation;
690
+ }
691
+
692
  private function _preparePrice($product, $price, $isPercent = false) {
693
  if ($isPercent && !empty($price)) {
694
  $price = $product->getFinalPrice() * $price / 100;
770
  $this->addtoDisplayPrices($display_prices, $this->__('From:'), $this->getCurrencyPrice($_minimalPrice), 'from');
771
  $this->addtoDisplayPrices($display_prices, $this->__('To:'), $this->getCurrencyPrice($_maximalPrice), 'to');
772
  } else {
773
+ $this->addtoDisplayPrices($display_prices, 'Price: ', $this->getCurrencyPrice($_minimalPrice), 'normal');
774
  }
775
  }
776
  $prices['base_price'] = array('price' => $this->getCurrencyPrice($_finalPrice));
app/code/community/Kancart/MobileApi/Model/Order.php CHANGED
@@ -252,54 +252,36 @@ class Kancart_MobileApi_Model_Order extends Kancart_MobileApi_Model_Abstract {
252
  return;
253
  }
254
 
255
- $session = Mage::getSingleton('customer/session');
256
- $purchased = Mage::getResourceModel('downloadable/link_purchased_collection')
257
- ->addFieldToFilter('customer_id', $session->getCustomerId())
258
- ->addFieldToFilter('order_id', $order->getId())
259
- ->addOrder('created_at', 'desc');
260
-
261
- $purchasedIds = array();
262
- foreach ($purchased as $_item) {
263
- $purchasedIds[] = $_item->getId();
264
- }
265
- if (empty($purchasedIds)) {
266
- return;
267
- }
268
- $purchasedItems = Mage::getResourceModel('downloadable/link_purchased_item_collection')
269
- ->addFieldToFilter('purchased_id', array('in' => $purchasedIds))
270
- ->addFieldToFilter('status', array(
271
- 'nin' => array(
272
- Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING_PAYMENT,
273
- Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PAYMENT_REVIEW
274
- )
275
- )
276
- )
277
- ->setOrder('item_id', 'desc');
278
-
279
  $block = Mage::getBlockSingleton('downloadable/catalog_product_links');
280
- foreach ($purchasedItems as $item) {
281
- $item->setPurchased($purchased->getItemById($item->getPurchasedId()));
282
- $item->setQty($_products[$item->getOrderItemId()]['qty']);
283
- $item->setProduct($_products[$item->getOrderItemId()]['product']);
284
- $block->setProduct($item->getProduct());
285
- $links = $block->getLinks();
286
- preg_match('/\d+\.\d+/', $block->getFormattedLinkPrice($links[$item->getLinkId()]), $prices);
287
- $item->setPrice($prices[0]);
 
 
 
288
  }
289
 
290
- $arrtibute = Mage::helper('downloadable')->__('Date') . ': %s<br>' . Mage::helper('downloadable')->__('Status') . ': %s<br>' . Mage::helper('downloadable')->__('Remaining Downloads') . ': %s<br>';
291
  foreach ($purchasedItems as $item) {
292
  if ($item->getNumberOfDownloadsBought()) {
293
- $limit = $item->getNumberOfDownloadsBought() - $item->getNumberOfDownloadsUsed();
294
  } else {
295
- $limit = Mage::helper('downloadable')->__('Unlimited');
296
  }
297
 
298
  $items[] = array(
299
  'item_id' => $item->getOrderItemId(),
300
  'display_id' => $item->getOrderItemId(),
301
- 'display_attributes' => sprintf($arrtibute, Varien_Date::formatDate($item->getPurchased()->getCreatedAt()), Mage::helper('downloadable')->__(ucfirst($item->getStatus())), $limit),
302
- 'item_title' => $item->getPurchased()->getProductName() . ' - <a href="' . $block->getUrl('downloadable/download/link', array('id' => $item->getLinkHash(), '_secure' => true)) . '" title="' . Mage::helper('downloadable')->__('Start Download') . '"' . (Mage::getStoreConfigFlag(Mage_Downloadable_Model_Link::XML_PATH_TARGET_NEW_WINDOW) ? 'onclick="this.target=\'_blank\'">' : '>') . $item->getLinkTitle() . '</a>',
303
  'thumbnail_pic_url' => $item->getProduct()->getThumbnailUrl(),
304
  'qty' => (int) $item->getQty(),
305
  'price' => $item->getPrice(),
252
  return;
253
  }
254
 
255
+ $purchasedItems = array();
256
+ $list = Mage::getBlockSingleton('Downloadable/Customer_Products_List');
257
+ $purchased = $list->getPurchased();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  $block = Mage::getBlockSingleton('downloadable/catalog_product_links');
259
+ foreach ($list->getItems() as $item) {
260
+ if ($item->getPurchased()->getOrderId() == $order->getId()) {
261
+ $item->setPurchased($purchased->getItemById($item->getPurchasedId()));
262
+ $item->setQty($_products[$item->getOrderItemId()]['qty']);
263
+ $item->setProduct($_products[$item->getOrderItemId()]['product']);
264
+ $block->setProduct($item->getProduct());
265
+ $links = $block->getLinks();
266
+ preg_match('/\d+\.\d+/', $block->getFormattedLinkPrice($links[$item->getLinkId()]), $prices);
267
+ $item->setPrice($prices[0]);
268
+ $purchasedItems[] = $item;
269
+ }
270
  }
271
 
272
+ $arrtibute = Mage::helper('downloadable')->__('Date') . ': %s<br>' . Mage::helper('downloadable')->__('Status') . ': %s<br>' . Mage::helper('downloadable')->__('Remaining Downloads') . ': %s<br>Download Url: %s<br>';
273
  foreach ($purchasedItems as $item) {
274
  if ($item->getNumberOfDownloadsBought()) {
275
+ $url = '<a href="' . $list->getDownloadUrl($item) . '" title="' . Mage::helper('downloadable')->__('Start Download') . '"' . ($list->getIsOpenInNewWindow() ? 'onclick="this.target=\'_blank\'">' : '>') . $item->getLinkTitle() . '</a>';
276
  } else {
277
+ $url = '<a href="' . $item->getLinkUrl() . '" title="' . Mage::helper('downloadable')->__('Start Download') . '"' . ($list->getIsOpenInNewWindow() ? 'onclick="this.target=\'_blank\'">' : '>') . $item->getLinkTitle() . '</a>';
278
  }
279
 
280
  $items[] = array(
281
  'item_id' => $item->getOrderItemId(),
282
  'display_id' => $item->getOrderItemId(),
283
+ 'display_attributes' => sprintf($arrtibute, $list->formatDate($item->getPurchased()->getCreatedAt()), Mage::helper('downloadable')->__(ucfirst($item->getStatus())), $list->getRemainingDownloads($item), $url),
284
+ 'item_title' => $item->getPurchased()->getProductName(),
285
  'thumbnail_pic_url' => $item->getProduct()->getThumbnailUrl(),
286
  'qty' => (int) $item->getQty(),
287
  'price' => $item->getPrice(),
app/code/community/Kancart/MobileApi/Model/PayPalEC.php CHANGED
@@ -37,7 +37,7 @@ class Kancart_MobileApi_Model_PayPalEC extends Kancart_MobileApi_Model_Abstract
37
  * @var string
38
  */
39
  protected $_configMethod = Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS;
40
- protected $_checkout = null;
41
  protected $_config = null;
42
 
43
  protected function _initCheckout() {
@@ -46,7 +46,7 @@ class Kancart_MobileApi_Model_PayPalEC extends Kancart_MobileApi_Model_Abstract
46
  Mage::throwException(Mage::helper('paypal')->__('Unable to initialize Express Checkout.'));
47
  }
48
  if (is_null($this->_config)) {
49
- $this->_config = Mage::getModel($this->_configType, array($this->_configMethod));
50
  }
51
  $this->_checkout = Mage::getSingleton('paypal/express_checkout', array(
52
  'config' => $this->_config,
@@ -204,4 +204,16 @@ class Kancart_MobileApi_Model_PayPalEC extends Kancart_MobileApi_Model_Abstract
204
  return $this->_quote;
205
  }
206
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  }
37
  * @var string
38
  */
39
  protected $_configMethod = Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS;
40
+ protected $_checkout = null; //Mage_Paypal_Model_Config
41
  protected $_config = null;
42
 
43
  protected function _initCheckout() {
46
  Mage::throwException(Mage::helper('paypal')->__('Unable to initialize Express Checkout.'));
47
  }
48
  if (is_null($this->_config)) {
49
+ $this->_config = new Kancart_Paypal_Model_Config(array($this->_configMethod));
50
  }
51
  $this->_checkout = Mage::getSingleton('paypal/express_checkout', array(
52
  'config' => $this->_config,
204
  return $this->_quote;
205
  }
206
 
207
+ }
208
+
209
+ class Kancart_Paypal_Model_Config extends Mage_Paypal_Model_Config {
210
+
211
+ public function __construct($params = array()) {
212
+ parent::__construct($params);
213
+ }
214
+
215
+ public function getBuildNotationCode($countryCode = null) {
216
+ return 'Kancart_SP_EC';
217
+ }
218
+
219
  }
app/code/community/Kancart/MobileApi/Model/PayPalWPS.php CHANGED
@@ -42,7 +42,7 @@ class Kancart_MobileApi_Model_PayPalWPS extends Kancart_MobileApi_Model_Abstract
42
  foreach ($standard->getStandardCheckoutFormFields() as $field => $value) {
43
  $paypalParams[$field] = $value;
44
  }
45
- $paypalParams['bn'] = 'PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted';
46
  $paypalParams['shopping_url'] = $requestData['shoppingcart_url'];
47
  $paypalParams['return'] = $requestData['return_url'];
48
  $paypalParams['cancel_return'] = $requestData['cancel_url'];
42
  foreach ($standard->getStandardCheckoutFormFields() as $field => $value) {
43
  $paypalParams[$field] = $value;
44
  }
45
+ $paypalParams['bn'] = 'Kancart_SP_WPS';
46
  $paypalParams['shopping_url'] = $requestData['shoppingcart_url'];
47
  $paypalParams['return'] = $requestData['return_url'];
48
  $paypalParams['cancel_return'] = $requestData['cancel_url'];
app/code/community/Kancart/MobileApi/Model/Result.php CHANGED
@@ -70,7 +70,6 @@ class Kancart_MobileApi_Model_Result extends Kancart_MobileApi_Model_Abstract {
70
  }
71
 
72
  public function returnResult() {
73
- define('REQUEST_NORMAL_COMPLETE', true);
74
  $arr = array('result' => $this->result, 'code' => $this->code, 'info' => $this->info);
75
  if (PHP_VERSION >= '5.2.0') {
76
  return json_encode($arr);
70
  }
71
 
72
  public function returnResult() {
 
73
  $arr = array('result' => $this->result, 'code' => $this->code, 'info' => $this->info);
74
  if (PHP_VERSION >= '5.2.0') {
75
  return json_encode($arr);
app/code/community/Kancart/MobileApi/Model/Store.php CHANGED
@@ -219,7 +219,8 @@ class Kancart_MobileApi_Model_Store extends Kancart_MobileApi_Model_Abstract {
219
  $update = $layout->getUpdate();
220
  $rootCategory = Mage::getModel('catalog/category')
221
  ->load(Mage::app()->getStore()->getRootCategoryId());
222
- Mage::register('root_category', $rootCategory);
 
223
  $update->addHandle($rootCategory->getLayoutUpdateHandle());
224
  $update->load();
225
  $layout->generateXml()->generateBlocks();
@@ -243,7 +244,7 @@ class Kancart_MobileApi_Model_Store extends Kancart_MobileApi_Model_Abstract {
243
  }
244
 
245
  public function getSearchSortOptions() {
246
- if (!($rootCategory = Mage::registry('root_category'))) {
247
  $rootCategory = Mage::getModel('catalog/category')
248
  ->load(Mage::app()->getStore()->getRootCategoryId());
249
  }
219
  $update = $layout->getUpdate();
220
  $rootCategory = Mage::getModel('catalog/category')
221
  ->load(Mage::app()->getStore()->getRootCategoryId());
222
+ Mage::register('current_category', $rootCategory);
223
+ $update->addHandle('default');
224
  $update->addHandle($rootCategory->getLayoutUpdateHandle());
225
  $update->load();
226
  $layout->generateXml()->generateBlocks();
244
  }
245
 
246
  public function getSearchSortOptions() {
247
+ if (!($rootCategory = Mage::registry('current_category'))) {
248
  $rootCategory = Mage::getModel('catalog/category')
249
  ->load(Mage::app()->getStore()->getRootCategoryId());
250
  }
app/code/community/Kancart/MobileApi/Model/User.php CHANGED
@@ -110,6 +110,7 @@ class Kancart_MobileApi_Model_User extends Kancart_MobileApi_Model_Abstract {
110
  $uname = $userLoginData['uname'];
111
  $pwd = $userLoginData['pwd'];
112
  $session = $this->_getSession();
 
113
  $desPassword = Kancart::helper('CryptoUtil')->Crypto($pwd, 'AES-256', KANCART_APP_SECRECT, false);
114
  if ($uname != null && $pwd != null) {
115
  try {
@@ -117,7 +118,9 @@ class Kancart_MobileApi_Model_User extends Kancart_MobileApi_Model_Abstract {
117
  if ($session->getCustomer()->getIsJustConfirmed()) {
118
  $session->getCustomer()->sendNewAccountEmail('confirmed');
119
  }
120
- return array(true, '0x0000', array('sessionkey' => md5(time())));
 
 
121
  } else {
122
  return array(false, '0x1001', Mage::helper('customer')->__('Invalid login or password.'));
123
  }
110
  $uname = $userLoginData['uname'];
111
  $pwd = $userLoginData['pwd'];
112
  $session = $this->_getSession();
113
+ $defaultGroupId = $session->getCustomer()->getGroupId();
114
  $desPassword = Kancart::helper('CryptoUtil')->Crypto($pwd, 'AES-256', KANCART_APP_SECRECT, false);
115
  if ($uname != null && $pwd != null) {
116
  try {
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));
124
  } else {
125
  return array(false, '0x1001', Mage::helper('customer')->__('Invalid login or password.'));
126
  }
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.6');
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__)));
1
  <?php
2
 
3
  error_reporting(E_ALL ^ E_NOTICE);
4
+ define('KANCART_PLUGIN_VERSION', '2.0.7');
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__)));
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>KANCART_MobileAPI</name>
4
- <version>2.0.6</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
@@ -9,11 +9,12 @@
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>bug fix</notes>
 
13
  <authors><author><name>Kancart.com</name><user>Kancarter</user><email>support@kancart.com</email></author></authors>
14
- <date>2013-09-17</date>
15
- <time>03:56:42</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="9065be20accd25bccb48b1ffbe7a0424"/><file name="Cart.php" hash="0a27bc879f150a3bf6692de55a2e1152"/><file name="Category.php" hash="dfedccdc604796a9cee2251128da0b36"/><file name="Checkout.php" hash="fb4cab29eb43431aa5506a979a29dd9f"/><file name="ErrorHandler.php" hash="eb30cf58679a2d8bbb7efe3f3c1e36b7"/><file name="Item.php" hash="5b5a45db12c8dc6a86a36c24988bc0b3"/><file name="Items.php" hash="d9ce1a9bbbf33f7c266b2939b4a1d12e"/><file name="Order.php" hash="efe25de48deb4c1e7482edb0b34aa2fe"/><file name="PayPalEC.php" hash="6bc8f751c7aed75170ece42e7ed9c614"/><file name="PayPalWPS.php" hash="2ad17303398c699f790e1e57a07aab45"/><file name="Payment.php" hash="258e8c42fb2ee84fa0619dcc2db54eee"/><file name="Result.php" hash="d3c49099fd34d7dc7547ad4a329b1fd1"/><file name="Review.php" hash="d320736cc3a8ce67f7aae9b60b7c85eb"/><file name="Store.php" hash="4537b0875c3e216acfd308de0fc29ca5"/><file name="User.php" hash="e5266eeefb678bd6f54307cf52b76f46"/></dir><dir name="controllers"><file name="IndexController.php" hash="20f40697387ea683573d627e2807b71f"/></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>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>KANCART_MobileAPI</name>
4
+ <version>2.0.7</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>Improved support for downloadable products; Solve a conflict with Amasty extension;&#xD;
13
+ </notes>
14
  <authors><author><name>Kancart.com</name><user>Kancarter</user><email>support@kancart.com</email></author></authors>
15
+ <date>2013-10-15</date>
16
+ <time>06:47:47</time>
17
+ <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="8c350a634389b4346ec06eb9d22e5584"/><file name="Cart.php" hash="0a27bc879f150a3bf6692de55a2e1152"/><file name="Category.php" hash="dfedccdc604796a9cee2251128da0b36"/><file name="Checkout.php" hash="35185a231d6cbfdacc5d300bc56b42b8"/><file name="Coupon.php" hash="512c92915f02e353ba32b95e90b0c410"/><file name="ErrorHandler.php" hash="6d62e02c4ce592a41b242e781fe2c28a"/><file name="Item.php" hash="6402877ed7f91ac2e5fd817132e0b273"/><file name="Items.php" hash="d9ce1a9bbbf33f7c266b2939b4a1d12e"/><file name="Order.php" hash="c130f62e60a52feee620193f2aa14d0b"/><file name="PayPalEC.php" hash="936af8c18938954caf8a196f48b9fc5a"/><file name="PayPalWPS.php" hash="59aae032bd1f763df04fecb50198ad35"/><file name="Payment.php" hash="258e8c42fb2ee84fa0619dcc2db54eee"/><file name="Result.php" hash="64759b5dcb022186f12c0cb043877af0"/><file name="Review.php" hash="d320736cc3a8ce67f7aae9b60b7c85eb"/><file name="Store.php" hash="2a3574a2162812eb6a9b80b9852347a0"/><file name="User.php" hash="76a6bb66aa098090fd5b25af7546569c"/></dir><dir name="controllers"><file name="IndexController.php" hash="c78762b71fcdf0560c6ba28e19a4b567"/></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>
18
  <compatible/>
19
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
20
  </package>