KANCART_MobileAPI - Version 2.0.8

Version Notes

Improve: Add related items and recommended items for Items.
Improve: Static block only categories will not be fetched.
Improve: Item's main image will be displayed as first image.
Bug Fix: Categories is not sorted by sort order.
Bug Fix: Custom shipping plugin compatibility issue.
Bug Fix: Can not fetch review on Magento 1.8.
Bug Fix: No quotes are available error occurred when new user first time checkout.
Bug Fix: Call to undefined method error occurred on Magento 1.5.

Download this release

Release Info

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


Code changes from version 2.0.7 to 2.0.8

app/code/community/Kancart/MobileApi/Model/Abstract.php CHANGED
@@ -110,6 +110,7 @@ abstract class Kancart_MobileApi_Model_Abstract {
110
  } elseif ($type == 'reward_label') {
111
  $type = 'info';
112
  }
 
113
  $PriceInfos[] = array(
114
  'title' => $item->getTitle(),
115
  'currency' => $currency,
@@ -121,10 +122,20 @@ abstract class Kancart_MobileApi_Model_Abstract {
121
  return $PriceInfos;
122
  }
123
 
 
 
 
 
 
124
  public function getRequest() {
125
  return Mage::app()->getRequest();
126
  }
127
 
 
 
 
 
 
128
  public function getOnepage() {
129
  return Mage::getSingleton('checkout/type_onepage');
130
  }
110
  } elseif ($type == 'reward_label') {
111
  $type = 'info';
112
  }
113
+
114
  $PriceInfos[] = array(
115
  'title' => $item->getTitle(),
116
  'currency' => $currency,
122
  return $PriceInfos;
123
  }
124
 
125
+ /**
126
+ * Retrieve request object
127
+ *
128
+ * @return Mage_Core_Controller_Request_Http
129
+ */
130
  public function getRequest() {
131
  return Mage::app()->getRequest();
132
  }
133
 
134
+ /**
135
+ * Retrieve Onepage object
136
+ *
137
+ * @return Mage_Checkout_Model_Type_Onepage
138
+ */
139
  public function getOnepage() {
140
  return Mage::getSingleton('checkout/type_onepage');
141
  }
app/code/community/Kancart/MobileApi/Model/Category.php CHANGED
@@ -60,17 +60,24 @@ class Kancart_MobileApi_Model_Category extends Kancart_MobileApi_Model_Abstract
60
 
61
  $collection = $category->getCollection()
62
  ->addNameToResult()
 
63
  ->addIsActiveFilter()
64
  ->addFieldToFilter('include_in_menu', 1)
65
  ->addPathsFilter($category->getPath() . '/')
66
  ->addAttributeToSelect('is_anchor')
67
- ->addOrderField('path');
68
 
69
  $collection->load();
70
  $categories = $collection->getItems();
71
 
72
  $layer = Mage::getSingleton('catalog/layer');
