Massale_Facebook_Connector - Version 1.0.0.7

Version Notes

stable

Download this release

Release Info

Developer Magestore
Extension Massale_Facebook_Connector
Version 1.0.0.7
Comparing to
See all releases


Code changes from version 0.1.0 to 1.0.0.7

app/code/local/Magestore/Mageconnector/Exception.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * Class manipulate with Exception in Magestore_Mageconnector module
4
  *
@@ -6,6 +7,8 @@
6
  * @package Magestore_Mageconnector
7
  * @author Nguyen Minh Dung (http://oss.com.vn)
8
  */
9
- class Magestore_Mageconnector_Exception extends Mage_Core_Exception
10
- {
 
 
11
  }
1
  <?php
2
+
3
  /**
4
  * Class manipulate with Exception in Magestore_Mageconnector module
5
  *
7
  * @package Magestore_Mageconnector
8
  * @author Nguyen Minh Dung (http://oss.com.vn)
9
  */
10
+ class Magestore_Mageconnector_Exception extends Mage_Core_Exception {
11
+ const BASE_URL_INVALID = 'Store Base Url is invalid';
12
+ const CATEGORY_INVALID = 'There is no found category';
13
+ const NO_PRODUCT = 'There is no found product';
14
  }
app/code/local/Magestore/Mageconnector/Helper/Data.php CHANGED
@@ -1,71 +1,218 @@
1
  <?php
2
 
3
- class Magestore_Mageconnector_Helper_Data extends Mage_Core_Helper_Abstract
4
- {
5
- public function getListStoreView() {
6
- $collection = Mage::getResourceModel('core/website_collection');
7
- $default_view = Mage::getStoreConfig('mageconnector/store/default_store_view');
8
-
9
- $xml = '<?xml version="1.0" encoding="utf-8"?><views>';
10
-
11
- $i = 0;
12
- foreach($collection as $website) {
13
-
14
- $goupcollection = $website->getGroupCollection();
15
- foreach($goupcollection as $group) {
16
-
17
- $storecollection = $group->getStoreCollection();
18
- foreach ($storecollection as $store) {
19
- $data = $store->toArray();
20
-
21
- $isDefault = false;
22
- if (($default_view != '' && $default_view == $data['code']) ||
23
- ($default_view == '' && $website->__get('is_default') &&
24
- $website->__get('default_group_id') == $group->getId() &&
25
- $group->__get('default_store_id') == $store->getId())
26
- ) {
27
- $isDefault = true;
28
- }
29
-
30
- $totalProducts = count(Mage::getModel('catalog/product')->getCollection()
31
- ->addAttributeToSelect('name')
32
- ->addStoreFilter($store->getId())
33
- ->addAttributeToFilter(array(
34
- array(
35
- 'attribute' => 'name',
36
- 'like' => '%%'
37
- ),
38
- array(
39
- 'attribute' => 'url_key',
40
- 'like' => '%%'
41
- ),
42
- array(
43
- 'attribute' => 'short_description',
44
- 'like' => '%%'
45
- )
46
- ))
47
- ->addAttributeToFilter(array(
48
- array(
49
- 'attribute' => 'visibility',
50
- 'in' => array(3,4)
51
- )
52
- ))
53
- ->addFieldToFilter("status", 1)
54
- );
55
-
56
- $xml .= '<view>'
57
- .'<code><![CDATA['.$data['code'].']]></code>'
58
- .'<name><![CDATA['.$data['name'].']]></name>'
59
- .'<is_active>'.$data['is_active'].'</is_active>'
60
- .'<is_default>'.$isDefault.'</is_default>'
61
- .'<total_products>'.$totalProducts.'</total_products>'
62
- .'<order>'.(++$i).'</order>'
63
- .'</view>';
64
- }
65
- }
66
- }
67
-
68
- $xml .= '</views>';
69
  return $xml;
70
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
1
  <?php
2
 
3
+ class Magestore_Mageconnector_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ /**
6
+ * Get list store view code by store base url. Store base url is url of registed store
7
+ *
8
+ * @param string $baseUrl
9
+ * @return string
10
+ */
11
+ public function getListStoreViewCodesByStoreBaseUrl($baseUrl) {
12
+ $cWebsites = Mage::getResourceModel('core/website_collection');
13
+ $xml = '<?xml version="1.0" encoding="utf-8"?><massale-views>';
14
+ $baseUrl = str_replace('www.', '', $baseUrl);
15
+ $baseUrl = str_replace('http://', '', $baseUrl);
16
+ $baseUrl = str_replace('https://', '', $baseUrl);
17
+
18
+ $i = 0;
19
+ foreach ($cWebsites as $website) {
20
+ $cGroups = $website->getGroupCollection();
21
+ foreach ($cGroups as $group) {
22
+ $cStores = $group->getStoreCollection();
23
+ foreach ($cStores as $store) {
24
+ if (!$store->getIsActive()) {
25
+ continue;
26
+ }
27
+ $storeBaseUrlConfig = Mage::app()->getStore($store->getId())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
28
+ $storeBaseUrlConfig = str_replace('www.', '', $storeBaseUrlConfig);
29
+ $storeBaseUrlConfig = str_replace('http://', '', $storeBaseUrlConfig);
30
+ $storeBaseUrlConfig = str_replace('https://', '', $storeBaseUrlConfig);
31
+
32
+ if ($storeBaseUrlConfig != $baseUrl) {
33
+ continue;
34
+ }
35
+ $isDefault = false;
36
+ if ($website->getIsDefault() &&
37
+ $website->getDefaultGroupId() == $group->getId() &&
38
+ $group->getDefaultStoreId() == $store->getId()) {
39
+ $isDefault = true;
40
+ }
41
+
42
+ if ($store->getIsActive()) {
43
+ $xml .= '<view order="#' . (++$i) . '">'
44
+ . '<code><![CDATA[' . $store->getCode() . ']]></code>'
45
+ . '<name><![CDATA[' . $store->getName() . ']]></name>'
46
+ . '<is_default>' . $isDefault . '</is_default>'
47
+ . '</view>';
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ $xml .= '</massale-views>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  return $xml;
55
+ }
56
+
57
+ private static $dStore = null;
58
+
59
+ /**
60
+ * Get Defaule Store By Store Base Url
61
+ *
62
+ * @param string $baseUrl
63
+ * @return Mage_Core_Model_Store
64
+ */
65
+ public function getDefaultStoreByStoreBaseUrl($baseUrl) {
66
+ if (is_null(self::$dStore)) {
67
+ $cWebsites = Mage::getResourceModel('core/website_collection');
68
+ $baseUrl = str_replace('www.', '', $baseUrl);
69
+ $baseUrl = str_replace('http://', '', $baseUrl);
70
+ $baseUrl = str_replace('https://', '', $baseUrl);
71
+
72
+ foreach ($cWebsites as $website) {
73
+ $cGroups = $website->getGroupCollection();
74
+ foreach ($cGroups as $group) {
75
+ $cStores = $group->getStoreCollection();
76
+ foreach ($cStores as $store) {
77
+ if (!$store->getIsActive()) {
78
+ continue;
79
+ }
80
+ $storeBaseUrlConfig = Mage::app()->getStore($store->getId())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
81
+ $storeBaseUrlConfig = str_replace('www.', '', $storeBaseUrlConfig);
82
+ $storeBaseUrlConfig = str_replace('http://', '', $storeBaseUrlConfig);
83
+ $storeBaseUrlConfig = str_replace('https://', '', $storeBaseUrlConfig);
84
+
85
+ if ($storeBaseUrlConfig != $baseUrl) {
86
+ continue;
87
+ }
88
+
89
+ if (is_null(self::$dStore)) {
90
+ self::$dStore = $store;
91
+ }
92
+ if ($website->getIsDefault() &&
93
+ $website->getDefaultGroupId() == $group->getId() &&
94
+ $group->getDefaultStoreId() == $store->getId()) {
95
+ self::$dStore = $store;
96
+ return $store;
97
+ }
98
+ }
99
+ }
100
+ }
101
+ }
102
+ if (is_null(self::$dStore)) {
103
+ throw new Magestore_Mageconnector_Exception(Magestore_Mageconnector_Exception::BASE_URL_INVALID);
104
+ } else {
105
+ return self::$dStore;
106
+ }
107
+ }
108
+
109
+ public function update() {
110
+ return Magestore_Mageconnector_Autoupdate::run();
111
+ }
112
+
113
+ /**
114
+ * Get store by base Url
115
+ *
116
+ * @param string $baseUrl
117
+ * @param string $storeCode
118
+ * @return Mage_Core_Model_Store
119
+ */
120
+ public function getStoreByBaseUrl($baseUrl, $storeCode = null) {
121
+ static $_baseUrl = null, $_storeCode = null, $store = null;
122
+ if ($_baseUrl == $baseUrl && $_storeCode == $storeCode && $store instanceof Mage_Core_Model_Store) {
123
+ return $store;
124
+ }
125
+
126
+ if (is_null($storeCode) || $storeCode == '') {
127
+ $store = $this->getDefaultStoreByStoreBaseUrl($baseUrl);
128
+ } else {
129
+ $store = Mage::getModel('core/store')->load($storeCode);
130
+ $baseUrl = str_replace('www.', '', $baseUrl);
131
+ $baseUrl = str_replace('http://', '', $baseUrl);
132
+ $baseUrl = str_replace('https://', '', $baseUrl);
133
+ $storeBaseUrlConfig = Mage::app()->getStore($store->getId())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
134
+ $storeBaseUrlConfig = str_replace('www.', '', $storeBaseUrlConfig);
135
+ $storeBaseUrlConfig = str_replace('http://', '', $storeBaseUrlConfig);
136
+ $storeBaseUrlConfig = str_replace('https://', '', $storeBaseUrlConfig);
137
+
138
+ if ($storeBaseUrlConfig != $baseUrl) {
139
+ throw new Magestore_Mageconnector_Exception(Magestore_Mageconnector_Exception::BASE_URL_INVALID);
140
+ }
141
+ }
142
+ return $store;
143
+ }
144
+
145
+ /**
146
+ * Prepare url $url to appropriate with baseUrl
147
+ *
148
+ * @param string $baseUrl
149
+ * @param string $url
150
+ * @param string $storeCode
151
+ * @return string
152
+ */
153
+ public function prepareUrl($baseUrl, $url, $storeCode = null) {
154
+ $hasIndexInUrl = false;
155
+ if (str_replace('index.php', '', $url) != $url) {
156
+ $hasIndexInUrl = true;
157
+ $url = explode('index.php', $url);
158
+ $url = ltrim($url[1], '/');
159
+ } else {
160
+ $url = str_replace($baseUrl, '', $url);
161
+ }
162
+ if ($this->currentStoreAddStoreCodeInUrl()) {
163
+ // $code = $this->getStoreCodeInCurrentUrl();
164
+ // $url = str_replace($code, '', $url);
165
+
166
+ $url = str_replace($storeCode . '/', '', $url);
167
+ return $baseUrl . ($hasIndexInUrl ? 'index.php/' : '') . $storeCode . '/' . $url;
168
+ } else if (!is_null($storeCode)) {
169
+ $defaultStore = Mage::helper('mageconnector')->getDefaultStoreByStoreBaseUrl($baseUrl);
170
+ if ($storeCode == $defaultStore->getCode() || strpos($url, '?___store=') > 0) {
171
+ return $baseUrl . ($hasIndexInUrl ? 'index.php/' : '') . $url;
172
+ } else {
173
+ return $baseUrl . ($hasIndexInUrl ? 'index.php/' : '') . $url . '?___store=' . $storeCode;
174
+ }
175
+ } else {
176
+ return $baseUrl . ($hasIndexInUrl ? 'index.php/' : '') . $url;
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Check current website add store code in url or not
182
+ *
183
+ * @return bool
184
+ */
185
+ public function currentStoreAddStoreCodeInUrl() {
186
+ static $webUrlUseStoreCode = null;
187
+ if (is_null($webUrlUseStoreCode)) {
188
+ $webUrlUseStoreCode = Mage::getStoreConfig('web/url/use_store');
189
+ }
190
+ return $webUrlUseStoreCode;
191
+ }
192
+
193
+ /**
194
+ *
195
+ * @param string $baseUrl
196
+ * @return string
197
+ */
198
+ public function getStoreCodeInCurrentUrl() {
199
+ static $storeCode = '';
200
+ if ($storeCode == '' && $this->currentStoreAddStoreCodeInUrl()) {
201
+ $parts = explode('index.php/', Mage::getUrl());
202
+ $parts = explode('/', $parts[1]);
203
+ $storeCode = $parts[0] . '/';
204
+ }
205
+ return $storeCode;
206
+ }
207
+
208
+ /**
209
+ * Edit current store to appropriate with baseUrl and storeCode
210
+ *
211
+ * @param string $baseUrl
212
+ * @param string $storeCode
213
+ */
214
+ public function editCurrentStore($baseUrl, $storeCode = null) {
215
+ $store = $this->getStoreByBaseUrl($baseUrl, $storeCode);
216
+ Mage::app()->setCurrentStore($store);
217
+ }
218
  }
app/code/local/Magestore/Mageconnector/Model/Abstract.php DELETED
@@ -1,42 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Model abstract class for module
5
- *
6
- * @category Magestore
7
- * @package Magestore_Mageconnector
8
- * @author Nguyen Minh Dung (http://oss.com.vn)
9
- */
10
- abstract class Magestore_Mageconnector_Model_Abstract {
11
-
12
- /**
13
- * Export Product to XML Data by store code
14
- *
15
- * @param string $store_code
16
- * @return array Store array data
17
- */
18
- public function getStore($store_code = null) {
19
- if (is_null($store_code) || $store_code == '') {
20
- $store_code = Mage::getStoreConfig('mageconnector/store/default_store_view');
21
-
22
- if ($store_code == '') {
23
- $options = Mage::getModel('mageconnector/importstore')->toOptionArray();
24
-
25
- foreach ($options as $item) {
26
- $store_code = $item['value'];
27
- break;
28
- }
29
- }
30
- }
31
-
32
- $resource = Mage::getSingleton('core/resource');
33
- $read = $resource->getConnection("core_read");
34
- $getStore = Mage::getResourceModel('core/store_collection')
35
- ->getSelect()
36
- ->where('code = ?', $store_code);
37
-
38
- $store = $read->fetchRow($getStore);
39
- return $store;
40
- }
41
-
42
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Magestore/Mageconnector/Model/Cart.php DELETED
@@ -1,268 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Export Category data to xml data
5
- *
6
- * @category Magestore
7
- * @package Magestore_Mageconnector
8
- * @author Nguyen Minh Dung (http://oss.com.vn)
9
- */
10
- class Magestore_Mageconnector_Model_Cart extends Magestore_Mageconnector_Model_Abstract {
11
-
12
- /**
13
- * Initialize product instance from request data
14
- *
15
- * @return Mage_Catalog_Model_Product || false
16
- */
17
- protected function _initProduct() {
18
- $productId = (int) $_REQUEST['product'];
19
- if ($productId) {
20
- try {
21
- $view_code = $_REQUEST['view'];
22
- } catch (Exception $e) {
23
- $view_code = '';
24
- }
25
- $store = $this->getStore($view_code);
26
- $storeId = $store['store_id'];
27
-
28
- $product = Mage::getModel('catalog/product')
29
- ->setStoreId($storeId)
30
- ->load($productId);
31
- if ($product->getId()) {
32
- return $product;
33
- }
34
- }
35
- return false;
36
- }
37
-
38
- public function addToCart() {
39
- $cart = Mage::getSingleton('checkout/cart');
40
- $params = $_REQUEST;
41
- try {
42
- if (isset($params['qty'])) {
43
- $filter = new Zend_Filter_LocalizedToNormalized(
44
- array('locale' => Mage::app()->getLocale()->getLocaleCode())
45
- );
46
- $params['qty'] = $filter->filter($params['qty']);
47
- }
48
-
49
- $product = $this->_initProduct();
50
- try {
51
- $related = $params['related_product'];
52
- } catch (Exception $e) {
53
- $related = null;
54
- }
55
-
56
- /**
57
- * Check product availability
58
- */
59
- if (!$product) {
60
- return false;
61
- }
62
-
63
- $cart->addProduct($product, $params);
64
- if (!empty($related) && !is_null($related)) {
65
- $cart->addProductsByIds(explode(',', $related));
66
- }
67
-
68
- $cart->save();
69
-
70
- Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
71
-
72
- return true;
73
- } catch (Exception $e) {
74
- Zend_Debug::dump($e);
75
- die();
76
- }
77
- return false;
78
- }
79
-
80
- public function updateCart() {
81
- try {
82
- $cartData = $_REQUEST['cart'];
83
- if (is_array($cartData)) {
84
- $filter = new Zend_Filter_LocalizedToNormalized(
85
- array('locale' => Mage::app()->getLocale()->getLocaleCode())
86
- );
87
- foreach ($cartData as $index => $data) {
88
- if (isset($data['qty'])) {
89
- $cartData[$index]['qty'] = $filter->filter($data['qty']);
90
- }
91
- }
92
- $cart = Mage::getSingleton('checkout/cart');
93
- if (!$cart->getCustomerSession()->getCustomer()->getId() && $cart->getQuote()->getCustomerId()) {
94
- $cart->getQuote()->setCustomerId(null);
95
- }
96
- $cart->updateItems($cartData)
97
- ->save();
98
- }
99
- Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
100
- return true;
101
- } catch (Exception $e) {
102
-
103
- }
104
- return false;
105
- }
106
-
107
- public function deleteCartItem() {
108
- $id = $_REQUEST['item'];
109
- if ($id) {
110
- try {
111
- $cart = Mage::getSingleton('checkout/cart')->removeItem($id)
112
- ->save();
113
- return true;
114
- } catch (Exception $e) {
115
-
116
- }
117
- }
118
- return false;
119
- }
120
-
121
- public function exportXml() {
122
- $cartXML = '<?xml version="1.0" encoding="UTF-8"?><massale-cart>';
123
-
124
- $quote = Mage::getSingleton('checkout/session')->getQuote();
125
- $items = $quote->getAllVisibleItems();
126
-
127
- if (count($items) > 0) {
128
- $cartXML .= '<products>';
129
- $i = 0;
130
- foreach ($items as $item) {
131
- $product = $item->getProduct();
132
-
133
- switch ($product->getTypeId()) {
134
- case "configurable":
135
- $blockId = "checkout/cart_item_renderer_configurable";
136
- break;
137
- case "bundle":
138
- $blockId = "bundle/checkout_cart_item_renderer";
139
- break;
140
- case "downloadable":
141
- $blockId = "downloadable/checkout_cart_item_renderer";
142
- break;
143
- default:
144
- $blockId = "checkout/cart_item_renderer";
145
- }
146
-
147
- $block = Mage::getBlockSingleton($blockId)
148
- ->setItem($item);
149
-
150
- $cartXML .= '<product>'
151
- . '<order>#' . (++$i) . '</order>'
152
- . '<id>' . $block->getItem()->getId() . '</id>'
153
- . '<name><![CDATA[' . $block->htmlEscape($block->getProductName()) . ']]></name>'
154
- . '<image><![CDATA[' . $block->getProductThumbnail() . ']]></image>'
155
- . '<url_key><![CDATA[' . $product->getUrlKey() . ']]></url_key>';
156
-
157
- if ($_options = $block->getOptionList()):
158
- $cartXML .= '<options>';
159
- foreach ($_options as $_option):
160
- $_formatedOptionValue = $block->getFormatedOptionValue($_option);
161
- $cartXML .= '<option>'
162
- . '<label><![CDATA[' . $block->htmlEscape($_option['label']) . ']]></label>'
163
- . '<value><![CDATA[' . $_formatedOptionValue['value'] . ']]></value>'
164
- . '</option>'
165
- ;
166
- endforeach;
167
- $cartXML .= '</options>';
168
- endif;
169
-
170
- $cartXML .= '<qty>' . $item->getQty() . '</qty>';
171
-
172
- $price = Mage::helper('core')
173
- ->currency($item->getPrice(), true, false);
174
- $rowsubtotal = Mage::helper('core')
175
- ->currency($item->getRowTotal(), true, false);
176
-
177
- $cartXML .= '<price><![CDATA[' . $price . ']]></price>';
178
- $cartXML .= '<subtotal><![CDATA[' . $rowsubtotal . ']]></subtotal>';
179
- $cartXML .= '</product>';
180
- }
181
- $cartXML .= '</products>';
182
-
183
- if ($quote->getCouponCode() != '') {
184
- $cartXML .= '<coupon>'
185
- . '<code><![CDATA[' . $quote->getCouponCode() . ']]></code>'
186
- . '<label><![CDATA[' . $quote->getCouponCode() . ']]></label>'
187
- . '</coupon>';
188
- }
189
-
190
- $subtotal = $quote->getSubtotal();
191
- $subtotal_withdiscount = $quote->getSubtotalWithDiscount();
192
-
193
- $discount = floatval($subtotal_withdiscount) - floatval($subtotal);
194
- $subtotal = Mage::helper('core')
195
- ->currency($subtotal, true, false);
196
- $cartXML .= '<subtotal><![CDATA[' . $subtotal . ']]></subtotal>';
197
-
198
- if ($discount != 0) {
199
- $discount = Mage::helper('core')
200
- ->currency($discount, true, false);
201
- $cartXML .= '<discount><![CDATA[' . $discount . ']]></discount>';
202
- }
203
-
204
- $grandtotal = $quote->getGrandTotal();
205
- $tax = $grandtotal - $subtotal_withdiscount;
206
-
207
- if ($tax != 0) {
208
- $tax = Mage::helper('core')
209
- ->currency($tax, true, false);
210
- $cartXML .= '<tax><![CDATA[' . $tax . ']]></tax>';
211
- }
212
- $grandtotal = Mage::helper('core')
213
- ->currency($grandtotal, true, false);
214
-
215
- $cartXML .= '<grandtotal><![CDATA[' . $grandtotal . ']]></grandtotal>';
216
- } else {
217
- $cartXML .= 'empty';
218
- }
219
- $cartXML .= '</massale-cart>';
220
- return $cartXML;
221
- }
222
-
223
- public function applyCoupon() {
224
- if (!Mage::getSingleton('checkout/cart')->getQuote()->getItemsCount()) {
225
- return false;
226
- }
227
-
228
- $couponCode = $_REQUEST['coupon_code'];
229
- $oldCouponCode = Mage::getSingleton('checkout/cart')->getQuote()->getCouponCode();
230
-
231
- if (!strlen($couponCode) && !strlen($oldCouponCode)) {
232
- return false;
233
- }
234
-
235
- try {
236
- Mage::getSingleton('checkout/cart')->getQuote()->getShippingAddress()->setCollectShippingRates(true);
237
- Mage::getSingleton('checkout/cart')->getQuote()->setCouponCode(strlen($couponCode) ? $couponCode : '')
238
- ->collectTotals()
239
- ->save();
240
-
241
- if ($couponCode) {
242
- if ($couponCode == Mage::getSingleton('checkout/cart')->getQuote()->getCouponCode()) {
243
- return true;
244
- }
245
- }
246
- } catch (Exception $e) {
247
-
248
- }
249
-
250
- return false;
251
- }
252
-
253
- public function cancelCoupon() {
254
- try {
255
- Mage::getSingleton('checkout/cart')->getQuote()->getShippingAddress()->setCollectShippingRates(true);
256
- Mage::getSingleton('checkout/cart')->getQuote()->setCouponCode('')
257
- ->collectTotals()
258
- ->save();
259
-
260
- return true;
261
- } catch (Exception $e) {
262
-
263
- }
264
-
265
- return false;
266
- }
267
-
268
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Magestore/Mageconnector/Model/Category.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * Export Category data to xml data
4
  *
@@ -6,69 +7,104 @@
6
  * @package Magestore_Mageconnector
7
  * @author Nguyen Minh Dung (http://oss.com.vn)
8
  */
9
- class Magestore_Mageconnector_Model_Category extends Magestore_Mageconnector_Model_Abstract
10
- {
11
- /**
12
- * Export Category to XML Data by store code
13
- *
14
- * @param string $store_code
15
- */
16
- public function exportXML($store_code = null) {
17
- $store = $this->getStore($store_code);
18
- $storeId = $store['store_id'];
19
-
20
- $group = Mage::getModel('core/store_group')->load($store['group_id']);
21
- $rootCategoryId = $group->getRootCategoryId();
22
-
23
- $xml = '<?xml version="1.0"?><categories>';
24
-
25
- $category = Mage::getModel('catalog/category')
26
- ->setStoreId($storeId)
27
- ->load($rootCategoryId);
28
-
29
- if ($category instanceof Mage_Catalog_Model_Category) {
30
- $data = $category->toArray();
31
- if (array_key_exists('entity_id', $data)) {
32
- $this->pushChildrenCategory($category
33
- ->getChildrenCategories(), $xml, $storeId);
34
- }
35
  }
36
-
37
- $xml .= '</categories>';
38
- return $xml;
39
- }
40
-
41
- private function pushChildrenCategory($categoryCollection, &$xml, $storeId) {
42
- foreach($categoryCollection as $category) {
43
- if ($category instanceof Mage_Catalog_Model_Category) {
44
- if ($category->getIsActive()) {
45
- $productList = $category->getProductCollection();
46
- $total_products = count($category
47
- ->setStoreId($storeId)
48
- ->getProductCollection()
49
- ->addAttributeToFilter(array(
50
- array(
51
- 'attribute' => 'visibility',
52
- 'in' => array(2,4)
53
- )
54
- ))
55
- );
56
- $url_key = $category->getRequestPath();
57
- $url_key = str_replace('.html', '', $url_key);
58
- $parts = split('/', $url_key);
59
- $url_key = $parts[count($parts) - 1];
60
-
61
- $xml .= '<category>'
62
- .'<id>'.$category->getId().'</id>'
63
- .'<name><![CDATA['.$category->getName().']]></name>'
64
- .'<url_key><![CDATA['.$url_key.']]></url_key>'
65
- .'<url><![CDATA['.$category->getUrl().']]></url>'
66
- .'<total_products>'.$total_products.'</total_products>'
67
- .'<children>';
68
- $this->pushChildrenCategory($category->getChildrenCategories(), $xml, $storeId);
69
- $xml .= '</children></category>';
70
- }
71
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
73
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  }
1
  <?php
2
+
3
  /**
4
  * Export Category data to xml data
5
  *
7
  * @package Magestore_Mageconnector
8
  * @author Nguyen Minh Dung (http://oss.com.vn)
9
  */
10
+ class Magestore_Mageconnector_Model_Category {
11
+
12
+ /**
13
+ * Export Category to XML Data by store code
14
+ *
15
+ * @return string
16
+ */
17
+ public function exportXML() {
18
+ $store = Mage::app()->getStore();
19
+ $group = Mage::getModel('core/store_group')->load($store->getGroupId());
20
+ $xml = '<?xml version="1.0"?><massale-categories>';
21
+ $category = Mage::getModel('catalog/category')
22
+ ->setStoreId($store->getId())
23
+ ->load($group->getRootCategoryId());
24
+
25
+ if ($category instanceof Mage_Catalog_Model_Category) {
26
+ $this->pushChildrenCategory($category->getChildrenCategories(), $xml, $store);
 
 
 
 
 
 
 
 
 
27
  }
28
+ $xml .= '</massale-categories>';
29
+ return $xml;
30
+ }
31
+
32
+ /**
33
+ *
34
+ * @param string $baseUrl
35
+ * @param string $categoryCollection
36
+ * @param string $xml
37
+ * @param Mage_Core_Model_Store $store
38
+ */
39
+ private function pushChildrenCategory($categoryCollection, &$xml, $store) {
40
+ foreach ($categoryCollection as $category) {
41
+ if ($category instanceof Mage_Catalog_Model_Category) {
42
+ if ($category->getIsActive()) {
43
+ $totalProducts = count(
44
+ $category->setStoreId($store->getId())
45
+ ->getProductCollection()
46
+ ->addAttributeToFilter(
47
+ array(
48
+ array(
49
+ 'attribute' => 'visibility',
50
+ 'in' => array(2, 4)
51
+ )
52
+ )
53
+ )
54
+ );
55
+ $urlKey = $category->getUrlKey();
56
+ if ($urlKey == '') {
57
+ $url = $category->getUrlPath();
58
+ $urlParts = explode('/', $url);
59
+ $urlParts = $urlParts[count($urlParts) - 1];
60
+ $urlParts = explode('.html', $urlParts);
61
+ $urlKey = $urlParts[0];
62
+ }
63
+ // For Magento 1.5
64
+ if ($urlKey == '') {
65
+ $url = $category->getRequestPath();
66
+ $urlParts = explode('/', $url);
67
+ $urlParts = $urlParts[count($urlParts) - 1];
68
+ $urlParts = explode('.html', $urlParts);
69
+ $urlKey = $urlParts[0];
70
+ }
71
+
72
+ $xml .= '<category>'
73
+ . '<id>' . $category->getId() . '</id>'
74
+ . '<name><![CDATA[' . $category->getName() . ']]></name>'
75
+ . '<url_key><![CDATA[' . $urlKey . ']]></url_key>'
76
+ . '<total_products>' . $totalProducts . '</total_products>'
77
+ . '<children>';
78
+ $this->pushChildrenCategory($category->getChildrenCategories(), $xml, $store);
79
+ $xml .= '</children></category>';
80
+ }
81
+ }
82
  }
83
+ }
84
+
85
+ public function getListActiveCategoryIdsByStoreView() {
86
+ $store = Mage::app()->getStore();
87
+ $group = Mage::getModel('core/store_group')->load($store->getGroupId());
88
+ $category = Mage::getModel('catalog/category')
89
+ ->setStoreId($store->getId())
90
+ ->load($group->getRootCategoryId());
91
+
92
+ $list = array();
93
+ if ($category instanceof Mage_Catalog_Model_Category) {
94
+ $this->pushActiveChildrenCategory($category->getChildrenCategories(), $list, $store);
95
+ }
96
+ return $list;
97
+ }
98
+
99
+ private function pushActiveChildrenCategory($categoryCollection, &$list, $store) {
100
+ foreach ($categoryCollection as $category) {
101
+ if ($category instanceof Mage_Catalog_Model_Category) {
102
+ if ($category->getIsActive()) {
103
+ $list[] = $category->getId();
104
+ $this->pushActiveChildrenCategory($category->getChildrenCategories(), $list, $store);
105
+ }
106
+ }
107
+ }
108
+ }
109
+
110
  }
app/code/local/Magestore/Mageconnector/Model/Importstore.php DELETED
@@ -1,62 +0,0 @@
1
- <?php
2
- /**
3
- * Source for import Store to get store view default
4
- *
5
- * @category Magestore
6
- * @package Magestore_Mageconnector
7
- * @author Nguyen Minh Dung (http://magestore.com)
8
- */
9
- class Magestore_Mageconnector_Model_Importstore
10
- {
11
- public function toOptionArray()
12
- {
13
- $collection = Mage::getResourceModel('core/website_collection');
14
-
15
- $options = array();
16
-
17
- foreach($collection as $website) {
18
-
19
- $goupcollection = $website->getGroupCollection();
20
- foreach($goupcollection as $group) {
21
-
22
- $storecollection = $group->getStoreCollection();
23
- foreach ($storecollection as $store) {
24
-
25
- if ($website->__get('is_default') &&
26
- $website->__get('default_group_id') == $group->getId() &&
27
- $group->__get('default_store_id') == $store->getId()) {
28
- $options[] = array(
29
- 'value' => $store->code,
30
- 'label' => $website->getName().' / '.$group->getName().' / '.$store->getName()
31
- );
32
- break;
33
- }
34
- }
35
- }
36
- }
37
-
38
- foreach($collection as $website) {
39
-
40
- $goupcollection = $website->getGroupCollection();
41
- foreach($goupcollection as $group) {
42
-
43
- $storecollection = $group->getStoreCollection();
44
- foreach ($storecollection as $store) {
45
-
46
- if ($website->__get('is_default') &&
47
- $website->__get('default_group_id') == $group->getId() &&
48
- $group->__get('default_store_id') == $store->getId()) {
49
- continue;
50
- } else {
51
- $options[] = array(
52
- 'value' => $store->code,
53
- 'label' => $website->getName().' / '.$group->getName().' / '.$store->getName()
54
- );
55
- }
56
- }
57
- }
58
- }
59
-
60
- return $options;
61
- }
62
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Magestore/Mageconnector/Model/Information.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Get version of module
5
+ *
6
+ * @category Magestore
7
+ * @package Magestore_Mageconnector
8
+ * @author Nguyen Minh Dung (http://oss.com.vn)
9
+ */
10
+ class Magestore_Mageconnector_Model_Information {
11
+
12
+ private static $config = null;
13
+
14
+ public function getConfig() {
15
+ if (is_null(self::$config)) {
16
+ self::$config = simplexml_load_file(
17
+ Mage::getBaseDir() . DS . 'app' . DS . 'code' . DS . 'local' . DS . 'Magestore' . DS . 'Mageconnector' . DS . 'etc' . DS . 'config.xml'
18
+ );
19
+ }
20
+
21
+ return self::$config;
22
+ }
23
+
24
+ public function getVersion() {
25
+ $xml = '<?xml version="1.0" encoding="UTF-8"?><massale-module><platform>Magento</platform><version>'
26
+ .$this->getConfig()->modules->Magestore_Mageconnector->version.
27
+ '</version><platform-version>'.Mage::getVersion().'</platform-version></massale-module>';
28
+
29
+ return $xml;
30
+ }
31
+
32
+ }
app/code/local/Magestore/Mageconnector/Model/Override/Mage/Checkout/Cart.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * To change this template, choose Tools | Templates
5
+ * and open the template in the editor.
6
+ */
7
+ include_once Mage::getBaseDir() . DS . 'app' . DS . 'code' . DS . 'core' . DS . 'Mage' . DS . 'Checkout' . DS . 'Model' . DS . 'Cart.php';
8
+
9
+ class Magestore_Mageconnector_Model_Override_Mage_Checkout_Cart extends Mage_Checkout_Model_Cart {
10
+
11
+ private $productUrlWhenAddCartError;
12
+
13
+ public function setProductUrlWhenAddCartError($productUrlWhenAddCartError) {
14
+ $this->productUrlWhenAddCartError = $productUrlWhenAddCartError;
15
+ return $this;
16
+ }
17
+
18
+ public function addProduct($productInfo, $requestInfo = null) {
19
+ $product = $this->_getProduct($productInfo);
20
+ $request = $this->_getProductRequest($requestInfo);
21
+
22
+ $productId = $product->getId();
23
+
24
+ if ($product->getStockItem()) {
25
+ $minimumQty = $product->getStockItem()->getMinSaleQty();
26
+ //If product was not found in cart and there is set minimal qty for it
27
+ if ($minimumQty && $minimumQty > 0 && $request->getQty() < $minimumQty
28
+ && !$this->getQuote()->hasProductId($productId)
29
+ ) {
30
+ $request->setQty($minimumQty);
31
+ }
32
+ }
33
+
34
+ if ($productId) {
35
+ try {
36
+ $result = $this->getQuote()->addProduct($product, $request);
37
+ } catch (Mage_Core_Exception $e) {
38
+ $this->getCheckoutSession()->setUseNotice(false);
39
+ $result = $e->getMessage();
40
+ }
41
+ /**
42
+ * String we can get if prepare process has error
43
+ */
44
+ if (is_string($result)) {
45
+ header("Location: " . $this->productUrlWhenAddCartError);
46
+ exit (0);
47
+ }
48
+ } else {
49
+ Mage::throwException(Mage::helper('checkout')->__('The product does not exist.'));
50
+ }
51
+
52
+ Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product));
53
+ $this->getCheckoutSession()->setLastAddedProductId($productId);
54
+ return $this;
55
+ }
56
+
57
+ }
app/code/local/Magestore/Mageconnector/Model/Product.php CHANGED
@@ -7,17 +7,25 @@
7
  * @package Magestore_Mageconnector
8
  * @author Nguyen Minh Dung (http://oss.com.vn)
9
  */
10
- class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Model_Abstract {
11
 
12
- public function exportXMLProduct(Mage_Catalog_Model_Product $product, &$i, $isShowAllDetails = false) {
 
 
 
 
 
 
 
 
 
13
  try {
14
  $xml = '';
15
  $inventory = Mage::getModel('cataloginventory/stock_item')
16
  ->loadByProduct($product);
17
 
18
  if ($product->getStatus()) {
19
- $xml .= '<product>'
20
- . '<order>#' . ++$i . '</order>'
21
  . '<id>' . $product->getId() . '</id>'
22
  . '<name><![CDATA[' . $product->getName() . ']]></name>';
23
 
@@ -34,9 +42,9 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
34
  , true, false);
35
 
36
  $now = date('Y-m-d');
37
- $special_from_date = split(' ', $product->getSpecialFromDate());
38
  $special_from_date = $special_from_date[0];
39
- $special_to_date = split(' ', $product->getSpecialToDate());
40
  $special_to_date = $special_to_date[0];
41
 
42
  $xml .= '<price><![CDATA[' . $price . ']]></price>';
@@ -84,25 +92,47 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
84
  }
85
  }
86
 
87
- $xml .= '<url_key><![CDATA[' . $product->getUrlKey() . ']]></url_key>'
88
- . '<url><![CDATA[' . $product->getProductUrl() . ']]></url>'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  . '<short_description><![CDATA[' . $product->getShortDescription() . ']]></short_description>'
90
  . '<is_in_stock>' . $product->isInStock() . '</is_in_stock>'
91
  . '<is_salable>' . $product->isSalable() . '</is_salable>'
92
- . '<image><![CDATA[' . $product->getImageUrl() . ']]></image>'
93
  . '<image_label><![CDATA[' . $product->getImageLabel() . ']]></image_label>';
94
 
95
- $listImage = $product->getMediaGalleryImages();
96
- $gallery = '';
97
- foreach ($listImage as $image) {
98
- $gallery .= '<image>'
99
- . '<src><![CDATA[' . $image->getUrl() . ']]></src>'
100
- . '<label><![CDATA[' . $image->getLabel() . ']]></label>'
101
- . '</image>';
102
- }
103
- $xml .= '<image_gallery>' . $gallery . '</image_gallery>';
104
-
105
  if ($isShowAllDetails) {
 
 
 
 
 
 
 
 
 
 
 
 
106
  $xml .= '<description><![CDATA[' . $product->getDescription() . ']]></description>';
107
 
108
  switch ($product->getTypeId()) {
@@ -123,8 +153,7 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
123
  }
124
  return $xml;
125
  } catch (Exception $e) {
126
- Zend_Debug::dump($e);
127
- die();
128
  }
129
  }
130
 
@@ -132,13 +161,15 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
132
  $xml = '<downloadable_links>';
133
  try {
134
  $xml .= '<links_purchased_separately>' . $product->getLinksPurchasedSeparately() . '</links_purchased_separately>'
135
- . '<purchased_links_title>' . $product->getLinksTitle() . '</purchased_links_title>'
136
  . '<links_form_key>links[]</links_form_key>'
137
  . '<purchased_links>';
138
  $links = $product->getTypeInstance(true)->getLinks($product);
139
  foreach ($links as $item) {
140
  if ($item instanceof Mage_Downloadable_Model_Link) {
141
- $xml .= '<link><title><![CDATA[' . $item->getTitle() . ']]></title>';
 
 
142
  if (floatval($item->getPrice()) != 0) {
143
  $p = Mage::helper('core')
144
  ->currency($item->getPrice(), true, false);
@@ -156,6 +187,7 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
156
  . '<sample_links_title>' . $product->getSamplesTitle() . '</sample_links_title>'
157
  . '<sample_links>';
158
  $samples = $product->getTypeInstance(true)->getSamples($product);
 
159
  foreach ($samples as $item) {
160
  if ($item instanceof Mage_Downloadable_Model_Sample) {
161
  $xml .= '<link>'
@@ -201,7 +233,7 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
201
  }
202
  }
203
  } catch (Exception $e) {
204
- Zend_Debug::dump($e);
205
  }
206
 
207
  $xml .= '</more_attributes>';
@@ -221,8 +253,7 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
221
  $i = 0;
222
  foreach ($listAssociatedProducts as $associatedProduct) {
223
  if ($associatedProduct->getStatus()) {
224
- $xml .= '<associated_product>'
225
- . '<order>#' . ++$i . '</order>'
226
  . '<id>' . $associatedProduct->getId() . '</id>'
227
  . '<name><![CDATA[' . $associatedProduct->getName() . ']]></name>';
228
 
@@ -237,9 +268,9 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
237
  , true, false);
238
 
239
  $now = date('Y-m-d');
240
- $special_from_date = split(' ', $associatedProduct->getSpecialFromDate());
241
  $special_from_date = $special_from_date[0];
242
- $special_to_date = split(' ', $associatedProduct->getSpecialToDate());
243
  $special_to_date = $special_to_date[0];
244
 
245
  $xml .= '<price><![CDATA[' . $price . ']]></price>';
@@ -435,8 +466,8 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
435
  $xml .= '</configuration_options>';
436
  return $xml;
437
  } catch (Exception $e) {
438
- Zend_Debug::dump($e);
439
- die();
440
  }
441
  return '';
442
  }
@@ -444,6 +475,8 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
444
  /**
445
  * Export Product to XML Data by store code
446
  *
 
 
447
  * @param Mage_Catalog_Model_Product_Collection $collection
448
  * @param int $totalProducts
449
  * @param int $totalPages
@@ -452,13 +485,12 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
452
  * @param string $orderBy
453
  * @param string $typeOrder
454
  */
455
- public function exportXML($collection, $totalProducts = 1, $totalPages = 1, $currentPage = 1, $pageSize = 1, $orderBy = 'entity_id', $typeOrder = 'desc') {
456
-
457
- $xml = '<?xml version="1.0"?><root><products>';
458
 
459
  $i = $pageSize * ($currentPage - 1);
460
  foreach ($collection as $product) {
461
- $xml .= $this->exportXMLProduct($product, $i);
462
  }
463
 
464
  if ($orderBy == 'entity_id') {
@@ -472,7 +504,7 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
472
  . '<pageSize>' . $pageSize . '</pageSize>'
473
  . '<orderBy>' . $orderBy . '</orderBy>'
474
  . '<typeOrder>' . $typeOrder . '</typeOrder></paginator>'
475
- . '</root>';
476
 
477
  return $xml;
478
  }
@@ -483,17 +515,21 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
483
  * If category has no product and $showProductsInSubCategories = true, then shows
484
  * all product in sub categories
485
  *
486
- * @param string $store_code
487
- * @param string $category_url_key
 
 
 
 
488
  * @param int $_currentPage
489
  * @param int $_pageSize
490
  * @param string $_orderBy
491
  * @param string $_typeOrder
492
  * @param boolean $showProductsInSubCategories
493
  */
494
- public function getProductListByCategory($store_code, $category_url_key, $_currentPage = 1, $_pageSize = 10, $_orderBy = 'new', $_typeOrder = 'desc', $showProductsInSubCategories = false) {
495
- $store = $this->getStore($store_code);
496
- $storeId = $store['store_id'];
497
 
498
  if (is_null($_orderBy) || $_orderBy == '' || $_orderBy == 'new') {
499
  $_orderBy = 'entity_id';
@@ -514,23 +550,68 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
514
  }
515
 
516
  $category = Mage::getModel('catalog/category')
517
- ->loadByAttribute('url_key', $category_url_key);
518
 
519
- if ($category instanceof Mage_Catalog_Model_Category) {
520
- $totalProducts = count($category
521
- ->setStoreId($storeId)
522
- ->getProductCollection()
523
- ->addAttributeToFilter(array(
524
- array(
525
- 'attribute' => 'visibility',
526
- 'in' => array(2, 4)
527
- )
528
- ))
529
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
530
  $collection = array();
531
  if ($totalProducts > 0) {
532
- $collection = $category->setStoreId($storeId)
533
  ->getProductCollection()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
534
  ->addAttributeToFilter(array(
535
  array(
536
  'attribute' => 'visibility',
@@ -540,12 +621,15 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
540
  ->addAttributeToSort($_orderBy, $_typeOrder)
541
  ->setCurPage($_currentPage)
542
  ->setPageSize($_pageSize);
543
- } else if ($showProductsInSubCategories) {
544
  $children_category_ids = $category->getChildren();
 
 
 
545
  $resource = Mage::getSingleton("core/resource");
546
  $read = $resource->getConnection("core_read");
547
 
548
- $sql = Mage::getModel("catalog/product")
549
  ->getCollection()
550
  ->addStoreFilter($storeId)
551
  ->addAttributeToFilter(array(
@@ -553,13 +637,33 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
553
  'attribute' => 'visibility',
554
  'in' => array(2, 4)
555
  )
556
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
557
  ->addAttributeToSort($_orderBy, $_typeOrder)
558
  ->getSelect()
559
  ->distinct()
560
- ->join(array('B' => Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')),
561
  'e.entity_id = B.product_id', '')
562
- ->where('B.category_id in (?)', split(',', $children_category_ids));
563
 
564
  $rows = $read->fetchAll($sql->__toString());
565
  $ids = array();
@@ -597,12 +701,49 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
597
  $totalPages++;
598
  }
599
 
600
- return $this->exportXML($list, $totalProducts, $totalPages, $_currentPage, $_pageSize, $_orderBy, $_typeOrder);
601
  } else {
602
- return '';
603
  }
604
  }
605
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
606
  /**
607
  * Searchs Products, if $category_url_key = '' then searchs all product by keyword
608
  * else searchs product in category has url_key = $category_url_key
@@ -610,18 +751,22 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
610
  * If category has no product and $showProductsInSubCategories = true, then search
611
  * all product in sub categories
612
  *
613
- * @param string $store_code
 
 
 
614
  * @param string $keyword
615
- * @param string $category_url_key
 
616
  * @param int $_currentPage
617
  * @param int $_pageSize
618
  * @param string $_orderBy
619
  * @param string $_typeOrder
620
  * @param boolean $showProductsInSubCategories
621
  */
622
- public function searchProduct($store_code = null, $keyword = '', $category_url_key = '', $_currentPage = 1, $_pageSize = 10, $_orderBy = 'new', $_typeOrder = 'desc', $showProductsInSubCategories = false) {
623
- $store = $this->getStore($store_code);
624
- $storeId = $store['store_id'];
625
 
626
  if (is_null($_currentPage) || $_currentPage == '') {
627
  $_currentPage = 1;
@@ -630,10 +775,14 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
630
  if (is_null($_pageSize) || $_pageSize == '') {
631
  $_pageSize = 10;
632
  }
 
633
 
634
  if (is_null($_orderBy) || $_orderBy == '' || $_orderBy == 'new') {
635
  $_orderBy = 'entity_id';
636
  }
 
 
 
637
 
638
  if (is_null($_typeOrder) || $_typeOrder == '') {
639
  $_typeOrder = 'desc';
@@ -641,20 +790,43 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
641
 
642
  $_orderBy = strtolower($_orderBy);
643
  $_typeOrder = strtolower($_typeOrder);
644
-
645
- if (is_null($category_url_key) || $category_url_key == '') {
646
- $collection = Mage::getModel('catalog/product')->getCollection()
 
 
 
 
 
 
 
 
647
  ->addAttributeToSelect('name')
648
- ->addStoreFilter($storeId)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
649
  ->addAttributeToFilter(array(
650
  array(
651
  'attribute' => 'name',
652
  'like' => '%' . $this->clean_url($keyword) . '%'
653
  ),
654
- array(
655
- 'attribute' => 'url_key',
656
- 'like' => '%' . $this->clean_url($keyword) . '%'
657
- ),
658
  array(
659
  'attribute' => 'short_description',
660
  'like' => '%' . $this->clean_url($keyword) . '%'
@@ -666,24 +838,43 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
666
  'in' => array(3, 4)
667
  )
668
  ))
 
669
  ->addFieldToFilter("status", 1)
670
- ->setOrder($_orderBy, $_typeOrder)
671
- ->setCurPage($_currentPage)
672
- ->setPageSize($_pageSize)
 
 
 
673
  ;
 
 
 
 
 
 
 
 
 
 
 
 
674
 
675
- $products = Mage::getModel('catalog/product')->getCollection()
676
- ->addAttributeToSelect('name')
677
- ->addStoreFilter($storeId)
 
 
 
 
 
 
 
678
  ->addAttributeToFilter(array(
679
  array(
680
  'attribute' => 'name',
681
  'like' => '%' . $this->clean_url($keyword) . '%'
682
  ),
683
- array(
684
- 'attribute' => 'url_key',
685
- 'like' => '%' . $this->clean_url($keyword) . '%'
686
- ),
687
  array(
688
  'attribute' => 'short_description',
689
  'like' => '%' . $this->clean_url($keyword) . '%'
@@ -695,15 +886,30 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
695
  'in' => array(3, 4)
696
  )
697
  ))
698
- ->addFieldToFilter("status", 1);
699
-
700
- $totalProducts = count($products);
 
 
 
 
 
 
 
 
 
 
 
701
  } else {
702
  $category = Mage::getModel('catalog/category')
703
- ->loadByAttribute('url_key', $category_url_key);
 
 
 
 
704
 
705
- $totalProducts = count($category
706
- ->setStoreId($storeId)
707
  ->getProductCollection()
708
  ->addAttributeToFilter(array(
709
  array(
@@ -711,21 +917,36 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
711
  'in' => array(3, 4)
712
  )
713
  ))
714
- ->addFieldToFilter("status", 1));
715
- $collection = array();
 
716
  if ($totalProducts > 0) {
717
- $products = Mage::getModel('catalog/product')->getCollection()
718
- ->addAttributeToSelect('name')
719
- ->addStoreFilter($storeId)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
720
  ->addAttributeToFilter(array(
721
  array(
722
  'attribute' => 'name',
723
  'like' => '%' . $this->clean_url($keyword) . '%'
724
  ),
725
- array(
726
- 'attribute' => 'url_key',
727
- 'like' => '%' . $this->clean_url($keyword) . '%'
728
- ),
729
  array(
730
  'attribute' => 'short_description',
731
  'like' => '%' . $this->clean_url($keyword) . '%'
@@ -738,10 +959,35 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
738
  'in' => array(3, 4)
739
  )
740
  ))
741
- ->addFieldToFilter("status", 1);
742
- $totalProducts = count($products);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
743
 
744
- $collection = Mage::getModel('catalog/product')->getCollection()
745
  ->addAttributeToSelect('name')
746
  ->addStoreFilter($storeId)
747
  ->addAttributeToFilter(array(
@@ -749,10 +995,6 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
749
  'attribute' => 'name',
750
  'like' => '%' . $this->clean_url($keyword) . '%'
751
  ),
752
- array(
753
- 'attribute' => 'url_key',
754
- 'like' => '%' . $this->clean_url($keyword) . '%'
755
- ),
756
  array(
757
  'attribute' => 'short_description',
758
  'like' => '%' . $this->clean_url($keyword) . '%'
@@ -765,28 +1007,47 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
765
  'in' => array(3, 4)
766
  )
767
  ))
 
768
  ->addFieldToFilter("status", 1)
769
- ->setOrder($_orderBy, $_typeOrder)
770
- ->setCurPage($_currentPage)
771
- ->setPageSize($_pageSize)
772
  ;
 
773
  } else if ($showProductsInSubCategories) {
774
  $children_category_ids = $category->getChildren();
 
 
775
  $resource = Mage::getSingleton("core/resource");
776
  $read = $resource->getConnection("core_read");
777
 
778
- $sql = Mage::getModel("catalog/product")
779
- ->getCollection()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
780
  ->addStoreFilter($storeId)
781
  ->addAttributeToFilter(array(
782
  array(
783
  'attribute' => 'name',
784
  'like' => '%' . $this->clean_url($keyword) . '%'
785
  ),
786
- array(
787
- 'attribute' => 'url_key',
788
- 'like' => '%' . $this->clean_url($keyword) . '%'
789
- ),
790
  array(
791
  'attribute' => 'short_description',
792
  'like' => '%' . $this->clean_url($keyword) . '%'
@@ -800,42 +1061,64 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
800
  ))
801
  ->addFieldToFilter("status", 1)
802
  ->addAttributeToSort($_orderBy, $_typeOrder)
803
- ->getSelect()
804
- ->distinct()
805
- ->join(array('B' => Mage::getSingleton('core/resource')->getTableName('catalog_category_product_index')),
806
  'e.entity_id = B.product_id', '')
807
- ->where('B.category_id in (?)', split(',', $children_category_ids));
 
808
 
809
- $rows = $read->fetchAll($sql->__toString());
810
- $ids = array();
811
- foreach ($rows as $row) {
812
- $ids[] = $row['entity_id'];
813
  }
814
- $totalProducts = count($ids);
815
 
816
- $collection = Mage::getModel("catalog/product")
817
- ->getCollection()
818
- ->addStoreFilter($storeId)
819
- ->addAttributeToFilter(array(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
820
  array(
821
  'attribute' => 'visibility',
822
  'in' => array(3, 4)
823
  )
824
  ))
 
825
  ->addFieldToFilter("status", 1)
826
- ->addAttributeToSort($_orderBy, $_typeOrder)
827
- ->addAttributeToFilter('entity_id', array('in' => $ids))
828
- ->setCurPage($_currentPage)
829
- ->setPageSize($_pageSize);
 
 
 
 
 
830
  }
831
  }
832
 
833
  $list = array();
834
- foreach ($collection as $p) {
 
835
  $product = Mage::getModel('catalog/product')
836
  ->setStoreId($storeId)
837
- ->load($p->getId());
838
-
839
  $list[] = $product;
840
  }
841
 
@@ -844,41 +1127,42 @@ class Magestore_Mageconnector_Model_Product extends Magestore_Mageconnector_Mode
844
  $totalPages++;
845
  }
846
 
847
- return $this->exportXML($list, $totalProducts, $totalPages, $_currentPage, $_pageSize, $_orderBy, $_typeOrder);
848
  }
849
 
850
  /**
851
  * Get product detail
 
 
 
 
 
852
  */
853
- public function getProductDetail($store_code = null, $product_url_key = null) {
854
  try {
855
- $store = $this->getStore($store_code);
856
- $storeId = $store['store_id'];
857
  $product = Mage::getModel('catalog/product')
858
- ->loadByAttribute('url_key', $product_url_key);
 
859
 
860
- $product = Mage::getModel('catalog/product')
861
- ->setStoreId($storeId)
862
- ->load($product->getId());
863
-
864
- $xml = '<?xml version="1.0"?><root>';
865
  $i = 0;
866
- $xml .= $this->exportXMLProduct($product, $i, true);
867
- $xml .= '</root>';
868
 
869
  return $xml;
870
  } catch (Exception $e) {
871
- Zend_Debug::dump($e);
872
- die();
873
  }
874
  }
875
 
876
  public function clean_url($text) {
877
- $text = strtolower($text);
878
- $code_entities_match = array(' ', '--', '&quot;', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '{', '}', '|', ':', '"', '<', '>', '?', '[', ']', '\\', ';', "'", ',', '.', '/', '*', '+', '~', '`', '=');
879
- $code_entities_replace = array('-', '-', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');
880
- $text = str_replace($code_entities_match, $code_entities_replace, $text);
881
- return $text;
 
882
  }
883
 
884
  }
7
  * @package Magestore_Mageconnector
8
  * @author Nguyen Minh Dung (http://oss.com.vn)
9
  */
10
+ class Magestore_Mageconnector_Model_Product {
11
 
12
+ /**
13
+ *
14
+ * @param Mage_Catalog_Model_Product $product
15
+ * @param string $baseUrl
16
+ * @param string $storeCode
17
+ * @param int $i
18
+ * @param bool $isShowAllDetails
19
+ * @return string
20
+ */
21
+ public function exportXMLProduct(Mage_Catalog_Model_Product $product, $baseUrl, $storeCode, &$i, $isShowAllDetails = false) {
22
  try {
23
  $xml = '';
24
  $inventory = Mage::getModel('cataloginventory/stock_item')
25
  ->loadByProduct($product);
26
 
27
  if ($product->getStatus()) {
28
+ $xml .= '<product order="#' . (++$i) . '">'
 
29
  . '<id>' . $product->getId() . '</id>'
30
  . '<name><![CDATA[' . $product->getName() . ']]></name>';
31
 
42
  , true, false);
43
 
44
  $now = date('Y-m-d');
45
+ $special_from_date = explode(' ', $product->getSpecialFromDate());
46
  $special_from_date = $special_from_date[0];
47
+ $special_to_date = explode(' ', $product->getSpecialToDate());
48
  $special_to_date = $special_to_date[0];
49
 
50
  $xml .= '<price><![CDATA[' . $price . ']]></price>';
92
  }
93
  }
94
 
95
+ $productImageUrl = $product->getImageUrl();
96
+ $productImageUrl = str_replace('https://', 'http://', $productImageUrl);
97
+
98
+ $url_key = explode('/', $product->getUrlPath());
99
+ $url_key = str_replace('.html', '', $url_key[count($url_key) - 1]);
100
+
101
+ if ($url_key == '') {
102
+ $url_key = $product->getRequestPath();
103
+ $url_key = str_replace('.html', '', $url_key[count($url_key) - 1]);
104
+ if ($url_key == '') {
105
+ $url_key = $product->getUrlKey();
106
+ }
107
+ }
108
+
109
+ $categories = $product->getCategoryIds();
110
+ $categories = implode(',', $categories);
111
+
112
+ $productUrl = Mage::helper('mageconnector')->prepareUrl($baseUrl, $product->getProductUrl(), $storeCode);
113
+ // $productUrl = $product->getProductUrl();
114
+ $xml .= '<categories><![CDATA[' . $categories . ']]></categories>'
115
+ .'<url_key><![CDATA[' . $url_key . ']]></url_key>'
116
+ . '<url><![CDATA[' . $productUrl . ']]></url>'
117
  . '<short_description><![CDATA[' . $product->getShortDescription() . ']]></short_description>'
118
  . '<is_in_stock>' . $product->isInStock() . '</is_in_stock>'
119
  . '<is_salable>' . $product->isSalable() . '</is_salable>'
120
+ . '<image><![CDATA[' . $productImageUrl . ']]></image>'
121
  . '<image_label><![CDATA[' . $product->getImageLabel() . ']]></image_label>';
122
 
 
 
 
 
 
 
 
 
 
 
123
  if ($isShowAllDetails) {
124
+ $listImage = $product->getMediaGalleryImages();
125
+ $gallery = '';
126
+ foreach ($listImage as $image) {
127
+ $imageUrl = $image->getUrl();
128
+ $imageUrl = str_replace('https://', 'http://', $imageUrl);
129
+ $gallery .= '<image>'
130
+ . '<src><![CDATA[' . $imageUrl . ']]></src>'
131
+ . '<label><![CDATA[' . $image->getLabel() . ']]></label>'
132
+ . '</image>';
133
+ }
134
+ $xml .= '<image_gallery>' . $gallery . '</image_gallery>';
135
+
136
  $xml .= '<description><![CDATA[' . $product->getDescription() . ']]></description>';
137
 
138
  switch ($product->getTypeId()) {
153
  }
154
  return $xml;
155
  } catch (Exception $e) {
156
+
 
157
  }
158
  }
159
 
161
  $xml = '<downloadable_links>';
162
  try {
163
  $xml .= '<links_purchased_separately>' . $product->getLinksPurchasedSeparately() . '</links_purchased_separately>'
164
+ . '<purchased_links_title><![CDATA[' . $product->getLinksTitle() . ']]></purchased_links_title>'
165
  . '<links_form_key>links[]</links_form_key>'
166
  . '<purchased_links>';
167
  $links = $product->getTypeInstance(true)->getLinks($product);
168
  foreach ($links as $item) {
169
  if ($item instanceof Mage_Downloadable_Model_Link) {
170
+ $xml .= '<link>';
171
+ $xml .= '<title><![CDATA[' . $item->getTitle() . ']]></title>';
172
+ $xml .= '<url><![CDATA[' . Mage::getBaseUrl() . 'downloadable/download/linkSample/link_id/' . $item->getId() . '/]]></url>';
173
  if (floatval($item->getPrice()) != 0) {
174
  $p = Mage::helper('core')
175
  ->currency($item->getPrice(), true, false);
187
  . '<sample_links_title>' . $product->getSamplesTitle() . '</sample_links_title>'
188
  . '<sample_links>';
189
  $samples = $product->getTypeInstance(true)->getSamples($product);
190
+
191
  foreach ($samples as $item) {
192
  if ($item instanceof Mage_Downloadable_Model_Sample) {
193
  $xml .= '<link>'
233
  }
234
  }
235
  } catch (Exception $e) {
236
+ // Zend_Debug::dump($e);
237
  }
238
 
239
  $xml .= '</more_attributes>';
253
  $i = 0;
254
  foreach ($listAssociatedProducts as $associatedProduct) {
255
  if ($associatedProduct->getStatus()) {
256
+ $xml .= '<associated_product order="#' . (++$i) . '">'
 
257
  . '<id>' . $associatedProduct->getId() . '</id>'
258
  . '<name><![CDATA[' . $associatedProduct->getName() . ']]></name>';
259
 
268
  , true, false);
269
 
270
  $now = date('Y-m-d');
271
+ $special_from_date = explode(' ', $associatedProduct->getSpecialFromDate());
272
  $special_from_date = $special_from_date[0];
273
+ $special_to_date = explode(' ', $associatedProduct->getSpecialToDate());
274
  $special_to_date = $special_to_date[0];
275
 
276
  $xml .= '<price><![CDATA[' . $price . ']]></price>';
466
  $xml .= '</configuration_options>';
467
  return $xml;
468
  } catch (Exception $e) {
469
+ // Zend_Debug::dump($e);
470
+ // die();
471
  }
472
  return '';
473
  }
475
  /**
476
  * Export Product to XML Data by store code
477
  *
478
+ * @param string $baseUrl
479
+ * @param string $storeCode
480
  * @param Mage_Catalog_Model_Product_Collection $collection
481
  * @param int $totalProducts
482
  * @param int $totalPages
485
  * @param string $orderBy
486
  * @param string $typeOrder
487
  */
488
+ public function exportXML($baseUrl, $storeCode, $collection, $totalProducts = 1, $totalPages = 1, $currentPage = 1, $pageSize = 1, $orderBy = 'entity_id', $typeOrder = 'desc') {
489
+ $xml = '<?xml version="1.0"?><massale><products>';
 
490
 
491
  $i = $pageSize * ($currentPage - 1);
492
  foreach ($collection as $product) {
493
+ $xml .= $this->exportXMLProduct($product, $baseUrl, $storeCode, $i);
494
  }
495
 
496
  if ($orderBy == 'entity_id') {
504
  . '<pageSize>' . $pageSize . '</pageSize>'
505
  . '<orderBy>' . $orderBy . '</orderBy>'
506
  . '<typeOrder>' . $typeOrder . '</typeOrder></paginator>'
507
+ . '</massale>';
508
 
509
  return $xml;
510
  }
515
  * If category has no product and $showProductsInSubCategories = true, then shows
516
  * all product in sub categories
517
  *
518
+ * @param string $categoryUrlKey
519
+ * @param array $excludeCategoryIds
520
+ * @param string $baseUrl
521
+ * @param string $storeCode
522
+ * @param array $disabledProductIds
523
+ * @param array $inProductIds
524
  * @param int $_currentPage
525
  * @param int $_pageSize
526
  * @param string $_orderBy
527
  * @param string $_typeOrder
528
  * @param boolean $showProductsInSubCategories
529
  */
530
+ public function getProductListByCategory($categoryUrlKey, $excludeCategoryIds, $baseUrl, $storeCode, $disabledProductIds = array(), $inProductIds = array(), $_currentPage = 1, $_pageSize = 10, $_orderBy = 'new', $_typeOrder = 'desc', $showProductsInSubCategories = false) {
531
+ $store = Mage::app()->getStore();
532
+ $storeId = $store->getId();
533
 
534
  if (is_null($_orderBy) || $_orderBy == '' || $_orderBy == 'new') {
535
  $_orderBy = 'entity_id';
550
  }
551
 
552
  $category = Mage::getModel('catalog/category')
553
+ ->loadByAttribute('url_key', $categoryUrlKey);
554
 
555
+ if ($category instanceof Mage_Catalog_Model_Category && $category->getIsActive()) {
556
+ $queryCountProductInCategory = $category
557
+ ->setStoreId($storeId)
558
+ ->getProductCollection()
559
+ ->addAttributeToFilter(array(
560
+ array(
561
+ 'attribute' => 'visibility',
562
+ 'in' => array(2, 4)
563
+ )
564
+ ));
565
+
566
+ if (count($disabledProductIds) > 0) {
567
+ $queryCountProductInCategory->addAttributeToFilter(array(
568
+ array(
569
+ 'attribute' => 'entity_id',
570
+ 'nin' => $disabledProductIds
571
+ )
572
+ ));
573
+ }
574
+
575
+ if (count($inProductIds) > 0) {
576
+ $queryCountProductInCategory->addAttributeToFilter(array(
577
+ array(
578
+ 'attribute' => 'entity_id',
579
+ 'in' => $inProductIds
580
+ )
581
+ ));
582
+ }
583
+
584
+ $totalProducts = count($queryCountProductInCategory);
585
  $collection = array();
586
  if ($totalProducts > 0) {
587
+ $queryProductInCategory = $category->setStoreId($storeId)
588
  ->getProductCollection()
589
+ ->addAttributeToFilter(array(
590
+ array(
591
+ 'attribute' => 'visibility',
592
+ 'in' => array(2, 4)
593
+ )
594
+ ));
595
+
596
+ if (count($disabledProductIds) > 0) {
597
+ $queryProductInCategory->addAttributeToFilter(array(
598
+ array(
599
+ 'attribute' => 'entity_id',
600
+ 'nin' => $disabledProductIds
601
+ )
602
+ ));
603
+ }
604
+
605
+ if (count($inProductIds) > 0) {
606
+ $queryProductInCategory->addAttributeToFilter(array(
607
+ array(
608
+ 'attribute' => 'entity_id',
609
+ 'in' => $inProductIds
610
+ )
611
+ ));
612
+ }
613
+
614
+ $collection = $queryProductInCategory
615
  ->addAttributeToFilter(array(
616
  array(
617
  'attribute' => 'visibility',
621
  ->addAttributeToSort($_orderBy, $_typeOrder)
622
  ->setCurPage($_currentPage)
623
  ->setPageSize($_pageSize);
624
+ } else if ($showProductsInSubCategories || $showProductsInSubCategories == "1") {
625
  $children_category_ids = $category->getChildren();
626
+ $children_category_ids = explode(',', $children_category_ids);
627
+ $children_category_ids = array_diff($children_category_ids, $excludeCategoryIds);
628
+ $children_category_ids = implode(',', $children_category_ids);
629
  $resource = Mage::getSingleton("core/resource");
630
  $read = $resource->getConnection("core_read");
631
 
632
+ $queryProductInSubCategory = Mage::getModel("catalog/product")
633
  ->getCollection()
634
  ->addStoreFilter($storeId)
635
  ->addAttributeToFilter(array(
637
  'attribute' => 'visibility',
638
  'in' => array(2, 4)
639
  )
640
+ ));
641
+
642
+ if (count($disabledProductIds) > 0) {
643
+ $queryProductInSubCategory->addAttributeToFilter(array(
644
+ array(
645
+ 'attribute' => 'entity_id',
646
+ 'nin' => $disabledProductIds
647
+ )
648
+ ));
649
+ }
650
+
651
+ if (count($inProductIds) > 0) {
652
+ $queryProductInSubCategory->addAttributeToFilter(array(
653
+ array(
654
+ 'attribute' => 'entity_id',
655
+ 'in' => $inProductIds
656
+ )
657
+ ));
658
+ }
659
+
660
+ $sql = $queryProductInSubCategory
661
  ->addAttributeToSort($_orderBy, $_typeOrder)
662
  ->getSelect()
663
  ->distinct()
664
+ ->join(array('B' => Mage::getSingleton('core/resource')->getTableName('catalog_category_product')),
665
  'e.entity_id = B.product_id', '')
666
+ ->where('B.category_id in (?)', explode(',', $children_category_ids));
667
 
668
  $rows = $read->fetchAll($sql->__toString());
669
  $ids = array();
701
  $totalPages++;
702
  }
703
 
704
+ return $this->exportXML($baseUrl, $store->getCode(), $list, $totalProducts, $totalPages, $_currentPage, $_pageSize, $_orderBy, $_typeOrder);
705
  } else {
706
+ throw new Magestore_Mageconnector_Exception(Magestore_Mageconnector_Exception::CATEGORY_INVALID);
707
  }
708
  }
709
 
710
+ /**
711
+ * Get number total product of current store view in the active categories
712
+ *
713
+ * @return string
714
+ */
715
+ public function totalProducts() {
716
+ $store = Mage::app()->getStore();
717
+ $storeId = $store->getId();
718
+ $listActiveCategory = Mage::getModel('mageconnector/category')
719
+ ->getListActiveCategoryIdsByStoreView();
720
+
721
+ $resource = Mage::getSingleton("core/resource");
722
+ $read = $resource->getConnection("core_read");
723
+ $sqlCountFoundProducts = Mage::getModel('catalog/product')->getCollection()
724
+ ->addStoreFilter($storeId)
725
+ ->addAttributeToFilter(array(
726
+ array(
727
+ 'attribute' => 'visibility',
728
+ 'in' => array(3, 4)
729
+ )
730
+ ))
731
+ ->addFieldToFilter("status", 1)
732
+ ->getSelectCountSql()
733
+ ->where("`e`.entity_id IN ( SELECT DISTINCT A.product_id FROM " .
734
+ Mage::getSingleton('core/resource')->getTableName('catalog_category_product')
735
+ . " AS A WHERE A.category_id IN (?) )", $listActiveCategory)
736
+ ;
737
+ $totalProducts = $read->fetchRow($sqlCountFoundProducts);
738
+ foreach ($totalProducts as $v) {
739
+ $totalProducts = $v;
740
+ break;
741
+ }
742
+
743
+ $xml = '<?xml version="1.0"?><massale><totalProducts>' . $totalProducts . '</totalProducts></massale>';
744
+ return $xml;
745
+ }
746
+
747
  /**
748
  * Searchs Products, if $category_url_key = '' then searchs all product by keyword
749
  * else searchs product in category has url_key = $category_url_key
751
  * If category has no product and $showProductsInSubCategories = true, then search
752
  * all product in sub categories
753
  *
754
+ * @param string $baseUrl
755
+ * @param string $storeCode
756
+ * @param array $disabledProductIds
757
+ * @param array $inProductIds
758
  * @param string $keyword
759
+ * @param string $categoryUrlKey
760
+ * @param array $excludeCategoryIds
761
  * @param int $_currentPage
762
  * @param int $_pageSize
763
  * @param string $_orderBy
764
  * @param string $_typeOrder
765
  * @param boolean $showProductsInSubCategories
766
  */
767
+ public function searchProduct($baseUrl, $storeCode = null, $disabledProductIds = array(), $inProductIds = array(), $keyword = '', $categoryUrlKey = '', $excludeCategoryIds = array(), $_currentPage = 1, $_pageSize = 10, $_orderBy = 'new', $_typeOrder = 'desc', $showProductsInSubCategories = false) {
768
+ $store = Mage::app()->getStore();
769
+ $storeId = $store->getId();
770
 
771
  if (is_null($_currentPage) || $_currentPage == '') {
772
  $_currentPage = 1;
775
  if (is_null($_pageSize) || $_pageSize == '') {
776
  $_pageSize = 10;
777
  }
778
+ $_start = ((int) $_currentPage - 1) * (int) $_pageSize;
779
 
780
  if (is_null($_orderBy) || $_orderBy == '' || $_orderBy == 'new') {
781
  $_orderBy = 'entity_id';
782
  }
783
+ if ($_orderBy == 'price') {
784
+ $_orderBy = 'final_price';
785
+ }
786
 
787
  if (is_null($_typeOrder) || $_typeOrder == '') {
788
  $_typeOrder = 'desc';
790
 
791
  $_orderBy = strtolower($_orderBy);
792
  $_typeOrder = strtolower($_typeOrder);
793
+
794
+ $resource = Mage::getSingleton("core/resource");
795
+ $read = $resource->getConnection("core_read");
796
+ $listActiveCategory = Mage::getModel('mageconnector/category')
797
+ ->getListActiveCategoryIdsByStoreView();
798
+
799
+ $listActiveCategory = array_diff($listActiveCategory, $excludeCategoryIds);
800
+
801
+ if (is_null($categoryUrlKey) || $categoryUrlKey == '') {
802
+ $queryProduct = Mage::getModel('catalog/product')->getCollection()
803
+ ->distinct(true)
804
  ->addAttributeToSelect('name')
805
+ ->addStoreFilter($storeId);
806
+
807
+ if (count($disabledProductIds) > 0) {
808
+ $queryProduct->addAttributeToFilter(array(
809
+ array(
810
+ 'attribute' => 'entity_id',
811
+ 'nin' => $disabledProductIds
812
+ )
813
+ ));
814
+ }
815
+ if (count($inProductIds) > 0) {
816
+ $queryProduct->addAttributeToFilter(array(
817
+ array(
818
+ 'attribute' => 'entity_id',
819
+ 'in' => $inProductIds
820
+ )
821
+ ));
822
+ }
823
+
824
+ $sqlGetProductList = $queryProduct
825
  ->addAttributeToFilter(array(
826
  array(
827
  'attribute' => 'name',
828
  'like' => '%' . $this->clean_url($keyword) . '%'
829
  ),
 
 
 
 
830
  array(
831
  'attribute' => 'short_description',
832
  'like' => '%' . $this->clean_url($keyword) . '%'
838
  'in' => array(3, 4)
839
  )
840
  ))
841
+ // ->addFinalPrice()
842
  ->addFieldToFilter("status", 1)
843
+ ->getSelect()
844
+ ->where("`e`.entity_id IN ( SELECT DISTINCT A.product_id FROM " .
845
+ Mage::getSingleton('core/resource')->getTableName('catalog_category_product')
846
+ . " AS A WHERE A.category_id IN (?) )", $listActiveCategory)
847
+ ->order($_orderBy . ' ' . $_typeOrder)
848
+ ->limit($_pageSize, $_start)
849
  ;
850
+ $productsList = $read->fetchAll($sqlGetProductList);
851
+ $queryCountProduct = Mage::getModel('catalog/product')->getCollection()
852
+ ->addStoreFilter($storeId);
853
+
854
+ if (count($disabledProductIds) > 0) {
855
+ $queryCountProduct->addAttributeToFilter(array(
856
+ array(
857
+ 'attribute' => 'entity_id',
858
+ 'nin' => $disabledProductIds
859
+ )
860
+ ));
861
+ }
862
 
863
+ if (count($inProductIds) > 0) {
864
+ $queryCountProduct->addAttributeToFilter(array(
865
+ array(
866
+ 'attribute' => 'entity_id',
867
+ 'in' => $inProductIds
868
+ )
869
+ ));
870
+ }
871
+
872
+ $sqlCountFoundProducts = $queryCountProduct
873
  ->addAttributeToFilter(array(
874
  array(
875
  'attribute' => 'name',
876
  'like' => '%' . $this->clean_url($keyword) . '%'
877
  ),
 
 
 
 
878
  array(
879
  'attribute' => 'short_description',
880
  'like' => '%' . $this->clean_url($keyword) . '%'
886
  'in' => array(3, 4)
887
  )
888
  ))
889
+ ->addFieldToFilter("status", 1)
890
+ ->getSelectCountSql()
891
+ ->where("`e`.entity_id IN ( SELECT DISTINCT A.product_id FROM " .
892
+ Mage::getSingleton('core/resource')->getTableName('catalog_category_product')
893
+ . " AS A WHERE A.category_id IN (?) )", $listActiveCategory)
894
+ ;
895
+ $totalProducts = $read->fetchRow($sqlCountFoundProducts);
896
+ foreach ($totalProducts as $v) {
897
+ $totalProducts = $v;
898
+ break;
899
+ }
900
+ if ($totalProducts == 0) {
901
+ throw new Magestore_Mageconnector_Exception(Magestore_Mageconnector_Exception::NO_PRODUCT);
902
+ }
903
  } else {
904
  $category = Mage::getModel('catalog/category')
905
+ ->loadByAttribute('url_key', $categoryUrlKey);
906
+
907
+ if (!($category instanceof Mage_Catalog_Model_Category) || !($category->getIsActive())) {
908
+ throw new Magestore_Mageconnector_Exception(Magestore_Mageconnector_Exception::CATEGORY_INVALID);
909
+ }
910
 
911
+ $totalProducts = count(
912
+ $category->setStoreId($storeId)
913
  ->getProductCollection()
914
  ->addAttributeToFilter(array(
915
  array(
917
  'in' => array(3, 4)
918
  )
919
  ))
920
+ ->addFieldToFilter("status", 1)
921
+ );
922
+
923
  if ($totalProducts > 0) {
924
+ $queryCountSearchProductInCategory = Mage::getModel('catalog/product')->getCollection()
925
+ ->addStoreFilter($storeId);
926
+ if (count($disabledProductIds) > 0) {
927
+ $queryCountSearchProductInCategory->addAttributeToFilter(array(
928
+ array(
929
+ 'attribute' => 'entity_id',
930
+ 'nin' => $disabledProductIds
931
+ )
932
+ ));
933
+ }
934
+
935
+ if (count($inProductIds) > 0) {
936
+ $queryCountSearchProductInCategory->addAttributeToFilter(array(
937
+ array(
938
+ 'attribute' => 'entity_id',
939
+ 'in' => $inProductIds
940
+ )
941
+ ));
942
+ }
943
+
944
+ $sqlCountFoundProducts = $queryCountSearchProductInCategory
945
  ->addAttributeToFilter(array(
946
  array(
947
  'attribute' => 'name',
948
  'like' => '%' . $this->clean_url($keyword) . '%'
949
  ),
 
 
 
 
950
  array(
951
  'attribute' => 'short_description',
952
  'like' => '%' . $this->clean_url($keyword) . '%'
959
  'in' => array(3, 4)
960
  )
961
  ))
962
+ ->addFieldToFilter("status", 1)
963
+ ->getSelectCountSql();
964
+ $totalProducts = $read->fetchRow($sqlCountFoundProducts);
965
+ foreach ($totalProducts as $v) {
966
+ $totalProducts = $v;
967
+ break;
968
+ }
969
+
970
+ $querySearchProductInCategory = Mage::getModel('catalog/product')->getCollection()
971
+ ->addStoreFilter($storeId);
972
+ if (count($disabledProductIds) > 0) {
973
+ $querySearchProductInCategory->addAttributeToFilter(array(
974
+ array(
975
+ 'attribute' => 'entity_id',
976
+ 'nin' => $disabledProductIds
977
+ )
978
+ ));
979
+ }
980
+
981
+ if (count($inProductIds) > 0) {
982
+ $querySearchProductInCategory->addAttributeToFilter(array(
983
+ array(
984
+ 'attribute' => 'entity_id',
985
+ 'in' => $inProductIds
986
+ )
987
+ ));
988
+ }
989
 
990
+ $sqlGetProductList = $querySearchProductInCategory
991
  ->addAttributeToSelect('name')
992
  ->addStoreFilter($storeId)
993
  ->addAttributeToFilter(array(
995
  'attribute' => 'name',
996
  'like' => '%' . $this->clean_url($keyword) . '%'
997
  ),
 
 
 
 
998
  array(
999
  'attribute' => 'short_description',
1000
  'like' => '%' . $this->clean_url($keyword) . '%'
1007
  'in' => array(3, 4)
1008
  )
1009
  ))
1010
+ // ->addFinalPrice()
1011
  ->addFieldToFilter("status", 1)
1012
+ ->getSelect()
1013
+ ->order($_orderBy . ' ' . $_typeOrder)
1014
+ ->limit($_pageSize, $_start)
1015
  ;
1016
+ $productsList = $read->fetchAll($sqlGetProductList);
1017
  } else if ($showProductsInSubCategories) {
1018
  $children_category_ids = $category->getChildren();
1019
+ $active_children_category_ids = array_intersect(explode(',', $children_category_ids), $listActiveCategory);
1020
+
1021
  $resource = Mage::getSingleton("core/resource");
1022
  $read = $resource->getConnection("core_read");
1023
 
1024
+ $queryCountSearchProductInSubCategory = Mage::getModel('catalog/product')->getCollection()
1025
+ ->addStoreFilter($storeId);
1026
+ if (count($disabledProductIds) > 0) {
1027
+ $queryCountSearchProductInSubCategory->addAttributeToFilter(array(
1028
+ array(
1029
+ 'attribute' => 'entity_id',
1030
+ 'nin' => $disabledProductIds
1031
+ )
1032
+ ));
1033
+ }
1034
+
1035
+ if (count($inProductIds) > 0) {
1036
+ $queryCountSearchProductInSubCategory->addAttributeToFilter(array(
1037
+ array(
1038
+ 'attribute' => 'entity_id',
1039
+ 'in' => $inProductIds
1040
+ )
1041
+ ));
1042
+ }
1043
+
1044
+ $sqlCountFoundProducts = $queryCountSearchProductInSubCategory
1045
  ->addStoreFilter($storeId)
1046
  ->addAttributeToFilter(array(
1047
  array(
1048
  'attribute' => 'name',
1049
  'like' => '%' . $this->clean_url($keyword) . '%'
1050
  ),
 
 
 
 
1051
  array(
1052
  'attribute' => 'short_description',
1053
  'like' => '%' . $this->clean_url($keyword) . '%'
1061
  ))
1062
  ->addFieldToFilter("status", 1)
1063
  ->addAttributeToSort($_orderBy, $_typeOrder)
1064
+ ->getSelectCountSql()
1065
+ ->join(array('B' => Mage::getSingleton('core/resource')->getTableName('catalog_category_product')),
 
1066
  'e.entity_id = B.product_id', '')
1067
+ ->where('B.category_id in (?)', $active_children_category_ids)
1068
+ ;
1069
 
1070
+ $totalProducts = $read->fetchRow($sqlCountFoundProducts);
1071
+ foreach ($totalProducts as $v) {
1072
+ $totalProducts = $v;
1073
+ break;
1074
  }
 
1075
 
1076
+ $querySearchProductInSubCategory = Mage::getModel('catalog/product')->getCollection()
1077
+ ->addStoreFilter($storeId);
1078
+ if (count($disabledProductIds) > 0) {
1079
+ $querySearchProductInSubCategory->addAttributeToFilter(array(
1080
+ array(
1081
+ 'attribute' => 'entity_id',
1082
+ 'nin' => $disabledProductIds
1083
+ )
1084
+ ));
1085
+ }
1086
+
1087
+ if (count($inProductIds) > 0) {
1088
+ $querySearchProductInSubCategory->addAttributeToFilter(array(
1089
+ array(
1090
+ 'attribute' => 'entity_id',
1091
+ 'in' => $inProductIds
1092
+ )
1093
+ ));
1094
+ }
1095
+
1096
+ $sqlGetProductList = $querySearchProductInSubCategory->addAttributeToFilter(array(
1097
  array(
1098
  'attribute' => 'visibility',
1099
  'in' => array(3, 4)
1100
  )
1101
  ))
1102
+ // ->addFinalPrice()
1103
  ->addFieldToFilter("status", 1)
1104
+ ->getSelect()
1105
+ ->join(array('B' => Mage::getSingleton('core/resource')->getTableName('catalog_category_product')),
1106
+ 'e.entity_id = B.product_id', '')
1107
+ ->where('B.category_id in (?)', $active_children_category_ids)
1108
+ ->order($_orderBy . ' ' . $_typeOrder)
1109
+ ->limit($_pageSize, $_start);
1110
+ $productsList = $read->fetchAll($sqlGetProductList);
1111
+ } else {
1112
+ throw new Magestore_Mageconnector_Exception(Magestore_Mageconnector_Exception::NO_PRODUCT);
1113
  }
1114
  }
1115
 
1116
  $list = array();
1117
+
1118
+ foreach ($productsList as $p) {
1119
  $product = Mage::getModel('catalog/product')
1120
  ->setStoreId($storeId)
1121
+ ->load($p['entity_id']);
 
1122
  $list[] = $product;
1123
  }
1124
 
1127
  $totalPages++;
1128
  }
1129
 
1130
+ return $this->exportXML($baseUrl, $store->getCode(), $list, $totalProducts, $totalPages, $_currentPage, $_pageSize, $_orderBy, $_typeOrder);
1131
  }
1132
 
1133
  /**
1134
  * Get product detail
1135
+ *
1136
+ * @param string $productId
1137
+ * @param string $baseUrl
1138
+ * @param string $storeCode
1139
+ * @return string
1140
  */
1141
+ public function getProductDetail($productId, $baseUrl, $storeCode = null) {
1142
  try {
1143
+ $store = Mage::app()->getStore();
 
1144
  $product = Mage::getModel('catalog/product')
1145
+ ->setStoreId($store->getId())
1146
+ ->load($productId);
1147
 
1148
+ $xml = '<?xml version="1.0"?><massale-product-detail>';
 
 
 
 
1149
  $i = 0;
1150
+ $xml .= $this->exportXMLProduct($product, $baseUrl, $store->getCode(), $i, true);
1151
+ $xml .= '</massale-product-detail>';
1152
 
1153
  return $xml;
1154
  } catch (Exception $e) {
1155
+
 
1156
  }
1157
  }
1158
 
1159
  public function clean_url($text) {
1160
+ $text = urldecode($text);
1161
+ // $text = strtolower($text);
1162
+ // $code_entities_match = array(' ', '--', '&quot;', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '{', '}', '|', ':', '"', '<', '>', '?', '[', ']', '\\', ';', "'", ',', '.', '/', '*', '+', '~', '`', '=');
1163
+ // $code_entities_replace = array('-', '-', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');
1164
+ // $text = str_replace($code_entities_match, $code_entities_replace, $text);
1165
+ return trim($text);
1166
  }
1167
 
1168
  }
app/code/local/Magestore/Mageconnector/controllers/IndexController.php CHANGED
@@ -3,176 +3,268 @@
3
  class Magestore_Mageconnector_IndexController extends Mage_Core_Controller_Front_Action {
4
 
5
  public function indexAction() {
6
- $action = $this->getRequest()->get('action');
7
-
8
- switch ($action) {
9
- case 'xml':
10
- $this->xml();
11
- break;
12
- case 'view':
13
- $this->storeView();
14
- break;
15
- case 'category':
16
- $this->category();
17
- break;
18
- case 'addToCart':
19
- $this->addToCart();
20
- break;
21
- case 'refreshCart':
22
- $this->refreshCart();
23
- break;
24
- case 'updateCart':
25
- $this->updateCart();
26
- break;
27
- case 'cartApplyCoupon':
28
- $this->cartApplyCoupon();
29
- break;
30
- case 'cartCancelCoupon':
31
- $this->cartCancelCoupon();
32
- break;
33
- case 'deleteCartItem':
34
- $this->deleteCartItem();
35
- break;
36
- case 'checkout':
37
- $this->checkout();
38
- break;
39
- default:
40
- $this->product();
41
- }
42
- }
43
 
44
- private function checkout() {
45
- $view = $this->getRequest()->getParam('view');
46
- if (!is_null($view) && $view != '') {
47
- header("Location: " . Mage::getBaseUrl() . 'checkout/?___store=' . $view);
48
- } else {
49
- header("Location: " . Mage::getBaseUrl() . 'checkout/');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  }
51
  }
52
 
53
- private function addCartDataToUrl(&$url) {
54
- $cartData = Mage::getModel('mageconnector/cart')
55
- ->exportXML();
 
 
 
56
 
57
- $cartData = urlencode($cartData);
58
- $url .= "&cart=$cartData";
 
59
  }
60
 
61
- private function addToCart() {
62
- $result = Mage::getModel('mageconnector/cart')
63
- ->addToCart();
 
64
 
65
- $url = $_REQUEST['url'];
66
- if ($result) {
67
- $url .= "&addToCart=success";
68
- } else {
69
- $url .= "&addToCart=unsuccess";
 
 
 
 
 
 
70
  }
71
- $this->addCartDataToUrl($url);
72
- header("Location: $url");
73
  }
74
 
75
- private function refreshCart() {
76
- $url = $_REQUEST['url'];
77
- $url .= "&refreshCart=success";
78
- $this->addCartDataToUrl($url);
79
- header("Location: $url");
80
  }
81
 
82
- private function cartApplyCoupon() {
83
- $result = Mage::getModel('mageconnector/cart')
84
- ->applyCoupon();
 
 
 
 
85
 
86
- $url = $_REQUEST['couponUrl'];
87
- if ($result) {
88
- $url .= "&applyCoupon=success&couponCode=" . $_REQUEST['coupon_code'];
89
- } else {
90
- $url .= "&applyCoupon=unsuccess&couponCode=" . $_REQUEST['coupon_code'];
91
- }
92
- $this->addCartDataToUrl($url);
93
- header("Location: $url");
94
  }
95
 
96
- private function cartCancelCoupon() {
97
- $result = Mage::getModel('mageconnector/cart')
98
- ->cancelCoupon();
 
 
 
 
 
 
 
99
 
100
- $url = $_REQUEST['couponUrl'];
101
- if ($result) {
102
- $url .= "&cancelCoupon=success";
103
- } else {
104
- $url .= "&cancelCoupon=unsuccess";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  }
106
- $this->addCartDataToUrl($url);
107
- header("Location: $url");
108
  }
109
 
110
  private function updateCart() {
111
- $result = Mage::getModel('mageconnector/cart')
112
- ->updateCart();
 
113
 
114
- $url = $_REQUEST['url'];
115
- if ($result) {
116
- $url .= "&updateCart=success";
117
- } else {
118
- $url .= "&updateCart=unsuccess";
119
- }
120
- $this->addCartDataToUrl($url);
121
- header("Location: $url");
122
  }
123
 
124
  private function deleteCartItem() {
125
- $result = Mage::getModel('mageconnector/cart')
126
- ->deleteCartItem();
 
127
 
128
- $url = $_REQUEST['url'];
129
- if ($result) {
130
- $url .= "&deleteCartItem=success";
131
- } else {
132
- $url .= "&deleteCartItem=unsuccess";
133
- }
134
- $this->addCartDataToUrl($url);
135
- header("Location: $url");
136
  }
137
 
138
- private function storeView() {
139
- $output = Mage::helper('mageconnector')->getListStoreView();
 
 
140
 
141
- $response = $this->getResponse();
142
- $response->setHeader('Content-Type', 'text/xml; charset=utf-8')
143
- ->setBody($output);
 
 
 
 
144
  }
145
 
146
- private function category() {
147
- $store_code = $this->getRequest()->get('view');
 
 
148
 
149
- if ($store_code == '') {
150
- $store_code = null;
151
- }
 
152
 
153
- $output = Mage::getModel('mageconnector/category')
154
- ->exportXML($store_code);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
 
156
  $response = $this->getResponse();
157
  $response->setHeader('Content-Type', 'text/xml; charset=utf-8')
158
  ->setBody($output);
159
  }
160
 
161
- private function product() {
162
  $keyword = $this->getRequest()->get('keyword');
163
  $category = $this->getRequest()->get('category');
164
 
165
  if ($keyword != '') {
166
- $output = $this->productSearch($keyword, $category);
167
  } else {
168
- $urlKey = $this->getRequest()->get('url_key');
169
- if ($urlKey != '') {
170
- $output = $this->productDetail($urlKey);
171
  } else {
172
  if ($category != '') {
173
- $output = $this->productCategory($category);
174
  } else {
175
- $output = $this->allProducts();
176
  }
177
  }
178
  }
@@ -182,88 +274,86 @@ class Magestore_Mageconnector_IndexController extends Mage_Core_Controller_Front
182
  ->setBody($output);
183
  }
184
 
185
- private function productCategory($category) {
186
- $store_code = $this->getRequest()->get('view');
187
-
188
  $currentPage = $this->getRequest()->get('page');
189
  $pageSize = $this->getRequest()->get('pageSize');
190
  $orderBy = $this->getRequest()->get('orderBy');
191
  $typeOrder = $this->getRequest()->get('typeOrder');
192
  $showProductsInSubCategories = $this->getRequest()->get('showProductsInSubCategories');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
 
194
  return Mage::getModel('mageconnector/product')
195
- ->getProductListByCategory($store_code, $category, $currentPage, $pageSize, $orderBy, $typeOrder, $showProductsInSubCategories);
196
  }
197
 
198
- private function productSearch($keyword, $category) {
199
- $store_code = $this->getRequest()->get('view');
200
-
201
  $currentPage = $this->getRequest()->get('page');
202
  $pageSize = $this->getRequest()->get('pageSize');
203
  $orderBy = $this->getRequest()->get('orderBy');
204
  $typeOrder = $this->getRequest()->get('typeOrder');
205
  $showProductsInSubCategories = $this->getRequest()->get('showProductsInSubCategories');
 
 
 
206
 
207
- return Mage::getModel('mageconnector/product')
208
- ->searchProduct($store_code, $keyword, $category, $currentPage, $pageSize, $orderBy, $typeOrder, $showProductsInSubCategories);
209
- }
210
 
211
- private function productDetail($productUrlKey) {
212
- $store_code = $this->getRequest()->get('view');
 
 
 
 
 
 
 
213
 
214
  return Mage::getModel('mageconnector/product')
215
- ->getProductDetail($store_code, $productUrlKey);
216
  }
217
 
218
- private function allProducts() {
219
- $store_code = $this->getRequest()->get('view');
 
 
220
 
 
221
  $currentPage = $this->getRequest()->get('page');
222
  $pageSize = $this->getRequest()->get('pageSize');
223
  $orderBy = $this->getRequest()->get('orderBy');
224
  $typeOrder = $this->getRequest()->get('typeOrder');
 
 
 
225
 
226
- return Mage::getModel('mageconnector/product')
227
- ->searchProduct($store_code, '', '', $currentPage, $pageSize, $orderBy, $typeOrder);
228
- }
229
 
230
- public function xml() {
231
- $products = Mage::getModel('catalog/product')->getCollection()
232
- ->addAttributeToSelect('name')
233
- ->addStoreFilter(1)
234
- ->addAttributeToFilter(array(
235
- array(
236
- 'attribute' => 'visibility',
237
- 'in' => array(3, 4)
238
- )
239
- ))
240
- ->addFieldToFilter("status", 1);
241
-
242
- $xml = '<?xml version="1.0"?><products>';
243
-
244
- $i = 0;
245
- foreach ($products as $p) {
246
- $product = Mage::getModel('catalog/product')
247
- ->setStoreId(1)
248
- ->load($p->getId());
249
- $xml .= '<product order="#' . ++$i . '">'
250
- . '<id>' . $product->getId() . '</id>'
251
- . '<name><![CDATA[' . $product->getName() . ']]></name>'
252
- . '<price><![CDATA[' . Mage::helper('core')
253
- ->currency(Mage::helper('tax')
254
- ->getPrice(
255
- $product,
256
- $product->getFinalPrice()
257
- )
258
- , true, false) . ']]></price>'
259
- . '<description><![CDATA[' . $product->getShortDescription() . ']]></description>'
260
- . '</product>';
261
  }
262
 
263
- $xml .= '</products>';
264
- $response = $this->getResponse();
265
- $response->setHeader('Content-Type', 'text/xml; charset=utf-8')
266
- ->setBody($xml);
267
  }
268
 
269
  }
3
  class Magestore_Mageconnector_IndexController extends Mage_Core_Controller_Front_Action {
4
 
5
  public function indexAction() {
6
+ try {
7
+ $action = $this->getRequest()->get('action');
8
+ $storeCode = $this->getRequest()->get('view');
9
+ $baseUrl = $this->getParamBaseUrl();
10
+ if ($action != 'version' && $action != 'refreshModule') {
11
+ Mage::helper('mageconnector')->editCurrentStore($baseUrl, $storeCode);
12
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ switch ($action) {
15
+ case 'refreshModule':
16
+ $this->refreshModule();
17
+ break;
18
+ case 'version':
19
+ $this->getCurrentVersion();
20
+ break;
21
+ case 'view':
22
+ $this->storeView($baseUrl);
23
+ break;
24
+ case 'category':
25
+ $this->category();
26
+ break;
27
+ case 'checkout':
28
+ $this->checkout($baseUrl, $storeCode);
29
+ break;
30
+
31
+ case 'addToCart':
32
+ $this->addToCart();
33
+ break;
34
+ case 'refreshCart':
35
+ $this->refreshCart();
36
+ break;
37
+ case 'updateCart':
38
+ $this->updateCart();
39
+ break;
40
+ case 'cartApplyCoupon':
41
+ $this->cartApplyCoupon();
42
+ break;
43
+ case 'cartCancelCoupon':
44
+ $this->cartCancelCoupon();
45
+ break;
46
+ case 'deleteCartItem':
47
+ $this->deleteCartItem();
48
+ break;
49
+ case 'cart':
50
+ $this->cartData();
51
+ break;
52
+
53
+ case 'totalProducts':
54
+ $this->totalProducts();
55
+ break;
56
+ default:
57
+ $this->product($baseUrl, $storeCode);
58
+ }
59
+ } catch (Magestore_Mageconnector_Exception $e) {
60
+ $xml = '<?xml version="1.0"?><exception><message><![CDATA[' . $e->getMessage() . ']]></message></exception>';
61
+ $response = $this->getResponse();
62
+ $response->setHeader('Content-Type', 'text/xml; charset=utf-8')
63
+ ->setBody($xml);
64
  }
65
  }
66
 
67
+ private function refreshModule() {
68
+ $db = Mage::getSingleton('core/resource')->getConnection('core_write');
69
+ $db->query("
70
+
71
+ DELETE FROM " . Mage::getModel('core/resource')->getTableName('core/resource') . "
72
+ WHERE `code` = 'mageconnector_setup';
73
 
74
+ ");
75
+
76
+ $this->getCurrentVersion();
77
  }
78
 
79
+ private function totalProducts() {
80
+ $output = Mage::getModel('mageconnector/product')
81
+ ->totalProducts(
82
+ );
83
 
84
+ $response = $this->getResponse();
85
+ $response->setHeader('Content-Type', 'text/xml; charset=utf-8')
86
+ ->setBody($output);
87
+ }
88
+
89
+ private function getParamBaseUrl() {
90
+ $baseUrl = $this->getRequest()->get('baseUrl');
91
+ $baseUrl = $this->prepareUrl($baseUrl);
92
+ $baseUrl = explode('index.php', $baseUrl);
93
+ if (count($baseUrl)) {
94
+ $baseUrl = rtrim($baseUrl[0], '/');
95
  }
96
+ return $baseUrl . '/';
 
97
  }
98
 
99
+ private function prepareUrl($url) {
100
+ $url = urldecode($url);
101
+ $urlReplace = $this->getRequest()->get('urlReplace');
102
+ $url = str_replace($urlReplace, '/', $url);
103
+ return $url;
104
  }
105
 
106
+ /**
107
+ * Get Current Version of this module
108
+ *
109
+ */
110
+ private function getCurrentVersion() {
111
+ $version = new Magestore_Mageconnector_Model_Information();
112
+ $output = $version->getVersion();
113
 
114
+ $response = $this->getResponse();
115
+ $response->setHeader('Content-Type', 'text/xml; charset=utf-8')
116
+ ->setBody($output);
 
 
 
 
 
117
  }
118
 
119
+ /**
120
+ * Get list store view by base url
121
+ *
122
+ * @param string $baseUrl
123
+ */
124
+ private function storeView($baseUrl) {
125
+ $output = Mage::helper('mageconnector')
126
+ ->getListStoreViewCodesByStoreBaseUrl(
127
+ $baseUrl
128
+ );
129
 
130
+ $response = $this->getResponse();
131
+ $response->setHeader('Content-Type', 'text/xml; charset=utf-8')
132
+ ->setBody($output);
133
+ }
134
+
135
+ private function category() {
136
+ $output = Mage::getModel('mageconnector/category')
137
+ ->exportXML();
138
+
139
+ $response = $this->getResponse();
140
+ $response->setHeader('Content-Type', 'text/xml; charset=utf-8')
141
+ ->setBody($output);
142
+ }
143
+
144
+ private function checkout($baseUrl, $storeCode) {
145
+ $checkoutUrl = Mage::getBaseUrl() . 'checkout/';
146
+ $checkoutUrl = Mage::helper('mageconnector')->prepareUrl($baseUrl, $checkoutUrl, $storeCode);
147
+ header("Location: $checkoutUrl");
148
+ exit(0);
149
+ }
150
+
151
+ private function addToCart() {
152
+ try {
153
+ include_once Mage::getBaseDir() . DS . 'app' . DS . 'code' . DS . 'local' . DS .
154
+ 'Magestore' . DS . 'Mageconnector' . DS .
155
+ 'controllers' . DS . 'Override' . DS . 'Mage' . DS . 'Checkout' . DS . 'CartController.php';
156
+
157
+ $cartController = new Magestore_Mageconnector_Mage_Checkout_CartController($this->getRequest(), $this->getResponse());
158
+ $backUrl = $this->getRequest()->get('url');
159
+ $backUrl = $this->prepareUrl($backUrl);
160
+ $backUrl = $cartController->addAction($backUrl);
161
+ header("Location: " . $backUrl);
162
+ exit(0);
163
+ } catch (Exception $e) {
164
+ // Zend_Debug::dump($e);
165
  }
 
 
166
  }
167
 
168
  private function updateCart() {
169
+ include_once Mage::getBaseDir() . DS . 'app' . DS . 'code' . DS . 'local' . DS .
170
+ 'Magestore' . DS . 'Mageconnector' . DS .
171
+ 'controllers' . DS . 'Override' . DS . 'Mage' . DS . 'Checkout' . DS . 'CartController.php';
172
 
173
+ $cartController = new Magestore_Mageconnector_Mage_Checkout_CartController($this->getRequest(), $this->getResponse());
174
+ $backUrl = $this->getRequest()->get('url');
175
+ $backUrl = $this->prepareUrl($backUrl);
176
+ $backUrl = $cartController->updatePostAction($backUrl);
177
+
178
+ header("Location: " . $backUrl);
179
+ exit(0);
 
180
  }
181
 
182
  private function deleteCartItem() {
183
+ include_once Mage::getBaseDir() . DS . 'app' . DS . 'code' . DS . 'local' . DS .
184
+ 'Magestore' . DS . 'Mageconnector' . DS .
185
+ 'controllers' . DS . 'Override' . DS . 'Mage' . DS . 'Checkout' . DS . 'CartController.php';
186
 
187
+ $cartController = new Magestore_Mageconnector_Mage_Checkout_CartController($this->getRequest(), $this->getResponse());
188
+ $backUrl = $this->getRequest()->get('url');
189
+ $backUrl = $this->prepareUrl($backUrl);
190
+ $backUrl = $cartController->deleteAction($backUrl);
191
+
192
+ header("Location: " . $backUrl);
193
+ exit(0);
 
194
  }
195
 
196
+ private function refreshCart() {
197
+ include_once Mage::getBaseDir() . DS . 'app' . DS . 'code' . DS . 'local' . DS .
198
+ 'Magestore' . DS . 'Mageconnector' . DS .
199
+ 'controllers' . DS . 'Override' . DS . 'Mage' . DS . 'Checkout' . DS . 'CartController.php';
200
 
201
+ $cartController = new Magestore_Mageconnector_Mage_Checkout_CartController($this->getRequest(), $this->getResponse());
202
+ $backUrl = $this->getRequest()->get('url');
203
+ $backUrl = $this->prepareUrl($backUrl);
204
+ $backUrl = $cartController->refreshAction($backUrl);
205
+
206
+ header("Location: " . $backUrl);
207
+ exit(0);
208
  }
209
 
210
+ private function cartApplyCoupon() {
211
+ include_once Mage::getBaseDir() . DS . 'app' . DS . 'code' . DS . 'local' . DS .
212
+ 'Magestore' . DS . 'Mageconnector' . DS .
213
+ 'controllers' . DS . 'Override' . DS . 'Mage' . DS . 'Checkout' . DS . 'CartController.php';
214
 
215
+ $cartController = new Magestore_Mageconnector_Mage_Checkout_CartController($this->getRequest(), $this->getResponse());
216
+ $backUrl = $this->getRequest()->get('couponUrl');
217
+ $backUrl = $this->prepareUrl($backUrl);
218
+ $backUrl = $cartController->couponPostAction($backUrl);
219
 
220
+ header("Location: " . $backUrl);
221
+ exit(0);
222
+ }
223
+
224
+ private function cartCancelCoupon() {
225
+ include_once Mage::getBaseDir() . DS . 'app' . DS . 'code' . DS . 'local' . DS .
226
+ 'Magestore' . DS . 'Mageconnector' . DS .
227
+ 'controllers' . DS . 'Override' . DS . 'Mage' . DS . 'Checkout' . DS . 'CartController.php';
228
+
229
+ $cartController = new Magestore_Mageconnector_Mage_Checkout_CartController($this->getRequest(), $this->getResponse());
230
+ $backUrl = $this->getRequest()->get('couponUrl');
231
+ $backUrl = $this->prepareUrl($backUrl);
232
+ $backUrl = $cartController->cancelCouponAction($backUrl);
233
+
234
+ header("Location: " . $backUrl);
235
+ exit(0);
236
+ }
237
+
238
+ private function cartData() {
239
+ include_once Mage::getBaseDir() . DS . 'app' . DS . 'code' . DS . 'local' . DS .
240
+ 'Magestore' . DS . 'Mageconnector' . DS .
241
+ 'controllers' . DS . 'Override' . DS . 'Mage' . DS . 'Checkout' . DS . 'CartController.php';
242
+
243
+ $cartController = new Magestore_Mageconnector_Mage_Checkout_CartController($this->getRequest(), $this->getResponse());
244
+ $backUrl = $this->getRequest()->get('url');
245
+ $backUrl = $this->prepareUrl($backUrl);
246
+ $output = $cartController->getCartDataAction();
247
 
248
  $response = $this->getResponse();
249
  $response->setHeader('Content-Type', 'text/xml; charset=utf-8')
250
  ->setBody($output);
251
  }
252
 
253
+ private function product($baseUrl, $storeCode) {
254
  $keyword = $this->getRequest()->get('keyword');
255
  $category = $this->getRequest()->get('category');
256
 
257
  if ($keyword != '') {
258
+ $output = $this->productSearch($baseUrl, $storeCode, $keyword, $category, $baseUrl, $storeCode);
259
  } else {
260
+ $productId = $this->getRequest()->get('product_id');
261
+ if ($productId != '') {
262
+ $output = $this->productDetail($productId, $baseUrl, $storeCode);
263
  } else {
264
  if ($category != '') {
265
+ $output = $this->productCategory($category, $baseUrl, $storeCode);
266
  } else {
267
+ $output = $this->allProducts($baseUrl, $storeCode);
268
  }
269
  }
270
  }
274
  ->setBody($output);
275
  }
276
 
277
+ private function productCategory($category, $baseUrl, $storeCode) {
 
 
278
  $currentPage = $this->getRequest()->get('page');
279
  $pageSize = $this->getRequest()->get('pageSize');
280
  $orderBy = $this->getRequest()->get('orderBy');
281
  $typeOrder = $this->getRequest()->get('typeOrder');
282
  $showProductsInSubCategories = $this->getRequest()->get('showProductsInSubCategories');
283
+ $disabledProductIds = $this->getRequest()->get('disabledProductIds');
284
+ $inProductIds = $this->getRequest()->get('inProductIds');
285
+ $excludeCategoryIds = $this->getRequest()->get('excludeCategories');
286
+
287
+ $excludeCategoryIds = explode(',', $excludeCategoryIds);
288
+
289
+ if ($disabledProductIds != '') {
290
+ $disabledProductIds = explode(',', $disabledProductIds);
291
+ }
292
+ if ($inProductIds != '') {
293
+ $inProductIds = explode(',', $inProductIds);
294
+ if (is_array($disabledProductIds) && count($disabledProductIds)) {
295
+ $inProductIds = array_diff($inProductIds, $disabledProductIds);
296
+ }
297
+ }
298
 
299
  return Mage::getModel('mageconnector/product')
300
+ ->getProductListByCategory($category, $excludeCategoryIds, $baseUrl, $storeCode, $disabledProductIds, $inProductIds, $currentPage, $pageSize, $orderBy, $typeOrder, $showProductsInSubCategories);
301
  }
302
 
303
+ private function productSearch($baseUrl, $storeCode, $keyword, $category) {
 
 
304
  $currentPage = $this->getRequest()->get('page');
305
  $pageSize = $this->getRequest()->get('pageSize');
306
  $orderBy = $this->getRequest()->get('orderBy');
307
  $typeOrder = $this->getRequest()->get('typeOrder');
308
  $showProductsInSubCategories = $this->getRequest()->get('showProductsInSubCategories');
309
+ $disabledProductIds = $this->getRequest()->get('disabledProductIds');
310
+ $inProductIds = $this->getRequest()->get('inProductIds');
311
+ $excludeCategoryIds = $this->getRequest()->get('excludeCategories');
312
 
313
+ $excludeCategoryIds = explode(',', $excludeCategoryIds);
 
 
314
 
315
+ if ($disabledProductIds != '') {
316
+ $disabledProductIds = explode(',', $disabledProductIds);
317
+ }
318
+ if ($inProductIds != '') {
319
+ $inProductIds = explode(',', $inProductIds);
320
+ if (is_array($disabledProductIds) && count($disabledProductIds)) {
321
+ $inProductIds = array_diff($inProductIds, $disabledProductIds);
322
+ }
323
+ }
324
 
325
  return Mage::getModel('mageconnector/product')
326
+ ->searchProduct($baseUrl, $storeCode, $disabledProductIds, $inProductIds, $keyword, $category, $excludeCategoryIds, $currentPage, $pageSize, $orderBy, $typeOrder, $showProductsInSubCategories);
327
  }
328
 
329
+ private function productDetail($productId, $baseUrl, $storeCode) {
330
+ return Mage::getModel('mageconnector/product')
331
+ ->getProductDetail($productId, $baseUrl, $storeCode);
332
+ }
333
 
334
+ private function allProducts($baseUrl, $storeCode) {
335
  $currentPage = $this->getRequest()->get('page');
336
  $pageSize = $this->getRequest()->get('pageSize');
337
  $orderBy = $this->getRequest()->get('orderBy');
338
  $typeOrder = $this->getRequest()->get('typeOrder');
339
+ $disabledProductIds = $this->getRequest()->get('disabledProductIds');
340
+ $inProductIds = $this->getRequest()->get('inProductIds');
341
+ $excludeCategoryIds = $this->getRequest()->get('excludeCategories');
342
 
343
+ $excludeCategoryIds = explode(',', $excludeCategoryIds);
 
 
344
 
345
+ if ($disabledProductIds != '') {
346
+ $disabledProductIds = explode(',', $disabledProductIds);
347
+ }
348
+ if ($inProductIds != '') {
349
+ $inProductIds = explode(',', $inProductIds);
350
+ if (is_array($disabledProductIds) && count($disabledProductIds)) {
351
+ $inProductIds = array_diff($inProductIds, $disabledProductIds);
352
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  }
354
 
355
+ return Mage::getModel('mageconnector/product')
356
+ ->searchProduct($baseUrl, $storeCode, $disabledProductIds, $inProductIds, '', '', $excludeCategoryIds, $currentPage, $pageSize, $orderBy, $typeOrder);
 
 
357
  }
358
 
359
  }
app/code/local/Magestore/Mageconnector/controllers/Override/Mage/Checkout/CartController.php ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ include_once Mage::getBaseDir() . DS . 'app' . DS . 'code' . DS . 'core' . DS . 'Mage' . DS . 'Checkout' . DS . 'controllers' . DS . 'CartController.php';
4
+
5
+ class Magestore_Mageconnector_Mage_Checkout_CartController extends Mage_Checkout_CartController {
6
+
7
+ public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array()) {
8
+ parent::__construct($request, $response, $invokeArgs);
9
+ }
10
+
11
+ protected function _goBack() {
12
+ $this->flagAddCartError = true;
13
+ return;
14
+ }
15
+
16
+ protected function _getCart() {
17
+ $backUrl = $this->backUrl . "&addToCart=unsuccess";
18
+ $this->addCartDataToUrl($backUrl);
19
+ return Mage::getModel('mageconnector/override_mage_checkout_cart')->setProductUrlWhenAddCartError($backUrl);
20
+ }
21
+
22
+ private $backUrl;
23
+ private $flagAddCartError = false;
24
+
25
+ public function addAction($backUrl = null) {
26
+ $this->backUrl = $backUrl;
27
+ $this->getRequest()->setParam('related_product', '');
28
+ parent::addAction();
29
+ $this->_getSession()->getMessages(true);
30
+
31
+ $backUrl .= "&addToCart=success";
32
+ $this->addCartDataToUrl($backUrl);
33
+ return $backUrl;
34
+ }
35
+
36
+ public function updatePostAction($backUrl = null) {
37
+ parent::updatePostAction();
38
+ $this->_getSession()->getMessages(true);
39
+
40
+ $backUrl .= "&updateCart=success";
41
+ $this->addCartDataToUrl($backUrl);
42
+ return $backUrl;
43
+ }
44
+
45
+ public function deleteAction($backUrl = null) {
46
+ $item = $this->getRequest()->get('item');
47
+ $deleted = false;
48
+ if ($item) {
49
+ try {
50
+ $cart = Mage::getSingleton('checkout/cart')->removeItem($item)
51
+ ->save();
52
+ $deleted = true;
53
+ } catch (Exception $e) {
54
+
55
+ }
56
+ }
57
+ if ($deleted) {
58
+ $backUrl .= "&deleteCartItem=success";
59
+ } else {
60
+ $backUrl .= "&deleteCartItem=unsuccess";
61
+ }
62
+
63
+ $this->addCartDataToUrl($backUrl);
64
+ return $backUrl;
65
+ }
66
+
67
+ public function refreshAction($backUrl) {
68
+ $this->addCartDataToUrl($backUrl);
69
+ $backUrl .= "&refreshCart=success";
70
+ return $backUrl;
71
+ }
72
+
73
+ public function couponPostAction($backUrl = null) {
74
+ parent::couponPostAction();
75
+ $this->_getSession()->getMessages(true);
76
+
77
+ if ($this->_getQuote()->getCouponCode() == $this->getRequest()->get('coupon_code')) {
78
+ $backUrl .= "&applyCoupon=success&couponCode=" . $this->getRequest()->get('coupon_code');
79
+ } else {
80
+ $backUrl .= "&applyCoupon=unsuccess&couponCode=" . $this->getRequest()->get('coupon_code');
81
+ }
82
+
83
+ $this->addCartDataToUrl($backUrl);
84
+ return $backUrl;
85
+ }
86
+
87
+ public function cancelCouponAction($backUrl) {
88
+ $cancelled = false;
89
+ try {
90
+ Mage::getSingleton('checkout/cart')->getQuote()->getShippingAddress()->setCollectShippingRates(true);
91
+ Mage::getSingleton('checkout/cart')->getQuote()->setCouponCode('')
92
+ ->collectTotals()
93
+ ->save();
94
+
95
+ $cancelled = true;
96
+ } catch (Exception $e) {
97
+
98
+ }
99
+
100
+ if ($cancelled) {
101
+ $backUrl .= "&cancelCoupon=success";
102
+ } else {
103
+ $backUrl .= "&cancelCoupon=unsuccess";
104
+ }
105
+ $this->addCartDataToUrl($backUrl);
106
+ return $backUrl;
107
+ }
108
+
109
+ /**
110
+ * Get Cart data by store view
111
+ *
112
+ * @param string $baseUrl
113
+ * @param string $storeCode
114
+ */
115
+ public function getCartDataAction() {
116
+ return $this->exportXml();
117
+ }
118
+
119
+ private function addCartDataToUrl(&$backUrl) {
120
+ $cartData = $this->exportCartXml();
121
+ $cartData = urlencode(base64_encode($cartData));
122
+ $backUrl .= "&cart=$cartData";
123
+ }
124
+
125
+ public function exportCartXml() {
126
+ $cartXML = '<?xml version="1.0" encoding="UTF-8"?><massale-cart>';
127
+
128
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
129
+ $items = $quote->getAllVisibleItems();
130
+
131
+ if (count($items) > 0) {
132
+ $cartXML .= '<products>';
133
+ $i = 0;
134
+ foreach ($items as $item) {
135
+ $product = $item->getProduct();
136
+
137
+ switch ($product->getTypeId()) {
138
+ case "configurable":
139
+ $blockId = "checkout/cart_item_renderer_configurable";
140
+ break;
141
+ case "bundle":
142
+ $blockId = "bundle/checkout_cart_item_renderer";
143
+ break;
144
+ case "downloadable":
145
+ $blockId = "downloadable/checkout_cart_item_renderer";
146
+ break;
147
+ default:
148
+ $blockId = "checkout/cart_item_renderer";
149
+ }
150
+
151
+ $block = Mage::getBlockSingleton($blockId)
152
+ ->setItem($item);
153
+
154
+ $imageUrl = $block->getProductThumbnail();
155
+ $imageUrl = str_replace('https://', 'http://', $imageUrl);
156
+ $cartXML .= '<product>'
157
+ . '<order>#' . (++$i) . '</order>'
158
+ . '<id>' . $block->getItem()->getId() . '</id>'
159
+ . '<name><![CDATA[' . $block->htmlEscape($block->getProductName()) . ']]></name>'
160
+ . '<image><![CDATA[' . $imageUrl . ']]></image>'
161
+ . '<url_key><![CDATA[' . $product->getUrlKey() . ']]></url_key>';
162
+
163
+ if ($_options = $block->getOptionList()):
164
+ $cartXML .= '<options>';
165
+ foreach ($_options as $_option):
166
+ $_formatedOptionValue = $block->getFormatedOptionValue($_option);
167
+ $cartXML .= '<option>'
168
+ . '<label><![CDATA[' . $block->htmlEscape($_option['label']) . ']]></label>'
169
+ . '<value><![CDATA[' . $_formatedOptionValue['value'] . ']]></value>'
170
+ . '</option>'
171
+ ;
172
+ endforeach;
173
+ $cartXML .= '</options>';
174
+ endif;
175
+
176
+ $cartXML .= '<qty>' . $item->getQty() . '</qty>';
177
+
178
+ $price = Mage::helper('core')
179
+ ->currency($item->getPrice(), true, false);
180
+ $rowsubtotal = Mage::helper('core')
181
+ ->currency($item->getRowTotal(), true, false);
182
+
183
+ $cartXML .= '<price><![CDATA[' . $price . ']]></price>';
184
+ $cartXML .= '<subtotal><![CDATA[' . $rowsubtotal . ']]></subtotal>';
185
+ $cartXML .= '</product>';
186
+ }
187
+ $cartXML .= '</products>';
188
+ $cartXML .= '<hasCoupon>' . ($quote->getCouponCode() != '') . '</hasCoupon>';
189
+
190
+ $quoteTotals = $quote->getTotals();
191
+ $cartXML .= '<totals>';
192
+ foreach ($quoteTotals as $k => $v) {
193
+ $cartXML .= '<' . $k . '>';
194
+ $cartXML .= '<title><![CDATA[' . $v->title . ']]></title>';
195
+ $cartXML .= '<value><![CDATA[' . Mage::helper('core')
196
+ ->currency($v->value, true, false) . ']]></value>';
197
+ $cartXML .= '</' . $k . '>';
198
+ }
199
+ $cartXML .= '</totals>';
200
+ } else {
201
+ $cartXML .= 'empty';
202
+ }
203
+ $cartXML .= '</massale-cart>';
204
+ return $cartXML;
205
+ }
206
+
207
+ }
app/code/local/Magestore/Mageconnector/etc/adminhtml.xml DELETED
@@ -1,46 +0,0 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <menu>
4
- <catalog>
5
- <children>
6
- <mageconnector>
7
- <title>Magestore Connector Settings</title>
8
- <sort_order>20</sort_order>
9
- <action>adminhtml/system_config/edit/section/mageconnector</action>
10
- </mageconnector>
11
- </children>
12
- </catalog>
13
- </menu>
14
- <acl>
15
- <resources>
16
- <all>
17
- <title>Allow Everything</title>
18
- </all>
19
- <admin>
20
- <children>
21
- <catalog>
22
- <children>
23
- <mageconnector>
24
- <title>Magestore Connector Settings</title>
25
- <sort_order>20</sort_order>
26
- <action>adminhtml/system_config/edit/section/mageconnector</action>
27
- </mageconnector>
28
- </children>
29
- </catalog>
30
- <system>
31
- <children>
32
- <config>
33
- <children>
34
- <mageconnector translate="title">
35
- <title>Magestore Connector Settings</title>
36
- <sort_order>50</sort_order>
37
- </mageconnector>
38
- </children>
39
- </config>
40
- </children>
41
- </system>
42
- </children>
43
- </admin>
44
- </resources>
45
- </acl>
46
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/local/Magestore/Mageconnector/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Magestore_Mageconnector>
5
- <version>0.1.0</version>
6
  </Magestore_Mageconnector>
7
  </modules>
8
  <frontend>
@@ -25,66 +25,48 @@
25
  </frontend>
26
  <admin>
27
  <routers>
28
- <mageconnector>
29
- <use>admin</use>
30
- <args>
31
- <module>Magestore_Mageconnector</module>
32
- <frontName>mageconnector</frontName>
33
- </args>
34
- </mageconnector>
35
  </routers>
36
  </admin>
37
  <adminhtml>
38
- <menu>
39
- <catalog>
40
- <children>
41
- <mageconnector>
42
- <title>Magestore Connector Settings</title>
43
- <sort_order>20</sort_order>
44
- <action>adminhtml/system_config/edit/section/mageconnector</action>
45
- </mageconnector>
46
- </children>
47
- </catalog>
48
- </menu>
49
- <acl>
50
- <resources>
51
- <all>
52
- <title>Allow Everything</title>
53
- </all>
54
- <admin>
55
- <children>
56
- <catalog>
57
- <children>
58
- <mageconnector>
59
- <title>Magestore Connector Settings</title>
60
- <sort_order>20</sort_order>
61
- <action>adminhtml/system_config/edit/section/mageconnector</action>
62
- </mageconnector>
63
- </children>
64
- </catalog>
65
- <system>
66
  <children>
67
  <config>
68
  <children>
69
  <mageconnector translate="title">
70
- <title>Magestore Connector Settings</title>
71
  <sort_order>50</sort_order>
72
  </mageconnector>
73
  </children>
74
  </config>
75
  </children>
76
  </system>
77
- </children>
78
- </admin>
79
- </resources>
80
- </acl>
81
- <layout>
82
- <updates>
83
- <mageconnector>
84
- <file>mageconnector.xml</file>
85
- </mageconnector>
86
- </updates>
87
- </layout>
88
  </adminhtml>
89
  <global>
90
  <models>
@@ -96,7 +78,7 @@
96
  <class>Magestore_Mageconnector_Model_Mysql4</class>
97
  <entities>
98
  <mageconnector>
99
- <table>mageconnector_featured_products</table>
100
  </mageconnector>
101
  </entities>
102
  </mageconnector_mysql4>
2
  <config>
3
  <modules>
4
  <Magestore_Mageconnector>
5
+ <version>1.0.0.7</version>
6
  </Magestore_Mageconnector>
7
  </modules>
8
  <frontend>
25
  </frontend>
26
  <admin>
27
  <routers>
28
+ <mageconnector>
29
+ <use>admin</use>
30
+ <args>
31
+ <module>Magestore_Mageconnector</module>
32
+ <frontName>mageconnector</frontName>
33
+ </args>
34
+ </mageconnector>
35
  </routers>
36
  </admin>
37
  <adminhtml>
38
+ <menu>
39
+ </menu>
40
+ <acl>
41
+ <resources>
42
+ <all>
43
+ <title>Allow Everything</title>
44
+ </all>
45
+ <admin>
46
+ <children>
47
+ <system>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  <children>
49
  <config>
50
  <children>
51
  <mageconnector translate="title">
52
+ <title>Massale Magento Connector</title>
53
  <sort_order>50</sort_order>
54
  </mageconnector>
55
  </children>
56
  </config>
57
  </children>
58
  </system>
59
+ </children>
60
+ </admin>
61
+ </resources>
62
+ </acl>
63
+ <layout>
64
+ <updates>
65
+ <mageconnector>
66
+ <file>mageconnector.xml</file>
67
+ </mageconnector>
68
+ </updates>
69
+ </layout>
70
  </adminhtml>
71
  <global>
72
  <models>
78
  <class>Magestore_Mageconnector_Model_Mysql4</class>
79
  <entities>
80
  <mageconnector>
81
+ <table></table>
82
  </mageconnector>
83
  </entities>
84
  </mageconnector_mysql4>
app/code/local/Magestore/Mageconnector/etc/system.xml DELETED
@@ -1,43 +0,0 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <tabs>
4
- <magestore translate="label">
5
- <label>Magestore Extension</label>
6
- <sort_order>400</sort_order>
7
- </magestore>
8
- </tabs>
9
- <sections>
10
- <mageconnector translate="label" module="mageconnector">
11
- <class>separator-top</class>
12
- <label>Magestore Connector</label>
13
- <tab>magestore</tab>
14
- <frontend_type>text</frontend_type>
15
- <sort_order>300</sort_order>
16
- <show_in_default>1</show_in_default>
17
- <show_in_website>1</show_in_website>
18
- <show_in_store>1</show_in_store>
19
- <groups>
20
- <store translate="label">
21
- <label>Store View Connector Information</label>
22
- <frontend_type>text</frontend_type>
23
- <sort_order>0</sort_order>
24
- <show_in_default>1</show_in_default>
25
- <show_in_website>1</show_in_website>
26
- <show_in_store>1</show_in_store>
27
- <fields>
28
- <default_store_view translate="label">
29
- <label>Default store view</label>
30
- <frontend_type>select</frontend_type>
31
- <source_model>mageconnector/importstore</source_model>
32
- <sort_order>0</sort_order>
33
- <show_in_default>1</show_in_default>
34
- <show_in_website>1</show_in_website>
35
- <show_in_store>1</show_in_store>
36
- <comment>Default store view will export data went external website don't request view parameter</comment>
37
- </default_store_view>
38
- </fields>
39
- </store>
40
- </groups>
41
- </mageconnector>
42
- </sections>
43
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Massale_Facebook_Connector</name>
4
- <version>0.1.0</version>
5
  <stability>stable</stability>
6
- <license uri="http://www.opensource.org/licenses/osl-3.0.php">http://www.opensource.org/licenses/osl-3.0.php</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Massale_Facbook_Connector</summary>
10
- <description>Module to connect magento with Facebook.</description>
11
- <notes>Massale_FacbookConnector</notes>
12
- <authors><author><name>massale</name><user>auto-converted</user><email>sales@massale.com</email></author></authors>
13
- <date>2011-03-18</date>
14
- <time>03:04:27</time>
15
- <contents><target name="magelocal"><dir name="Magestore"><dir name="Mageconnector"><file name="Exception.php" hash="a26ebf68f3fa9b9674770653147c9404"/><dir name="controllers"><file name="IndexController.php" hash="6618290d9de2a807f53918418cb04da8"/></dir><dir name="etc"><file name="adminhtml.xml" hash="744adb7936a5a62726d9af2b20655554"/><file name="config.xml" hash="f5b69ad7195f6eb8e467d49b093baccb"/><file name="system.xml" hash="ba54c582b5105840e664598c7daec065"/></dir><dir name="Helper"><file name="Data.php" hash="ca3999ca04541005a2b7a4f52a01be43"/></dir><dir name="Model"><file name="Abstract.php" hash="74a75bafc0d7aae284af9efbae629d5f"/><file name="Cart.php" hash="8aa1031721fddab9aff262517815bce5"/><file name="Category.php" hash="1e5f56107e247ab5c05829dd6e7091ce"/><file name="Importstore.php" hash="b7421ba269bc92444f9d755930dc5b54"/><file name="Product.php" hash="43c23b53e5a4d39a8072502ee394e219"/></dir><dir name="sql"><dir name="mageconnector_setup"><file name="mysql4-install-0.1.0.php" hash="e5605e8c961291ba9633a78777eb3cb0"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Magestore_Mageconnector.xml" hash="0443a138f02d278a3f928ada60f57101"/></dir></target></contents>
16
  <compatible/>
17
- <dependencies/>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Massale_Facebook_Connector</name>
4
+ <version>1.0.0.7</version>
5
  <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>massale and magento connect</summary>
10
+ <description>massale and magento connect</description>
11
+ <notes>stable</notes>
12
+ <authors><author><name>Magestore</name><user>magestore</user><email>magento.subscription@magestore.com</email></author></authors>
13
+ <date>2011-09-01</date>
14
+ <time>09:27:41</time>
15
+ <contents><target name="magelocal"><dir name="Magestore"><dir name="Mageconnector"><file name="Exception.php" hash="ac09b60b831c92e6ecdb2518362c2f48"/><dir name="Helper"><file name="Data.php" hash="8331eb0345f6dc83eb378808829a49a1"/></dir><dir name="Model"><file name="Category.php" hash="689550984662feddc59d1ae480ec7b7f"/><file name="Information.php" hash="b133fcc4ca70edec41759f1f12a49f44"/><dir name="Override"><dir name="Mage"><dir name="Checkout"><file name="Cart.php" hash="d22856c26fca2e190333ab33a6d95dbd"/></dir></dir></dir><file name="Product.php" hash="64b522ddb8546ed5e859991434d5943c"/></dir><dir name="controllers"><file name="IndexController.php" hash="8a293165d50f83acc26e6a6d1b8609e0"/><dir name="Override"><dir name="Mage"><dir name="Checkout"><file name="CartController.php" hash="53962bb70fbec54fb3180d3141bda618"/></dir></dir></dir></dir><dir name="etc"><file name="config.xml" hash="bc02a2255b393a350be75977af36a600"/></dir><dir name="sql"><dir name="mageconnector_setup"><file name="mysql4-install-0.1.0.php" hash="e5605e8c961291ba9633a78777eb3cb0"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Magestore_Mageconnector.xml" hash="0443a138f02d278a3f928ada60f57101"/></dir></target></contents>
16
  <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>