73
- foreach ($categories as &$cat) {
 
 
 
 
 
 
74
  $productCollection = $cat->getProductCollection();
75
  $layer->prepareProductCollection($productCollection);
76
  $cat->setProductCount($productCollection->getSize());
60
 
61
  $collection = $category->getCollection()
62
  ->addNameToResult()
63
+ ->addAttributeToSelect('display_mode')
64
  ->addIsActiveFilter()
65
  ->addFieldToFilter('include_in_menu', 1)
66
  ->addPathsFilter($category->getPath() . '/')
67
  ->addAttributeToSelect('is_anchor')
68
+ ->addOrderField('position');
69
 
70
  $collection->load();
71
  $categories = $collection->getItems();
72
 
73
  $layer = Mage::getSingleton('catalog/layer');
74
+ foreach ($categories as $key => &$cat) {
75
+ if ($cat->getDisplayMode() == Mage_Catalog_Model_Category::DM_PAGE) {
76
+ if (!$cat->hasChildren()) {
77
+ $collection->removeItemByKey($key);
78
+ continue;
79
+ }
80
+ }
81
  $productCollection = $cat->getProductCollection();
82
  $layer->prepareProductCollection($productCollection);
83
  $cat->setProductCount($productCollection->getSize());
app/code/community/Kancart/MobileApi/Model/Checkout.php CHANGED
@@ -34,7 +34,7 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
34
  $address = max($addressData['shipping_address'], $addressData['billing_address']);
35
 
36
  if ($address) { // update or add address
37
- $address = json_decode(htmlspecialchars_decode(stripslashes($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();
@@ -82,7 +82,7 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
82
  return array(true, '0x0000', $checkoutDetailArr);
83
  }
84
  }
85
-
86
  Mage::getSingleton('checkout/session')->setCartWasUpdated(false);
87
  $this->getOnepage()->initCheckout();
88
 
@@ -206,7 +206,7 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
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) {
@@ -229,7 +229,7 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
229
  $this->getOnepage()->getQuote()->collectTotals()->save();
230
  $this->getQuote()->setTotalsCollectedFlag(false)->collectTotals()->save();
231
  } else {
232
- $_SESSION['checkout_messages'][] = $block->__('Sorry, no quotes are available for this order at this time.');
233
  }
234
 
235
  return $shippingMethods;
@@ -297,8 +297,6 @@ class Kancart_MobileApi_Model_Checkout extends Kancart_MobileApi_Model_Abstract
297
  }
298
 
299
  try {
300
- Kancart::getModel('Coupon')->applyPromotion(); //apply mobile Promotion
301
-
302
  if ($this->getQuote()->getGrandTotal() == 0) {
303
  $payment_id = 'free';
304
  }
34
  $address = max($addressData['shipping_address'], $addressData['billing_address']);
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();
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
 
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) {
229
  $this->getOnepage()->getQuote()->collectTotals()->save();
230
  $this->getQuote()->setTotalsCollectedFlag(false)->collectTotals()->save();
231
  } else {
232
+ //$_SESSION['checkout_messages'][] = $block->__('Sorry, no quotes are available for this order at this time.');
233
  }
234
 
235
  return $shippingMethods;
297
  }
298
 
299
  try {
 
 
300
  if ($this->getQuote()->getGrandTotal() == 0) {
301
  $payment_id = 'free';
302
  }
app/code/community/Kancart/MobileApi/Model/Coupon.php DELETED
@@ -1,169 +0,0 @@
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/Discount.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
37
+ $totalDiscountAmount = $this->getRequest()->getParam('discount_amount', 0);
38
+ if ($totalDiscountAmount && !is_numeric($totalDiscountAmount)) {
39
+ $totalDiscountAmount = $address->getBaseSubtotal() * floatval($totalDiscountAmount) / 100;
40
+ }
41
+
42
+ $freeShipping = $this->getRequest()->getParam('coupon_free_ship');
43
+ if ($freeShipping && $freeShipping > 0 && $address->getShippingAmount()) {
44
+ $totalDiscountAmount+=$address->getShippingAmount();
45
+ }
46
+
47
+ if ($totalDiscountAmount <= 0) {
48
+ return $this;
49
+ }
50
+
51
+ $totalDiscountAmount += $address->getDiscountAmount();
52
+ $subtotalWithDiscount = $totalDiscountAmount + $address->getSubtotalWithDiscount();
53
+ $baseTotalDiscountAmount = $totalDiscountAmount + $address->getBaseDiscountAmount();
54
+ $baseSubtotalWithDiscount = $totalDiscountAmount + $address->getBaseSubtotalWithDiscount();
55
+
56
+ $address->setDiscountAmount($totalDiscountAmount);
57
+ $address->setSubtotalWithDiscount($subtotalWithDiscount);
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
+
66
+ /**
67
+ * Retrieve request object
68
+ *
69
+ * @return Mage_Core_Controller_Request_Http
70
+ */
71
+ public function getRequest() {
72
+ return Mage::app()->getRequest();
73
+ }
74
+
75
+ }
app/code/community/Kancart/MobileApi/Model/Item.php CHANGED
@@ -60,7 +60,7 @@ 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));
@@ -68,13 +68,14 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
68
 
69
  public function getItemBaseInfo() {
70
  $helper = Mage::helper('catalog/image');
 
71
  $this->item['item_id'] = $this->product->getId();
72
  $this->item['item_title'] = $this->product->getName();
73
  $this->item['item_url'] = $this->product->getProductUrl();
74
  $this->item['cid'] = $this->product->getCategoryIds();
75
  $this->item['qty'] = $this->product->getStockItem()->getQty();
76
- $this->item['thumbnail_pic_url'] = (string) $helper->init($this->product, $this->getProductImageType())->resize(320, 320);
77
- $this->item['main_pic_url'] = (string) $helper->init($this->product, $this->getProductImageType())->resize(640, 640);
78
  $this->item['is_virtual'] = $this->product->isVirtual();
79
  $this->item['item_status'] = $this->product->isSaleable() ? 'instock' : 'outofstock';
80
  if (!$this->product->getRatingSummary()) {
@@ -211,7 +212,7 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
211
  $this->item['detail_description'] = $_helper->productAttribute($this->product, $this->product->getDescription(), 'description');
212
  if (preg_match('/{{(.+)}}/i', $this->item['detail_description'])) {
213
  $host = ((isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . ($_SERVER['SERVER_PORT'] == 80 ? '' : $_SERVER['SERVER_PORT']);
214
- $this->item['detail_description'] = preg_replace('/(\<img[^\<^\>]+src\s*=\s*"){{(\w+)\s*url="(.+)}}/i', '$1' . $host . '/$2/$3', $this->item['detail_description']);
215
  }
216
  $this->item['specifications'] = $this->getProductFeature();
217
  }
@@ -248,13 +249,13 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
248
  private function getItemImageUrl($imageFile = null) {
249
  $imageType = $this->getProductImageType();
250
  $helper = Mage::helper('catalog/image');
251
- return (string) $helper->init($this->product, $imageType, $imageFile)->resize(640, 640);
252
  }
253
 
254
  public function getItemImages() {
255
  $this->item['item_imgs'] = array();
256
- if ($this->product->getMediaGalleryImages()) {
257
- $images = $this->product->getMediaGalleryImages();
258
  if (count($images) > 0) {
259
  $position = 0;
260
  foreach ($images as $image) {
@@ -262,8 +263,17 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
262
  $itemImg['img_id'] = $image->getId();
263
  $itemImg['img_url'] = $this->getItemImageUrl($image->getFile());
264
  $itemImg['position'] = ++$position;
265
- $this->item['item_imgs'][] = $itemImg;
 
 
 
 
 
266
  }
 
 
 
 
267
  return $this->item['item_imgs'];
268
  }
269
  }
@@ -276,34 +286,38 @@ class Kancart_MobileApi_Model_Item extends Kancart_MobileApi_Model_Abstract {
276
  }
277
 
278
  public function getRelatedItems() {
279
- $relatedItems = array();
280
- $products = $this->product->getRelatedProducts();
 
 
 
281
  if ($products) {
282
  $itemObject = Kancart::getModel('Item');
283
  foreach ($products as $product) {
284
- if (!$product->getName()) {
285
- $product->setName($product->getSku());
286
- }
287
  $itemObject->setProduct($product);
288
- $relatedItems[] = $itemObject->getItemBaseInfo();
 
 
289
  $itemObject->clear();
290
  }
291
  }
292
- $this->item['related_items'] = $relatedItems;
293
- return $relatedItems;
294
  }
295
 
296
  public function getRecommendedItems() {
297
  $items = array();
298
- $products = $this->product->getUpSellProducts();
 
 
 
299
  if ($products) {
300
  $itemObject = Kancart::getModel('Item');
301
  foreach ($products as $product) {
302
- if (!$product->getName()) {
303
- $product->setName($product->getSku());
304
- }
305
  $itemObject->setProduct($product);
306
- $items[] = $itemObject->getItemBaseInfo();
 
 
307
  $itemObject->clear();
308
  }
309
  }
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));
68
 
69
  public function getItemBaseInfo() {
70
  $helper = Mage::helper('catalog/image');
71
+ $helper->init($this->product, $this->getProductImageType())->keepFrame(false);
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()) {
212
  $this->item['detail_description'] = $_helper->productAttribute($this->product, $this->product->getDescription(), 'description');
213
  if (preg_match('/{{(.+)}}/i', $this->item['detail_description'])) {
214
  $host = ((isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . ($_SERVER['SERVER_PORT'] == 80 ? '' : $_SERVER['SERVER_PORT']);
215
+ $this->item['detail_description'] = preg_replace('/(\<img[^\<\>]+src\s*=\s*"){{(\w+)\s*url="(.+)}}/i', '$1' . $host . '/$2/$3', $this->item['detail_description']);
216
  }
217
  $this->item['specifications'] = $this->getProductFeature();
218
  }
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(false)->resize(640);
253
  }
254
 
255
  public function getItemImages() {
256
  $this->item['item_imgs'] = array();
257
+ $name = basename($this->product->getImageUrl());
258
+ if (($images = $this->product->getMediaGalleryImages())) {
259
  if (count($images) > 0) {
260
  $position = 0;
261
  foreach ($images as $image) {
263
  $itemImg['img_id'] = $image->getId();
264
  $itemImg['img_url'] = $this->getItemImageUrl($image->getFile());
265
  $itemImg['position'] = ++$position;
266
+ if ($position > 1 && $name == basename($image->getFile())) {
267
+ $first = $itemImg;
268
+ $first['position'] = 0;
269
+ } else {
270
+ $this->item['item_imgs'][] = $itemImg;
271
+ }
272
  }
273
+ if (isset($first)) {
274
+ $this->item['item_imgs'] = array_merge(array($first), $this->item['item_imgs']);
275
+ }
276
+
277
  return $this->item['item_imgs'];
278
  }
279
  }
286
  }
287
 
288
  public function getRelatedItems() {
289
+ $items = array();
290
+ $collection = $this->product->getRelatedProductCollection();
291
+ $layer = Mage::getSingleton('catalog/layer');
292
+ $layer->prepareProductCollection($collection);
293
+ $products = $collection->getItems();
294
  if ($products) {
295
  $itemObject = Kancart::getModel('Item');
296
  foreach ($products as $product) {
 
 
 
297
  $itemObject->setProduct($product);
298
+ $itemObject->getItemBaseInfo();
299
+ $itemObject->getItemPrices();
300
+ $items[] = $itemObject->getItem();
301
  $itemObject->clear();
302
  }
303
  }
304
+ $this->item['related_items'] = $items;
305
+ return $items;
306
  }
307
 
308
  public function getRecommendedItems() {
309
  $items = array();
310
+ $collection = $this->product->getUpSellProductCollection();
311
+ $layer = Mage::getSingleton('catalog/layer');
312
+ $layer->prepareProductCollection($collection);
313
+ $products = $collection->getItems();
314
  if ($products) {
315
  $itemObject = Kancart::getModel('Item');
316
  foreach ($products as $product) {
 
 
 
317
  $itemObject->setProduct($product);
318
+ $itemObject->getItemBaseInfo();
319
+ $itemObject->getItemPrices();
320
+ $items[] = $itemObject->getItem();
321
  $itemObject->clear();
322
  }
323
  }
app/code/community/Kancart/MobileApi/Model/Items.php CHANGED
@@ -47,7 +47,7 @@ class Kancart_MobileApi_Model_Items extends Kancart_MobileApi_Model_Abstract {
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 ($query) {
51
  // get by query
52
  $products = $this->getProductsByQuery($query, $pageNo, $pageSize, $order, $direction);
53
  } else if ($cid == -1) {
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) {
app/code/community/Kancart/MobileApi/Model/PayPalWPS.php CHANGED
@@ -82,7 +82,7 @@ class Kancart_MobileApi_Model_PayPalWPS extends Kancart_MobileApi_Model_Abstract
82
  * save order 2012-05-24
83
  * @return bool
84
  */
85
- public function saveOrder($payment, $comment = 'from mobile') {
86
  $request = $this->getRequest()
87
  ->setPost('payment', $payment)
88
  ->setActionName('index')
@@ -116,7 +116,7 @@ class Kancart_MobileApi_Model_PayPalWPS extends Kancart_MobileApi_Model_Abstract
116
  }
117
  }
118
 
119
- public function placeOrder($payment, $comment = 'from mobile') {
120
  $result = FALSE;
121
  $mesg = NULL;
122
  try {
82
  * save order 2012-05-24
83
  * @return bool
84
  */
85
+ public function placeOrder($payment, $comment = 'from mobile') {
86
  $request = $this->getRequest()
87
  ->setPost('payment', $payment)
88
  ->setActionName('index')
116
  }
117
  }
118
 
119
+ public function saveOrder($payment, $comment = 'from mobile') {
120
  $result = FALSE;
121
  $mesg = NULL;
122
  try {
app/code/community/Kancart/MobileApi/Model/Review.php CHANGED
@@ -25,10 +25,40 @@
25
  class Kancart_MobileApi_Model_Review extends Kancart_MobileApi_Model_Abstract {
26
 
27
  public function kancart_reviews_get() {
28
- $apidata = $this->getRequest()->getParams();
29
- $item_id = $apidata['item_id'];
30
- $rates = $this->getRates($item_id);
31
- return array(true, '0x0000', $rates);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  }
33
 
34
  public function kancart_review_add() {
@@ -82,42 +112,6 @@ class Kancart_MobileApi_Model_Review extends Kancart_MobileApi_Model_Abstract {
82
  }
83
  }
84
 
85
- public function getRates($productId, $storeId = 0) {
86
- $collection = Mage::getResourceModel('review/review_collection')
87
- ->addEntityFilter('product', $productId)
88
- ->addStoreFilter(Mage::app()->getStore()->getId())
89
- ->addStatusFilter('approved')
90
- ->setDateOrder();
91
- if (!$collection) {
92
- $result = array();
93
- $result['total_results'] = 0;
94
- $result['trade_rates'] = array();
95
- return $result;
96
- }
97
- $tradeRates = array();
98
- foreach ($collection->getItems() as $review) {
99
- $tradeRate = array();
100
- $tradeRate['item_id'] = $productId;
101
- $tradeRate['uname'] = $review->getNickname();
102
- $tradeRate['rate_title'] = $review->getTitle();
103
- $tradeRate['rate_content'] = $review->getDetail();
104
- $tradeRate['rate_date'] = $review->getCreatedAt();
105
- $tradeRate['rate_score'] = '0';
106
- $summary = Mage::getModel('rating/rating')->getReviewSummary($review->getId());
107
- if ($summary->getCount() > 0) {
108
- $rating = round($summary->getSum() / $summary->getCount() / 20);
109
- }
110
- if ($rating) {
111
- $tradeRate['rate_score'] = (string) $rating;
112
- }
113
- array_push($tradeRates, $tradeRate);
114
- }
115
- $result = array();
116
- $result['total_results'] = $collection->getSize();
117
- $result['trade_rates'] = $tradeRates;
118
- return $result;
119
- }
120
-
121
  protected function _loadProduct($productId) {
122
  if (!$productId) {
123
  return false;
25
  class Kancart_MobileApi_Model_Review extends Kancart_MobileApi_Model_Abstract {
26
 
27
  public function kancart_reviews_get() {
28
+ $productId = $this->getRequest()->getParam('item_id');
29
+ $pageNo = $this->getRequest()->getParam('page_no', 1);
30
+ $pageSize = $this->getRequest()->getParam('page_size', 10);
31
+ $block = Mage::getBlockSingleton('review/product_view');
32
+ $block->setProductId($productId);
33
+ $collection = $block->getReviewsCollection()
34
+ ->setCurPage($pageNo)
35
+ ->setPageSize($pageSize);
36
+
37
+ $rate = Mage::getModel('rating/rating');
38
+ $tradeRates = array();
39
+ foreach ($collection->getItems() as $review) {
40
+ $summary = $rate->getReviewSummary($review->getId());
41
+ if ($summary->getCount() > 0) {
42
+ $rating = round($summary->getSum() / $summary->getCount() / 20);
43
+ } else {
44
+ $rating = 0;
45
+ }
46
+
47
+ $tradeRates[] = array(
48
+ 'uname' => $review->getNickname(),
49
+ 'item_id' => $productId,
50
+ 'rate_score' => $rating,
51
+ 'rate_content' => $review->getDetail(),
52
+ 'rate_date' => $review->getCreatedAt(),
53
+ 'rate_title' => $review->getTitle()
54
+ );
55
+ }
56
+
57
+ $result = array();
58
+ $result['total_results'] = $collection->getSize();
59
+ $result['trade_rates'] = $tradeRates;
60
+
61
+ return array(true, '0x0000', $result);
62
  }
63
 
64
  public function kancart_review_add() {
112
  }
113
  }
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  protected function _loadProduct($productId) {
116
  if (!$productId) {
117
  return false;
app/code/community/Kancart/MobileApi/Model/Store.php CHANGED
@@ -276,6 +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
  'login_by_mail' => true
280
  );
281
  }
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/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.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__)));
@@ -69,6 +69,8 @@ class Kancart_MobileApi_IndexController extends Mage_Core_Controller_Front_Actio
69
  Mage::app()->getStore()->setCurrentCurrencyCode($curency);
70
  }
71
 
 
 
72
  $this->compilerPlugin(); //To prevent user backstage collapse after compiled
73
  }
74
 
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
  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
  }
76
 
package.xml CHANGED
@@ -1,7 +1,7 @@
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,12 +9,19 @@
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>
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
  <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>