Version Notes
Contus M-Comm, a ready to go solution to build native Magento mobile apps for your store across all devices.
Download this release
Release Info
Developer | contus |
Extension | Contus_Mcomm |
Version | 1.0.1 |
Comparing to | |
See all releases |
Code changes from version 1.0.0 to 1.0.1
- app/code/local/Contus/Configuration/Block/Adminhtml/About.php +1 -1
- app/code/local/Contus/Configuration/Model/Adminhtml/Cmspages.php +55 -0
- app/code/local/Contus/Configuration/Model/Config.php +23 -22
- app/code/local/Contus/Configuration/etc/config.xml +17 -0
- app/code/local/Contus/Configuration/etc/system.xml +80 -6
- app/code/local/Contus/Offers/Block/Adminhtml/Offers/Edit/Tab/Form.php +106 -98
- app/code/local/Contus/Offers/Block/Adminhtml/Offers/Grid.php +14 -0
- app/code/local/Contus/Offers/controllers/Adminhtml/OffersController.php +488 -479
- app/code/local/Contus/Offers/etc/config.xml +1 -1
- app/code/local/Contus/Offers/sql/offers_setup/mysql4-install-0.1.0.php +5 -3
- app/code/local/Contus/Pushnoteorders/controllers/Adminhtml/PushnoteordersController.php +7 -7
- app/code/local/Contus/Pushnoteproducts/controllers/Adminhtml/PushnoteproductsController.php +14 -10
- app/code/local/ContusRestapi/ApplyCoupon/Model/Api2/ApplyCouponapi.php +1 -1
- app/code/local/ContusRestapi/CartAddressapi/Model/Api2/CartAddressapi.php +308 -87
- app/code/local/ContusRestapi/CartAddressapi/etc/api2.xml +27 -20
- app/code/local/ContusRestapi/Cartapi/Model/Api2/Cartapi.php +1 -1
- app/code/local/ContusRestapi/Contactus/Model/Api2/Contactus.php +142 -0
- app/code/local/ContusRestapi/Contactus/Model/Api2/Contactus/Rest.php +30 -0
- app/code/local/ContusRestapi/Contactus/Model/Api2/Contactus/Rest/Admin/V1.php +30 -0
- app/code/local/ContusRestapi/Contactus/Model/Api2/Contactus/Rest/Customer/V1.php +30 -0
- app/code/local/ContusRestapi/Contactus/Model/Api2/Contactus/Rest/Guest/V1.php +30 -0
- app/code/local/ContusRestapi/Contactus/etc/api2.xml +60 -0
- app/code/local/ContusRestapi/Contactus/etc/config.xml +15 -0
- app/code/local/ContusRestapi/Filters/Model/Api2/Filters.php +277 -265
- app/code/local/ContusRestapi/HomePageapi/Model/Api2/HomePageapi.php +676 -576
- app/code/local/ContusRestapi/HomePageapi/etc/api2.xml +1 -0
- app/code/local/ContusRestapi/Login/Model/Methods/Functions.php +297 -115
- app/code/local/ContusRestapi/Login/Model/Token.php +743 -687
- app/code/local/ContusRestapi/Login/etc/config.xml +1 -1
- app/code/local/ContusRestapi/Login/sql/login_setup/install-0.0.1.php +2 -2
- app/code/local/ContusRestapi/MultiCartapi/Model/Api2/MultiCartapi.php +391 -370
- app/code/local/ContusRestapi/MultiCartapi/etc/api2.xml +1 -1
- app/code/local/ContusRestapi/MyOrders/Model/Api2/MyOrderapi.php +564 -377
- app/code/local/ContusRestapi/MyOrders/etc/api2.xml +7 -0
- app/code/local/ContusRestapi/PlaceOrder/Model/Api2/PlaceOrderapi.php +321 -287
- app/code/local/ContusRestapi/PlaceOrder/Model/Sales/Quote/Address/Total/Deliverycost.php +80 -0
- app/code/local/ContusRestapi/PlaceOrder/etc/api2.xml +8 -0
- app/code/local/ContusRestapi/PlaceOrder/etc/config.xml +11 -0
- app/code/local/ContusRestapi/ProductList/Model/Api2/ProductList/Rest.php +895 -721
- app/code/local/ContusRestapi/ProductList/etc/api2.xml +1 -0
- app/code/local/ContusRestapi/Products/Model/Api2/Products.php +325 -0
- app/code/local/ContusRestapi/Products/Model/Api2/Products/Rest.php +30 -0
- app/code/local/ContusRestapi/Products/Model/Api2/Products/Rest/Admin/V1.php +30 -0
- app/code/local/ContusRestapi/Products/Model/Api2/Products/Rest/Customer/V1.php +30 -0
- app/code/local/ContusRestapi/Products/Model/Api2/Products/Rest/Guest/V1.php +30 -0
- app/code/local/ContusRestapi/Products/etc/api2.xml +50 -0
- app/code/local/ContusRestapi/Products/etc/config.xml +15 -0
- app/code/local/ContusRestapi/ReviewRating/Model/Api2/ReviewRating.php +246 -186
- app/code/local/ContusRestapi/ReviewRating/etc/api2.xml +4 -0
- app/code/local/ContusRestapi/SearchProducts/Model/Api2/SearchProducts.php +302 -210
- app/code/local/ContusRestapi/SearchProducts/etc/api2.xml +9 -1
- app/code/local/ContusRestapi/Sellers/Model/Api2/Sellers.php +387 -0
- app/code/local/ContusRestapi/Sellers/Model/Api2/Sellers/Rest.php +30 -0
- app/code/local/ContusRestapi/Sellers/Model/Api2/Sellers/Rest/Admin/V1.php +30 -0
- app/code/local/ContusRestapi/Sellers/Model/Api2/Sellers/Rest/Customer/V1.php +30 -0
- app/code/local/ContusRestapi/Sellers/Model/Api2/Sellers/Rest/Guest/V1.php +30 -0
- app/code/local/ContusRestapi/Sellers/etc/api2.xml +72 -0
- app/code/local/ContusRestapi/Sellers/etc/config.xml +15 -0
- app/code/local/ContusRestapi/SocialLogin/Model/Api2/SocialLogin.php +2 -2
- app/code/local/ContusRestapi/SocialLogin/etc/api2.xml +3 -0
- app/code/local/ContusRestapi/SplashPage/Model/Api2/SplashPage.php +77 -0
- app/code/local/ContusRestapi/SplashPage/Model/Api2/SplashPage/Rest.php +30 -0
- app/code/local/ContusRestapi/SplashPage/Model/Api2/SplashPage/Rest/Admin/V1.php +30 -0
- app/code/local/ContusRestapi/SplashPage/Model/Api2/SplashPage/Rest/Customer/V1.php +30 -0
- app/code/local/ContusRestapi/SplashPage/Model/Api2/SplashPage/Rest/Guest/V1.php +30 -0
- app/code/local/ContusRestapi/SplashPage/etc/api2.xml +50 -0
- app/code/local/ContusRestapi/SplashPage/etc/config.xml +15 -0
- app/design/adminhtml/default/default/layout/offers.xml +6 -0
- app/design/adminhtml/default/default/layout/pushnoteproducts.xml +12 -6
- app/design/adminhtml/default/default/template/pushnoteproducts/pushnoteproducts.phtml +38 -1
- app/etc/modules/ContusRestapi_Contactus.xml +9 -0
- app/etc/modules/ContusRestapi_Sellers.xml +9 -0
- app/etc/modules/ContusRestapi_Splashpage.xml +9 -0
- package.xml +5 -5
- paypal/ipn.log +0 -0
- paypal/ipn.php +2 -2
- paypal/redirect.php +6 -5
- paypal/success.php +157 -3
- rest/api.php +1911 -1592
app/code/local/Contus/Configuration/Block/Adminhtml/About.php
CHANGED
@@ -48,7 +48,7 @@ class Contus_Configuration_Block_Adminhtml_About extends Mage_Adminhtml_Block_Ab
|
|
48 |
<table cellspacing="0" cellpading="0" class="developer">
|
49 |
<tr>
|
50 |
<td class="developer-label "><img src="' . $logoLink . '" width="180px" > </td>
|
51 |
-
<td class="developer-text ">' . $helper->__ ( '<strong>version 2.
|
52 |
</tr>
|
53 |
<tr>
|
54 |
<td class="developer-label line">' . $helper->__ ( 'Extension:' ) . '</td>
|
48 |
<table cellspacing="0" cellpading="0" class="developer">
|
49 |
<tr>
|
50 |
<td class="developer-label "><img src="' . $logoLink . '" width="180px" > </td>
|
51 |
+
<td class="developer-text ">' . $helper->__ ( '<strong>version 2.2</strong> ' ) . '</td>
|
52 |
</tr>
|
53 |
<tr>
|
54 |
<td class="developer-label line">' . $helper->__ ( 'Extension:' ) . '</td>
|
app/code/local/Contus/Configuration/Model/Adminhtml/Cmspages.php
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
<?php
|
3 |
+
/**
|
4 |
+
* Contus
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the EULA
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://www.apptha.com/LICENSE.txt
|
12 |
+
*
|
13 |
+
* ==============================================================
|
14 |
+
* MAGENTO EDITION USAGE NOTICE
|
15 |
+
* ==============================================================
|
16 |
+
* This package designed for Magento COMMUNITY edition
|
17 |
+
* Apptha does not guarantee correct work of this extension
|
18 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
19 |
+
* Apptha does not provide extension support in case of
|
20 |
+
* incorrect edition usage.
|
21 |
+
* ==============================================================
|
22 |
+
*
|
23 |
+
* @category Contus
|
24 |
+
* @package Contus_Configuration
|
25 |
+
* @author Contus Team <developers@contus.in>
|
26 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
27 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
28 |
+
* @since 1.0
|
29 |
+
*/
|
30 |
+
class Contus_Configuration_Model_Adminhtml_Cmspages {
|
31 |
+
public function toOptionArray() {
|
32 |
+
if (is_null ( $this->_options )) {
|
33 |
+
$this->_options = array ();
|
34 |
+
$collection = Mage::getModel ( 'cms/page' )->getCollection ();
|
35 |
+
$this->_options [] = array (
|
36 |
+
'label' => "Select Page",
|
37 |
+
value => ""
|
38 |
+
);
|
39 |
+
foreach ( $collection as $block ) {
|
40 |
+
$this->_options [] = array (
|
41 |
+
'label' => $block->getTitle (),
|
42 |
+
value => $block->getIdentifier ()
|
43 |
+
);
|
44 |
+
}
|
45 |
+
}
|
46 |
+
$options = $this->_options;
|
47 |
+
if ($withEmpty) {
|
48 |
+
array_unshift ( $options, array (
|
49 |
+
'value' => '',
|
50 |
+
'label' => ''
|
51 |
+
) );
|
52 |
+
}
|
53 |
+
return $options;
|
54 |
+
}
|
55 |
+
}
|
app/code/local/Contus/Configuration/Model/Config.php
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
<?php
|
3 |
/**
|
4 |
* Contus
|
@@ -28,25 +27,27 @@
|
|
28 |
* @since 1.0
|
29 |
*/
|
30 |
class Contus_Configuration_Model_Config {
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
52 |
}
|
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Contus
|
27 |
* @since 1.0
|
28 |
*/
|
29 |
class Contus_Configuration_Model_Config {
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Change push notification mode
|
33 |
+
* true - live mode
|
34 |
+
* false - development mode
|
35 |
+
*
|
36 |
+
* @return boolean
|
37 |
+
*/
|
38 |
+
public function getNotificationMode() {
|
39 |
+
$response = array ();
|
40 |
+
$notificationMode = true;
|
41 |
+
|
42 |
+
if ($notificationMode) {
|
43 |
+
$pemfile = getcwd () . '/contus/Mcom_production.pem';
|
44 |
+
} else {
|
45 |
+
$pemfile = getcwd () . '/contus/Mcom_development.pem';
|
46 |
+
}
|
47 |
+
$response ['mode'] = $notificationMode;
|
48 |
+
$response ['pemfile'] = $pemfile;
|
49 |
+
return $response;
|
50 |
+
}
|
51 |
+
|
52 |
+
|
53 |
}
|
app/code/local/Contus/Configuration/etc/config.xml
CHANGED
@@ -5,6 +5,23 @@
|
|
5 |
<version>0.1.0</version>
|
6 |
</Contus_Configuration>
|
7 |
</modules>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
<global>
|
9 |
<models>
|
10 |
<configuration>
|
5 |
<version>0.1.0</version>
|
6 |
</Contus_Configuration>
|
7 |
</modules>
|
8 |
+
|
9 |
+
<stores>
|
10 |
+
<admin>
|
11 |
+
<!-- override default admin design package and theme -->
|
12 |
+
<design>
|
13 |
+
<package>
|
14 |
+
<name>default</name>
|
15 |
+
</package>
|
16 |
+
<theme>
|
17 |
+
<!-- this is the theme name -->
|
18 |
+
<default>mcomm</default>
|
19 |
+
</theme>
|
20 |
+
</design>
|
21 |
+
</admin>
|
22 |
+
</stores>
|
23 |
+
|
24 |
+
|
25 |
<global>
|
26 |
<models>
|
27 |
<configuration>
|
app/code/local/Contus/Configuration/etc/system.xml
CHANGED
@@ -40,7 +40,7 @@
|
|
40 |
<mcomapp_about translate="label">
|
41 |
<label>MCOMM App</label>
|
42 |
<frontend_type>text</frontend_type>
|
43 |
-
<sort_order>
|
44 |
<show_in_default>1</show_in_default>
|
45 |
<show_in_website>1</show_in_website>
|
46 |
<show_in_store>1</show_in_store>
|
@@ -77,7 +77,7 @@
|
|
77 |
translate="label">
|
78 |
<label>Push Notifications</label>
|
79 |
<frontend_type>text</frontend_type>
|
80 |
-
<sort_order>
|
81 |
<show_in_default>1</show_in_default>
|
82 |
<show_in_website>1</show_in_website>
|
83 |
<show_in_store>1</show_in_store>
|
@@ -124,14 +124,14 @@
|
|
124 |
<expanded>1</expanded>
|
125 |
</configuration_pushnotifications>
|
126 |
|
127 |
-
<configuration_home translate="label" module="configuration">
|
128 |
<label>Home Page Banner</label>
|
129 |
<frontend_type>text</frontend_type>
|
130 |
-
<sort_order>
|
131 |
<show_in_default>1</show_in_default>
|
132 |
<show_in_website>1</show_in_website>
|
133 |
<show_in_store>1</show_in_store>
|
134 |
-
|
135 |
<fields>
|
136 |
<home_banner translate="label">
|
137 |
<label>Home Banner</label>
|
@@ -160,7 +160,81 @@
|
|
160 |
<show_in_store>1</show_in_store>
|
161 |
</banner_count>
|
162 |
</fields>
|
163 |
-
</configuration_home>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
</groups>
|
165 |
</contus>
|
166 |
</sections>
|
40 |
<mcomapp_about translate="label">
|
41 |
<label>MCOMM App</label>
|
42 |
<frontend_type>text</frontend_type>
|
43 |
+
<sort_order>2</sort_order>
|
44 |
<show_in_default>1</show_in_default>
|
45 |
<show_in_website>1</show_in_website>
|
46 |
<show_in_store>1</show_in_store>
|
77 |
translate="label">
|
78 |
<label>Push Notifications</label>
|
79 |
<frontend_type>text</frontend_type>
|
80 |
+
<sort_order>3</sort_order>
|
81 |
<show_in_default>1</show_in_default>
|
82 |
<show_in_website>1</show_in_website>
|
83 |
<show_in_store>1</show_in_store>
|
124 |
<expanded>1</expanded>
|
125 |
</configuration_pushnotifications>
|
126 |
|
127 |
+
<!-- <configuration_home translate="label" module="configuration">
|
128 |
<label>Home Page Banner</label>
|
129 |
<frontend_type>text</frontend_type>
|
130 |
+
<sort_order>4</sort_order>
|
131 |
<show_in_default>1</show_in_default>
|
132 |
<show_in_website>1</show_in_website>
|
133 |
<show_in_store>1</show_in_store>
|
134 |
+
<expanded>1</expanded>
|
135 |
<fields>
|
136 |
<home_banner translate="label">
|
137 |
<label>Home Banner</label>
|
160 |
<show_in_store>1</show_in_store>
|
161 |
</banner_count>
|
162 |
</fields>
|
163 |
+
</configuration_home> -->
|
164 |
+
|
165 |
+
|
166 |
+
<configuration_cms translate="label" module="configuration">
|
167 |
+
<label>CMS Pages</label>
|
168 |
+
<frontend_type>text</frontend_type>
|
169 |
+
<sort_order>5</sort_order>
|
170 |
+
<show_in_default>1</show_in_default>
|
171 |
+
<show_in_website>1</show_in_website>
|
172 |
+
<show_in_store>1</show_in_store>
|
173 |
+
<expanded>1</expanded>
|
174 |
+
<fields>
|
175 |
+
|
176 |
+
<cms_pages_enabled translate="label">
|
177 |
+
<label>CMS Pages </label>
|
178 |
+
<frontend_type>select</frontend_type>
|
179 |
+
<source_model>adminhtml/system_config_source_enabledisable
|
180 |
+
</source_model>
|
181 |
+
<sort_order>0</sort_order>
|
182 |
+
<show_in_default>1</show_in_default>
|
183 |
+
<show_in_website>1</show_in_website>
|
184 |
+
<show_in_store>1</show_in_store>
|
185 |
+
</cms_pages_enabled>
|
186 |
+
<about_us translate="label">
|
187 |
+
<label>About Us Page</label>
|
188 |
+
<frontend_type>select</frontend_type>
|
189 |
+
<source_model>configuration/adminhtml_cmspages</source_model>
|
190 |
+
|
191 |
+
<sort_order>1</sort_order>
|
192 |
+
<show_in_default>1</show_in_default>
|
193 |
+
<show_in_website>1</show_in_website>
|
194 |
+
<show_in_store>1</show_in_store>
|
195 |
+
</about_us>
|
196 |
+
<contact_us translate="label">
|
197 |
+
<label>Contact Us Page</label>
|
198 |
+
<frontend_type>select</frontend_type>
|
199 |
+
<source_model>configuration/adminhtml_cmspages</source_model>
|
200 |
+
|
201 |
+
<sort_order>2</sort_order>
|
202 |
+
<show_in_default>1</show_in_default>
|
203 |
+
<show_in_website>1</show_in_website>
|
204 |
+
<show_in_store>1</show_in_store>
|
205 |
+
</contact_us>
|
206 |
+
<terms_condition translate="label">
|
207 |
+
<label>Term Condition Page</label>
|
208 |
+
<frontend_type>select</frontend_type>
|
209 |
+
<source_model>configuration/adminhtml_cmspages</source_model>
|
210 |
+
|
211 |
+
<sort_order>3</sort_order>
|
212 |
+
<show_in_default>1</show_in_default>
|
213 |
+
<show_in_website>1</show_in_website>
|
214 |
+
<show_in_store>1</show_in_store>
|
215 |
+
</terms_condition>
|
216 |
+
<privacy_policy translate="label">
|
217 |
+
<label>Privacy Policy Page</label>
|
218 |
+
<frontend_type>select</frontend_type>
|
219 |
+
<source_model>configuration/adminhtml_cmspages</source_model>
|
220 |
+
|
221 |
+
<sort_order>4</sort_order>
|
222 |
+
<show_in_default>1</show_in_default>
|
223 |
+
<show_in_website>1</show_in_website>
|
224 |
+
<show_in_store>1</show_in_store>
|
225 |
+
</privacy_policy>
|
226 |
+
<customer_service translate="label">
|
227 |
+
<label>Customer Service Page</label>
|
228 |
+
<frontend_type>select</frontend_type>
|
229 |
+
<source_model>configuration/adminhtml_cmspages</source_model>
|
230 |
+
|
231 |
+
<sort_order>5</sort_order>
|
232 |
+
<show_in_default>1</show_in_default>
|
233 |
+
<show_in_website>1</show_in_website>
|
234 |
+
<show_in_store>1</show_in_store>
|
235 |
+
</customer_service>
|
236 |
+
</fields>
|
237 |
+
</configuration_cms>
|
238 |
</groups>
|
239 |
</contus>
|
240 |
</sections>
|
app/code/local/Contus/Offers/Block/Adminhtml/Offers/Edit/Tab/Form.php
CHANGED
@@ -27,102 +27,110 @@
|
|
27 |
* @since 1.0
|
28 |
*/
|
29 |
class Contus_Offers_Block_Adminhtml_Offers_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form {
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
}
|
27 |
* @since 1.0
|
28 |
*/
|
29 |
class Contus_Offers_Block_Adminhtml_Offers_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form {
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Defines Form field to be edited
|
33 |
+
*
|
34 |
+
* @return object Form field to be edited
|
35 |
+
*/
|
36 |
+
protected function _prepareForm() {
|
37 |
+
$form = new Varien_Data_Form ();
|
38 |
+
$this->setForm ( $form );
|
39 |
+
$fieldset = $form->addFieldset ( 'offers_form', array (
|
40 |
+
'legend' => Mage::helper ( 'offers' )->__ ( 'Offer information' )
|
41 |
+
) );
|
42 |
+
|
43 |
+
$fieldset->addField ( 'offer_title', 'text', array (
|
44 |
+
'label' => Mage::helper ( 'offers' )->__ ( 'Offer Title' ),
|
45 |
+
'class' => 'required-entry',
|
46 |
+
'required' => true,
|
47 |
+
'name' => 'offer_title'
|
48 |
+
) );
|
49 |
+
|
50 |
+
// display Promotion image if already exit
|
51 |
+
$data = Mage::registry ( 'offers_data' );
|
52 |
+
|
53 |
+
if ($data->getData ( 'offer_img' ) != '') {
|
54 |
+
$html = '';
|
55 |
+
$url = Mage::getBaseUrl ( 'media' );
|
56 |
+
$html = '<img ';
|
57 |
+
$html .= 'src="' . $url . $data->getData ( 'offer_img' ) . '"' . 'width = "60px" />';
|
58 |
+
Mage::registry ( 'offers_data' )->setData ( 'offer_img_view', $data->getData ( 'offer_img' ) );
|
59 |
+
|
60 |
+
$fieldset->addField ( 'offer_img_view', 'text', array (
|
61 |
+
'label' => '',
|
62 |
+
'required' => false,
|
63 |
+
'style' => "display:none",
|
64 |
+
'name' => "offer_img_view",
|
65 |
+
'after_element_html' => $html
|
66 |
+
) );
|
67 |
+
|
68 |
+
$fieldset->addField ( 'offer_img', 'file', array (
|
69 |
+
'label' => Mage::helper ( 'offers' )->__ ( 'Promotion Image' ),
|
70 |
+
'required' => false,
|
71 |
+
'name' => 'offer_img',
|
72 |
+
'after_element_html' => '<small style="display:block">Upload image size (1200 X 900 pixels)<small>'
|
73 |
+
) );
|
74 |
+
} else {
|
75 |
+
$fieldset->addField ( 'offer_img', 'file', array (
|
76 |
+
'label' => Mage::helper ( 'offers' )->__ ( 'Promotion Image ' ),
|
77 |
+
'required' => true,
|
78 |
+
'name' => 'offer_img',
|
79 |
+
'class' => 'required-entry required-file',
|
80 |
+
'after_element_html' => '<small style="display:block">Upload image size (1200 X 900 pixels)<small>'
|
81 |
+
) );
|
82 |
+
}
|
83 |
+
|
84 |
+
$fieldset->addField ( 'store_id', 'multiselect', array (
|
85 |
+
'name' => 'stores[]',
|
86 |
+
'label' => Mage::helper ( 'offers' )->__ ( 'Store View' ),
|
87 |
+
'title' => Mage::helper ( 'offers' )->__ ( 'Store View' ),
|
88 |
+
'required' => true,
|
89 |
+
'values' => Mage::getSingleton ( 'adminhtml/system_store' )->getStoreValuesForForm ( false, true )
|
90 |
+
) );
|
91 |
+
|
92 |
+
$fieldset->addField ( 'from_date', 'date', array (
|
93 |
+
'name' => 'from_date',
|
94 |
+
'label' => Mage::helper ( 'offers' )->__ ( 'From Date' ),
|
95 |
+
'style' => 'width:200px;',
|
96 |
+
'image' => $this->getSkinUrl ( 'images/grid-cal.gif' ),
|
97 |
+
'format' => Mage::app ()->getLocale ()->getDateFormat ( Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM ),
|
98 |
+
'required' => false,
|
99 |
+
'class' => ' validate-date validate-date-range date-range-to_date-from'
|
100 |
+
) );
|
101 |
+
|
102 |
+
$fieldset->addField ( 'to_date', 'date', array (
|
103 |
+
'name' => 'to_date',
|
104 |
+
'label' => Mage::helper ( 'offers' )->__ ( 'To Date' ),
|
105 |
+
'style' => 'width:200px;',
|
106 |
+
'image' => $this->getSkinUrl ( 'images/grid-cal.gif' ),
|
107 |
+
'format' => Mage::app ()->getLocale ()->getDateFormat ( Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM ),
|
108 |
+
'required' => false,
|
109 |
+
'class' => 'validate-date validate-date-range date-range-to_date-to'
|
110 |
+
) );
|
111 |
+
|
112 |
+
$fieldset->addField ( 'status', 'select', array (
|
113 |
+
'label' => Mage::helper ( 'offers' )->__ ( 'Status' ),
|
114 |
+
'name' => 'status',
|
115 |
+
'values' => array (
|
116 |
+
array (
|
117 |
+
'value' => 1,
|
118 |
+
'label' => Mage::helper ( 'offers' )->__ ( 'Enabled' )
|
119 |
+
),
|
120 |
+
|
121 |
+
array (
|
122 |
+
'value' => 2,
|
123 |
+
'label' => Mage::helper ( 'offers' )->__ ( 'Disabled' )
|
124 |
+
)
|
125 |
+
)
|
126 |
+
) );
|
127 |
+
|
128 |
+
if (Mage::getSingleton ( 'adminhtml/session' )->getOffersData ()) {
|
129 |
+
$form->setValues ( Mage::getSingleton ( 'adminhtml/session' )->getOffersData () );
|
130 |
+
Mage::getSingleton ( 'adminhtml/session' )->setOffersData ( null );
|
131 |
+
} elseif (Mage::registry ( 'offers_data' )) {
|
132 |
+
$form->setValues ( Mage::registry ( 'offers_data' )->getData () );
|
133 |
+
}
|
134 |
+
return parent::_prepareForm ();
|
135 |
+
}
|
136 |
}
|
app/code/local/Contus/Offers/Block/Adminhtml/Offers/Grid.php
CHANGED
@@ -46,6 +46,20 @@ class Contus_Offers_Block_Adminhtml_Offers_Grid extends Mage_Adminhtml_Block_Wid
|
|
46 |
*/
|
47 |
protected function _prepareCollection() {
|
48 |
$collection = Mage::getModel ( 'offers/offers' )->getCollection ();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
$this->setCollection ( $collection );
|
50 |
return parent::_prepareCollection ();
|
51 |
}
|
46 |
*/
|
47 |
protected function _prepareCollection() {
|
48 |
$collection = Mage::getModel ( 'offers/offers' )->getCollection ();
|
49 |
+
|
50 |
+
$storeId = ( int ) Mage::app ()->getRequest ()->getParam ( 'store' );
|
51 |
+
|
52 |
+
|
53 |
+
if ($storeId) {
|
54 |
+
$collection->addFieldToFilter ( 'store_id', array (
|
55 |
+
array (
|
56 |
+
'regexp' => $storeId
|
57 |
+
),
|
58 |
+
array (
|
59 |
+
'eq' => '0'
|
60 |
+
)
|
61 |
+
) );
|
62 |
+
}
|
63 |
$this->setCollection ( $collection );
|
64 |
return parent::_prepareCollection ();
|
65 |
}
|
app/code/local/Contus/Offers/controllers/Adminhtml/OffersController.php
CHANGED
@@ -27,499 +27,508 @@
|
|
27 |
* @since 1.0
|
28 |
*/
|
29 |
class Contus_Offers_Adminhtml_OffersController extends Mage_Adminhtml_Controller_action {
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
return $this;
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Initialize the layout
|
44 |
-
* $cnt
|
45 |
-
*
|
46 |
-
* @return mixed Loads current page layouts
|
47 |
-
*/
|
48 |
-
public function indexAction() {
|
49 |
-
$this->_initAction ()->_title ( $this->__ ( 'Offers' ) )->renderLayout ();
|
50 |
-
}
|
51 |
-
|
52 |
-
/**
|
53 |
-
* Check total count of offers
|
54 |
-
* Restrict only 5 offers to add
|
55 |
-
*/
|
56 |
-
public function checkCountAction() {
|
57 |
-
$collection = Mage::getModel ( 'offers/offers' )->getCollection ();
|
58 |
-
|
59 |
-
$size = $collection->getSize ();
|
60 |
-
$cnt = count ( $collection );
|
61 |
-
if ($cnt >= 5) {
|
62 |
-
Mage::getSingleton ( 'core/session' )->addError ( "Can't add more than 5 offers. " );
|
63 |
-
$this->_redirectReferer ();
|
64 |
-
} else {
|
65 |
-
$key = Mage::getSingleton ( 'adminhtml/url' )->getSecretKey ( "adminhtml_offers", "new" );
|
66 |
-
|
67 |
-
$this->_redirect ( '*/*/new', array (
|
68 |
-
'key' => $key
|
69 |
-
) );
|
70 |
-
}
|
71 |
-
}
|
72 |
-
|
73 |
-
/**
|
74 |
-
* Get Message and product id to push message from web to app
|
75 |
-
*/
|
76 |
-
public function getPushMsgParamsAction() {
|
77 |
-
$isEnabled = true;
|
78 |
-
|
79 |
-
$params = $this->getRequest ()->getPost ();
|
80 |
-
$message = $params ['offer_desc'];
|
81 |
-
$id = $params ['offer_id'];
|
82 |
-
|
83 |
-
if ($isEnabled) {
|
84 |
-
$this->notification ( $message, $id );
|
85 |
-
} else {
|
86 |
-
Mage::getSingleton ( 'core/session' )->addError ( 'Please enable push notification option for offers.' );
|
87 |
-
$this->_redirectReferer ();
|
88 |
-
}
|
89 |
-
}
|
90 |
-
|
91 |
-
/**
|
92 |
-
* Nofication
|
93 |
-
*
|
94 |
-
* @param string $message
|
95 |
-
* message which was given by admin to display in app
|
96 |
-
*
|
97 |
-
* @param int $id
|
98 |
-
*/
|
99 |
-
public function notification($message, $id) {
|
100 |
-
|
101 |
-
// Information to send in the push notification
|
102 |
-
$msg ['msg'] = $message;
|
103 |
-
$msg ['id'] = $id;
|
104 |
-
$msg ['type'] = 'list';
|
105 |
-
|
106 |
-
// MCOM demo googel api key
|
107 |
-
$gcmKey = Mage::getStoreConfig ( 'contus/configuration_pushnotifications/gcm_apikey' );
|
108 |
-
$result['mode'] = false;
|
109 |
-
$result = Mage::getModel ( 'configuration/config' )->getNotificationMode();
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
}
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
}
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
$this->loadLayout ();
|
270 |
-
$this->_setActiveMenu ( 'offers/items' );
|
271 |
-
|
272 |
-
$this->_addBreadcrumb ( Mage::helper ( 'adminhtml' )->__ ( 'Item Manager' ), Mage::helper ( 'adminhtml' )->__ ( 'Item Manager' ) );
|
273 |
-
$this->_addBreadcrumb ( Mage::helper ( 'adminhtml' )->__ ( 'Item News' ), Mage::helper ( 'adminhtml' )->__ ( 'Item News' ) );
|
274 |
-
|
275 |
-
$this->getLayout ()->getBlock ( 'head' )->setCanLoadExtJs ( true );
|
276 |
-
|
277 |
-
$this->_addContent ( $this->getLayout ()->createBlock ( 'offers/adminhtml_offers_edit' ) )->_addLeft ( $this->getLayout ()->createBlock ( 'offers/adminhtml_offers_edit_tabs' ) );
|
278 |
-
|
279 |
-
$this->renderLayout ();
|
280 |
-
} else {
|
281 |
-
Mage::getSingleton ( 'adminhtml/session' )->addError ( Mage::helper ( 'offers' )->__ ( 'Item does not exist' ) );
|
282 |
-
$this->_redirect ( '*/*/' );
|
283 |
-
}
|
284 |
-
}
|
285 |
-
|
286 |
-
/**
|
287 |
-
* Redirects page to edit action
|
288 |
-
*
|
289 |
-
* @return void Redirects to edit action
|
290 |
-
*/
|
291 |
-
public function newAction() {
|
292 |
-
$this->_forward ( 'edit' );
|
293 |
-
}
|
294 |
-
|
295 |
-
/**
|
296 |
-
* Save action for current records
|
297 |
-
*
|
298 |
-
* @return boolean True if data saved successfull else redirects page to edit action
|
299 |
-
*/
|
300 |
-
public function saveAction() {
|
301 |
-
if ($data = $this->getRequest ()->getPost ()) {
|
302 |
-
|
303 |
-
// convert offer_products array to string
|
304 |
-
if (! is_array ( $data ['offer_products'] )) {
|
305 |
-
$err_offer_product = 1;
|
306 |
-
} else if (is_array ( $data ['offer_products'] )) {
|
307 |
-
$err_offer_product = '';
|
308 |
-
$data ['offer_products'] = implode ( ',', $data ['offer_products'] );
|
309 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
310 |
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
) )
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
$err_array = array ();
|
320 |
-
|
321 |
-
if (isset ( $_FILES ['offer_img'] ['name'] ) && $_FILES ['offer_img'] ['name'] != '') {
|
322 |
-
try {
|
323 |
-
|
324 |
-
/* Starting upload */
|
325 |
-
$uploader = new Varien_File_Uploader ( 'offer_img' );
|
326 |
-
|
327 |
-
// for creating the directory if not exists
|
328 |
-
$uploader->setAllowCreateFolders ( true );
|
329 |
-
// Alloweed extention would work
|
330 |
-
$uploader->setAllowedExtensions ( array (
|
331 |
-
'jpg',
|
332 |
-
'jpeg',
|
333 |
-
'gif',
|
334 |
-
'png'
|
335 |
-
) );
|
336 |
-
$uploader->setAllowRenameFiles ( false );
|
337 |
-
$uploader->setFilesDispersion ( false );
|
338 |
-
|
339 |
-
// We set media as the upload dir
|
340 |
-
$path = Mage::getBaseDir ( 'media' ) . DS . 'offers' . DS;
|
341 |
-
if ($uploader->save ( $path, $_FILES ['offer_img'] ['name'] )) {
|
342 |
-
|
343 |
-
// this way the name is saved in DB
|
344 |
-
$data ['offer_img'] = 'offers/' . $_FILES ['offer_img'] ['name'];
|
345 |
-
}
|
346 |
-
} catch ( Exception $e ) {
|
347 |
-
$err_img = 1;
|
348 |
-
$err_array [] = $e->getMessage ();
|
349 |
-
}
|
350 |
} else {
|
351 |
-
|
352 |
-
|
353 |
-
|
|
|
|
|
|
|
|
|
354 |
}
|
355 |
|
356 |
-
|
357 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
|
359 |
-
|
|
|
|
|
360 |
|
361 |
-
if (
|
362 |
-
|
|
|
|
|
|
|
363 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
364 |
|
365 |
-
|
366 |
-
|
367 |
-
foreach ( $err_array as $msg ) {
|
368 |
-
Mage::getSingleton ( 'adminhtml/session' )->addError ( Mage::helper ( 'offers' )->__ ( $msg ) );
|
369 |
-
}
|
370 |
-
$offerId = $this->getRequest ()->getParam ( 'id' );
|
371 |
-
if (isset ( $offerId ) && $this->getRequest ()->getParam ( 'id' ) != '') {
|
372 |
-
$this->_redirect ( '*/*/edit', array (
|
373 |
-
'id' => $model->getId ()
|
374 |
-
) );
|
375 |
-
} else {
|
376 |
-
|
377 |
-
Mage::getSingleton ( 'adminhtml/session' )->setFormData ( $data );
|
378 |
-
$key = Mage::getSingleton ( 'adminhtml/url' )->getSecretKey ( "adminhtml_offers", "new" );
|
379 |
-
|
380 |
-
$this->_redirect ( '*/*/new', array (
|
381 |
-
'key' => $key
|
382 |
-
) );
|
383 |
-
}
|
384 |
-
|
385 |
-
return;
|
386 |
-
}
|
387 |
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
}
|
415 |
-
}
|
416 |
-
Mage::getSingleton ( 'adminhtml/session' )->addError ( Mage::helper ( 'offers' )->__ ( 'Unable to find item to save.' ) );
|
417 |
-
$this->_redirect ( '*/*/' );
|
418 |
-
}
|
419 |
-
|
420 |
-
/**
|
421 |
-
* Delete the current id
|
422 |
-
*
|
423 |
-
* @return void Redirects to grid page
|
424 |
-
*/
|
425 |
-
public function deleteAction() {
|
426 |
-
if ($this->getRequest ()->getParam ( 'id' ) > 0) {
|
427 |
-
try {
|
428 |
-
$model = Mage::getModel ( 'offers/offers' );
|
429 |
-
|
430 |
-
$model->setId ( $this->getRequest ()->getParam ( 'id' ) )->delete ();
|
431 |
-
|
432 |
-
Mage::getSingleton ( 'adminhtml/session' )->addSuccess ( Mage::helper ( 'adminhtml' )->__ ( 'Item was successfully deleted.' ) );
|
433 |
-
$this->_redirect ( '*/*/' );
|
434 |
-
} catch ( Exception $e ) {
|
435 |
-
Mage::getSingleton ( 'adminhtml/session' )->addError ( $e->getMessage () );
|
436 |
-
$this->_redirect ( '*/*/edit', array (
|
437 |
-
'id' => $this->getRequest ()->getParam ( 'id' )
|
438 |
-
) );
|
439 |
-
}
|
440 |
-
}
|
441 |
-
$this->_redirect ( '*/*/' );
|
442 |
-
}
|
443 |
-
|
444 |
-
/**
|
445 |
-
* Deletes selected records from database
|
446 |
-
*
|
447 |
-
* @return void Redirect to grid page
|
448 |
-
*/
|
449 |
-
public function massDeleteAction() {
|
450 |
-
$offersIds = $this->getRequest ()->getParam ( 'offers' );
|
451 |
-
if (! is_array ( $offersIds )) {
|
452 |
-
Mage::getSingleton ( 'adminhtml/session' )->addError ( Mage::helper ( 'adminhtml' )->__ ( 'Please select item(s).' ) );
|
453 |
-
} else {
|
454 |
-
try {
|
455 |
-
foreach ( $offersIds as $offersId ) {
|
456 |
-
$offers = Mage::getModel ( 'offers/offers' )->load ( $offersId );
|
457 |
-
$offers->delete ();
|
458 |
-
}
|
459 |
-
Mage::getSingleton ( 'adminhtml/session' )->addSuccess ( Mage::helper ( 'adminhtml' )->__ ( 'Total of %d record(s) were successfully deleted', count ( $offersIds ) ) );
|
460 |
-
} catch ( Exception $e ) {
|
461 |
-
Mage::getSingleton ( 'adminhtml/session' )->addError ( $e->getMessage () );
|
462 |
}
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
}
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
|
|
|
|
|
|
|
|
525 |
}
|
27 |
* @since 1.0
|
28 |
*/
|
29 |
class Contus_Offers_Adminhtml_OffersController extends Mage_Adminhtml_Controller_action {
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Initialize the current item tab with label
|
33 |
+
*
|
34 |
+
* @return mixed Current page breadcrumb object
|
35 |
+
*/
|
36 |
+
protected function _initAction() {
|
37 |
+
$this->loadLayout ()->_setActiveMenu ( 'pushnoteproducts/items' )->_addBreadcrumb ( Mage::helper ( 'adminhtml' )->__ ( 'Items Manager' ), Mage::helper ( 'adminhtml' )->__ ( 'Item Manager' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
return $this;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Initialize the layout
|
44 |
+
* $cnt
|
45 |
+
*
|
46 |
+
* @return mixed Loads current page layouts
|
47 |
+
*/
|
48 |
+
public function indexAction() {
|
49 |
+
$this->_initAction ()->_title ( $this->__ ( 'Offers' ) )->renderLayout ();
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Check total count of offers
|
54 |
+
* Restrict only 5 offers to add
|
55 |
+
*/
|
56 |
+
public function checkCountAction() {
|
57 |
+
$collection = Mage::getModel ( 'offers/offers' )->getCollection ();
|
58 |
+
|
59 |
+
$size = $collection->getSize ();
|
60 |
+
$cnt = count ( $collection );
|
61 |
+
if ($cnt >= 5) {
|
62 |
+
Mage::getSingleton ( 'core/session' )->addError ( "Can't add more than 5 offers. " );
|
63 |
+
$this->_redirectReferer ();
|
64 |
+
} else {
|
65 |
+
$key = Mage::getSingleton ( 'adminhtml/url' )->getSecretKey ( "adminhtml_offers", "new" );
|
66 |
+
|
67 |
+
$this->_redirect ( '*/*/new', array (
|
68 |
+
'key' => $key
|
69 |
+
) );
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Get Message and product id to push message from web to app
|
75 |
+
*/
|
76 |
+
public function getPushMsgParamsAction() {
|
77 |
+
$isEnabled = true;
|
78 |
+
|
79 |
+
$params = $this->getRequest ()->getPost ();
|
80 |
+
$message = $params ['offer_desc'];
|
81 |
+
$id = $params ['offer_id'];
|
82 |
+
|
83 |
+
if ($isEnabled) {
|
84 |
+
$this->notification ( $message, $id );
|
85 |
+
} else {
|
86 |
+
Mage::getSingleton ( 'core/session' )->addError ( 'Please enable push notification option for offers.' );
|
87 |
+
$this->_redirectReferer ();
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Nofication
|
93 |
+
*
|
94 |
+
* @param string $message
|
95 |
+
* message which was given by admin to display in app
|
96 |
+
*
|
97 |
+
* @param int $id
|
98 |
+
*/
|
99 |
+
public function notification($message, $id) {
|
100 |
+
|
101 |
+
// Information to send in the push notification
|
102 |
+
$msg ['msg'] = $message;
|
103 |
+
$msg ['id'] = $id;
|
104 |
+
$msg ['type'] = 'list';
|
105 |
+
|
106 |
+
// MCOM demo googel api key
|
107 |
+
$gcmKey = Mage::getStoreConfig ( 'contus/configuration_pushnotifications/gcm_apikey' );
|
108 |
+
$result ['mode'] = false;
|
109 |
+
$result = Mage::getModel ( 'configuration/config' )->getNotificationMode ();
|
110 |
+
|
111 |
+
// Send Push Notification to Android and ios
|
112 |
+
$this->sendNotificationAndroid ( $gcmKey, $msg );
|
113 |
+
$this->sendNotificationiOS ( $result ['pemfile'], $gcmKey, $result ['mode'], $msg );
|
114 |
+
Mage::getSingleton ( 'core/session' )->addSuccess ( 'Notification Sent Successfully.' );
|
115 |
+
$this->_redirectReferer ();
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Function to Sending Push Notification to Andriod
|
120 |
+
*
|
121 |
+
* @param $androidAuthKey android
|
122 |
+
* Auth key given by android developer
|
123 |
+
* @param $message array
|
124 |
+
* information related to the push notification
|
125 |
+
*
|
126 |
+
*/
|
127 |
+
public function sendNotificationAndroid($androidAuthKey, $message) {
|
128 |
+
// database write adapter
|
129 |
+
$db_write = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_write' );
|
130 |
+
// database read adapter
|
131 |
+
$db_read = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
|
132 |
+
// get the table preix value
|
133 |
+
$prefix = Mage::getConfig ()->getTablePrefix ();
|
134 |
+
$userDetails = $db_read->fetchAll ( "SELECT devicetoken FROM " . $prefix . "mcomm_token WHERE devicetype='android' group by devicetoken" );
|
135 |
+
|
136 |
+
foreach ( $userDetails as $users ) {
|
137 |
+
// get the device token from the database
|
138 |
+
$registration_ids [] = $users ['devicetoken'];
|
139 |
+
}
|
140 |
+
|
141 |
+
// Set POST variables
|
142 |
+
$url = 'https://android.googleapis.com/gcm/send';
|
143 |
+
|
144 |
+
$fields = array (
|
145 |
+
'registration_ids' => $registration_ids,
|
146 |
+
'data' => $message
|
147 |
+
);
|
148 |
+
$headers = array (
|
149 |
+
'Authorization: key=' . $androidAuthKey,
|
150 |
+
'Content-Type: application/json'
|
151 |
+
);
|
152 |
+
// Open connection
|
153 |
+
$ch = curl_init ();
|
154 |
+
|
155 |
+
// Set the url, number of POST vars, POST data
|
156 |
+
curl_setopt ( $ch, CURLOPT_URL, $url );
|
157 |
+
|
158 |
+
curl_setopt ( $ch, CURLOPT_POST, true );
|
159 |
+
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
|
160 |
+
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
|
161 |
+
|
162 |
+
// Disabling SSL Certificate support temporarly
|
163 |
+
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
|
164 |
+
|
165 |
+
curl_setopt ( $ch, CURLOPT_POSTFIELDS, json_encode ( $fields ) );
|
166 |
+
|
167 |
+
// Execute post
|
168 |
+
$result = curl_exec ( $ch );
|
169 |
+
if ($result === FALSE) {
|
170 |
+
die ( 'Curl failed: ' . curl_error ( $ch ) );
|
171 |
+
}
|
172 |
+
// Close connection
|
173 |
+
curl_close ( $ch );
|
174 |
+
}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* Function to Sending Push Notification to IOS
|
178 |
+
*
|
179 |
+
* @param $pemfile this
|
180 |
+
* file user for push from server to ios device
|
181 |
+
* @param $passphrase while
|
182 |
+
* creating pem file if we given password here we use. In this project we have not created
|
183 |
+
*
|
184 |
+
*/
|
185 |
+
public function sendNotificationiOS($pemfile, $passphrase, $mode, $message) {
|
186 |
+
// database write adapter
|
187 |
+
$db_write = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_write' );
|
188 |
+
// database read adapter
|
189 |
+
$db_read = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
|
190 |
+
// get the table preix value
|
191 |
+
$prefix = Mage::getConfig ()->getTablePrefix ();
|
192 |
+
$userDetails = $db_read->fetchAll ( "SELECT devicetoken FROM " . $prefix . "mcomm_token WHERE devicetype='iphone' AND `devicetoken` IS NOT NULL
|
193 |
+
AND `devicetoken` != '' group by devicetoken" );
|
194 |
+
|
195 |
+
foreach ( $userDetails as $users ) {
|
196 |
+
// get the device token from database
|
197 |
+
$registration_ids [] = $users ['devicetoken'];
|
198 |
+
}
|
199 |
+
echo $pemfile;
|
200 |
+
$ctx = stream_context_create ();
|
201 |
+
stream_context_set_option ( $ctx, 'ssl', 'local_cert', $pemfile );
|
202 |
+
|
203 |
+
// Type pem file name
|
204 |
+
stream_context_set_option ( $ctx, 'ssl', 'passphrase', '' );
|
205 |
+
|
206 |
+
// Open a connection to the APNS server
|
207 |
+
if ($mode == false) {
|
208 |
+
$fp = stream_socket_client ( 'ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx );
|
209 |
+
} else {
|
210 |
+
|
211 |
+
$fp = stream_socket_client ( 'ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx );
|
212 |
+
}
|
213 |
+
if (! $fp)
|
214 |
+
$connetionStatus = ("Failed to connect: $err $errstr" . PHP_EOL);
|
215 |
+
else
|
216 |
+
$connetionStatus = 'Connected to APNS' . PHP_EOL;
|
217 |
+
|
218 |
+
// Create the payload body
|
219 |
+
$body ['aps'] = array (
|
220 |
|
221 |
+
'alert' => $message ['msg'],
|
222 |
+
'sound' => 'default',
|
223 |
+
'id' => $message ['id'],
|
224 |
+
'type' => $message ['type'],
|
225 |
+
'content-available' => '1'
|
226 |
+
);
|
227 |
+
|
228 |
+
// Encode the payload as JSON
|
229 |
+
$payload = json_encode ( $body );
|
230 |
+
// Build the binary notification
|
231 |
+
for($i = 0; $i < count ( $registration_ids ); $i ++) {
|
232 |
+
$msg = chr ( 0 ) . pack ( 'n', 32 ) . pack ( 'H*', $registration_ids [$i] ) . pack ( 'n', strlen ( $payload ) ) . $payload;
|
233 |
+
// Send it to the server
|
234 |
+
$result = fwrite ( $fp, $msg, strlen ( $msg ) );
|
235 |
+
|
236 |
+
if (! $result)
|
237 |
+
$deliverStatus = 'Message not delivered' . PHP_EOL;
|
238 |
+
else
|
239 |
+
$deliverStatus = 'Message successfully delivered->' . $message ['msg'] . PHP_EOL;
|
240 |
+
|
241 |
+
//print_r ( $message );
|
242 |
+
}
|
243 |
+
// Close the connection to the server
|
244 |
+
fclose ( $fp );
|
245 |
+
return $result;
|
246 |
+
}
|
247 |
+
|
248 |
+
/**
|
249 |
+
* Edit or create offer details
|
250 |
+
*
|
251 |
+
* @return void Created record values and redirect to current page
|
252 |
+
*/
|
253 |
+
public function editAction() {
|
254 |
+
$id = $this->getRequest ()->getParam ( 'id' );
|
255 |
+
$model = Mage::getModel ( 'offers/offers' )->load ( $id );
|
256 |
+
|
257 |
+
if ($model->getId () || $id == 0) {
|
258 |
+
$data = Mage::getSingleton ( 'adminhtml/session' )->getFormData ( true );
|
259 |
+
if (! empty ( $data )) {
|
260 |
+
$model->setData ( $data );
|
261 |
+
}
|
262 |
+
|
263 |
+
// set offer_products data string to array to model
|
264 |
+
if (isset ( $model ['offer_products'] ) && $model ['offer_products'] != '') {
|
265 |
+
$model ['offer_products'] = explode ( ',', $model ['offer_products'] );
|
266 |
+
}
|
267 |
+
|
268 |
+
Mage::register ( 'offers_data', $model );
|
269 |
+
|
270 |
+
$this->loadLayout ();
|
271 |
+
$this->_setActiveMenu ( 'offers/items' );
|
272 |
+
|
273 |
+
$this->_addBreadcrumb ( Mage::helper ( 'adminhtml' )->__ ( 'Item Manager' ), Mage::helper ( 'adminhtml' )->__ ( 'Item Manager' ) );
|
274 |
+
$this->_addBreadcrumb ( Mage::helper ( 'adminhtml' )->__ ( 'Item News' ), Mage::helper ( 'adminhtml' )->__ ( 'Item News' ) );
|
275 |
+
|
276 |
+
$this->getLayout ()->getBlock ( 'head' )->setCanLoadExtJs ( true );
|
277 |
+
|
278 |
+
$this->_addContent ( $this->getLayout ()->createBlock ( 'offers/adminhtml_offers_edit' ) )->_addLeft ( $this->getLayout ()->createBlock ( 'offers/adminhtml_offers_edit_tabs' ) );
|
279 |
+
|
280 |
+
$this->renderLayout ();
|
281 |
+
} else {
|
282 |
+
Mage::getSingleton ( 'adminhtml/session' )->addError ( Mage::helper ( 'offers' )->__ ( 'Item does not exist' ) );
|
283 |
+
$this->_redirect ( '*/*/' );
|
284 |
+
}
|
285 |
+
}
|
286 |
+
|
287 |
+
/**
|
288 |
+
* Redirects page to edit action
|
289 |
+
*
|
290 |
+
* @return void Redirects to edit action
|
291 |
+
*/
|
292 |
+
public function newAction() {
|
293 |
+
$this->_forward ( 'edit' );
|
294 |
+
}
|
295 |
+
|
296 |
+
/**
|
297 |
+
* Save action for current records
|
298 |
+
*
|
299 |
+
* @return boolean True if data saved successfull else redirects page to edit action
|
300 |
+
*/
|
301 |
+
public function saveAction() {
|
302 |
+
if ($data = $this->getRequest ()->getPost ()) {
|
303 |
+
|
304 |
+
// convert offer_products array to string
|
305 |
+
if (! is_array ( $data ['offer_products'] )) {
|
306 |
+
$err_offer_product = '';
|
307 |
+
} else if (is_array ( $data ['offer_products'] )) {
|
308 |
+
$err_offer_product = '';
|
309 |
+
$data ['offer_products'] = implode ( ',', $data ['offer_products'] );
|
310 |
+
}
|
311 |
+
|
312 |
+
// Format date
|
313 |
+
$data = $this->_filterDates ( $data, array (
|
314 |
+
'from_date',
|
315 |
+
'to_date'
|
316 |
+
) );
|
317 |
+
|
318 |
+
// Save offer image
|
319 |
+
$err_img = '';
|
320 |
+
$err_array = array ();
|
321 |
+
|
322 |
+
if (isset ( $data ['stores'] )) {
|
323 |
+
if (in_array ( '0', $data ['stores'] )) {
|
324 |
+
$data ['store_id'] = '0';
|
325 |
+
} else {
|
326 |
+
$data ['store_id'] = implode ( ",", $data ['stores'] );
|
327 |
}
|
328 |
+
unset ( $data ['stores'] );
|
329 |
+
}
|
330 |
+
if (isset ( $_FILES ['offer_img'] ['name'] ) && $_FILES ['offer_img'] ['name'] != '') {
|
331 |
+
try {
|
332 |
+
|
333 |
+
/* Starting upload */
|
334 |
+
$uploader = new Varien_File_Uploader ( 'offer_img' );
|
335 |
+
|
336 |
+
// for creating the directory if not exists
|
337 |
+
$uploader->setAllowCreateFolders ( true );
|
338 |
+
// Alloweed extention would work
|
339 |
+
$uploader->setAllowedExtensions ( array (
|
340 |
+
'jpg',
|
341 |
+
'jpeg',
|
342 |
+
'gif',
|
343 |
+
'png'
|
344 |
+
) );
|
345 |
+
$uploader->setAllowRenameFiles ( false );
|
346 |
+
$uploader->setFilesDispersion ( false );
|
347 |
+
|
348 |
+
// We set media as the upload dir
|
349 |
+
$path = Mage::getBaseDir ( 'media' ) . DS . 'offers' . DS;
|
350 |
+
if ($uploader->save ( $path, $_FILES ['offer_img'] ['name'] )) {
|
351 |
+
|
352 |
+
// this way the name is saved in DB
|
353 |
+
$data ['offer_img'] = 'offers/' . $_FILES ['offer_img'] ['name'];
|
354 |
+
}
|
355 |
+
} catch ( Exception $e ) {
|
356 |
+
$err_img = 1;
|
357 |
+
$err_array [] = $e->getMessage ();
|
358 |
}
|
359 |
+
} else {
|
360 |
+
if (isset ( $data ['offer_img_view'] ) && $data ['offer_img_view'] != '') {
|
361 |
+
$data ['offer_img'] = $data ['offer_img_view'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
}
|
363 |
+
}
|
364 |
+
|
365 |
+
$model = Mage::getModel ( 'offers/offers' );
|
366 |
+
$model->setData ( $data )->setId ( $this->getRequest ()->getParam ( 'id' ) );
|
367 |
+
|
368 |
+
// Check validation for uploaded imgae and non empty of products before insert
|
369 |
+
|
370 |
+
if (isset ( $err_offer_product ) && $err_offer_product == 1) {
|
371 |
+
$err_array [] = 'Please select product(s) for this offer';
|
372 |
+
}
|
373 |
+
|
374 |
+
if (isset ( $err_img ) && $err_img == 1 || isset ( $err_offer_product ) && $err_offer_product == 1) {
|
375 |
|
376 |
+
foreach ( $err_array as $msg ) {
|
377 |
+
Mage::getSingleton ( 'adminhtml/session' )->addError ( Mage::helper ( 'offers' )->__ ( $msg ) );
|
378 |
+
}
|
379 |
+
$offerId = $this->getRequest ()->getParam ( 'id' );
|
380 |
+
if (isset ( $offerId ) && $this->getRequest ()->getParam ( 'id' ) != '') {
|
381 |
+
$this->_redirect ( '*/*/edit', array (
|
382 |
+
'id' => $model->getId ()
|
383 |
+
) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
384 |
} else {
|
385 |
+
|
386 |
+
Mage::getSingleton ( 'adminhtml/session' )->setFormData ( $data );
|
387 |
+
$key = Mage::getSingleton ( 'adminhtml/url' )->getSecretKey ( "adminhtml_offers", "new" );
|
388 |
+
|
389 |
+
$this->_redirect ( '*/*/new', array (
|
390 |
+
'key' => $key
|
391 |
+
) );
|
392 |
}
|
393 |
|
394 |
+
return;
|
395 |
+
}
|
396 |
+
|
397 |
+
try {
|
398 |
+
if ($model->getCreatedOn == NULL || $model->getUpdateOn () == NULL) {
|
399 |
+
$model->setCreatedOn ( now () )->setUpdateOn ( now () );
|
400 |
+
} else {
|
401 |
+
$model->setUpdateOn ( now () );
|
402 |
+
}
|
403 |
|
404 |
+
$model->save ();
|
405 |
+
Mage::getSingleton ( 'adminhtml/session' )->addSuccess ( Mage::helper ( 'offers' )->__ ( 'Offer was successfully saved.' ) );
|
406 |
+
Mage::getSingleton ( 'adminhtml/session' )->setFormData ( false );
|
407 |
|
408 |
+
if ($this->getRequest ()->getParam ( 'back' )) {
|
409 |
+
$this->_redirect ( '*/*/edit', array (
|
410 |
+
'id' => $model->getId ()
|
411 |
+
) );
|
412 |
+
return;
|
413 |
}
|
414 |
+
$this->_redirect ( '*/*/' );
|
415 |
+
return;
|
416 |
+
} catch ( Exception $e ) {
|
417 |
+
Mage::getSingleton ( 'adminhtml/session' )->addError ( $e->getMessage () );
|
418 |
+
Mage::getSingleton ( 'adminhtml/session' )->setFormData ( $data );
|
419 |
+
$this->_redirect ( '*/*/edit', array (
|
420 |
+
'id' => $this->getRequest ()->getParam ( 'id' )
|
421 |
+
) );
|
422 |
+
return;
|
423 |
+
}
|
424 |
+
}
|
425 |
+
Mage::getSingleton ( 'adminhtml/session' )->addError ( Mage::helper ( 'offers' )->__ ( 'Unable to find item to save.' ) );
|
426 |
+
$this->_redirect ( '*/*/' );
|
427 |
+
}
|
428 |
+
|
429 |
+
/**
|
430 |
+
* Delete the current id
|
431 |
+
*
|
432 |
+
* @return void Redirects to grid page
|
433 |
+
*/
|
434 |
+
public function deleteAction() {
|
435 |
+
if ($this->getRequest ()->getParam ( 'id' ) > 0) {
|
436 |
+
try {
|
437 |
+
$model = Mage::getModel ( 'offers/offers' );
|
438 |
|
439 |
+
$model->setId ( $this->getRequest ()->getParam ( 'id' ) )->delete ();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
440 |
|
441 |
+
Mage::getSingleton ( 'adminhtml/session' )->addSuccess ( Mage::helper ( 'adminhtml' )->__ ( 'Item was successfully deleted.' ) );
|
442 |
+
$this->_redirect ( '*/*/' );
|
443 |
+
} catch ( Exception $e ) {
|
444 |
+
Mage::getSingleton ( 'adminhtml/session' )->addError ( $e->getMessage () );
|
445 |
+
$this->_redirect ( '*/*/edit', array (
|
446 |
+
'id' => $this->getRequest ()->getParam ( 'id' )
|
447 |
+
) );
|
448 |
+
}
|
449 |
+
}
|
450 |
+
$this->_redirect ( '*/*/' );
|
451 |
+
}
|
452 |
+
|
453 |
+
/**
|
454 |
+
* Deletes selected records from database
|
455 |
+
*
|
456 |
+
* @return void Redirect to grid page
|
457 |
+
*/
|
458 |
+
public function massDeleteAction() {
|
459 |
+
$offersIds = $this->getRequest ()->getParam ( 'offers' );
|
460 |
+
if (! is_array ( $offersIds )) {
|
461 |
+
Mage::getSingleton ( 'adminhtml/session' )->addError ( Mage::helper ( 'adminhtml' )->__ ( 'Please select item(s).' ) );
|
462 |
+
} else {
|
463 |
+
try {
|
464 |
+
foreach ( $offersIds as $offersId ) {
|
465 |
+
$offers = Mage::getModel ( 'offers/offers' )->load ( $offersId );
|
466 |
+
$offers->delete ();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
467 |
}
|
468 |
+
Mage::getSingleton ( 'adminhtml/session' )->addSuccess ( Mage::helper ( 'adminhtml' )->__ ( 'Total of %d record(s) were successfully deleted', count ( $offersIds ) ) );
|
469 |
+
} catch ( Exception $e ) {
|
470 |
+
Mage::getSingleton ( 'adminhtml/session' )->addError ( $e->getMessage () );
|
471 |
+
}
|
472 |
+
}
|
473 |
+
$this->_redirect ( '*/*/index' );
|
474 |
+
}
|
475 |
+
|
476 |
+
/**
|
477 |
+
* Updates mass status update on selected grid records
|
478 |
+
*
|
479 |
+
* @return void Redirects back to index page
|
480 |
+
*/
|
481 |
+
public function massStatusAction() {
|
482 |
+
$offersIds = $this->getRequest ()->getParam ( 'offers' );
|
483 |
+
if (! is_array ( $offersIds )) {
|
484 |
+
Mage::getSingleton ( 'adminhtml/session' )->addError ( $this->__ ( 'Please select item(s)' ) );
|
485 |
+
} else {
|
486 |
+
try {
|
487 |
+
foreach ( $offersIds as $offersId ) {
|
488 |
+
$offers = Mage::getSingleton ( 'offers/offers' )->load ( $offersId )->setStatus ( $this->getRequest ()->getParam ( 'status' ) )->setIsMassupdate ( true )->save ();
|
489 |
}
|
490 |
+
$this->_getSession ()->addSuccess ( $this->__ ( 'Total of %d record(s) were successfully updated', count ( $offersIds ) ) );
|
491 |
+
} catch ( Exception $e ) {
|
492 |
+
$this->_getSession ()->addError ( $e->getMessage () );
|
493 |
+
}
|
494 |
+
}
|
495 |
+
$this->_redirect ( '*/*/index' );
|
496 |
+
}
|
497 |
+
|
498 |
+
/**
|
499 |
+
* CSV file export
|
500 |
+
*
|
501 |
+
* @return csv Returns csv file
|
502 |
+
*/
|
503 |
+
public function exportCsvAction() {
|
504 |
+
$fileName = 'offers.csv';
|
505 |
+
$content = $this->getLayout ()->createBlock ( 'offers/adminhtml_offers_grid' )->getCsv ();
|
506 |
+
|
507 |
+
$this->_sendUploadResponse ( $fileName, $content );
|
508 |
+
}
|
509 |
+
|
510 |
+
/**
|
511 |
+
* XML file export
|
512 |
+
*
|
513 |
+
* @return xml Returns xml file to be download
|
514 |
+
*/
|
515 |
+
public function exportXmlAction() {
|
516 |
+
$fileName = 'offers.xml';
|
517 |
+
$content = $this->getLayout ()->createBlock ( 'offers/adminhtml_offers_grid' )->getXml ();
|
518 |
+
|
519 |
+
$this->_sendUploadResponse ( $fileName, $content );
|
520 |
+
}
|
521 |
+
protected function _sendUploadResponse($fileName, $content, $contentType = 'application/octet-stream') {
|
522 |
+
$response = $this->getResponse ();
|
523 |
+
$response->setHeader ( 'HTTP/1.1 200 OK', '' );
|
524 |
+
$response->setHeader ( 'Pragma', 'public', true );
|
525 |
+
$response->setHeader ( 'Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true );
|
526 |
+
$response->setHeader ( 'Content-Disposition', 'attachment; filename=' . $fileName );
|
527 |
+
$response->setHeader ( 'Last-Modified', date ( 'r' ) );
|
528 |
+
$response->setHeader ( 'Accept-Ranges', 'bytes' );
|
529 |
+
$response->setHeader ( 'Content-Length', strlen ( $content ) );
|
530 |
+
$response->setHeader ( 'Content-type', $contentType );
|
531 |
+
$response->setBody ( $content );
|
532 |
+
$response->sendResponse ();
|
533 |
+
}
|
534 |
}
|
app/code/local/Contus/Offers/etc/config.xml
CHANGED
@@ -69,7 +69,7 @@
|
|
69 |
<class>Contus_Offers_Model_Mysql4</class>
|
70 |
<entities>
|
71 |
<offers>
|
72 |
-
<table>
|
73 |
</offers>
|
74 |
</entities>
|
75 |
</offers_mysql4>
|
69 |
<class>Contus_Offers_Model_Mysql4</class>
|
70 |
<entities>
|
71 |
<offers>
|
72 |
+
<table>mcomm_offers</table>
|
73 |
</offers>
|
74 |
</entities>
|
75 |
</offers_mysql4>
|
app/code/local/Contus/Offers/sql/offers_setup/mysql4-install-0.1.0.php
CHANGED
@@ -36,11 +36,12 @@ $installer->startSetup ();
|
|
36 |
|
37 |
$installer->run ( "
|
38 |
|
39 |
-
-- DROP TABLE IF EXISTS {$this->getTable('
|
40 |
-
CREATE TABLE {$this->getTable('
|
41 |
`offers_id` int(11) unsigned NOT NULL auto_increment,
|
42 |
`offer_title` varchar(255) NOT NULL default '',
|
43 |
`offer_img` varchar(255) NOT NULL default '',
|
|
|
44 |
`from_date` date DEFAULT NULL,
|
45 |
`to_date` date DEFAULT NULL,
|
46 |
`offer_products` varchar(255) NOT NULL default '',
|
@@ -52,4 +53,5 @@ CREATE TABLE {$this->getTable('offers')} (
|
|
52 |
|
53 |
" );
|
54 |
|
55 |
-
|
|
36 |
|
37 |
$installer->run ( "
|
38 |
|
39 |
+
-- DROP TABLE IF EXISTS {$this->getTable('mcomm_offers')};
|
40 |
+
CREATE TABLE {$this->getTable('mcomm_offers')} (
|
41 |
`offers_id` int(11) unsigned NOT NULL auto_increment,
|
42 |
`offer_title` varchar(255) NOT NULL default '',
|
43 |
`offer_img` varchar(255) NOT NULL default '',
|
44 |
+
`store_id` varchar( 100 ) DEFAULT NULL,
|
45 |
`from_date` date DEFAULT NULL,
|
46 |
`to_date` date DEFAULT NULL,
|
47 |
`offer_products` varchar(255) NOT NULL default '',
|
53 |
|
54 |
" );
|
55 |
|
56 |
+
|
57 |
+
$installer->endSetup ();
|
app/code/local/Contus/Pushnoteorders/controllers/Adminhtml/PushnoteordersController.php
CHANGED
@@ -101,7 +101,7 @@ class Contus_Pushnoteorders_Adminhtml_PushnoteordersController extends Mage_Admi
|
|
101 |
$db_read = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
|
102 |
// get the table preix value
|
103 |
$prefix = Mage::getConfig ()->getTablePrefix ();
|
104 |
-
$userDetails = $db_read->fetchAll ( "SELECT devicetoken FROM " . $prefix . "
|
105 |
|
106 |
foreach ( $userDetails as $users ) {
|
107 |
// get the device token from the database
|
@@ -159,7 +159,7 @@ class Contus_Pushnoteorders_Adminhtml_PushnoteordersController extends Mage_Admi
|
|
159 |
$db_read = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
|
160 |
// get the table preix value
|
161 |
$prefix = Mage::getConfig ()->getTablePrefix ();
|
162 |
-
$userDetails = $db_read->fetchAll ( "SELECT devicetoken FROM " . $prefix . "
|
163 |
foreach ( $userDetails as $users ) {
|
164 |
// get the device token from database
|
165 |
$registration_ids [] = $users ['devicetoken'];
|
@@ -178,9 +178,9 @@ class Contus_Pushnoteorders_Adminhtml_PushnoteordersController extends Mage_Admi
|
|
178 |
$fp = stream_socket_client ( 'ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx );
|
179 |
}
|
180 |
if (! $fp)
|
181 |
-
|
182 |
else
|
183 |
-
|
184 |
|
185 |
// Create the payload body
|
186 |
$body ['aps'] = array (
|
@@ -201,11 +201,11 @@ class Contus_Pushnoteorders_Adminhtml_PushnoteordersController extends Mage_Admi
|
|
201 |
$result = fwrite ( $fp, $msg, strlen ( $msg ) );
|
202 |
|
203 |
if (! $result)
|
204 |
-
|
205 |
else
|
206 |
-
|
207 |
|
208 |
-
|
209 |
}
|
210 |
// Close the connection to the server
|
211 |
fclose ( $fp );
|
101 |
$db_read = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
|
102 |
// get the table preix value
|
103 |
$prefix = Mage::getConfig ()->getTablePrefix ();
|
104 |
+
$userDetails = $db_read->fetchAll ( "SELECT devicetoken FROM " . $prefix . "mcomm_token WHERE devicetype='android' and userid=" . $customer_id );
|
105 |
|
106 |
foreach ( $userDetails as $users ) {
|
107 |
// get the device token from the database
|
159 |
$db_read = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
|
160 |
// get the table preix value
|
161 |
$prefix = Mage::getConfig ()->getTablePrefix ();
|
162 |
+
$userDetails = $db_read->fetchAll ( "SELECT devicetoken FROM " . $prefix . "mcomm_token WHERE devicetype='iphone' and userid=" . $customer_id );
|
163 |
foreach ( $userDetails as $users ) {
|
164 |
// get the device token from database
|
165 |
$registration_ids [] = $users ['devicetoken'];
|
178 |
$fp = stream_socket_client ( 'ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx );
|
179 |
}
|
180 |
if (! $fp)
|
181 |
+
$connetionStatus = ("Failed to connect: $err $errstr" . PHP_EOL);
|
182 |
else
|
183 |
+
$connetionStatus = 'Connected to APNS' . PHP_EOL;
|
184 |
|
185 |
// Create the payload body
|
186 |
$body ['aps'] = array (
|
201 |
$result = fwrite ( $fp, $msg, strlen ( $msg ) );
|
202 |
|
203 |
if (! $result)
|
204 |
+
$deliverStatus = 'Message not delivered' . PHP_EOL;
|
205 |
else
|
206 |
+
$deliverStatus = 'Message successfully delivered->' . $message ['msg'] . PHP_EOL;
|
207 |
|
208 |
+
// print_r ( $message );
|
209 |
}
|
210 |
// Close the connection to the server
|
211 |
fclose ( $fp );
|
app/code/local/Contus/Pushnoteproducts/controllers/Adminhtml/PushnoteproductsController.php
CHANGED
@@ -46,9 +46,10 @@ class Contus_Pushnoteproducts_Adminhtml_PushnoteproductsController extends Mage_
|
|
46 |
$params = $this->getRequest ()->getPost ();
|
47 |
$message = $params ['product_name'];
|
48 |
$id = $params ['product_id'];
|
|
|
49 |
|
50 |
if ($isEnabled) {
|
51 |
-
$this->notification ( $message, $id );
|
52 |
} else {
|
53 |
Mage::getSingleton ( 'core/session' )->addError ( 'Please enable push notification option for product.' );
|
54 |
$this->_redirectReferer ();
|
@@ -63,11 +64,12 @@ class Contus_Pushnoteproducts_Adminhtml_PushnoteproductsController extends Mage_
|
|
63 |
*
|
64 |
* @param int $id
|
65 |
*/
|
66 |
-
public function notification($message, $id) {
|
67 |
|
68 |
// Information to send in the push notification
|
69 |
$msg ['msg'] = $message;
|
70 |
$msg ['id'] = $id;
|
|
|
71 |
$msg ['type'] = 'product';
|
72 |
|
73 |
// MCOM demo googel api key
|
@@ -78,7 +80,7 @@ class Contus_Pushnoteproducts_Adminhtml_PushnoteproductsController extends Mage_
|
|
78 |
// Send Push Notification to Android and ios
|
79 |
$this->sendNotificationAndroid ( $gcmKey, $msg );
|
80 |
$result = $this->sendNotificationiOS ( $result['pemfile'], $gcmKey, $result['mode'], $msg);
|
81 |
-
|
82 |
Mage::getSingleton ( 'core/session' )->addSuccess ( 'Notification Sent Successfully. ' );
|
83 |
$this->_redirectReferer ();
|
84 |
}
|
@@ -99,7 +101,7 @@ class Contus_Pushnoteproducts_Adminhtml_PushnoteproductsController extends Mage_
|
|
99 |
$db_read = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
|
100 |
// get the table preix value
|
101 |
$prefix = Mage::getConfig ()->getTablePrefix ();
|
102 |
-
$userDetails = $db_read->fetchAll ( "SELECT devicetoken FROM " . $prefix . "
|
103 |
|
104 |
foreach ( $userDetails as $users ) {
|
105 |
// get the device token from the database
|
@@ -158,12 +160,14 @@ class Contus_Pushnoteproducts_Adminhtml_PushnoteproductsController extends Mage_
|
|
158 |
$db_read = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
|
159 |
// get the table preix value
|
160 |
$prefix = Mage::getConfig ()->getTablePrefix ();
|
161 |
-
$userDetails = $db_read->fetchAll ( "SELECT devicetoken FROM " . $prefix . "
|
|
|
162 |
|
163 |
foreach ( $userDetails as $users ) {
|
164 |
// get the device token from database
|
165 |
$registration_ids [] = $users ['devicetoken'];
|
166 |
}
|
|
|
167 |
$ctx = stream_context_create ();
|
168 |
stream_context_set_option ( $ctx, 'ssl', 'local_cert', $pemfile );
|
169 |
|
@@ -178,9 +182,9 @@ class Contus_Pushnoteproducts_Adminhtml_PushnoteproductsController extends Mage_
|
|
178 |
$fp = stream_socket_client ( 'ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx );
|
179 |
}
|
180 |
if (! $fp)
|
181 |
-
|
182 |
else
|
183 |
-
|
184 |
|
185 |
// Create the payload body
|
186 |
$body ['aps'] = array (
|
@@ -201,11 +205,11 @@ class Contus_Pushnoteproducts_Adminhtml_PushnoteproductsController extends Mage_
|
|
201 |
$result = fwrite ( $fp, $msg, strlen ( $msg ) );
|
202 |
|
203 |
if (! $result)
|
204 |
-
|
205 |
else
|
206 |
-
|
207 |
|
208 |
-
|
209 |
}
|
210 |
// Close the connection to the server
|
211 |
fclose ( $fp );
|
46 |
$params = $this->getRequest ()->getPost ();
|
47 |
$message = $params ['product_name'];
|
48 |
$id = $params ['product_id'];
|
49 |
+
$store_id = $params ['store_id'];
|
50 |
|
51 |
if ($isEnabled) {
|
52 |
+
$this->notification ( $message, $id, $store_id );
|
53 |
} else {
|
54 |
Mage::getSingleton ( 'core/session' )->addError ( 'Please enable push notification option for product.' );
|
55 |
$this->_redirectReferer ();
|
64 |
*
|
65 |
* @param int $id
|
66 |
*/
|
67 |
+
public function notification($message, $id, $store_id) {
|
68 |
|
69 |
// Information to send in the push notification
|
70 |
$msg ['msg'] = $message;
|
71 |
$msg ['id'] = $id;
|
72 |
+
$msg ['store_id'] = $store_id;
|
73 |
$msg ['type'] = 'product';
|
74 |
|
75 |
// MCOM demo googel api key
|
80 |
// Send Push Notification to Android and ios
|
81 |
$this->sendNotificationAndroid ( $gcmKey, $msg );
|
82 |
$result = $this->sendNotificationiOS ( $result['pemfile'], $gcmKey, $result['mode'], $msg);
|
83 |
+
|
84 |
Mage::getSingleton ( 'core/session' )->addSuccess ( 'Notification Sent Successfully. ' );
|
85 |
$this->_redirectReferer ();
|
86 |
}
|
101 |
$db_read = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
|
102 |
// get the table preix value
|
103 |
$prefix = Mage::getConfig ()->getTablePrefix ();
|
104 |
+
$userDetails = $db_read->fetchAll ( "SELECT devicetoken FROM " . $prefix . "mcomm_token WHERE devicetype='android' group by devicetoken" );
|
105 |
|
106 |
foreach ( $userDetails as $users ) {
|
107 |
// get the device token from the database
|
160 |
$db_read = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
|
161 |
// get the table preix value
|
162 |
$prefix = Mage::getConfig ()->getTablePrefix ();
|
163 |
+
$userDetails = $db_read->fetchAll ( "SELECT devicetoken FROM " . $prefix . "mcomm_token WHERE devicetype='iphone' AND `devicetoken` IS NOT NULL
|
164 |
+
AND `devicetoken` != '' group by devicetoken" );
|
165 |
|
166 |
foreach ( $userDetails as $users ) {
|
167 |
// get the device token from database
|
168 |
$registration_ids [] = $users ['devicetoken'];
|
169 |
}
|
170 |
+
|
171 |
$ctx = stream_context_create ();
|
172 |
stream_context_set_option ( $ctx, 'ssl', 'local_cert', $pemfile );
|
173 |
|
182 |
$fp = stream_socket_client ( 'ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx );
|
183 |
}
|
184 |
if (! $fp)
|
185 |
+
$connetionStatus = ("Failed to connect: $err $errstr" . PHP_EOL);
|
186 |
else
|
187 |
+
$connetionStatus = 'Connected to APNS' . PHP_EOL;
|
188 |
|
189 |
// Create the payload body
|
190 |
$body ['aps'] = array (
|
205 |
$result = fwrite ( $fp, $msg, strlen ( $msg ) );
|
206 |
|
207 |
if (! $result)
|
208 |
+
$deliverStatus = 'Message not delivered' . PHP_EOL;
|
209 |
else
|
210 |
+
$deliverStatus = 'Message successfully delivered->' . $message ['msg'] . PHP_EOL;
|
211 |
|
212 |
+
// print_r ( $message );
|
213 |
}
|
214 |
// Close the connection to the server
|
215 |
fclose ( $fp );
|
app/code/local/ContusRestapi/ApplyCoupon/Model/Api2/ApplyCouponapi.php
CHANGED
@@ -176,7 +176,7 @@ class ContusRestapi_ApplyCoupon_Model_Api2_ApplyCouponapi extends Mage_Api2_Mode
|
|
176 |
try {
|
177 |
$quote->setData ( static::COUPON_CODE, '' )->collectTotals ()->save ();
|
178 |
$success = 1;
|
179 |
-
$message = 'Coupon code was
|
180 |
$cartproducts = $this->getCartAmountDetails ( array (
|
181 |
static::STOREID => $storeId,
|
182 |
static::CUSTOMER_ID => $customerId
|
176 |
try {
|
177 |
$quote->setData ( static::COUPON_CODE, '' )->collectTotals ()->save ();
|
178 |
$success = 1;
|
179 |
+
$message = 'Coupon code was revoked.';
|
180 |
$cartproducts = $this->getCartAmountDetails ( array (
|
181 |
static::STOREID => $storeId,
|
182 |
static::CUSTOMER_ID => $customerId
|
app/code/local/ContusRestapi/CartAddressapi/Model/Api2/CartAddressapi.php
CHANGED
@@ -27,93 +27,314 @@
|
|
27 |
* @since 1.0
|
28 |
*/
|
29 |
class ContusRestapi_CartAddressapi_Model_Api2_CartAddressapi extends Mage_Api2_Model_Resource {
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
// set shipping adress
|
85 |
-
$quoteShippingAddress = Mage::getModel ( 'sales/quote_address' );
|
86 |
-
$quoteShippingAddress->setStoreId ( $storeId )->setCustomerId ( $customerId )->setCustomerAddressId ( $shipping_addressId );
|
87 |
-
$shippingAddress = Mage::getModel ( 'customer/address' )->load ( $shipping_addressId );
|
88 |
-
|
89 |
-
$quoteShippingAddress->setData ( $shippingAddress->getData () );
|
90 |
-
$quote->setShippingAddress ( $quoteShippingAddress );
|
91 |
-
$quote->getShippingAddress ()->setCollectShippingRates ( true );
|
92 |
-
$quote->collectTotals ();
|
93 |
-
$quote->setIsActive ( 1 );
|
94 |
-
$quote->save ();
|
95 |
-
|
96 |
-
$success = 1;
|
97 |
-
$message = "Billing and Shipping Address added successfully.";
|
98 |
-
} else {
|
99 |
-
$success = 0;
|
100 |
-
$message = "Please select billing and shipping address.";
|
101 |
-
}
|
102 |
-
$ship_payment = Mage::getModel ( 'login/methods_functions' )->getShippingPaymentMethods ( $quoteId, $storeId );
|
103 |
-
} catch ( Exception $e ) {
|
104 |
-
$success = 0;
|
105 |
-
$message = $e->getMessage ();
|
106 |
}
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
$success = 0;
|
109 |
-
$message =
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
}
|
27 |
* @since 1.0
|
28 |
*/
|
29 |
class ContusRestapi_CartAddressapi_Model_Api2_CartAddressapi extends Mage_Api2_Model_Resource {
|
30 |
+
const SCHEDULE_TYPE = 'schedule_type';
|
31 |
+
const SCHEDULE_TYPE_ID = 'schedule_type_id';
|
32 |
+
const TITLE = 'title';
|
33 |
+
const SCHEDULE_TITLE = 'schedule_title';
|
34 |
+
const DELIVERY_SCHEDULE_ID = 'deliveryschedule_id';
|
35 |
+
const SCHEDULE_ID = 'schedule_id';
|
36 |
+
const INTERVAL = 'interval';
|
37 |
+
const TIME_SLOT = 'time_slot';
|
38 |
+
const TIME_INTERVAL = 'time_interval';
|
39 |
+
const DAY_INTERVAL = 'day_interval';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* function that is called when post is done **
|
43 |
+
* Get active shipping and payment Methods
|
44 |
+
*
|
45 |
+
* @return array json array
|
46 |
+
*/
|
47 |
+
protected function _create(array $data) {
|
48 |
+
$response = array ();
|
49 |
+
$ship_payment = array ();
|
50 |
+
// get website id
|
51 |
+
$websiteId = ( int ) $data ['website_id'];
|
52 |
+
if ($websiteId <= 0) {
|
53 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
54 |
+
}
|
55 |
+
// get website id from request
|
56 |
+
$storeId = ( int ) $data ['store_id'];
|
57 |
+
if ($storeId <= 0) {
|
58 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
59 |
+
}
|
60 |
+
// get customer id
|
61 |
+
$customerId = ( int ) $data ['customer_id'];
|
62 |
+
|
63 |
+
// get quote id
|
64 |
+
$quoteId = ( int ) $data ['quote_id'];
|
65 |
+
// get default billing address id
|
66 |
+
$billing_addressId = ( int ) $data ['billing_address_id'];
|
67 |
+
// get default shipping address id
|
68 |
+
$shipping_addressId = ( int ) $data ['shipping_address_id'];
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Check this customer has valid token or not
|
72 |
+
*
|
73 |
+
* @var $isValidToken Mage_Login_Model_Token
|
74 |
+
*/
|
75 |
+
$isValidToken = Mage::getModel ( 'login/token' )->checkUserToken ( $customerId, $data ['token'] );
|
76 |
+
if ($quoteId && $isValidToken) {
|
77 |
+
try {
|
78 |
+
$quote = Mage::getModel ( 'sales/quote' );
|
79 |
+
$quote->setStoreId ( $storeId )->load ( $quoteId );
|
80 |
+
|
81 |
+
$active = $quote->getIsActive ();
|
82 |
+
if (! $active) {
|
83 |
+
throw new Exception ( 'Quote is invalid!.' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
}
|
85 |
+
|
86 |
+
// Set billing address
|
87 |
+
$quoteBillingAddress = Mage::getModel ( 'sales/quote_address' );
|
88 |
+
if ($billing_addressId > 0 && $shipping_addressId > 0) {
|
89 |
+
$quoteBillingAddress->setStoreId ( $storeId )->setCustomerId ( $customerId )->setCustomerAddressId ( $billing_addressId );
|
90 |
+
$billingAddress = Mage::getModel ( 'customer/address' )->load ( $billing_addressId );
|
91 |
+
$quoteBillingAddress->setData ( $billingAddress->getData () );
|
92 |
+
$quote->setBillingAddress ( $quoteBillingAddress );
|
93 |
+
|
94 |
+
// set shipping adress
|
95 |
+
$quoteShippingAddress = Mage::getModel ( 'sales/quote_address' );
|
96 |
+
$quoteShippingAddress->setStoreId ( $storeId )->setCustomerId ( $customerId )->setCustomerAddressId ( $shipping_addressId );
|
97 |
+
$shippingAddress = Mage::getModel ( 'customer/address' )->load ( $shipping_addressId );
|
98 |
+
|
99 |
+
$quoteShippingAddress->setData ( $shippingAddress->getData () );
|
100 |
+
$quote->setShippingAddress ( $quoteShippingAddress );
|
101 |
+
$quote->getShippingAddress ()->setCollectShippingRates ( true );
|
102 |
+
$quote->collectTotals ();
|
103 |
+
$quote->setIsActive ( 1 );
|
104 |
+
$quote->save ();
|
105 |
+
|
106 |
+
$success = 1;
|
107 |
+
$message = "Billing and Shipping Address added successfully.";
|
108 |
+
} else {
|
109 |
+
$success = 0;
|
110 |
+
$message = "Please select billing and shipping address.";
|
111 |
+
}
|
112 |
+
$ship_payment = Mage::getModel ( 'login/methods_functions' )->getShippingPaymentMethods ( $quoteId, $storeId );
|
113 |
+
} catch ( Exception $e ) {
|
114 |
$success = 0;
|
115 |
+
$message = $e->getMessage ();
|
116 |
+
}
|
117 |
+
} else {
|
118 |
+
$success = 0;
|
119 |
+
$message = "Authentication failed.";
|
120 |
+
}
|
121 |
+
$response ['isValidToken'] = $isValidToken;
|
122 |
+
$response ['error'] = false;
|
123 |
+
$response ['success'] = $success;
|
124 |
+
$response ['message'] = $message;
|
125 |
+
$response ['result'] = $ship_payment;
|
126 |
+
$this->getResponse ()->setBody ( json_encode ( $response ) );
|
127 |
+
return;
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Retrieve information Delivery information
|
132 |
+
*
|
133 |
+
* @throws Mage_Api2_Exception
|
134 |
+
* @return array
|
135 |
+
*/
|
136 |
+
protected function _retrieve() {
|
137 |
+
$response = array ();
|
138 |
+
// get website id from request
|
139 |
+
$websiteId = ( int ) $this->getRequest ()->getParam ( 'website_id' );
|
140 |
+
if ($websiteId <= 0) {
|
141 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
142 |
+
}
|
143 |
+
// get website id from request
|
144 |
+
$storeId = ( int ) $this->getRequest ()->getParam ( 'store_id' );
|
145 |
+
if ($storeId <= 0) {
|
146 |
+
Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
147 |
+
}
|
148 |
+
$deliveryInfo = array ();
|
149 |
+
$deliveryModes = array ();
|
150 |
+
if (Mage::getStoreConfig ( 'deliveryschedule/general/delivery_schedule_enabled' ) == 1) {
|
151 |
+
$deliveryInfo = $this->getdeliveryDetails ( $storeId );
|
152 |
+
$deliveryModes = $this->getDeliveryModes ( $storeId );
|
153 |
+
}
|
154 |
+
|
155 |
+
$response ['error'] = false;
|
156 |
+
$response ['success'] = 1;
|
157 |
+
$response ['message'] = 'Get Delivery Information';
|
158 |
+
|
159 |
+
$response ['modes'] = $deliveryModes;
|
160 |
+
$response ['result'] = $deliveryInfo;
|
161 |
+
|
162 |
+
return $response;
|
163 |
+
}
|
164 |
+
|
165 |
+
/**
|
166 |
+
* get delivery modes
|
167 |
+
*
|
168 |
+
* @param int $storeId
|
169 |
+
* @return array $modes
|
170 |
+
*/
|
171 |
+
public function getDeliveryModes($storeId) {
|
172 |
+
$modes = array ();
|
173 |
+
$scheduleTypes = Mage::getModel ( 'deliveryschedule/deliveryscheduletypes' )->getCollection ()->addFieldToFilter ( "status", 1 )->setOrder ( 'sorting', 'ASC' )->addFieldToFilter ( "store_view", array (
|
174 |
+
"in" => array (
|
175 |
+
'0',
|
176 |
+
$storeId
|
177 |
+
)
|
178 |
+
) );
|
179 |
+
$i = 0;
|
180 |
+
foreach ( $scheduleTypes as $type ) {
|
181 |
+
$modes [$i] ['schedule_type_id'] = $type->getId ();
|
182 |
+
$modes [$i] ['schedule_type'] = $type->getName ();
|
183 |
+
$modes [$i] ['desc'] = $type->getDescription ();
|
184 |
+
$i ++;
|
185 |
+
}
|
186 |
+
|
187 |
+
return $modes;
|
188 |
+
}
|
189 |
+
|
190 |
+
/**
|
191 |
+
* Get delivery time slots from mwdtime table
|
192 |
+
*
|
193 |
+
* @param int $storeId
|
194 |
+
* @return array $delivery
|
195 |
+
*/
|
196 |
+
public function getdeliveryDetails($storeId) {
|
197 |
+
$deliveryschedule = Mage::getModel ( 'deliveryschedule/deliveryschedule' )->getCollection ();
|
198 |
+
$deliveryschedule->getSelect ()->join ( array (
|
199 |
+
static::SCHEDULE_TYPE => Mage::getSingleton ( "core/resource" )->getTableName ( 'deliveryschedule_types' )
|
200 |
+
), 'schedule_type.id = main_table.schedule_type_id and main_table.status= 1', array (
|
201 |
+
'schedule_type.id',
|
202 |
+
'schedule_type.name',
|
203 |
+
'schedule_type.monday as mon',
|
204 |
+
'schedule_type.tuesday as tue',
|
205 |
+
'schedule_type.wednesday as wed',
|
206 |
+
'schedule_type.thursday as thu',
|
207 |
+
'schedule_type.friday as fri',
|
208 |
+
'schedule_type.saturday as sat',
|
209 |
+
'schedule_type.sunday as sun'
|
210 |
+
) )->where ( 'schedule_type.store_view in (?)', array (
|
211 |
+
'0',
|
212 |
+
$storeId
|
213 |
+
) )->where ( 'schedule_type.status = 1' )->order ( 'main_table.sorting asc' );
|
214 |
+
|
215 |
+
$delivery = array ();
|
216 |
+
$m = 0;
|
217 |
+
$t = 0;
|
218 |
+
$w = 0;
|
219 |
+
$th = 0;
|
220 |
+
$f = 0;
|
221 |
+
$sat = 0;
|
222 |
+
$sun = 0;
|
223 |
+
foreach ( $deliveryschedule as $schedule ) {
|
224 |
+
if ($schedule ['mon'] == 1) {
|
225 |
+
$delivery ['mon'] [$m] [static::SCHEDULE_TYPE_ID] = $schedule [static::SCHEDULE_TYPE_ID];
|
226 |
+
$delivery ['mon'] [$m] [static::SCHEDULE_TYPE] = $schedule ['name'];
|
227 |
+
$delivery ['mon'] [$m] [static::SCHEDULE_TITLE] = $schedule [static::TITLE];
|
228 |
+
$delivery ['mon'] [$m] [static::SCHEDULE_ID] = $schedule [static::DELIVERY_SCHEDULE_ID];
|
229 |
+
$delivery ['mon'] [$m] [static::INTERVAL] = $schedule [static::TIME_SLOT];
|
230 |
+
|
231 |
+
$delivery ['mon'] [$m] [static::TIME_INTERVAL] = $schedule [static::TIME_INTERVAL];
|
232 |
+
$delivery ['mon'] [$m] [static::DAY_INTERVAL] = $schedule [static::DAY_INTERVAL];
|
233 |
+
$delivery ['mon'] [$m] ['cost'] = $schedule ['monday_cost'];
|
234 |
+
$m ++;
|
235 |
+
} elseif ($m == 0) {
|
236 |
+
$delivery ['mon'] [$m] = array ();
|
237 |
+
} else {
|
238 |
+
// no code here
|
239 |
+
}
|
240 |
+
if ($schedule ['tue'] == 1) {
|
241 |
+
$delivery ['tue'] [$t] [static::SCHEDULE_TYPE_ID] = $schedule [static::SCHEDULE_TYPE_ID];
|
242 |
+
$delivery ['tue'] [$t] [static::SCHEDULE_TYPE] = $schedule ['name'];
|
243 |
+
$delivery ['tue'] [$t] [static::SCHEDULE_ID] = $schedule [static::DELIVERY_SCHEDULE_ID];
|
244 |
+
$delivery ['tue'] [$t] [static::SCHEDULE_TITLE] = $schedule [static::TITLE];
|
245 |
+
$delivery ['tue'] [$t] [static::INTERVAL] = $schedule [static::TIME_SLOT];
|
246 |
+
|
247 |
+
$delivery ['tue'] [$t] [static::TIME_INTERVAL] = $schedule [static::TIME_INTERVAL];
|
248 |
+
$delivery ['tue'] [$t] [static::DAY_INTERVAL] = $schedule [static::DAY_INTERVAL];
|
249 |
+
$delivery ['tue'] [$t] ['cost'] = $schedule ['tuesday_cost'];
|
250 |
+
$t ++;
|
251 |
+
} elseif ($t == 0) {
|
252 |
+
$delivery ['tue'] = array ();
|
253 |
+
} else {
|
254 |
+
// no code here
|
255 |
+
}
|
256 |
+
if ($schedule ['wed'] == 1) {
|
257 |
+
$delivery ['wed'] [$w] [static::SCHEDULE_TYPE_ID] = $schedule [static::SCHEDULE_TYPE_ID];
|
258 |
+
$delivery ['wed'] [$w] [static::SCHEDULE_TYPE] = $schedule ['name'];
|
259 |
+
$delivery ['wed'] [$w] [static::SCHEDULE_ID] = $schedule [static::DELIVERY_SCHEDULE_ID];
|
260 |
+
$delivery ['wed'] [$w] [static::SCHEDULE_TITLE] = $schedule [static::TITLE];
|
261 |
+
$delivery ['wed'] [$w] [static::INTERVAL] = $schedule [static::TIME_SLOT];
|
262 |
+
|
263 |
+
$delivery ['wed'] [$w] [static::TIME_INTERVAL] = $schedule [static::TIME_INTERVAL];
|
264 |
+
$delivery ['wed'] [$w] [static::DAY_INTERVAL] = $schedule [static::DAY_INTERVAL];
|
265 |
+
$delivery ['wed'] [$w] ['cost'] = $schedule ['wednesday_cost'];
|
266 |
+
$w ++;
|
267 |
+
} elseif ($w == 0) {
|
268 |
+
$delivery ['wed'] = array ();
|
269 |
+
} else {
|
270 |
+
// no code here
|
271 |
+
}
|
272 |
+
if ($schedule ['thu'] == 1) {
|
273 |
+
$delivery ['thu'] [$th] [static::SCHEDULE_TYPE_ID] = $schedule [static::SCHEDULE_TYPE_ID];
|
274 |
+
$delivery ['thu'] [$th] [static::SCHEDULE_TYPE] = $schedule ['name'];
|
275 |
+
$delivery ['thu'] [$th] [static::SCHEDULE_ID] = $schedule [static::DELIVERY_SCHEDULE_ID];
|
276 |
+
$delivery ['thu'] [$th] [static::SCHEDULE_TITLE] = $schedule [static::TITLE];
|
277 |
+
$delivery ['thu'] [$th] [static::INTERVAL] = $schedule [static::TIME_SLOT];
|
278 |
+
|
279 |
+
$delivery ['thu'] [$th] [static::TIME_INTERVAL] = $schedule [static::TIME_INTERVAL];
|
280 |
+
$delivery ['thu'] [$th] [static::DAY_INTERVAL] = $schedule [static::DAY_INTERVAL];
|
281 |
+
$delivery ['thu'] [$th] ['cost'] = $schedule ['thursday_cost'];
|
282 |
+
$th ++;
|
283 |
+
} elseif ($th == 0) {
|
284 |
+
$delivery ['thu'] = array ();
|
285 |
+
} else {
|
286 |
+
// no code here
|
287 |
+
}
|
288 |
+
if ($schedule ['fri'] == 1) {
|
289 |
+
$delivery ['fri'] [$f] [static::SCHEDULE_TYPE_ID] = $schedule [static::SCHEDULE_TYPE_ID];
|
290 |
+
$delivery ['fri'] [$f] [static::SCHEDULE_TYPE] = $schedule ['name'];
|
291 |
+
$delivery ['fri'] [$f] [static::SCHEDULE_ID] = $schedule [static::DELIVERY_SCHEDULE_ID];
|
292 |
+
$delivery ['fri'] [$f] [static::SCHEDULE_TITLE] = $schedule [static::TITLE];
|
293 |
+
$delivery ['fri'] [$f] [static::INTERVAL] = $schedule [static::TIME_SLOT];
|
294 |
+
|
295 |
+
$delivery ['fri'] [$f] [static::TIME_INTERVAL] = $schedule [static::TIME_INTERVAL];
|
296 |
+
$delivery ['fri'] [$f] [static::DAY_INTERVAL] = $schedule [static::DAY_INTERVAL];
|
297 |
+
|
298 |
+
$delivery ['fri'] [$f] ['cost'] = $schedule ['friday_cost'];
|
299 |
+
$f ++;
|
300 |
+
} elseif ($f == 0) {
|
301 |
+
$delivery ['fri'] = array ();
|
302 |
+
} else {
|
303 |
+
// no code here
|
304 |
+
}
|
305 |
+
if ($schedule ['sat'] == 1) {
|
306 |
+
$delivery ['sat'] [$sat] [static::SCHEDULE_TYPE_ID] = $schedule [static::SCHEDULE_TYPE_ID];
|
307 |
+
$delivery ['sat'] [$sat] [static::SCHEDULE_TYPE] = $schedule ['name'];
|
308 |
+
$delivery ['sat'] [$sat] [static::SCHEDULE_ID] = $schedule [static::DELIVERY_SCHEDULE_ID];
|
309 |
+
$delivery ['sat'] [$sat] [static::SCHEDULE_TITLE] = $schedule [static::TITLE];
|
310 |
+
$delivery ['sat'] [$sat] [static::INTERVAL] = $schedule [static::TIME_SLOT];
|
311 |
+
|
312 |
+
$delivery ['sat'] [$sat] [static::TIME_INTERVAL] = $schedule [static::TIME_INTERVAL];
|
313 |
+
$delivery ['sat'] [$sat] [static::DAY_INTERVAL] = $schedule [static::DAY_INTERVAL];
|
314 |
+
$delivery ['sat'] [$sat] ['cost'] = $schedule ['saturday_cost'];
|
315 |
+
$sat ++;
|
316 |
+
} elseif ($sat == 0) {
|
317 |
+
$delivery ['sat'] = array ();
|
318 |
+
} else {
|
319 |
+
// no code here
|
320 |
+
}
|
321 |
+
if ($schedule ['sun'] == 1) {
|
322 |
+
$delivery ['sun'] [$sun] [static::SCHEDULE_TYPE_ID] = $schedule [static::SCHEDULE_TYPE_ID];
|
323 |
+
$delivery ['sun'] [$sun] [static::SCHEDULE_TYPE] = $schedule ['name'];
|
324 |
+
$delivery ['sun'] [$sun] [static::SCHEDULE_ID] = $schedule [static::DELIVERY_SCHEDULE_ID];
|
325 |
+
$delivery ['sun'] [$sun] [static::SCHEDULE_TITLE] = $schedule [static::TITLE];
|
326 |
+
$delivery ['sun'] [$sun] [static::INTERVAL] = $schedule [static::TIME_SLOT];
|
327 |
+
|
328 |
+
$delivery ['sun'] [$sun] [static::TIME_INTERVAL] = $schedule [static::TIME_INTERVAL];
|
329 |
+
$delivery ['sun'] [$sun] [static::DAY_INTERVAL] = $schedule [static::DAY_INTERVAL];
|
330 |
+
$delivery ['sun'] [$sun] ['cost'] = $schedule ['sunday_cost'];
|
331 |
+
$sun ++;
|
332 |
+
} elseif ($sun == 0) {
|
333 |
+
$delivery ['sun'] = array ();
|
334 |
+
} else {
|
335 |
+
// no code here
|
336 |
+
}
|
337 |
+
}
|
338 |
+
return $delivery;
|
339 |
+
}
|
340 |
}
|
app/code/local/ContusRestapi/CartAddressapi/etc/api2.xml
CHANGED
@@ -34,28 +34,35 @@
|
|
34 |
<quote_id>Shopping cart Id</quote_id>
|
35 |
<billing_address_id>Billing Address Id</billing_address_id>
|
36 |
<shipping_address_id>Shipping Address Id</shipping_address_id>
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
51 |
</attributes>
|
52 |
<routes>
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
59 |
</routes>
|
60 |
<versions>1</versions>
|
61 |
</cartAddressapi>
|
34 |
<quote_id>Shopping cart Id</quote_id>
|
35 |
<billing_address_id>Billing Address Id</billing_address_id>
|
36 |
<shipping_address_id>Shipping Address Id</shipping_address_id>
|
37 |
+
<address_type>address_type</address_type>
|
38 |
+
<same_for_shipping>same_for_shipping</same_for_shipping>
|
39 |
+
<first_name>first_name</first_name>
|
40 |
+
<last_name>last_name</last_name>
|
41 |
+
<address1>address1</address1>
|
42 |
+
<city>city</city>
|
43 |
+
<state>state</state>
|
44 |
+
<zip>zip</zip>
|
45 |
+
<country>country</country>
|
46 |
+
<telephone>telephone</telephone>
|
47 |
+
<success>success</success>
|
48 |
+
<message>message</message>
|
49 |
+
<token>Token</token>
|
50 |
+
<customer_id>Customer Id</customer_id>
|
51 |
+
<error>Error</error>
|
52 |
+
<result>Result</result>
|
53 |
+
<modes>Modes</modes>
|
54 |
</attributes>
|
55 |
<routes>
|
56 |
+
|
57 |
+
<address_add>
|
58 |
+
<route>/cart_address/add/</route>
|
59 |
+
<action_type>collection</action_type>
|
60 |
+
</address_add>
|
61 |
+
<delivery_details>
|
62 |
+
<route>/delivery/info/</route>
|
63 |
+
<action_type>entity</action_type>
|
64 |
+
</delivery_details>
|
65 |
+
|
66 |
</routes>
|
67 |
<versions>1</versions>
|
68 |
</cartAddressapi>
|
app/code/local/ContusRestapi/Cartapi/Model/Api2/Cartapi.php
CHANGED
@@ -110,7 +110,7 @@ class ContusRestapi_Cartapi_Model_Api2_Cartapi extends Mage_Api2_Model_Resource
|
|
110 |
$error = $this->addToCart ( $product, $quote, $qty, $data );
|
111 |
}
|
112 |
|
113 |
-
if (is_string ( $error ) || $quote
|
114 |
$message = ($quote) ? $error : 'Customer not found.';
|
115 |
$error_flag = false;
|
116 |
$success = 0;
|
110 |
$error = $this->addToCart ( $product, $quote, $qty, $data );
|
111 |
}
|
112 |
|
113 |
+
if (is_string ( $error ) || empty($quote)) {
|
114 |
$message = ($quote) ? $error : 'Customer not found.';
|
115 |
$error_flag = false;
|
116 |
$success = 0;
|
app/code/local/ContusRestapi/Contactus/Model/Api2/Contactus.php
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the EULA
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://www.apptha.com/LICENSE.txt
|
12 |
+
*
|
13 |
+
* ==============================================================
|
14 |
+
* MAGENTO EDITION USAGE NOTICE
|
15 |
+
* ==============================================================
|
16 |
+
* This package designed for Magento COMMUNITY edition
|
17 |
+
* Apptha does not guarantee correct work of this extension
|
18 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
19 |
+
* Apptha does not provide extension support in case of
|
20 |
+
* incorrect edition usage.
|
21 |
+
* ==============================================================
|
22 |
+
*
|
23 |
+
* @category Contus
|
24 |
+
* @package ContusRestapi_Contactus
|
25 |
+
* @author Contus Team <developers@contus.in>
|
26 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
27 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
28 |
+
* @since 1.0
|
29 |
+
*/
|
30 |
+
class ContusRestapi_Contactus_Model_Api2_Contactus extends Mage_Api2_Model_Resource {
|
31 |
+
|
32 |
+
|
33 |
+
// Declaring the string literals variable
|
34 |
+
const EMAIL = 'email';
|
35 |
+
|
36 |
+
/**
|
37 |
+
* function that is called when post is done **
|
38 |
+
*
|
39 |
+
* Contact us form
|
40 |
+
*
|
41 |
+
* @param array $data
|
42 |
+
*
|
43 |
+
* @return array json array
|
44 |
+
*/
|
45 |
+
protected function _create(array $data) {
|
46 |
+
$response = array ();
|
47 |
+
|
48 |
+
// get website id from request
|
49 |
+
$websiteId = ( int ) $data ['website_id'];
|
50 |
+
if ($websiteId <= 0) {
|
51 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
52 |
+
}
|
53 |
+
// get store id from request
|
54 |
+
$storeId = ( int ) $data ['store_id'];
|
55 |
+
if ($storeId <= 0) {
|
56 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
57 |
+
}
|
58 |
+
|
59 |
+
try {
|
60 |
+
$postObject = new Varien_Object ();
|
61 |
+
$postObject->setData ( $data );
|
62 |
+
|
63 |
+
$error = false;
|
64 |
+
|
65 |
+
if (! Zend_Validate::is ( trim ( $data ['comment'] ), 'NotEmpty' )) {
|
66 |
+
$error = true;
|
67 |
+
$message = 'Message is required field';
|
68 |
+
}
|
69 |
+
|
70 |
+
if (! Zend_Validate::is ( trim ( $data [static::EMAIL] ), 'EmailAddress' )) {
|
71 |
+
$error = true;
|
72 |
+
$message = 'Email Address is required field';
|
73 |
+
}
|
74 |
+
|
75 |
+
if ($error) {
|
76 |
+
throw new Exception ( $message );
|
77 |
+
}
|
78 |
+
$mailTemplate = Mage::getModel ( 'core/email_template' );
|
79 |
+
/* @var $mailTemplate Mage_Core_Model_Email_Template */
|
80 |
+
$mailTemplate->setDesignConfig ( array (
|
81 |
+
'area' => 'frontend'
|
82 |
+
) )->setReplyTo ( $data [static::EMAIL] )->sendTransactional ( Mage::getStoreConfig ( 'contacts/email/email_template', $storeId ), Mage::getStoreConfig ( 'contacts/email/sender_email_identity', $storeId ), Mage::getStoreConfig ( 'contacts/email/recipient_email', $storeId ), null, array (
|
83 |
+
'data' => $postObject
|
84 |
+
) );
|
85 |
+
$mailTemplate->setStoreId ( $storeId );
|
86 |
+
|
87 |
+
if (! $mailTemplate->getSentSuccess ()) {
|
88 |
+
throw new Exception ( 'Unable to submit your request. Please, try again later' );
|
89 |
+
}
|
90 |
+
$success = 1;
|
91 |
+
$message = 'Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.';
|
92 |
+
} catch ( Exception $e ) {
|
93 |
+
$success = 0;
|
94 |
+
$message = $e->getMessage ();
|
95 |
+
}
|
96 |
+
|
97 |
+
$response ['error'] = false;
|
98 |
+
$response ['success'] = $success;
|
99 |
+
$response ['message'] = $message;
|
100 |
+
|
101 |
+
$this->getResponse ()->setBody ( json_encode ( $response ) );
|
102 |
+
return;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Get Contact details about store
|
107 |
+
*
|
108 |
+
* @param array $data
|
109 |
+
*
|
110 |
+
* @return array json array
|
111 |
+
*/
|
112 |
+
protected function _retrieve() {
|
113 |
+
$response = array ();
|
114 |
+
$contactDetail = array ();
|
115 |
+
|
116 |
+
// get website id from request
|
117 |
+
$websiteId = ( int ) Mage::app ()->getRequest ()->getParam ( 'website_id' );
|
118 |
+
if ($websiteId <= 0) {
|
119 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
120 |
+
}
|
121 |
+
|
122 |
+
// get store id
|
123 |
+
$storeId = ( int ) Mage::app ()->getRequest ()->getParam ( 'store_id' );
|
124 |
+
if ($storeId <= 0) {
|
125 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
126 |
+
}
|
127 |
+
// get store name
|
128 |
+
$contactDetail ['name'] = Mage::getStoreConfig ( 'general/store_information/name', $storeId );
|
129 |
+
// get store phone number
|
130 |
+
$contactDetail ['phone'] = Mage::getStoreConfig ( 'general/store_information/phone', $storeId );
|
131 |
+
// get store address
|
132 |
+
$contactDetail ['address'] = Mage::getStoreConfig ( 'general/store_information/address', $storeId );
|
133 |
+
// get store general email address
|
134 |
+
$contactDetail [static::EMAIL] = Mage::getStoreConfig ( 'trans_email/ident_general/email', $storeId );
|
135 |
+
$response ['success'] = 1;
|
136 |
+
$response ['error'] = false;
|
137 |
+
|
138 |
+
$response ['result'] = $contactDetail;
|
139 |
+
|
140 |
+
return $response;
|
141 |
+
}
|
142 |
+
}
|
app/code/local/ContusRestapi/Contactus/Model/Api2/Contactus/Rest.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_Contactus
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_Contactus_Model_Api2_Contactus_Rest extends ContusRestapi_Contactus_Model_Api2_Contactus {
|
30 |
+
}
|
app/code/local/ContusRestapi/Contactus/Model/Api2/Contactus/Rest/Admin/V1.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_Contactus
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_Contactus_Model_Api2_Contactus_Rest_Admin_V1 extends ContusRestapi_Contactus_Model_Api2_Contactus_Rest {
|
30 |
+
}
|
app/code/local/ContusRestapi/Contactus/Model/Api2/Contactus/Rest/Customer/V1.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_Contactus
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_Contactus_Model_Api2_Contactus_Rest_Customer_V1 extends ContusRestapi_Contactus_Model_Api2_Contactus_Rest {
|
30 |
+
}
|
app/code/local/ContusRestapi/Contactus/Model/Api2/Contactus/Rest/Guest/V1.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_Contactus
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_Contactus_Model_Api2_Contactus_Rest_Guest_V1 extends ContusRestapi_Contactus_Model_Api2_Contactus_Rest {
|
30 |
+
}
|
app/code/local/ContusRestapi/Contactus/etc/api2.xml
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<api2>
|
4 |
+
<resource_groups>
|
5 |
+
<contusRestapi translate="title" module="Contactus">
|
6 |
+
<title>Contact us form</title>
|
7 |
+
<sort_order>10</sort_order>
|
8 |
+
</contusRestapi>
|
9 |
+
</resource_groups>
|
10 |
+
<resources>
|
11 |
+
<contactus translate="title" module="Contactus">
|
12 |
+
<group>contusrestapi</group>
|
13 |
+
<model>contactus/api2_contactus</model>
|
14 |
+
<title>Contact us form</title>
|
15 |
+
<sort_order>10</sort_order>
|
16 |
+
<privileges>
|
17 |
+
<admin>
|
18 |
+
<create>1</create>
|
19 |
+
<retrieve>1</retrieve>
|
20 |
+
<delete>1</delete>
|
21 |
+
</admin>
|
22 |
+
<customer>
|
23 |
+
<create>1</create>
|
24 |
+
<retrieve>1</retrieve>
|
25 |
+
<delete>1</delete>
|
26 |
+
</customer>
|
27 |
+
<guest>
|
28 |
+
<create>1</create>
|
29 |
+
<retrieve>1</retrieve>
|
30 |
+
<delete>1</delete>
|
31 |
+
</guest>
|
32 |
+
</privileges>
|
33 |
+
<attributes module="api2">
|
34 |
+
<website_id>websiteid</website_id>
|
35 |
+
<store_id>Associate to Store</store_id>
|
36 |
+
<name>Name</name>
|
37 |
+
<email>Email</email>
|
38 |
+
<telephone>Telephine number</telephone>
|
39 |
+
<comment>Comment</comment>
|
40 |
+
<error>Error flag</error>
|
41 |
+
<success>Success</success>
|
42 |
+
<result>Result</result>
|
43 |
+
</attributes>
|
44 |
+
<routes>
|
45 |
+
<route_collection>
|
46 |
+
<route>/contactus/</route>
|
47 |
+
<action_type>collection</action_type>
|
48 |
+
</route_collection>
|
49 |
+
|
50 |
+
<contact_details>
|
51 |
+
<route>/contact_details/</route>
|
52 |
+
<action_type>entity</action_type>
|
53 |
+
</contact_details>
|
54 |
+
</routes>
|
55 |
+
<versions>1</versions>
|
56 |
+
</contactus>
|
57 |
+
|
58 |
+
</resources>
|
59 |
+
</api2>
|
60 |
+
</config>
|
app/code/local/ContusRestapi/Contactus/etc/config.xml
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<ContusRestapi_Contactus>
|
5 |
+
<version>0.1.0.0</version>
|
6 |
+
</ContusRestapi_Contactus>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<models>
|
10 |
+
<contactus>
|
11 |
+
<class>ContusRestapi_Contactus_Model</class>
|
12 |
+
</contactus>
|
13 |
+
</models>
|
14 |
+
</global>
|
15 |
+
</config>
|
app/code/local/ContusRestapi/Filters/Model/Api2/Filters.php
CHANGED
@@ -28,276 +28,288 @@
|
|
28 |
* @since 1.0
|
29 |
*/
|
30 |
class ContusRestapi_Filters_Model_Api2_Filters extends Mage_Api2_Model_Resource {
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
// get
|
86 |
-
$
|
87 |
-
|
88 |
-
//
|
89 |
-
$
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
}
|
98 |
-
// form array for sock availability
|
99 |
-
$availability [static::ATTR_CODE] = 'availability';
|
100 |
-
$availability ['attribute_label'] = 'Availability';
|
101 |
-
$values [static::VALUE] = 1;
|
102 |
-
$values [static::LABEL] = 'Availability';
|
103 |
-
$values [static::COUNT] = '';
|
104 |
-
$availability [static::VALUES] [] = $values;
|
105 |
-
$filters [] = $availability;
|
106 |
-
|
107 |
-
$response ['error'] = false;
|
108 |
-
$response ['success'] = 1;
|
109 |
-
$response ['message'] = '';
|
110 |
-
$response ['result'] = $filters;
|
111 |
-
return json_encode ( $response );
|
112 |
-
}
|
113 |
-
|
114 |
-
/**
|
115 |
-
* Get attribute set ids
|
116 |
-
*
|
117 |
-
* @param int $storeId
|
118 |
-
* @param int $categoryId
|
119 |
-
*/
|
120 |
-
public function getAttributeSetIds($storeId, $category) {
|
121 |
-
$select = Mage::getResourceModel ( 'catalog/product_collection' )->setStoreId ( $storeId )->addCategoryFilter ( $category );
|
122 |
-
$select->getSelect ()->distinct ( static::E_ATTR_SET_ID );
|
123 |
-
|
124 |
-
$select->getSelect ()->reset ( Zend_Db_Select::COLUMNS )->columns ( static::E_ATTR_SET_ID );
|
125 |
-
|
126 |
-
return $select->getData ();
|
127 |
-
}
|
128 |
-
|
129 |
-
/**
|
130 |
-
* Get searchable attributes from attribute set id
|
131 |
-
*
|
132 |
-
* @param array $setIds
|
133 |
-
* @param int $storeId
|
134 |
-
*/
|
135 |
-
public function getSearchableAttr($setIds, $storeId) {
|
136 |
-
$collection = Mage::getResourceModel ( 'catalog/product_attribute_collection' );
|
137 |
-
$collection->setItemObjectClass ( 'catalog/resource_eav_attribute' )->setAttributeSetFilter ( array (
|
138 |
-
$setIds
|
139 |
-
) )->addStoreLabel ( $storeId )->setOrder ( 'position', 'ASC' );
|
140 |
-
$collection = $collection->addIsFilterableFilter ();
|
141 |
-
|
142 |
-
return $collection->load ()->getData ();
|
143 |
-
}
|
144 |
-
|
145 |
-
/**
|
146 |
-
* Get attribute collection from category products
|
147 |
-
*
|
148 |
-
* @param object $category
|
149 |
-
* @param string $attributeCode
|
150 |
-
* @return array $attrCollection
|
151 |
-
*/
|
152 |
-
public function getAttributeCollection($category, $attributeCode) {
|
153 |
-
$config = false;
|
154 |
-
$productAttr = array ();
|
155 |
-
// dtabase read
|
156 |
-
$connection = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
|
157 |
-
|
158 |
-
// get these type of products only
|
159 |
-
$productType = array (
|
160 |
-
"simple",
|
161 |
-
"configurable"
|
162 |
-
);
|
163 |
-
// get attribute values from CATEGORY model
|
164 |
-
$productAttr = Mage::getModel ( static::CATALOG_PRODUCT )->getCollection ()->addCategoryFilter ( $category )->addAttributeToFilter ( 'type_id', array (
|
165 |
-
'in' => $productType
|
166 |
-
) );
|
167 |
-
|
168 |
-
// get attribute value from associaded products
|
169 |
-
$childproduct = Mage::getModel ( static::CATALOG_PRODUCT )->getCollection ();
|
170 |
-
foreach ( $productAttr as $_product ) {
|
171 |
-
if ($_product ['type_id'] == 'configurable') {
|
172 |
-
|
173 |
-
// get the children ids through a simple query
|
174 |
-
$ids = '';
|
175 |
-
$ids = Mage::getModel ( 'catalog/product_type_configurable' )->getChildrenIds ( $_product ['entity_id'] );
|
176 |
-
// get associated products count
|
177 |
-
$counted = count ( $ids [0] );
|
178 |
-
if ($counted > 0) {
|
179 |
-
$config = true;
|
180 |
-
$filter_attr ['attribute'] = 'entity_id';
|
181 |
-
$filter_attr ['in'] = array (
|
182 |
-
$ids
|
183 |
-
);
|
184 |
-
$data [] = $filter_attr;
|
185 |
-
}
|
186 |
-
} else {
|
187 |
-
$productAttr->addAttributeToSelect ( $attributeCode, 'asc' );
|
188 |
-
$productAttr->getSelect ()->reset ( Zend_Db_Select::COLUMNS )->columns ( 'e.entity_id' )->columns ( static::E_ATTR_SET_ID )->columns ( 'e.type_id' )->columns ( 'e.sku' )->columns ( 'at_' . $attributeCode . '.value as ' . $attributeCode );
|
189 |
}
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
$
|
194 |
-
|
195 |
-
|
196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
$main_select = $connection->select ()->union ( array (
|
198 |
-
|
199 |
-
|
200 |
), Zend_Db_Select::SQL_UNION )->group ( $attributeCode );
|
201 |
|
202 |
$attrCollection = $connection->fetchAll ( $main_select );
|
203 |
-
|
204 |
-
$
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
if ($price_flag) {
|
268 |
-
// sort price array
|
269 |
-
sort ( $price );
|
270 |
-
// get minimum price
|
271 |
-
$result [0] [static::VALUE] = number_format ( $price [0], 2, '.', '' );
|
272 |
-
$result [0] [static::LABEL] = 'min_price';
|
273 |
-
$result [0] [static::COUNT] = '';
|
274 |
-
// get maximum price
|
275 |
-
$result [1] [static::VALUE] = number_format ( end ( $price ), 2, '.', '' );
|
276 |
-
$result [1] [static::LABEL] = 'max_price';
|
277 |
-
$result [1] [static::COUNT] = '';
|
278 |
-
}
|
279 |
-
|
280 |
-
return $result;
|
281 |
-
}
|
282 |
-
|
283 |
-
/**
|
284 |
-
*
|
285 |
-
* @param string $key
|
286 |
-
* @param array $data
|
287 |
-
* @return array $data
|
288 |
-
*/
|
289 |
-
public function remove_duplicateKeys($key, $data) {
|
290 |
-
$_data = array ();
|
291 |
-
|
292 |
-
foreach ( $data as $v ) {
|
293 |
-
if (isset ( $_data [$v [$key]] )) {
|
294 |
-
// found duplicate
|
295 |
-
continue;
|
296 |
}
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
}
|
28 |
* @since 1.0
|
29 |
*/
|
30 |
class ContusRestapi_Filters_Model_Api2_Filters extends Mage_Api2_Model_Resource {
|
31 |
+
|
32 |
+
// define static variable
|
33 |
+
const PRICE = 'price';
|
34 |
+
const ATTR_CODE = 'attribute_code';
|
35 |
+
const ATTR_ID = 'attribute_id';
|
36 |
+
const VALUES = 'values';
|
37 |
+
const VALUE = 'value';
|
38 |
+
const LABEL = 'label';
|
39 |
+
const COUNT = 'count';
|
40 |
+
const CATALOG_PRODUCT = 'catalog/product';
|
41 |
+
const E_ATTR_SET_ID = 'e.attribute_set_id';
|
42 |
+
|
43 |
+
/**
|
44 |
+
* function that is called when post is done **
|
45 |
+
*
|
46 |
+
* Get product types for filter category products based on category id
|
47 |
+
*
|
48 |
+
* @param array $data
|
49 |
+
*
|
50 |
+
* @return array json array
|
51 |
+
*/
|
52 |
+
protected function _retrieveCollection() {
|
53 |
+
$response = array ();
|
54 |
+
$filters = array ();
|
55 |
+
// get customer id from request
|
56 |
+
$categoryId = ( int ) $this->getRequest ()->getParam ( 'category_id' );
|
57 |
+
|
58 |
+
// get website id from request
|
59 |
+
$websiteId = ( int ) $this->getRequest ()->getParam ( 'website_id' );
|
60 |
+
if ($websiteId <= 0) {
|
61 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
62 |
+
}
|
63 |
+
// get store id from request
|
64 |
+
$storeId = ( int ) $this->getRequest ()->getParam ( 'store_id' );
|
65 |
+
if ($storeId <= 0) {
|
66 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
67 |
+
}
|
68 |
+
// load category model
|
69 |
+
$category = Mage::getModel ( 'catalog/category' )->load ( $categoryId );
|
70 |
+
|
71 |
+
// Get attribute set ids based on category
|
72 |
+
$setIds = $this->getAttributeSetIds ( $storeId, $category );
|
73 |
+
// get searchable attributes from attribute set id
|
74 |
+
$attribuets = $this->getSearchableAttr ( $setIds, $storeId );
|
75 |
+
|
76 |
+
foreach ( $attribuets as $attribute ) {
|
77 |
+
$result = array ();
|
78 |
+
// assigen attribute code
|
79 |
+
$result [static::ATTR_CODE] = $attribute [static::ATTR_CODE];
|
80 |
+
// assigen attribute label
|
81 |
+
$result ['attribute_label'] = $attribute ['store_label'];
|
82 |
+
// assigen attribute id
|
83 |
+
$result [static::ATTR_ID] = $attribute [static::ATTR_ID];
|
84 |
+
|
85 |
+
// get attribute values from CATEGORY model
|
86 |
+
$attrCollection = $this->getAttributeCollection ( $category, $attribute [static::ATTR_CODE] );
|
87 |
+
|
88 |
+
// remove duplicate attribute value from array
|
89 |
+
$attriArray = $this->remove_duplicateKeys ( $attribute [static::ATTR_CODE], $attrCollection );
|
90 |
+
|
91 |
+
// get product count in each attriubute
|
92 |
+
$productCount = $this->getProductCount ( $attribute [static::ATTR_CODE], $attribute [static::ATTR_ID], $storeId, $category );
|
93 |
+
// get attribute value array
|
94 |
+
$result [static::VALUES] = $this->setAttr ( $attriArray, $attribute [static::ATTR_CODE], $attribute [static::ATTR_ID], $productCount );
|
95 |
+
// form array
|
96 |
+
$filters [] = $result;
|
97 |
+
}
|
98 |
+
// form array for sock availability
|
99 |
+
$availability [static::ATTR_CODE] = 'availability';
|
100 |
+
$availability ['attribute_label'] = 'Availability';
|
101 |
+
$values [static::VALUE] = 1;
|
102 |
+
$values [static::LABEL] = 'Availability';
|
103 |
+
$values [static::COUNT] = '';
|
104 |
+
$availability [static::VALUES] [] = $values;
|
105 |
+
$filters [] = $availability;
|
106 |
+
|
107 |
+
$response ['error'] = false;
|
108 |
+
$response ['success'] = 1;
|
109 |
+
$response ['message'] = '';
|
110 |
+
$response ['result'] = $filters;
|
111 |
+
return json_encode ( $response );
|
112 |
+
}
|
113 |
+
|
114 |
+
/**
|
115 |
+
* Get attribute set ids
|
116 |
+
*
|
117 |
+
* @param int $storeId
|
118 |
+
* @param int $categoryId
|
119 |
+
*/
|
120 |
+
public function getAttributeSetIds($storeId, $category) {
|
121 |
+
$select = Mage::getResourceModel ( 'catalog/product_collection' )->setStoreId ( $storeId )->addCategoryFilter ( $category );
|
122 |
+
$select->getSelect ()->distinct ( static::E_ATTR_SET_ID );
|
123 |
+
|
124 |
+
$select->getSelect ()->reset ( Zend_Db_Select::COLUMNS )->columns ( static::E_ATTR_SET_ID );
|
125 |
+
|
126 |
+
return $select->getData ();
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Get searchable attributes from attribute set id
|
131 |
+
*
|
132 |
+
* @param array $setIds
|
133 |
+
* @param int $storeId
|
134 |
+
*/
|
135 |
+
public function getSearchableAttr($setIds, $storeId) {
|
136 |
+
$collection = Mage::getResourceModel ( 'catalog/product_attribute_collection' );
|
137 |
+
$collection->setItemObjectClass ( 'catalog/resource_eav_attribute' )->setAttributeSetFilter ( array (
|
138 |
+
$setIds
|
139 |
+
) )->addStoreLabel ( $storeId )->setOrder ( 'position', 'ASC' );
|
140 |
+
$collection = $collection->addIsFilterableFilter ();
|
141 |
+
|
142 |
+
return $collection->load ()->getData ();
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Get attribute collection from category products
|
147 |
+
*
|
148 |
+
* @param object $category
|
149 |
+
* @param string $attributeCode
|
150 |
+
* @return array $attrCollection
|
151 |
+
*/
|
152 |
+
public function getAttributeCollection($category, $attributeCode) {
|
153 |
+
$config = false;
|
154 |
+
$simple = false;
|
155 |
+
$productAttr = array ();
|
156 |
+
// dtabase read
|
157 |
+
$connection = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
|
158 |
+
|
159 |
+
// get these type of products only
|
160 |
+
$productType = array (
|
161 |
+
"simple",
|
162 |
+
"configurable"
|
163 |
+
);
|
164 |
+
// get attribute values from CATEGORY model
|
165 |
+
$productAttr = Mage::getModel ( static::CATALOG_PRODUCT )->getCollection ()->addCategoryFilter ( $category )->addAttributeToFilter ( 'type_id', array (
|
166 |
+
'in' => $productType
|
167 |
+
) );
|
168 |
+
|
169 |
+
// get attribute value from associaded products
|
170 |
+
$childproduct = Mage::getModel ( static::CATALOG_PRODUCT )->getCollection ();
|
171 |
+
foreach ( $productAttr as $_product ) {
|
172 |
+
if ($_product ['type_id'] == 'configurable') {
|
173 |
|
174 |
+
// get the children ids through a simple query
|
175 |
+
$ids = '';
|
176 |
+
$ids = Mage::getModel ( 'catalog/product_type_configurable' )->getChildrenIds ( $_product ['entity_id'] );
|
177 |
+
// get associated products count
|
178 |
+
$counted = count ( $ids [0] );
|
179 |
+
if ($counted > 0) {
|
180 |
+
$config = true;
|
181 |
+
$filter_attr ['attribute'] = 'entity_id';
|
182 |
+
$filter_attr ['in'] = array (
|
183 |
+
$ids
|
184 |
+
);
|
185 |
+
$data [] = $filter_attr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
}
|
187 |
+
} else {
|
188 |
+
$simple = true;
|
189 |
+
$productAttr->addAttributeToSelect ( $attributeCode, 'asc' );
|
190 |
+
$productAttr->getSelect ()->reset ( Zend_Db_Select::COLUMNS )->columns ( 'e.entity_id' )->columns ( static::E_ATTR_SET_ID )->columns ( 'e.type_id' )->columns ( 'e.sku' )->columns ( 'at_' . $attributeCode . '.value as ' . $attributeCode );
|
191 |
+
}
|
192 |
+
}
|
193 |
+
|
194 |
+
if ($config) {
|
195 |
+
$childproduct->addAttributeToFilter ( $data, '', 'left' )->addAttributeToSelect ( $attributeCode, 'asc' );
|
196 |
+
$childproduct->getSelect ()->reset ( Zend_Db_Select::COLUMNS )->columns ( 'e.entity_id' )->columns ( 'e.attribute_set_id' )->columns ( 'e.type_id' )->columns ( 'e.sku' )->columns ( 'at_' . $attributeCode . '.value as ' . $attributeCode );
|
197 |
+
$childproduct->getSelect ()->group ( $attributeCode );
|
198 |
+
// union queries in product and associated product
|
199 |
+
if ($simple) {
|
200 |
$main_select = $connection->select ()->union ( array (
|
201 |
+
$childproduct->getSelectSql ( true ),
|
202 |
+
$productAttr->getSelectSql ( true )
|
203 |
), Zend_Db_Select::SQL_UNION )->group ( $attributeCode );
|
204 |
|
205 |
$attrCollection = $connection->fetchAll ( $main_select );
|
206 |
+
} else {
|
207 |
+
$attrCollection = $childproduct->getConnection ()->fetchAll ( $childproduct->getSelect () );
|
208 |
+
}
|
209 |
+
} else {
|
210 |
+
$productAttr->getSelect ()->group ( $attributeCode );
|
211 |
+
$attrCollection = $productAttr->getConnection ()->fetchAll ( $productAttr->getSelect () );
|
212 |
+
}
|
213 |
+
|
214 |
+
return $attrCollection;
|
215 |
+
}
|
216 |
+
|
217 |
+
/**
|
218 |
+
* Retrieve array with products counts per attribute option
|
219 |
+
*
|
220 |
+
* @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
|
221 |
+
* @return array
|
222 |
+
*/
|
223 |
+
public function getProductCount($attributeCode, $attributeId, $storeId, $category) {
|
224 |
+
// get the table preix value
|
225 |
+
$prefix = Mage::getConfig ()->getTablePrefix ();
|
226 |
+
// dtabase read
|
227 |
+
$connection = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
|
228 |
+
|
229 |
+
$select = Mage::getResourceModel ( 'catalog/product_collection' )->setStoreId ( $storeId )->addCategoryFilter ( $category );
|
230 |
+
Mage::getSingleton ( 'catalog/product_visibility' )->addVisibleInCatalogFilterToCollection ( $select );
|
231 |
+
$query_count = $select->getSelect ()->reset ( Zend_Db_Select::COLUMNS )->reset ( Zend_Db_Select::ORDER )->reset ( Zend_Db_Select::LIMIT_COUNT )->reset ( Zend_Db_Select::LIMIT_OFFSET )->join ( array (
|
232 |
+
$attributeCode . '_idx' => $prefix . 'catalog_product_index_eav'
|
233 |
+
), $attributeCode . '_idx.entity_id = e.entity_id AND ' . $attributeCode . '_idx.attribute_id = ' . $attributeId . ' AND ' . $attributeCode . '_idx.store_id = ' . $storeId, array (
|
234 |
+
$attributeCode . '_idx.value, COUNT(' . $attributeCode . '_idx.entity_id) AS count'
|
235 |
+
) )->group ( $attributeCode . '_idx.value' );
|
236 |
+
return $connection->fetchPairs ( $query_count );
|
237 |
+
}
|
238 |
+
|
239 |
+
/**
|
240 |
+
* Set attibute values as array with product count
|
241 |
+
*
|
242 |
+
* @param array $productAttr
|
243 |
+
* @param string $attributeCode
|
244 |
+
* @param int $productCount
|
245 |
+
* @return array $result
|
246 |
+
*/
|
247 |
+
public function setAttr($productAttr, $attributeCode, $attributeId, $productCount) {
|
248 |
+
$result = array ();
|
249 |
+
$price = array ();
|
250 |
+
foreach ( $productAttr as $attr ) {
|
251 |
+
if ($attr [$attributeCode] != '') {
|
252 |
+
$values = array ();
|
253 |
+
// is attribute id is not price ste fale
|
254 |
+
$price_flag = false;
|
255 |
+
// check attribute id price
|
256 |
+
if ($attributeCode == static::PRICE) {
|
257 |
+
array_push ( $price, $attr [$attributeCode] );
|
258 |
+
$price_flag = true;
|
259 |
+
} else {
|
260 |
+
// get attribute value id
|
261 |
+
$values [static::VALUE] = $attr [$attributeCode];
|
262 |
+
// get attribute value label
|
263 |
+
$productModel = Mage::getModel ( static::CATALOG_PRODUCT )->getResource ()->getAttribute ( $attributeId );
|
264 |
+
$values [static::LABEL] = $productModel->getSource ()->getOptionText ( $attr [$attributeCode] );
|
265 |
+
// get product count
|
266 |
+
$values [static::COUNT] = isset ( $productCount [$attr [$attributeCode]] ) ? $productCount [$attr [$attributeCode]] : 0;
|
267 |
+
$result [] = $values;
|
268 |
+
|
269 |
+
$sort_array [] = $values [static::LABEL];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
}
|
271 |
+
}
|
272 |
+
}
|
273 |
+
|
274 |
+
// Sort the data with mid descending
|
275 |
+
// Add $result as the last parameter, to sort by the common key
|
276 |
+
array_multisort ( $sort_array, SORT_ASC, $result );
|
277 |
+
|
278 |
+
// get minmum and maximum price from price attribute
|
279 |
+
if ($price_flag) {
|
280 |
+
// sort price array
|
281 |
+
sort ( $price );
|
282 |
+
// get minimum price
|
283 |
+
$result [0] [static::VALUE] = number_format ( $price [0], 2, '.', '' );
|
284 |
+
$result [0] [static::LABEL] = 'min_price';
|
285 |
+
$result [0] [static::COUNT] = '';
|
286 |
+
// get maximum price
|
287 |
+
$result [1] [static::VALUE] = number_format ( end ( $price ), 2, '.', '' );
|
288 |
+
$result [1] [static::LABEL] = 'max_price';
|
289 |
+
$result [1] [static::COUNT] = '';
|
290 |
+
}
|
291 |
+
|
292 |
+
return $result;
|
293 |
+
}
|
294 |
+
|
295 |
+
/**
|
296 |
+
*
|
297 |
+
* @param string $key
|
298 |
+
* @param array $data
|
299 |
+
* @return array $data
|
300 |
+
*/
|
301 |
+
public function remove_duplicateKeys($key, $data) {
|
302 |
+
$_data = array ();
|
303 |
+
|
304 |
+
foreach ( $data as $v ) {
|
305 |
+
if (isset ( $_data [$v [$key]] )) {
|
306 |
+
// found duplicate
|
307 |
+
continue;
|
308 |
+
}
|
309 |
+
// remember unique item
|
310 |
+
$_data [$v [$key]] = $v;
|
311 |
+
}
|
312 |
+
// if you need a zero-based array, otheriwse work with $_data
|
313 |
+
return array_values ( $_data );
|
314 |
+
}
|
315 |
}
|
app/code/local/ContusRestapi/HomePageapi/Model/Api2/HomePageapi.php
CHANGED
@@ -27,593 +27,693 @@
|
|
27 |
* @since 1.0
|
28 |
*/
|
29 |
class ContusRestapi_HomePageapi_Model_Api2_HomePageapi extends Mage_Api2_Model_Resource {
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
}
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
// get product id
|
355 |
-
$
|
356 |
-
|
357 |
-
$Products [$j] [static::TYPE_ID] = $product->getTypeId ();
|
358 |
// get product name
|
359 |
-
$
|
360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
if ($imageSize <= 0) {
|
362 |
-
|
363 |
} else {
|
364 |
-
|
365 |
}
|
366 |
-
// get the product final price
|
367 |
-
$Products [$j] [static::REGULARPRICE] = number_format ( $product->getPrice (), 2, '.', '' );
|
368 |
-
$Products [$j] [static::FINALPRICE] = number_format ( $product->getFinalPrice (), 2, '.', '' );
|
369 |
-
$j ++;
|
370 |
-
}
|
371 |
-
return $Products;
|
372 |
-
}
|
373 |
-
/**
|
374 |
-
* Get Categories
|
375 |
-
*
|
376 |
-
* @param int $storeId
|
377 |
-
* @param int $rootCatId
|
378 |
-
*
|
379 |
-
* @return array $curcategory
|
380 |
-
*/
|
381 |
-
public function getCategoryList($storeId, $rootCatId) {
|
382 |
-
// declare empty array
|
383 |
-
$curcategory = array ();
|
384 |
-
|
385 |
-
/**
|
386 |
-
*
|
387 |
-
* @var $categories Mage_Catalog_Model_Category
|
388 |
-
*/
|
389 |
-
$categories = Mage::getModel ( 'catalog/category' )->getCollection ()->setStoreId ( $storeId )->addFieldToFilter ( 'is_active', 1 )->addAttributeToFilter ( 'path', array (
|
390 |
-
'like' => "1/{$rootCatId}/%"
|
391 |
-
) )->addAttributeToSelect ( '*' );
|
392 |
-
$k = 0;
|
393 |
-
foreach ( $categories as $category ) {
|
394 |
-
// get category id
|
395 |
-
$curcategory [$k] ['category_id'] = $category->getId ();
|
396 |
-
// get Category name
|
397 |
-
$curcategory [$k] [static::NAME] = $category->getName ();
|
398 |
|
399 |
-
// get
|
400 |
-
|
401 |
-
$curcategory [$k] [static::IMGURL] = $category->getImageUrl ();
|
402 |
-
} else {
|
403 |
-
$curcategory [$k] [static::IMGURL] = '';
|
404 |
-
}
|
405 |
-
// get category position for sorting
|
406 |
-
$curcategory [$k] ['position'] = $category->getPosition ();
|
407 |
-
// get parent category of current category
|
408 |
-
$curcategory [$k] ['parent_id'] = $category->getParent_id ();
|
409 |
|
410 |
-
//
|
411 |
-
$
|
412 |
-
if ($
|
413 |
-
|
414 |
-
} else {
|
415 |
-
$curcategory [$k] ['is_child'] = false;
|
416 |
}
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
/**
|
423 |
-
* Get Available stores based on website id
|
424 |
-
*
|
425 |
-
* @param int $storeId
|
426 |
-
* @param int $websiteId
|
427 |
-
* @return array $storesArray
|
428 |
-
*/
|
429 |
-
public function getAvailableStores($websiteId) {
|
430 |
-
$storesArray = array ();
|
431 |
-
try {
|
432 |
-
$website = Mage::app ()->getWebsite ( $websiteId );
|
433 |
-
foreach ( $website->getGroups () as $group ) {
|
434 |
-
$stores = $group->getStores ();
|
435 |
-
$l = 0;
|
436 |
-
foreach ( $stores as $store ) {
|
437 |
-
$storesArray [$l] ['store_id'] = $store->getId ();
|
438 |
-
$storesArray [$l] [static::NAME] = $store->getName ();
|
439 |
-
$currency_code = Mage::app ()->getStore ( $store->getId () )->getCurrentCurrencyCode ();
|
440 |
-
$storesArray [$l] ['currency_code'] = $currency_code;
|
441 |
-
$storesArray [$l] ['currency_symbol'] = Mage::app ()->getLocale ()->currency ( $currency_code )->getSymbol ();
|
442 |
-
$l ++;
|
443 |
-
}
|
444 |
}
|
445 |
-
|
446 |
-
$
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
public function getOffers($count) {
|
457 |
-
// Get today date
|
458 |
-
$today_date = Date ( 'Y-m-d' );
|
459 |
-
$model = Mage::getModel ( 'offers/offers' );
|
460 |
-
$collection = $model->getCollection ()->addFieldToFilter ( 'status', '1' )->addFieldToFilter ( 'from_date', array (
|
461 |
-
array (
|
462 |
-
'lteq' => $today_date
|
463 |
-
),
|
464 |
-
array (
|
465 |
-
'from_date',
|
466 |
-
'null' => ''
|
467 |
-
)
|
468 |
-
) )->addFieldToFilter ( 'to_date', array (
|
469 |
-
array (
|
470 |
-
'gteq' => $today_date
|
471 |
-
),
|
472 |
-
array (
|
473 |
-
'to_date',
|
474 |
-
'null' => ''
|
475 |
-
)
|
476 |
-
) )->setOrder ( "offers_id", 'DESC' );
|
477 |
-
$collection->setPageSize ( $count )->setCurPage ( 1 );
|
478 |
-
$i = 0;
|
479 |
-
$OffersList = array ();
|
480 |
-
foreach ( $collection as $offer ) {
|
481 |
-
$offer = $model->load ( $offer->getOffersId () );
|
482 |
-
// get offer id
|
483 |
-
$OffersList [$i] [static::ENTITYID] = $offer->getOffersId ();
|
484 |
-
// get type id as null
|
485 |
-
$OffersList [$i] [static::TYPE_ID] = '';
|
486 |
-
// get offer Title
|
487 |
-
$OffersList [$i] [static::NAME] = $offer->getOfferTitle ();
|
488 |
-
// get Offer image
|
489 |
-
$OffersList [$i] [static::IMGURL] = Mage::getBaseUrl ( 'media' ) . $offer->getOfferImg ();
|
490 |
-
$OffersList [$i] [static::REGULARPRICE] = '';
|
491 |
-
$OffersList [$i] [static::FINALPRICE] = '';
|
492 |
|
493 |
-
$
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
/**
|
500 |
-
* function that is called when post is done **
|
501 |
-
* offer products list
|
502 |
-
*
|
503 |
-
* @param array $data
|
504 |
-
*
|
505 |
-
* @return array json array
|
506 |
-
*/
|
507 |
-
protected function _retrieve() {
|
508 |
-
$response = array ();
|
509 |
-
|
510 |
-
$offerId = ( int ) Mage::app ()->getRequest ()->getParam ( 'offer_id' );
|
511 |
-
|
512 |
-
// get website id from request
|
513 |
-
$websiteId = ( int ) Mage::app ()->getRequest ()->getParam ( static::WEBSITE_ID );
|
514 |
-
if ($websiteId <= 0) {
|
515 |
-
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
516 |
-
}
|
517 |
-
|
518 |
-
// get store id
|
519 |
-
$storeId = ( int ) Mage::app ()->getRequest ()->getParam ( static::STORE_ID );
|
520 |
-
if ($storeId <= 0) {
|
521 |
-
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
522 |
-
}
|
523 |
-
|
524 |
-
// get the offer model
|
525 |
-
$model = Mage::getModel ( 'offers/offers' )->load ( $offerId );
|
526 |
-
|
527 |
-
$response ['offer_title'] = $model ['offer_title'];
|
528 |
-
// get offer products
|
529 |
-
$offer_products = $model->getOfferProducts ();
|
530 |
-
|
531 |
-
// set offer_products data string to array to model
|
532 |
-
if (isset ( $offer_products ) && $offer_products != '') {
|
533 |
-
$offer_products = explode ( ',', $offer_products );
|
534 |
-
}
|
535 |
-
|
536 |
-
$productCollection = $this->offerProductList ( $offer_products, $storeId );
|
537 |
-
|
538 |
-
$response ['success'] = 1;
|
539 |
-
$response ['error'] = false;
|
540 |
-
$response ['total_count'] = count ( $offer_products );
|
541 |
-
$response ['result'] = $productCollection;
|
542 |
-
|
543 |
-
return $response;
|
544 |
-
}
|
545 |
-
|
546 |
-
/**
|
547 |
-
* Get offer products list
|
548 |
-
*
|
549 |
-
* @param array $offer_products
|
550 |
-
* @param int $storeId
|
551 |
-
* @return $offerProdcuts
|
552 |
-
*/
|
553 |
-
public function offerProductList($offer_products, $storeId) {
|
554 |
-
$offerProdcuts = array ();
|
555 |
-
$customerId = ( int ) Mage::app ()->getRequest ()->getParam ( 'customer_id' );
|
556 |
-
// get image size for resize
|
557 |
-
$imageSize = ( int ) $this->getRequest ()->getParam ( 'image_size' );
|
558 |
-
// get page from request
|
559 |
-
$page = ( int ) $this->getRequest ()->getParam ( 'page' );
|
560 |
-
if ($page <= 0) {
|
561 |
-
$page = 1;
|
562 |
-
}
|
563 |
-
// get page from request
|
564 |
-
$limit = ( int ) $this->getRequest ()->getParam ( 'limit' );
|
565 |
-
if ($limit <= 0) {
|
566 |
-
$limit = 10;
|
567 |
-
}
|
568 |
-
$page = ($page - 1) * $limit;
|
569 |
-
// for pagination
|
570 |
-
$offer_products = array_slice ( $offer_products, $page, $limit );
|
571 |
-
|
572 |
-
foreach ( $offer_products as $key => $productid ) {
|
573 |
-
$item = Mage::getModel ( 'catalog/product' )->load ( $productid );
|
574 |
-
$item->setStoreId ( $storeId )->load ( $item->getId () );
|
575 |
-
// get product status
|
576 |
-
$productStatus = $item->getStatus ();
|
577 |
-
// get only enabled products
|
578 |
-
if ($productStatus == 1 && $item->getId () != '') {
|
579 |
-
// get product id
|
580 |
-
$products [static::ENTITYID] = $item->getId ();
|
581 |
-
|
582 |
-
// get product name
|
583 |
-
$products [static::NAME] = $item->getName ();
|
584 |
-
$products [static::TYPE_ID] = $item->getTypeId ();
|
585 |
-
// get the product final price
|
586 |
-
$products [static::REGULARPRICE] = number_format ( $item->getPrice (), 2, '.', '' );
|
587 |
-
$products [static::FINALPRICE] = number_format ( $item->getFinalPrice (), 2, '.', '' );
|
588 |
-
// get product stock details
|
589 |
-
$stockDetail = Mage::getModel ( static::LOGIN_TOKEN )->getStockDetail ( $item );
|
590 |
-
$products ['is_saleable'] = $stockDetail ['is_saleable'];
|
591 |
-
$products ['is_stock'] = $stockDetail ['is_stock'];
|
592 |
-
// get product image
|
593 |
-
if ($imageSize <= 0) {
|
594 |
-
$products [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $item, static::SMALLIMG );
|
595 |
-
} else {
|
596 |
-
$products [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $item, static::SMALLIMG )->constrainOnly ( TRUE )->keepAspectRatio ( TRUE )->keepFrame ( FALSE )->resize ( $imageSize, null );
|
597 |
-
}
|
598 |
-
|
599 |
-
// get rating
|
600 |
-
$products ['summary_rating'] = Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $item->getId (), $storeId ) ? Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $item->getId (), $storeId ) : '0';
|
601 |
-
|
602 |
-
// get wishlisted products by customer
|
603 |
-
$wishListIds = array ();
|
604 |
-
if ($customerId > 0) {
|
605 |
-
$wishListIds = Mage::getModel ( static::LOGIN_TOKEN )->getWishlistByCustomer ( $customerId );
|
606 |
-
}
|
607 |
-
// Check to see the product is in wishlist
|
608 |
-
if (in_array ( $item->getId (), $wishListIds )) {
|
609 |
-
$products ['is_wishlist'] = true;
|
610 |
-
} else {
|
611 |
-
$products ['is_wishlist'] = false;
|
612 |
-
}
|
613 |
-
$offerProdcuts [] = $products;
|
614 |
-
}
|
615 |
-
$i ++;
|
616 |
-
}
|
617 |
-
return $offerProdcuts;
|
618 |
-
}
|
619 |
}
|
27 |
* @since 1.0
|
28 |
*/
|
29 |
class ContusRestapi_HomePageapi_Model_Api2_HomePageapi extends Mage_Api2_Model_Resource {
|
30 |
+
|
31 |
+
// Declaring the string literals variable
|
32 |
+
const ENTITYID = 'entity_id';
|
33 |
+
const NAME = 'name';
|
34 |
+
const IMGURL = 'image_url';
|
35 |
+
const REGULARPRICE = 'regular_price_with_tax';
|
36 |
+
const FINALPRICE = 'final_price_with_tax';
|
37 |
+
const PRODUCTTYPE = 'product_type';
|
38 |
+
const PROCOLLECTION = 'collection';
|
39 |
+
const VISIBILITY = 'visibility';
|
40 |
+
const STATUS = 'status';
|
41 |
+
const CATIMG = 'catalog/image';
|
42 |
+
const SMALLIMG = 'small_image';
|
43 |
+
const TYPE_ID = 'type_id';
|
44 |
+
const OFFER = 'offer';
|
45 |
+
const SETTINGS = 'settings';
|
46 |
+
const BANNER_TYPE = 'banner_type';
|
47 |
+
const LOGIN_TOKEN = 'login/token';
|
48 |
+
const WEBSITE_ID = 'website_id';
|
49 |
+
const STORE_ID = 'store_id';
|
50 |
+
const DETAIL = 'detail';
|
51 |
+
const STOCK_QTY = 'stock_qty';
|
52 |
+
const CONFIGURABLE = 'configurable';
|
53 |
+
const MIN_SALE_QTY = 'min_sale_qty';
|
54 |
+
const MAX_SALE_QTY = 'max_sale_qty';
|
55 |
+
const QTY_INCR = 'qty_increments';
|
56 |
+
const REGEXP = 'regexp';
|
57 |
+
const IS_QTY_DECIMAL = 'is_qty_decimal';
|
58 |
+
const CART_COUNT = 'cart_count';
|
59 |
+
|
60 |
+
/**
|
61 |
+
* function that is called when post is done **
|
62 |
+
* Home page details
|
63 |
+
*
|
64 |
+
* @param array $data
|
65 |
+
*
|
66 |
+
* @return array json array
|
67 |
+
*/
|
68 |
+
protected function _retrieveCollection() {
|
69 |
+
$response = array ();
|
70 |
+
// set page size as 1
|
71 |
+
$page = 1;
|
72 |
+
|
73 |
+
// get website id from request
|
74 |
+
$websiteId = ( int ) Mage::app ()->getRequest ()->getParam ( static::WEBSITE_ID );
|
75 |
+
if ($websiteId <= 0) {
|
76 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
77 |
+
}
|
78 |
+
// get store id from request
|
79 |
+
$storeId = ( int ) Mage::app ()->getRequest ()->getParam ( static::STORE_ID );
|
80 |
+
if ($storeId <= 0) {
|
81 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
82 |
+
}
|
83 |
+
|
84 |
+
// get image size for resize
|
85 |
+
$imageSize = ( int ) Mage::app ()->getRequest ()->getParam ( 'image_size' );
|
86 |
+
|
87 |
+
// get city for filter products
|
88 |
+
$city = ( int ) Mage::app ()->getRequest ()->getParam ( 'city' );
|
89 |
+
|
90 |
+
// get today date
|
91 |
+
$todayDate = Mage::app ()->getLocale ()->date ()->toString ( Varien_Date::DATETIME_INTERNAL_FORMAT );
|
92 |
+
// get these type of products only
|
93 |
+
$productType = array (
|
94 |
+
"simple",
|
95 |
+
"configurable"
|
96 |
+
);
|
97 |
+
|
98 |
+
// get values from system->configuration
|
99 |
+
$response [static::SETTINGS] = $this->getinventoryConfigValues ( $storeId );
|
100 |
+
|
101 |
+
// get cms pages values
|
102 |
+
$response ['cms_pages'] = $this->getcmsPages ( $storeId );
|
103 |
+
|
104 |
+
// Get Categories
|
105 |
+
// get root category for store base
|
106 |
+
$rootCatId = Mage::app ()->getStore ( $storeId )->getRootCategoryId ();
|
107 |
+
$response [static::SETTINGS] ['root_category_id'] = $rootCatId;
|
108 |
+
$response ['categories'] = $this->getCategoryList ( $storeId, $rootCatId );
|
109 |
+
|
110 |
+
// Get new arrival products
|
111 |
+
$limit = 10;
|
112 |
+
$newProdCollection = array ();
|
113 |
+
$newProdCollection = $this->getNewArrivalProducts ( $storeId, $page, $limit, $todayDate, $productType, $imageSize, $city );
|
114 |
+
$response [static::PROCOLLECTION] = $newProdCollection;
|
115 |
+
$collection_type = 'New Arrivals';
|
116 |
+
// get new product count
|
117 |
+
$newProCount = count ( $newProdCollection );
|
118 |
+
|
119 |
+
// Get best selling products
|
120 |
+
if ($newProCount < 3) {
|
121 |
+
$bestSelling = $this->getbestSellingProducts ( $storeId, $page, $limit, $imageSize, $city );
|
122 |
+
$response [static::PROCOLLECTION] = $bestSelling;
|
123 |
+
$collection_type = 'Best Seller';
|
124 |
+
}
|
125 |
+
// get best selling products count
|
126 |
+
$bestProCount = count ( $bestSelling );
|
127 |
+
|
128 |
+
// Get all product collection
|
129 |
+
if ($newProCount < 3 && $bestProCount < 3) {
|
130 |
+
$allProduct = $this->getallProducts ( $storeId, $page, $limit, $productType, $imageSize, $city );
|
131 |
+
$response [static::PROCOLLECTION] = $allProduct;
|
132 |
+
$collection_type = 'All Products';
|
133 |
+
}
|
134 |
+
$response [static::SETTINGS] [static::PRODUCTTYPE] = $collection_type;
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Home page banner - offers module
|
138 |
+
*/
|
139 |
+
$offersCollection = array ();
|
140 |
+
$response [static::OFFER] = array ();
|
141 |
+
$offersCollection = $this->getOffers ( 5, $storeId );
|
142 |
+
$response [static::SETTINGS] [static::BANNER_TYPE] = 'list';
|
143 |
+
$response [static::OFFER] = $offersCollection;
|
144 |
+
|
145 |
+
// Get Available stores based on website id
|
146 |
+
$response ['available_stores'] = $this->getAvailableStores ( $websiteId );
|
147 |
+
$response ['error'] = false;
|
148 |
+
$response ['success'] = 1;
|
149 |
+
return json_encode ( $response );
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Get configuration values
|
154 |
+
*
|
155 |
+
* @param int $storeId
|
156 |
+
*/
|
157 |
+
public function getinventoryConfigValues($storeId) {
|
158 |
+
$result = array ();
|
159 |
+
// get display cart products count in header
|
160 |
+
// get this value from system->configuration->Sales->Checkout->My Cart Lik ->Display Cart Summary
|
161 |
+
$cartLink = Mage::getStoreConfig ( 'checkout/cart_link/use_qty', $storeId );
|
162 |
+
if ($cartLink) {
|
163 |
+
$result [static::CART_COUNT] = 'items_qty';
|
164 |
+
} else {
|
165 |
+
$result [static::CART_COUNT] = 'items_count';
|
166 |
+
}
|
167 |
+
// get inventory maintanance settings
|
168 |
+
// get this value from system->configuration->Catalog->Inventory-> Product Stock Options
|
169 |
+
$result ['manage_stock'] = Mage::getStoreConfig ( 'cataloginventory/item_options/manage_stock', $storeId );
|
170 |
+
$result ['backorders'] = Mage::getStoreConfig ( 'cataloginventory/item_options/backorders', $storeId );
|
171 |
+
// ==> 0 No back orders. Product Qty <= 0 - No proceed ( This product is currently out of stock.)
|
172 |
+
// ==>1 allow qty below 0. Product Qty <= 0 - proceed (no message)
|
173 |
+
// ==>2 allow and notify. Product Qty <= 0 - proceed (This product is not available in the requested quantity. 3 of the items will be backordered.)
|
174 |
+
|
175 |
+
return $result;
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Get cms pages
|
180 |
+
*
|
181 |
+
* @param int $storeId
|
182 |
+
*/
|
183 |
+
public function getcmsPages($storeId) {
|
184 |
+
$result = array ();
|
185 |
+
$cms_enabled = Mage::getStoreConfig ( 'contus/configuration_cms/cms_pages_enabled', $storeId );
|
186 |
+
if ($cms_enabled) {
|
187 |
+
$result ['about_us'] = Mage::getStoreConfig ( 'contus/configuration_cms/about_us', $storeId );
|
188 |
+
$result ['contact_us'] = Mage::getStoreConfig ( 'contus/configuration_cms/contact_us', $storeId );
|
189 |
+
$result ['terms_condition'] = Mage::getStoreConfig ( 'contus/configuration_cms/terms_condition', $storeId );
|
190 |
+
$result ['privacy_policy'] = Mage::getStoreConfig ( 'contus/configuration_cms/privacy_policy', $storeId );
|
191 |
+
$result ['customer_service'] = Mage::getStoreConfig ( 'contus/configuration_cms/customer_service', $storeId );
|
192 |
+
}
|
193 |
+
return $result;
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Get Special offerd Products
|
198 |
+
*
|
199 |
+
* @param int $page
|
200 |
+
* @param int $storeId
|
201 |
+
* @param int $limit
|
202 |
+
*
|
203 |
+
* @param date $todayDate
|
204 |
+
* @return array $offerProducts
|
205 |
+
*/
|
206 |
+
public function getOfferedProducts($storeId, $page, $limit, $todayDate, $productType, $imageSize) {
|
207 |
+
$_productCollection = Mage::getResourceModel ( 'catalog/product_collection' );
|
208 |
+
$_productCollection->setStoreId ( $storeId );
|
209 |
+
|
210 |
+
$_productCollection->addAttributeToFilter ( 'special_from_date', array (
|
211 |
+
'date' => true,
|
212 |
+
'to' => $todayDate
|
213 |
+
) )->addAttributeToFilter ( static::TYPE_ID, array (
|
214 |
+
'in' => $productType
|
215 |
+
) )->
|
216 |
|
217 |
+
addAttributeToFilter ( 'special_to_date', array (
|
218 |
+
'or' => array (
|
219 |
+
|
220 |
+
0 => array (
|
221 |
+
'date' => true,
|
222 |
+
'from' => $todayDate
|
223 |
+
),
|
224 |
+
|
225 |
+
1 => array (
|
226 |
+
'is' => new Zend_Db_Expr ( 'null' )
|
227 |
+
)
|
228 |
+
)
|
229 |
+
), 'left' )->
|
230 |
|
231 |
+
addAttributeToSort ( 'special_price', 'asc' );
|
232 |
+
$_productCollection->addAttributeToFilter ( static::VISIBILITY, array (
|
233 |
+
'neq' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
|
234 |
+
) )->addAttributeToFilter ( static::STATUS, array (
|
235 |
+
'eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED
|
236 |
+
) );
|
237 |
+
$_productCollection->addAttributeToFilter ( 'special_price', array (
|
238 |
+
'neq' => '0'
|
239 |
+
) );
|
240 |
+
$_productCollection->addStoreFilter ( $storeId );
|
241 |
+
$_productCollection->setPage ( $page, $limit );
|
242 |
+
|
243 |
+
$offerProducts = array ();
|
244 |
+
$i = 0;
|
245 |
+
|
246 |
+
foreach ( $_productCollection as $item ) {
|
247 |
+
$item->setStoreId ( $storeId )->load ( $item->getId () );
|
248 |
+
// get product id
|
249 |
+
$offerProducts [$i] [static::ENTITYID] = $item->getId ();
|
250 |
+
// get type id
|
251 |
+
$offerProducts [$i] [static::TYPE_ID] = $item->getTypeId ();
|
252 |
+
// get product name
|
253 |
+
$offerProducts [$i] [static::NAME] = $item->getName ();
|
254 |
+
// get product small image
|
255 |
+
if ($imageSize <= 0) {
|
256 |
+
$offerProducts [$i] [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $item, static::SMALLIMG );
|
257 |
+
} else {
|
258 |
+
$offerProducts [$i] [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $item, static::SMALLIMG )->constrainOnly ( TRUE )->keepAspectRatio ( TRUE )->keepFrame ( FALSE )->resize ( $imageSize, null );
|
259 |
+
}
|
260 |
+
// get the product final price
|
261 |
+
$offerProducts [$i] [static::REGULARPRICE] = number_format ( $item->getPrice (), 2, '.', '' );
|
262 |
+
$offerProducts [$i] [static::FINALPRICE] = number_format ( $item->getFinalPrice (), 2, '.', '' );
|
263 |
+
$i ++;
|
264 |
+
}
|
265 |
+
|
266 |
+
return $offerProducts;
|
267 |
+
}
|
268 |
+
|
269 |
+
/**
|
270 |
+
* Get new arrival products
|
271 |
+
* Based on news_from_date attribute
|
272 |
+
*
|
273 |
+
* @param int $storeId
|
274 |
+
* @param int $page
|
275 |
+
* @param $limit 10
|
276 |
+
* @param date $todayDate
|
277 |
+
* @return array $newProducts
|
278 |
+
*/
|
279 |
+
public function getNewArrivalProducts($storeId, $page, $limit, $todayDate, $productType, $imageSize, $city) {
|
280 |
+
$collection = Mage::getResourceModel ( 'catalog/product_collection' );
|
281 |
+
$collection->setStoreId ( $storeId );
|
282 |
+
|
283 |
+
$collection->addAttributeToFilter ( static::TYPE_ID, array (
|
284 |
+
'in' => $productType
|
285 |
+
) )->addAttributeToFilter ( 'news_from_date', array (
|
286 |
+
'date' => true,
|
287 |
+
'to' => $todayDate
|
288 |
+
) )->addAttributeToFilter ( 'news_to_date', array (
|
289 |
+
'or' => array (
|
290 |
+
|
291 |
+
0 => array (
|
292 |
+
'date' => true,
|
293 |
+
'from' => $todayDate
|
294 |
+
),
|
295 |
+
|
296 |
+
1 => array (
|
297 |
+
'is' => new Zend_Db_Expr ( 'null' )
|
298 |
+
)
|
299 |
+
)
|
300 |
+
), 'left' );
|
301 |
+
// Filter products by city
|
302 |
+
if ($city) {
|
303 |
+
$collection->addFieldToFilter ( 'city', array (
|
304 |
+
array (
|
305 |
+
static::REGEXP => $city
|
306 |
+
)
|
307 |
+
) );
|
308 |
+
}
|
309 |
+
$collection->addAttributeToSort ( 'news_from_date', 'desc' );
|
310 |
+
$collection->addAttributeToFilter ( static::VISIBILITY, array (
|
311 |
+
'neq' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
|
312 |
+
) )->addAttributeToFilter ( static::STATUS, array (
|
313 |
+
'eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED
|
314 |
+
) );
|
315 |
+
$collection->addStoreFilter ( $storeId );
|
316 |
+
$collection->setPage ( $page, $limit );
|
317 |
+
|
318 |
+
return $this->getProductDetail ( $collection, $storeId, $imageSize );
|
319 |
+
}
|
320 |
+
|
321 |
+
/**
|
322 |
+
* Get best selling products
|
323 |
+
*
|
324 |
+
* @param int $storeId
|
325 |
+
* @param int $page
|
326 |
+
* @param $limit 10
|
327 |
+
* @return array $bestProducts
|
328 |
+
*/
|
329 |
+
public function getbestSellingProducts($storeId, $page, $limit, $imageSize, $city) {
|
330 |
+
$visibility = array (
|
331 |
+
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
|
332 |
+
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
|
333 |
+
);
|
334 |
+
|
335 |
+
$productType [0] = 'simple';
|
336 |
+
|
337 |
+
$_productCollection = Mage::getResourceModel ( 'reports/product_collection' )->addAttributeToSelect ( '*' )->addOrderedQty ()->addAttributeToFilter ( static::VISIBILITY, $visibility )->addAttributeToFilter ( static::STATUS, array (
|
338 |
+
'eq' => '1'
|
339 |
+
) )->addAttributeToFilter ( static::TYPE_ID, array (
|
340 |
+
'in' => $productType
|
341 |
+
) )->addStoreFilter ( $storeId );
|
342 |
+
// Filter products by city
|
343 |
+
if ($city) {
|
344 |
+
$_productCollection->addFieldToFilter ( 'city', array (
|
345 |
+
array (
|
346 |
+
static::REGEXP => $city
|
347 |
+
)
|
348 |
+
) );
|
349 |
+
}
|
350 |
+
$_productCollection->setPage ( $page, $limit )->setOrder ( 'ordered_qty', 'desc' );
|
351 |
+
|
352 |
+
return $this->getProductDetail ( $_productCollection, $storeId, $imageSize );
|
353 |
+
}
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Get Most viewed products
|
357 |
+
*
|
358 |
+
* @param int $storeId
|
359 |
+
* @param int $page
|
360 |
+
* @param $limit 10
|
361 |
+
* @return array $mostViewProducts
|
362 |
+
*/
|
363 |
+
public function geMostViewProducts($storeId, $page, $limit, $productType, $imageSize, $city) {
|
364 |
+
$visibility = array (
|
365 |
+
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
|
366 |
+
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
|
367 |
+
);
|
368 |
+
$_productCollection = Mage::getResourceModel ( 'reports/product_collection' )->addAttributeToSelect ( '*' )->setStoreId ( $storeId )->addStoreFilter ( $storeId )->addAttributeToFilter ( static::VISIBILITY, $visibility )->addAttributeToFilter ( static::STATUS, array (
|
369 |
+
'eq' => '1'
|
370 |
+
) )->addAttributeToFilter ( static::TYPE_ID, array (
|
371 |
+
'in' => $productType
|
372 |
+
) )->addViewsCount ()->addStoreFilter ( $storeId )->setPage ( $page, $limit );
|
373 |
+
|
374 |
+
return $this->getProductDetail ( $_productCollection, $storeId, $imageSize );
|
375 |
+
}
|
376 |
+
|
377 |
+
/**
|
378 |
+
* Get all products collection
|
379 |
+
*
|
380 |
+
* @param int $storeId
|
381 |
+
* @param int $page
|
382 |
+
* @param $limit 10
|
383 |
+
* @return array $productColl
|
384 |
+
*/
|
385 |
+
public function getallProducts($storeId, $page, $limit, $productType, $imageSize, $city) {
|
386 |
+
$visibility = array (
|
387 |
+
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
|
388 |
+
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
|
389 |
+
);
|
390 |
+
$collection = Mage::getModel ( 'catalog/product' )->getCollection ()->addAttributeToSelect ( array (
|
391 |
+
'*'
|
392 |
+
) )->addAttributeToFilter ( static::STATUS, array (
|
393 |
+
'eq' => '1'
|
394 |
+
) )->addAttributeToFilter ( static::TYPE_ID, array (
|
395 |
+
'in' => $productType
|
396 |
+
) )->addAttributeToFilter ( static::VISIBILITY, $visibility )->setStoreId ( $storeId );
|
397 |
+
// Filter products by city
|
398 |
+
if ($city) {
|
399 |
+
$collection->addFieldToFilter ( 'city', array (
|
400 |
+
array (
|
401 |
+
static::REGEXP => $city
|
402 |
+
)
|
403 |
+
) );
|
404 |
+
}
|
405 |
+
$collection->addStoreFilter ( $storeId )->setPage ( $page, $limit )->addAttributeToSort ( 'created_at', 'desc' );
|
406 |
+
|
407 |
+
return $this->getProductDetail ( $collection, $storeId, $imageSize );
|
408 |
+
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
* Get Product details
|
412 |
+
*
|
413 |
+
* @param array $collection
|
414 |
+
* @param int $storeId
|
415 |
+
* @param int $imageSize
|
416 |
+
* @return $Products
|
417 |
+
*/
|
418 |
+
public function getProductDetail($collection, $storeId, $imageSize) {
|
419 |
+
$Products = array ();
|
420 |
+
$j = 0;
|
421 |
+
foreach ( $collection as $product ) {
|
422 |
+
$product->setStoreId ( $storeId )->load ( $product->getId () );
|
423 |
+
// get product id
|
424 |
+
$Products [$j] [static::ENTITYID] = $product->getId ();
|
425 |
+
// get type id
|
426 |
+
$Products [$j] [static::TYPE_ID] = $product->getTypeId ();
|
427 |
+
// get product name
|
428 |
+
$Products [$j] [static::NAME] = $product->getName ();
|
429 |
+
// get product small image
|
430 |
+
if ($imageSize <= 0) {
|
431 |
+
$Products [$j] [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, static::SMALLIMG );
|
432 |
+
} else {
|
433 |
+
$Products [$j] [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, static::SMALLIMG )->constrainOnly ( TRUE )->keepAspectRatio ( TRUE )->keepFrame ( FALSE )->resize ( $imageSize, null );
|
434 |
+
}
|
435 |
+
// get the product final price
|
436 |
+
$Products [$j] [static::REGULARPRICE] = number_format ( $product->getPrice (), 2, '.', '' );
|
437 |
+
$Products [$j] [static::FINALPRICE] = number_format ( $product->getFinalPrice (), 2, '.', '' );
|
438 |
+
|
439 |
+
// get product stock details
|
440 |
+
$inventoryDetail = Mage::getModel ( 'login/methods_functions' )->getinventoryDetail ( $product, $storeId );
|
441 |
+
$Products [$j] [static::STOCK_QTY] = $inventoryDetail [static::STOCK_QTY];
|
442 |
+
$Products [$j] [static::MIN_SALE_QTY] = $inventoryDetail [static::MIN_SALE_QTY];
|
443 |
+
$Products [$j] [static::MAX_SALE_QTY] = $inventoryDetail [static::MAX_SALE_QTY];
|
444 |
+
$Products [$j] [static::QTY_INCR] = $inventoryDetail [static::QTY_INCR];
|
445 |
+
$Products [$j] [static::IS_QTY_DECIMAL] = $inventoryDetail [static::IS_QTY_DECIMAL];
|
446 |
+
|
447 |
+
$j ++;
|
448 |
+
}
|
449 |
+
return $Products;
|
450 |
+
}
|
451 |
+
/**
|
452 |
+
* Get Categories
|
453 |
+
*
|
454 |
+
* @param int $storeId
|
455 |
+
* @param int $rootCatId
|
456 |
+
*
|
457 |
+
* @return array $curcategory
|
458 |
+
*/
|
459 |
+
public function getCategoryList($storeId, $rootCatId) {
|
460 |
+
// declare empty array
|
461 |
+
$curcategory = array ();
|
462 |
+
|
463 |
+
/**
|
464 |
+
*
|
465 |
+
* @var $categories Mage_Catalog_Model_Category
|
466 |
+
*/
|
467 |
+
$categories = Mage::getModel ( 'catalog/category' )->getCollection ()->setStoreId ( $storeId )->addFieldToFilter ( 'is_active', 1 )->addAttributeToFilter ( 'path', array (
|
468 |
+
'like' => "1/{$rootCatId}/%"
|
469 |
+
) )->addAttributeToSelect ( '*' );
|
470 |
+
$k = 0;
|
471 |
+
foreach ( $categories as $category ) {
|
472 |
+
// get category id
|
473 |
+
$curcategory [$k] ['category_id'] = $category->getId ();
|
474 |
+
// get Category name
|
475 |
+
$curcategory [$k] [static::NAME] = $category->getName ();
|
476 |
+
|
477 |
+
// get image url
|
478 |
+
if ($category->getImageUrl () != '') {
|
479 |
+
$curcategory [$k] [static::IMGURL] = $category->getImageUrl ();
|
480 |
+
} else {
|
481 |
+
$curcategory [$k] [static::IMGURL] = '';
|
482 |
+
}
|
483 |
+
// get category position for sorting
|
484 |
+
$curcategory [$k] ['position'] = $category->getPosition ();
|
485 |
+
// get parent category of current category
|
486 |
+
$curcategory [$k] ['parent_id'] = $category->getParent_id ();
|
487 |
+
|
488 |
+
// check category has sub category or not
|
489 |
+
$subCategory = $category->getChildren ();
|
490 |
+
if ($subCategory != "") {
|
491 |
+
$curcategory [$k] ['is_child'] = true;
|
492 |
+
} else {
|
493 |
+
$curcategory [$k] ['is_child'] = false;
|
494 |
+
}
|
495 |
+
$k ++;
|
496 |
+
}
|
497 |
+
return $curcategory;
|
498 |
+
}
|
499 |
+
|
500 |
+
/**
|
501 |
+
* Get Available stores based on website id
|
502 |
+
*
|
503 |
+
* @param int $storeId
|
504 |
+
* @param int $websiteId
|
505 |
+
* @return array $storesArray
|
506 |
+
*/
|
507 |
+
public function getAvailableStores($websiteId) {
|
508 |
+
$storesArray = array ();
|
509 |
+
try {
|
510 |
+
$website = Mage::app ()->getWebsite ( $websiteId );
|
511 |
+
foreach ( $website->getGroups () as $group ) {
|
512 |
+
$stores = $group->getStores ();
|
513 |
+
$l = 0;
|
514 |
+
foreach ( $stores as $store ) {
|
515 |
+
$storesArray [$l] [static::STORE_ID] = $store->getId ();
|
516 |
+
$storesArray [$l] [static::NAME] = $store->getName ();
|
517 |
+
$currency_code = Mage::app ()->getStore ( $store->getId () )->getCurrentCurrencyCode ();
|
518 |
+
$storesArray [$l] ['currency_code'] = $currency_code;
|
519 |
+
$storesArray [$l] ['currency_symbol'] = Mage::app ()->getLocale ()->currency ( $currency_code )->getSymbol ();
|
520 |
+
$l ++;
|
521 |
}
|
522 |
+
}
|
523 |
+
} catch ( Exception $e ) {
|
524 |
+
$e->getMessage ();
|
525 |
+
}
|
526 |
+
return $storesArray;
|
527 |
+
}
|
528 |
+
|
529 |
+
/**
|
530 |
+
* Get offers list
|
531 |
+
*
|
532 |
+
* @return array $OffersList
|
533 |
+
*/
|
534 |
+
public function getOffers($count, $storeId) {
|
535 |
+
// Get today date
|
536 |
+
$today_date = Date ( 'Y-m-d' );
|
537 |
+
$model = Mage::getModel ( 'offers/offers' );
|
538 |
+
$collection = $model->getCollection ()->addFieldToFilter ( 'status', '1' )->addFieldToFilter ( 'from_date', array (
|
539 |
+
array (
|
540 |
+
'lteq' => $today_date
|
541 |
+
),
|
542 |
+
array (
|
543 |
+
'from_date',
|
544 |
+
'null' => ''
|
545 |
+
)
|
546 |
+
) )->addFieldToFilter ( 'to_date', array (
|
547 |
+
array (
|
548 |
+
'gteq' => $today_date
|
549 |
+
),
|
550 |
+
array (
|
551 |
+
'to_date',
|
552 |
+
'null' => ''
|
553 |
+
)
|
554 |
+
) )->addFieldToFilter ( static::STORE_ID, array (
|
555 |
+
array (
|
556 |
+
static::REGEXP => $storeId
|
557 |
+
),
|
558 |
+
array (
|
559 |
+
'eq' => '0'
|
560 |
+
)
|
561 |
+
) )->setOrder ( "offers_id", 'DESC' );
|
562 |
+
$collection->setPageSize ( $count )->setCurPage ( 1 );
|
563 |
+
$i = 0;
|
564 |
+
$OffersList = array ();
|
565 |
+
foreach ( $collection as $offer ) {
|
566 |
+
$offer = $model->load ( $offer->getOffersId () );
|
567 |
+
// get offer id
|
568 |
+
$OffersList [$i] [static::ENTITYID] = $offer->getOffersId ();
|
569 |
+
// get type id as null
|
570 |
+
$OffersList [$i] [static::TYPE_ID] = '';
|
571 |
+
// get offer Title
|
572 |
+
$OffersList [$i] [static::NAME] = $offer->getOfferTitle ();
|
573 |
+
// get Offer image
|
574 |
+
$OffersList [$i] [static::IMGURL] = Mage::getBaseUrl ( 'media' ) . $offer->getOfferImg ();
|
575 |
+
$OffersList [$i] [static::REGULARPRICE] = '';
|
576 |
+
$OffersList [$i] [static::FINALPRICE] = '';
|
577 |
+
|
578 |
+
$i ++;
|
579 |
+
}
|
580 |
+
|
581 |
+
return $OffersList;
|
582 |
+
}
|
583 |
+
|
584 |
+
/**
|
585 |
+
* function that is called when post is done **
|
586 |
+
* offer products list
|
587 |
+
*
|
588 |
+
* @param array $data
|
589 |
+
*
|
590 |
+
* @return array json array
|
591 |
+
*/
|
592 |
+
protected function _retrieve() {
|
593 |
+
$response = array ();
|
594 |
+
|
595 |
+
$offerId = ( int ) Mage::app ()->getRequest ()->getParam ( 'offer_id' );
|
596 |
+
|
597 |
+
// get website id from request
|
598 |
+
$websiteId = ( int ) Mage::app ()->getRequest ()->getParam ( static::WEBSITE_ID );
|
599 |
+
if ($websiteId <= 0) {
|
600 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
601 |
+
}
|
602 |
+
|
603 |
+
// get store id
|
604 |
+
$storeId = ( int ) Mage::app ()->getRequest ()->getParam ( static::STORE_ID );
|
605 |
+
if ($storeId <= 0) {
|
606 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
607 |
+
}
|
608 |
+
|
609 |
+
// get the offer model
|
610 |
+
$model = Mage::getModel ( 'offers/offers' )->load ( $offerId );
|
611 |
+
|
612 |
+
$response ['offer_title'] = $model ['offer_title'];
|
613 |
+
// get offer products
|
614 |
+
$offer_products = $model->getOfferProducts ();
|
615 |
+
|
616 |
+
// set offer_products data string to array to model
|
617 |
+
if (isset ( $offer_products ) && $offer_products != '') {
|
618 |
+
$offer_products = explode ( ',', $offer_products );
|
619 |
+
$totalProducts = count ( $offer_products );
|
620 |
+
} else {
|
621 |
+
$totalProducts = 0;
|
622 |
+
}
|
623 |
+
|
624 |
+
$productCollection = $this->offerProductList ( $offer_products, $storeId );
|
625 |
+
|
626 |
+
$response ['success'] = 1;
|
627 |
+
$response ['error'] = false;
|
628 |
+
$response ['total_count'] = $totalProducts;
|
629 |
+
$response ['result'] = $productCollection;
|
630 |
+
|
631 |
+
return $response;
|
632 |
+
}
|
633 |
+
|
634 |
+
/**
|
635 |
+
* Get offer products list
|
636 |
+
*
|
637 |
+
* @param array $offer_products
|
638 |
+
* @param int $storeId
|
639 |
+
* @return $offerProdcuts
|
640 |
+
*/
|
641 |
+
public function offerProductList($offer_products, $storeId) {
|
642 |
+
$offerProdcuts = array ();
|
643 |
+
$customerId = ( int ) Mage::app ()->getRequest ()->getParam ( 'customer_id' );
|
644 |
+
// get image size for resize
|
645 |
+
$imageSize = ( int ) $this->getRequest ()->getParam ( 'image_size' );
|
646 |
+
// get page from request
|
647 |
+
$page = ( int ) $this->getRequest ()->getParam ( 'page' );
|
648 |
+
if ($page <= 0) {
|
649 |
+
$page = 1;
|
650 |
+
}
|
651 |
+
// get page from request
|
652 |
+
$limit = ( int ) $this->getRequest ()->getParam ( 'limit' );
|
653 |
+
if ($limit <= 0) {
|
654 |
+
$limit = 10;
|
655 |
+
}
|
656 |
+
$page = ($page - 1) * $limit;
|
657 |
+
// for pagination
|
658 |
+
$offer_products = array_slice ( $offer_products, $page, $limit );
|
659 |
+
|
660 |
+
foreach ( $offer_products as $productid ) {
|
661 |
+
$item = Mage::getModel ( 'catalog/product' )->load ( $productid );
|
662 |
+
$item->setStoreId ( $storeId )->load ( $item->getId () );
|
663 |
+
// get product status
|
664 |
+
$productStatus = $item->getStatus ();
|
665 |
+
// get only enabled products
|
666 |
+
if ($productStatus == 1 && $item->getId () != '') {
|
667 |
// get product id
|
668 |
+
$products [static::ENTITYID] = $item->getId ();
|
669 |
+
|
|
|
670 |
// get product name
|
671 |
+
$products [static::NAME] = $item->getName ();
|
672 |
+
$products [static::TYPE_ID] = $item->getTypeId ();
|
673 |
+
// get the product final price
|
674 |
+
$products [static::REGULARPRICE] = number_format ( $item->getPrice (), 2, '.', '' );
|
675 |
+
$products [static::FINALPRICE] = number_format ( $item->getFinalPrice (), 2, '.', '' );
|
676 |
+
// get product stock details
|
677 |
+
$stockDetail = Mage::getModel ( static::LOGIN_TOKEN )->getStockDetail ( $item );
|
678 |
+
$products ['is_saleable'] = $stockDetail ['is_saleable'];
|
679 |
+
$products ['is_stock'] = $stockDetail ['is_stock'];
|
680 |
+
// get product image
|
681 |
if ($imageSize <= 0) {
|
682 |
+
$products [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $item, static::SMALLIMG );
|
683 |
} else {
|
684 |
+
$products [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $item, static::SMALLIMG )->constrainOnly ( TRUE )->keepAspectRatio ( TRUE )->keepFrame ( FALSE )->resize ( $imageSize, null );
|
685 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
686 |
|
687 |
+
// get rating
|
688 |
+
$products ['summary_rating'] = Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $item->getId (), $storeId ) ? Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $item->getId (), $storeId ) : '0';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
689 |
|
690 |
+
// get wishlisted products by customer
|
691 |
+
$wishListIds = array ();
|
692 |
+
if ($customerId > 0) {
|
693 |
+
$wishListIds = Mage::getModel ( static::LOGIN_TOKEN )->getWishlistByCustomer ( $customerId );
|
|
|
|
|
694 |
}
|
695 |
+
// Check to see the product is in wishlist
|
696 |
+
if (in_array ( $item->getId (), $wishListIds )) {
|
697 |
+
$products ['is_wishlist'] = true;
|
698 |
+
} else {
|
699 |
+
$products ['is_wishlist'] = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
700 |
}
|
701 |
+
// get product stock details
|
702 |
+
$inventoryDetail = Mage::getModel ( 'login/methods_functions' )->getinventoryDetail ( $item, $storeId );
|
703 |
+
// get stock available qty
|
704 |
+
$products [static::STOCK_QTY] = $inventoryDetail [static::STOCK_QTY];
|
705 |
+
// get product minimum qty allowed to cart
|
706 |
+
$products [static::MIN_SALE_QTY] = $inventoryDetail [static::MIN_SALE_QTY];
|
707 |
+
// get product maximm qty allowed to cart
|
708 |
+
$products [static::MAX_SALE_QTY] = $inventoryDetail [static::MAX_SALE_QTY];
|
709 |
+
// get product increment qty allowed to cart
|
710 |
+
$products [static::QTY_INCR] = $inventoryDetail [static::QTY_INCR];
|
711 |
+
$products [static::IS_QTY_DECIMAL] = $inventoryDetail [static::IS_QTY_DECIMAL];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
712 |
|
713 |
+
$offerProdcuts [] = $products;
|
714 |
+
}
|
715 |
+
$i ++;
|
716 |
+
}
|
717 |
+
return $offerProdcuts;
|
718 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
719 |
}
|
app/code/local/ContusRestapi/HomePageapi/etc/api2.xml
CHANGED
@@ -44,6 +44,7 @@
|
|
44 |
<total_count>Total products</total_count>
|
45 |
<error>Error</error>
|
46 |
<Offer_title>Offer Title</Offer_title>
|
|
|
47 |
</attributes>
|
48 |
<routes>
|
49 |
<route_collection>
|
44 |
<total_count>Total products</total_count>
|
45 |
<error>Error</error>
|
46 |
<Offer_title>Offer Title</Offer_title>
|
47 |
+
<city>City</city>
|
48 |
</attributes>
|
49 |
<routes>
|
50 |
<route_collection>
|
app/code/local/ContusRestapi/Login/Model/Methods/Functions.php
CHANGED
@@ -29,124 +29,306 @@
|
|
29 |
* @since 1.0
|
30 |
*/
|
31 |
class ContusRestapi_Login_Model_Methods_Functions extends Mage_Core_Model_Abstract {
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
$message = $e->getMessage ();
|
71 |
}
|
72 |
-
|
|
|
|
|
|
|
73 |
$success = 0;
|
74 |
-
$message =
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
}
|
106 |
-
|
107 |
-
|
108 |
-
}
|
109 |
-
public function getPayments($_code, $payment_model) {
|
110 |
-
$_title = Mage::getStoreConfig ( 'payment/' . $_code . '/title' );
|
111 |
-
if (strtoupper ( $_code ) == 'PAYPAL_EXPRESS' || strtoupper ( $_code ) == 'PAYPAL_DIRECT' || strtoupper ( $_code ) == 'PAYPAL_STANDARD' || strtoupper ( $_code ) == 'PAYPALUK_DIRECT' || strtoupper ( $_code ) == 'PAYPALUK_EXPRESS') {
|
112 |
-
$paymentMethods ['code'] = 'paypal_standard';
|
113 |
-
} else {
|
114 |
-
$paymentMethods ['code'] = $_code;
|
115 |
-
}
|
116 |
-
|
117 |
-
$paymentMethods [static::TITLE] = $_title;
|
118 |
-
|
119 |
-
$ccTypes = explode ( ',', $payment_model->getConfigData ( 'cctypes' ) );
|
120 |
-
$aType = Mage::getSingleton ( 'payment/config' )->getCcTypes ();
|
121 |
-
$cc = array ();
|
122 |
-
$i = 0;
|
123 |
-
foreach ( $ccTypes as $cctype ) {
|
124 |
-
if ($cctype != '') {
|
125 |
-
$cc [$i] ['card_code'] = $cctype;
|
126 |
-
$cc [$i] ['card_name'] = $aType [$cctype];
|
127 |
-
|
128 |
-
$i ++;
|
129 |
}
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
$tokenObj = Mage::getModel ( 'login/token' )->load ( $customerId, 'userid' );
|
145 |
-
$tokenObj->setUserid ( $customerId );
|
146 |
-
$tokenObj->setDevicetoken ( $deviceToken );
|
147 |
-
$tokenObj->setDevicetype ( $deviceType );
|
148 |
-
$tokenObj->save ();
|
149 |
-
}
|
150 |
-
|
151 |
-
|
152 |
}
|
29 |
* @since 1.0
|
30 |
*/
|
31 |
class ContusRestapi_Login_Model_Methods_Functions extends Mage_Core_Model_Abstract {
|
32 |
+
const SLAES_QUOTE = 'sales/quote';
|
33 |
+
const RESULT = 'result';
|
34 |
+
const MESSAGE = 'message';
|
35 |
+
const DETAILS = 'details';
|
36 |
+
const TITLE = 'title';
|
37 |
+
const STOREID = 'store_id';
|
38 |
+
const SELLER_ID = 'seller_id';
|
39 |
+
const STATUS = 'status';
|
40 |
+
const COUNTRY = 'country';
|
41 |
+
const MARKETPLACE_SELLERREVIEW = 'marketplace/sellerreview';
|
42 |
+
const STOCK_QTY = 'stock_qty';
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Get active shipping methods and payment methods
|
46 |
+
*
|
47 |
+
* @param int $quoteId
|
48 |
+
* @param int $storeId
|
49 |
+
* @return array $response
|
50 |
+
*/
|
51 |
+
public function getShippingPaymentMethods($quoteId, $storeId) {
|
52 |
+
$response = array ();
|
53 |
+
$shippings = array ();
|
54 |
+
if ($quoteId) {
|
55 |
+
try {
|
56 |
+
$quote = Mage::getModel ( static::SLAES_QUOTE )->loadByIdWithoutStore ( $quoteId );
|
57 |
+
$shippingMethods = Mage::getModel ( 'checkout/cart_shipping_api' )->getShippingMethodsList ( $quoteId, $storeId );
|
58 |
+
$i = 0;
|
59 |
+
foreach ( $shippingMethods as $shipping ) {
|
60 |
+
$shippings [$i] ['carrier'] = $shipping ['carrier'];
|
61 |
+
$shippings [$i] ['carrier_title'] = $shipping ['carrier_title'];
|
62 |
+
$shippings [$i] ['code'] = $shipping ['code'];
|
63 |
+
$shippings [$i] ['method'] = $shipping ['method'];
|
64 |
+
$shippings [$i] ['method_description'] = $shipping ['method_description'];
|
65 |
+
$shippings [$i] ['price'] = number_format ( $shipping ['price'], 2, '.', '' );
|
66 |
+
$shippings [$i] ['error_message'] = $shipping ['error_message'];
|
67 |
+
$shippings [$i] ['method_title'] = $shipping ['method_title'];
|
68 |
+
$shippings [$i] ['carrierName'] = $shipping ['carrierName'];
|
69 |
+
$i ++;
|
|
|
70 |
}
|
71 |
+
$payMentMethods = $this->getActivPaymentMethods ( $quote );
|
72 |
+
$success = 1;
|
73 |
+
$message = "Get shipping and payment methods successfully.";
|
74 |
+
} catch ( Exception $e ) {
|
75 |
$success = 0;
|
76 |
+
$message = $e->getMessage ();
|
77 |
+
}
|
78 |
+
} else {
|
79 |
+
$success = 0;
|
80 |
+
$message = "Quote id not exist.";
|
81 |
+
}
|
82 |
+
$response ['success'] = $success;
|
83 |
+
$response [static::MESSAGE] = $message;
|
84 |
+
$response ['shipping_methods'] = $shippings;
|
85 |
+
$response ['payment_methods'] = $payMentMethods;
|
86 |
+
return $response;
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Get active payment methods
|
91 |
+
*
|
92 |
+
* @param object $quote
|
93 |
+
* @return $result
|
94 |
+
*/
|
95 |
+
public function getActivPaymentMethods($quote) {
|
96 |
+
$total = $quote->getBaseSubtotal ();
|
97 |
+
$active_methods = Mage::getSingleton ( 'payment/config' )->getActiveMethods ();
|
98 |
+
$result = array ();
|
99 |
+
foreach ( $active_methods as $_code => $payment_model ) {
|
100 |
+
|
101 |
+
if ($_code != 'free' && ($total) > 0) {
|
102 |
+
$result [] = $this->getPayments ( $_code, $payment_model );
|
103 |
+
} else if ($_code == 'free' && $total <= 0) {
|
104 |
+
$_title = Mage::getStoreConfig ( 'payment/' . $_code . '/title' );
|
105 |
+
$paymentMethods ['code'] = $_code;
|
106 |
+
$paymentMethods [static::TITLE] = $_title;
|
107 |
+
$paymentMethods ['ccTypes'] = array ();
|
108 |
+
$result [] = $paymentMethods;
|
109 |
+
} else {
|
110 |
+
// no need this condition
|
111 |
+
}
|
112 |
+
}
|
113 |
+
return $result;
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Get active payment methods
|
118 |
+
*
|
119 |
+
* @param object $quote
|
120 |
+
* @return $result
|
121 |
+
*/
|
122 |
+
public function getPayments($_code, $payment_model) {
|
123 |
+
$_title = Mage::getStoreConfig ( 'payment/' . $_code . '/title' );
|
124 |
+
$pos = strpos ( strtoupper ( $_code ), 'PAYPAL' );
|
125 |
+
if ($pos === false) {
|
126 |
+
$paymentMethods ['code'] = $_code;
|
127 |
+
} else {
|
128 |
+
$paymentMethods ['code'] = 'paypal_standard';
|
129 |
+
}
|
130 |
+
|
131 |
+
$paymentMethods [static::TITLE] = $_title;
|
132 |
+
|
133 |
+
$ccTypes = explode ( ',', $payment_model->getConfigData ( 'cctypes' ) );
|
134 |
+
$aType = Mage::getSingleton ( 'payment/config' )->getCcTypes ();
|
135 |
+
$cc = array ();
|
136 |
+
$i = 0;
|
137 |
+
foreach ( $ccTypes as $cctype ) {
|
138 |
+
if ($cctype != '') {
|
139 |
+
$cc [$i] ['card_code'] = $cctype;
|
140 |
+
$cc [$i] ['card_name'] = $aType [$cctype];
|
141 |
+
|
142 |
+
$i ++;
|
143 |
+
}
|
144 |
+
}
|
145 |
+
$paymentMethods ['ccTypes'] = $cc;
|
146 |
+
|
147 |
+
return $paymentMethods;
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Update device token and type in token table
|
152 |
+
*
|
153 |
+
* @param int $customerId
|
154 |
+
* @param string $deviceToken
|
155 |
+
* @param string $deviceType
|
156 |
+
*/
|
157 |
+
public function updateDeviceToken($customerId, $deviceToken, $deviceType) {
|
158 |
+
$tokenObj = Mage::getModel ( 'login/token' )->load ( $customerId, 'userid' );
|
159 |
+
$tokenObj->setUserid ( $customerId );
|
160 |
+
$tokenObj->setDevicetoken ( $deviceToken );
|
161 |
+
$tokenObj->setDevicetype ( $deviceType );
|
162 |
+
$tokenObj->save ();
|
163 |
+
}
|
164 |
+
|
165 |
+
/**
|
166 |
+
* Function to get the seller profile data
|
167 |
+
*
|
168 |
+
* Passed the seller id as $sellerId to get particular seller info
|
169 |
+
*
|
170 |
+
* @param int $sellerId
|
171 |
+
* Return store title of the seller as $StoreTitle
|
172 |
+
* @return varchar
|
173 |
+
*/
|
174 |
+
public function sellerdisplay($sellerId, $current, $storeId, $productId) {
|
175 |
+
$sellerInfo = array ();
|
176 |
+
if ($sellerId > 0) {
|
177 |
+
$sellerData = Mage::getModel ( 'marketplace/sellerprofile' )->load ( $sellerId, static::SELLER_ID );
|
178 |
+
$sellerInfo [static::SELLER_ID] = $sellerData->getData ( static::SELLER_ID );
|
179 |
+
$sellerInfo ['store_title'] = $sellerData->getData ( 'store_title' );
|
180 |
+
$sellerInfo ['state'] = $sellerData->getData ( 'state' );
|
181 |
+
$sellerInfo [static::COUNTRY] = $sellerData->getData ( static::COUNTRY );
|
182 |
+
if ($sellerData->getData ( static::COUNTRY )) {
|
183 |
+
$country = Mage::getModel ( 'directory/country' )->loadByCode ( $sellerData->getData ( static::COUNTRY ) );
|
184 |
+
// get country name
|
185 |
+
$sellerInfo ['country_name'] = $country->getName ();
|
186 |
+
}
|
187 |
+
$sellerInfo ['contact'] = $sellerData->getData ( 'contact' );
|
188 |
+
$sellerInfo ['store_logo'] = Mage::getBaseUrl ( 'media' ) . DS . 'marketplace/resized/' . $sellerData->getData ( 'store_logo' );
|
189 |
+
$sellerInfo ['current_seller'] = $current;
|
190 |
+
$sellerInfo ['summary_rating'] = strval ( $this->averageRatings ( $sellerId, $storeId ) );
|
191 |
+
$sellerInfo ['ratings'] = strval ( $this->getReviewsCount ( $sellerId, $storeId ) );
|
192 |
+
$_product = Mage::getModel ( 'catalog/product' )->load ( $productId );
|
193 |
+
|
194 |
+
$sellerInfo ['entity_id'] = $productId;
|
195 |
+
$sellerInfo ['regular_price_with_tax'] = number_format ( $_product->getPrice (), 2, '.', '' );
|
196 |
+
$sellerInfo ['final_price_with_tax'] = number_format ( $_product->getFinalPrice (), 2, '.', '' );
|
197 |
+
}
|
198 |
+
return $sellerInfo;
|
199 |
+
}
|
200 |
+
|
201 |
+
/**
|
202 |
+
* Get Review Collection of the particular seller
|
203 |
+
*
|
204 |
+
* Passed the seller id to get the review collection
|
205 |
+
*
|
206 |
+
* @param int $sellerId
|
207 |
+
* Return the reviews count of particular seller
|
208 |
+
* @return int
|
209 |
+
*/
|
210 |
+
public function getReviewsCount($sellerId, $storeId) {
|
211 |
+
$reviewsCollection = Mage::getModel ( static::MARKETPLACE_SELLERREVIEW )->getCollection ()->addFieldToFilter ( static::SELLER_ID, $sellerId )->addFieldToFilter ( static::STATUS, 1 )->addFieldToFilter ( static::STOREID, $storeId );
|
212 |
+
return $reviewsCollection->getSize ();
|
213 |
+
}
|
214 |
+
|
215 |
+
/**
|
216 |
+
* Calculating average rating for each seller
|
217 |
+
*
|
218 |
+
* Passed the seller id to get the review collection
|
219 |
+
*
|
220 |
+
* @param int $sellerId
|
221 |
+
* Return the average rating of particular seller
|
222 |
+
* @return int
|
223 |
+
*/
|
224 |
+
public function averageRatings($sellerId, $storeId) {
|
225 |
+
/**
|
226 |
+
* Review Collection to retrive the ratings of the seller
|
227 |
+
*/
|
228 |
+
$reviews = Mage::getModel ( static::MARKETPLACE_SELLERREVIEW )->getCollection ()->addFieldToFilter ( static::SELLER_ID, $sellerId )->addFieldToFilter ( static::STATUS, 1 )->addFieldToFilter ( static::STOREID, $storeId );
|
229 |
+
/**
|
230 |
+
* Calculate average ratings
|
231 |
+
*/
|
232 |
+
$ratingsVal = array ();
|
233 |
+
$avg = 0;
|
234 |
+
if (count ( $reviews ) > 0) {
|
235 |
+
foreach ( $reviews as $review ) {
|
236 |
+
$ratingsVal [] = $review->getRating ();
|
237 |
+
}
|
238 |
+
/**
|
239 |
+
* Calcualte count of ratings
|
240 |
+
*/
|
241 |
+
$count = count ( $ratingsVal );
|
242 |
+
/**
|
243 |
+
* Calculate average ratings from count
|
244 |
+
*/
|
245 |
+
$avg = array_sum ( $ratingsVal ) / $count;
|
246 |
+
}
|
247 |
+
return round ( $avg, 1 );
|
248 |
+
}
|
249 |
+
|
250 |
+
/**
|
251 |
+
* Get Seller reviews and Rating
|
252 |
+
*
|
253 |
+
* @param int $sellerId
|
254 |
+
* @param int $storeId
|
255 |
+
*
|
256 |
+
* @return array $response
|
257 |
+
*/
|
258 |
+
public function getSellerReviews($sellerId, $storeId, $page, $limit) {
|
259 |
+
$reviews = array ();
|
260 |
+
$response = array ();
|
261 |
+
/**
|
262 |
+
* Review Collection to retrive the ratings of the seller
|
263 |
+
*/
|
264 |
+
$reviewcoll = Mage::getModel ( static::MARKETPLACE_SELLERREVIEW )->getCollection ()->addFieldToFilter ( static::SELLER_ID, $sellerId )->addFieldToFilter ( static::STATUS, 1 )->addFieldToFilter ( static::STOREID, $storeId );
|
265 |
+
$totalReviews = $reviewcoll->getSize ();
|
266 |
+
$reviewcoll->setPageSize ( $limit )->setCurPage ( $page );
|
267 |
+
if (count ( $reviewcoll ) > 0) {
|
268 |
+
$j = 0;
|
269 |
+
foreach ( $reviewcoll as $review ) {
|
270 |
+
|
271 |
+
$reviews [$j] ['feedback'] = $review->getReview ();
|
272 |
+
$reviews [$j] ['product_id'] = $review->getProductId ();
|
273 |
|
274 |
+
/**
|
275 |
+
* load customer info
|
276 |
+
*/
|
277 |
+
$customerInfo = Mage::getModel ( 'customer/customer' )->load ( $review->getCustomerId () );
|
278 |
+
// get customer name
|
279 |
+
$reviews [$j] ['customer_name'] = $customerInfo->getName ();
|
280 |
+
$reviews [$j] ['date'] = date ( "Y-m-d", strtotime ( $review->getCreatedAt () ) );
|
281 |
+
$reviews [$j] ['rating'] = $review->getRating ();
|
282 |
+
|
283 |
+
$j ++;
|
284 |
+
}
|
285 |
+
}
|
286 |
+
$response ['total_reviews_count'] = $totalReviews;
|
287 |
+
$response ['reviews'] = $reviews;
|
288 |
+
return $response;
|
289 |
+
}
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Get stock information for product from inventory tab
|
293 |
+
*
|
294 |
+
* @param int $storeId
|
295 |
+
* @param object $product
|
296 |
+
* @return array $_proudct_data
|
297 |
+
*/
|
298 |
+
public function getinventoryDetail($product, $storeId) {
|
299 |
+
$inventoryData = array ();
|
300 |
+
// get stock available qty
|
301 |
+
$inventory = Mage::getModel ( 'cataloginventory/stock_item' )->loadByProduct ( $product );
|
302 |
+
if ($product->getTypeId () != 'configurable') {
|
303 |
+
// get product availabile qty
|
304 |
+
$inventoryData [static::STOCK_QTY] = floatval ( $inventory->getQty () );
|
305 |
+
$minCartQty = $inventory->getMinSaleQty ();
|
306 |
+
$inventoryData ['min_sale_qty'] = (isset ( $minCartQty )) ? floatval ( $minCartQty ) : floatval ( 1 );
|
307 |
+
|
308 |
+
$maxCartQty = $inventory->getMaxSaleQty ();
|
309 |
+
$inventoryData ['max_sale_qty'] = (isset ( $maxCartQty )) ? floatval ( $maxCartQty ) : floatval ( Mage::getStoreConfig ( 'cataloginventory/item_options/max_sale_qty', $storeId ) );
|
310 |
+
|
311 |
+
$qtyIncr = $inventory->getQtyIncrements ();
|
312 |
+
$enable_qty_increments = Mage::getStoreConfig ( 'cataloginventory/item_options/enable_qty_increments', $storeId );
|
313 |
+
if ($qtyIncr == false) {
|
314 |
+
if ($enable_qty_increments) {
|
315 |
+
$qtyIncr = Mage::getStoreConfig ( 'cataloginventory/item_options/qty_increments', $storeId );
|
316 |
}
|
317 |
+
if ($qtyIncr == 0) {
|
318 |
+
$qtyIncr = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
319 |
}
|
320 |
+
}
|
321 |
+
|
322 |
+
$inventoryData ['qty_increments'] = floatval ( $qtyIncr );
|
323 |
+
$inventoryData ['is_qty_decimal'] = floatval ( $inventory->getIsQtyDecimal () );
|
324 |
+
} else {
|
325 |
+
$inventoryData [static::STOCK_QTY] = floatval ( '' );
|
326 |
+
$inventoryData ['min_sale_qty'] = floatval ( '' );
|
327 |
+
$inventoryData ['max_sale_qty'] = floatval ( '' );
|
328 |
+
$inventoryData ['qty_increments'] = floatval ( '' );
|
329 |
+
$inventoryData ['is_qty_decimal'] = floatval ( '' );
|
330 |
+
}
|
331 |
+
|
332 |
+
return $inventoryData;
|
333 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
}
|
app/code/local/ContusRestapi/Login/Model/Token.php
CHANGED
@@ -28,710 +28,766 @@
|
|
28 |
* @since 1.0
|
29 |
*/
|
30 |
class ContusRestapi_Login_Model_Token extends Mage_Core_Model_Abstract {
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
$
|
140 |
-
|
141 |
-
$response [static::SUCCESS] = 0;
|
142 |
-
}
|
143 |
-
|
144 |
-
return $response;
|
145 |
-
}
|
146 |
-
|
147 |
-
/**
|
148 |
-
* Get product count in cart by customer
|
149 |
-
*
|
150 |
-
* @param int $customerId
|
151 |
-
* @param int $storeId
|
152 |
-
* @return number $itemCount
|
153 |
-
*/
|
154 |
-
public function getCartCount($customerId, $storeId) {
|
155 |
-
$quote = Mage::getModel ( static::SLAES_QUOTE )->getCollection ()->addFieldToFilter ( static::CUSTOMERID, $customerId )->addFieldToFilter ( static::STOREID, $storeId )->addFieldToFilter ( static::IS_ACTIVE, "1" )->setOrder ( static::ENTITYID, 'desc' );
|
156 |
-
$quoteData = $quote->getData ();
|
157 |
-
$itemCount = '0';
|
158 |
-
$cartLink = Mage::getStoreConfig ( static::CHECKOUT_CART_QTY, $storeId );
|
159 |
-
if (isset ( $quoteData )) {
|
160 |
-
if ($cartLink) {
|
161 |
-
$itemCount = strval ( intval ( $quoteData [0] ['items_qty'] ) );
|
162 |
-
} else {
|
163 |
-
$itemCount = strval ( $quoteData [0] ['items_count'] );
|
164 |
-
}
|
165 |
-
}
|
166 |
-
return $itemCount;
|
167 |
-
}
|
168 |
-
|
169 |
-
/**
|
170 |
-
* Customer Wishlist collection
|
171 |
-
*
|
172 |
-
* @param int $customerId
|
173 |
-
*
|
174 |
-
* @return array $wishListIds
|
175 |
-
*/
|
176 |
-
public function getWishlistByCustomer($customerId) {
|
177 |
-
$wishListIds = array ();
|
178 |
-
|
179 |
-
/**
|
180 |
-
*
|
181 |
-
* @var $customer Mage_Customer_Model_Customer
|
182 |
-
*/
|
183 |
-
$customerModel = Mage::getModel ( static::CUSTOMER_CUSTOMER );
|
184 |
-
$customerModel->load ( $customerId );
|
185 |
-
if (! empty ( $customerModel [static::EMAIL] ) && $customerModel [static::EMAIL] != "") {
|
186 |
-
$wishList = Mage::getSingleton ( 'wishlist/wishlist' )->loadByCustomer ( $customerId, true );
|
187 |
-
$wishListItemCollection = $wishList->getItemCollection ();
|
188 |
-
if (count ( $wishListItemCollection ) > 0) {
|
189 |
-
foreach ( $wishListItemCollection as $wishitem ) {
|
190 |
-
$wishListIds [] = $wishitem->getProductId ();
|
191 |
-
}
|
192 |
-
}
|
193 |
-
}
|
194 |
-
return $wishListIds;
|
195 |
-
}
|
196 |
-
|
197 |
-
/**
|
198 |
-
* Products Rating
|
199 |
-
*
|
200 |
-
* @param int $productId
|
201 |
-
* Getting the particular product id
|
202 |
-
* @param int $storeId
|
203 |
-
* @return array as json message as string and success rate count
|
204 |
-
*/
|
205 |
-
public function rateSummary($productId, $storeId) {
|
206 |
-
// getting rate model
|
207 |
-
$summaryData = Mage::getModel ( 'review/review_summary' )->setStoreId ( $storeId )->load ( $productId )->getRatingSummary ();
|
208 |
-
// calculate overage for ratings
|
209 |
-
return strval ( $summaryData / 20 );
|
210 |
-
}
|
211 |
-
|
212 |
-
/**
|
213 |
-
* Get product reviews and Rating
|
214 |
-
*
|
215 |
-
* @param int $productId
|
216 |
-
* @param int $storeId
|
217 |
-
*
|
218 |
-
* @return array $response
|
219 |
-
*/
|
220 |
-
public function getReviews($productId, $storeId, $page, $limit) {
|
221 |
-
// get only five revieews in product detail page
|
222 |
-
$reviewcoll = Mage::getModel ( 'review/review' )->getResourceCollection ()->addStoreFilter ( $storeId )->addEntityFilter ( 'product', $productId )->addStatusFilter ( Mage_Review_Model_Review::STATUS_APPROVED )->setDateOrder ( 'desc' )->setPageSize ( $limit )->setCurPage ( $page )->addRateVotes ();
|
223 |
-
|
224 |
-
$response = array ();
|
225 |
-
$reviews = array ();
|
226 |
-
|
227 |
-
if (count ( $reviewcoll ) > 0) {
|
228 |
-
$j = 0;
|
229 |
-
// get all reviews collection
|
230 |
-
foreach ( $reviewcoll->getItems () as $key => $review ) {
|
231 |
-
$reviews [$j] ['title'] = $review->getTitle ();
|
232 |
-
$reviews [$j] ['detail'] = $review->getDetail ();
|
233 |
-
$reviews [$j] ['author'] = $review->getNickname ();
|
234 |
-
$reviews [$j] ['date'] = date ( "Y-m-d", strtotime ( $review->getCreatedAt () ) );
|
235 |
-
|
236 |
-
$rateAvg = 0;
|
237 |
-
|
238 |
-
foreach ( $review->getRatingVotes () as $vote ) {
|
239 |
-
$rateAvg += $vote->getPercent ();
|
240 |
-
}
|
241 |
-
// get summary rating
|
242 |
-
$reviews [$j] [static::RATING] = floor ( $rateAvg / 60 );
|
243 |
-
|
244 |
-
$j ++;
|
245 |
}
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
|
|
276 |
}
|
277 |
-
// get rating
|
278 |
-
$rating =
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
}
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
|
325 |
-
|
326 |
-
$
|
|
|
|
|
327 |
|
328 |
-
|
329 |
-
|
330 |
-
$_proudct_data [static::IS_STOCK] = false;
|
331 |
-
} else {
|
332 |
-
$_proudct_data [static::IS_SALABLE] = true;
|
333 |
-
$_proudct_data [static::IS_STOCK] = true;
|
334 |
-
}
|
335 |
-
}
|
336 |
-
|
337 |
-
return $_proudct_data;
|
338 |
-
}
|
339 |
-
|
340 |
-
/**
|
341 |
-
* Get associated product stock
|
342 |
-
*
|
343 |
-
* @param object $stockItem
|
344 |
-
* @param array $childProducts
|
345 |
-
* @return boolean true| false
|
346 |
-
*/
|
347 |
-
public function getChildStock($stockItem, $childProducts) {
|
348 |
-
$instock_childrenisinstock = false;
|
349 |
-
if ($stockItem->getIsInStock ()) {
|
350 |
-
/**
|
351 |
-
* All configurable products, which are in stock
|
352 |
-
*/
|
353 |
|
354 |
-
|
355 |
-
|
356 |
-
Mage::getModel ( static::CATALOG_STOCK )->loadByProduct ( $childProduct );
|
357 |
-
if ($child_stockItem->getIsInStock ()) {
|
358 |
-
$instock_childrenisinstock = true;
|
359 |
-
}
|
360 |
-
}
|
361 |
-
}
|
362 |
-
return $instock_childrenisinstock;
|
363 |
-
}
|
364 |
-
|
365 |
-
/**
|
366 |
-
* Get Cart Amount Details
|
367 |
-
*
|
368 |
-
* @param array $data
|
369 |
-
* @return array $response
|
370 |
-
*/
|
371 |
-
public function getCartTotal($data) {
|
372 |
-
// get customer id
|
373 |
-
$customerId = $data [static::CUSTOMERID];
|
374 |
-
// get category id
|
375 |
-
$storeId = $data [static::STOREID];
|
376 |
-
$quoteData = $this->getQuoteIdBycustomer ( $customerId, $storeId );
|
377 |
-
$quoteId = $quoteData [0] [static::ENTITYID];
|
378 |
-
$cartTotal = array ();
|
379 |
-
$quote = $this->_getQuote ( $quoteId, $storeId );
|
380 |
-
$totals = $quote->getTotals ();
|
381 |
-
if (isset ( $totals [static::DISCOUNT] )) {
|
382 |
-
$discount = number_format ( abs ( $totals [static::DISCOUNT]->getValue () ), 2, '.', '' );
|
383 |
-
} else {
|
384 |
-
$discount = '';
|
385 |
-
}
|
386 |
-
// get system/configuration -checkout - cart liks value
|
387 |
-
$cartLink = Mage::getStoreConfig ( static::CHECKOUT_CART_QTY, $storeId );
|
388 |
-
if (isset ( $quoteData ) && ! empty ( $quoteData )) {
|
389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
390 |
if ($cartLink) {
|
391 |
-
|
392 |
-
|
393 |
} else {
|
394 |
-
|
395 |
-
|
396 |
}
|
397 |
-
|
398 |
-
$
|
399 |
-
$
|
400 |
-
$
|
401 |
-
$
|
402 |
-
$
|
403 |
-
$
|
|
|
404 |
$addressobj = $quote->getShippingAddress ();
|
405 |
-
|
406 |
-
$cartTotal [static::TAX] = 0;
|
407 |
if ($addressobj) {
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
}
|
413 |
-
} else {
|
414 |
|
415 |
-
$
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
/**
|
444 |
-
*
|
445 |
-
* @var $quote Mage_Sales_Model_Quote
|
446 |
-
*/
|
447 |
-
$quote = Mage::getModel ( static::SLAES_QUOTE );
|
448 |
-
$quote->setStoreId ( $storeId )->load ( $quoteId );
|
449 |
-
return $quote;
|
450 |
-
}
|
451 |
-
|
452 |
-
/**
|
453 |
-
* Get cart quote by customer
|
454 |
-
*
|
455 |
-
* @param int $customerId
|
456 |
-
* @param in $storeId
|
457 |
-
* @return object $$quote
|
458 |
-
*/
|
459 |
-
public function setSaleQuoteByCustomer($customerId, $storeId, $currencyCode) {
|
460 |
-
/**
|
461 |
-
*
|
462 |
-
* @var $quote Mage_Sales_Model_Quote
|
463 |
-
*/
|
464 |
-
$quote = Mage::getModel ( static::SLAES_QUOTE )->getCollection ()->addFieldToFilter ( static::CUSTOMERID, $customerId )->addFieldToFilter ( static::STOREID, $storeId )->addFieldToFilter ( static::IS_ACTIVE, '1' )->setOrder ( static::ENTITYID, 'desc' );
|
465 |
-
$quoteData = $quote->getData ();
|
466 |
-
if (empty ( $quoteData )) {
|
467 |
-
$quote = Mage::getModel ( static::SLAES_QUOTE );
|
468 |
-
$customer = Mage::getModel ( static::CUSTOMER_CUSTOMER )->load ( $customerId );
|
469 |
-
// Check this customer id is in record
|
470 |
-
if ($customer->getId ()) {
|
471 |
-
$quote->assignCustomer ( $customer );
|
472 |
-
$quote->setStore_id ( $storeId );
|
473 |
-
|
474 |
-
$quote->setQuoteCurrencyCode ( $currencyCode );
|
475 |
-
$quote->setGlobalCurrencyCode ( $currencyCode )->setCustomerId ( $customerId )->setUpdatedAt ( now () )->setCreatedAt ( now () );
|
476 |
-
$quote->setCustomerEmail ( $customer->getEmail () )->setCustomerFirstname ( $customer->getFirstname () )->setCustomerLastname ( $customer->getLastname () )->setCustomerIsGuest ( 0 )->setCustomer ( $customer );
|
477 |
-
$quote->save ();
|
478 |
-
} else {
|
479 |
-
$quote = 0;
|
480 |
}
|
481 |
-
} else {
|
482 |
-
$quote = Mage::getModel ( static::SLAES_QUOTE );
|
483 |
-
$quote->setStoreId ( $storeId )->load ( $quoteData [0] [static::ENTITYID] );
|
484 |
-
$quote->setUpdatedAt ( now () );
|
485 |
-
}
|
486 |
-
return $quote;
|
487 |
-
}
|
488 |
-
|
489 |
-
/**
|
490 |
-
*
|
491 |
-
* @param Mage_Sales_Model_Quote $quote
|
492 |
-
* @param Mage_Catalog_Model_Product $product
|
493 |
-
* @param Varien_Object $requestInfo
|
494 |
-
* @return Varien_Object
|
495 |
-
*/
|
496 |
-
public function _getQuoteItemByProduct(Mage_Sales_Model_Quote $quote, Mage_Catalog_Model_Product $product, Varien_Object $requestInfo) {
|
497 |
-
$cartCandidates = $product->getTypeInstance ( TRUE )->prepareForCartAdvanced ( $requestInfo, $product, Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_FULL );
|
498 |
-
/**
|
499 |
-
* Error message
|
500 |
-
*/
|
501 |
-
if (is_string ( $cartCandidates )) {
|
502 |
-
throw Mage::throwException ( $cartCandidates );
|
503 |
-
}
|
504 |
-
|
505 |
-
/**
|
506 |
-
* If prepare process return one object
|
507 |
-
*/
|
508 |
-
if (! is_array ( $cartCandidates )) {
|
509 |
-
$cartCandidates = array (
|
510 |
-
$cartCandidates
|
511 |
-
);
|
512 |
-
}
|
513 |
-
|
514 |
-
/**
|
515 |
-
*
|
516 |
-
* @var $item Mage_Sales_Model_Quote_Item
|
517 |
-
*/
|
518 |
-
$item = NULL;
|
519 |
-
foreach ( $cartCandidates as $candidate ) {
|
520 |
-
if ($candidate->getParentProductId ()) {
|
521 |
-
Mage::log ( 'productID' . $candidate->getParentProductId () );
|
522 |
-
continue;
|
523 |
-
}
|
524 |
-
|
525 |
-
$item = $quote->getItemByProduct ( $candidate );
|
526 |
-
}
|
527 |
-
|
528 |
-
if (is_null ( $item )) {
|
529 |
-
$item = Mage::getModel ( 'sales/quote_item' );
|
530 |
-
}
|
531 |
-
|
532 |
-
return $item;
|
533 |
-
}
|
534 |
-
|
535 |
-
/**
|
536 |
-
*
|
537 |
-
* @param array $requestInfo
|
538 |
-
* @return Varien_Object
|
539 |
-
*/
|
540 |
-
public function _getProductRequest($requestInfo) {
|
541 |
-
if ($requestInfo instanceof Varien_Object) {
|
542 |
-
$request = $requestInfo;
|
543 |
-
} elseif (is_numeric ( $requestInfo )) {
|
544 |
-
Mage::log ( 'else in product request' );
|
545 |
-
$request = new Varien_Object ();
|
546 |
-
$request->setQty ( $requestInfo );
|
547 |
-
} else {
|
548 |
-
$request = new Varien_Object ( $requestInfo );
|
549 |
-
}
|
550 |
-
|
551 |
-
if (! $request->hasQty ()) {
|
552 |
-
$request->setQty ( 1 );
|
553 |
-
}
|
554 |
-
|
555 |
-
return $request;
|
556 |
-
}
|
557 |
-
|
558 |
-
/**
|
559 |
-
* Get Cart product details
|
560 |
-
*
|
561 |
-
* @param array $data
|
562 |
-
* @return array $response
|
563 |
-
*/
|
564 |
-
public function getCartProducts($data) {
|
565 |
-
|
566 |
-
// get category id
|
567 |
-
$storeId = $data [static::STOREID];
|
568 |
-
// get customer id
|
569 |
-
$customerId = $data [static::CUSTOMERID];
|
570 |
-
|
571 |
-
$quoteData = $this->getQuoteIdBycustomer ( $customerId, $storeId );
|
572 |
-
$quoteId = $quoteData [0] [static::ENTITYID];
|
573 |
-
|
574 |
-
$quote = $this->_getQuote ( $quoteId, $storeId );
|
575 |
-
$totals = $quote->getTotals ();
|
576 |
-
if (isset ( $totals [static::DISCOUNT] )) {
|
577 |
-
$discount = number_format ( abs ( $totals [static::DISCOUNT]->getValue () ), 2, '.', '' );
|
578 |
-
} else {
|
579 |
-
$discount = '';
|
580 |
-
}
|
581 |
-
// get system/configuration -checkout - cart liks value
|
582 |
-
$cartLink = Mage::getStoreConfig ( static::CHECKOUT_CART_QTY, $storeId );
|
583 |
-
$returnArray = array ();
|
584 |
-
$returnArray ['items'] = array ();
|
585 |
-
$items = array ();
|
586 |
-
if (isset ( $quoteData ) && ! empty ( $quoteData )) {
|
587 |
|
588 |
-
$
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
} else {
|
595 |
-
// Display Cart Summary - Display no.of items in cart
|
596 |
-
$itemCount = strval ( $quoteData [0] [static::ITEMS_COUNT] );
|
597 |
-
}
|
598 |
-
|
599 |
-
$returnArray [static::ITEM_COUNT] = $itemCount;
|
600 |
-
$returnArray [static::SHIPPING_AMT] = 0;
|
601 |
-
$returnArray [static::TAX] = 0;
|
602 |
-
$returnArray [static::GRAND_TOTAL] = number_format ( $quoteData [0] [static::GRAND_TOTAL], 2, '.', '' );
|
603 |
-
$returnArray [static::SUBTOTAL] = number_format ( $quoteData [0] [static::SUBTOTAL], 2, '.', '' );
|
604 |
-
$returnArray [static::DISCOUNT] = $discount;
|
605 |
-
$returnArray [static::QUOTE_ID] = $quoteId;
|
606 |
-
$returnArray [static::COUPON_CODE] = $quoteData [0] [static::COUPON_CODE];
|
607 |
-
$addressobj = $quote->getShippingAddress ();
|
608 |
-
|
609 |
-
if ($addressobj) {
|
610 |
-
$returnArray [static::SHIPPING_AMT] = $quote->getShippingAddress ()->getData ( static::SHIPPING_AMT );
|
611 |
-
$returnArray [static::TAX] = $quote->getShippingAddress ()->getData ( 'tax_amount' );
|
612 |
-
$returnArray [static::SHIPPING_AMT] = number_format ( $returnArray [static::SHIPPING_AMT], 2, '.', '' );
|
613 |
-
$returnArray [static::TAX] = number_format ( $returnArray ['tax'], 2, '.', '' );
|
614 |
-
}
|
615 |
-
|
616 |
-
$i = 0;
|
617 |
-
|
618 |
-
foreach ( $quote->getAllVisibleItems () as $item ) {
|
619 |
-
$product = $item->getProduct ();
|
620 |
-
$product->setStoreId ( $storeId )->load ( $product->getId () );
|
621 |
-
$items [$i] ['type_id'] = $item->getProductType ();
|
622 |
-
$items [$i] ['item_id_test'] = $item->getItemId ();
|
623 |
-
// get product id
|
624 |
-
$items [$i] [static::ENTITYID] = $product->getEntityId ();
|
625 |
-
// get product name
|
626 |
-
$items [$i] ['name'] = $product->getName ();
|
627 |
-
// get product image
|
628 |
-
$items [$i] ['image_url'] = ( string ) Mage::helper ( 'catalog/image' )->init ( $product, 'small_image' );
|
629 |
-
// get product price
|
630 |
-
$items [$i] ['price'] = number_format ( $item->getPrice (), 2, '.', '' );
|
631 |
-
// get product qty
|
632 |
-
$items [$i] [static::QTY] = $item->getQty ();
|
633 |
-
// get product row total
|
634 |
-
$items [$i] ['row_total'] = number_format ( $item->getRowTotal (), 2, '.', '' );
|
635 |
-
|
636 |
-
$stockDetail = $this->getProductStock ( $product, $item );
|
637 |
-
$items [$i] [static::STOCK_QTY] = $stockDetail [static::STOCK_QTY];
|
638 |
-
$items [$i] [static::IS_STOCK] = $stockDetail [static::IS_STOCK];
|
639 |
-
$items [$i] ['config'] = Mage::getModel ( 'catalog/product_type_configurable' )->getOrderOptions ( $product );
|
640 |
-
$i ++;
|
641 |
-
}
|
642 |
-
|
643 |
-
$returnArray ['items'] = $items;
|
644 |
-
$returnArray ['address'] = $this->getAddressByCustomer ( $customerId );
|
645 |
-
$error = false;
|
646 |
-
$message = 'Quote fetched successfully.';
|
647 |
-
} else {
|
648 |
-
|
649 |
-
$error = false;
|
650 |
-
$message = static::NO_ITEM;
|
651 |
-
}
|
652 |
-
} else {
|
653 |
-
$error = true;
|
654 |
$message = static::NO_ITEM;
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
$
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
737 |
}
|
28 |
* @since 1.0
|
29 |
*/
|
30 |
class ContusRestapi_Login_Model_Token extends Mage_Core_Model_Abstract {
|
31 |
+
const STOREID = 'store_id';
|
32 |
+
const FIRSTNAME = 'firstname';
|
33 |
+
const LASTNAME = 'lastname';
|
34 |
+
const NEWSLETTER = 'newsletter';
|
35 |
+
const ENTITYID = 'entity_id';
|
36 |
+
const CUSTOMERID = 'customer_id';
|
37 |
+
const EMAIL = 'email';
|
38 |
+
const SUCCESS = 'success';
|
39 |
+
const TOKEN = 'token';
|
40 |
+
const IS_SALABLE = 'is_saleable';
|
41 |
+
const IS_STOCK = 'is_stock';
|
42 |
+
const RATING = 'rating';
|
43 |
+
const PRODUCT_ID = 'product_id';
|
44 |
+
const QUOTE_ID = 'quote_id';
|
45 |
+
const QTY = 'qty';
|
46 |
+
const DISCOUNT = 'discount';
|
47 |
+
const SHIPPING_AMT = 'shipping_amount';
|
48 |
+
const TAX = 'tax';
|
49 |
+
const ITEM_COUNT = 'item_count';
|
50 |
+
const ITEMS_QTY = 'items_qty';
|
51 |
+
const GRAND_TOTAL = 'grand_total';
|
52 |
+
const SUBTOTAL = 'subtotal';
|
53 |
+
const COUPON_CODE = 'coupon_code';
|
54 |
+
const SLAES_QUOTE = 'sales/quote';
|
55 |
+
const IS_ACTIVE = 'is_active';
|
56 |
+
const CUSTOMER_CUSTOMER = 'customer/customer';
|
57 |
+
const ITEMS_COUNT = 'items_count';
|
58 |
+
const NO_ITEM = 'No items in your cart.';
|
59 |
+
const STOCK_QTY = 'stock_qty';
|
60 |
+
const CATALOG_STOCK = 'cataloginventory/stock_item';
|
61 |
+
const RESULT = 'result';
|
62 |
+
const MESSAGE = 'message';
|
63 |
+
const BILLING = 'billing';
|
64 |
+
const SHIPPING = 'shipping';
|
65 |
+
const CHECKOUT_CART_QTY = 'checkout/cart_link/use_qty';
|
66 |
+
const CONFIGURABLE = 'configurable';
|
67 |
+
const MIN_SALE_QTY = 'min_sale_qty';
|
68 |
+
const MAX_SALE_QTY = 'max_sale_qty';
|
69 |
+
const QTY_INCR = 'qty_increments';
|
70 |
+
const IS_QTY_DECIAML = 'is_qty_decimal';
|
71 |
+
|
72 |
+
protected function _construct() {
|
73 |
+
$this->_init ( 'login/token' );
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Generate token value for customer
|
78 |
+
*/
|
79 |
+
public function getRandomString($length = 6) {
|
80 |
+
$validCharacters = "abcdefghijklmnopqrstuxyvwzABCDEFGHIJKLMNOPQRSTUXYVWZ123456789";
|
81 |
+
$validCharNumber = strlen ( $validCharacters );
|
82 |
+
$result = "";
|
83 |
+
for($i = 0; $i < $length; $i ++) {
|
84 |
+
$index = mt_rand ( 0, $validCharNumber - 1 );
|
85 |
+
$result .= $validCharacters [$index];
|
86 |
+
}
|
87 |
+
$tokobj = Mage::getModel ( 'login/token' )->load ( $result, 'token' );
|
88 |
+
if ($tokobj->getTokenid ()) {
|
89 |
+
$this->getRandomString ( 6 );
|
90 |
+
}
|
91 |
+
return $result;
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Check Customer has vaild token or not
|
96 |
+
*
|
97 |
+
* @param int $userid
|
98 |
+
* @param string $token
|
99 |
+
* @return boolean
|
100 |
+
*/
|
101 |
+
public function checkUserToken($userid, $token) {
|
102 |
+
$tokenObj = $this->load ( $userid, 'userid' );
|
103 |
+
$value = TRUE;
|
104 |
+
if ($tokenObj->getToken () == $token && trim ( $token ) != '') {
|
105 |
+
$value = TRUE;
|
106 |
+
} else {
|
107 |
+
$value = FALSE;
|
108 |
+
}
|
109 |
+
return $value;
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Get Customer Details by id
|
114 |
+
*
|
115 |
+
* @param int $customerId
|
116 |
+
* @return array $response
|
117 |
+
*/
|
118 |
+
public function getCustomerDetail($customerId) {
|
119 |
+
$response = array ();
|
120 |
+
|
121 |
+
/**
|
122 |
+
*
|
123 |
+
* @var $customer Mage_Customer_Model_Customer
|
124 |
+
*/
|
125 |
+
$customerData = Mage::getModel ( static::CUSTOMER_CUSTOMER )->load ( $customerId )->getData ();
|
126 |
+
$customerID = $customerData [static::ENTITYID];
|
127 |
+
if (isset ( $customerID )) {
|
128 |
+
$response [static::SUCCESS] = 1;
|
129 |
+
$response [static::CUSTOMERID] = $customerData [static::ENTITYID];
|
130 |
+
// get customer name
|
131 |
+
$response [static::FIRSTNAME] = $customerData [static::FIRSTNAME];
|
132 |
+
$response [static::LASTNAME] = $customerData [static::LASTNAME];
|
133 |
+
// get customer email
|
134 |
+
$response [static::EMAIL] = $customerData [static::EMAIL];
|
135 |
+
$subscriber = Mage::getModel ( 'newsletter/subscriber' )->loadByEmail ( $customerData [static::EMAIL] );
|
136 |
+
if ($subscriber->getId () && $subscriber->getStatus () == 1) {
|
137 |
+
$response [static::NEWSLETTER] = 1;
|
138 |
+
} else {
|
139 |
+
$response [static::NEWSLETTER] = 0;
|
140 |
+
}
|
141 |
+
|
142 |
+
// get customer dob yyyy-mm-dd hh:mm:ss
|
143 |
+
$response ['dob'] = $customerData ['dob'];
|
144 |
+
$response [static::STOREID] = $customerData [static::STOREID];
|
145 |
+
} else {
|
146 |
+
$response [static::SUCCESS] = 0;
|
147 |
+
}
|
148 |
+
|
149 |
+
return $response;
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Get product count in cart by customer
|
154 |
+
*
|
155 |
+
* @param int $customerId
|
156 |
+
* @param int $storeId
|
157 |
+
* @return number $itemCount
|
158 |
+
*/
|
159 |
+
public function getCartCount($customerId, $storeId) {
|
160 |
+
$quote = Mage::getModel ( static::SLAES_QUOTE )->getCollection ()->addFieldToFilter ( static::CUSTOMERID, $customerId )->addFieldToFilter ( static::STOREID, $storeId )->addFieldToFilter ( static::IS_ACTIVE, "1" )->setOrder ( static::ENTITYID, 'desc' );
|
161 |
+
$quoteData = $quote->getData ();
|
162 |
+
$itemCount = '0';
|
163 |
+
$cartLink = Mage::getStoreConfig ( static::CHECKOUT_CART_QTY, $storeId );
|
164 |
+
if (isset ( $quoteData )) {
|
165 |
+
if ($cartLink) {
|
166 |
+
$itemCount = strval ( floatval ( $quoteData [0] ['items_qty'] ) );
|
167 |
+
} else {
|
168 |
+
$itemCount = strval ( $quoteData [0] ['items_count'] );
|
169 |
+
}
|
170 |
+
}
|
171 |
+
return $itemCount;
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Customer Wishlist collection
|
176 |
+
*
|
177 |
+
* @param int $customerId
|
178 |
+
*
|
179 |
+
* @return array $wishListIds
|
180 |
+
*/
|
181 |
+
public function getWishlistByCustomer($customerId) {
|
182 |
+
$wishListIds = array ();
|
183 |
+
|
184 |
+
/**
|
185 |
+
*
|
186 |
+
* @var $customer Mage_Customer_Model_Customer
|
187 |
+
*/
|
188 |
+
$customerModel = Mage::getModel ( static::CUSTOMER_CUSTOMER );
|
189 |
+
$customerModel->load ( $customerId );
|
190 |
+
if (! empty ( $customerModel [static::EMAIL] ) && $customerModel [static::EMAIL] != "") {
|
191 |
+
$wishList = Mage::getSingleton ( 'wishlist/wishlist' )->loadByCustomer ( $customerId, true );
|
192 |
+
$wishListItemCollection = $wishList->getItemCollection ();
|
193 |
+
if (count ( $wishListItemCollection ) > 0) {
|
194 |
+
foreach ( $wishListItemCollection as $wishitem ) {
|
195 |
+
$wishListIds [] = $wishitem->getProductId ();
|
196 |
}
|
197 |
+
}
|
198 |
+
}
|
199 |
+
return $wishListIds;
|
200 |
+
}
|
201 |
+
|
202 |
+
/**
|
203 |
+
* Products Rating
|
204 |
+
*
|
205 |
+
* @param int $productId
|
206 |
+
* Getting the particular product id
|
207 |
+
* @param int $storeId
|
208 |
+
* @return array as json message as string and success rate count
|
209 |
+
*/
|
210 |
+
public function rateSummary($productId, $storeId) {
|
211 |
+
// getting rate model
|
212 |
+
$summaryData = Mage::getModel ( 'review/review_summary' )->setStoreId ( $storeId )->load ( $productId )->getRatingSummary ();
|
213 |
+
// calculate overage for ratings
|
214 |
+
return strval ( $summaryData / 20 );
|
215 |
+
}
|
216 |
+
|
217 |
+
/**
|
218 |
+
* Get product reviews and Rating
|
219 |
+
*
|
220 |
+
* @param int $productId
|
221 |
+
* @param int $storeId
|
222 |
+
*
|
223 |
+
* @return array $response
|
224 |
+
*/
|
225 |
+
public function getReviews($productId, $storeId, $page, $limit) {
|
226 |
+
// get only five revieews in product detail page
|
227 |
+
$reviewcoll = Mage::getModel ( 'review/review' )->getResourceCollection ()->addStoreFilter ( $storeId )->addEntityFilter ( 'product', $productId )->addStatusFilter ( Mage_Review_Model_Review::STATUS_APPROVED )->setDateOrder ( 'desc' )->setPageSize ( $limit )->setCurPage ( $page )->addRateVotes ();
|
228 |
+
|
229 |
+
$response = array ();
|
230 |
+
$reviews = array ();
|
231 |
+
|
232 |
+
if (count ( $reviewcoll ) > 0) {
|
233 |
+
$j = 0;
|
234 |
+
// get all reviews collection
|
235 |
+
foreach ( $reviewcoll->getItems () as $review ) {
|
236 |
+
$reviews [$j] ['title'] = $review->getTitle ();
|
237 |
+
$reviews [$j] ['detail'] = $review->getDetail ();
|
238 |
+
$reviews [$j] ['author'] = $review->getNickname ();
|
239 |
+
$reviews [$j] ['date'] = date ( "Y-m-d", strtotime ( $review->getCreatedAt () ) );
|
240 |
|
241 |
+
$rateAvg = 0;
|
242 |
+
|
243 |
+
foreach ( $review->getRatingVotes () as $vote ) {
|
244 |
+
$rateAvg += $vote->getPercent ();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
}
|
246 |
+
// get summary rating
|
247 |
+
$reviews [$j] [static::RATING] = floor ( $rateAvg / 60 );
|
248 |
+
|
249 |
+
$j ++;
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
$response ['reviews'] = $reviews;
|
254 |
+
return $response;
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* Get product reviews and Rating
|
259 |
+
*
|
260 |
+
* @param int $productId
|
261 |
+
* @param int $storeId
|
262 |
+
*
|
263 |
+
* @return array $response
|
264 |
+
*/
|
265 |
+
public function getRatingResult($productId, $storeId) {
|
266 |
+
$reviewcoll = Mage::getModel ( 'review/review' )->getResourceCollection ()->addStoreFilter ( $storeId )->addEntityFilter ( 'product', $productId )->addStatusFilter ( Mage_Review_Model_Review::STATUS_APPROVED )->setDateOrder ()->addRateVotes ();
|
267 |
+
$response = array ();
|
268 |
+
|
269 |
+
$rate = array ();
|
270 |
+
if (count ( $reviewcoll ) > 0) {
|
271 |
+
$j = 0;
|
272 |
+
// get all reviews collection
|
273 |
+
foreach ( $reviewcoll->getItems () as $review ) {
|
274 |
+
$rateAvg = 0;
|
275 |
+
foreach ( $review->getRatingVotes () as $vote ) {
|
276 |
+
$rateAvg += $vote->getPercent ();
|
277 |
}
|
278 |
+
// get summary rating
|
279 |
+
$rating [$j] = trim ( floor ( $rateAvg / 60 ) );
|
280 |
+
$j ++;
|
281 |
+
}
|
282 |
+
// get rating count summary
|
283 |
+
$rating = array_count_values ( $rating );
|
284 |
+
for($k = 1; $k <= 5; $k ++) {
|
285 |
+
$ratingCount ['star'] = $k;
|
286 |
+
$ratingCount ['count'] = ($rating [$k] > 0 ? $rating [$k] : 0);
|
287 |
+
$rate [] = $ratingCount;
|
288 |
+
}
|
289 |
+
}
|
290 |
+
|
291 |
+
$response [static::RATING] = $rate;
|
292 |
+
return $response;
|
293 |
+
}
|
294 |
+
|
295 |
+
/**
|
296 |
+
* Get stock detail for product
|
297 |
+
*
|
298 |
+
* @param object $product
|
299 |
+
* @return array $_proudct_data
|
300 |
+
*/
|
301 |
+
public function getStockDetail($product) {
|
302 |
+
$_proudct_data = array ();
|
303 |
+
|
304 |
+
/**
|
305 |
+
* get stock details for product
|
306 |
+
*
|
307 |
+
* @var $stockItem Mage_CatalogInventory_Model_Stock_Item
|
308 |
+
*/
|
309 |
+
$stockItem = Mage::getModel ( static::CATALOG_STOCK )->loadByProduct ( $product->getId () );
|
310 |
+
if ($product->getTypeId () != static::CONFIGURABLE) {
|
311 |
+
$_proudct_data [static::IS_SALABLE] = ($product->getIsSalable () > 0);
|
312 |
+
$_proudct_data [static::IS_STOCK] = ($stockItem->getIsInStock () > 0);
|
313 |
+
}
|
314 |
+
/**
|
315 |
+
* get stock details for product
|
316 |
+
*
|
317 |
+
* @var $stockItem Mage_CatalogInventory_Model_Stock_Item
|
318 |
+
*/
|
319 |
+
$instock_childrenisinstock = false;
|
320 |
+
|
321 |
+
if ($product->getTypeId () == static::CONFIGURABLE) {
|
322 |
+
|
323 |
+
/**
|
324 |
+
* Get children products (all associated children products data)
|
325 |
+
*/
|
326 |
+
$childProducts = Mage::getModel ( 'catalog/product_type_configurable' )->getUsedProducts ( null, $product );
|
327 |
+
|
328 |
+
$stockItem = $product->getStockItem ();
|
329 |
+
|
330 |
+
// get associated product stock detail
|
331 |
+
$instock_childrenisinstock = $this->getChildStock ( $stockItem, $childProducts );
|
332 |
+
|
333 |
+
if (! $instock_childrenisinstock) {
|
334 |
+
$_proudct_data [static::IS_SALABLE] = false;
|
335 |
+
$_proudct_data [static::IS_STOCK] = false;
|
336 |
+
} else {
|
337 |
+
$_proudct_data [static::IS_SALABLE] = true;
|
338 |
+
$_proudct_data [static::IS_STOCK] = true;
|
339 |
+
}
|
340 |
+
}
|
341 |
+
|
342 |
+
return $_proudct_data;
|
343 |
+
}
|
344 |
+
|
345 |
+
/**
|
346 |
+
* Get associated product stock
|
347 |
+
*
|
348 |
+
* @param object $stockItem
|
349 |
+
* @param array $childProducts
|
350 |
+
* @return boolean true| false
|
351 |
+
*/
|
352 |
+
public function getChildStock($stockItem, $childProducts) {
|
353 |
+
$instock_childrenisinstock = false;
|
354 |
+
if ($stockItem->getIsInStock ()) {
|
355 |
+
/**
|
356 |
+
* All configurable products, which are in stock
|
357 |
+
*/
|
358 |
+
|
359 |
+
foreach ( $childProducts as $childProduct ) {
|
360 |
+
$child_stockItem = $childProduct->getStockItem ();
|
361 |
+
Mage::getModel ( static::CATALOG_STOCK )->loadByProduct ( $childProduct );
|
362 |
+
if ($child_stockItem->getIsInStock ()) {
|
363 |
+
$instock_childrenisinstock = true;
|
364 |
}
|
365 |
+
}
|
366 |
+
}
|
367 |
+
return $instock_childrenisinstock;
|
368 |
+
}
|
369 |
+
|
370 |
+
/**
|
371 |
+
* Get Cart Amount Details
|
372 |
+
*
|
373 |
+
* @param array $data
|
374 |
+
* @return array $response
|
375 |
+
*/
|
376 |
+
public function getCartTotal($data) {
|
377 |
+
// get customer id
|
378 |
+
$customerId = $data [static::CUSTOMERID];
|
379 |
+
// get category id
|
380 |
+
$storeId = $data [static::STOREID];
|
381 |
+
$quoteData = $this->getQuoteIdBycustomer ( $customerId, $storeId );
|
382 |
+
$quoteId = $quoteData [0] [static::ENTITYID];
|
383 |
+
$cartTotal = array ();
|
384 |
+
$quote = $this->_getQuote ( $quoteId, $storeId );
|
385 |
+
$totals = $quote->getTotals ();
|
386 |
+
if (isset ( $totals [static::DISCOUNT] )) {
|
387 |
+
$discount = number_format ( abs ( $totals [static::DISCOUNT]->getValue () ), 2, '.', '' );
|
388 |
+
} else {
|
389 |
+
$discount = '';
|
390 |
+
}
|
391 |
+
// get system/configuration -checkout - cart liks value
|
392 |
+
$cartLink = Mage::getStoreConfig ( static::CHECKOUT_CART_QTY, $storeId );
|
393 |
+
if (isset ( $quoteData ) && ! empty ( $quoteData )) {
|
394 |
+
|
395 |
+
if ($cartLink) {
|
396 |
+
// Display Cart Summary - Display item quantities
|
397 |
+
$itemCount = strval ( floatval ( $quoteData [0] [static::ITEMS_QTY] ) );
|
398 |
+
} else {
|
399 |
+
// Display Cart Summary - Display no.of items in cart
|
400 |
+
$itemCount = strval ( $quoteData [0] [static::ITEMS_COUNT] );
|
401 |
+
}
|
402 |
+
|
403 |
+
$cartTotal [static::ITEM_COUNT] = $itemCount;
|
404 |
+
$cartTotal [static::GRAND_TOTAL] = number_format ( $quoteData [0] [static::GRAND_TOTAL], 2, '.', '' );
|
405 |
+
$cartTotal [static::SUBTOTAL] = number_format ( $quoteData [0] [static::SUBTOTAL], 2, '.', '' );
|
406 |
+
$cartTotal [static::DISCOUNT] = $discount;
|
407 |
+
$cartTotal [static::QUOTE_ID] = $quoteId;
|
408 |
+
$cartTotal [static::COUPON_CODE] = $quoteData [0] [static::COUPON_CODE];
|
409 |
+
$addressobj = $quote->getShippingAddress ();
|
410 |
+
$cartTotal [static::SHIPPING_AMT] = 0;
|
411 |
+
$cartTotal [static::TAX] = 0;
|
412 |
+
if ($addressobj) {
|
413 |
+
$cartTotal [static::SHIPPING_AMT] = $quote->getShippingAddress ()->getData ( static::SHIPPING_AMT );
|
414 |
+
$cartTotal [static::TAX] = $quote->getShippingAddress ()->getData ( 'tax_amount' );
|
415 |
+
$cartTotal [static::SHIPPING_AMT] = number_format ( $cartTotal [static::SHIPPING_AMT], 2, '.', '' );
|
416 |
+
$cartTotal [static::TAX] = number_format ( $cartTotal ['tax'], 2, '.', '' );
|
417 |
+
}
|
418 |
+
} else {
|
419 |
+
|
420 |
+
$message = 'No items in your cart.';
|
421 |
+
}
|
422 |
+
$response [static::ITEM_COUNT] = $itemCount;
|
423 |
+
$response ['result'] = $cartTotal;
|
424 |
+
$response [static::SUCCESS] = false;
|
425 |
+
$response [static::MESSAGE] = $message;
|
426 |
+
return $response;
|
427 |
+
}
|
428 |
+
|
429 |
+
/**
|
430 |
+
* Get Quote data by customer
|
431 |
+
*
|
432 |
+
* @param int $customerId
|
433 |
+
* @param int $storeId
|
434 |
+
* @return array $quoteData
|
435 |
+
*/
|
436 |
+
public function getQuoteIdBycustomer($customerId, $storeId) {
|
437 |
+
$quote = Mage::getModel ( static::SLAES_QUOTE )->getCollection ()->addFieldToFilter ( static::CUSTOMERID, $customerId )->addFieldToFilter ( static::STOREID, $storeId )->addFieldToFilter ( static::IS_ACTIVE, '1' )->setOrder ( static::ENTITYID, 'desc' );
|
438 |
+
return $quote->getData ();
|
439 |
+
}
|
440 |
+
|
441 |
+
/**
|
442 |
+
*
|
443 |
+
* @param integer $quoteId
|
444 |
+
* @param integer $storeId
|
445 |
+
* @return mixed array $quote
|
446 |
+
*/
|
447 |
+
protected function _getQuote($quoteId, $storeId) {
|
448 |
+
/**
|
449 |
+
*
|
450 |
+
* @var $quote Mage_Sales_Model_Quote
|
451 |
+
*/
|
452 |
+
$quote = Mage::getModel ( static::SLAES_QUOTE );
|
453 |
+
$quote->setStoreId ( $storeId )->load ( $quoteId );
|
454 |
+
return $quote;
|
455 |
+
}
|
456 |
+
|
457 |
+
/**
|
458 |
+
* Get cart quote by customer
|
459 |
+
*
|
460 |
+
* @param int $customerId
|
461 |
+
* @param in $storeId
|
462 |
+
* @return object $$quote
|
463 |
+
*/
|
464 |
+
public function setSaleQuoteByCustomer($customerId, $storeId, $currencyCode) {
|
465 |
+
/**
|
466 |
+
*
|
467 |
+
* @var $quote Mage_Sales_Model_Quote
|
468 |
+
*/
|
469 |
+
$quote = Mage::getModel ( static::SLAES_QUOTE )->getCollection ()->addFieldToFilter ( static::CUSTOMERID, $customerId )->addFieldToFilter ( static::STOREID, $storeId )->addFieldToFilter ( static::IS_ACTIVE, '1' )->setOrder ( static::ENTITYID, 'desc' );
|
470 |
+
$quoteData = $quote->getData ();
|
471 |
+
|
472 |
+
// get base currency code
|
473 |
+
$baseCurrency = Mage::app ()->getBaseCurrencyCode ();
|
474 |
+
// get default currency code
|
475 |
+
$defaultCurrency = Mage::app ()->getStore ( $storeId )->getDefaultCurrencyCode ();
|
476 |
+
if (! $currencyCode) {
|
477 |
+
$currencyCode = $defaultCurrency;
|
478 |
+
}
|
479 |
+
// get all allowed currnecy codess
|
480 |
+
$allowedCurrencies = Mage::getModel ( 'directory/currency' )->getConfigAllowCurrencies ();
|
481 |
+
// get base currency rate
|
482 |
+
$baseCurrencyRates = Mage::getModel ( 'directory/currency' )->getCurrencyRates ( $baseCurrency, array_values ( $allowedCurrencies ) );
|
483 |
+
Mage::log ( 'base currency:' . $baseCurrency );
|
484 |
+
Mage::log ( ' currency:' . $currencyCode );
|
485 |
+
Mage::log ( ' StoreToBaseRate:' . $baseCurrencyRates [$baseCurrency] );
|
486 |
+
Mage::log ( ' StoreToQuoteRate:' . $baseCurrencyRates [$currencyCode] );
|
487 |
+
Mage::log ( ' BaseToGlobalRate:' . $baseCurrencyRates [$baseCurrency] );
|
488 |
+
Mage::log ( ' BaseToQuoteRate:' . $baseCurrencyRates [$currencyCode] );
|
489 |
+
|
490 |
+
if (empty ( $quoteData )) {
|
491 |
+
$quote = Mage::getModel ( static::SLAES_QUOTE );
|
492 |
+
$customer = Mage::getModel ( static::CUSTOMER_CUSTOMER )->load ( $customerId );
|
493 |
+
// Check this customer id is in record
|
494 |
+
if ($customer->getId ()) {
|
495 |
+
$quote->assignCustomer ( $customer );
|
496 |
+
$quote->setStore_id ( $storeId );
|
497 |
|
498 |
+
$quote->setGlobalCurrencyCode ( $currencyCode );
|
499 |
+
$quote->setBaseCurrencyCode ( $baseCurrency );
|
500 |
+
$quote->setStoreCurrencyCode ( $baseCurrency );
|
501 |
+
$quote->setQuoteCurrencyCode ( $currencyCode );
|
502 |
|
503 |
+
$quote->setStoreToBaseRate ( $baseCurrencyRates [$baseCurrency] );
|
504 |
+
$quote->setStoreToQuoteRate ( $baseCurrencyRates [$currencyCode] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
505 |
|
506 |
+
$quote->setBaseToGlobalRate ( $baseCurrencyRates [$baseCurrency] );
|
507 |
+
$quote->setBaseToQuoteRate ( $baseCurrencyRates [$currencyCode] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
508 |
|
509 |
+
$quote->setCustomerId ( $customerId )->setUpdatedAt ( now () )->setCreatedAt ( now () );
|
510 |
+
$quote->setCustomerEmail ( $customer->getEmail () )->setCustomerFirstname ( $customer->getFirstname () )->setCustomerLastname ( $customer->getLastname () )->setCustomerIsGuest ( 0 )->setCustomer ( $customer );
|
511 |
+
$quote->save ();
|
512 |
+
} else {
|
513 |
+
$quote = 0;
|
514 |
+
}
|
515 |
+
} else {
|
516 |
+
$quote = Mage::getModel ( static::SLAES_QUOTE );
|
517 |
+
$quote->setStoreId ( $storeId )->load ( $quoteData [0] [static::ENTITYID] );
|
518 |
+
$quote->setGlobalCurrencyCode ( $currencyCode );
|
519 |
+
$quote->setBaseCurrencyCode ( $baseCurrency );
|
520 |
+
$quote->setStoreCurrencyCode ( $baseCurrency );
|
521 |
+
$quote->setQuoteCurrencyCode ( $currencyCode );
|
522 |
+
|
523 |
+
$quote->setStoreToBaseRate ( $baseCurrencyRates );
|
524 |
+
$quote->setStoreToQuoteRate ( $baseCurrencyRates [$currencyCode] );
|
525 |
+
|
526 |
+
$quote->setBaseToGlobalRate ( $baseCurrencyRates );
|
527 |
+
$quote->setBaseToQuoteRate ( $baseCurrencyRates [$currencyCode] );
|
528 |
+
$quote->setUpdatedAt ( now () );
|
529 |
+
}
|
530 |
+
return $quote;
|
531 |
+
}
|
532 |
+
|
533 |
+
/**
|
534 |
+
*
|
535 |
+
* @param Mage_Sales_Model_Quote $quote
|
536 |
+
* @param Mage_Catalog_Model_Product $product
|
537 |
+
* @param Varien_Object $requestInfo
|
538 |
+
* @return Varien_Object
|
539 |
+
*/
|
540 |
+
public function _getQuoteItemByProduct(Mage_Sales_Model_Quote $quote, Mage_Catalog_Model_Product $product, Varien_Object $requestInfo) {
|
541 |
+
$cartCandidates = $product->getTypeInstance ( TRUE )->prepareForCartAdvanced ( $requestInfo, $product, Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_FULL );
|
542 |
+
/**
|
543 |
+
* Error message
|
544 |
+
*/
|
545 |
+
if (is_string ( $cartCandidates )) {
|
546 |
+
throw Mage::throwException ( $cartCandidates );
|
547 |
+
}
|
548 |
+
|
549 |
+
/**
|
550 |
+
* If prepare process return one object
|
551 |
+
*/
|
552 |
+
if (! is_array ( $cartCandidates )) {
|
553 |
+
$cartCandidates = array (
|
554 |
+
$cartCandidates
|
555 |
+
);
|
556 |
+
}
|
557 |
+
|
558 |
+
/**
|
559 |
+
*
|
560 |
+
* @var $item Mage_Sales_Model_Quote_Item
|
561 |
+
*/
|
562 |
+
$item = NULL;
|
563 |
+
foreach ( $cartCandidates as $candidate ) {
|
564 |
+
if ($candidate->getParentProductId ()) {
|
565 |
+
Mage::log ( 'productID' . $candidate->getParentProductId () );
|
566 |
+
continue;
|
567 |
+
}
|
568 |
+
|
569 |
+
$item = $quote->getItemByProduct ( $candidate );
|
570 |
+
}
|
571 |
+
|
572 |
+
if (is_null ( $item )) {
|
573 |
+
$item = Mage::getModel ( 'sales/quote_item' );
|
574 |
+
}
|
575 |
+
|
576 |
+
return $item;
|
577 |
+
}
|
578 |
+
|
579 |
+
/**
|
580 |
+
*
|
581 |
+
* @param array $requestInfo
|
582 |
+
* @return Varien_Object
|
583 |
+
*/
|
584 |
+
public function _getProductRequest($requestInfo) {
|
585 |
+
if ($requestInfo instanceof Varien_Object) {
|
586 |
+
$request = $requestInfo;
|
587 |
+
} elseif (is_numeric ( $requestInfo )) {
|
588 |
+
Mage::log ( 'else in product request' );
|
589 |
+
$request = new Varien_Object ();
|
590 |
+
$request->setQty ( $requestInfo );
|
591 |
+
} else {
|
592 |
+
$request = new Varien_Object ( $requestInfo );
|
593 |
+
}
|
594 |
+
|
595 |
+
if (! $request->hasQty ()) {
|
596 |
+
$request->setQty ( 1 );
|
597 |
+
}
|
598 |
+
|
599 |
+
return $request;
|
600 |
+
}
|
601 |
+
|
602 |
+
/**
|
603 |
+
* Get Cart product details
|
604 |
+
*
|
605 |
+
* @param array $data
|
606 |
+
* @return array $response
|
607 |
+
*/
|
608 |
+
public function getCartProducts($data) {
|
609 |
+
|
610 |
+
// get category id
|
611 |
+
$storeId = $data [static::STOREID];
|
612 |
+
// get customer id
|
613 |
+
$customerId = $data [static::CUSTOMERID];
|
614 |
+
|
615 |
+
$quoteData = $this->getQuoteIdBycustomer ( $customerId, $storeId );
|
616 |
+
$quoteId = $quoteData [0] [static::ENTITYID];
|
617 |
+
|
618 |
+
$quote = $this->_getQuote ( $quoteId, $storeId );
|
619 |
+
$totals = $quote->getTotals ();
|
620 |
+
if (isset ( $totals [static::DISCOUNT] )) {
|
621 |
+
$discount = number_format ( abs ( $totals [static::DISCOUNT]->getValue () ), 2, '.', '' );
|
622 |
+
} else {
|
623 |
+
$discount = '';
|
624 |
+
}
|
625 |
+
// get system/configuration -checkout - cart liks value
|
626 |
+
$cartLink = Mage::getStoreConfig ( static::CHECKOUT_CART_QTY, $storeId );
|
627 |
+
$returnArray = array ();
|
628 |
+
$returnArray ['items'] = array ();
|
629 |
+
$items = array ();
|
630 |
+
if (isset ( $quoteData ) && ! empty ( $quoteData )) {
|
631 |
+
|
632 |
+
$itemCount = $quoteData [0] [static::ITEMS_COUNT];
|
633 |
+
if ($itemCount > 0) {
|
634 |
if ($cartLink) {
|
635 |
+
// Display Cart Summary - Display item quantities
|
636 |
+
$itemCount = strval ( floatval ( $quoteData [0] [static::ITEMS_QTY] ) );
|
637 |
} else {
|
638 |
+
// Display Cart Summary - Display no.of items in cart
|
639 |
+
$itemCount = strval ( $quoteData [0] [static::ITEMS_COUNT] );
|
640 |
}
|
641 |
+
$returnArray [static::ITEM_COUNT] = $itemCount;
|
642 |
+
$returnArray [static::SHIPPING_AMT] = 0;
|
643 |
+
$returnArray [static::TAX] = 0;
|
644 |
+
$returnArray [static::GRAND_TOTAL] = number_format ( $quoteData [0] [static::GRAND_TOTAL], 2, '.', '' );
|
645 |
+
$returnArray [static::SUBTOTAL] = number_format ( $quoteData [0] [static::SUBTOTAL], 2, '.', '' );
|
646 |
+
$returnArray [static::DISCOUNT] = $discount;
|
647 |
+
$returnArray [static::QUOTE_ID] = $quoteId;
|
648 |
+
$returnArray [static::COUPON_CODE] = $quoteData [0] [static::COUPON_CODE];
|
649 |
$addressobj = $quote->getShippingAddress ();
|
650 |
+
|
|
|
651 |
if ($addressobj) {
|
652 |
+
$returnArray [static::SHIPPING_AMT] = $quote->getShippingAddress ()->getData ( static::SHIPPING_AMT );
|
653 |
+
$returnArray [static::TAX] = $quote->getShippingAddress ()->getData ( 'tax_amount' );
|
654 |
+
$returnArray [static::SHIPPING_AMT] = number_format ( $returnArray [static::SHIPPING_AMT], 2, '.', '' );
|
655 |
+
$returnArray [static::TAX] = number_format ( $returnArray ['tax'], 2, '.', '' );
|
656 |
}
|
|
|
657 |
|
658 |
+
$i = 0;
|
659 |
+
foreach ( $quote->getAllVisibleItems () as $item ) {
|
660 |
+
$product = $item->getProduct ();
|
661 |
+
$product->setStoreId ( $storeId )->load ( $product->getId () );
|
662 |
+
$items [$i] ['type_id'] = $item->getProductType ();
|
663 |
+
$items [$i] ['item_id_test'] = $item->getItemId ();
|
664 |
+
// get product id
|
665 |
+
$items [$i] [static::ENTITYID] = $product->getEntityId ();
|
666 |
+
// get product name
|
667 |
+
$items [$i] ['name'] = $product->getName ();
|
668 |
+
// get product image
|
669 |
+
$items [$i] ['image_url'] = ( string ) Mage::helper ( 'catalog/image' )->init ( $product, 'small_image' );
|
670 |
+
// get product price
|
671 |
+
$items [$i] ['price'] = number_format ( $item->getPrice (), 2, '.', '' );
|
672 |
+
// get product qty
|
673 |
+
$items [$i] [static::QTY] = $item->getQty ();
|
674 |
+
// get product row total
|
675 |
+
$items [$i] ['row_total'] = number_format ( $item->getRowTotal (), 2, '.', '' );
|
676 |
+
|
677 |
+
$stockDetail = $this->getProductStock ( $product, $item );
|
678 |
+
$items [$i] [static::STOCK_QTY] = $stockDetail [static::STOCK_QTY];
|
679 |
+
$items [$i] [static::IS_STOCK] = $stockDetail [static::IS_STOCK];
|
680 |
+
$items [$i] [static::MIN_SALE_QTY] = $stockDetail [static::MIN_SALE_QTY];
|
681 |
+
$items [$i] [static::MAX_SALE_QTY] = $stockDetail [static::MAX_SALE_QTY];
|
682 |
+
$items [$i] [static::QTY_INCR] = $stockDetail [static::QTY_INCR];
|
683 |
+
$items [$i] [static::IS_QTY_DECIAML] = $stockDetail [static::IS_QTY_DECIAML];
|
684 |
+
$items [$i] ['config'] = Mage::getModel ( 'catalog/product_type_configurable' )->getOrderOptions ( $product );
|
685 |
+
$i ++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
686 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
687 |
|
688 |
+
$returnArray ['items'] = $items;
|
689 |
+
$returnArray ['address'] = $this->getAddressByCustomer ( $customerId );
|
690 |
+
$error = false;
|
691 |
+
$message = 'Quote fetched successfully.';
|
692 |
+
} else {
|
693 |
+
$error = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
694 |
$message = static::NO_ITEM;
|
695 |
+
}
|
696 |
+
} else {
|
697 |
+
$error = true;
|
698 |
+
$message = static::NO_ITEM;
|
699 |
+
}
|
700 |
+
$response [static::ITEM_COUNT] = $itemCount;
|
701 |
+
$response [static::RESULT] = $returnArray;
|
702 |
+
$response [static::SUCCESS] = $error;
|
703 |
+
$response [static::MESSAGE] = $message;
|
704 |
+
return $response;
|
705 |
+
}
|
706 |
+
|
707 |
+
/**
|
708 |
+
* Get product stock details
|
709 |
+
*
|
710 |
+
* @param object $product
|
711 |
+
* @param object $item
|
712 |
+
* @return array $items
|
713 |
+
*/
|
714 |
+
public function getProductStock($product, $item) {
|
715 |
+
$items = array ();
|
716 |
+
if ($product->getTypeId () != static::CONFIGURABLE) {
|
717 |
+
// get product availabile qty
|
718 |
+
$items [static::STOCK_QTY] = floatval ( Mage::getModel ( static::CATALOG_STOCK )->loadByProduct ( $product )->getQty () );
|
719 |
+
$stockItem = $product->getStockItem ();
|
720 |
+
if (! $stockItem) {
|
721 |
+
$stockItem = Mage::getModel ( static::CATALOG_STOCK );
|
722 |
+
$stockItem->loadByProduct ( $product );
|
723 |
+
}
|
724 |
+
// get product stock status
|
725 |
+
$items [static::IS_STOCK] = ($stockItem->getIsInStock () > 0);
|
726 |
+
|
727 |
+
// get product stock details
|
728 |
+
$inventoryDetail = Mage::getModel ( 'login/methods_functions' )->getinventoryDetail ( $product, $storeId );
|
729 |
+
} else {
|
730 |
+
|
731 |
+
$asso_productId = intval ( preg_replace ( '/[^0-9]+/', '', json_encode ( $item->getQtyOptions () ) ), 10 );
|
732 |
+
// get simple product stock status
|
733 |
+
$stockLevel = Mage::getModel ( static::CATALOG_STOCK )->loadByProduct ( $asso_productId );
|
734 |
+
$items [static::STOCK_QTY] = floatval ( $stockLevel->getQty () );
|
735 |
+
// get stock details for product
|
736 |
+
// get config product stock status
|
737 |
+
$stockItem = Mage::getModel ( static::CATALOG_STOCK )->loadByProduct ( $product->getId () );
|
738 |
+
if ($stockLevel->getIsInStock () == 1 && $stockItem->getIsInStock () == 1) {
|
739 |
+
$items [static::IS_STOCK] = true;
|
740 |
+
} else {
|
741 |
+
$items [static::IS_STOCK] = false;
|
742 |
+
}
|
743 |
+
//load product by associate product id
|
744 |
+
$simpleProduct = Mage::getModel ( 'catalog/product' )->load ( $asso_productId );
|
745 |
+
// get product stock details
|
746 |
+
$inventoryDetail = Mage::getModel ( 'login/methods_functions' )->getinventoryDetail ( $simpleProduct, $storeId );
|
747 |
+
}
|
748 |
+
//get min sale qty
|
749 |
+
$items [static::MIN_SALE_QTY] = $inventoryDetail [static::MIN_SALE_QTY];
|
750 |
+
//get max sale qty
|
751 |
+
$items [static::MAX_SALE_QTY] = $inventoryDetail [static::MAX_SALE_QTY];
|
752 |
+
//get qty incremnet qty in cart
|
753 |
+
$items [static::QTY_INCR] = $inventoryDetail [static::QTY_INCR];
|
754 |
+
$items [static::IS_QTY_DECIAML] = $inventoryDetail [static::IS_QTY_DECIAML];
|
755 |
+
return $items;
|
756 |
+
}
|
757 |
+
/**
|
758 |
+
* Get customer default billing and shipping address
|
759 |
+
*
|
760 |
+
* @param int $customerId
|
761 |
+
*/
|
762 |
+
public function getAddressByCustomer($customerId) {
|
763 |
+
$address = array ();
|
764 |
+
$customerObj = Mage::getModel ( 'customer/customer' )->load ( $customerId );
|
765 |
+
|
766 |
+
// get customer default billing address
|
767 |
+
$billingAddress = $customerObj->getDefaultBillingAddress ();
|
768 |
+
if ($billingAddress) {
|
769 |
+
$country = Mage::getModel ( 'directory/country' )->loadByCode ( $billingAddress->country_id );
|
770 |
+
$billingAddress->setData ( 'country_name', $country->getName () );
|
771 |
+
$address [static::BILLING] = $billingAddress->getData ();
|
772 |
+
$address [static::BILLING] ['street'] = $billingAddress->getStreet ();
|
773 |
+
$address [static::BILLING] ['region_code'] = $billingAddress->getRegionCode ();
|
774 |
+
$address ['is_billing'] = true;
|
775 |
+
} else {
|
776 |
+
$address ['is_billing'] = false;
|
777 |
+
}
|
778 |
+
// get customer default shipping address
|
779 |
+
$shippingAddress = $customerObj->getDefaultShippingAddress ();
|
780 |
+
if ($shippingAddress) {
|
781 |
+
$country = Mage::getModel ( 'directory/country' )->loadByCode ( $shippingAddress->country_id );
|
782 |
+
$shippingAddress->setData ( 'country_name', $country->getName () );
|
783 |
+
$address [static::SHIPPING] = $shippingAddress->getData ();
|
784 |
+
$address [static::SHIPPING] ['street'] = $shippingAddress->getStreet ();
|
785 |
+
$address [static::SHIPPING] ['region_code'] = $shippingAddress->getRegionCode ();
|
786 |
+
$address ['is_shipping'] = true;
|
787 |
+
} else {
|
788 |
+
$address ['is_shipping'] = false;
|
789 |
+
}
|
790 |
+
|
791 |
+
return $address;
|
792 |
+
}
|
793 |
}
|
app/code/local/ContusRestapi/Login/etc/config.xml
CHANGED
@@ -22,7 +22,7 @@
|
|
22 |
<class>ContusRestapi_Login_Model_Resource</class>
|
23 |
<entities>
|
24 |
<token>
|
25 |
-
<table>
|
26 |
</token>
|
27 |
</entities>
|
28 |
</login_resource>
|
22 |
<class>ContusRestapi_Login_Model_Resource</class>
|
23 |
<entities>
|
24 |
<token>
|
25 |
+
<table>mcomm_token</table>
|
26 |
</token>
|
27 |
</entities>
|
28 |
</login_resource>
|
app/code/local/ContusRestapi/Login/sql/login_setup/install-0.0.1.php
CHANGED
@@ -12,9 +12,9 @@
|
|
12 |
|
13 |
$installer = $this;
|
14 |
|
15 |
-
$installer->run ( "DROP TABLE IF EXISTS " . $installer->getTable ( '
|
16 |
|
17 |
-
$token = $installer->getConnection ()->newTable ( $installer->getTable ( '
|
18 |
'unsigned' => TRUE,
|
19 |
'identity' => TRUE,
|
20 |
'nullable' => FALSE,
|
12 |
|
13 |
$installer = $this;
|
14 |
|
15 |
+
$installer->run ( "DROP TABLE IF EXISTS " . $installer->getTable ( 'mcomm_token' ) );
|
16 |
|
17 |
+
$token = $installer->getConnection ()->newTable ( $installer->getTable ( 'mcomm_token' ) )->addColumn ( 'tokenid', Varien_Db_Ddl_Table::TYPE_INTEGER, NULL, array (
|
18 |
'unsigned' => TRUE,
|
19 |
'identity' => TRUE,
|
20 |
'nullable' => FALSE,
|
app/code/local/ContusRestapi/MultiCartapi/Model/Api2/MultiCartapi.php
CHANGED
@@ -29,385 +29,406 @@
|
|
29 |
* @since 1.0
|
30 |
*/
|
31 |
class ContusRestapi_MultiCartapi_Model_Api2_MultiCartapi extends Mage_Api2_Model_Resource {
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
$
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
}
|
|
|
|
|
|
|
|
|
117 |
$quote->collectTotals ();
|
118 |
$quote->save ();
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
-
if (
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
$error_flag = true;
|
180 |
-
|
181 |
-
foreach ( $products as $item ) {
|
182 |
-
$quote = Mage::getModel ( static::SLAES_QUOTE );
|
183 |
-
$quote->setStoreId ( $storeId )->load ( $quoteId );
|
184 |
-
$productByItem = $this->_getProduct ( $item [static::PRODUCT_ID], $storeId, 'id' );
|
185 |
-
|
186 |
-
if (is_null ( $productByItem )) {
|
187 |
-
|
188 |
-
$messages [$i] [static::UPDATED] = 0;
|
189 |
-
$messages [$i] [static::MESSAGE] = 'Item is not available.';
|
190 |
-
$error_flag = false;
|
191 |
-
} else {
|
192 |
-
$productItem = $this->updateToCart ( $productByItem, $quote, $item [static::QTY], $item );
|
193 |
-
$quoteItem = Mage::getModel ( static::LOGIN_TOKEN )->_getQuoteItemByProduct ( $quote, $productByItem, Mage::getModel ( static::LOGIN_TOKEN )->_getProductRequest ( $productItem ) );
|
194 |
-
|
195 |
-
$update = $this->cartUpdate ( $quoteItem, $quote, $item [static::QTY] );
|
196 |
-
$messages [$i] [static::UPDATED] = $update [static::SUCCESS];
|
197 |
-
$messages [$i] [static::MESSAGE] = $productByItem->getName () . '- ' . $update [static::MESSAGE];
|
198 |
-
}
|
199 |
-
if ($messages [$i] [static::UPDATED] == 0) {
|
200 |
-
$error_flag = false;
|
201 |
-
}
|
202 |
-
|
203 |
-
$i ++;
|
204 |
-
$success = 1;
|
205 |
-
}
|
206 |
-
if ($error_flag) {
|
207 |
-
$success = 1;
|
208 |
-
$message = 'Cart updated successfully.';
|
209 |
} else {
|
210 |
-
|
211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
}
|
213 |
-
} catch ( Mage_Core_Exception $e ) {
|
214 |
|
215 |
-
$
|
216 |
-
$success =
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
) );
|
223 |
-
$response [static::ERROR] = false;
|
224 |
-
|
225 |
-
$response [static::SUCCESS] = $success;
|
226 |
-
$response [static::VALID_TOKEN] = $isValidToken;
|
227 |
-
$response [static::MESSAGE] = $message;
|
228 |
-
$response [static::RESULT] = $prodctsList [static::RESULT];
|
229 |
-
$response [static::RESULT] ['errors'] = $messages;
|
230 |
-
$this->getResponse ()->setBody ( json_encode ( $response ) );
|
231 |
-
|
232 |
-
return;
|
233 |
-
}
|
234 |
-
|
235 |
-
/**
|
236 |
-
* Get product details
|
237 |
-
*
|
238 |
-
* @param integer $productId
|
239 |
-
* @param string $store
|
240 |
-
* @param string $identifierType
|
241 |
-
* @return NULL array
|
242 |
-
*/
|
243 |
-
public function _getProduct($productId, $store = NULL, $identifierType = NULL) {
|
244 |
-
|
245 |
-
/**
|
246 |
-
*
|
247 |
-
* @var $product Mage_Catalog_Model_Product
|
248 |
-
*/
|
249 |
-
$product = Mage::helper ( 'catalog/product' )->getProduct ( $productId, $store, $identifierType );
|
250 |
-
if (! $product->getId ()) {
|
251 |
-
return NULL;
|
252 |
-
}
|
253 |
-
|
254 |
-
return $product;
|
255 |
-
}
|
256 |
-
|
257 |
-
/**
|
258 |
-
*
|
259 |
-
* @param integer $quoteId
|
260 |
-
* @param integer $storeId
|
261 |
-
* @return mixed array $quote
|
262 |
-
*/
|
263 |
-
protected function _getQuote($quoteId, $storeId) {
|
264 |
-
/**
|
265 |
-
*
|
266 |
-
* @var $quote Mage_Sales_Model_Quote
|
267 |
-
*/
|
268 |
-
$quote = Mage::getModel ( static::SLAES_QUOTE );
|
269 |
-
$quote->setStoreId ( $storeId )->load ( $quoteId );
|
270 |
-
return $quote;
|
271 |
-
}
|
272 |
-
|
273 |
-
/**
|
274 |
-
* Get Quote data by customer
|
275 |
-
*
|
276 |
-
* @param int $customerId
|
277 |
-
* @param int $storeId
|
278 |
-
* @return array $quoteData
|
279 |
-
*/
|
280 |
-
public function getQuoteIdBycustomer($customerId, $storeId) {
|
281 |
-
$quote = Mage::getModel ( static::SLAES_QUOTE )->getCollection ()->addFieldToFilter ( static::CUSTOMER_ID, $customerId )->addFieldToFilter ( static::STOREID, $storeId )->addFieldToFilter ( 'is_active', '1' )->setOrder ( static::ENTITYID, 'desc' );
|
282 |
-
return $quote->getData ();
|
283 |
-
}
|
284 |
-
|
285 |
-
/**
|
286 |
-
* Add product to cart
|
287 |
-
*
|
288 |
-
* @param object $product
|
289 |
-
* @param object $quote
|
290 |
-
* @param int $qty
|
291 |
-
* @return $result
|
292 |
-
*/
|
293 |
-
public function addToCart($product, $quote, $qty, $data) {
|
294 |
-
// get product type
|
295 |
-
$type = $product->getTypeId ();
|
296 |
-
switch ($type) {
|
297 |
-
case Mage_Catalog_Model_Product_Type::TYPE_GROUPED :
|
298 |
-
$request_add = new Varien_Object ( array (
|
299 |
-
static::SUPER_GRP => $qty
|
300 |
-
) );
|
301 |
-
$result = $quote->addProduct ( $product, $request_add );
|
302 |
-
break;
|
303 |
-
case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE :
|
304 |
-
$request_add = new Varien_Object ( array (
|
305 |
-
static::SUPER_ATTR => $data [static::SUPER_ATTR],
|
306 |
-
static::OPTIONS => $data [static::CUSTOM_OPTION],
|
307 |
-
static::QTY => $qty
|
308 |
-
) );
|
309 |
-
$result = $quote->addProduct ( $product, $request_add );
|
310 |
-
break;
|
311 |
-
case Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE :
|
312 |
-
$request_add = new Varien_Object ( array (
|
313 |
-
static::LINKS => explode ( ',', $data [static::LINKS] ),
|
314 |
-
static::OPTIONS => $data [static::CUSTOM_OPTION],
|
315 |
-
static::QTY => $qty
|
316 |
-
) );
|
317 |
-
$result = $quote->addProduct ( $product, $request_add );
|
318 |
-
break;
|
319 |
-
default :
|
320 |
-
if (isset ( $data [static::CUSTOM_OPTION] )) {
|
321 |
-
$request_add = new Varien_Object ( array (
|
322 |
-
static::OPTIONS => $data [static::CUSTOM_OPTION],
|
323 |
-
static::QTY => $qty
|
324 |
-
) );
|
325 |
-
}
|
326 |
-
$result = $quote->addProduct ( $product, $request_add );
|
327 |
-
break;
|
328 |
-
}
|
329 |
-
return $result;
|
330 |
-
}
|
331 |
-
|
332 |
-
/**
|
333 |
-
* Update product to cart
|
334 |
-
*
|
335 |
-
* @param object $productByItem
|
336 |
-
* @param object $quote
|
337 |
-
* @param int $qty
|
338 |
-
* @return $result
|
339 |
-
*/
|
340 |
-
public function updateToCart($productByItem, $quote, $qty, $data) {
|
341 |
-
$type = $productByItem->getTypeId ();
|
342 |
-
$updateProduct = '';
|
343 |
-
switch ($type) {
|
344 |
-
case Mage_Catalog_Model_Product_Type::TYPE_GROUPED :
|
345 |
-
$updateProduct = new Varien_Object ( array (
|
346 |
-
static::SUPER_GRP => $qty
|
347 |
-
) );
|
348 |
-
$quote->addProduct ( $product, $request );
|
349 |
-
break;
|
350 |
-
case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE :
|
351 |
-
if (isset ( $data [static::SUPER_ATTR] ) && $data [static::SUPER_ATTR] != '') {
|
352 |
-
$updateProduct = new Varien_Object ( array (
|
353 |
-
static::SUPER_ATTR => json_decode ( $data [static::SUPER_ATTR], true ),
|
354 |
-
static::OPTIONS => json_decode ( $data [static::CUSTOM_OPTION], true ),
|
355 |
-
static::QTY => $qty
|
356 |
-
) );
|
357 |
-
}
|
358 |
-
break;
|
359 |
-
case Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE :
|
360 |
-
if (isset ( $data [static::LINKS] ) && $data [static::LINKS] != '') {
|
361 |
-
$updateProduct = new Varien_Object ( array (
|
362 |
-
static::LINKS => explode ( ',', $data [static::LINKS] ),
|
363 |
-
static::OPTIONS => json_decode ( $data [static::CUSTOM_OPTION], true ),
|
364 |
-
static::QTY => $qty
|
365 |
-
) );
|
366 |
-
}
|
367 |
-
break;
|
368 |
-
default :
|
369 |
-
if (isset ( $data [static::CUSTOM_OPTION] ) && $data [static::CUSTOM_OPTION] != '') {
|
370 |
-
$updateProduct = new Varien_Object ( array (
|
371 |
-
static::OPTIONS => json_decode ( $data [static::CUSTOM_OPTION], true ),
|
372 |
-
static::QTY => $qty
|
373 |
-
) );
|
374 |
-
} else {
|
375 |
-
$updateProduct = '';
|
376 |
-
}
|
377 |
-
break;
|
378 |
-
}
|
379 |
-
|
380 |
-
return $updateProduct;
|
381 |
-
}
|
382 |
-
|
383 |
-
/**
|
384 |
-
* Update product in cart
|
385 |
-
*
|
386 |
-
* @param object $quoteItem
|
387 |
-
* @param object $quote
|
388 |
-
* @return array $response
|
389 |
-
*/
|
390 |
-
public function cartUpdate($quoteProduct, $quote, $qty) {
|
391 |
-
$response = array ();
|
392 |
-
if (empty ( $quoteProduct )) {
|
393 |
$success = 0;
|
394 |
-
$message = '
|
395 |
-
|
396 |
-
|
397 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
398 |
} else {
|
399 |
-
|
400 |
}
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
413 |
}
|
29 |
* @since 1.0
|
30 |
*/
|
31 |
class ContusRestapi_MultiCartapi_Model_Api2_MultiCartapi extends Mage_Api2_Model_Resource {
|
32 |
+
// define staic variable
|
33 |
+
const STOREID = 'store_id';
|
34 |
+
const WEBSITEID = 'website_id';
|
35 |
+
const CUSTOMER_ID = 'customer_id';
|
36 |
+
const ENTITYID = 'entity_id';
|
37 |
+
const PRODUCT_ID = 'product_id';
|
38 |
+
const QUOTE_ID = 'quote_id';
|
39 |
+
const SLAES_QUOTE = 'sales/quote';
|
40 |
+
const SUCCESS = 'success';
|
41 |
+
const MESSAGE = 'message';
|
42 |
+
const ERROR = 'error';
|
43 |
+
const RESULT = 'result';
|
44 |
+
const TOKEN = 'token';
|
45 |
+
const ITEM_COUNT = 'item_count';
|
46 |
+
const ITEMS_COUNT = 'items_count';
|
47 |
+
const LINKS = 'links';
|
48 |
+
const LOGIN_TOKEN = 'login/token';
|
49 |
+
const VALID_TOKEN = 'isValidToken';
|
50 |
+
const AUTH_FAIL = 'Authentication failed.';
|
51 |
+
const CUSTOM_OPTION = 'custom_option';
|
52 |
+
const OPTIONS = 'options';
|
53 |
+
const SUPER_ATTR = 'super_attribute';
|
54 |
+
const SUPER_GRP = 'super_group';
|
55 |
+
const QTY = 'qty';
|
56 |
+
const UPDATED = 'updated';
|
57 |
+
|
58 |
+
/**
|
59 |
+
* function that is called when post is done **
|
60 |
+
* Add product to cart
|
61 |
+
*
|
62 |
+
* @param array $data
|
63 |
+
* @return array json array
|
64 |
+
*/
|
65 |
+
protected function _create(array $data) {
|
66 |
+
$response = array ();
|
67 |
+
$messages = array ();
|
68 |
+
// Get website id
|
69 |
+
$websiteId = (isset ( $data [static::WEBSITEID] )) ? $data [static::WEBSITEID] : Mage::app ()->getWebsite ( 'base' )->getId ();
|
70 |
+
// get store id
|
71 |
+
$storeId = (isset ( $data [static::STOREID] )) ? $data [static::STOREID] : Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
72 |
+
// get customer id
|
73 |
+
$customerId = ( int ) $data [static::CUSTOMER_ID];
|
74 |
+
|
75 |
+
$products = $data ['detail'];
|
76 |
+
// get base currency code
|
77 |
+
$currencyCode = $data ['currencyCode'];
|
78 |
+
// get quote id from request
|
79 |
+
$quoteId = ( int ) $data [static::QUOTE_ID];
|
80 |
+
// get cart quote by customer
|
81 |
+
$quote = Mage::getModel ( static::LOGIN_TOKEN )->setSaleQuoteByCustomer ( $customerId, $storeId, $currencyCode );
|
82 |
+
if ($quoteId <= 0) {
|
83 |
+
$quoteId = $quote->getId ();
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Check this customer has valid token or not
|
88 |
+
*
|
89 |
+
* @var $isValidToken Mage_Login_Model_Token
|
90 |
+
*/
|
91 |
+
$isValidToken = Mage::getModel ( static::LOGIN_TOKEN )->checkUserToken ( $customerId, $data [static::TOKEN] );
|
92 |
+
$error_flag = false;
|
93 |
+
try {
|
94 |
+
|
95 |
+
if (! $isValidToken) {
|
96 |
+
throw new Exception ( static::AUTH_FAIL );
|
97 |
+
}
|
98 |
+
$i = 0;
|
99 |
+
foreach ( $products as $item ) {
|
100 |
+
$product = $this->_getProduct ( $item [static::PRODUCT_ID], $storeId, 'id' );
|
101 |
|
102 |
+
// Note: 1. $item ['flag'] = 1 => for add item to cart
|
103 |
+
// Note: 2. $item ['flag'] = 2 => for update item in cart
|
104 |
+
// check product
|
105 |
+
if (is_null ( $product )) {
|
106 |
+
$messages [$i] [static::SUCCESS] = 0;
|
107 |
+
$messages [$i] [static::MESSAGE] = $item [static::PRODUCT_ID] . ' - Can not specify the product.';
|
108 |
+
$error_flag = false;
|
109 |
+
} elseif ($item ['flag'] == 2) {
|
110 |
+
// update product qty in cart
|
111 |
+
$quote = Mage::getModel ( static::SLAES_QUOTE );
|
112 |
+
$quote->setStoreId ( $storeId )->load ( $quoteId );
|
113 |
+
$productItem = $this->updateToCart ( $product, $quote, $item [static::QTY], $item );
|
114 |
+
$quoteItem = Mage::getModel ( static::LOGIN_TOKEN )->_getQuoteItemByProduct ( $quote, $product, Mage::getModel ( static::LOGIN_TOKEN )->_getProductRequest ( $productItem ) );
|
115 |
+
|
116 |
+
$update = $this->cartUpdate ( $quoteItem, $quote, $item [static::QTY] );
|
117 |
+
$messages [$i] [static::SUCCESS] = $update [static::SUCCESS];
|
118 |
+
$messages [$i] [static::MESSAGE] = $product->getName () . '- ' . $update [static::MESSAGE];
|
119 |
+
$error_flag = true;
|
120 |
+
} else {
|
121 |
+
$quote = Mage::getModel ( static::LOGIN_TOKEN )->setSaleQuoteByCustomer ( $customerId, $storeId, $currencyCode );
|
122 |
+
// add product to cart
|
123 |
+
$error = $this->addToCart ( $product, $quote, $item [static::QTY], $item );
|
124 |
+
if (is_string ( $error )) {
|
125 |
+
$messages [$i] [static::MESSAGE] = $product->getName () . '- ' . $error;
|
126 |
+
$messages [$i] [static::SUCCESS] = 0;
|
127 |
+
$error_flag = false;
|
128 |
+
} else {
|
129 |
+
$messages [$i] [static::MESSAGE] = $product->getName () . ' was added to your cart successfully.';
|
130 |
+
$messages [$i] [static::SUCCESS] = 1;
|
131 |
+
$error_flag = true;
|
132 |
+
}
|
133 |
}
|
134 |
+
|
135 |
+
$i ++;
|
136 |
+
$success = 1;
|
137 |
+
$message = 'Cart add and upadte Successfully';
|
138 |
$quote->collectTotals ();
|
139 |
$quote->save ();
|
140 |
+
}
|
141 |
+
} catch ( Mage_Core_Exception $e ) {
|
142 |
+
$message = $e->getMessage ();
|
143 |
+
$success = 0;
|
144 |
+
$error_flag = false;
|
145 |
+
}
|
146 |
+
|
147 |
+
// get cart product list
|
148 |
+
$prodctsList = Mage::getModel ( static::LOGIN_TOKEN )->getCartProducts ( array (
|
149 |
+
static::STOREID => $storeId,
|
150 |
+
static::CUSTOMER_ID => $customerId
|
151 |
+
) );
|
152 |
+
$response [static::VALID_TOKEN] = $isValidToken;
|
153 |
+
$response [static::SUCCESS] = $success;
|
154 |
+
$response [static::ERROR] = $error_flag;
|
155 |
+
$response [static::MESSAGE] = $message;
|
156 |
+
$response [static::RESULT] = $prodctsList [static::RESULT];
|
157 |
+
$response [static::RESULT] ['errors'] = $messages;
|
158 |
+
|
159 |
+
$this->getResponse ()->setBody ( json_encode ( $response ) );
|
160 |
+
return;
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* function that is called when put is done **
|
165 |
+
* Update Cart products Qty
|
166 |
+
*
|
167 |
+
* @param array $data
|
168 |
+
* @return array json array
|
169 |
+
*/
|
170 |
+
protected function _update(array $data) {
|
171 |
+
$response = array ();
|
172 |
+
$messages = array ();
|
173 |
+
$message = '';
|
174 |
+
// get quote id from request
|
175 |
+
$quoteId = ( int ) $data [static::QUOTE_ID];
|
176 |
+
|
177 |
+
// get customer id from request
|
178 |
+
$customerId = ( int ) $data [static::CUSTOMER_ID];
|
179 |
+
|
180 |
+
// Get website id
|
181 |
+
$websiteId = (isset ( $data [static::WEBSITEID] )) ? $data [static::WEBSITEID] : Mage::app ()->getWebsite ( 'base' )->getId ();
|
182 |
+
// get store id
|
183 |
+
$storeId = (isset ( $data [static::STOREID] )) ? $data [static::STOREID] : Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
184 |
+
|
185 |
+
$products = $data ['detail'];
|
186 |
+
|
187 |
+
/**
|
188 |
+
* Check this customer has valid token or not
|
189 |
+
*
|
190 |
+
* @var $isValidToken Mage_Login_Model_Token
|
191 |
+
*/
|
192 |
+
$isValidToken = Mage::getModel ( static::LOGIN_TOKEN )->checkUserToken ( $customerId, $data [static::TOKEN] );
|
193 |
+
try {
|
194 |
+
|
195 |
+
if (! $isValidToken) {
|
196 |
+
throw new Exception ( static::AUTH_FAIL );
|
197 |
+
}
|
198 |
+
|
199 |
+
$i = 0;
|
200 |
+
$error_flag = true;
|
201 |
+
|
202 |
+
foreach ( $products as $item ) {
|
203 |
+
$quote = Mage::getModel ( static::SLAES_QUOTE );
|
204 |
+
$quote->setStoreId ( $storeId )->load ( $quoteId );
|
205 |
+
$productByItem = $this->_getProduct ( $item [static::PRODUCT_ID], $storeId, 'id' );
|
206 |
|
207 |
+
if (is_null ( $productByItem )) {
|
208 |
+
|
209 |
+
$messages [$i] [static::UPDATED] = 0;
|
210 |
+
$messages [$i] [static::MESSAGE] = 'Item is not available.';
|
211 |
+
$error_flag = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
} else {
|
213 |
+
$productItem = $this->updateToCart ( $productByItem, $quote, $item [static::QTY], $item );
|
214 |
+
$quoteItem = Mage::getModel ( static::LOGIN_TOKEN )->_getQuoteItemByProduct ( $quote, $productByItem, Mage::getModel ( static::LOGIN_TOKEN )->_getProductRequest ( $productItem ) );
|
215 |
+
|
216 |
+
$update = $this->cartUpdate ( $quoteItem, $quote, $item [static::QTY] );
|
217 |
+
$messages [$i] [static::UPDATED] = $update [static::SUCCESS];
|
218 |
+
$messages [$i] [static::MESSAGE] = $productByItem->getName () . '- ' . $update [static::MESSAGE];
|
219 |
+
}
|
220 |
+
if ($messages [$i] [static::UPDATED] == 0) {
|
221 |
+
$error_flag = false;
|
222 |
}
|
|
|
223 |
|
224 |
+
$i ++;
|
225 |
+
$success = 1;
|
226 |
+
}
|
227 |
+
if ($error_flag) {
|
228 |
+
$success = 1;
|
229 |
+
$message = 'Cart updated successfully.';
|
230 |
+
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
$success = 0;
|
232 |
+
$message = 'Cart not updated.';
|
233 |
+
}
|
234 |
+
} catch ( Mage_Core_Exception $e ) {
|
235 |
+
|
236 |
+
$message = $e->getMessage ();
|
237 |
+
$success = 0;
|
238 |
+
}
|
239 |
+
// get cart product list
|
240 |
+
$prodctsList = Mage::getModel ( static::LOGIN_TOKEN )->getCartProducts ( array (
|
241 |
+
static::STOREID => $storeId,
|
242 |
+
static::CUSTOMER_ID => $customerId
|
243 |
+
) );
|
244 |
+
$response [static::ERROR] = false;
|
245 |
+
|
246 |
+
$response [static::SUCCESS] = $success;
|
247 |
+
$response [static::VALID_TOKEN] = $isValidToken;
|
248 |
+
$response [static::MESSAGE] = $message;
|
249 |
+
$response [static::RESULT] = $prodctsList [static::RESULT];
|
250 |
+
$response [static::RESULT] ['errors'] = $messages;
|
251 |
+
$this->getResponse ()->setBody ( json_encode ( $response ) );
|
252 |
+
|
253 |
+
return;
|
254 |
+
}
|
255 |
+
|
256 |
+
/**
|
257 |
+
* Get product details
|
258 |
+
*
|
259 |
+
* @param integer $productId
|
260 |
+
* @param string $store
|
261 |
+
* @param string $identifierType
|
262 |
+
* @return NULL array
|
263 |
+
*/
|
264 |
+
public function _getProduct($productId, $store = NULL, $identifierType = NULL) {
|
265 |
+
|
266 |
+
/**
|
267 |
+
*
|
268 |
+
* @var $product Mage_Catalog_Model_Product
|
269 |
+
*/
|
270 |
+
$product = Mage::helper ( 'catalog/product' )->getProduct ( $productId, $store, $identifierType );
|
271 |
+
if (! $product->getId ()) {
|
272 |
+
return NULL;
|
273 |
+
}
|
274 |
+
|
275 |
+
return $product;
|
276 |
+
}
|
277 |
+
|
278 |
+
/**
|
279 |
+
*
|
280 |
+
* @param integer $quoteId
|
281 |
+
* @param integer $storeId
|
282 |
+
* @return mixed array $quote
|
283 |
+
*/
|
284 |
+
protected function _getQuote($quoteId, $storeId) {
|
285 |
+
/**
|
286 |
+
*
|
287 |
+
* @var $quote Mage_Sales_Model_Quote
|
288 |
+
*/
|
289 |
+
$quote = Mage::getModel ( static::SLAES_QUOTE );
|
290 |
+
$quote->setStoreId ( $storeId )->load ( $quoteId );
|
291 |
+
return $quote;
|
292 |
+
}
|
293 |
+
|
294 |
+
/**
|
295 |
+
* Get Quote data by customer
|
296 |
+
*
|
297 |
+
* @param int $customerId
|
298 |
+
* @param int $storeId
|
299 |
+
* @return array $quoteData
|
300 |
+
*/
|
301 |
+
public function getQuoteIdBycustomer($customerId, $storeId) {
|
302 |
+
$quote = Mage::getModel ( static::SLAES_QUOTE )->getCollection ()->addFieldToFilter ( static::CUSTOMER_ID, $customerId )->addFieldToFilter ( static::STOREID, $storeId )->addFieldToFilter ( 'is_active', '1' )->setOrder ( static::ENTITYID, 'desc' );
|
303 |
+
return $quote->getData ();
|
304 |
+
}
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Add product to cart
|
308 |
+
*
|
309 |
+
* @param object $product
|
310 |
+
* @param object $quote
|
311 |
+
* @param int $qty
|
312 |
+
* @return $result
|
313 |
+
*/
|
314 |
+
public function addToCart($product, $quote, $qty, $data) {
|
315 |
+
// get product type
|
316 |
+
$type = $product->getTypeId ();
|
317 |
+
switch ($type) {
|
318 |
+
case Mage_Catalog_Model_Product_Type::TYPE_GROUPED :
|
319 |
+
$request_add = new Varien_Object ( array (
|
320 |
+
static::SUPER_GRP => $qty
|
321 |
+
) );
|
322 |
+
$cartResult = $quote->addProduct ( $product, $request_add );
|
323 |
+
break;
|
324 |
+
case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE :
|
325 |
+
$request_add = new Varien_Object ( array (
|
326 |
+
static::SUPER_ATTR => $data [static::SUPER_ATTR],
|
327 |
+
static::OPTIONS => $data [static::CUSTOM_OPTION],
|
328 |
+
static::QTY => $qty
|
329 |
+
) );
|
330 |
+
$cartResult = $quote->addProduct ( $product, $request_add );
|
331 |
+
break;
|
332 |
+
case Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE :
|
333 |
+
$request_add = new Varien_Object ( array (
|
334 |
+
static::LINKS => explode ( ',', $data [static::LINKS] ),
|
335 |
+
static::OPTIONS => $data [static::CUSTOM_OPTION],
|
336 |
+
static::QTY => $qty
|
337 |
+
) );
|
338 |
+
$cartResult = $quote->addProduct ( $product, $request_add );
|
339 |
+
break;
|
340 |
+
default :
|
341 |
+
if (isset ( $data [static::CUSTOM_OPTION] )) {
|
342 |
+
$qty = new Varien_Object ( array (
|
343 |
+
static::OPTIONS => $data [static::CUSTOM_OPTION],
|
344 |
+
static::QTY => $qty
|
345 |
+
) );
|
346 |
+
}
|
347 |
+
$cartResult = $quote->addProduct ( $product, $qty );
|
348 |
+
break;
|
349 |
+
}
|
350 |
+
return $cartResult;
|
351 |
+
}
|
352 |
+
|
353 |
+
/**
|
354 |
+
* Update product to cart
|
355 |
+
*
|
356 |
+
* @param object $productByItem
|
357 |
+
* @param object $quote
|
358 |
+
* @param int $qty
|
359 |
+
* @return $result
|
360 |
+
*/
|
361 |
+
public function updateToCart($productByItem, $quote, $qty, $data) {
|
362 |
+
$type = $productByItem->getTypeId ();
|
363 |
+
$updateProduct = '';
|
364 |
+
switch ($type) {
|
365 |
+
case Mage_Catalog_Model_Product_Type::TYPE_GROUPED :
|
366 |
+
$updateProduct = new Varien_Object ( array (
|
367 |
+
static::SUPER_GRP => $qty
|
368 |
+
) );
|
369 |
+
$quote->addProduct ( $product, $request );
|
370 |
+
break;
|
371 |
+
case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE :
|
372 |
+
if (isset ( $data [static::SUPER_ATTR] ) && $data [static::SUPER_ATTR] != '') {
|
373 |
+
$updateProduct = new Varien_Object ( array (
|
374 |
+
static::SUPER_ATTR => json_decode ( $data [static::SUPER_ATTR], true ),
|
375 |
+
static::OPTIONS => json_decode ( $data [static::CUSTOM_OPTION], true ),
|
376 |
+
static::QTY => $qty
|
377 |
+
) );
|
378 |
+
}
|
379 |
+
break;
|
380 |
+
case Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE :
|
381 |
+
if (isset ( $data [static::LINKS] ) && $data [static::LINKS] != '') {
|
382 |
+
$updateProduct = new Varien_Object ( array (
|
383 |
+
static::LINKS => explode ( ',', $data [static::LINKS] ),
|
384 |
+
static::OPTIONS => json_decode ( $data [static::CUSTOM_OPTION], true ),
|
385 |
+
static::QTY => $qty
|
386 |
+
) );
|
387 |
+
}
|
388 |
+
break;
|
389 |
+
default :
|
390 |
+
if (isset ( $data [static::CUSTOM_OPTION] ) && $data [static::CUSTOM_OPTION] != '') {
|
391 |
+
$updateProduct = new Varien_Object ( array (
|
392 |
+
static::OPTIONS => json_decode ( $data [static::CUSTOM_OPTION], true ),
|
393 |
+
static::QTY => $qty
|
394 |
+
) );
|
395 |
} else {
|
396 |
+
$updateProduct = '';
|
397 |
}
|
398 |
+
break;
|
399 |
+
}
|
400 |
+
|
401 |
+
return $updateProduct;
|
402 |
+
}
|
403 |
+
|
404 |
+
/**
|
405 |
+
* Update product in cart
|
406 |
+
*
|
407 |
+
* @param object $quoteItem
|
408 |
+
* @param object $quote
|
409 |
+
* @return array $response
|
410 |
+
*/
|
411 |
+
public function cartUpdate($quoteProduct, $quote, $qty) {
|
412 |
+
$response = array ();
|
413 |
+
if (empty ( $quoteProduct )) {
|
414 |
+
$success = 0;
|
415 |
+
$message = 'Item is not added in cart';
|
416 |
+
} else {
|
417 |
+
if ($qty > 0) {
|
418 |
+
$quoteProduct->setQty ( $qty );
|
419 |
+
} else {
|
420 |
+
$quote->removeItem ( $quoteProduct->getId () );
|
421 |
+
}
|
422 |
+
$quote->getBillingAddress ();
|
423 |
+
$quote->getShippingAddress ()->setCollectShippingRates ( TRUE );
|
424 |
+
$quote->collectTotals ();
|
425 |
+
$quote->save ();
|
426 |
+
$success = 1;
|
427 |
+
$message = 'Cart updated successfully.';
|
428 |
+
}
|
429 |
+
|
430 |
+
$response [static::SUCCESS] = $success;
|
431 |
+
$response [static::MESSAGE] = $message;
|
432 |
+
return $response;
|
433 |
+
}
|
434 |
}
|
app/code/local/ContusRestapi/MultiCartapi/etc/api2.xml
CHANGED
@@ -79,7 +79,7 @@
|
|
79 |
<route>/cart/bulk_update/</route>
|
80 |
<action_type>entity</action_type>
|
81 |
</cart_update>
|
82 |
-
|
83 |
</routes>
|
84 |
<versions>1</versions>
|
85 |
</multiCartapi>
|
79 |
<route>/cart/bulk_update/</route>
|
80 |
<action_type>entity</action_type>
|
81 |
</cart_update>
|
82 |
+
|
83 |
</routes>
|
84 |
<versions>1</versions>
|
85 |
</multiCartapi>
|
app/code/local/ContusRestapi/MyOrders/Model/Api2/MyOrderapi.php
CHANGED
@@ -28,400 +28,587 @@
|
|
28 |
* @since 1.0
|
29 |
*/
|
30 |
class ContusRestapi_MyOrders_Model_Api2_MyOrderapi extends Mage_Sales_Model_Api2_Order_Rest {
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
/**
|
76 |
*
|
77 |
* @var $order Mage_Sales_Model_Order
|
78 |
*/
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
if ($order->getIncrementId () != '') {
|
85 |
-
// get order id
|
86 |
-
$ordersData [static::ORDER_ID] = $order->getIncrementId ();
|
87 |
-
$ordersData [static::STATUS] = ucfirst ( strtolower ( $order->getStatusLabel () ) );
|
88 |
-
$ordersData ['order_date'] = $order->getCreatedAt ();
|
89 |
-
$ordersData ['item_count'] = $order->getTotalItemCount ();
|
90 |
-
$ordersData ['grand_total'] = number_format ( $order->getGrandTotal (), 2, '.', '' );
|
91 |
-
// get shipping address
|
92 |
-
$shipping_address = $order->getShippingAddress ();
|
93 |
-
if ($shipping_address) {
|
94 |
-
$shippingAddresDetail = $shipping_address->getData ();
|
95 |
-
// get shipping address details
|
96 |
-
$ordersData [static::SHIPPING_ADDR] ['firstname'] = $shippingAddresDetail ['firstname'];
|
97 |
-
$ordersData [static::SHIPPING_ADDR] ['lastname'] = $shippingAddresDetail ['lastname'];
|
98 |
-
$ordersData [static::SHIPPING_ADDR] ['street'] = explode ( "\n", $shippingAddresDetail ['street'] );
|
99 |
-
$ordersData [static::SHIPPING_ADDR] ['city'] = $shippingAddresDetail ['city'];
|
100 |
-
$ordersData [static::SHIPPING_ADDR] ['region'] = $shippingAddresDetail ['region'];
|
101 |
-
$ordersData [static::SHIPPING_ADDR] ['country_id'] = $shippingAddresDetail ['country_id'];
|
102 |
-
// get country name by country id
|
103 |
-
$country = Mage::getModel ( 'directory/country' )->loadByCode ( $shipping_address->country_id );
|
104 |
-
$ordersData [static::SHIPPING_ADDR] ['country_name'] = $country->getName ();
|
105 |
-
$ordersData [static::SHIPPING_ADDR] ['telephone'] = $shippingAddresDetail ['telephone'];
|
106 |
-
$ordersData [static::SHIPPING_ADDR] ['postcode'] = $shippingAddresDetail ['postcode'];
|
107 |
-
}
|
108 |
-
$orderCurrencyCode = $order->getOrderCurrencyCode ();
|
109 |
-
$ordersData ['currency_symbol'] = Mage::app ()->getLocale ()->currency ( $orderCurrencyCode )->getSymbol ();
|
110 |
-
// get shipping method
|
111 |
-
$ordersData ['shipping_method'] = $order->getShippingDescription ();
|
112 |
-
// get payment method
|
113 |
-
$ordersData ['payment_method'] = $order->getPayment ()->getMethodInstance ()->getTitle ();
|
114 |
-
|
115 |
-
$orderItems = $order->getItemsCollection ();
|
116 |
-
// get item collection
|
117 |
-
$ordersData ['items'] = $this->getOrderedItemDetail ( $orderItems );
|
118 |
-
// get shipping amount
|
119 |
-
$ordersData ['shipping_amount'] = number_format ( $order ['base_shipping_amount'], 2, '.', '' );
|
120 |
-
$ordersData ['discount_amount'] = number_format ( $order ['base_discount_amount'], 2, '.', '' );
|
121 |
-
$ordersData ['tax_amount'] = number_format ( $order ['base_tax_amount'], 2, '.', '' );
|
122 |
-
$ordersData ['sub_amount'] = number_format ( $order ['base_subtotal'], 2, '.', '' );
|
123 |
-
$ordersData ['total_amount'] = number_format ( $order ['base_grand_total'], 2, '.', '' );
|
124 |
-
$success = 1;
|
125 |
-
$message = 'Get order details.';
|
126 |
} else {
|
127 |
-
|
128 |
-
$message = 'No data found.';
|
129 |
}
|
130 |
-
} catch ( Exception $e ) {
|
131 |
-
$success = 0;
|
132 |
-
$message = $e->getMessage ();
|
133 |
-
}
|
134 |
-
$response [static::VALID_TOKEN] = $isValidToken;
|
135 |
-
$response [static::ERROR] = false;
|
136 |
-
$response [static::SUCCESS] = $success;
|
137 |
-
$response [static::MESSAGE] = $message;
|
138 |
-
$response [static::RESULT] = $ordersData;
|
139 |
-
return json_encode ( $response );
|
140 |
-
}
|
141 |
-
|
142 |
-
/**
|
143 |
-
* Get orders list
|
144 |
-
*
|
145 |
-
* @return array
|
146 |
-
*/
|
147 |
-
protected function _retrieveCollection() {
|
148 |
-
$response = array ();
|
149 |
-
|
150 |
-
/**
|
151 |
-
* Check this customer has valid token or not
|
152 |
-
*
|
153 |
-
* @var $isValidToken Mage_Login_Model_Token
|
154 |
-
*/
|
155 |
-
$isValidToken = Mage::getModel ( static::LOGIN_TOKEN )->checkUserToken ( Mage::app ()->getRequest ()->getParam ( static::CUSTOMERID ), Mage::app ()->getRequest ()->getParam ( static::TOKEN ) );
|
156 |
-
|
157 |
-
if ($isValidToken) {
|
158 |
|
159 |
-
$
|
160 |
-
|
161 |
-
$
|
162 |
-
$
|
163 |
-
$response [static::VALID_TOKEN] = $isValidToken;
|
164 |
-
$response [static::ERROR] = false;
|
165 |
-
$response [static::SUCCESS] = $success;
|
166 |
-
$response [static::MESSAGE] = $message;
|
167 |
-
$response [static::TOTAL_COUNT] = 0;
|
168 |
|
169 |
-
$
|
170 |
-
}
|
171 |
-
|
172 |
-
return json_encode ( $response );
|
173 |
-
}
|
174 |
-
|
175 |
-
/**
|
176 |
-
* Retrieve collection instance for orders list
|
177 |
-
*
|
178 |
-
* @return Mage_Sales_Model_Resource_Order_Collection
|
179 |
-
*/
|
180 |
-
protected function _getCollectionForRetrieve() {
|
181 |
-
|
182 |
-
// get website id from request
|
183 |
-
$websiteId = ( int ) $this->getRequest ()->getParam ( 'website_id' );
|
184 |
-
if ($websiteId <= 0) {
|
185 |
-
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
186 |
-
}
|
187 |
-
// get store id from request
|
188 |
-
$storeId = ( int ) $this->getRequest ()->getParam ( static::STOREID );
|
189 |
-
if ($storeId <= 0) {
|
190 |
-
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
191 |
-
}
|
192 |
-
|
193 |
-
// get page from request
|
194 |
-
$page = ( int ) $this->getRequest ()->getParam ( 'page' );
|
195 |
-
// get page from request
|
196 |
-
$limit = ( int ) $this->getRequest ()->getParam ( 'limit' );
|
197 |
-
|
198 |
-
/**
|
199 |
-
*
|
200 |
-
* @var $collection Mage_Sales_Model_Resource_Order_Collection
|
201 |
-
*/
|
202 |
-
$collection = Mage::getResourceModel ( 'sales/order_collection' );
|
203 |
-
if (isset ( $_GET ) && Mage::app ()->getRequest ()->getParam ( static::CUSTOMERID )) {
|
204 |
-
$collection->addFieldToFilter ( static::CUSTOMERID, Mage::app ()->getRequest ()->getParam ( static::CUSTOMERID ) )->addFieldToFilter ( static::STOREID, $storeId );
|
205 |
-
$collection->setPage ( $page, $limit );
|
206 |
-
$collection->setOrder ( static::CREATED_AT, 'DESC' );
|
207 |
-
}
|
208 |
-
|
209 |
-
if ($this->_isPaymentMethodAllowed ()) {
|
210 |
-
$this->_addPaymentMethodInfo ( $collection );
|
211 |
-
}
|
212 |
-
if ($this->_isGiftMessageAllowed ()) {
|
213 |
-
$this->_addGiftMessageInfo ( $collection );
|
214 |
-
}
|
215 |
-
$this->_addTaxInfo ( $collection );
|
216 |
-
$this->_applyCollectionModifiers ( $collection );
|
217 |
-
|
218 |
-
$ordersData = array ();
|
219 |
-
$i = 0;
|
220 |
-
$collection->getSelectSql ( true );
|
221 |
-
|
222 |
-
// get total orders count
|
223 |
-
$totalOrders = $collection->getSize ();
|
224 |
-
$last_page = ceil ( $totalOrders / $limit );
|
225 |
-
if ($last_page < $page) {
|
226 |
-
$success = 1;
|
227 |
-
$message = 'No Orders Found';
|
228 |
-
$ordersData = array();
|
229 |
-
} else {
|
230 |
|
231 |
-
$
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
$response [static::ERROR] = false;
|
265 |
-
$response [static::SUCCESS] = $success;
|
266 |
-
$response [static::MESSAGE] = $message;
|
267 |
-
$response [static::TOTAL_COUNT] = $totalOrders;
|
268 |
-
$response [static::RESULT] = $ordersData;
|
269 |
-
return $response;
|
270 |
-
}
|
271 |
-
|
272 |
-
/**
|
273 |
-
* Get ordered item collection
|
274 |
-
*
|
275 |
-
* @param array $orderItems
|
276 |
-
* @return $items
|
277 |
-
*/
|
278 |
-
public function getOrderedItemDetail($orderItems) {
|
279 |
-
$items = array ();
|
280 |
-
foreach ( $orderItems as $item ) {
|
281 |
-
$product = array ();
|
282 |
-
if ($item ['parent_item_id'] == '') {
|
283 |
-
$product ['entity_id'] = $item->product_id;
|
284 |
-
$product ['price'] = number_format ( $item->getPrice (), 2, '.', '' );
|
285 |
-
$product ['name'] = $item->getName ();
|
286 |
-
$_product = Mage::getModel ( 'catalog/product' )->load ( $item->product_id );
|
287 |
-
$product ['image_url'] = ( string ) Mage::helper ( 'catalog/image' )->init ( $_product, 'thumbnail' );
|
288 |
-
$product ['qty'] = intval ( $item ['qty_ordered'] );
|
289 |
-
$product ['row_total'] = number_format ( $item ['base_row_total'], 2, '.', '' );
|
290 |
-
|
291 |
-
$product_options = $item ['product_options'];
|
292 |
-
$super_attribute = unserialize ( $product_options );
|
293 |
-
if (isset ( $super_attribute [static::ATTR_INFO] )) {
|
294 |
-
$product [static::ATTR_INFO] = $super_attribute ['attributes_info'];
|
295 |
-
} else {
|
296 |
-
$product [static::ATTR_INFO] = array ();
|
297 |
-
}
|
298 |
-
if (isset ( $super_attribute [static::OPTIONS] )) {
|
299 |
-
$product [static::OPTIONS] = $super_attribute ['options'];
|
300 |
-
} else {
|
301 |
-
$product [static::OPTIONS] = array ();
|
302 |
-
}
|
303 |
-
|
304 |
-
$items [] = $product;
|
305 |
-
}
|
306 |
-
}
|
307 |
-
return $items;
|
308 |
-
}
|
309 |
-
|
310 |
-
/**
|
311 |
-
* (non-PHPdoc)
|
312 |
-
*
|
313 |
-
* @see Mage_Api2_Model_Resource::_create($filteredData)
|
314 |
-
*/
|
315 |
-
public function _create(array $data) {
|
316 |
-
$response = array ();
|
317 |
-
$download_items = array ();
|
318 |
-
// get customer id from request
|
319 |
-
$customerId = ( int ) $data [static::CUSTOMERID];
|
320 |
-
|
321 |
-
/**
|
322 |
-
* Check this customer has valid token or not
|
323 |
-
*
|
324 |
-
* @var $isValidToken Mage_Login_Model_Token
|
325 |
-
*/
|
326 |
-
$isValidToken = Mage::getModel ( static::LOGIN_TOKEN )->checkUserToken ( $customerId, $data [static::TOKEN] );
|
327 |
-
|
328 |
-
try {
|
329 |
-
// check customer token
|
330 |
-
if (! $isValidToken) {
|
331 |
-
throw new Exception ( static::AUTH_ERR_MSG );
|
332 |
-
}
|
333 |
|
334 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
335 |
|
336 |
-
$
|
337 |
-
|
338 |
-
|
339 |
-
|
|
|
|
|
340 |
}
|
341 |
-
if (
|
342 |
-
|
343 |
-
|
344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
}
|
346 |
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
*/
|
411 |
-
$orderItem = Mage::getModel ( 'sales/order_item' )->getCollection ()->addFieldToFilter ( 'item_id', $item [static::ORDER_ITEM_ID] )->getFirstItem ();
|
412 |
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
|
|
418 |
|
419 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
|
421 |
-
$
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
427 |
}
|
28 |
* @since 1.0
|
29 |
*/
|
30 |
class ContusRestapi_MyOrders_Model_Api2_MyOrderapi extends Mage_Sales_Model_Api2_Order_Rest {
|
31 |
+
|
32 |
+
// Declaring the string literals variable
|
33 |
+
const STOREID = 'store_id';
|
34 |
+
const CUSTOMERID = 'customer_id';
|
35 |
+
const ATTR_INFO = 'attributes_info';
|
36 |
+
const OPTIONS = 'options';
|
37 |
+
const SHIPPING_ADDR = 'shipping_address';
|
38 |
+
const RESULT = 'result';
|
39 |
+
const SUCCESS = 'success';
|
40 |
+
const MESSAGE = 'message';
|
41 |
+
const ERROR = 'error';
|
42 |
+
const VALID_TOKEN = 'isValidToken';
|
43 |
+
const LOGIN_TOKEN = 'login/token';
|
44 |
+
const TOKEN = 'token';
|
45 |
+
const TOTAL_COUNT = 'total_count';
|
46 |
+
const AUTH_ERR_MSG = 'Authentication failed.';
|
47 |
+
const SALES_ORDER = 'sales/order';
|
48 |
+
const ORDER_ID = 'order_id';
|
49 |
+
const STATUS = 'status';
|
50 |
+
const ITEM_ID = 'item_id';
|
51 |
+
const PURCHASE_ID = 'purchased_id';
|
52 |
+
const ORDER_ITEM_ID = 'order_item_id';
|
53 |
+
const CREATED_AT = 'created_at';
|
54 |
+
const PRODUCT_ID = 'product_id';
|
55 |
+
const CUSTOM_OPTION = 'custom_option';
|
56 |
+
const SUPER_ATTR = 'super_attribute';
|
57 |
+
const SUPER_GRP = 'super_group';
|
58 |
+
const QTY = 'qty';
|
59 |
+
const CATALOG_PRO = 'catalog/product';
|
60 |
+
const WEBSITE_ID = 'website_id';
|
61 |
+
const SELLER_STATUS = 'seller_status';
|
62 |
+
const SELLER_ID = 'seller_id';
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Retrieve information about specified order item
|
66 |
+
*
|
67 |
+
* @throws Mage_Api2_Exception
|
68 |
+
* @return array
|
69 |
+
*/
|
70 |
+
protected function _retrieve() {
|
71 |
+
$response = array ();
|
72 |
+
$ordersData = array ();
|
73 |
+
$orderId = $this->getRequest ()->getParam ( 'id' );
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Check this customer has valid token or not
|
77 |
+
*
|
78 |
+
* @var $isValidToken Mage_Login_Model_Token
|
79 |
+
*/
|
80 |
+
$isValidToken = Mage::getModel ( static::LOGIN_TOKEN )->checkUserToken ( Mage::app ()->getRequest ()->getParam ( static::CUSTOMERID ), Mage::app ()->getRequest ()->getParam ( static::TOKEN ) );
|
81 |
+
try {
|
82 |
+
|
83 |
+
/**
|
84 |
+
*
|
85 |
+
* @var $order Mage_Sales_Model_Order
|
86 |
+
*/
|
87 |
+
if (! $isValidToken) {
|
88 |
+
throw new Exception ( static::AUTH_ERR_MSG );
|
89 |
+
}
|
90 |
+
|
91 |
+
$order = Mage::getModel ( static::SALES_ORDER )->loadByIncrementId ( $orderId );
|
92 |
+
if ($order->getIncrementId () != '') {
|
93 |
+
// get order id
|
94 |
+
$ordersData [static::ORDER_ID] = $order->getIncrementId ();
|
95 |
+
$ordersData [static::STATUS] = ucfirst ( strtolower ( $order->getStatusLabel () ) );
|
96 |
+
$ordersData ['order_date'] = $order->getCreatedAt ();
|
97 |
+
$ordersData ['item_count'] = $order->getTotalItemCount ();
|
98 |
+
$ordersData ['grand_total'] = number_format ( $order->getGrandTotal (), 2, '.', '' );
|
99 |
+
// get shipping address
|
100 |
+
$shipping_address = $order->getShippingAddress ();
|
101 |
+
if ($shipping_address) {
|
102 |
+
$shippingAddresDetail = $shipping_address->getData ();
|
103 |
+
// get shipping address details
|
104 |
+
$ordersData [static::SHIPPING_ADDR] ['firstname'] = $shippingAddresDetail ['firstname'];
|
105 |
+
$ordersData [static::SHIPPING_ADDR] ['lastname'] = $shippingAddresDetail ['lastname'];
|
106 |
+
$ordersData [static::SHIPPING_ADDR] ['street'] = explode ( "\n", $shippingAddresDetail ['street'] );
|
107 |
+
$ordersData [static::SHIPPING_ADDR] ['city'] = $shippingAddresDetail ['city'];
|
108 |
+
$ordersData [static::SHIPPING_ADDR] ['region'] = $shippingAddresDetail ['region'];
|
109 |
+
$ordersData [static::SHIPPING_ADDR] ['country_id'] = $shippingAddresDetail ['country_id'];
|
110 |
+
// get country name by country id
|
111 |
+
$country = Mage::getModel ( 'directory/country' )->loadByCode ( $shipping_address->country_id );
|
112 |
+
$ordersData [static::SHIPPING_ADDR] ['country_name'] = $country->getName ();
|
113 |
+
$ordersData [static::SHIPPING_ADDR] ['telephone'] = $shippingAddresDetail ['telephone'];
|
114 |
+
$ordersData [static::SHIPPING_ADDR] ['postcode'] = $shippingAddresDetail ['postcode'];
|
115 |
+
}
|
116 |
+
$orderCurrencyCode = $order->getOrderCurrencyCode ();
|
117 |
+
$ordersData ['currency_symbol'] = Mage::app ()->getLocale ()->currency ( $orderCurrencyCode )->getSymbol ();
|
118 |
+
// get shipping method
|
119 |
+
$ordersData ['shipping_method'] = $order->getShippingDescription ();
|
120 |
+
// get payment method
|
121 |
+
$ordersData ['payment_method'] = $order->getPayment ()->getMethodInstance ()->getTitle ();
|
122 |
+
|
123 |
+
// get delivery information
|
124 |
+
if (Mage::getStoreConfig ( 'deliveryschedule/general/delivery_schedule_enabled' ) == 1) {
|
125 |
+
$ordersData ['delivery_info'] = $this->getdeliveryDetails ( $order );
|
126 |
+
}
|
127 |
+
$orderItems = $order->getItemsCollection ();
|
128 |
+
// get item collection
|
129 |
+
$ordersData ['items'] = $this->getOrderedItemDetail ( $orderItems, $order->getIncrementId () );
|
130 |
|
131 |
+
// get shipping amount
|
132 |
+
$ordersData ['shipping_amount'] = number_format ( $order ['base_shipping_amount'], 2, '.', '' );
|
133 |
+
$ordersData ['discount_amount'] = number_format ( $order ['base_discount_amount'], 2, '.', '' );
|
134 |
+
$ordersData ['tax_amount'] = number_format ( $order ['base_tax_amount'], 2, '.', '' );
|
135 |
+
$ordersData ['sub_amount'] = number_format ( $order ['base_subtotal'], 2, '.', '' );
|
136 |
+
$ordersData ['total_amount'] = number_format ( $order ['base_grand_total'], 2, '.', '' );
|
137 |
+
|
138 |
+
// get surprise gift option
|
139 |
+
if (! is_null ( $order->getGiftMessageId () )) {
|
140 |
+
$ordersData ['surprise_gift'] = 1;
|
141 |
+
$message = Mage::getModel ( 'giftmessage/message' );
|
142 |
+
$message->load ( ( int ) $order->getGiftMessageId () );
|
143 |
+
$ordersData ['gift_message'] = $message->getData ( 'message' );
|
144 |
+
} else {
|
145 |
+
$ordersData ['surprise_gift'] = 0;
|
146 |
+
$ordersData ['gift_message'] = '';
|
147 |
+
}
|
148 |
+
|
149 |
+
$success = 1;
|
150 |
+
$message = 'Get order details.';
|
151 |
+
} else {
|
152 |
+
$success = 0;
|
153 |
+
$message = 'No data found.';
|
154 |
+
}
|
155 |
+
} catch ( Exception $e ) {
|
156 |
+
$success = 0;
|
157 |
+
$message = $e->getMessage ();
|
158 |
+
}
|
159 |
+
$response [static::VALID_TOKEN] = $isValidToken;
|
160 |
+
$response [static::ERROR] = false;
|
161 |
+
$response [static::SUCCESS] = $success;
|
162 |
+
$response [static::MESSAGE] = $message;
|
163 |
+
$response [static::RESULT] = $ordersData;
|
164 |
+
return json_encode ( $response );
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Get Delivery information about order
|
169 |
+
*
|
170 |
+
* @return array $deliveryInfo
|
171 |
+
*/
|
172 |
+
public function getdeliveryDetails($order) {
|
173 |
+
$deliveryInfo = array ();
|
174 |
+
// get delivery schedule type name
|
175 |
+
$schedule_type = $order->getShippingDeliverySchedule ();
|
176 |
+
if ($schedule_type) {
|
177 |
+
$deliveryInfo ['schedule_type'] = $schedule_type;
|
178 |
+
// get delivery date
|
179 |
+
$deliveryInfo ['date'] = date ( "M d Y", strtotime ( $order->getShippingDeliveryDate () ) );
|
180 |
+
// get delivery title
|
181 |
+
$deliveryInfo ['schedule_title'] = $order->getShippingDeliveryTime ();
|
182 |
+
// get delivery cost
|
183 |
+
$deliveryInfo ['cost'] = $order->getDeliveryCost ();
|
184 |
+
// get delivery time
|
185 |
+
$deliveryInfo ['delivery_time'] = $order->getDeliveryTime ();
|
186 |
+
if (Mage::getStoreConfig ( 'deliveryschedule/general/delivery_comment_enabled' ) == 1) {
|
187 |
+
// get delivery comment
|
188 |
+
$deliveryInfo ['comment'] = $order->getShippingDeliveryComments ();
|
189 |
+
} else {
|
190 |
+
$deliveryInfo ['comment'] = '';
|
191 |
+
}
|
192 |
+
}
|
193 |
+
return $deliveryInfo;
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Get orders list
|
198 |
+
*
|
199 |
+
* @return array
|
200 |
+
*/
|
201 |
+
protected function _retrieveCollection() {
|
202 |
+
$response = array ();
|
203 |
+
|
204 |
+
/**
|
205 |
+
* Check this customer has valid token or not
|
206 |
+
*
|
207 |
+
* @var $isValidToken Mage_Login_Model_Token
|
208 |
+
*/
|
209 |
+
$isValidToken = Mage::getModel ( static::LOGIN_TOKEN )->checkUserToken ( Mage::app ()->getRequest ()->getParam ( static::CUSTOMERID ), Mage::app ()->getRequest ()->getParam ( static::TOKEN ) );
|
210 |
+
|
211 |
+
if ($isValidToken) {
|
212 |
+
|
213 |
+
$response = $this->_getCollectionForRetrieve ();
|
214 |
+
} else {
|
215 |
+
$success = 0;
|
216 |
+
$message = static::AUTH_ERR_MSG;
|
217 |
+
$response [static::VALID_TOKEN] = $isValidToken;
|
218 |
+
$response [static::ERROR] = false;
|
219 |
+
$response [static::SUCCESS] = $success;
|
220 |
+
$response [static::MESSAGE] = $message;
|
221 |
+
$response [static::TOTAL_COUNT] = 0;
|
222 |
+
|
223 |
+
$response [static::RESULT] = array ();
|
224 |
+
}
|
225 |
+
|
226 |
+
return json_encode ( $response );
|
227 |
+
}
|
228 |
+
|
229 |
+
/**
|
230 |
+
* Retrieve collection instance for orders list
|
231 |
+
*
|
232 |
+
* @return Mage_Sales_Model_Resource_Order_Collection
|
233 |
+
*/
|
234 |
+
protected function _getCollectionForRetrieve() {
|
235 |
+
|
236 |
+
// get website id from request
|
237 |
+
$websiteId = ( int ) $this->getRequest ()->getParam ( static::WEBSITE_ID );
|
238 |
+
if ($websiteId <= 0) {
|
239 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
240 |
+
}
|
241 |
+
// get store id from request
|
242 |
+
$storeId = ( int ) $this->getRequest ()->getParam ( static::STOREID );
|
243 |
+
if ($storeId <= 0) {
|
244 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
245 |
+
}
|
246 |
+
|
247 |
+
// get page from request
|
248 |
+
$page = ( int ) $this->getRequest ()->getParam ( 'page' );
|
249 |
+
// get page from request
|
250 |
+
$limit = ( int ) $this->getRequest ()->getParam ( 'limit' );
|
251 |
+
|
252 |
+
/**
|
253 |
+
*
|
254 |
+
* @var $collection Mage_Sales_Model_Resource_Order_Collection
|
255 |
+
*/
|
256 |
+
$collection = Mage::getResourceModel ( 'sales/order_collection' );
|
257 |
+
if (isset ( $_GET ) && Mage::app ()->getRequest ()->getParam ( static::CUSTOMERID )) {
|
258 |
+
$collection->addFieldToFilter ( static::CUSTOMERID, Mage::app ()->getRequest ()->getParam ( static::CUSTOMERID ) )->addFieldToFilter ( static::STOREID, $storeId );
|
259 |
+
$collection->setPage ( $page, $limit );
|
260 |
+
$collection->setOrder ( static::CREATED_AT, 'DESC' );
|
261 |
+
}
|
262 |
+
|
263 |
+
if ($this->_isPaymentMethodAllowed ()) {
|
264 |
+
$this->_addPaymentMethodInfo ( $collection );
|
265 |
+
}
|
266 |
+
if ($this->_isGiftMessageAllowed ()) {
|
267 |
+
$this->_addGiftMessageInfo ( $collection );
|
268 |
+
}
|
269 |
+
$this->_addTaxInfo ( $collection );
|
270 |
+
$this->_applyCollectionModifiers ( $collection );
|
271 |
+
|
272 |
+
$ordersData = array ();
|
273 |
+
$i = 0;
|
274 |
+
$collection->getSelectSql ( true );
|
275 |
+
|
276 |
+
// get total orders count
|
277 |
+
$totalOrders = $collection->getSize ();
|
278 |
+
$last_page = ceil ( $totalOrders / $limit );
|
279 |
+
if ($last_page < $page) {
|
280 |
+
$success = 1;
|
281 |
+
$message = 'No Orders Found';
|
282 |
+
$ordersData = array ();
|
283 |
+
} else {
|
284 |
+
|
285 |
+
$collection = $collection->getItems ();
|
286 |
+
foreach ( $collection as $order ) {
|
287 |
+
$name = '';
|
288 |
/**
|
289 |
*
|
290 |
* @var $order Mage_Sales_Model_Order
|
291 |
*/
|
292 |
+
$order = Mage::getModel ( static::SALES_ORDER )->load ( $order->getId () );
|
293 |
+
$shipping_address = $order->getShippingAddress ();
|
294 |
+
$billing_address = $order->getBillingAddress ();
|
295 |
+
if ($shipping_address) {
|
296 |
+
$name = $shipping_address->getFirstname () . ' ' . $shipping_address->getLastname ();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
} else {
|
298 |
+
$name = $billing_address->getFirstname () . ' ' . $billing_address->getLastname ();
|
|
|
299 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
|
301 |
+
$ordersData [$i] [static::ORDER_ID] = $order->getIncrementId ();
|
302 |
+
$ordersData [$i] [static::STATUS] = ucfirst ( strtolower ( $order->getStatusLabel () ) );
|
303 |
+
$ordersData [$i] ['order_date'] = $order->getCreatedAt ();
|
304 |
+
$ordersData [$i] ['item_count'] = $order->getTotalItemCount ();
|
|
|
|
|
|
|
|
|
|
|
305 |
|
306 |
+
$ordersData [$i] ['grand_total'] = number_format ( $order->getGrandTotal (), 2, '.', '' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
|
308 |
+
$ordersData [$i] ['ship_name'] = $name;
|
309 |
+
$orderCurrencyCode = $order->getOrderCurrencyCode ();
|
310 |
+
$ordersData [$i] ['currency_symbol'] = Mage::app ()->getLocale ()->currency ( $orderCurrencyCode )->getSymbol ();
|
311 |
+
$i ++;
|
312 |
+
}
|
313 |
+
$success = 1;
|
314 |
+
$message = 'Orders listed successfully.';
|
315 |
+
}
|
316 |
+
|
317 |
+
$response [static::VALID_TOKEN] = true;
|
318 |
+
$response [static::ERROR] = false;
|
319 |
+
$response [static::SUCCESS] = $success;
|
320 |
+
$response [static::MESSAGE] = $message;
|
321 |
+
$response [static::TOTAL_COUNT] = $totalOrders;
|
322 |
+
$response [static::RESULT] = $ordersData;
|
323 |
+
return $response;
|
324 |
+
}
|
325 |
+
|
326 |
+
/**
|
327 |
+
* Get ordered item collection
|
328 |
+
*
|
329 |
+
* @param array $orderItems
|
330 |
+
* @return $items
|
331 |
+
*/
|
332 |
+
public function getOrderedItemDetail($orderItems, $orderId) {
|
333 |
+
$items = array ();
|
334 |
+
$catalogProduct = Mage::getModel ( static::CATALOG_PRO );
|
335 |
+
foreach ( $orderItems as $item ) {
|
336 |
+
$product = array ();
|
337 |
+
if ($item ['parent_item_id'] == '') {
|
338 |
+
/**
|
339 |
+
* load the product ID
|
340 |
+
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
|
342 |
+
$product ['entity_id'] = $item->product_id;
|
343 |
+
$product ['price'] = number_format ( $item->getPrice (), 2, '.', '' );
|
344 |
+
$product ['name'] = $item->getName ();
|
345 |
+
$_product = Mage::getModel ( static::CATALOG_PRO )->load ( $item->product_id );
|
346 |
+
$product ['image_url'] = ( string ) Mage::helper ( 'catalog/image' )->init ( $_product, 'thumbnail' );
|
347 |
+
$product ['qty'] = strval ( $item ['qty_ordered'] );
|
348 |
+
$product ['row_total'] = number_format ( $item ['base_row_total'], 2, '.', '' );
|
349 |
|
350 |
+
$product_options = $item ['product_options'];
|
351 |
+
$super_attribute = unserialize ( $product_options );
|
352 |
+
if (isset ( $super_attribute [static::ATTR_INFO] )) {
|
353 |
+
$product [static::ATTR_INFO] = $super_attribute ['attributes_info'];
|
354 |
+
} else {
|
355 |
+
$product [static::ATTR_INFO] = array ();
|
356 |
}
|
357 |
+
if (isset ( $super_attribute [static::OPTIONS] )) {
|
358 |
+
$product [static::OPTIONS] = $super_attribute [static::OPTIONS];
|
359 |
+
} else {
|
360 |
+
$product [static::OPTIONS] = array ();
|
361 |
+
}
|
362 |
+
if (Mage::getStoreConfig ( 'marketplace/marketplace/activate' )) {
|
363 |
+
|
364 |
+
$catalogProduct->load ( $item->product_id );
|
365 |
+
/**
|
366 |
+
* Get the Seller ID
|
367 |
+
*/
|
368 |
+
$sellerId = $catalogProduct->getSellerId ();
|
369 |
+
/**
|
370 |
+
* Get the Item order status
|
371 |
+
*/
|
372 |
+
$sellerStatus = $this->getMarketplaceStatus ( $sellerId, $item->product_id, $orderId );
|
373 |
+
$product [static::SELLER_STATUS] = $sellerStatus [static::SELLER_STATUS];
|
374 |
+
$product [static::SELLER_ID] = $sellerStatus [static::SELLER_ID];
|
375 |
}
|
376 |
|
377 |
+
$items [] = $product;
|
378 |
+
}
|
379 |
+
}
|
380 |
+
return $items;
|
381 |
+
}
|
382 |
+
|
383 |
+
/**
|
384 |
+
* Get the Seller Item order status
|
385 |
+
*
|
386 |
+
* @param int $sellerId
|
387 |
+
* @param int $productId
|
388 |
+
* @param int $orderId
|
389 |
+
* @return array $sellerStatus
|
390 |
+
*/
|
391 |
+
public function getMarketplaceStatus($sellerId, $productId, $orderId) {
|
392 |
+
$sellerStatus = array ();
|
393 |
+
if ($sellerId) {
|
394 |
+
/**
|
395 |
+
* Get the Seller Item order status
|
396 |
+
*/
|
397 |
+
$checkOrderStatus = Mage::getModel ( 'marketplace/commission' )->getCollection ()->addFieldToSelect ( 'item_order_status' )->addFieldToFilter ( 'increment_id', $orderId )->addFieldToFilter ( 'product_id', $productId )->addFieldToFilter ( 'seller_id', $sellerId );
|
398 |
+
|
399 |
+
foreach ( $checkOrderStatus as $orderStatus ) {
|
400 |
+
$sellerStatus [static::SELLER_STATUS] = $orderStatus ['item_order_status'];
|
401 |
+
}
|
402 |
+
$sellerStatus [static::SELLER_ID] = $sellerId;
|
403 |
+
} else {
|
404 |
+
$sellerStatus [static::SELLER_STATUS] = '';
|
405 |
+
$sellerStatus [static::SELLER_ID] = '';
|
406 |
+
}
|
407 |
+
return $sellerStatus;
|
408 |
+
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
* (non-PHPdoc)
|
412 |
+
*
|
413 |
+
* @see Mage_Api2_Model_Resource::_create($filteredData)
|
414 |
+
*/
|
415 |
+
public function _create(array $data) {
|
416 |
+
$response = array ();
|
417 |
+
$download_items = array ();
|
418 |
+
// get customer id from request
|
419 |
+
$customerId = ( int ) $data [static::CUSTOMERID];
|
420 |
+
|
421 |
+
/**
|
422 |
+
* Check this customer has valid token or not
|
423 |
+
*
|
424 |
+
* @var $isValidToken Mage_Login_Model_Token
|
425 |
+
*/
|
426 |
+
$isValidToken = Mage::getModel ( static::LOGIN_TOKEN )->checkUserToken ( $customerId, $data [static::TOKEN] );
|
427 |
+
|
428 |
+
try {
|
429 |
+
// check customer token
|
430 |
+
if (! $isValidToken) {
|
431 |
+
throw new Exception ( static::AUTH_ERR_MSG );
|
432 |
+
}
|
433 |
+
|
434 |
+
$purchased = Mage::getResourceModel ( 'downloadable/link_purchased_collection' )->addFieldToFilter ( static::CUSTOMERID, $customerId )->addOrder ( static::CREATED_AT, 'desc' );
|
435 |
+
|
436 |
+
$purchasedIds = array ();
|
437 |
+
// form array
|
438 |
+
foreach ( $purchased as $_item ) {
|
439 |
+
$purchasedIds [] = $_item->getId ();
|
440 |
+
}
|
441 |
+
if (empty ( $purchasedIds )) {
|
442 |
+
$purchasedIds = array (
|
443 |
+
null
|
444 |
+
);
|
445 |
+
}
|
446 |
+
|
447 |
+
/**
|
448 |
+
* $purchasedItems Mage_Downloadble_Model_Link_Purchase_Item_Collection
|
449 |
+
*/
|
450 |
+
$purchasedItems = Mage::getResourceModel ( 'downloadable/link_purchased_item_collection' )->addFieldToFilter ( static::PURCHASE_ID, array (
|
451 |
+
'in' => $purchasedIds
|
452 |
+
) )->addFieldToFilter ( static::STATUS, array (
|
453 |
+
'nin' => array (
|
454 |
+
Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING_PAYMENT,
|
455 |
+
Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PAYMENT_REVIEW
|
456 |
+
)
|
457 |
+
) )->setOrder ( static::ITEM_ID, 'desc' );
|
458 |
+
|
459 |
+
$success = 1;
|
460 |
+
$message = '';
|
461 |
+
$download_items = $this->getdownloadItemsLik ( $purchasedItems->getData () );
|
462 |
+
} catch ( Exception $e ) {
|
463 |
+
$success = 0;
|
464 |
+
$message = $e->getMessage ();
|
465 |
+
}
|
466 |
+
|
467 |
+
$response [static::VALID_TOKEN] = $isValidToken;
|
468 |
+
$response [static::ERROR] = false;
|
469 |
+
$response [static::SUCCESS] = $success;
|
470 |
+
$response [static::MESSAGE] = $message;
|
471 |
+
$response [static::RESULT] = $download_items;
|
472 |
+
|
473 |
+
$this->getResponse ()->setBody ( json_encode ( $response ) );
|
474 |
+
return;
|
475 |
+
}
|
476 |
+
|
477 |
+
/**
|
478 |
+
* Get Downloadable product collection
|
479 |
+
*
|
480 |
+
* @param array $items
|
481 |
+
* @return array:
|
482 |
+
*/
|
483 |
+
public function getdownloadItemsLik($items) {
|
484 |
+
$data = array ();
|
485 |
+
$j = 0;
|
486 |
+
foreach ( $items as $item ) {
|
487 |
+
$data [$j] [static::ITEM_ID] = $item [static::ITEM_ID];
|
488 |
+
$data [$j] [static::PURCHASE_ID] = $item [static::PURCHASE_ID];
|
489 |
+
$data [$j] [static::ORDER_ITEM_ID] = $item [static::ORDER_ITEM_ID];
|
490 |
+
// get product id
|
491 |
+
$data [$j] [static::PRODUCT_ID] = $item [static::PRODUCT_ID];
|
492 |
+
// get download link id
|
493 |
+
$data [$j] ['link_id'] = $item ['link_id'];
|
494 |
+
// get download title
|
495 |
+
$data [$j] ['link_title'] = $item ['link_title'];
|
496 |
+
// get media url
|
497 |
+
$mediaUrl = Mage::getBaseUrl ( Mage_Core_Model_Store::URL_TYPE_MEDIA );
|
498 |
+
// get download url
|
499 |
+
$data [$j] ['link_file'] = $mediaUrl . "downloadable/files/links" . $item ['link_file'];
|
500 |
+
// get status
|
501 |
+
$data [$j] [static::STATUS] = $item [static::STATUS];
|
502 |
+
// number_of_downloads_bought 0 ->unlimited
|
503 |
+
$data [$j] ['number_of_downloads_bought'] = $item ['number_of_downloads_bought'];
|
504 |
+
$data [$j] ['number_of_downloads_used'] = $item ['number_of_downloads_used'];
|
505 |
+
$data [$j] [static::CREATED_AT] = $item [static::CREATED_AT];
|
506 |
+
|
507 |
+
/**
|
508 |
+
*
|
509 |
+
* @var $orderItem Mage_Sales_Model_Order_Item
|
510 |
+
*/
|
511 |
+
$orderItem = Mage::getModel ( 'sales/order_item' )->getCollection ()->addFieldToFilter ( 'item_id', $item [static::ORDER_ITEM_ID] )->getFirstItem ();
|
512 |
+
|
513 |
+
/**
|
514 |
+
*
|
515 |
+
* @var $order Mage_Sales_Model_Order
|
516 |
+
*/
|
517 |
+
$order = Mage::getModel ( static::SALES_ORDER )->getCollection ()->addFieldToFilter ( 'entity_id', $orderItem->getOrderId () )->getFirstItem ();
|
518 |
+
|
519 |
+
$data [$j] [static::ORDER_ID] = $order->getIncrementId ();
|
520 |
+
|
521 |
+
$productModel = Mage::getModel ( static::CATALOG_PRO )->load ( $item [static::PRODUCT_ID] );
|
522 |
+
$data [$j] ['name'] = $productModel->getName ();
|
523 |
+
$j ++;
|
524 |
+
}
|
525 |
+
return $data;
|
526 |
+
}
|
527 |
+
|
528 |
+
/**
|
529 |
+
* Reorder option
|
530 |
+
*
|
531 |
+
* @see Mage_Api2_Model_Resource::_update($filteredData)
|
532 |
+
*/
|
533 |
+
public function _update(array $data) {
|
534 |
+
$response = array ();
|
535 |
+
$message = array ();
|
536 |
+
// get customer id from request
|
537 |
+
$customerId = ( int ) $data [static::CUSTOMERID];
|
538 |
+
|
539 |
+
// Get website id
|
540 |
+
$websiteId = (isset ( $data [static::WEBSITE_ID] )) ? $data [static::WEBSITE_ID] : Mage::app ()->getWebsite ( 'base' )->getId ();
|
541 |
+
// get store id
|
542 |
+
$storeId = (isset ( $data [static::STOREID] )) ? $data [static::STOREID] : Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
543 |
+
|
544 |
+
$orderId = $data ['order_id'];
|
545 |
+
/**
|
546 |
+
* Check this customer has valid token or not
|
547 |
+
*
|
548 |
+
* @var $isValidToken Mage_Login_Model_Token
|
549 |
+
*/
|
550 |
+
$isValidToken = Mage::getModel ( static::LOGIN_TOKEN )->checkUserToken ( $customerId, $data [static::TOKEN] );
|
551 |
+
$error_flag = true;
|
552 |
+
try {
|
553 |
+
if (! $isValidToken) {
|
554 |
+
throw new Exception ( static::AUTH_ERR_MSG );
|
555 |
+
}
|
556 |
+
|
557 |
+
$order = Mage::getModel ( static::SALES_ORDER )->loadByIncrementId ( $orderId );
|
558 |
+
$orderCurrencyCode = $order->getOrderCurrencyCode ();
|
559 |
+
|
560 |
+
// get cart quote by customer
|
561 |
+
$quote = Mage::getModel ( static::LOGIN_TOKEN )->setSaleQuoteByCustomer ( $customerId, $storeId, $orderCurrencyCode );
|
562 |
+
|
563 |
+
$i = 0;
|
564 |
+
// oop for all order items
|
565 |
+
$products = $order->getAllVisibleItems ();
|
566 |
+
foreach ( $products as $item ) {
|
567 |
|
568 |
+
$super_attribute = unserialize ( $item ['product_options'] );
|
569 |
+
$config [static::SUPER_ATTR] = $super_attribute ['info_buyRequest'] [static::SUPER_ATTR];
|
570 |
+
$config [static::OPTIONS] = $super_attribute ['info_buyRequest'] [static::OPTIONS];
|
|
|
|
|
571 |
|
572 |
+
$product = Mage::getModel ( 'multiCartapi/api2_multiCartapi' )->_getProduct ( $item->getProductId (), $storeId, 'id' );
|
573 |
+
if (is_null ( $product )) {
|
574 |
+
$error = $item->getProductId () . ' - Can not specify the product.';
|
575 |
+
} else {
|
576 |
+
$error = Mage::getModel ( 'multiCartapi/api2_multiCartapi' )->addToCart ( $product, $quote, $item->getQtyToInvoice (), $config );
|
577 |
+
}
|
578 |
|
579 |
+
if (is_string ( $error )) {
|
580 |
+
$messages [$i] [static::MESSAGE] = $item->getName () . '- ' . $error;
|
581 |
+
$messages [$i] [static::SUCCESS] = 0;
|
582 |
+
$error_flag = true;
|
583 |
+
} else {
|
584 |
+
$messages [$i] [static::MESSAGE] = $item->getName () . ' was added to your cart successfully.';
|
585 |
+
$messages [$i] [static::SUCCESS] = 1;
|
586 |
+
$error_flag = false;
|
587 |
+
}
|
588 |
|
589 |
+
$i ++;
|
590 |
+
}
|
591 |
+
$quote->collectTotals ();
|
592 |
+
$quote->save ();
|
593 |
+
if ($error_flag) {
|
594 |
+
$success = 0;
|
595 |
+
$message = 'Can not added to cart.';
|
596 |
+
} else {
|
597 |
+
$success = 1;
|
598 |
+
$message = 'Products added to cart successfully.';
|
599 |
+
}
|
600 |
+
} catch ( Mage_Core_Exception $e ) {
|
601 |
+
$success = 0;
|
602 |
+
$message = $e->getMessage ();
|
603 |
+
}
|
604 |
+
|
605 |
+
$response [static::VALID_TOKEN] = $isValidToken;
|
606 |
+
$response [static::ERROR] = false;
|
607 |
+
$response [static::SUCCESS] = $success;
|
608 |
+
$response [static::MESSAGE] = $message;
|
609 |
+
|
610 |
+
$response [static::RESULT] ['errors'] = $messages;
|
611 |
+
$this->getResponse ()->setBody ( json_encode ( $response ) );
|
612 |
+
return;
|
613 |
+
}
|
614 |
}
|
app/code/local/ContusRestapi/MyOrders/etc/api2.xml
CHANGED
@@ -60,6 +60,7 @@
|
|
60 |
<fax>Fax</fax>
|
61 |
<result>Result</result>
|
62 |
<token>Token</token>
|
|
|
63 |
</attributes>
|
64 |
|
65 |
<routes>
|
@@ -75,6 +76,12 @@
|
|
75 |
<action_type>collection</action_type>
|
76 |
</order_collection>
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
<!-- Downloadable Products collection -->
|
79 |
<downloadable_collection>
|
80 |
<route>/my_download/products/</route>
|
60 |
<fax>Fax</fax>
|
61 |
<result>Result</result>
|
62 |
<token>Token</token>
|
63 |
+
<order_id>Order Id</order_id>
|
64 |
</attributes>
|
65 |
|
66 |
<routes>
|
76 |
<action_type>collection</action_type>
|
77 |
</order_collection>
|
78 |
|
79 |
+
<!-- Reorder -->
|
80 |
+
<reorder>
|
81 |
+
<route>/reorder/</route>
|
82 |
+
<action_type>entity</action_type>
|
83 |
+
</reorder>
|
84 |
+
|
85 |
<!-- Downloadable Products collection -->
|
86 |
<downloadable_collection>
|
87 |
<route>/my_download/products/</route>
|
app/code/local/ContusRestapi/PlaceOrder/Model/Api2/PlaceOrderapi.php
CHANGED
@@ -27,296 +27,330 @@
|
|
27 |
* @since 1.0
|
28 |
*/
|
29 |
class ContusRestapi_PlaceOrder_Model_Api2_PlaceOrderapi extends Mage_Api2_Model_Resource {
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
$
|
103 |
-
$
|
104 |
-
|
105 |
-
$response ['isValidToken'] = $isValidToken;
|
106 |
-
$response ['error'] = false;
|
107 |
-
|
108 |
-
$this->getResponse ()->setBody ( json_encode ( $response ) );
|
109 |
-
return;
|
110 |
-
}
|
111 |
-
|
112 |
-
/**
|
113 |
-
* Place order using paypal standard payment
|
114 |
-
*
|
115 |
-
* @param object $quoteObj
|
116 |
-
* @param object $orderObj
|
117 |
-
* @return array
|
118 |
-
*/
|
119 |
-
public function paypalStandard($quoteObj, $orderObj) {
|
120 |
-
$response = array ();
|
121 |
-
$transaction = Mage::getModel ( 'core/resource_transaction' );
|
122 |
-
if ($quoteObj->getCustomerId ()) {
|
123 |
-
$transaction->addObject ( $quoteObj->getCustomer () );
|
124 |
-
}
|
125 |
-
|
126 |
-
$transaction->addObject ( $orderObj );
|
127 |
-
$transaction->addCommitCallback ( array (
|
128 |
-
$orderObj,
|
129 |
-
'place'
|
130 |
-
) );
|
131 |
-
$transaction->addCommitCallback ( array (
|
132 |
-
$orderObj,
|
133 |
-
'save'
|
134 |
-
) );
|
135 |
-
try {
|
136 |
-
$transaction->save ();
|
137 |
-
} catch ( Exception $e ) {
|
138 |
-
// Set error message if the place order get failed transaction.
|
139 |
-
$response [static::SUCCESS] = 0;
|
140 |
-
$response [static::MESSAGE] = $e->getMessage ();
|
141 |
-
}
|
142 |
-
|
143 |
-
Mage::dispatchEvent ( 'checkout_type_onepage_save_order_after', array (
|
144 |
-
'order' => $orderObj,
|
145 |
-
'quote' => $quoteObj
|
146 |
-
) );
|
147 |
-
$quoteObj->setIsActive ( 0 )->save ();
|
148 |
-
|
149 |
-
$response [static::MESSAGE] = static::SUCCESS_MSG;
|
150 |
-
$response [static::ORDER_ID] = $quoteObj->getreservedOrderId ();
|
151 |
-
$response [static::SUCCESS] = 1;
|
152 |
-
$resourcePath = Mage::getBaseUrl ( Mage_Core_Model_Store::URL_TYPE_WEB ) . 'paypal/';
|
153 |
-
$redirectUrl = $resourcePath . 'redirect.php?id=' . $response [static::ORDER_ID];
|
154 |
-
$response [static::URL] = $redirectUrl;
|
155 |
-
|
156 |
-
return $response;
|
157 |
-
}
|
158 |
-
|
159 |
-
/**
|
160 |
-
* Place order using paypal stanadard
|
161 |
-
*
|
162 |
-
* @return array json array
|
163 |
-
*/
|
164 |
-
protected function _retrieveCollection() {
|
165 |
-
$response = array ();
|
166 |
-
$redirectUrl = '';
|
167 |
-
// get website id from request
|
168 |
-
$websiteId = ( int ) $this->getRequest ()->getParam ( 'website_id' );
|
169 |
-
if ($websiteId <= 0) {
|
170 |
-
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
171 |
-
}
|
172 |
-
// get website id from request
|
173 |
-
$storeId = ( int ) $this->getRequest ()->getParam ( 'store_id' );
|
174 |
-
if ($storeId <= 0) {
|
175 |
-
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
176 |
-
}
|
177 |
-
// get quote id
|
178 |
-
$quoteId = ( int ) $this->getRequest ()->getParam ( 'quote_id' );
|
179 |
-
// get customer id
|
180 |
-
$customerId = ( int ) $this->getRequest ()->getParam ( 'customer_id' );
|
181 |
-
|
182 |
-
/**
|
183 |
-
* Check this customer has valid token or not
|
184 |
-
*
|
185 |
-
* @var $isValidToken Mage_Login_Model_Token
|
186 |
-
*/
|
187 |
-
$isValidToken = Mage::getModel ( 'login/token' )->checkUserToken ( $customerId, $this->getRequest ()->getParam ( 'token' ) );
|
188 |
-
try {
|
189 |
-
$paymentMethod = $this->getRequest ()->getParam ( 'payment_method' );
|
190 |
-
$shippingMethod = $this->getRequest ()->getParam ( 'shipping_method' );
|
191 |
-
|
192 |
-
if (! $isValidToken) {
|
193 |
-
throw new Exception ( 'Authentication failed.' );
|
194 |
-
}
|
195 |
-
|
196 |
-
$quoteObj = Mage::getModel ( 'sales/quote' );
|
197 |
-
$quoteObj->setStoreId ( $storeId )->load ( $quoteId );
|
198 |
-
$active = $quoteObj->getIsActive ();
|
199 |
-
if (! $active) {
|
200 |
-
throw new Exception ( 'Quote is invalid!.' );
|
201 |
-
}
|
202 |
-
|
203 |
-
$quoteObj->reserveOrderId ();
|
204 |
-
$transactionModel = Mage::getModel ( 'core/resource_transaction' );
|
205 |
-
if ($quoteObj->getCustomerId ()) {
|
206 |
-
$transactionModel->addObject ( $quoteObj->getCustomer () );
|
207 |
-
}
|
208 |
-
$transactionModel->addObject ( $quoteObj );
|
209 |
-
$quoteObj->getAllItems ();
|
210 |
-
$orderObj = $this->SetQuoteObject ( $quoteObj, $shippingMethod, $paymentMethod );
|
211 |
-
|
212 |
-
$transactionModel->addObject ( $orderObj );
|
213 |
-
$transactionModel->addCommitCallback ( array (
|
214 |
-
$orderObj,
|
215 |
-
'place'
|
216 |
-
) );
|
217 |
-
$transactionModel->addCommitCallback ( array (
|
218 |
-
$orderObj,
|
219 |
-
'save'
|
220 |
-
) );
|
221 |
-
try {
|
222 |
-
$transactionModel->save ();
|
223 |
-
} catch ( Exception $e ) {
|
224 |
-
// Set error message if the place order get failed transaction.
|
225 |
-
$response [static::SUCCESS] = 0;
|
226 |
-
$response [static::MESSAGE] = $e->getMessage ();
|
227 |
-
}
|
228 |
-
|
229 |
-
Mage::dispatchEvent ( 'checkout_type_onepage_save_order_after', array (
|
230 |
-
'order' => $orderObj,
|
231 |
-
'quote' => $quoteObj
|
232 |
-
) );
|
233 |
$quoteObj->setIsActive ( 0 )->save ();
|
234 |
-
|
235 |
$response [static::MESSAGE] = static::SUCCESS_MSG;
|
236 |
$response [static::ORDER_ID] = $quoteObj->getreservedOrderId ();
|
237 |
$response [static::SUCCESS] = 1;
|
238 |
-
$
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
313 |
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
$orderObj->
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
}
|
27 |
* @since 1.0
|
28 |
*/
|
29 |
class ContusRestapi_PlaceOrder_Model_Api2_PlaceOrderapi extends Mage_Api2_Model_Resource {
|
30 |
+
const MESSAGE = 'message';
|
31 |
+
const SUCCESS = 'success';
|
32 |
+
const ORDER_ID = 'order_id';
|
33 |
+
const URL = 'url';
|
34 |
+
const SUCCESS_MSG = 'Order placed successfully.';
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Place order using Cash on delivery
|
38 |
+
*
|
39 |
+
* @return array json array
|
40 |
+
*/
|
41 |
+
protected function _create(array $data) {
|
42 |
+
$response = array ();
|
43 |
+
|
44 |
+
// get customer id
|
45 |
+
$customerId = ( int ) $data ['customer_id'];
|
46 |
+
// get quote id
|
47 |
+
$quoteId = ( int ) $data ['quote_id'];
|
48 |
+
|
49 |
+
// get website id
|
50 |
+
$websiteId = ( int ) $data ['website_id'];
|
51 |
+
if ($websiteId <= 0) {
|
52 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
53 |
+
}
|
54 |
+
// get website id from request
|
55 |
+
$storeId = ( int ) $data ['store_id'];
|
56 |
+
if ($storeId <= 0) {
|
57 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Check this customer has valid token or not
|
62 |
+
*
|
63 |
+
* @var $isValidToken Mage_Login_Model_Token
|
64 |
+
*/
|
65 |
+
$isValidToken = Mage::getModel ( 'login/token' )->checkUserToken ( $customerId, $data ['token'] );
|
66 |
+
|
67 |
+
try {
|
68 |
+
$paymentMethod = $data ['payment_method'];
|
69 |
+
$shippingMethod = $data ['shipping_method'];
|
70 |
+
$quoteObj = Mage::getModel ( 'sales/quote' );
|
71 |
+
$quoteObj->setStoreId ( $storeId )->load ( $quoteId );
|
72 |
+
// check customer token
|
73 |
+
if (! $isValidToken) {
|
74 |
+
throw new Exception ( 'Authentication failed.' );
|
75 |
+
}
|
76 |
+
// check quote id in valid
|
77 |
+
$active = $quoteObj->getIsActive ();
|
78 |
+
if (! $active) {
|
79 |
+
throw new Exception ( 'Quote is invalid!.' );
|
80 |
+
}
|
81 |
+
$quoteObj->getAllItems ();
|
82 |
+
$quoteObj->reserveOrderId ();
|
83 |
+
$orderObj = $this->SetQuoteObject ( $quoteObj, $shippingMethod, $paymentMethod );
|
84 |
+
|
85 |
+
// Add delivery info to order
|
86 |
+
if (Mage::getStoreConfig ( 'deliveryschedule/general/delivery_schedule_enabled' ) == 1) {
|
87 |
+
$this->addDeliveryInfo ( $quoteObj, $orderObj, $data );
|
88 |
+
}
|
89 |
+
|
90 |
+
// Add gift message id to this order
|
91 |
+
if ($data ['surprise_gift'] == 1) {
|
92 |
+
$this->addGift ( $quoteObj, $orderObj, $customerId, $data );
|
93 |
+
}
|
94 |
+
|
95 |
+
if ($paymentMethod == 'paypal_standard') {
|
96 |
+
$result = $this->paypalStandard ( $quoteObj, $orderObj );
|
97 |
+
$response [static::MESSAGE] = $result [static::MESSAGE];
|
98 |
+
$response [static::ORDER_ID] = $result [static::ORDER_ID];
|
99 |
+
$response [static::SUCCESS] = $result [static::SUCCESS];
|
100 |
+
$response [static::URL] = $result [static::URL];
|
101 |
+
} else {
|
102 |
+
$orderObj->place ();
|
103 |
+
$orderObj->save ();
|
104 |
+
$orderObj->sendNewOrderEmail ();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
$quoteObj->setIsActive ( 0 )->save ();
|
|
|
106 |
$response [static::MESSAGE] = static::SUCCESS_MSG;
|
107 |
$response [static::ORDER_ID] = $quoteObj->getreservedOrderId ();
|
108 |
$response [static::SUCCESS] = 1;
|
109 |
+
$response [static::URL] = '';
|
110 |
+
}
|
111 |
+
} catch ( Exception $e ) {
|
112 |
+
$response [static::SUCCESS] = 0;
|
113 |
+
$response [static::MESSAGE] = $e->getMessage ();
|
114 |
+
}
|
115 |
+
$response ['isValidToken'] = $isValidToken;
|
116 |
+
$response ['error'] = false;
|
117 |
+
|
118 |
+
$this->getResponse ()->setBody ( json_encode ( $response ) );
|
119 |
+
return;
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Place order using paypal standard payment
|
124 |
+
*
|
125 |
+
* @param object $quoteObj
|
126 |
+
* @param object $orderObj
|
127 |
+
* @return array
|
128 |
+
*/
|
129 |
+
public function paypalStandard($quoteObj, $orderObj) {
|
130 |
+
$response = array ();
|
131 |
+
$transaction = Mage::getModel ( 'core/resource_transaction' );
|
132 |
+
if ($quoteObj->getCustomerId ()) {
|
133 |
+
$transaction->addObject ( $quoteObj->getCustomer () );
|
134 |
+
}
|
135 |
+
|
136 |
+
$transaction->addObject ( $orderObj );
|
137 |
+
$transaction->addCommitCallback ( array (
|
138 |
+
$orderObj,
|
139 |
+
'place'
|
140 |
+
) );
|
141 |
+
$transaction->addCommitCallback ( array (
|
142 |
+
$orderObj,
|
143 |
+
'save'
|
144 |
+
) );
|
145 |
+
try {
|
146 |
+
$transaction->save ();
|
147 |
+
} catch ( Exception $e ) {
|
148 |
+
// Set error message if the place order get failed transaction.
|
149 |
+
$response [static::SUCCESS] = 0;
|
150 |
+
$response [static::MESSAGE] = $e->getMessage ();
|
151 |
+
}
|
152 |
+
|
153 |
+
Mage::dispatchEvent ( 'checkout_type_onepage_save_order_after', array (
|
154 |
+
'order' => $orderObj,
|
155 |
+
'quote' => $quoteObj
|
156 |
+
) );
|
157 |
+
$quoteObj->setIsActive ( 0 )->save ();
|
158 |
+
|
159 |
+
$response [static::MESSAGE] = static::SUCCESS_MSG;
|
160 |
+
$response [static::ORDER_ID] = $quoteObj->getreservedOrderId ();
|
161 |
+
$response [static::SUCCESS] = 1;
|
162 |
+
$resourcePath = Mage::getBaseUrl ( Mage_Core_Model_Store::URL_TYPE_WEB ) . 'paypal/';
|
163 |
+
$redirectUrl = $resourcePath . 'redirect.php?id=' . $response [static::ORDER_ID] . '&expType=mini';
|
164 |
+
$response [static::URL] = $redirectUrl;
|
165 |
+
|
166 |
+
return $response;
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Add shipping and payment method
|
171 |
+
*
|
172 |
+
* @param object $quoteObj
|
173 |
+
* @param string $shippingMethod
|
174 |
+
* @param string $paymentMethod
|
175 |
+
* @return object
|
176 |
+
*/
|
177 |
+
public function SetQuoteObject($quoteObj, $shippingMethod, $paymentMethod) {
|
178 |
+
|
179 |
+
// set shipping method
|
180 |
+
$quoteObj->getShippingAddress ()->setShippingMethod ( $shippingMethod );
|
181 |
+
$quoteObj->getShippingAddress ()->setCollectShippingRates ( false );
|
182 |
+
$quoteObj->getShippingAddress ()->collectShippingRates ();
|
183 |
+
|
184 |
+
$items = $quoteObj->getAllItems ();
|
185 |
+
// set payment method
|
186 |
+
$quotePaymentObj = $quoteObj->getPayment ();
|
187 |
+
// Mage_Sales_Model_Quote_Payment
|
188 |
+
$quotePaymentObj->setMethod ( $paymentMethod );
|
189 |
+
$quoteObj->setPayment ( $quotePaymentObj );
|
190 |
+
$quoteObj->collectTotals ();
|
191 |
+
$quoteObj->save ();
|
192 |
+
|
193 |
+
// convert quote to order
|
194 |
+
$convertQuoteObj = Mage::getSingleton ( 'sales/convert_quote' );
|
195 |
+
$orderObj = $convertQuoteObj->addressToOrder ( $quoteObj->getShippingAddress () );
|
196 |
+
$convertQuoteObj->paymentToOrderPayment ( $quotePaymentObj );
|
197 |
+
|
198 |
+
// convert quote addresses
|
199 |
+
$orderObj->setBillingAddress ( $convertQuoteObj->addressToOrderAddress ( $quoteObj->getBillingAddress () ) );
|
200 |
+
$orderObj->setShippingAddress ( $convertQuoteObj->addressToOrderAddress ( $quoteObj->getShippingAddress () ) );
|
201 |
+
|
202 |
+
// set payment options
|
203 |
+
$orderObj->setPayment ( $convertQuoteObj->paymentToOrderPayment ( $quoteObj->getPayment () ) );
|
204 |
+
|
205 |
+
// convert quote items
|
206 |
+
$orderObj = $this->addQuoteProduct ( $items, $convertQuoteObj, $orderObj );
|
207 |
+
|
208 |
+
$orderObj->setCanShipPartiallyItem ( TRUE );
|
209 |
+
|
210 |
+
return $orderObj;
|
211 |
+
}
|
212 |
+
|
213 |
+
/**
|
214 |
+
* Add products to Sales_order_items table
|
215 |
+
*
|
216 |
+
* @param array $items
|
217 |
+
* @param object $convertQuoteObj
|
218 |
+
* @param object $orderObj
|
219 |
+
* @return object $orderObj
|
220 |
+
*/
|
221 |
+
public function addQuoteProduct($items, $convertQuoteObj, $orderObj) {
|
222 |
+
|
223 |
+
// convert quote items
|
224 |
+
foreach ( $items as $item ) {
|
225 |
+
$itemDesc = $item->getItemDescription ();
|
226 |
+
$orderItem = $convertQuoteObj->itemToOrderItem ( $item );
|
227 |
+
$options = array ();
|
228 |
+
|
229 |
+
if ($productOptions = $item->getProduct ()->getTypeInstance ( TRUE )->getOrderOptions ( $item->getProduct () )) {
|
230 |
+
$options = $productOptions;
|
231 |
+
}
|
232 |
+
|
233 |
+
if ($addOptions = $item->getOptionByCode ( 'additional_options' )) {
|
234 |
+
$options ['additional_options'] = unserialize ( $addOptions->getValue () );
|
235 |
+
}
|
236 |
+
|
237 |
+
if ($options) {
|
238 |
+
$orderItem->setProductOptions ( $options );
|
239 |
+
}
|
240 |
+
|
241 |
+
if ($itemDesc) {
|
242 |
+
$orderItem->setName ( $itemDesc );
|
243 |
+
}
|
244 |
+
|
245 |
+
if ($item->getParentItem ()) {
|
246 |
+
$orderItem->setParentItem ( $orderObj->getItemByQuoteItemId ( $item->getParentItem ()->getId () ) );
|
247 |
+
}
|
248 |
+
$orderObj->addItem ( $orderItem );
|
249 |
+
Mage::getSingleton ( 'cataloginventory/stock' )->registerItemSale ( $orderItem );
|
250 |
+
}
|
251 |
+
|
252 |
+
return $orderObj;
|
253 |
+
}
|
254 |
+
|
255 |
+
/**
|
256 |
+
* Add delivery information to quote,address and order
|
257 |
+
*
|
258 |
+
* @param object $quoteObj
|
259 |
+
* @param object $orderObj
|
260 |
+
* @param array $data
|
261 |
+
*/
|
262 |
+
public function addDeliveryInfo($quoteObj, $orderObj, $data) {
|
263 |
+
$desiredDeliverySchedule = $data ['delivery_schedule_types'];
|
264 |
+
$shippingDeliveryTimeId = $data ['shipping_delivery_time'];
|
265 |
+
$shippingDeliveryCost = $data ['shipping_delivery_cost'];
|
266 |
+
$desireDeliveryDate = $data ['shipping_delivery_date'];
|
267 |
+
$desireDeliveryComments = $data ['shipping_delivery_comments'];
|
268 |
+
$delivery_time = $data ['delivery_time'];
|
269 |
+
/**
|
270 |
+
* shipping delivery time slot using id
|
271 |
+
*/
|
272 |
+
$getTimeById = Mage::helper ( 'deliveryschedule' )->getTimeById ( $shippingDeliveryTimeId );
|
273 |
+
/**
|
274 |
+
* get delivery schedule type by id
|
275 |
+
*/
|
276 |
+
$getScheduleTypeById = Mage::helper ( 'deliveryschedule' )->getScheduleTypeById ( $desiredDeliverySchedule );
|
277 |
+
$title = $scheduleTypeName = "";
|
278 |
+
foreach ( $getTimeById as $row ) {
|
279 |
+
$title = $row->getTitle ();
|
280 |
+
}
|
281 |
+
foreach ( $getScheduleTypeById as $rows ) {
|
282 |
+
$scheduleTypeName = $rows->getName ();
|
283 |
+
}
|
284 |
+
if (isset ( $desireDeliveryDate ) && ! empty ( $desireDeliveryDate )) {
|
285 |
+
// save deliver info to sales_flat_quote table
|
286 |
+
$quoteObj->setShippingDeliverySchedule ( $scheduleTypeName );
|
287 |
+
$quoteObj->setShippingDeliveryComments ( $desireDeliveryComments );
|
288 |
+
$quoteObj->setShippingDeliveryDate ( $desireDeliveryDate );
|
289 |
+
$quoteObj->setShippingDeliveryTime ( $title );
|
290 |
+
$quoteObj->setShippingDeliveryCost ( $shippingDeliveryCost );
|
291 |
+
$quoteObj->setDeliveryTime ( $delivery_time );
|
292 |
+
$quoteObj->save ();
|
293 |
+
|
294 |
+
// save delivery info to sales_flat_order table
|
295 |
+
$orderObj->setShippingDeliverySchedule ( $scheduleTypeName );
|
296 |
+
$orderObj->setShippingDeliveryComments ( $desireDeliveryComments );
|
297 |
+
$orderObj->setShippingDeliveryDate ( $desireDeliveryDate );
|
298 |
+
$orderObj->setShippingDeliveryTime ( $title );
|
299 |
+
$orderObj->setShippingDeliveryCost ( $shippingDeliveryCost );
|
300 |
+
$orderObj->setDeliveryTime ( $delivery_time );
|
301 |
+
if ($shippingDeliveryCost != '') {
|
302 |
+
$address = $quoteObj->getShippingAddress ();
|
303 |
+
// save delivery info to sales/quote_address table
|
304 |
+
$address->setDeliveryCost ( $shippingDeliveryCost );
|
305 |
+
$address->setBaseDeliveryCost ( $shippingDeliveryCost );
|
306 |
+
// calculate GrandTotal
|
307 |
+
$address->setGrandTotal ( $address->getGrandTotal () + $address->getDeliveryCost () );
|
308 |
+
$address->setBaseGrandTotal ( $address->getBaseGrandTotal () + $address->getBaseDeliveryCost () );
|
309 |
|
310 |
+
// save delivery cost to sales_flat_order table
|
311 |
+
$orderObj->setDeliveryCost ( $shippingDeliveryCost );
|
312 |
+
$orderObj->setBaseDeliveryCost ( $shippingDeliveryCost );
|
313 |
+
$orderObj->setGrandTotal ( $address->getGrandTotal () );
|
314 |
+
$orderObj->setBaseGrandTotal ( $address->getBaseGrandTotal () );
|
315 |
+
$orderObj->save ();
|
316 |
+
}
|
317 |
+
}
|
318 |
+
}
|
319 |
+
|
320 |
+
/**
|
321 |
+
* Add Gift mesage to this order and quote
|
322 |
+
*
|
323 |
+
* @param object $quoteObj
|
324 |
+
* @param object $orderObj
|
325 |
+
*/
|
326 |
+
public function addGift($quoteObj, $orderObj, $customerId, $data) {
|
327 |
+
|
328 |
+
/**
|
329 |
+
* load customer info
|
330 |
+
*/
|
331 |
+
$customerInfo = Mage::getModel ( 'customer/customer' )->load ( $customerId );
|
332 |
+
// get sender name from customer info
|
333 |
+
$fromName = $customerInfo->getName ();
|
334 |
+
// get recepient name from shipping address
|
335 |
+
$toName = $quoteObj->getShippingAddress ()->getName ();
|
336 |
+
|
337 |
+
/**
|
338 |
+
* Laod gift message model
|
339 |
+
*
|
340 |
+
* @var $giftMessage Mage_Giftmessage_Model_Message
|
341 |
+
*/
|
342 |
+
$giftMessage = Mage::getModel ( 'giftmessage/message' );
|
343 |
+
$giftMessage->setCustomerId ( $customerId );
|
344 |
+
$giftMessage->setSender ( $fromName );
|
345 |
+
$giftMessage->setRecipient ( $toName );
|
346 |
+
$giftMessage->setMessage ( $data ['gift_message'] );
|
347 |
+
$giftObj = $giftMessage->save ();
|
348 |
+
|
349 |
+
// save gift message id to quote
|
350 |
+
$quoteObj->setGiftMessageId ( $giftObj->getId () );
|
351 |
+
$quoteObj->save ();
|
352 |
+
// save gift message id to order
|
353 |
+
$orderObj->setGiftMessageId ( $giftObj->getId () );
|
354 |
+
$orderObj->save ();
|
355 |
+
}
|
356 |
}
|
app/code/local/ContusRestapi/PlaceOrder/Model/Sales/Quote/Address/Total/Deliverycost.php
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Apptha
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Apptha
|
23 |
+
* @package Apptha_Deliveryschedule
|
24 |
+
* @version 0.1.0
|
25 |
+
* @author Apptha Team <developers@contus.in>
|
26 |
+
* @copyright Copyright (c) 2015 Apptha. (http://www.apptha.com)
|
27 |
+
* @license http://www.apptha.com/LICENSE.txt
|
28 |
+
*
|
29 |
+
* */
|
30 |
+
class Apptha_Deliveryschedule_Model_Sales_Quote_Address_Total_Deliverycost extends Mage_Sales_Model_Quote_Address_Total_Abstract{
|
31 |
+
/**
|
32 |
+
* set code for display delivery cost
|
33 |
+
*/
|
34 |
+
protected $_code = 'deliveryschedule';
|
35 |
+
/**
|
36 |
+
* collect(Mage_Sales_Model_Quote_Address $address)- used to set suntotal and grand total amount based on delivery cost
|
37 |
+
*/
|
38 |
+
public function collect(Mage_Sales_Model_Quote_Address $address) {
|
39 |
+
parent::collect($address);
|
40 |
+
$this->_setAmount(0);
|
41 |
+
$this->_setBaseAmount(0);
|
42 |
+
|
43 |
+
$items = $this->_getAddressItems($address);
|
44 |
+
if (!count($items)) {
|
45 |
+
/**
|
46 |
+
* this makes only address type shipping to come through
|
47 |
+
*/
|
48 |
+
return $this;
|
49 |
+
}
|
50 |
+
$quote = $address->getQuote();
|
51 |
+
$deliveryCost=$quote->getShippingDeliveryCost();
|
52 |
+
$address->setDeliveryCost($deliveryCost);
|
53 |
+
$address->setBaseDeliveryCost($deliveryCost);
|
54 |
+
$quote->setDeliveryCost($deliveryCost);
|
55 |
+
$address->setGrandTotal($address->getGrandTotal() + $address->getDeliveryCost());
|
56 |
+
$address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseDeliveryCost());
|
57 |
+
}
|
58 |
+
/**
|
59 |
+
* fetch(Mage_Sales_Model_Quote_Address $address) - used to set a delivery cost before the grnd total
|
60 |
+
*/
|
61 |
+
public function fetch(Mage_Sales_Model_Quote_Address $address) {
|
62 |
+
$amt = $address->getDeliveryCost();
|
63 |
+
/**
|
64 |
+
* check if $amt is not zero
|
65 |
+
*/
|
66 |
+
if($amt !=0){
|
67 |
+
$address->addTotal(array(
|
68 |
+
'code'=>$this->getCode(),
|
69 |
+
'title'=>Mage::helper('deliveryschedule')->__('Delivery Cost'),
|
70 |
+
'value'=> $amt
|
71 |
+
));
|
72 |
+
}
|
73 |
+
/**
|
74 |
+
* return array
|
75 |
+
*/
|
76 |
+
return $this;
|
77 |
+
}
|
78 |
+
}
|
79 |
+
|
80 |
+
|
app/code/local/ContusRestapi/PlaceOrder/etc/api2.xml
CHANGED
@@ -40,6 +40,14 @@
|
|
40 |
<message>message</message>
|
41 |
<order_id>Order Id</order_id>
|
42 |
<payment_url>Payment Url</payment_url>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
</attributes>
|
44 |
<routes>
|
45 |
<!-- Place order using Knet -->
|
40 |
<message>message</message>
|
41 |
<order_id>Order Id</order_id>
|
42 |
<payment_url>Payment Url</payment_url>
|
43 |
+
<delivery_schedule_types>delivery_schedule_types</delivery_schedule_types>
|
44 |
+
<shipping_delivery_time>shipping_delivery_time</shipping_delivery_time>
|
45 |
+
<shipping_delivery_cost>shipping_delivery_cost</shipping_delivery_cost>
|
46 |
+
<shipping_delivery_date>shipping_delivery_date</shipping_delivery_date>
|
47 |
+
<shipping_delivery_comments>shipping_delivery_comments</shipping_delivery_comments>
|
48 |
+
<delivery_time>Delivery Time</delivery_time>
|
49 |
+
<surprise_gift>Surprise Gift</surprise_gift>
|
50 |
+
<gift_message>gift_message</gift_message>
|
51 |
</attributes>
|
52 |
<routes>
|
53 |
<!-- Place order using Knet -->
|
app/code/local/ContusRestapi/PlaceOrder/etc/config.xml
CHANGED
@@ -11,5 +11,16 @@
|
|
11 |
<class>ContusRestapi_PlaceOrder_Model</class>
|
12 |
</placeOrder>
|
13 |
</models>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
</global>
|
15 |
</config>
|
11 |
<class>ContusRestapi_PlaceOrder_Model</class>
|
12 |
</placeOrder>
|
13 |
</models>
|
14 |
+
|
15 |
+
<!-- <sales>
|
16 |
+
<quote>
|
17 |
+
<totals>
|
18 |
+
<placeOrder>
|
19 |
+
<class>placeOrder/sales_quote_address_total_deliverycost</class>
|
20 |
+
</placeOrder>
|
21 |
+
</totals>
|
22 |
+
</quote>
|
23 |
+
</sales> -->
|
24 |
+
|
25 |
</global>
|
26 |
</config>
|
app/code/local/ContusRestapi/ProductList/Model/Api2/ProductList/Rest.php
CHANGED
@@ -31,740 +31,914 @@
|
|
31 |
* @since 1.0
|
32 |
*/
|
33 |
class ContusRestapi_ProductList_Model_Api2_ProductList_Rest extends Mage_Catalog_Model_Api2_Product_Rest {
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
$
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
$
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
'type' => $option->getType (),
|
263 |
-
static::OPTIONID => $option->getOptionId (),
|
264 |
-
'product_id' => $option->getProductId (),
|
265 |
-
'type' => $option->getType (),
|
266 |
-
'is_require' => $option->getIsRequire (),
|
267 |
-
'sort_order' => $option->getSortOrder (),
|
268 |
-
static::TITLE => $option->getTitle (),
|
269 |
-
static::PRICE => $option->getPrice (),
|
270 |
-
'price_type' => $option->getPriceType (),
|
271 |
-
'option_value' => $optionVal
|
272 |
-
);
|
273 |
-
}
|
274 |
-
|
275 |
-
return $options;
|
276 |
-
}
|
277 |
-
|
278 |
-
/**
|
279 |
-
* Get config options for configurable product
|
280 |
-
*
|
281 |
-
* @param object $product
|
282 |
-
* @param int $storeId
|
283 |
-
* @return array $result
|
284 |
-
*/
|
285 |
-
public function getConfigurableProductOptions($product, $storeId) {
|
286 |
-
// get product price
|
287 |
-
$finalPrice = $product->getFinalPrice ();
|
288 |
-
|
289 |
-
// Load all used configurable attributes
|
290 |
-
$configurableAttributeCollection = $product->getTypeInstance ( true )->getConfigurableAttributes ( $product );
|
291 |
-
|
292 |
-
$allProducts = $product->getTypeInstance ( true )->getUsedProducts ( null, $product );
|
293 |
-
foreach ( $allProducts as $product ) {
|
294 |
-
$products [] = $product;
|
295 |
-
}
|
296 |
-
|
297 |
-
$options = array ();
|
298 |
-
$result = array ();
|
299 |
-
$i = 0;
|
300 |
-
foreach ( $configurableAttributeCollection as $productAttribute ) {
|
301 |
-
$options [$i] [static::TITLE] = $productAttribute ['label'];
|
302 |
-
$options [$i] ['code'] = $productAttribute->getProductAttribute ()->getAttributeCode ();
|
303 |
-
$options [$i] ['attribute_id'] = $productAttribute ['attribute_id'];
|
304 |
-
$i ++;
|
305 |
-
}
|
306 |
-
$result ['config'] = $options;
|
307 |
-
$resultattr = array ();
|
308 |
-
// Get combinations
|
309 |
-
foreach ( $products as $product ) {
|
310 |
-
$attr = array ();
|
311 |
-
// get produt stock qty for simple product
|
312 |
-
/**
|
313 |
-
*
|
314 |
-
* @var $stockItem Mage_CatalogInventory_Model_Stock_Item
|
315 |
-
*/
|
316 |
-
$stockItem = $product->getStockItem ();
|
317 |
-
if (! $stockItem) {
|
318 |
-
$stockItem = Mage::getModel ( static::CATSTOCK );
|
319 |
-
$stockItem->loadByProduct ( $product );
|
320 |
-
}
|
321 |
-
$stockQty = floor ( $stockItem->getQty () );
|
322 |
-
$is_stock = $stockItem->getIsInStock ();
|
323 |
-
$j = 0;
|
324 |
-
foreach ( $configurableAttributeCollection as $attribute ) {
|
325 |
-
|
326 |
-
$productAttribute = $attribute->getProductAttribute ();
|
327 |
-
$attrCode = $productAttribute->getAttributeCode ();
|
328 |
-
$attributeValue = $product->getData ( $attrCode );
|
329 |
-
|
330 |
-
/* getting option text value */
|
331 |
-
if ($productAttribute->usesSource ()) {
|
332 |
-
$label = $productAttribute->setStoreId ( $storeId )->getSource ()->getOptionText ( $attributeValue );
|
333 |
-
} else {
|
334 |
-
$label = '';
|
335 |
-
}
|
336 |
-
|
337 |
-
/**
|
338 |
-
* Get price for associated product
|
339 |
-
*/
|
340 |
-
$prices = $attribute->getPrices ();
|
341 |
-
$value = $product->getData ( $attribute->getProductAttribute ()->getAttributeCode () );
|
342 |
-
|
343 |
-
$valuearry ['label'] = $label;
|
344 |
-
$valuearry ['code'] = $attrCode;
|
345 |
-
$valuearry ['config_id'] = $attributeValue;
|
346 |
-
$valuearry [static::ISSTOCK] = $is_stock;
|
347 |
-
$valuearry ['stock_qty'] = $stockQty;
|
348 |
-
$valuearry [static::PRICE] = $this->calculateCustumPrice ( $prices, $value, $finalPrice );
|
349 |
-
|
350 |
-
$val [$options [$j] ['code']] = $attributeValue;
|
351 |
-
$j ++;
|
352 |
-
array_push ( $attr, $valuearry );
|
353 |
-
}
|
354 |
-
// get configurable product options
|
355 |
-
$attr = $this->getAttrColl ( $val, $attr );
|
356 |
-
|
357 |
-
$resultattr = array_merge ( $resultattr, $attr );
|
358 |
-
}
|
359 |
-
$result ['attr'] = $resultattr;
|
360 |
-
return $result;
|
361 |
-
}
|
362 |
-
|
363 |
-
/**
|
364 |
-
* Get price for config options
|
365 |
-
*
|
366 |
-
* @param array $prices
|
367 |
-
* @param string $value
|
368 |
-
* @param float $finalPrice
|
369 |
-
* @return string $totalPrice
|
370 |
-
*/
|
371 |
-
public function calculateCustumPrice($prices, $value, $finalPrice) {
|
372 |
-
$totalPrice = 0;
|
373 |
-
foreach ( $prices as $price ) {
|
374 |
-
if ($price ['is_percent']) {
|
375 |
-
// if the price is specified in percents
|
376 |
-
$pricesByAttributeValues [$price ['value_index']] = ( float ) $price ['pricing_value'] * $finalPrice / 100;
|
377 |
} else {
|
378 |
-
|
379 |
-
$pricesByAttributeValues [$price ['value_index']] = ( float ) $price ['pricing_value'];
|
380 |
}
|
381 |
-
}
|
382 |
-
|
383 |
-
if (isset ( $pricesByAttributeValues [$value] )) {
|
384 |
-
$totalPrice = $pricesByAttributeValues [$value];
|
385 |
-
}
|
386 |
-
return strval ( $totalPrice );
|
387 |
-
}
|
388 |
-
|
389 |
-
/**
|
390 |
-
* Collect configurable product options
|
391 |
-
*
|
392 |
-
* @param array $val
|
393 |
-
* @param array $attr
|
394 |
-
* @return array $attr
|
395 |
-
*/
|
396 |
-
public function getAttrColl($val, $attr) {
|
397 |
-
$attr [0] ['attr_id'] = array ();
|
398 |
-
foreach ( $val as $key => $value ) {
|
399 |
|
400 |
-
for($k = 0; $k < count ( $attr ); $k ++) {
|
401 |
-
$attrValue = array ();
|
402 |
-
if ($attr [$k] ['code'] != $key) {
|
403 |
-
$attrValue ['value'] = $value;
|
404 |
-
$attrValue ['code'] = $key;
|
405 |
-
|
406 |
-
$attr [$k] ['attr_id'] [] = $attrValue;
|
407 |
-
}
|
408 |
-
}
|
409 |
-
}
|
410 |
-
return $attr;
|
411 |
-
}
|
412 |
-
|
413 |
-
/**
|
414 |
-
* Get Downloadable product
|
415 |
-
*
|
416 |
-
* @param object $product
|
417 |
-
* @return array $links
|
418 |
-
*/
|
419 |
-
public function getDownloadableLinks($product) {
|
420 |
-
$productAttributeLinks = $product->getTypeInstance ( true )->getLinks ( $product );
|
421 |
-
$i = 0;
|
422 |
-
foreach ( $productAttributeLinks as $productLinks ) {
|
423 |
-
$links [$i] ['link_id'] = $productLinks->getLinkId ();
|
424 |
-
$links [$i] [static::ENTITYID] = $productLinks->getProductId ();
|
425 |
-
$links [$i] ['is_require'] = $product->getLinksPurchasedSeparately ();
|
426 |
-
$links [$i] [static::PRICE] = $productLinks->getPrice ();
|
427 |
-
$links [$i] [static::TITLE] = $productLinks->getTitle ();
|
428 |
$i ++;
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
$totalProducts = $collection->getSize ();
|
481 |
-
$products = $collection->load ();
|
482 |
-
|
483 |
-
// get total pages with limit
|
484 |
-
$last_page = ceil ( $totalProducts / $limit );
|
485 |
-
if ($last_page < $page) {
|
486 |
-
$productArray = array ();
|
487 |
-
} else {
|
488 |
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
510 |
|
511 |
-
$
|
512 |
-
$
|
513 |
-
$
|
514 |
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
return $productArray;
|
519 |
-
}
|
520 |
-
|
521 |
-
/**
|
522 |
-
* Add special fields to product get response
|
523 |
-
*
|
524 |
-
* @param Mage_Catalog_Model_Product $product
|
525 |
-
*/
|
526 |
-
protected function _prepareProductForResponse(Mage_Catalog_Model_Product $product) {
|
527 |
-
$websiteId = ( int ) $this->getRequest ()->getParam ( static::WEBSITE_ID );
|
528 |
-
if ($websiteId <= 0) {
|
529 |
-
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
530 |
-
}
|
531 |
-
// get store id from request
|
532 |
-
$storeId = ( int ) $this->getRequest ()->getParam ( static::STORE_ID );
|
533 |
-
if ($storeId <= 0) {
|
534 |
-
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
535 |
-
}
|
536 |
-
// get customer id from request
|
537 |
-
$customerId = ( int ) $this->getRequest ()->getParam ( 'customer_id' );
|
538 |
-
|
539 |
-
// get image size for resize
|
540 |
-
$imageSize = ( int ) $this->getRequest ()->getParam ( 'image_size' );
|
541 |
-
|
542 |
-
/**
|
543 |
-
*
|
544 |
-
* @var $productHelper Mage_Catalog_Helper_Product
|
545 |
-
*/
|
546 |
-
$productHelper = Mage::helper ( 'catalog/product' );
|
547 |
-
|
548 |
-
$productData [static::ENTITYID] = $product->getEntity_id ();
|
549 |
-
$productData [static::NAME] = $product->getName ();
|
550 |
-
$productData ['type_id'] = $product->getTypeId ();
|
551 |
-
$product->setWebsiteId ( $websiteId );
|
552 |
-
// customer group is required in product for correct prices calculation
|
553 |
-
$product->setCustomerGroupId ( $this->_getCustomerGroupId () );
|
554 |
-
// calculate prices
|
555 |
-
$finalPrice = $product->getFinalPrice ();
|
556 |
-
if ($product->getTypeId () == 'grouped') {
|
557 |
-
$productData ['regular_price_with_tax'] = number_format ( $product->getMinimalPrice (), 2, '.', '' );
|
558 |
-
$productData ['final_price_with_tax'] = number_format ( $product->getMinimalPrice (), 2, '.', '' );
|
559 |
-
} else {
|
560 |
-
$productData ['regular_price_with_tax'] = number_format ( $this->_applyTaxToPrice ( $product->getPrice (), true ), 2, '.', '' );
|
561 |
-
$productData ['regular_price_without_tax'] = number_format ( $this->_applyTaxToPrice ( $product->getPrice (), false ), 2, '.', '' );
|
562 |
-
$productData ['final_price_with_tax'] = number_format ( $this->_applyTaxToPrice ( $finalPrice, true ), 2, '.', '' );
|
563 |
-
$productData ['final_price_without_tax'] = number_format ( $this->_applyTaxToPrice ( $finalPrice, false ), 2, '.', '' );
|
564 |
-
}
|
565 |
-
|
566 |
-
// get product stock details
|
567 |
-
$stockDetail = Mage::getModel ( static::LOGIN_TOKEN )->getStockDetail ( $product );
|
568 |
-
$productData [static::IS_SALEABLE] = $stockDetail [static::IS_SALEABLE];
|
569 |
-
$productData [static::ISSTOCK] = $stockDetail ['is_stock'];
|
570 |
-
// get product image
|
571 |
-
if ($imageSize <= 0) {
|
572 |
-
$productData [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, static::SMALLIMG );
|
573 |
-
} else {
|
574 |
-
$productData [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, static::SMALLIMG )->constrainOnly ( TRUE )->keepAspectRatio ( TRUE )->keepFrame ( FALSE )->resize ( $imageSize, null );
|
575 |
-
}
|
576 |
-
|
577 |
-
// get rating
|
578 |
-
$productData ['summary_rating'] = Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $product->getId (), $storeId ) ? Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $product->getId (), $storeId ) : '0';
|
579 |
-
|
580 |
-
// get wishlisted products by customer
|
581 |
-
$wishListIds = array ();
|
582 |
-
if ($customerId > 0) {
|
583 |
-
$wishListIds = Mage::getModel ( static::LOGIN_TOKEN )->getWishlistByCustomer ( $customerId );
|
584 |
-
}
|
585 |
-
// Check to see the product is in wishlist
|
586 |
-
if (in_array ( $product->getId (), $wishListIds )) {
|
587 |
-
$productData [static::ISWISHLIST] = true;
|
588 |
-
} else {
|
589 |
-
$productData [static::ISWISHLIST] = false;
|
590 |
-
}
|
591 |
-
if ($this->getActionType () == static::ACTION_TYPE_ENTITY) {
|
592 |
-
// define URLs
|
593 |
-
$productData ['url'] = $productHelper->getProductUrl ( $product->getId () );
|
594 |
-
if ($imageSize <= 0) {
|
595 |
-
$productData [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, 'image' );
|
596 |
} else {
|
597 |
-
|
598 |
}
|
599 |
-
/**
|
600 |
-
*
|
601 |
-
* @var $cartHelper Mage_Checkout_Helper_Cart
|
602 |
-
*/
|
603 |
-
$cartHelper = Mage::helper ( 'checkout/cart' );
|
604 |
-
$productData ['buy_now_url'] = $cartHelper->getAddUrl ( $product );
|
605 |
|
606 |
/**
|
607 |
-
*
|
608 |
-
* @var $reviewModel Mage_Review_Model_Review
|
609 |
*/
|
610 |
-
$
|
611 |
-
$
|
612 |
|
613 |
-
$
|
614 |
-
|
615 |
-
$
|
616 |
-
|
617 |
-
|
618 |
-
$
|
619 |
-
unset ( $productData [static::TIERPRICE] );
|
620 |
-
}
|
621 |
-
return $productData;
|
622 |
-
}
|
623 |
-
|
624 |
-
/**
|
625 |
-
* Filter products collection
|
626 |
-
*
|
627 |
-
* @param object $collection
|
628 |
-
* @param int $storeId
|
629 |
-
* @return mixed object
|
630 |
-
*/
|
631 |
-
public function _getProductByFilter($collection, $storeId) {
|
632 |
-
|
633 |
-
// get filter types attributes
|
634 |
-
$filters = json_decode ( $this->getRequest ()->getParam ( 'filters' ), true );
|
635 |
-
|
636 |
-
if (array_key_exists ( static::PRICE, $filters )) {
|
637 |
|
638 |
-
|
639 |
-
$
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
695 |
}
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
|
|
770 |
}
|
31 |
* @since 1.0
|
32 |
*/
|
33 |
class ContusRestapi_ProductList_Model_Api2_ProductList_Rest extends Mage_Catalog_Model_Api2_Product_Rest {
|
34 |
+
|
35 |
+
// Declaring the string literals variable
|
36 |
+
const ENTITYID = 'entity_id';
|
37 |
+
const NAME = 'name';
|
38 |
+
const IMGURL = 'image_url';
|
39 |
+
const REGULARPRICE = 'regular_price';
|
40 |
+
const FINALPRICE = 'final_price';
|
41 |
+
const PRODUCTTYPE = 'product_type';
|
42 |
+
const PROCOLLECTION = 'collection';
|
43 |
+
const VISIBILITY = 'visibility';
|
44 |
+
const STATUS = 'status';
|
45 |
+
const CATIMG = 'catalog/image';
|
46 |
+
const SMALLIMG = 'small_image';
|
47 |
+
const PRICE = 'price';
|
48 |
+
const TIERPRICE = 'tier_price';
|
49 |
+
const ISWISHLIST = 'is_wishlist';
|
50 |
+
const RATING = 'rating';
|
51 |
+
const OPTIONS = 'options';
|
52 |
+
const CATSTOCK = 'cataloginventory/stock_item';
|
53 |
+
const ISSTOCK = 'is_stock';
|
54 |
+
const OPTIONID = 'option_id';
|
55 |
+
const TITLE = 'title';
|
56 |
+
const WEBSITE_ID = 'website_id';
|
57 |
+
const STORE_ID = 'store_id';
|
58 |
+
const LOGIN_TOKEN = 'login/token';
|
59 |
+
const IS_IN_STOCK = 'is_in_stock';
|
60 |
+
const E_ENTITY_ID = 'e.entity_id';
|
61 |
+
const AVAILABILITY = 'availability';
|
62 |
+
const IS_SALEABLE = 'is_saleable';
|
63 |
+
const MEDIA = 'media';
|
64 |
+
const MOBILEAPP = 'mobileapp';
|
65 |
+
const RESIZED = 'resized';
|
66 |
+
const ATTRIBUTE_ID = 'attribute_id';
|
67 |
+
const CAT_PRO = 'catalog/product';
|
68 |
+
const SELLER_ID = 'seller_id';
|
69 |
+
const STOCK_QTY = 'stock_qty';
|
70 |
+
const MIN_SALE_QTY = 'min_sale_qty';
|
71 |
+
const MAX_SALE_QTY = 'max_sale_qty';
|
72 |
+
const QTY_INCR = 'qty_increments';
|
73 |
+
const IS_QTY_DECIMAL = 'is_qty_decimal';
|
74 |
+
CONST LOGIN_FUNCTIONS = 'login/methods_functions';
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Retrieve product data
|
78 |
+
*
|
79 |
+
* @return array
|
80 |
+
*/
|
81 |
+
protected function _retrieve() {
|
82 |
+
$response = array ();
|
83 |
+
|
84 |
+
// get website id from request
|
85 |
+
$websiteId = ( int ) $this->getRequest ()->getParam ( static::WEBSITE_ID );
|
86 |
+
if ($websiteId <= 0) {
|
87 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
88 |
+
}
|
89 |
+
|
90 |
+
// get store id from request
|
91 |
+
$storeId = ( int ) $this->getRequest ()->getParam ( static::STORE_ID );
|
92 |
+
if ($storeId <= 0) {
|
93 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
94 |
+
}
|
95 |
+
|
96 |
+
$productDetail = array ();
|
97 |
+
// get default product details
|
98 |
+
$product = $this->_getProduct ();
|
99 |
+
// load producs based on store id
|
100 |
+
$product->setStoreId ( $storeId )->load ( $product->getId () );
|
101 |
+
$productDetail = $this->_prepareProductForResponse ( $product );
|
102 |
+
|
103 |
+
// get product description
|
104 |
+
$productDetail ['description'] = $product->getDescription ();
|
105 |
+
// get product short description
|
106 |
+
$productDetail ['short_description'] = $product->getShortDescription ();
|
107 |
+
|
108 |
+
// get additional images for product
|
109 |
+
$productDetail ['images'] = $this->getProductImages ( $product );
|
110 |
+
|
111 |
+
// Getting ratings/reviews
|
112 |
+
// get only five revieews in product detail page
|
113 |
+
$reviews = Mage::getModel ( static::LOGIN_TOKEN )->getReviews ( $product->getId (), $storeId, 1, 5 );
|
114 |
+
$productDetail ['reviews'] = $reviews ['reviews'];
|
115 |
+
// get product rating count summary
|
116 |
+
$ratings = Mage::getModel ( static::LOGIN_TOKEN )->getRatingResult ( $product->getId (), $storeId );
|
117 |
+
$productDetail [static::RATING] = $ratings [static::RATING];
|
118 |
+
|
119 |
+
$type = $product->getTypeId ();
|
120 |
+
$options = array ();
|
121 |
+
$super_group = array ();
|
122 |
+
$links = array ();
|
123 |
+
switch ($type) {
|
124 |
+
case Mage_Catalog_Model_Product_Type::TYPE_GROUPED :
|
125 |
+
$super_group = $this->getGroupedProductOptions ( $product );
|
126 |
+
break;
|
127 |
+
|
128 |
+
case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE :
|
129 |
+
$options = $this->getConfigurableProductOptions ( $product, $storeId );
|
130 |
+
break;
|
131 |
+
|
132 |
+
case Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE :
|
133 |
+
$links = $this->getDownloadableLinks ( $product );
|
134 |
+
break;
|
135 |
+
|
136 |
+
default :
|
137 |
+
break;
|
138 |
+
}
|
139 |
+
// get configurable product options
|
140 |
+
if (! empty ( $options )) {
|
141 |
+
$productDetail [static::OPTIONS] = $options;
|
142 |
+
}
|
143 |
+
// get grouped product options
|
144 |
+
if (! empty ( $super_group )) {
|
145 |
+
$productDetail ['group_options'] = $super_group;
|
146 |
+
}
|
147 |
+
|
148 |
+
// get downloadble product links
|
149 |
+
if (! empty ( $links )) {
|
150 |
+
$productDetail ['links'] = $links;
|
151 |
+
}
|
152 |
+
|
153 |
+
// get custom options
|
154 |
+
$customOptions = $this->getCustomOptions ( $product );
|
155 |
+
$productDetail ['custom_options'] = $customOptions;
|
156 |
+
|
157 |
+
if (Mage::getStoreConfig ( 'marketplace/marketplace/activate' )) {
|
158 |
+
$productDetail ['seller_info'] = $this->getmarketPlaceDetal ( $product, $storeId );
|
159 |
+
}
|
160 |
+
|
161 |
+
$response ['error'] = false;
|
162 |
+
$response ['success'] = 1;
|
163 |
+
$response ['result'] = $productDetail;
|
164 |
+
return $response;
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Get seller details
|
169 |
+
*
|
170 |
+
* @param objet $product
|
171 |
+
* @param int $storeId
|
172 |
+
* @return array $sellers
|
173 |
+
*/
|
174 |
+
public function getmarketPlaceDetal($product, $storeId) {
|
175 |
+
$productId = $product->getEntity_id ();
|
176 |
+
// Get Seller Id
|
177 |
+
$sellerId = $product->getData ( static::SELLER_ID );
|
178 |
+
if ($sellerId > 0) {
|
179 |
+
$currentSeller [] = Mage::getModel ( static::LOGIN_FUNCTIONS )->sellerdisplay ( $sellerId, '1', $storeId, $productId );
|
180 |
+
}
|
181 |
+
$allSellers = $this->getSellerInfo ( $productId );
|
182 |
+
return array_merge ( ( array ) $currentSeller, ( array ) $allSellers );
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Get Seller info by product id
|
187 |
+
*
|
188 |
+
* @param int $productId
|
189 |
+
* return array sellers information
|
190 |
+
*/
|
191 |
+
public function getSellerInfo($productId) {
|
192 |
+
$sellerInfo = array ();
|
193 |
+
$i = 0;
|
194 |
+
$collection = $this->getComparePrice ( $productId );
|
195 |
+
|
196 |
+
foreach ( $collection as $_collection ) {
|
197 |
+
$sellerId = $_collection->getSellerId ();
|
198 |
+
if ($sellerId > 0) {
|
199 |
+
$sellerInfo [$i] = Mage::getModel ( static::LOGIN_FUNCTIONS )->sellerdisplay ( $sellerId, '0', $storeId, $_collection->getId () );
|
200 |
+
}
|
201 |
+
$i ++;
|
202 |
+
if ($i == count ( $collection )) {
|
203 |
+
continue;
|
204 |
+
}
|
205 |
+
}
|
206 |
+
return $sellerInfo;
|
207 |
+
}
|
208 |
+
|
209 |
+
/**
|
210 |
+
* Get Product Collection with 'compare_product_id' attribute filter
|
211 |
+
*
|
212 |
+
* Passed the product id for which we need to compare price
|
213 |
+
*
|
214 |
+
* @param int $productId
|
215 |
+
* Return product collection as array
|
216 |
+
* @return array
|
217 |
+
*/
|
218 |
+
public function getComparePrice($productId) {
|
219 |
+
$productCollection = Mage::getModel ( static::CAT_PRO )->getCollection ()->addAttributeToSelect ( '*' )->addAttributeToFilter ( 'is_assign_product', array (
|
220 |
+
'eq' => 1
|
221 |
+
) )->addAttributeToFilter ( static::STATUS, array (
|
222 |
+
'eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED
|
223 |
+
) );
|
224 |
+
|
225 |
+
$productCollection->addFieldToFilter ( 'assign_product_id', array (
|
226 |
+
'eq' => $productId
|
227 |
+
) );
|
228 |
+
$productCollection->setOrder ( 'price', 'ASC' );
|
229 |
+
return $productCollection;
|
230 |
+
}
|
231 |
+
|
232 |
+
/**
|
233 |
+
* Function to get seller product
|
234 |
+
*
|
235 |
+
* Passed the seller id as $sellerId to get particular seller products
|
236 |
+
*
|
237 |
+
* @param int $sellerId
|
238 |
+
* Return products of the seller
|
239 |
+
*/
|
240 |
+
function sellerproduct($sellerid) {
|
241 |
+
$sellerproduct = Mage::getModel ( static::CAT_PRO )->getCollection ()->addFieldToFilter ( static::SELLER_ID, $sellerid );
|
242 |
+
return $sellerproduct->getData ();
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* Get product Images
|
247 |
+
*
|
248 |
+
* @param object $product
|
249 |
+
* @return array $product_images
|
250 |
+
*/
|
251 |
+
public function getProductImages($product) {
|
252 |
+
$_images = $product->getMediaGalleryImages ();
|
253 |
+
$product_images = array ();
|
254 |
+
// get image size for resize
|
255 |
+
$imageSize = ( int ) $this->getRequest ()->getParam ( 'image_size' );
|
256 |
+
|
257 |
+
if (isset ( $_images )) {
|
258 |
+
$i = 0;
|
259 |
+
foreach ( $_images as $_image ) {
|
260 |
+
if ($imageSize <= 0) {
|
261 |
+
$product_images [$i] = $_image->url;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
} else {
|
263 |
+
$product_images [$i] = $this->imageResize ( $_image->url, $imageSize );
|
|
|
264 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
$i ++;
|
267 |
+
}
|
268 |
+
}
|
269 |
+
return $product_images;
|
270 |
+
}
|
271 |
+
/**
|
272 |
+
* Image resize and store
|
273 |
+
*
|
274 |
+
* @param string $imageUrl
|
275 |
+
* @param int $imageSize
|
276 |
+
* @return string image url
|
277 |
+
*/
|
278 |
+
public function imageResize($imageUrl, $imageSize) {
|
279 |
+
if (! file_exists ( Mage::getBaseDir ( static::MEDIA ) . DS . static::MOBILEAPP . DS . static::RESIZED )) {
|
280 |
+
mkdir ( Mage::getBaseDir ( static::MEDIA ) . DS . static::MOBILEAPP . DS . static::RESIZED, 0777 );
|
281 |
+
}
|
282 |
+
|
283 |
+
$imageName = substr ( strrchr ( $imageUrl, "/" ), 1 );
|
284 |
+
// get file extension
|
285 |
+
$extension = end ( explode ( ".", $imageName ) );
|
286 |
+
$imageName = uniqid () . '.' . $extension;
|
287 |
+
$imageResized = Mage::getBaseDir ( static::MEDIA ) . DS . static::MOBILEAPP . DS . static::RESIZED . DS . $imageName;
|
288 |
+
$dirImg = Mage::getBaseDir () . str_replace ( "/", DS, strstr ( $imageUrl, '/' . static::MEDIA ) );
|
289 |
+
if (! file_exists ( $imageResized ) && file_exists ( $dirImg )) :
|
290 |
+
$imageObj = new Varien_Image ( $dirImg );
|
291 |
+
$imageObj->constrainOnly ( true );
|
292 |
+
$imageObj->keepAspectRatio ( true );
|
293 |
+
$imageObj->keepFrame ( false );
|
294 |
+
$imageObj->resize ( $imageSize, null );
|
295 |
+
$imageObj->save ( $imageResized );
|
296 |
+
|
297 |
+
|
298 |
+
|
299 |
+
|
300 |
+
|
301 |
+
|
302 |
+
endif;
|
303 |
+
return Mage::getBaseUrl ( static::MEDIA ) . static::MOBILEAPP . "/" . static::RESIZED . "/" . $imageName;
|
304 |
+
}
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Grouped Product Options - Get Associated products
|
308 |
+
*
|
309 |
+
* @param object $product
|
310 |
+
* @return array $options
|
311 |
+
*/
|
312 |
+
public function getGroupedProductOptions($product) {
|
313 |
+
$options = array ();
|
314 |
+
$associatedProducts = $product->getTypeInstance ( true )->getAssociatedProducts ( $product );
|
315 |
+
|
316 |
+
if (count ( $associatedProducts )) {
|
317 |
+
foreach ( $associatedProducts as $product ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
|
319 |
+
// get stock data
|
320 |
+
$stockItem = Mage::getModel ( static::CATSTOCK )->loadByProduct ( $product->getId () );
|
321 |
+
$options [] = array (
|
322 |
+
static::OPTIONID => $product->getId (),
|
323 |
+
'option_value' => $product->getName (),
|
324 |
+
'option_title' => $product->getName (),
|
325 |
+
'option_regular_price' => number_format ( $product->getPrice (), 2, '.', '' ),
|
326 |
+
'option_final_price' => number_format ( $product->getFinalPrice (), 2, '.', '' ),
|
327 |
+
'option_image' => $product->getThumbnailUrl ( 105, 80 ),
|
328 |
+
static::ISSTOCK => ($stockItem->getIsInStock () > 0)
|
329 |
+
);
|
330 |
+
}
|
331 |
+
}
|
332 |
+
|
333 |
+
return $options;
|
334 |
+
}
|
335 |
+
|
336 |
+
/**
|
337 |
+
* Get Custom options of Simple Product
|
338 |
+
*
|
339 |
+
* @param object $product
|
340 |
+
* @return array $options
|
341 |
+
*/
|
342 |
+
public function getCustomOptions($product) {
|
343 |
+
$options = array ();
|
344 |
+
$optionsData = $product->getOptions ();
|
345 |
+
foreach ( $optionsData as $option ) {
|
346 |
+
$optionVal = array ();
|
347 |
+
$optionValues = $option->getValues ();
|
348 |
+
foreach ( $optionValues as $optVal ) {
|
349 |
+
$optionVal [] = array (
|
350 |
+
static::OPTIONID => $optVal->getOptionId (),
|
351 |
+
'option_type_id' => $optVal->getOptionTypeId (),
|
352 |
+
'sku' => $optVal->getSku (),
|
353 |
+
'sort_order' => $optVal->getSortOrder (),
|
354 |
+
static::TITLE => $optVal->getTitle (),
|
355 |
+
static::PRICE => $optVal->getPrice (),
|
356 |
+
'price_type' => $optVal->getPriceType ()
|
357 |
+
);
|
358 |
+
}
|
359 |
+
|
360 |
+
$options [] = array (
|
361 |
+
'type' => $option->getType (),
|
362 |
+
static::OPTIONID => $option->getOptionId (),
|
363 |
+
'product_id' => $option->getProductId (),
|
364 |
+
'type' => $option->getType (),
|
365 |
+
'is_require' => $option->getIsRequire (),
|
366 |
+
'sort_order' => $option->getSortOrder (),
|
367 |
+
static::TITLE => $option->getTitle (),
|
368 |
+
static::PRICE => $option->getPrice (),
|
369 |
+
'price_type' => $option->getPriceType (),
|
370 |
+
'option_value' => $optionVal
|
371 |
+
);
|
372 |
+
}
|
373 |
+
|
374 |
+
return $options;
|
375 |
+
}
|
376 |
+
|
377 |
+
/**
|
378 |
+
* Get config options for configurable product
|
379 |
+
*
|
380 |
+
* @param object $product
|
381 |
+
* @param int $storeId
|
382 |
+
* @return array $result
|
383 |
+
*/
|
384 |
+
public function getConfigurableProductOptions($product, $storeId) {
|
385 |
+
// get product price
|
386 |
+
$finalPrice = $product->getFinalPrice ();
|
387 |
+
|
388 |
+
// Load all used configurable attributes
|
389 |
+
$configurableAttributeCollection = $product->getTypeInstance ( true )->getConfigurableAttributes ( $product );
|
390 |
+
|
391 |
+
$allProducts = $product->getTypeInstance ( true )->getUsedProducts ( null, $product );
|
392 |
+
foreach ( $allProducts as $product ) {
|
393 |
+
$products [] = $product;
|
394 |
+
}
|
395 |
+
|
396 |
+
$options = array ();
|
397 |
+
$result = array ();
|
398 |
+
$i = 0;
|
399 |
+
foreach ( $configurableAttributeCollection as $productAttribute ) {
|
400 |
+
$options [$i] [static::TITLE] = $productAttribute ['label'];
|
401 |
+
$options [$i] ['code'] = $productAttribute->getProductAttribute ()->getAttributeCode ();
|
402 |
+
$options [$i] [static::ATTRIBUTE_ID] = $productAttribute [static::ATTRIBUTE_ID];
|
403 |
+
$i ++;
|
404 |
+
}
|
405 |
+
$result ['config'] = $options;
|
406 |
+
$resultattr = array ();
|
407 |
+
// Get combinations
|
408 |
+
foreach ( $products as $product ) {
|
409 |
+
$attr = array ();
|
410 |
+
// get produt stock qty for simple product
|
411 |
+
/**
|
412 |
+
*
|
413 |
+
* @var $stockItem Mage_CatalogInventory_Model_Stock_Item
|
414 |
+
*/
|
415 |
+
$stockItem = $product->getStockItem ();
|
416 |
+
if (! $stockItem) {
|
417 |
+
$stockItem = Mage::getModel ( static::CATSTOCK );
|
418 |
+
$stockItem->loadByProduct ( $product );
|
419 |
+
}
|
420 |
+
$stockQty = floor ( $stockItem->getQty () );
|
421 |
+
$is_stock = $stockItem->getIsInStock ();
|
422 |
+
$j = 0;
|
423 |
+
$valuearry ['product_id'] = $product->getId ();
|
424 |
+
// get product stock details
|
425 |
+
$inventoryDetail = Mage::getModel ( static::LOGIN_FUNCTIONS )->getinventoryDetail ( $product, $storeId );
|
426 |
+
// get stock qty
|
427 |
+
$valuearry [static::STOCK_QTY] = $inventoryDetail [static::STOCK_QTY];
|
428 |
+
$valuearry [static::MIN_SALE_QTY] = $inventoryDetail [static::MIN_SALE_QTY];
|
429 |
+
$valuearry [static::MAX_SALE_QTY] = $inventoryDetail [static::MAX_SALE_QTY];
|
430 |
+
$valuearry [static::QTY_INCR] = $inventoryDetail [static::QTY_INCR];
|
431 |
+
$valuearry [static::IS_QTY_DECIMAL] = $inventoryDetail [static::IS_QTY_DECIMAL];
|
432 |
+
foreach ( $configurableAttributeCollection as $attribute ) {
|
433 |
|
434 |
+
$productAttribute = $attribute->getProductAttribute ();
|
435 |
+
$attrCode = $productAttribute->getAttributeCode ();
|
436 |
+
$attributeValue = $product->getData ( $attrCode );
|
437 |
|
438 |
+
/* getting option text value */
|
439 |
+
if ($productAttribute->usesSource ()) {
|
440 |
+
$label = $productAttribute->setStoreId ( $storeId )->getSource ()->getOptionText ( $attributeValue );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
441 |
} else {
|
442 |
+
$label = '';
|
443 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
|
445 |
/**
|
446 |
+
* Get price for associated product
|
|
|
447 |
*/
|
448 |
+
$prices = $attribute->getPrices ();
|
449 |
+
$value = $product->getData ( $attribute->getProductAttribute ()->getAttributeCode () );
|
450 |
|
451 |
+
$valuearry ['label'] = $label;
|
452 |
+
$valuearry ['code'] = $attrCode;
|
453 |
+
$valuearry ['config_id'] = $attributeValue;
|
454 |
+
$valuearry [static::ISSTOCK] = $is_stock;
|
455 |
+
$valuearry ['stock_qty'] = $stockQty;
|
456 |
+
$valuearry [static::PRICE] = $this->calculateCustumPrice ( $prices, $value, $finalPrice );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
457 |
|
458 |
+
$val [$options [$j] ['code']] = $attributeValue;
|
459 |
+
$j ++;
|
460 |
+
array_push ( $attr, $valuearry );
|
461 |
+
}
|
462 |
+
// get configurable product options
|
463 |
+
$attr = $this->getAttrColl ( $val, $attr );
|
464 |
+
|
465 |
+
$resultattr = array_merge ( $resultattr, $attr );
|
466 |
+
}
|
467 |
+
$result ['attr'] = $resultattr;
|
468 |
+
return $result;
|
469 |
+
}
|
470 |
+
|
471 |
+
/**
|
472 |
+
* Get price for config options
|
473 |
+
*
|
474 |
+
* @param array $prices
|
475 |
+
* @param string $value
|
476 |
+
* @param float $finalPrice
|
477 |
+
* @return string $totalPrice
|
478 |
+
*/
|
479 |
+
public function calculateCustumPrice($prices, $value, $finalPrice) {
|
480 |
+
$totalPrice = 0;
|
481 |
+
foreach ( $prices as $price ) {
|
482 |
+
if ($price ['is_percent']) {
|
483 |
+
// if the price is specified in percents
|
484 |
+
$pricesByAttributeValues [$price ['value_index']] = ( float ) $price ['pricing_value'] * $finalPrice / 100;
|
485 |
+
} else {
|
486 |
+
// if the price is absolute value
|
487 |
+
$pricesByAttributeValues [$price ['value_index']] = ( float ) $price ['pricing_value'];
|
488 |
+
}
|
489 |
+
}
|
490 |
+
|
491 |
+
if (isset ( $pricesByAttributeValues [$value] )) {
|
492 |
+
$totalPrice = $pricesByAttributeValues [$value];
|
493 |
+
}
|
494 |
+
return strval ( $totalPrice );
|
495 |
+
}
|
496 |
+
|
497 |
+
/**
|
498 |
+
* Collect configurable product options
|
499 |
+
*
|
500 |
+
* @param array $val
|
501 |
+
* @param array $attr
|
502 |
+
* @return array $attr
|
503 |
+
*/
|
504 |
+
public function getAttrColl($val, $attr) {
|
505 |
+
$attr [0] ['attr_id'] = array ();
|
506 |
+
foreach ( $val as $key => $value ) {
|
507 |
+
|
508 |
+
for($k = 0; $k < count ( $attr ); $k ++) {
|
509 |
+
$attrValue = array ();
|
510 |
+
if ($attr [$k] ['code'] != $key) {
|
511 |
+
$attrValue ['value'] = $value;
|
512 |
+
$attrValue ['code'] = $key;
|
513 |
+
|
514 |
+
$attr [$k] ['attr_id'] [] = $attrValue;
|
515 |
+
}
|
516 |
+
}
|
517 |
+
}
|
518 |
+
return $attr;
|
519 |
+
}
|
520 |
+
|
521 |
+
/**
|
522 |
+
* Load product by its SKU or ID provided in request
|
523 |
+
*
|
524 |
+
* @return Mage_Catalog_Model_Product
|
525 |
+
*/
|
526 |
+
public function _getProduct() {
|
527 |
+
|
528 |
+
// get website id from request
|
529 |
+
$websiteId = ( int ) $this->getRequest ()->getParam ( static::WEBSITE_ID );
|
530 |
+
if ($websiteId <= 0) {
|
531 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
532 |
+
}
|
533 |
+
|
534 |
+
// get store id from request
|
535 |
+
$storeId = ( int ) $this->getRequest ()->getParam ( static::STORE_ID );
|
536 |
+
if ($storeId <= 0) {
|
537 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
538 |
+
}
|
539 |
+
if (is_null ( $this->_product )) {
|
540 |
+
$productId = $this->getRequest ()->getParam ( 'id' );
|
541 |
+
/**
|
542 |
+
*
|
543 |
+
* @var $productHelper Mage_Catalog_Helper_Product
|
544 |
+
*/
|
545 |
+
$productHelper = Mage::helper ( 'catalog/product' );
|
546 |
+
$product = $productHelper->getProduct ( $productId, $storeId );
|
547 |
+
if (! ($product->getId ())) {
|
548 |
+
$this->_critical ( static::RESOURCE_NOT_FOUND );
|
549 |
+
}
|
550 |
+
// check if product belongs to website current
|
551 |
+
if ($this->_getStore ()->getId ()) {
|
552 |
+
$isValidWebsite = in_array ( $websiteId, $product->getWebsiteIds () );
|
553 |
+
if (! $isValidWebsite) {
|
554 |
+
$this->_critical ( static::RESOURCE_NOT_FOUND );
|
555 |
+
}
|
556 |
+
}
|
557 |
+
// Check display settings for customers & guests
|
558 |
+
if ($this->getApiUser ()->getType () != Mage_Api2_Model_Auth_User_Admin::USER_TYPE) {
|
559 |
+
// check if product assigned to any website and can be shown
|
560 |
+
if ((! Mage::app ()->isSingleStoreMode () && ! count ( $product->getWebsiteIds () )) || ! $productHelper->canShow ( $product )) {
|
561 |
+
$this->_critical ( static::RESOURCE_NOT_FOUND );
|
562 |
+
}
|
563 |
+
}
|
564 |
+
$this->_product = $product;
|
565 |
+
}
|
566 |
+
return $this->_product;
|
567 |
+
}
|
568 |
+
|
569 |
+
/**
|
570 |
+
* Get Downloadable product
|
571 |
+
*
|
572 |
+
* @param object $product
|
573 |
+
* @return array $links
|
574 |
+
*/
|
575 |
+
public function getDownloadableLinks($product) {
|
576 |
+
$productAttributeLinks = $product->getTypeInstance ( true )->getLinks ( $product );
|
577 |
+
$i = 0;
|
578 |
+
foreach ( $productAttributeLinks as $productLinks ) {
|
579 |
+
$links [$i] ['link_id'] = $productLinks->getLinkId ();
|
580 |
+
$links [$i] [static::ENTITYID] = $productLinks->getProductId ();
|
581 |
+
$links [$i] ['is_require'] = $product->getLinksPurchasedSeparately ();
|
582 |
+
$links [$i] [static::PRICE] = $productLinks->getPrice ();
|
583 |
+
$links [$i] [static::TITLE] = $productLinks->getTitle ();
|
584 |
+
$i ++;
|
585 |
+
}
|
586 |
+
return $links;
|
587 |
+
}
|
588 |
+
|
589 |
+
/**
|
590 |
+
* Retrieve list of products
|
591 |
+
*
|
592 |
+
* @return array
|
593 |
+
*/
|
594 |
+
protected function _retrieveCollection() {
|
595 |
+
$response = array ();
|
596 |
+
$productArray = array ();
|
597 |
+
// get website id from request
|
598 |
+
$websiteId = ( int ) $this->getRequest ()->getParam ( static::WEBSITE_ID );
|
599 |
+
if ($websiteId <= 0) {
|
600 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
601 |
+
}
|
602 |
+
// get store id from request
|
603 |
+
$storeId = ( int ) $this->getRequest ()->getParam ( static::STORE_ID );
|
604 |
+
if ($storeId <= 0) {
|
605 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
606 |
+
}
|
607 |
+
// get page from request
|
608 |
+
$page = $this->getRequest ()->getParam ( 'page' );
|
609 |
+
if ($page <= 0) {
|
610 |
+
$page = 1;
|
611 |
+
}
|
612 |
+
// get page from request
|
613 |
+
$limit = $this->getRequest ()->getParam ( 'limit' );
|
614 |
+
if ($limit <= 0) {
|
615 |
+
$limit = 10;
|
616 |
+
}
|
617 |
+
|
618 |
+
// get these type of products only
|
619 |
+
$productType = array (
|
620 |
+
"simple",
|
621 |
+
"configurable"
|
622 |
+
);
|
623 |
+
|
624 |
+
// get city for filter products
|
625 |
+
$city = ( int ) Mage::app ()->getRequest ()->getParam ( 'city' );
|
626 |
+
|
627 |
+
/**
|
628 |
+
*
|
629 |
+
* @var $collection Mage_Catalog_Model_Resource_Product_Collection
|
630 |
+
*/
|
631 |
+
$collection = Mage::getResourceModel ( 'catalog/product_collection' );
|
632 |
+
$collection->addStoreFilter ( $storeId )->addPriceData ( $this->_getCustomerGroupId (), $websiteId )->addAttributeToSelect ( static::NAME, static::PRICE )->addAttributeToFilter ( static::VISIBILITY, array (
|
633 |
+
'neq' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
|
634 |
+
) )->addAttributeToFilter ( static::STATUS, array (
|
635 |
+
'eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED
|
636 |
+
) )->addAttributeToFilter ( 'type_id', array (
|
637 |
+
'in' => $productType
|
638 |
+
) );
|
639 |
+
// Filter products by city
|
640 |
+
if ($city) {
|
641 |
+
$collection->addFieldToFilter ( 'city', array (
|
642 |
+
array (
|
643 |
+
'regexp' => $city
|
644 |
+
)
|
645 |
+
) );
|
646 |
+
}
|
647 |
+
|
648 |
+
$this->_applyCategoryFilter ( $collection );
|
649 |
+
$this->_applyCollectionModifiers ( $collection );
|
650 |
+
|
651 |
+
// sort and filetr product collection
|
652 |
+
$collection = $this->_getProductByFilter ( $collection, $storeId );
|
653 |
+
// get total products count
|
654 |
+
$totalProducts = $collection->getSize ();
|
655 |
+
$collection = $this->_getProductBySort ( $collection, $storeId );
|
656 |
+
$products = $collection->load ();
|
657 |
+
|
658 |
+
// get total pages with limit
|
659 |
+
$last_page = ceil ( $totalProducts / $limit );
|
660 |
+
if ($last_page < $page) {
|
661 |
+
$productArray = array ();
|
662 |
+
} else {
|
663 |
+
$productArray = $this->getProductsList ( $products, $storeId );
|
664 |
+
}
|
665 |
+
$response ['success'] = 1;
|
666 |
+
$response ['error'] = false;
|
667 |
+
$response ['total_count'] = $totalProducts;
|
668 |
+
$response ['result'] = $productArray;
|
669 |
+
return json_encode ( $response );
|
670 |
+
}
|
671 |
+
|
672 |
+
/**
|
673 |
+
*
|
674 |
+
* @param array $products
|
675 |
+
* @param int $storeId
|
676 |
+
* @return array $productArray
|
677 |
+
*/
|
678 |
+
public function getProductsList($products, $storeId) {
|
679 |
+
$productArray = array ();
|
680 |
+
|
681 |
+
// @var Mage_Catalog_Model_Product $product
|
682 |
+
$productColl = array ();
|
683 |
+
foreach ( $products as $product ) {
|
684 |
+
|
685 |
+
$product->setStoreId ( $storeId )->load ( $product->getId () );
|
686 |
+
$this->_setProduct ( $product );
|
687 |
+
$productColl = $this->_prepareProductForResponse ( $product );
|
688 |
+
|
689 |
+
$productArray [] = $productColl;
|
690 |
+
}
|
691 |
+
|
692 |
+
return $productArray;
|
693 |
+
}
|
694 |
+
|
695 |
+
/**
|
696 |
+
* Add special fields to product get response
|
697 |
+
*
|
698 |
+
* @param Mage_Catalog_Model_Product $product
|
699 |
+
*/
|
700 |
+
protected function _prepareProductForResponse(Mage_Catalog_Model_Product $product) {
|
701 |
+
$websiteId = ( int ) $this->getRequest ()->getParam ( static::WEBSITE_ID );
|
702 |
+
if ($websiteId <= 0) {
|
703 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
704 |
+
}
|
705 |
+
// get store id from request
|
706 |
+
$storeId = ( int ) $this->getRequest ()->getParam ( static::STORE_ID );
|
707 |
+
if ($storeId <= 0) {
|
708 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
709 |
+
}
|
710 |
+
// get customer id from request
|
711 |
+
$customerId = ( int ) $this->getRequest ()->getParam ( 'customer_id' );
|
712 |
+
// get image size for resize
|
713 |
+
$imageSize = ( int ) $this->getRequest ()->getParam ( 'image_size' );
|
714 |
+
|
715 |
+
/**
|
716 |
+
*
|
717 |
+
* @var $productHelper Mage_Catalog_Helper_Product
|
718 |
+
*/
|
719 |
+
$productHelper = Mage::helper ( static::CAT_PRO );
|
720 |
+
|
721 |
+
$productData [static::ENTITYID] = $product->getEntity_id ();
|
722 |
+
$productData [static::NAME] = $product->getName ();
|
723 |
+
$productData ['type_id'] = $product->getTypeId ();
|
724 |
+
$product->setWebsiteId ( $websiteId );
|
725 |
+
// customer group is required in product for correct prices calculation
|
726 |
+
$product->setCustomerGroupId ( $this->_getCustomerGroupId () );
|
727 |
+
// calculate prices
|
728 |
+
$finalPrice = $product->getFinalPrice ();
|
729 |
+
if ($product->getTypeId () == 'grouped') {
|
730 |
+
$productData ['regular_price_with_tax'] = number_format ( $product->getMinimalPrice (), 2, '.', '' );
|
731 |
+
$productData ['final_price_with_tax'] = number_format ( $product->getMinimalPrice (), 2, '.', '' );
|
732 |
+
} else {
|
733 |
+
$productData ['regular_price_with_tax'] = number_format ( $this->_applyTaxToPrice ( $product->getPrice (), true ), 2, '.', '' );
|
734 |
+
$productData ['regular_price_without_tax'] = number_format ( $this->_applyTaxToPrice ( $product->getPrice (), false ), 2, '.', '' );
|
735 |
+
$productData ['final_price_with_tax'] = number_format ( $this->_applyTaxToPrice ( $finalPrice, true ), 2, '.', '' );
|
736 |
+
$productData ['final_price_without_tax'] = number_format ( $this->_applyTaxToPrice ( $finalPrice, false ), 2, '.', '' );
|
737 |
+
}
|
738 |
+
// get product stock details
|
739 |
+
$stockDetail = Mage::getModel ( static::LOGIN_TOKEN )->getStockDetail ( $product );
|
740 |
+
$productData [static::IS_SALEABLE] = $stockDetail [static::IS_SALEABLE];
|
741 |
+
$productData [static::ISSTOCK] = $stockDetail ['is_stock'];
|
742 |
+
// get product image
|
743 |
+
if ($imageSize <= 0) {
|
744 |
+
$productData [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, static::SMALLIMG );
|
745 |
+
} else {
|
746 |
+
$productData [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, static::SMALLIMG )->constrainOnly ( TRUE )->keepAspectRatio ( TRUE )->keepFrame ( FALSE )->resize ( $imageSize, null );
|
747 |
+
}
|
748 |
+
// get rating
|
749 |
+
$productData ['summary_rating'] = Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $product->getId (), $storeId ) ? Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $product->getId (), $storeId ) : '0';
|
750 |
+
// get wishlisted products by customer
|
751 |
+
$wishListIds = array ();
|
752 |
+
if ($customerId > 0) {
|
753 |
+
$wishListIds = Mage::getModel ( static::LOGIN_TOKEN )->getWishlistByCustomer ( $customerId );
|
754 |
+
}
|
755 |
+
// Check to see the product is in wishlist
|
756 |
+
if (in_array ( $product->getId (), $wishListIds )) {
|
757 |
+
$productData [static::ISWISHLIST] = true;
|
758 |
+
} else {
|
759 |
+
$productData [static::ISWISHLIST] = false;
|
760 |
+
}
|
761 |
+
// get product stock details
|
762 |
+
$inventoryDetail = Mage::getModel ( static::LOGIN_FUNCTIONS )->getinventoryDetail ( $product, $storeId );
|
763 |
+
// get stock qty
|
764 |
+
$productData [static::STOCK_QTY] = $inventoryDetail [static::STOCK_QTY];
|
765 |
+
$productData [static::MIN_SALE_QTY] = $inventoryDetail [static::MIN_SALE_QTY];
|
766 |
+
$productData [static::MAX_SALE_QTY] = $inventoryDetail [static::MAX_SALE_QTY];
|
767 |
+
$productData [static::QTY_INCR] = $inventoryDetail [static::QTY_INCR];
|
768 |
+
$productData [static::IS_QTY_DECIMAL] = $inventoryDetail [static::IS_QTY_DECIMAL];
|
769 |
+
|
770 |
+
if ($this->getActionType () == static::ACTION_TYPE_ENTITY) {
|
771 |
+
// define URLs
|
772 |
+
$productData ['url'] = $productHelper->getProductUrl ( $product->getId () );
|
773 |
+
if ($imageSize <= 0) {
|
774 |
+
$productData [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, 'image' );
|
775 |
+
} else {
|
776 |
+
$productData [static::IMGURL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, 'image' )->constrainOnly ( TRUE )->keepAspectRatio ( TRUE )->keepFrame ( FALSE )->resize ( $imageSize, null );
|
777 |
+
}
|
778 |
+
|
779 |
+
// @var $cartHelper Mage_Checkout_Helper_Cart
|
780 |
+
$cartHelper = Mage::helper ( 'checkout/cart' );
|
781 |
+
$productData ['buy_now_url'] = $cartHelper->getAddUrl ( $product );
|
782 |
+
|
783 |
+
/**
|
784 |
+
*
|
785 |
+
* @var $reviewModel Mage_Review_Model_Review
|
786 |
+
*/
|
787 |
+
$reviewModel = Mage::getModel ( 'review/review' );
|
788 |
+
$productData ['total_reviews_count'] = $reviewModel->getTotalReviews ( $product->getId (), true, $storeId );
|
789 |
+
$productData [static::TIERPRICE] = number_format ( $this->_getTierPrices (), 2, '.', '' );
|
790 |
+
// get product has custom options or not
|
791 |
+
$productData ['has_custom_options'] = count ( $product->getOptions () ) > 0;
|
792 |
+
} else {
|
793 |
+
// remove tier price from response
|
794 |
+
$product->unsetData ( static::TIERPRICE );
|
795 |
+
unset ( $productData [static::TIERPRICE] );
|
796 |
+
}
|
797 |
+
return $productData;
|
798 |
+
}
|
799 |
+
|
800 |
+
/**
|
801 |
+
* Filter products collection
|
802 |
+
*
|
803 |
+
* @param object $collection
|
804 |
+
* @param int $storeId
|
805 |
+
* @return mixed object
|
806 |
+
*/
|
807 |
+
public function _getProductByFilter($collection, $storeId) {
|
808 |
+
|
809 |
+
// get filter types attributes
|
810 |
+
$filters = json_decode ( $this->getRequest ()->getParam ( 'filters' ), true );
|
811 |
+
|
812 |
+
if (array_key_exists ( static::PRICE, $filters )) {
|
813 |
+
|
814 |
+
// get price range
|
815 |
+
$priceRange = $filters [static::PRICE];
|
816 |
+
unset ( $filters [static::PRICE] );
|
817 |
+
}
|
818 |
+
// get availability tag
|
819 |
+
if (array_key_exists ( static::AVAILABILITY, $filters )) {
|
820 |
+
$availability = $filters [static::AVAILABILITY];
|
821 |
+
unset ( $filters [static::AVAILABILITY] );
|
822 |
+
}
|
823 |
+
// get the table preix value
|
824 |
+
$prefix = Mage::getConfig ()->getTablePrefix ();
|
825 |
+
|
826 |
+
/**
|
827 |
+
* Filter collection Based on stock availability
|
828 |
+
*
|
829 |
+
* @param boolean $availability
|
830 |
+
* 0 | 1 input for stock in or stock out
|
831 |
+
*/
|
832 |
+
if ($availability != '') {
|
833 |
+
Mage::getSingleton ( 'cataloginventory/stock' )->addInStockFilterToCollection ( $collection );
|
834 |
+
}
|
835 |
+
|
836 |
+
/**
|
837 |
+
* Filter collection Based on minimun and maximum price
|
838 |
+
*
|
839 |
+
* @param integer $minPrice
|
840 |
+
* @param integer $maxPrice
|
841 |
+
*/
|
842 |
+
if ($priceRange [0] != '' && $priceRange [1] != '') {
|
843 |
+
$collection->getSelect ()->join ( array (
|
844 |
+
'price1' => $prefix . 'catalog_product_index_price'
|
845 |
+
), 'cat_pro.product_id = price1.entity_id', array (
|
846 |
+
static::FINALPRICE => 'price1.final_price'
|
847 |
+
) )->where ( 'price1.customer_group_id =1' )->where ( "price1.final_price >= $priceRange[0] and price1.final_price <= $priceRange[1]" );
|
848 |
+
$collection->getSelectSql ( true );
|
849 |
+
}
|
850 |
+
|
851 |
+
/**
|
852 |
+
* Filter collection Based on attribute code
|
853 |
+
*
|
854 |
+
* @param string $filters
|
855 |
+
* input for brand array filter products
|
856 |
+
*/
|
857 |
+
if (is_array ( $filters )) {
|
858 |
+
foreach ( $filters as $attrCode => $attrValueId ) {
|
859 |
+
$attributeid = $this->getAttributeId ( $attrCode );
|
860 |
+
if ($attrValueId != '') {
|
861 |
+
$attrValueId = implode ( ",", $attrValueId );
|
862 |
+
$collection->getSelect ()->join ( array (
|
863 |
+
$attrCode => Mage::getModel ( 'core/resource' )->getTableName ( 'catalog_product_index_eav' )
|
864 |
+
), "e.entity_id = " . $attrCode . ".entity_id AND " . $attrCode . ".attribute_id = " . $attributeid . " AND " . $attrCode . ".value IN(" . $attrValueId . ")", array (
|
865 |
+
'value'
|
866 |
+
) );
|
867 |
+
$collection->getSelectSql ( true );
|
868 |
}
|
869 |
+
}
|
870 |
+
}
|
871 |
+
$collection->getSelect ()->group ( static::E_ENTITY_ID );
|
872 |
+
return $collection;
|
873 |
+
}
|
874 |
+
|
875 |
+
/**
|
876 |
+
* Sort Products Collection
|
877 |
+
*
|
878 |
+
* @param object $collection
|
879 |
+
* @param int $storeId
|
880 |
+
* @return mixed object
|
881 |
+
*/
|
882 |
+
public function _getProductBySort($collection, $storeId) {
|
883 |
+
// get sort by for products from request
|
884 |
+
$sortBy = $this->getRequest ()->getParam ( 'sortby' );
|
885 |
+
// get orderby for products from request
|
886 |
+
$orderBy = $this->getRequest ()->getParam ( 'orderby' );
|
887 |
+
|
888 |
+
// get page from request
|
889 |
+
$page = ( int ) $this->getRequest ()->getParam ( 'page' );
|
890 |
+
if ($page <= 0) {
|
891 |
+
$page = 1;
|
892 |
+
}
|
893 |
+
// get page from request
|
894 |
+
$limit = ( int ) $this->getRequest ()->getParam ( 'limit' );
|
895 |
+
if ($limit <= 0) {
|
896 |
+
$limit = 10;
|
897 |
+
}
|
898 |
+
// get the table preix value
|
899 |
+
$prefix = Mage::getConfig ()->getTablePrefix ();
|
900 |
+
|
901 |
+
// sorting products by name
|
902 |
+
if ($sortBy == static::NAME) {
|
903 |
+
$collection->setPage ( $page, $limit );
|
904 |
+
$collection->setOrder ( static::NAME, $orderBy );
|
905 |
+
} else if ($sortBy == static::PRICE) {
|
906 |
+
// sorting products by price
|
907 |
+
$collection->setPage ( $page, $limit );
|
908 |
+
$collection->getSelect ()->join ( array (
|
909 |
+
static::PRICE => $prefix . 'catalog_product_index_price'
|
910 |
+
), 'cat_pro.product_id = price.entity_id', array (
|
911 |
+
static::FINALPRICE => 'price.final_price'
|
912 |
+
) )->where ( 'price.customer_group_id =1' )->group ( static::E_ENTITY_ID )->order ( "price.final_price $orderBy" );
|
913 |
+
} else if ($sortBy == static::RATING) {
|
914 |
+
// sorting products by rating
|
915 |
+
$collection->setPage ( $page, $limit );
|
916 |
+
$collection->getSelect ()->joinLeft ( array (
|
917 |
+
'rating' => $prefix . 'rating_option_vote_aggregated'
|
918 |
+
), 'rating.entity_pk_value = cat_pro.product_id and rating.store_id =' . $storeId, array (
|
919 |
+
'percent_approved' => 'rating.percent_approved'
|
920 |
+
) )->group ( static::E_ENTITY_ID )->order ( "rating.percent_approved $orderBy" );
|
921 |
+
$collection->getSelectSql ( true );
|
922 |
+
} else {
|
923 |
+
$collection->setPage ( $page, $limit );
|
924 |
+
$collection->setOrder ( static::NAME, 'asc' );
|
925 |
+
}
|
926 |
+
return $collection;
|
927 |
+
}
|
928 |
+
|
929 |
+
/**
|
930 |
+
* Get attribute id by attribute code
|
931 |
+
*
|
932 |
+
* @param string $code
|
933 |
+
* Getting the particular attribute id
|
934 |
+
*
|
935 |
+
* @return int $id
|
936 |
+
*/
|
937 |
+
public function getAttributeId($code = '') {
|
938 |
+
if (! $code) {
|
939 |
+
return;
|
940 |
+
}
|
941 |
+
$attribute_details = Mage::getSingleton ( "eav/config" )->getAttribute ( 'catalog_product', $code );
|
942 |
+
return $attribute_details->getData ( static::ATTRIBUTE_ID );
|
943 |
+
}
|
944 |
}
|
app/code/local/ContusRestapi/ProductList/etc/api2.xml
CHANGED
@@ -57,6 +57,7 @@
|
|
57 |
<filter_attr>Filter attribute</filter_attr>
|
58 |
<filters>Filters</filters>
|
59 |
<error>Error</error>
|
|
|
60 |
</attributes>
|
61 |
<entity_only_attributes>
|
62 |
<customer>
|
57 |
<filter_attr>Filter attribute</filter_attr>
|
58 |
<filters>Filters</filters>
|
59 |
<error>Error</error>
|
60 |
+
<city>City</city>
|
61 |
</attributes>
|
62 |
<entity_only_attributes>
|
63 |
<customer>
|
app/code/local/ContusRestapi/Products/Model/Api2/Products.php
ADDED
@@ -0,0 +1,325 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_Products
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_Products_Model_Api2_Products extends Mage_Api2_Model_Resource {
|
30 |
+
// Declaring the string literals variable
|
31 |
+
const IS_SALABLE = 'is_saleable';
|
32 |
+
const LOGIN_TOKEN = 'login/token';
|
33 |
+
const NAME = 'name';
|
34 |
+
const CATIMG = 'catalog/image';
|
35 |
+
const SMALLIMG = 'small_image';
|
36 |
+
const IMG_URL = 'image_url';
|
37 |
+
const STOCK_QTY = 'stock_qty';
|
38 |
+
const ENTITYID = 'entity_id';
|
39 |
+
const STATUS = 'status';
|
40 |
+
const PRICE = 'price';
|
41 |
+
const TIERPRICE = 'tier_price';
|
42 |
+
const ISWISHLIST = 'is_wishlist';
|
43 |
+
const RATING = 'rating';
|
44 |
+
const OPTIONS = 'options';
|
45 |
+
const CATSTOCK = 'cataloginventory/stock_item';
|
46 |
+
const ISSTOCK = 'is_stock';
|
47 |
+
const IS_IN_STOCK = 'is_in_stock';
|
48 |
+
const E_ENTITY_ID = 'e.entity_id';
|
49 |
+
const AVAILABILITY = 'availability';
|
50 |
+
const IS_SALEABLE = 'is_saleable';
|
51 |
+
|
52 |
+
/**
|
53 |
+
* function that is called when post is done **
|
54 |
+
* Home page details
|
55 |
+
*
|
56 |
+
* @param array $data
|
57 |
+
*
|
58 |
+
* @return array json array
|
59 |
+
*/
|
60 |
+
protected function _retrieveCollection() {
|
61 |
+
$response = array ();
|
62 |
+
|
63 |
+
// Get Available stores based on website id
|
64 |
+
$response = array ();
|
65 |
+
$productArray = array ();
|
66 |
+
|
67 |
+
// get page from request
|
68 |
+
$page = $this->getRequest ()->getParam ( 'page' );
|
69 |
+
if ($page <= 0) {
|
70 |
+
$page = 1;
|
71 |
+
}
|
72 |
+
// get page from request
|
73 |
+
$limit = $this->getRequest ()->getParam ( 'limit' );
|
74 |
+
if ($limit <= 0) {
|
75 |
+
$limit = 10;
|
76 |
+
}
|
77 |
+
// get website id from request
|
78 |
+
$websiteId = ( int ) $this->getRequest ()->getParam ( 'website_id' );
|
79 |
+
if ($websiteId <= 0) {
|
80 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
81 |
+
}
|
82 |
+
// get store id from request
|
83 |
+
$storeId = ( int ) $this->getRequest ()->getParam ( 'store_id' );
|
84 |
+
if ($storeId <= 0) {
|
85 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
86 |
+
}
|
87 |
+
|
88 |
+
// get $category id from request
|
89 |
+
$categoryid = ( int ) $this->getRequest ()->getParam ( 'category_id' );
|
90 |
+
// get these type of products only
|
91 |
+
$productType = array (
|
92 |
+
"simple",
|
93 |
+
"configurable"
|
94 |
+
);
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Get product collection based on $categoryid
|
98 |
+
*
|
99 |
+
* @return array of Object
|
100 |
+
*/
|
101 |
+
$category = new Mage_Catalog_Model_Category ();
|
102 |
+
// this is category id
|
103 |
+
$category->load ( $categoryid );
|
104 |
+
$collection = $category->getProductCollection ();
|
105 |
+
$collection = $collection->addAttributeToSelect ( '*' )->addAttributeToFilter ( 'status', array (
|
106 |
+
'eq' => '1'
|
107 |
+
) )->addAttributeToFilter ( 'visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH )->addAttributeToFilter ( 'type_id', array (
|
108 |
+
'in' => $productType
|
109 |
+
) );
|
110 |
+
// sort and filetr product collection
|
111 |
+
$collection = $this->_getProductByFilter ( $collection, $storeId );
|
112 |
+
// get total products count
|
113 |
+
$totalProducts = $collection->getSize ();
|
114 |
+
$collection = $this->_getProductBySort ( $collection, $storeId );
|
115 |
+
$products = $collection->load ();
|
116 |
+
|
117 |
+
// get total pages with limit
|
118 |
+
$last_page = ceil ( $totalProducts / $limit );
|
119 |
+
if ($last_page < $page) {
|
120 |
+
$productArray = array ();
|
121 |
+
} else {
|
122 |
+
$productArray = $this->getProductsList ( $products, $storeId );
|
123 |
+
}
|
124 |
+
$response ['success'] = 1;
|
125 |
+
$response ['error'] = false;
|
126 |
+
$response ['total_count'] = $totalProducts;
|
127 |
+
$response ['result'] = $productArray;
|
128 |
+
return json_encode ( $response );
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
*
|
133 |
+
* @param array $products
|
134 |
+
* @param int $storeId
|
135 |
+
* @return array $productArray
|
136 |
+
*/
|
137 |
+
public function getProductsList($products, $storeId) {
|
138 |
+
$_proudct_data = array ();
|
139 |
+
$i = 0;
|
140 |
+
// get image size for resize
|
141 |
+
$imageSize = ( int ) $this->getRequest ()->getParam ( 'image_size' );
|
142 |
+
|
143 |
+
foreach ( $products as $product ) {
|
144 |
+
$product->setStoreId ( $storeId )->load ( $product->getId () );
|
145 |
+
$_proudct_data [$i] ['entity_id'] = $product->getId ();
|
146 |
+
// get product name
|
147 |
+
$_proudct_data [$i] [static::NAME] = $product->getName ();
|
148 |
+
$_proudct_data [$i] ['type_id'] = $product->getTypeId ();
|
149 |
+
// get the product final price
|
150 |
+
if ($product->getTypeId () == 'grouped') {
|
151 |
+
$_proudct_data [$i] ['regular_price_with_tax'] = number_format ( $product->getMinimalPrice (), 2, '.', '' );
|
152 |
+
$_proudct_data [$i] ['fianl_price_with_tax'] = number_format ( $product->getMinimalPrice (), 2, '.', '' );
|
153 |
+
} else {
|
154 |
+
$_proudct_data [$i] ['regular_price_with_tax'] = number_format ( $product->getPrice (), 2, '.', '' );
|
155 |
+
$_proudct_data [$i] ['fianl_price_with_tax'] = number_format ( $product->getFinalPrice (), 2, '.', '' );
|
156 |
+
}
|
157 |
+
// get product stock details
|
158 |
+
$stockDetail = Mage::getModel ( static::LOGIN_TOKEN )->getStockDetail ( $product );
|
159 |
+
$_proudct_data [$i] [static::IS_SALABLE] = $stockDetail [static::IS_SALABLE];
|
160 |
+
$_proudct_data [$i] [static::ISSTOCK] = $stockDetail [static::ISSTOCK];
|
161 |
+
// get product image
|
162 |
+
if ($imageSize <= 0) {
|
163 |
+
$_proudct_data [$i] [static::IMG_URL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, static::SMALLIMG );
|
164 |
+
} else {
|
165 |
+
$_proudct_data [$i] [static::IMG_URL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, static::SMALLIMG )->constrainOnly ( TRUE )->keepAspectRatio ( TRUE )->keepFrame ( FALSE )->resize ( $imageSize, null );
|
166 |
+
}
|
167 |
+
|
168 |
+
// get rating
|
169 |
+
$_proudct_data [$i] ['summary_rating'] = Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $product->getId (), $storeId ) ? Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $product->getId (), $storeId ) : '0';
|
170 |
+
|
171 |
+
// get wishlisted products by customer
|
172 |
+
$wishListIds = array ();
|
173 |
+
if ($customerId > 0) {
|
174 |
+
$wishListIds = Mage::getModel ( static::LOGIN_TOKEN )->getWishlistByCustomer ( $customerId );
|
175 |
+
}
|
176 |
+
// Check to see the product is in wishlist
|
177 |
+
if (in_array ( $product->getId (), $wishListIds )) {
|
178 |
+
$_proudct_data [$i] [static::ISWISHLIST] = true;
|
179 |
+
} else {
|
180 |
+
$_proudct_data [$i] [static::ISWISHLIST] = false;
|
181 |
+
}
|
182 |
+
|
183 |
+
// get stock available qty
|
184 |
+
if ($product->getTypeId () != 'configurable') {
|
185 |
+
// get product availabile qty
|
186 |
+
$_proudct_data [$i] [static::STOCK_QTY] = floatval ( Mage::getModel ( 'cataloginventory/stock_item' )->loadByProduct ( $product )->getQty () );
|
187 |
+
} else {
|
188 |
+
$_proudct_data [$i] [static::STOCK_QTY] = floatval ( '' );
|
189 |
+
}
|
190 |
+
|
191 |
+
$i ++;
|
192 |
+
}
|
193 |
+
|
194 |
+
return $_proudct_data;
|
195 |
+
}
|
196 |
+
|
197 |
+
/**
|
198 |
+
* Filter products collection
|
199 |
+
*
|
200 |
+
* @param object $collection
|
201 |
+
* @param int $storeId
|
202 |
+
* @return mixed object
|
203 |
+
*/
|
204 |
+
public function _getProductByFilter($collection, $storeId) {
|
205 |
+
|
206 |
+
// get filter types attributes
|
207 |
+
$filters = json_decode ( $this->getRequest ()->getParam ( 'filters' ), true );
|
208 |
+
|
209 |
+
if (array_key_exists ( static::PRICE, $filters )) {
|
210 |
+
|
211 |
+
// get price range
|
212 |
+
$priceRange = $filters [static::PRICE];
|
213 |
+
unset ( $filters [static::PRICE] );
|
214 |
+
}
|
215 |
+
// get availability tag
|
216 |
+
if (array_key_exists ( static::AVAILABILITY, $filters )) {
|
217 |
+
$availability = $filters [static::AVAILABILITY];
|
218 |
+
unset ( $filters [static::AVAILABILITY] );
|
219 |
+
}
|
220 |
+
// get the table preix value
|
221 |
+
$prefix = Mage::getConfig ()->getTablePrefix ();
|
222 |
+
|
223 |
+
/**
|
224 |
+
* Filter collection Based on stock availability
|
225 |
+
*
|
226 |
+
* @param boolean $availability
|
227 |
+
* 0 | 1 input for stock in or stock out
|
228 |
+
*/
|
229 |
+
if ($availability != '') {
|
230 |
+
Mage::getSingleton ( 'cataloginventory/stock' )->addInStockFilterToCollection ( $collection );
|
231 |
+
}
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Filter collection Based on minimun and maximum price
|
235 |
+
*
|
236 |
+
* @param integer $minPrice
|
237 |
+
* @param integer $maxPrice
|
238 |
+
*/
|
239 |
+
if ($priceRange [0] != '' && $priceRange [1] != '') {
|
240 |
+
$collection->getSelect ()->join ( array (
|
241 |
+
'price1' => $prefix . 'catalog_product_index_price'
|
242 |
+
), 'cat_pro.product_id = price1.entity_id', array (
|
243 |
+
static::FINALPRICE => 'price1.final_price'
|
244 |
+
) )->where ( 'price1.customer_group_id =1' )->where ( "price1.final_price >= $priceRange[0] and price1.final_price <= $priceRange[1]" );
|
245 |
+
$collection->getSelectSql ( true );
|
246 |
+
}
|
247 |
+
|
248 |
+
/**
|
249 |
+
* Filter collection Based on attribute code
|
250 |
+
*
|
251 |
+
* @param string $filters
|
252 |
+
* input for brand array filter products
|
253 |
+
*/
|
254 |
+
if (is_array ( $filters )) {
|
255 |
+
foreach ( $filters as $attrCode => $attrValueId ) {
|
256 |
+
$attributeid = $this->getAttributeId ( $attrCode );
|
257 |
+
if ($attrValueId != '') {
|
258 |
+
$attrValueId = implode ( ",", $attrValueId );
|
259 |
+
$collection->getSelect ()->join ( array (
|
260 |
+
$attrCode => Mage::getModel ( 'core/resource' )->getTableName ( 'catalog_product_index_eav' )
|
261 |
+
), "e.entity_id = " . $attrCode . ".entity_id AND " . $attrCode . ".attribute_id = " . $attributeid . " AND " . $attrCode . ".value IN(" . $attrValueId . ")", array (
|
262 |
+
'value'
|
263 |
+
) );
|
264 |
+
$collection->getSelectSql ( true );
|
265 |
+
}
|
266 |
+
}
|
267 |
+
}
|
268 |
+
$collection->getSelect ()->group ( static::E_ENTITY_ID );
|
269 |
+
return $collection;
|
270 |
+
}
|
271 |
+
|
272 |
+
/**
|
273 |
+
* Sort Products Collection
|
274 |
+
*
|
275 |
+
* @param object $collection
|
276 |
+
* @param int $storeId
|
277 |
+
* @return mixed object
|
278 |
+
*/
|
279 |
+
public function _getProductBySort($collection, $storeId) {
|
280 |
+
// get sort by for products from request
|
281 |
+
$sortBy = $this->getRequest ()->getParam ( 'sortby' );
|
282 |
+
// get orderby for products from request
|
283 |
+
$orderBy = $this->getRequest ()->getParam ( 'orderby' );
|
284 |
+
|
285 |
+
// get page from request
|
286 |
+
$page = ( int ) $this->getRequest ()->getParam ( 'page' );
|
287 |
+
if ($page <= 0) {
|
288 |
+
$page = 1;
|
289 |
+
}
|
290 |
+
// get page from request
|
291 |
+
$limit = ( int ) $this->getRequest ()->getParam ( 'limit' );
|
292 |
+
if ($limit <= 0) {
|
293 |
+
$limit = 10;
|
294 |
+
}
|
295 |
+
// get the table preix value
|
296 |
+
$prefix = Mage::getConfig ()->getTablePrefix ();
|
297 |
+
|
298 |
+
// sorting products by name
|
299 |
+
if ($sortBy == static::NAME) {
|
300 |
+
$collection->setPage ( $page, $limit );
|
301 |
+
$collection->setOrder ( static::NAME, $orderBy );
|
302 |
+
} else if ($sortBy == static::PRICE) {
|
303 |
+
// sorting products by price
|
304 |
+
$collection->setPage ( $page, $limit );
|
305 |
+
$collection->getSelect ()->join ( array (
|
306 |
+
static::PRICE => $prefix . 'catalog_product_index_price'
|
307 |
+
), 'cat_pro.product_id = price.entity_id', array (
|
308 |
+
static::FINALPRICE => 'price.final_price'
|
309 |
+
) )->where ( 'price.customer_group_id =1' )->group ( static::E_ENTITY_ID )->order ( "price.final_price $orderBy" );
|
310 |
+
} else if ($sortBy == static::RATING) {
|
311 |
+
// sorting products by rating
|
312 |
+
$collection->setPage ( $page, $limit );
|
313 |
+
$collection->getSelect ()->joinLeft ( array (
|
314 |
+
'rating' => $prefix . 'rating_option_vote_aggregated'
|
315 |
+
), 'rating.entity_pk_value = cat_pro.product_id and rating.store_id =' . $storeId, array (
|
316 |
+
'percent_approved' => 'rating.percent_approved'
|
317 |
+
) )->group ( static::E_ENTITY_ID )->order ( "rating.percent_approved $orderBy" );
|
318 |
+
$collection->getSelectSql ( true );
|
319 |
+
} else {
|
320 |
+
$collection->setPage ( $page, $limit );
|
321 |
+
$collection->setOrder ( static::NAME, 'asc' );
|
322 |
+
}
|
323 |
+
return $collection;
|
324 |
+
}
|
325 |
+
}
|
app/code/local/ContusRestapi/Products/Model/Api2/Products/Rest.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_Products
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_Products_Model_Api2_Products_Rest extends ContusRestapi_Products_Model_Api2_Products {
|
30 |
+
}
|
app/code/local/ContusRestapi/Products/Model/Api2/Products/Rest/Admin/V1.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_SplashPage
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_Products_Model_Api2_Products_Rest_Admin_V1 extends ContusRestapi_Products_Model_Api2_Products_Rest {
|
30 |
+
}
|
app/code/local/ContusRestapi/Products/Model/Api2/Products/Rest/Customer/V1.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_SplashPage
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_Products_Model_Api2_Products_Rest_Customer_V1 extends ContusRestapi_Products_Model_Api2_Products_Rest {
|
30 |
+
}
|
app/code/local/ContusRestapi/Products/Model/Api2/Products/Rest/Guest/V1.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_Products
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_Products_Model_Api2_Products_Rest_Guest_V1 extends ContusRestapi_Products_Model_Api2_Products_Rest {
|
30 |
+
}
|
app/code/local/ContusRestapi/Products/etc/api2.xml
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<api2>
|
4 |
+
<resource_groups>
|
5 |
+
<contusRestapi translate="title" module="Products">
|
6 |
+
<title>Pproduct Module</title>
|
7 |
+
<sort_order>10</sort_order>
|
8 |
+
</contusRestapi>
|
9 |
+
</resource_groups>
|
10 |
+
<resources>
|
11 |
+
<products translate="title" module="Products">
|
12 |
+
<group>contusrestapi</group>
|
13 |
+
<model>products/api2_products</model>
|
14 |
+
<title>Splash api</title>
|
15 |
+
<sort_order>10</sort_order>
|
16 |
+
<privileges>
|
17 |
+
<admin>
|
18 |
+
<create>1</create>
|
19 |
+
<retrieve>1</retrieve>
|
20 |
+
<delete>1</delete>
|
21 |
+
</admin>
|
22 |
+
<customer>
|
23 |
+
<create>1</create>
|
24 |
+
<retrieve>1</retrieve>
|
25 |
+
</customer>
|
26 |
+
<guest>
|
27 |
+
<create>1</create>
|
28 |
+
<retrieve>1</retrieve>
|
29 |
+
</guest>
|
30 |
+
</privileges>
|
31 |
+
<attributes module="api2">
|
32 |
+
<website_id>websiteid</website_id>
|
33 |
+
<store_id>Associate to Store</store_id>
|
34 |
+
<results>Results</results>
|
35 |
+
<success>Success</success>
|
36 |
+
<error>Error</error>
|
37 |
+
</attributes>
|
38 |
+
<routes>
|
39 |
+
<route_collection>
|
40 |
+
<route>/productlist/</route>
|
41 |
+
<action_type>collection</action_type>
|
42 |
+
</route_collection>
|
43 |
+
|
44 |
+
</routes>
|
45 |
+
<versions>1</versions>
|
46 |
+
</products>
|
47 |
+
|
48 |
+
</resources>
|
49 |
+
</api2>
|
50 |
+
</config>
|
app/code/local/ContusRestapi/Products/etc/config.xml
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<ContusRestapi_Products>
|
5 |
+
<version>0.1.0.0</version>
|
6 |
+
</ContusRestapi_Products>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<models>
|
10 |
+
<products>
|
11 |
+
<class>ContusRestapi_Products_Model</class>
|
12 |
+
</products>
|
13 |
+
</models>
|
14 |
+
</global>
|
15 |
+
</config>
|
app/code/local/ContusRestapi/ReviewRating/Model/Api2/ReviewRating.php
CHANGED
@@ -29,192 +29,252 @@
|
|
29 |
* @since 1.0
|
30 |
*/
|
31 |
class ContusRestapi_ReviewRating_Model_Api2_ReviewRating extends Mage_Api2_Model_Resource {
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
$success = 0;
|
128 |
-
$message = 'Sorry, we are unable to add your review at this time.';
|
129 |
-
}
|
130 |
-
} catch ( Exception $e ) {
|
131 |
-
$success = 0;
|
132 |
-
$message = $e->getMessage ();
|
133 |
-
}
|
134 |
-
|
135 |
-
/**
|
136 |
-
* Getting average of ratings/reviews
|
137 |
-
*/
|
138 |
-
$reviewRating = Mage::getModel ( static::LOGIN_TOKEN )->getRatingResult ( $productId, $storeId );
|
139 |
-
// get total reviews
|
140 |
-
$total_reviews_count = $review->getTotalReviews ( $productId, true, $storeId );
|
141 |
-
|
142 |
-
$response [static::VALID_TOKEN] = $isValidToken;
|
143 |
-
$response [static::ERROR] = false;
|
144 |
-
$response [static::SUCCESS] = $success;
|
145 |
-
$response [static::MESSAGE] = $message;
|
146 |
-
$response [static::RESULT] = $reviewRating;
|
147 |
-
$response [static::RESULT] ['review_status'] = $reviewStatus;
|
148 |
-
$response [static::RESULT] ['total_reviews_count'] = $total_reviews_count;
|
149 |
-
$response [static::RESULT] ['summary_rating'] = Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $productId, $storeId ) ? Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $productId, $storeId ) : '0';
|
150 |
-
|
151 |
-
$this->getResponse ()->setBody ( json_encode ( $response ) );
|
152 |
-
return;
|
153 |
-
}
|
154 |
-
|
155 |
-
/**
|
156 |
-
* Get reviews ans rating colection fro Product
|
157 |
-
*
|
158 |
-
* @see Mage_Api2_Model_Resource::_retrieveCollection()
|
159 |
-
*/
|
160 |
-
protected function _retrieveCollection() {
|
161 |
-
$response = array ();
|
162 |
-
|
163 |
-
// get website id from request
|
164 |
-
$websiteId = ( int ) $this->getRequest ()->getParam ( static::WEBSITEID );
|
165 |
-
if ($websiteId <= 0) {
|
166 |
-
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
167 |
-
}
|
168 |
-
|
169 |
-
// get store id
|
170 |
-
$storeId = ( int ) $this->getRequest ()->getParam ( static::STOREID );
|
171 |
-
if ($storeId <= 0) {
|
172 |
-
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
173 |
-
}
|
174 |
-
// get product id
|
175 |
-
$productId = ( int ) $this->getRequest ()->getParam ( 'product_id' );
|
176 |
-
|
177 |
-
$page = ( int ) $this->getRequest ()->getParam ( 'page' );
|
178 |
-
if ($page <= 0) {
|
179 |
-
$page = 1;
|
180 |
-
}
|
181 |
-
$limit = ( int ) $this->getRequest ()->getParam ( 'limit' );
|
182 |
-
if ($limit <= 0) {
|
183 |
-
$limit = 10;
|
184 |
-
}
|
185 |
-
try {
|
186 |
-
/**
|
187 |
-
*
|
188 |
-
* @var $review Mage_Review_Model_Review
|
189 |
-
*/
|
190 |
-
$review = Mage::getModel ( 'review/review' );
|
191 |
-
// get total reviews
|
192 |
-
$total_reviews_count = $review->getTotalReviews ( $productId, true, $storeId );
|
193 |
-
|
194 |
-
/**
|
195 |
-
* Getting average of ratings/reviews
|
196 |
-
*/
|
197 |
-
$last_page = ceil ( $total_reviews_count / $limit );
|
198 |
-
if ($last_page < $page) {
|
199 |
-
$reviewRating [static::REVIEWS] = array ();
|
200 |
-
$ratings [static::RATING] = array ();
|
201 |
-
} else {
|
202 |
-
$reviewRating = Mage::getModel ( static::LOGIN_TOKEN )->getReviews ( $productId, $storeId, $page, $limit );
|
203 |
-
// get product rating count summary
|
204 |
-
$ratings = Mage::getModel ( static::LOGIN_TOKEN )->getRatingResult ( $productId, $storeId );
|
205 |
-
}
|
206 |
$success = 1;
|
207 |
-
|
|
|
|
|
208 |
$success = 0;
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
}
|
29 |
* @since 1.0
|
30 |
*/
|
31 |
class ContusRestapi_ReviewRating_Model_Api2_ReviewRating extends Mage_Api2_Model_Resource {
|
32 |
+
|
33 |
+
// define static variable.
|
34 |
+
const STOREID = 'store_id';
|
35 |
+
const WEBSITEID = 'website_id';
|
36 |
+
const CUSTOMER_ID = 'customer_id';
|
37 |
+
const PRODUCT_ID = 'product_id';
|
38 |
+
const SUCCESS = 'success';
|
39 |
+
const MESSAGE = 'message';
|
40 |
+
const ERROR = 'error';
|
41 |
+
const RESULT = 'result';
|
42 |
+
const TOKEN = 'token';
|
43 |
+
const LOGIN_TOKEN = 'login/token';
|
44 |
+
const VALID_TOKEN = 'isValidToken';
|
45 |
+
const REVIEWS = 'reviews';
|
46 |
+
const RATING = 'rating';
|
47 |
+
const RATINGS = 'ratings';
|
48 |
+
const LOGIN_METHODS = 'login/methods_functions';
|
49 |
+
const TOT_REVWS_CNT = 'total_reviews_count';
|
50 |
+
const SUMMARY_RATING = 'summary_rating';
|
51 |
+
|
52 |
+
/**
|
53 |
+
* function that is called when post is done **
|
54 |
+
*
|
55 |
+
* Add new review and rating and get all review by product id
|
56 |
+
*
|
57 |
+
* @param array $data
|
58 |
+
*
|
59 |
+
* @return array json array
|
60 |
+
*/
|
61 |
+
protected function _create(array $data) {
|
62 |
+
$response = array ();
|
63 |
+
// get customer id
|
64 |
+
$customerId = ( int ) $data [static::CUSTOMER_ID];
|
65 |
+
// get product Id from request
|
66 |
+
$productId = ( int ) $data [static::PRODUCT_ID];
|
67 |
+
$websiteId = ( int ) $data [static::WEBSITEID];
|
68 |
+
if ($websiteId <= 0) {
|
69 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
70 |
+
}
|
71 |
+
// get store id from request
|
72 |
+
$storeId = ( int ) $data [static::STOREID];
|
73 |
+
if ($storeId <= 0) {
|
74 |
+
Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
75 |
+
}
|
76 |
+
// set review status as static 1 for approved. 2 for pending
|
77 |
+
$reviewStatus = 1;
|
78 |
+
// get rating value from request
|
79 |
+
$rating = $data [static::RATING];
|
80 |
+
// get token value from request
|
81 |
+
$token = $data [static::TOKEN];
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Check this customer has valid token or not
|
85 |
+
*
|
86 |
+
* @var $isValidToken Mage_Login_Model_Token
|
87 |
+
*/
|
88 |
+
$isValidToken = Mage::getModel ( 'login/token' )->checkUserToken ( $customerId, $token );
|
89 |
+
|
90 |
+
/**
|
91 |
+
*
|
92 |
+
* @var $review Mage_Review_Model_Review
|
93 |
+
*/
|
94 |
+
$review = Mage::getModel ( 'review/review' );
|
95 |
+
try {
|
96 |
+
// check customer token
|
97 |
+
if (! $isValidToken) {
|
98 |
+
throw new Exception ( 'Authentication failed.' );
|
99 |
+
}
|
100 |
+
$review->setEntityPkValue ( $productId );
|
101 |
+
$review->setStatusId ( $reviewStatus );
|
102 |
+
$review->setTitle ( $data ['review_title'] );
|
103 |
+
$review->setDetail ( $data ['review_description'] );
|
104 |
+
$review->setEntityId ( 1 );
|
105 |
+
$review->setStoreId ( $sotreId );
|
106 |
+
$review->setCustomerId ( $customerId );
|
107 |
+
$review->setNickname ( $data ['customer_name'] );
|
108 |
+
$review->setReviewId ( $review->getId () );
|
109 |
+
$review->setStores ( array (
|
110 |
+
$storeId
|
111 |
+
) );
|
112 |
+
$review->save ();
|
113 |
+
|
114 |
+
/**
|
115 |
+
*
|
116 |
+
* @var $customer Mage_Rating_Model_Rating
|
117 |
+
*/
|
118 |
+
$ratingModel = Mage::getModel ( 'rating/rating' )->setReviewId ( $review->getId () )->setCustomerId ( $customerId );
|
119 |
+
// save rating for quality
|
120 |
+
$ratingModel->setRatingId ( 1 )->addOptionVote ( $rating, $productId );
|
121 |
+
// save rating for value
|
122 |
+
$ratingModel->setRatingId ( 2 )->addOptionVote ( $rating + 5, $productId );
|
123 |
+
// save rating for price
|
124 |
+
$ratingModel->setRatingId ( 3 )->addOptionVote ( $rating + 10, $productId );
|
125 |
+
$review->aggregate ();
|
126 |
+
if ($review->save ()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
$success = 1;
|
128 |
+
// Thank you for submitting a review. Your review is awaiting moderation. this is for pendind status
|
129 |
+
$message = 'Thank you for submitting a review. Your review is added successfully.';
|
130 |
+
} else {
|
131 |
$success = 0;
|
132 |
+
$message = 'Sorry, we are unable to add your review at this time.';
|
133 |
+
}
|
134 |
+
} catch ( Exception $e ) {
|
135 |
+
$success = 0;
|
136 |
+
$message = $e->getMessage ();
|
137 |
+
}
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Getting average of ratings/reviews
|
141 |
+
*/
|
142 |
+
$reviewRating = Mage::getModel ( static::LOGIN_TOKEN )->getRatingResult ( $productId, $storeId );
|
143 |
+
// get total reviews
|
144 |
+
$total_reviews_count = $review->getTotalReviews ( $productId, true, $storeId );
|
145 |
+
|
146 |
+
$response [static::VALID_TOKEN] = $isValidToken;
|
147 |
+
$response [static::ERROR] = false;
|
148 |
+
$response [static::SUCCESS] = $success;
|
149 |
+
$response [static::MESSAGE] = $message;
|
150 |
+
$response [static::RESULT] = $reviewRating;
|
151 |
+
$response [static::RESULT] ['review_status'] = $reviewStatus;
|
152 |
+
$response [static::RESULT] [static::TOT_REVWS_CNT] = $total_reviews_count;
|
153 |
+
$response [static::RESULT] [static::SUMMARY_RATING] = Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $productId, $storeId ) ? Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $productId, $storeId ) : '0';
|
154 |
+
|
155 |
+
$this->getResponse ()->setBody ( json_encode ( $response ) );
|
156 |
+
return;
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Get reviews ans rating colection fro Product
|
161 |
+
*
|
162 |
+
* @see Mage_Api2_Model_Resource::_retrieveCollection()
|
163 |
+
*/
|
164 |
+
protected function _retrieveCollection() {
|
165 |
+
$response = array ();
|
166 |
+
|
167 |
+
// get website id from request
|
168 |
+
$websiteId = ( int ) $this->getRequest ()->getParam ( static::WEBSITEID );
|
169 |
+
if ($websiteId <= 0) {
|
170 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
171 |
+
}
|
172 |
+
|
173 |
+
// get store id
|
174 |
+
$storeId = ( int ) $this->getRequest ()->getParam ( static::STOREID );
|
175 |
+
if ($storeId <= 0) {
|
176 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
177 |
+
}
|
178 |
+
// get product id
|
179 |
+
$productId = ( int ) $this->getRequest ()->getParam ( 'product_id' );
|
180 |
+
|
181 |
+
$page = ( int ) $this->getRequest ()->getParam ( 'page' );
|
182 |
+
if ($page <= 0) {
|
183 |
+
$page = 1;
|
184 |
+
}
|
185 |
+
$limit = ( int ) $this->getRequest ()->getParam ( 'limit' );
|
186 |
+
if ($limit <= 0) {
|
187 |
+
$limit = 10;
|
188 |
+
}
|
189 |
+
try {
|
190 |
+
/**
|
191 |
+
*
|
192 |
+
* @var $review Mage_Review_Model_Review
|
193 |
+
*/
|
194 |
+
$review = Mage::getModel ( 'review/review' );
|
195 |
+
// get total reviews
|
196 |
+
$total_reviews_count = $review->getTotalReviews ( $productId, true, $storeId );
|
197 |
+
|
198 |
+
/**
|
199 |
+
* Getting average of ratings/reviews
|
200 |
+
*/
|
201 |
+
$last_page = ceil ( $total_reviews_count / $limit );
|
202 |
+
if ($last_page < $page) {
|
203 |
+
$reviewRating [static::REVIEWS] = array ();
|
204 |
+
$ratings [static::RATING] = array ();
|
205 |
+
} else {
|
206 |
+
$reviewRating = Mage::getModel ( static::LOGIN_TOKEN )->getReviews ( $productId, $storeId, $page, $limit );
|
207 |
+
// get product rating count summary
|
208 |
+
$ratings = Mage::getModel ( static::LOGIN_TOKEN )->getRatingResult ( $productId, $storeId );
|
209 |
+
}
|
210 |
+
$success = 1;
|
211 |
+
} catch ( Exception $e ) {
|
212 |
+
$success = 0;
|
213 |
+
}
|
214 |
+
|
215 |
+
$response [static::ERROR] = false;
|
216 |
+
$response [static::SUCCESS] = $success;
|
217 |
+
$response [static::RESULT] [static::TOT_REVWS_CNT] = $total_reviews_count;
|
218 |
+
$response [static::RESULT] [static::SUMMARY_RATING] = Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $productId, $storeId ) ? Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $productId, $storeId ) : '0';
|
219 |
+
$response [static::RESULT] [static::REVIEWS] = $reviewRating [static::REVIEWS];
|
220 |
+
// get product rating count summary
|
221 |
+
$response [static::RESULT] [static::RATING] = $ratings [static::RATING];
|
222 |
+
return $response;
|
223 |
+
}
|
224 |
+
|
225 |
+
/**
|
226 |
+
* Retrieve seller reviews in Seller info page
|
227 |
+
*
|
228 |
+
* @return array json array
|
229 |
+
*/
|
230 |
+
protected function _retrieve() {
|
231 |
+
$response = array ();
|
232 |
+
|
233 |
+
// get website id from request
|
234 |
+
$websiteId = ( int ) $this->getRequest ()->getParam ( static::WEBSITEID );
|
235 |
+
if ($websiteId <= 0) {
|
236 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
237 |
+
}
|
238 |
+
|
239 |
+
// get store id
|
240 |
+
$storeId = ( int ) $this->getRequest ()->getParam ( static::STOREID );
|
241 |
+
if ($storeId <= 0) {
|
242 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
243 |
+
}
|
244 |
+
|
245 |
+
$page = ( int ) $this->getRequest ()->getParam ( 'page' );
|
246 |
+
if ($page <= 0) {
|
247 |
+
$page = 1;
|
248 |
+
}
|
249 |
+
$limit = ( int ) $this->getRequest ()->getParam ( 'limit' );
|
250 |
+
if ($limit <= 0) {
|
251 |
+
$limit = 10;
|
252 |
+
}
|
253 |
+
|
254 |
+
/**
|
255 |
+
* Get customer id from request
|
256 |
+
*/
|
257 |
+
$sellerId = ( int ) $this->getRequest ()->getParam ( 'seller_id' );
|
258 |
+
// get total review count
|
259 |
+
$total_reviews_count = Mage::getModel ( static::LOGIN_METHODS )->getReviewsCount ( $sellerId, $storeId );
|
260 |
+
// Getting ratings/reviews
|
261 |
+
// get only five reviews in seller info page
|
262 |
+
|
263 |
+
$last_page = ceil ( $total_reviews_count / $limit );
|
264 |
+
if ($last_page < $page) {
|
265 |
+
$reviews [static::REVIEWS] = array ();
|
266 |
+
} else {
|
267 |
+
$reviews = Mage::getModel ( static::LOGIN_METHODS )->getSellerReviews ( $sellerId, $storeId, $page, $limit );
|
268 |
+
}
|
269 |
+
|
270 |
+
$response [static::ERROR] = false;
|
271 |
+
$response [static::SUCCESS] = 1;
|
272 |
+
$response ['message'] = 'Get reviews list.';
|
273 |
+
$response [static::TOT_REVWS_CNT] = strval ( $total_reviews_count );
|
274 |
+
$response [static::RATINGS] = strval ( $total_reviews_count );
|
275 |
+
$response [static::SUMMARY_RATING] = strval ( Mage::getModel ( static::LOGIN_METHODS )->averageRatings ( $sellerId, $storeId ) );
|
276 |
+
$response [static::REVIEWS] = $reviews [static::REVIEWS];
|
277 |
+
|
278 |
+
return json_encode ( $response );
|
279 |
+
}
|
280 |
}
|
app/code/local/ContusRestapi/ReviewRating/etc/api2.xml
CHANGED
@@ -57,6 +57,10 @@
|
|
57 |
<route>/reviews/list/</route>
|
58 |
<action_type>collection</action_type>
|
59 |
</reviews_collection>
|
|
|
|
|
|
|
|
|
60 |
</routes>
|
61 |
<versions>1</versions>
|
62 |
</reviewRating>
|
57 |
<route>/reviews/list/</route>
|
58 |
<action_type>collection</action_type>
|
59 |
</reviews_collection>
|
60 |
+
<seller_reviews_collection>
|
61 |
+
<route>/seller/reviews/list/</route>
|
62 |
+
<action_type>entity</action_type>
|
63 |
+
</seller_reviews_collection>
|
64 |
</routes>
|
65 |
<versions>1</versions>
|
66 |
</reviewRating>
|
app/code/local/ContusRestapi/SearchProducts/Model/Api2/SearchProducts.php
CHANGED
@@ -1,9 +1,7 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Contus
|
4 |
-
*
|
5 |
-
* Forgotpassword API
|
6 |
-
*
|
7 |
* NOTICE OF LICENSE
|
8 |
*
|
9 |
* This source file is subject to the EULA
|
@@ -29,220 +27,314 @@
|
|
29 |
* @since 1.0
|
30 |
*/
|
31 |
class ContusRestapi_SearchProducts_Model_Api2_SearchProducts extends Mage_Api2_Model_Resource {
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
// set pagination
|
137 |
-
$collection->setPage ( $page, $limit );
|
138 |
-
$collection->setOrder ( 'name', 'asc' );
|
139 |
-
// get total products count
|
140 |
-
$totalProducts = $collection->getSize ();
|
141 |
-
// get total pages with limit
|
142 |
-
$last_page = ceil ( $totalProducts / $limit );
|
143 |
-
if ($last_page < $page) {
|
144 |
-
$_proudct_data = array ();
|
145 |
-
} else {
|
146 |
-
$_proudct_data = $this->getSearchCollection ( $collection, $customerId, $data [static::STOREID] );
|
147 |
-
}
|
148 |
-
}
|
149 |
-
$response ['success'] = 1;
|
150 |
-
$response ['error'] = false;
|
151 |
-
$response ['total_count'] = $totalProducts;
|
152 |
-
$response ['result'] = $_proudct_data;
|
153 |
-
|
154 |
-
return json_encode ( $response );
|
155 |
-
}
|
156 |
-
|
157 |
-
/**
|
158 |
-
* Get product detail as collection
|
159 |
-
*
|
160 |
-
* @param array $collection
|
161 |
-
* @param int $customerId
|
162 |
-
* @param int $storeId
|
163 |
-
* @return array $_proudct_data
|
164 |
-
*/
|
165 |
-
public function getSearchCollection($collection, $customerId, $storeId) {
|
166 |
-
$_proudct_data = array ();
|
167 |
-
$i = 0;
|
168 |
-
// get image size for resize
|
169 |
-
$imageSize = ( int ) $this->getRequest ()->getParam ( 'image_size' );
|
170 |
-
|
171 |
-
foreach ( $collection as $product ) {
|
172 |
$product->setStoreId ( $storeId )->load ( $product->getId () );
|
173 |
$_proudct_data [$i] ['entity_id'] = $product->getId ();
|
174 |
// get product name
|
175 |
-
$_proudct_data [$i] [
|
176 |
-
$_proudct_data [$i] [
|
177 |
-
// get the product final price
|
178 |
-
if ($product->getTypeId () == 'grouped') {
|
179 |
-
$_proudct_data [$i] ['regular_price_with_tax'] = number_format ( $product->getMinimalPrice (), 2, '.', '' );
|
180 |
-
$_proudct_data [$i] ['final_price_with_tax'] = number_format ( $product->getMinimalPrice (), 2, '.', '' );
|
181 |
-
} else {
|
182 |
-
$_proudct_data [$i] ['regular_price_with_tax'] = number_format ( $product->getPrice (), 2, '.', '' );
|
183 |
-
$_proudct_data [$i] ['final_price_with_tax'] = number_format ( $product->getFinalPrice (), 2, '.', '' );
|
184 |
-
}
|
185 |
-
// get product stock details
|
186 |
-
$stockDetail = Mage::getModel ( static::LOGIN_TOKEN )->getStockDetail ( $product );
|
187 |
-
$_proudct_data [$i] [static::IS_SALABLE] = $stockDetail [static::IS_SALABLE];
|
188 |
-
$_proudct_data [$i] ['is_stock'] = $stockDetail ['is_stock'];
|
189 |
-
// get product image
|
190 |
// get product image
|
191 |
if ($imageSize <= 0) {
|
192 |
-
|
193 |
} else {
|
194 |
-
|
195 |
-
}
|
196 |
-
|
197 |
-
// get rating
|
198 |
-
$_proudct_data [$i] ['summary_rating'] = Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $product->getId (), $storeId ) ? Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $product->getId (), $storeId ) : '0';
|
199 |
-
|
200 |
-
// get wishlisted products by customer
|
201 |
-
$wishListIds = array ();
|
202 |
-
if ($customerId > 0) {
|
203 |
-
$wishListIds = Mage::getModel ( static::LOGIN_TOKEN )->getWishlistByCustomer ( $customerId );
|
204 |
-
}
|
205 |
-
// Check to see the product is in wishlist
|
206 |
-
if (in_array ( $product->getId (), $wishListIds )) {
|
207 |
-
$_proudct_data [$i] ['is_wishlist'] = true;
|
208 |
-
} else {
|
209 |
-
$_proudct_data [$i] ['is_wishlist'] = false;
|
210 |
}
|
211 |
|
212 |
$i ++;
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* Contus
|
4 |
+
*
|
|
|
|
|
5 |
* NOTICE OF LICENSE
|
6 |
*
|
7 |
* This source file is subject to the EULA
|
27 |
* @since 1.0
|
28 |
*/
|
29 |
class ContusRestapi_SearchProducts_Model_Api2_SearchProducts extends Mage_Api2_Model_Resource {
|
30 |
+
|
31 |
+
// Declaring the string literals variable
|
32 |
+
const STOREID = 'store_id';
|
33 |
+
const CUSTOMER_ID = 'customer_id';
|
34 |
+
const SEARCH_TERM = 'search_term';
|
35 |
+
const CATEGORY_ID = 'category_id';
|
36 |
+
const CATALOGSEARCH = 'catalogsearch';
|
37 |
+
const IS_SALABLE = 'is_saleable';
|
38 |
+
const LIMIT = 'limit';
|
39 |
+
const PAGE = 'page';
|
40 |
+
const LOGIN_TOKEN = 'login/token';
|
41 |
+
const NAME = 'name';
|
42 |
+
const CATIMG = 'catalog/image';
|
43 |
+
const SMALLIMG = 'small_image';
|
44 |
+
const IMG_URL = 'image_url';
|
45 |
+
const FINAL_PRICE = 'final_price_with_tax';
|
46 |
+
const STOCK_QTY = 'stock_qty';
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Search products based on posted value
|
50 |
+
*
|
51 |
+
* @return array json array
|
52 |
+
*/
|
53 |
+
protected function _retrieveCollection() {
|
54 |
+
|
55 |
+
// get website id
|
56 |
+
$websiteId = ( int ) Mage::app ()->getRequest ()->getParam ( 'website_id' );
|
57 |
+
if ($websiteId <= 0) {
|
58 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
59 |
+
}
|
60 |
+
|
61 |
+
// get store id from request
|
62 |
+
$storeId = ( int ) Mage::app ()->getRequest ()->getParam ( static::STOREID );
|
63 |
+
if ($storeId <= 0) {
|
64 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
65 |
+
}
|
66 |
+
// get search term from request
|
67 |
+
$searchterm = Mage::app ()->getRequest ()->getParam ( static::SEARCH_TERM );
|
68 |
+
// get category id from request
|
69 |
+
$categoryId = ( int ) Mage::app ()->getRequest ()->getParam ( static::CATEGORY_ID );
|
70 |
+
|
71 |
+
// get page from request
|
72 |
+
$page = ( int ) $this->getRequest ()->getParam ( static::PAGE );
|
73 |
+
if ($page <= 0) {
|
74 |
+
$page = 1;
|
75 |
+
}
|
76 |
+
|
77 |
+
// get page from request
|
78 |
+
$limit = ( int ) $this->getRequest ()->getParam ( static::LIMIT );
|
79 |
+
if ($limit <= 0) {
|
80 |
+
$limit = 10;
|
81 |
+
}
|
82 |
+
// get customer id from request
|
83 |
+
$customerId = ( int ) Mage::app ()->getRequest ()->getParam ( static::CUSTOMER_ID );
|
84 |
+
|
85 |
+
$collection = $this->getCatalogSearch ( array (
|
86 |
+
static::SEARCH_TERM => $searchterm,
|
87 |
+
static::STOREID => $storeId,
|
88 |
+
static::CATEGORY_ID => $categoryId,
|
89 |
+
static::CUSTOMER_ID => $customerId,
|
90 |
+
static::PAGE => $page,
|
91 |
+
static::LIMIT => $limit
|
92 |
+
) );
|
93 |
+
|
94 |
+
return $this->getResult ( $collection, $page, $limit, $customerId, $storeId );
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Get cart dotal qty
|
99 |
+
*
|
100 |
+
* @param integer $customerId
|
101 |
+
* @return array json array
|
102 |
+
*/
|
103 |
+
protected function _retrieve() {
|
104 |
+
$response = array ();
|
105 |
+
$_proudct_data = array ();
|
106 |
+
// get website id
|
107 |
+
$websiteId = ( int ) Mage::app ()->getRequest ()->getParam ( 'website_id' );
|
108 |
+
if ($websiteId <= 0) {
|
109 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
110 |
+
}
|
111 |
+
|
112 |
+
// get store id from request
|
113 |
+
$storeId = ( int ) Mage::app ()->getRequest ()->getParam ( static::STOREID );
|
114 |
+
if ($storeId <= 0) {
|
115 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
116 |
+
}
|
117 |
+
// get image size for resize
|
118 |
+
$imageSize = ( int ) $this->getRequest ()->getParam ( 'image_size' );
|
119 |
+
|
120 |
+
// get search term from request
|
121 |
+
$searchterm = Mage::app ()->getRequest ()->getParam ( static::SEARCH_TERM );
|
122 |
+
$categoryId = '';
|
123 |
+
$collection = $this->getCatalogSearch ( array (
|
124 |
+
static::SEARCH_TERM => $searchterm,
|
125 |
+
static::STOREID => $storeId,
|
126 |
+
static::CATEGORY_ID => $categoryId
|
127 |
+
) );
|
128 |
+
if ($collection) {
|
129 |
+
$collection->addAttributeToSort ( static::NAME, 'asc' );
|
130 |
+
$collection->getSelect ()->limit ( 10 );
|
131 |
+
|
132 |
+
$i = 0;
|
133 |
+
foreach ( $collection as $product ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
$product->setStoreId ( $storeId )->load ( $product->getId () );
|
135 |
$_proudct_data [$i] ['entity_id'] = $product->getId ();
|
136 |
// get product name
|
137 |
+
$_proudct_data [$i] [static::NAME] = $product->getName ();
|
138 |
+
$_proudct_data [$i] [static::FINAL_PRICE] = number_format ( $product->getFinalPrice (), 2, '.', '' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
// get product image
|
140 |
if ($imageSize <= 0) {
|
141 |
+
$_proudct_data [$i] [static::IMG_URL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, static::SMALLIMG );
|
142 |
} else {
|
143 |
+
$_proudct_data [$i] [static::IMG_URL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, static::SMALLIMG )->constrainOnly ( TRUE )->keepAspectRatio ( TRUE )->keepFrame ( FALSE )->resize ( $imageSize, null );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
}
|
145 |
|
146 |
$i ++;
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
$response ['success'] = 1;
|
151 |
+
$response ['error'] = false;
|
152 |
+
$response ['total_count'] = count ( $_proudct_data );
|
153 |
+
$response ['result'] = $_proudct_data;
|
154 |
+
|
155 |
+
return $response;
|
156 |
+
}
|
157 |
+
|
158 |
+
/**
|
159 |
+
* Search products by given word
|
160 |
+
*
|
161 |
+
* @param array $data
|
162 |
+
* @return array
|
163 |
+
*/
|
164 |
+
public function getCatalogSearch($data) {
|
165 |
+
|
166 |
+
// get category id
|
167 |
+
$categoryId = ( int ) $data [static::CATEGORY_ID];
|
168 |
+
$collection = '';
|
169 |
+
$_helper = Mage::helper ( static::CATALOGSEARCH );
|
170 |
+
$queryParam = str_replace ( '%20', ' ', $data [static::SEARCH_TERM] );
|
171 |
+
Mage::app ()->getRequest ()->setParam ( $_helper->getQueryParamName (), $queryParam );
|
172 |
+
$query = $_helper->getQuery ();
|
173 |
+
$query->setStoreId ( $data [static::STOREID] );
|
174 |
+
$error = FALSE;
|
175 |
+
if ($query->getQueryText () != '') {
|
176 |
+
|
177 |
+
$this->searchQuery ( $query );
|
178 |
+
} else {
|
179 |
+
$error = TRUE;
|
180 |
+
}
|
181 |
+
// get these type of products only
|
182 |
+
$productType = array (
|
183 |
+
"simple",
|
184 |
+
"configurable"
|
185 |
+
);
|
186 |
+
|
187 |
+
// get city for filter products
|
188 |
+
$city = ( int ) Mage::app ()->getRequest ()->getParam ( 'city' );
|
189 |
+
|
190 |
+
if (! $error) {
|
191 |
+
$collection = Mage::getResourceModel ( 'catalogsearch/fulltext_collection' );
|
192 |
+
$collection->addAttributeToSelect ( Mage::getSingleton ( 'catalog/config' )->getProductAttributes () )->addSearchFilter ( $data [static::SEARCH_TERM] )->setstore ( $data [static::STOREID] )->addAttributeToFilter ( 'type_id', array (
|
193 |
+
'in' => $productType
|
194 |
+
) )->addStoreFilter ()->addUrlRewrite ();
|
195 |
+
$collection->addMinimalPrice ()->addFinalPrice ()->addTaxPercents ();
|
196 |
+
Mage::getSingleton ( 'catalog/product_status' )->addVisibleFilterToCollection ( $collection );
|
197 |
+
Mage::getSingleton ( 'catalog/product_visibility' )->addVisibleInSearchFilterToCollection ( $collection );
|
198 |
+
// Filter products by city
|
199 |
+
if ($city) {
|
200 |
+
$collection->addFieldToFilter ( 'city', array (
|
201 |
+
array (
|
202 |
+
'regexp' => $city
|
203 |
+
)
|
204 |
+
) );
|
205 |
+
}
|
206 |
+
// ge products by catgory id
|
207 |
+
if ($categoryId > 0) {
|
208 |
+
$collection->getSelect ()->join ( array (
|
209 |
+
'category' => $prefix . 'catalog_category_product_index'
|
210 |
+
), 'category.product_id = cat_index.product_id and category.category_id =' . $categoryId, array () )->group ( 'e.entity_id' );
|
211 |
+
}
|
212 |
+
}
|
213 |
+
return $collection;
|
214 |
+
}
|
215 |
+
public function getResult($collection, $page, $limit, $customerId, $storeId) {
|
216 |
+
$response = array ();
|
217 |
+
$totalProducts = 0;
|
218 |
+
$_proudct_data = array ();
|
219 |
+
if ($collection) {
|
220 |
+
// set pagination
|
221 |
+
$collection->setPage ( $page, $limit );
|
222 |
+
$collection->setOrder ( static::NAME, 'asc' );
|
223 |
+
// get total products count
|
224 |
+
$totalProducts = $collection->getSize ();
|
225 |
+
// get total pages with limit
|
226 |
+
$last_page = ceil ( $totalProducts / $limit );
|
227 |
+
if ($last_page < $page) {
|
228 |
+
$_proudct_data = array ();
|
229 |
+
} else {
|
230 |
+
$_proudct_data = $this->getSearchCollection ( $collection, $customerId, $storeId );
|
231 |
+
}
|
232 |
+
}
|
233 |
+
|
234 |
+
$response ['success'] = 1;
|
235 |
+
$response ['error'] = false;
|
236 |
+
$response ['total_count'] = $totalProducts;
|
237 |
+
$response ['result'] = $_proudct_data;
|
238 |
+
|
239 |
+
return json_encode ( $response );
|
240 |
+
}
|
241 |
+
/**
|
242 |
+
* Get product detail as collection
|
243 |
+
*
|
244 |
+
* @param array $collection
|
245 |
+
* @param int $customerId
|
246 |
+
* @param int $storeId
|
247 |
+
* @return array $_proudct_data
|
248 |
+
*/
|
249 |
+
public function getSearchCollection($collection, $customerId, $storeId) {
|
250 |
+
$_proudct_data = array ();
|
251 |
+
$i = 0;
|
252 |
+
// get image size for resize
|
253 |
+
$imageSize = ( int ) $this->getRequest ()->getParam ( 'image_size' );
|
254 |
+
|
255 |
+
foreach ( $collection as $product ) {
|
256 |
+
$product->setStoreId ( $storeId )->load ( $product->getId () );
|
257 |
+
$_proudct_data [$i] ['entity_id'] = $product->getId ();
|
258 |
+
// get product name
|
259 |
+
$_proudct_data [$i] [static::NAME] = $product->getName ();
|
260 |
+
$_proudct_data [$i] ['type_id'] = $product->getTypeId ();
|
261 |
+
// get the product final price
|
262 |
+
if ($product->getTypeId () == 'grouped') {
|
263 |
+
$_proudct_data [$i] ['regular_price_with_tax'] = number_format ( $product->getMinimalPrice (), 2, '.', '' );
|
264 |
+
$_proudct_data [$i] [static::FINAL_PRICE] = number_format ( $product->getMinimalPrice (), 2, '.', '' );
|
265 |
+
} else {
|
266 |
+
$_proudct_data [$i] ['regular_price_with_tax'] = number_format ( $product->getPrice (), 2, '.', '' );
|
267 |
+
$_proudct_data [$i] [static::FINAL_PRICE] = number_format ( $product->getFinalPrice (), 2, '.', '' );
|
268 |
+
}
|
269 |
+
// get product stock details
|
270 |
+
$stockDetail = Mage::getModel ( static::LOGIN_TOKEN )->getStockDetail ( $product );
|
271 |
+
$_proudct_data [$i] [static::IS_SALABLE] = $stockDetail [static::IS_SALABLE];
|
272 |
+
$_proudct_data [$i] ['is_stock'] = $stockDetail ['is_stock'];
|
273 |
+
// get product image
|
274 |
+
if ($imageSize <= 0) {
|
275 |
+
$_proudct_data [$i] [static::IMG_URL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, static::SMALLIMG );
|
276 |
+
} else {
|
277 |
+
$_proudct_data [$i] [static::IMG_URL] = ( string ) Mage::helper ( static::CATIMG )->init ( $product, static::SMALLIMG )->constrainOnly ( TRUE )->keepAspectRatio ( TRUE )->keepFrame ( FALSE )->resize ( $imageSize, null );
|
278 |
+
}
|
279 |
+
// get wishlisted products by customer
|
280 |
+
$wishListIds = array ();
|
281 |
+
if ($customerId > 0) {
|
282 |
+
$wishListIds = Mage::getModel ( static::LOGIN_TOKEN )->getWishlistByCustomer ( $customerId );
|
283 |
+
}
|
284 |
+
// Check to see the product is in wishlist
|
285 |
+
if (in_array ( $product->getId (), $wishListIds )) {
|
286 |
+
$_proudct_data [$i] ['is_wishlist'] = true;
|
287 |
+
} else {
|
288 |
+
$_proudct_data [$i] ['is_wishlist'] = false;
|
289 |
+
}
|
290 |
+
// get rating
|
291 |
+
$_proudct_data [$i] ['summary_rating'] = Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $product->getId (), $storeId ) ? Mage::getModel ( static::LOGIN_TOKEN )->rateSummary ( $product->getId (), $storeId ) : '0';
|
292 |
+
// get product stock details
|
293 |
+
$inventoryDetail = Mage::getModel ( 'login/methods_functions' )->getinventoryDetail ( $product, $storeId );
|
294 |
+
// get stock available qty
|
295 |
+
$_proudct_data [$i] [static::STOCK_QTY] = $inventoryDetail [static::STOCK_QTY];
|
296 |
+
// get product minimum qty allowed to cart
|
297 |
+
$_proudct_data [$i] ['min_sale_qty'] = $inventoryDetail ['min_sale_qty'];
|
298 |
+
// get product maximm qty allowed to cart
|
299 |
+
$_proudct_data [$i] ['max_sale_qty'] = $inventoryDetail ['max_sale_qty'];
|
300 |
+
// get product increment qty allowed to cart
|
301 |
+
$_proudct_data [$i] ['qty_increments'] = $inventoryDetail ['qty_increments'];
|
302 |
+
$_proudct_data [$i] ['is_qty_decimal'] = $inventoryDetail ['is_qty_decimal'];
|
303 |
+
|
304 |
+
$i ++;
|
305 |
+
}
|
306 |
+
|
307 |
+
return $_proudct_data;
|
308 |
+
}
|
309 |
+
|
310 |
+
/**
|
311 |
+
* Search Products
|
312 |
+
*
|
313 |
+
* @param object $query
|
314 |
+
*/
|
315 |
+
public function searchQuery($query) {
|
316 |
+
$check = FALSE;
|
317 |
+
if (Mage::helper ( static::CATALOGSEARCH )->isMinQueryLength ()) {
|
318 |
+
$query->setId ( 0 )->setIsActive ( 1 )->setIsProcessed ( 1 );
|
319 |
+
} else {
|
320 |
+
if ($query->getId ()) {
|
321 |
+
$query->setPopularity ( $query->getPopularity () + 1 );
|
322 |
+
} else {
|
323 |
+
$query->setPopularity ( 1 );
|
324 |
+
}
|
325 |
+
|
326 |
+
if ($query->getRedirect ()) {
|
327 |
+
$query->save ();
|
328 |
+
$check = TRUE;
|
329 |
+
} else {
|
330 |
+
$query->prepare ();
|
331 |
+
}
|
332 |
+
}
|
333 |
+
if (! $check) {
|
334 |
+
Mage::helper ( static::CATALOGSEARCH )->checkNotes ();
|
335 |
+
if (! Mage::helper ( static::CATALOGSEARCH )->isMinQueryLength ()) {
|
336 |
+
$query->save ();
|
337 |
+
}
|
338 |
+
}
|
339 |
+
}
|
340 |
}
|
app/code/local/ContusRestapi/SearchProducts/etc/api2.xml
CHANGED
@@ -39,13 +39,21 @@
|
|
39 |
<limit>Limit</limit>
|
40 |
<result>Search Result</result>
|
41 |
<count>Page Count</count>
|
42 |
-
<
|
|
|
|
|
|
|
43 |
</attributes>
|
44 |
<routes>
|
45 |
<route_collection>
|
46 |
<route>/search/products/</route>
|
47 |
<action_type>collection</action_type>
|
48 |
</route_collection>
|
|
|
|
|
|
|
|
|
|
|
49 |
</routes>
|
50 |
<versions>1</versions>
|
51 |
</searchProducts>
|
39 |
<limit>Limit</limit>
|
40 |
<result>Search Result</result>
|
41 |
<count>Page Count</count>
|
42 |
+
<total_count>Total Products Count</total_count>
|
43 |
+
<success>Success</success>
|
44 |
+
<error>Error</error>
|
45 |
+
<city>City</city>
|
46 |
</attributes>
|
47 |
<routes>
|
48 |
<route_collection>
|
49 |
<route>/search/products/</route>
|
50 |
<action_type>collection</action_type>
|
51 |
</route_collection>
|
52 |
+
|
53 |
+
<predictive_search>
|
54 |
+
<route>/predictive/search/</route>
|
55 |
+
<action_type>entity</action_type>
|
56 |
+
</predictive_search>
|
57 |
</routes>
|
58 |
<versions>1</versions>
|
59 |
</searchProducts>
|
app/code/local/ContusRestapi/Sellers/Model/Api2/Sellers.php
ADDED
@@ -0,0 +1,387 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the EULA
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://www.apptha.com/LICENSE.txt
|
12 |
+
*
|
13 |
+
* ==============================================================
|
14 |
+
* MAGENTO EDITION USAGE NOTICE
|
15 |
+
* ==============================================================
|
16 |
+
* This package designed for Magento COMMUNITY edition
|
17 |
+
* Apptha does not guarantee correct work of this extension
|
18 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
19 |
+
* Apptha does not provide extension support in case of
|
20 |
+
* incorrect edition usage.
|
21 |
+
* ==============================================================
|
22 |
+
*
|
23 |
+
* @category Contus
|
24 |
+
* @package ContusRestapi_Sellers
|
25 |
+
* @author Contus Team <developers@contus.in>
|
26 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
27 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
28 |
+
* @since 1.0
|
29 |
+
*/
|
30 |
+
class ContusRestapi_Sellers_Model_Api2_Sellers extends Mage_Api2_Model_Resource {
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Define staic variable
|
34 |
+
*/
|
35 |
+
const STOREID = 'store_id';
|
36 |
+
const WEBSITEID = 'website_id';
|
37 |
+
const CUSTOMER_ID = 'customer_id';
|
38 |
+
const SUCCESS = 'success';
|
39 |
+
const MESSAGE = 'message';
|
40 |
+
const ERROR = 'error';
|
41 |
+
const PAGE = 'page';
|
42 |
+
const LIMIT = 'limit';
|
43 |
+
const SELLER_ID = 'seller_id';
|
44 |
+
const CUSTOMER_CUSTOMER = 'customer/customer';
|
45 |
+
const CORE_EMAIL_TEMP = 'core/email_template';
|
46 |
+
const ENTITYID = 'entity_id';
|
47 |
+
const LOGIN_METHODS = 'login/methods_functions';
|
48 |
+
const SMALLIMG = 'small_image';
|
49 |
+
const RATINGS = 'ratings';
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Add rating points to seller
|
53 |
+
*
|
54 |
+
* @param array $data
|
55 |
+
* @return array json array
|
56 |
+
*/
|
57 |
+
protected function _create(array $data) {
|
58 |
+
$response = array ();
|
59 |
+
|
60 |
+
try {
|
61 |
+
|
62 |
+
$saveReview = $this->saveReview ( $data );
|
63 |
+
if ($saveReview == 1) {
|
64 |
+
$needAdmin = Mage::getStoreConfig ( 'marketplace/seller_review/need_approval' );
|
65 |
+
if ($needAdmin == 1) {
|
66 |
+
$message = 'Your review has been accepted for moderation.';
|
67 |
+
} else {
|
68 |
+
$message = 'Your review has been successfully posted.';
|
69 |
+
}
|
70 |
+
$success = 1;
|
71 |
+
}
|
72 |
+
} catch ( Mage_Core_Exception $e ) {
|
73 |
+
$message = $e->getMessage ();
|
74 |
+
$success = 0;
|
75 |
+
} catch ( Exception $e ) {
|
76 |
+
$message = $e->getMessage ();
|
77 |
+
$success = 0;
|
78 |
+
}
|
79 |
+
$response [static::ERROR] = false;
|
80 |
+
$response [static::SUCCESS] = $success;
|
81 |
+
$response [static::MESSAGE] = $message;
|
82 |
+
$response [static::RATINGS] = strval ( Mage::getModel ( static::LOGIN_METHODS )->averageRatings ( $data [static::SELLER_ID], $data [static::STOREID] ) );
|
83 |
+
$response ['summary_rating'] = strval ( Mage::getModel ( static::LOGIN_METHODS )->getReviewsCount ( $data [static::SELLER_ID], $data [static::STOREID] ) );
|
84 |
+
|
85 |
+
$this->getResponse ()->setBody ( json_encode ( $response ) );
|
86 |
+
return;
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Retrieve Sellers List collection
|
91 |
+
*
|
92 |
+
* @param integer $customerId
|
93 |
+
* @return array json array
|
94 |
+
*/
|
95 |
+
protected function _retrieveCollection() {
|
96 |
+
$response = array ();
|
97 |
+
|
98 |
+
// get page from request
|
99 |
+
$page = $this->getRequest ()->getParam ( 'page' );
|
100 |
+
if ($page <= 0) {
|
101 |
+
$page = 1;
|
102 |
+
}
|
103 |
+
// get page from request
|
104 |
+
$limit = $this->getRequest ()->getParam ( static::LIMIT );
|
105 |
+
if ($limit <= 0) {
|
106 |
+
$limit = 10;
|
107 |
+
}
|
108 |
+
/**
|
109 |
+
* Get website id from request
|
110 |
+
*/
|
111 |
+
$websiteId = ( int ) $this->getRequest ()->getParam ( static::WEBSITEID );
|
112 |
+
if ($websiteId <= 0) {
|
113 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Get store id
|
118 |
+
*/
|
119 |
+
$storeId = ( int ) $this->getRequest ()->getParam ( static::STOREID );
|
120 |
+
if ($storeId <= 0) {
|
121 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Get the sellers List
|
126 |
+
*/
|
127 |
+
$sellerList = Mage::getModel ( static::CUSTOMER_CUSTOMER )->getCollection ()->addFieldToFilter ( 'group_id', 6 );
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Set pagination
|
131 |
+
*/
|
132 |
+
$sellerList->setPage ( $page, $limit );
|
133 |
+
$sellerList->setOrder ( 'name', 'asc' );
|
134 |
+
/**
|
135 |
+
* Get total products count
|
136 |
+
*/
|
137 |
+
$totalSellers = $sellerList->getSize ();
|
138 |
+
/**
|
139 |
+
* Get total pages with limit
|
140 |
+
*/
|
141 |
+
$last_page = ceil ( $totalSellers / $limit );
|
142 |
+
if ($last_page < $page) {
|
143 |
+
$sellers = array ();
|
144 |
+
} else {
|
145 |
+
$i = 0;
|
146 |
+
foreach ( $sellerList->getData () as $_collection ) {
|
147 |
+
$sellerId = $_collection [static::ENTITYID];
|
148 |
+
|
149 |
+
$sellers [$i] = Mage::getModel ( static::LOGIN_METHODS )->sellerdisplay ( $sellerId, '0', $storeId, '' );
|
150 |
+
|
151 |
+
$i ++;
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
$response [static::ERROR] = false;
|
156 |
+
$response [static::SUCCESS] = 1;
|
157 |
+
$response ['totalCount'] = $totalSellers;
|
158 |
+
$response [static::MESSAGE] = 'Get sellers information.';
|
159 |
+
$response ['result'] = $sellers;
|
160 |
+
|
161 |
+
return json_encode ( $response );
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Retrieve Seller profile collection
|
166 |
+
*
|
167 |
+
* @param integer $customerId
|
168 |
+
* @return array json array
|
169 |
+
*/
|
170 |
+
protected function _retrieve() {
|
171 |
+
$response = array ();
|
172 |
+
|
173 |
+
/**
|
174 |
+
* Get website id from request
|
175 |
+
*/
|
176 |
+
$websiteId = ( int ) $this->getRequest ()->getParam ( static::WEBSITEID );
|
177 |
+
if ($websiteId <= 0) {
|
178 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Get store id from request
|
183 |
+
*/
|
184 |
+
$storeId = ( int ) Mage::app ()->getRequest ()->getParam ( static::STOREID );
|
185 |
+
if ($storeId <= 0) {
|
186 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
187 |
+
}
|
188 |
+
/**
|
189 |
+
* Get page from request
|
190 |
+
*/
|
191 |
+
$page = ( int ) $this->getRequest ()->getParam ( 'page' );
|
192 |
+
if ($page <= 0) {
|
193 |
+
$page = 1;
|
194 |
+
}
|
195 |
+
/**
|
196 |
+
* Get page from request
|
197 |
+
*/
|
198 |
+
$limit = ( int ) $this->getRequest ()->getParam ( static::LIMIT );
|
199 |
+
if ($limit <= 0) {
|
200 |
+
$limit = 10;
|
201 |
+
}
|
202 |
+
|
203 |
+
/**
|
204 |
+
* Get customer id from request
|
205 |
+
*/
|
206 |
+
$sellerId = ( int ) $this->getRequest ()->getParam ( static::SELLER_ID );
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Get the seller data
|
210 |
+
*/
|
211 |
+
$response ['seller_info'] = $this->sellerdisplay ( $sellerId, $storeId );
|
212 |
+
|
213 |
+
/**
|
214 |
+
* Get seller Product
|
215 |
+
*/
|
216 |
+
$sellerproduct = Mage::getModel ( 'catalog/product' )->setStoreId ( $storeId )->getCollection ()->addFieldToFilter ( static::SELLER_ID, $sellerId );
|
217 |
+
$sellerproduct->addAttributeToFilter ( 'status', array (
|
218 |
+
'eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED
|
219 |
+
) );
|
220 |
+
$sellerproduct->addAttributeToFilter ( 'visibility', array (
|
221 |
+
'neq' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
|
222 |
+
) );
|
223 |
+
|
224 |
+
// Get total products count
|
225 |
+
$totalProducts = $sellerproduct->getSize ();
|
226 |
+
$sellerproduct->setPage ( $page, $limit );
|
227 |
+
$products = $sellerproduct->load ();
|
228 |
+
|
229 |
+
/**
|
230 |
+
* Get total pages with limit
|
231 |
+
*/
|
232 |
+
$last_page = ceil ( $totalProducts / $limit );
|
233 |
+
if ($last_page < $page) {
|
234 |
+
$response ['seller_product'] = array ();
|
235 |
+
} else {
|
236 |
+
$response ['seller_product'] = $this->sellerproduct ( $products, $storeId );
|
237 |
+
}
|
238 |
+
|
239 |
+
// Getting ratings/reviews
|
240 |
+
// get only five reviews in seller info page
|
241 |
+
$reviews = Mage::getModel ( static::LOGIN_METHODS )->getSellerReviews ( $sellerId, $storeId, 1, 5 );
|
242 |
+
$response ['reviews'] = $reviews ['reviews'];
|
243 |
+
$response ['total_reviews_count'] = $reviews ['total_reviews_count'];
|
244 |
+
|
245 |
+
$response [static::ERROR] = false;
|
246 |
+
$response [static::SUCCESS] = 1;
|
247 |
+
$response ['total_count'] = $totalProducts;
|
248 |
+
|
249 |
+
return json_encode ( $response );
|
250 |
+
}
|
251 |
+
function saveReview($data) {
|
252 |
+
$needAdmin = Mage::getStoreConfig ( 'marketplace/seller_review/need_approval' );
|
253 |
+
if ($data) {
|
254 |
+
|
255 |
+
$collection = Mage::getModel ( 'marketplace/sellerreview' );
|
256 |
+
$collection->setSellerId ( $data [static::SELLER_ID] );
|
257 |
+
$collection->setProductId ( $data ['product_id'] );
|
258 |
+
$collection->setCustomerId ( $data [static::CUSTOMER_ID] );
|
259 |
+
$collection->setRating ( $data [static::RATINGS] );
|
260 |
+
$collection->setReview ( $data ['feedback'] );
|
261 |
+
$collection->setStoreId ( $data [static::STOREID] );
|
262 |
+
if ($needAdmin == 1) {
|
263 |
+
$collection->setStatus ( 0 );
|
264 |
+
} else {
|
265 |
+
$collection->setStatus ( 1 );
|
266 |
+
}
|
267 |
+
$collection->save ();
|
268 |
+
if ($needAdmin == 1) {
|
269 |
+
$templateId = ( int ) Mage::getStoreConfig ( 'marketplace/seller_review/admin_notify_review' );
|
270 |
+
} else {
|
271 |
+
$templateId = ( int ) Mage::getStoreConfig ( 'marketplace/seller_review/notify_new_review' );
|
272 |
+
}
|
273 |
+
$adminEmailId = Mage::getStoreConfig ( 'marketplace/marketplace/admin_email_id' );
|
274 |
+
$toMailId = Mage::getStoreConfig ( "trans_email/ident_$adminEmailId/email" );
|
275 |
+
$toName = Mage::getStoreConfig ( "trans_email/ident_$adminEmailId/name" );
|
276 |
+
if ($templateId) {
|
277 |
+
$emailTemplate = Mage::getModel ( static::CORE_EMAIL_TEMP )->load ( $templateId );
|
278 |
+
} else {
|
279 |
+
if ($needAdmin == 1) {
|
280 |
+
$emailTemplate = Mage::getModel ( static::CORE_EMAIL_TEMP )->loadDefault ( 'marketplace_seller_review_admin_notify_review' );
|
281 |
+
} else {
|
282 |
+
$emailTemplate = Mage::getModel ( static::CORE_EMAIL_TEMP )->loadDefault ( 'marketplace_seller_review_notify_new_review' );
|
283 |
+
}
|
284 |
+
}
|
285 |
+
$adminurl = Mage::helper ( 'adminhtml' )->getUrl ( 'marketplaceadmin/adminhtml_sellerreview/index' );
|
286 |
+
$customer = Mage::getModel ( static::CUSTOMER_CUSTOMER )->load ( $data [static::CUSTOMER_ID] );
|
287 |
+
$cname = $customer->getName ();
|
288 |
+
$cemail = $customer->getEmail ();
|
289 |
+
$emailTemplate->setSenderEmail ( $cemail );
|
290 |
+
$emailTemplate->setSenderName ( ucwords ( $cname ) );
|
291 |
+
$emailTemplate->setDesignConfig ( array (
|
292 |
+
'area' => 'frontend'
|
293 |
+
) );
|
294 |
+
$emailTemplateVariables = (array (
|
295 |
+
'ownername' => ucwords ( $toName ),
|
296 |
+
'cname' => ucwords ( $cname ),
|
297 |
+
'cemail' => $cemail,
|
298 |
+
'adminurl' => $adminurl
|
299 |
+
));
|
300 |
+
$emailTemplate->getProcessedTemplate ( $emailTemplateVariables );
|
301 |
+
$emailTemplate->send ( $toMailId, ucwords ( $toName ), $emailTemplateVariables );
|
302 |
+
return true;
|
303 |
+
} else {
|
304 |
+
return false;
|
305 |
+
}
|
306 |
+
}
|
307 |
+
|
308 |
+
/**
|
309 |
+
* Function to get the seller profile data
|
310 |
+
*
|
311 |
+
* Passed the seller id as $sellerId to get particular seller info
|
312 |
+
*
|
313 |
+
* @param int $sellerId
|
314 |
+
* Return store title of the seller as $StoreTitle
|
315 |
+
* @return varchar
|
316 |
+
*/
|
317 |
+
public function sellerdisplay($sellerId, $storeId) {
|
318 |
+
$sellerDetail = array ();
|
319 |
+
$sellerDetail = Mage::getModel ( 'marketplace/sellerprofile' )->load ( $sellerId, static::SELLER_ID )->getData ();
|
320 |
+
|
321 |
+
/**
|
322 |
+
* load customer info
|
323 |
+
*/
|
324 |
+
$customerInfo = Mage::getModel ( 'customer/customer' )->load ( $sellerDetail [static::SELLER_ID] );
|
325 |
+
// get seller email
|
326 |
+
$sellerDetail ['email'] = $customerInfo->getEmail ();
|
327 |
+
// get seller name
|
328 |
+
$sellerDetail ['name'] = $customerInfo->getName ();
|
329 |
+
|
330 |
+
if ($sellerDetail ['country']) {
|
331 |
+
$country = Mage::getModel ( 'directory/country' )->loadByCode ( $sellerDetail ['country'] );
|
332 |
+
// get country name
|
333 |
+
$sellerDetail ['country_name'] = $country->getName ();
|
334 |
+
}
|
335 |
+
$sellerDetail ['store_logo'] = Mage::getBaseUrl ( 'media' ) . DS . 'marketplace/resized/' . $sellerDetail ['store_logo'];
|
336 |
+
$sellerDetail ['store_banner'] = Mage::getBaseUrl ( 'media' ) . DS . 'marketplace/resized/' . $sellerDetail ['store_banner'];
|
337 |
+
$sellerDetail ['summary_rating'] = strval ( Mage::getModel ( static::LOGIN_METHODS )->averageRatings ( $sellerId, $storeId ) );
|
338 |
+
$sellerDetail [static::RATINGS] = strval ( Mage::getModel ( static::LOGIN_METHODS )->getReviewsCount ( $sellerId, $storeId ) );
|
339 |
+
return $sellerDetail;
|
340 |
+
}
|
341 |
+
|
342 |
+
/**
|
343 |
+
* Function to get seller product
|
344 |
+
*
|
345 |
+
* Passed the seller id as $sellerId to get particular seller products
|
346 |
+
*
|
347 |
+
* @param int $sellerId
|
348 |
+
* Return products of the seller
|
349 |
+
*/
|
350 |
+
public function sellerproduct($products, $storeId) {
|
351 |
+
$productDetail = array ();
|
352 |
+
|
353 |
+
/**
|
354 |
+
* Get image size for resize
|
355 |
+
*/
|
356 |
+
$imageSize = ( int ) $this->getRequest ()->getParam ( 'image_size' );
|
357 |
+
|
358 |
+
$i = 0;
|
359 |
+
foreach ( $products->getData () as $product ) {
|
360 |
+
$_product = Mage::getModel ( 'catalog/product' )->load ( $product [static::ENTITYID] );
|
361 |
+
$productDetail [$i] [static::ENTITYID] = $_product->getId ();
|
362 |
+
$productDetail [$i] ['type_id'] = $_product->getTypeId ();
|
363 |
+
$productDetail [$i] ['name'] = $_product->getName ();
|
364 |
+
/**
|
365 |
+
* Get product image
|
366 |
+
*/
|
367 |
+
if ($imageSize <= 0) {
|
368 |
+
$productDetail [$i] ['image_url'] = ( string ) Mage::helper ( 'catalog/image' )->init ( $_product, static::SMALLIMG );
|
369 |
+
} else {
|
370 |
+
$productDetail [$i] ['image_url'] = ( string ) Mage::helper ( 'catalog/image' )->init ( $_product, static::SMALLIMG )->constrainOnly ( TRUE )->keepAspectRatio ( TRUE )->keepFrame ( FALSE )->resize ( $imageSize, null );
|
371 |
+
}
|
372 |
+
$productDetail [$i] ['regular_price_with_tax'] = number_format ( $_product->getPrice (), 2, '.', '' );
|
373 |
+
$productDetail [$i] ['final_price_with_tax'] = number_format ( $_product->getFinalPrice (), 2, '.', '' );
|
374 |
+
$i ++;
|
375 |
+
}
|
376 |
+
|
377 |
+
return $productDetail;
|
378 |
+
}
|
379 |
+
|
380 |
+
/**
|
381 |
+
* Get all sellers list
|
382 |
+
*/
|
383 |
+
public function sellerList() {
|
384 |
+
$users = Mage::getModel ( static::CUSTOMER_CUSTOMER )->getCollection ()->addFieldToFilter ( 'group_id', 6 );
|
385 |
+
return $users->getData ();
|
386 |
+
}
|
387 |
+
}
|
app/code/local/ContusRestapi/Sellers/Model/Api2/Sellers/Rest.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_Sellers
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_Sellers_Model_Api2_Sellers_Rest extends ContusRestapi_Sellers_Model_Api2_Sellers {
|
30 |
+
}
|
app/code/local/ContusRestapi/Sellers/Model/Api2/Sellers/Rest/Admin/V1.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_Sellers
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_Sellers_Model_Api2_Sellers_Rest_Admin_V1 extends ContusRestapi_Sellers_Model_Api2_Sellers_Rest {
|
30 |
+
}
|
app/code/local/ContusRestapi/Sellers/Model/Api2/Sellers/Rest/Customer/V1.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_Sellers
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_Sellers_Model_Api2_Sellers_Rest_Customer_V1 extends ContusRestapi_Sellers_Model_Api2_Sellers_Rest {
|
30 |
+
}
|
app/code/local/ContusRestapi/Sellers/Model/Api2/Sellers/Rest/Guest/V1.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_Sellers
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_Sellers_Model_Api2_Sellers_Rest_Guest_V1 extends ContusRestapi_Sellers_Model_Api2_Sellers_Rest {
|
30 |
+
}
|
app/code/local/ContusRestapi/Sellers/etc/api2.xml
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<api2>
|
4 |
+
<resource_groups>
|
5 |
+
<contusRestapi translate="title" module="Sellers">
|
6 |
+
<title>Sellers</title>
|
7 |
+
<sort_order>10</sort_order>
|
8 |
+
</contusRestapi>
|
9 |
+
</resource_groups>
|
10 |
+
<resources>
|
11 |
+
<sellers translate="title" module="Sellers">
|
12 |
+
<group>contusrestapi</group>
|
13 |
+
<model>sellers/api2_sellers</model>
|
14 |
+
<title>Sellers</title>
|
15 |
+
<sort_order>10</sort_order>
|
16 |
+
<privileges>
|
17 |
+
<admin>
|
18 |
+
<create>1</create>
|
19 |
+
<retrieve>1</retrieve>
|
20 |
+
<delete>1</delete>
|
21 |
+
<update>1</update>
|
22 |
+
</admin>
|
23 |
+
<customer>
|
24 |
+
<create>1</create>
|
25 |
+
<retrieve>1</retrieve>
|
26 |
+
<delete>1</delete>
|
27 |
+
<update>1</update>
|
28 |
+
</customer>
|
29 |
+
<guest>
|
30 |
+
<create>1</create>
|
31 |
+
<retrieve>1</retrieve>
|
32 |
+
<delete>1</delete>
|
33 |
+
<update>1</update>
|
34 |
+
</guest>
|
35 |
+
</privileges>
|
36 |
+
<attributes module="api2">
|
37 |
+
<website_id>Website id</website_id>
|
38 |
+
<store_id>Store Id</store_id>
|
39 |
+
<customer_id>customer Id</customer_id>
|
40 |
+
<seller_id>seller Id</seller_id>
|
41 |
+
<ratings>Ratings</ratings>
|
42 |
+
<feedback>Feedback</feedback>
|
43 |
+
<product_id>Product Id</product_id>
|
44 |
+
<result>Result</result>
|
45 |
+
<success>success</success>
|
46 |
+
<message>message</message>
|
47 |
+
<image_size>Imgae Size</image_size>
|
48 |
+
|
49 |
+
</attributes>
|
50 |
+
<routes>
|
51 |
+
<route_collection>
|
52 |
+
<route>/sellers/rating/</route>
|
53 |
+
<action_type>collection</action_type>
|
54 |
+
</route_collection>
|
55 |
+
<!-- Sellers list -->
|
56 |
+
<sellers_collection>
|
57 |
+
<route>/sellers/list/</route>
|
58 |
+
<action_type>collection</action_type> <!-- This will call _retrieveCollection function -->
|
59 |
+
</sellers_collection>
|
60 |
+
|
61 |
+
<!-- Seller profile -->
|
62 |
+
<seller_profile>
|
63 |
+
<route>/sellers/profile/</route>
|
64 |
+
<action_type>entity</action_type>
|
65 |
+
</seller_profile>
|
66 |
+
</routes>
|
67 |
+
<versions>1</versions>
|
68 |
+
</sellers>
|
69 |
+
|
70 |
+
</resources>
|
71 |
+
</api2>
|
72 |
+
</config>
|
app/code/local/ContusRestapi/Sellers/etc/config.xml
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<ContusRestapi_Sellers>
|
5 |
+
<version>0.1.0.0</version>
|
6 |
+
</ContusRestapi_Sellers>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<models>
|
10 |
+
<sellers>
|
11 |
+
<class>ContusRestapi_Sellers_Model</class>
|
12 |
+
</sellers>
|
13 |
+
</models>
|
14 |
+
</global>
|
15 |
+
</config>
|
app/code/local/ContusRestapi/SocialLogin/Model/Api2/SocialLogin.php
CHANGED
@@ -85,7 +85,7 @@ class ContusRestapi_SocialLogin_Model_Api2_SocialLogin extends Mage_Api2_Model_R
|
|
85 |
|
86 |
$response [static::RESULT] = Mage::getModel ( static::LOGIN_TOKEN )->getCustomerDetail ( $customer->getId () );
|
87 |
$response [static::RESULT] ['token'] = $this->getToken ( $customer->getId () );
|
88 |
-
$
|
89 |
// Update device token and type in token table
|
90 |
Mage::getModel ( 'login/methods_functions' )->updateDeviceToken ( $customer->getId (), $deviceToken, $deviceType );
|
91 |
|
@@ -117,7 +117,7 @@ class ContusRestapi_SocialLogin_Model_Api2_SocialLogin extends Mage_Api2_Model_R
|
|
117 |
|
118 |
$response [static::RESULT] = Mage::getModel ( static::LOGIN_TOKEN )->getCustomerDetail ( $customerData [static::ENTITY_ID] );
|
119 |
$response [static::RESULT] ['token'] = $this->getToken ( $customer->getId () );
|
120 |
-
$
|
121 |
// Update device token and type in token table
|
122 |
Mage::getModel ( 'login/methods_functions' )->updateDeviceToken ( $customerData [static::ENTITY_ID], $deviceToken, $deviceType );
|
123 |
|
85 |
|
86 |
$response [static::RESULT] = Mage::getModel ( static::LOGIN_TOKEN )->getCustomerDetail ( $customer->getId () );
|
87 |
$response [static::RESULT] ['token'] = $this->getToken ( $customer->getId () );
|
88 |
+
$response [static::RESULT] ['cart_count'] = Mage::getModel ( static::LOGIN_TOKEN )->getCartCount ( $customer->getId (), $storeId );
|
89 |
// Update device token and type in token table
|
90 |
Mage::getModel ( 'login/methods_functions' )->updateDeviceToken ( $customer->getId (), $deviceToken, $deviceType );
|
91 |
|
117 |
|
118 |
$response [static::RESULT] = Mage::getModel ( static::LOGIN_TOKEN )->getCustomerDetail ( $customerData [static::ENTITY_ID] );
|
119 |
$response [static::RESULT] ['token'] = $this->getToken ( $customer->getId () );
|
120 |
+
$response [static::RESULT] ['cart_count'] = Mage::getModel ( static::LOGIN_TOKEN )->getCartCount ( $customerData [static::ENTITY_ID], $storeId );
|
121 |
// Update device token and type in token table
|
122 |
Mage::getModel ( 'login/methods_functions' )->updateDeviceToken ( $customerData [static::ENTITY_ID], $deviceToken, $deviceType );
|
123 |
|
app/code/local/ContusRestapi/SocialLogin/etc/api2.xml
CHANGED
@@ -47,8 +47,11 @@
|
|
47 |
<success>Success</success>
|
48 |
<message>Message</message>
|
49 |
<error>Error</error>
|
|
|
50 |
<device_token>Device Token</device_token>
|
51 |
<device_type>Device Type</device_type>
|
|
|
|
|
52 |
</attributes>
|
53 |
<routes>
|
54 |
<route_collection>
|
47 |
<success>Success</success>
|
48 |
<message>Message</message>
|
49 |
<error>Error</error>
|
50 |
+
<dob>Date of Birth</dob>
|
51 |
<device_token>Device Token</device_token>
|
52 |
<device_type>Device Type</device_type>
|
53 |
+
<cart_count>Cart count</cart_count>
|
54 |
+
<token>Token</token>
|
55 |
</attributes>
|
56 |
<routes>
|
57 |
<route_collection>
|
app/code/local/ContusRestapi/SplashPage/Model/Api2/SplashPage.php
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_SplashPage
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_SplashPage_Model_Api2_SplashPage extends Mage_Api2_Model_Resource {
|
30 |
+
|
31 |
+
/**
|
32 |
+
* function that is called when post is done **
|
33 |
+
* Home page details
|
34 |
+
*
|
35 |
+
* @param array $data
|
36 |
+
*
|
37 |
+
* @return array json array
|
38 |
+
*/
|
39 |
+
protected function _retrieveCollection() {
|
40 |
+
$response = array ();
|
41 |
+
|
42 |
+
$response ['error'] = false;
|
43 |
+
$response ['success'] = 1;
|
44 |
+
// Get Available cities
|
45 |
+
$response ['result'] = $this->getlist ();
|
46 |
+
return json_encode ( $response );
|
47 |
+
}
|
48 |
+
public function getlist() {
|
49 |
+
$cities = array ();
|
50 |
+
$i = 0;
|
51 |
+
|
52 |
+
$model = Mage::getModel ( 'cities/cities' );
|
53 |
+
$collection = $model->getCollection ();
|
54 |
+
foreach ( $collection as $city ) {
|
55 |
+
// load city module by id
|
56 |
+
$city = $model->load ( $city->getCitiesId () );
|
57 |
+
// get country id
|
58 |
+
$cities [$i] ['country_id'] = $city->getCountryId ();
|
59 |
+
// get country name
|
60 |
+
$country = Mage::getModel ( 'directory/country' )->loadByCode ( $cities [$i] ['country_id'] );
|
61 |
+
$cities [$i] ['country_name'] = $country->getName ();
|
62 |
+
// get state id
|
63 |
+
$cities [$i] ['state_id'] = $city->getRegionId ();
|
64 |
+
// get state name
|
65 |
+
$region = Mage::getModel ( 'directory/region' )->load ( $cities [$i] ['state_id'] );
|
66 |
+
$cities [$i] ['state_name'] = $region->getName ();
|
67 |
+
// get city id
|
68 |
+
$cities [$i] ['city_id'] = $city->getCitiesId ();
|
69 |
+
// get city name
|
70 |
+
$cities [$i] ['city_name'] = $city->getCityName ();
|
71 |
+
|
72 |
+
$i ++;
|
73 |
+
}
|
74 |
+
|
75 |
+
return $cities;
|
76 |
+
}
|
77 |
+
}
|
app/code/local/ContusRestapi/SplashPage/Model/Api2/SplashPage/Rest.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_SplashPage
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_SplashPage_Model_Api2_SplashPage_Rest extends ContusRestapi_SplashPage_Model_Api2_SplashPage {
|
30 |
+
}
|
app/code/local/ContusRestapi/SplashPage/Model/Api2/SplashPage/Rest/Admin/V1.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_SplashPage
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_SplashPage_Model_Api2_SplashPage_Rest_Admin_V1 extends ContusRestapi_SplashPage_Model_Api2_SplashPage_Rest {
|
30 |
+
}
|
app/code/local/ContusRestapi/SplashPage/Model/Api2/SplashPage/Rest/Customer/V1.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_SplashPage
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_SplashPage_Model_Api2_SplashPage_Rest_Customer_V1 extends ContusRestapi_SplashPage_Model_Api2_SplashPage_Rest {
|
30 |
+
}
|
app/code/local/ContusRestapi/SplashPage/Model/Api2/SplashPage/Rest/Guest/V1.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Contus
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the EULA
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://www.apptha.com/LICENSE.txt
|
11 |
+
*
|
12 |
+
* ==============================================================
|
13 |
+
* MAGENTO EDITION USAGE NOTICE
|
14 |
+
* ==============================================================
|
15 |
+
* This package designed for Magento COMMUNITY edition
|
16 |
+
* Apptha does not guarantee correct work of this extension
|
17 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
18 |
+
* Apptha does not provide extension support in case of
|
19 |
+
* incorrect edition usage.
|
20 |
+
* ==============================================================
|
21 |
+
*
|
22 |
+
* @category Contus
|
23 |
+
* @package ContusRestapi_SplashPage
|
24 |
+
* @author Contus Team <developers@contus.in>
|
25 |
+
* @copyright Copyright (c) 2014 Apptha. (http://www.apptha.com)
|
26 |
+
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
class ContusRestapi_SplashPage_Model_Api2_SplashPage_Rest_Guest_V1 extends ContusRestapi_SplashPage_Model_Api2_SplashPage_Rest {
|
30 |
+
}
|
app/code/local/ContusRestapi/SplashPage/etc/api2.xml
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<api2>
|
4 |
+
<resource_groups>
|
5 |
+
<contusRestapi translate="title" module="SplashPage">
|
6 |
+
<title>Splash Page Module</title>
|
7 |
+
<sort_order>10</sort_order>
|
8 |
+
</contusRestapi>
|
9 |
+
</resource_groups>
|
10 |
+
<resources>
|
11 |
+
<splashPage translate="title" module="SplashPage">
|
12 |
+
<group>contusrestapi</group>
|
13 |
+
<model>splashPage/api2_splashPage</model>
|
14 |
+
<title>Splash api</title>
|
15 |
+
<sort_order>10</sort_order>
|
16 |
+
<privileges>
|
17 |
+
<admin>
|
18 |
+
<create>1</create>
|
19 |
+
<retrieve>1</retrieve>
|
20 |
+
<delete>1</delete>
|
21 |
+
</admin>
|
22 |
+
<customer>
|
23 |
+
<create>1</create>
|
24 |
+
<retrieve>1</retrieve>
|
25 |
+
</customer>
|
26 |
+
<guest>
|
27 |
+
<create>1</create>
|
28 |
+
<retrieve>1</retrieve>
|
29 |
+
</guest>
|
30 |
+
</privileges>
|
31 |
+
<attributes module="api2">
|
32 |
+
<website_id>websiteid</website_id>
|
33 |
+
<store_id>Associate to Store</store_id>
|
34 |
+
<results>Results</results>
|
35 |
+
<success>Success</success>
|
36 |
+
<error>Error</error>
|
37 |
+
</attributes>
|
38 |
+
<routes>
|
39 |
+
<route_collection>
|
40 |
+
<route>/splashpage/</route>
|
41 |
+
<action_type>collection</action_type>
|
42 |
+
</route_collection>
|
43 |
+
|
44 |
+
</routes>
|
45 |
+
<versions>1</versions>
|
46 |
+
</splashPage>
|
47 |
+
|
48 |
+
</resources>
|
49 |
+
</api2>
|
50 |
+
</config>
|
app/code/local/ContusRestapi/SplashPage/etc/config.xml
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<ContusRestapi_SplashPage>
|
5 |
+
<version>0.1.0.0</version>
|
6 |
+
</ContusRestapi_SplashPage>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<models>
|
10 |
+
<splashPage>
|
11 |
+
<class>ContusRestapi_SplashPage_Model</class>
|
12 |
+
</splashPage>
|
13 |
+
</models>
|
14 |
+
</global>
|
15 |
+
</config>
|
app/design/adminhtml/default/default/layout/offers.xml
CHANGED
@@ -2,6 +2,12 @@
|
|
2 |
<layout version="0.1.0">
|
3 |
<offers_adminhtml_offers_index>
|
4 |
<reference name="content">
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
<block type="adminhtml/template" template="offers/offers.phtml" />
|
6 |
<block type="offers/adminhtml_offers" name="offers" />
|
7 |
</reference>
|
2 |
<layout version="0.1.0">
|
3 |
<offers_adminhtml_offers_index>
|
4 |
<reference name="content">
|
5 |
+
<block type="adminhtml/store_switcher" name="store_switcher"
|
6 |
+
as="store_switcher">
|
7 |
+
<action method="setUseConfirm">
|
8 |
+
<params>0</params>
|
9 |
+
</action>
|
10 |
+
</block>
|
11 |
<block type="adminhtml/template" template="offers/offers.phtml" />
|
12 |
<block type="offers/adminhtml_offers" name="offers" />
|
13 |
</reference>
|
app/design/adminhtml/default/default/layout/pushnoteproducts.xml
CHANGED
@@ -1,9 +1,15 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<layout version="0.1.0">
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
</layout>
|
1 |
<?xml version="1.0"?>
|
2 |
<layout version="0.1.0">
|
3 |
+
<pushnoteproducts_adminhtml_pushnoteproducts_index>
|
4 |
+
<reference name="content">
|
5 |
+
<block type="adminhtml/store_switcher" name="store_switcher"
|
6 |
+
as="store_switcher">
|
7 |
+
<action method="setUseConfirm">
|
8 |
+
<params>0</params>
|
9 |
+
</action>
|
10 |
+
</block>
|
11 |
+
<block type="adminhtml/template" template="pushnoteproducts/pushnoteproducts.phtml" />
|
12 |
+
<block type="pushnoteproducts/adminhtml_pushnoteproducts" name="pushnoteproducts" />
|
13 |
+
</reference>
|
14 |
+
</pushnoteproducts_adminhtml_pushnoteproducts_index>
|
15 |
</layout>
|
app/design/adminhtml/default/default/template/pushnoteproducts/pushnoteproducts.phtml
CHANGED
@@ -25,6 +25,37 @@
|
|
25 |
*/
|
26 |
?>
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
<?php
|
29 |
/* Added simplemodal js for showing iframe code in a pop-up - contus groupclone manage deals grid */
|
30 |
$mainjsUrl = Mage::getBaseUrl ( Mage_Core_Model_Store::URL_TYPE_JS ) . 'iframe/jquery-2.1.1.min.js';
|
@@ -47,7 +78,9 @@ $baseUrl = Mage::getBaseUrl ();
|
|
47 |
method="post">
|
48 |
<label>Enter your message to push</label> <span class="required">*</span><br />
|
49 |
<textarea rows="5" cols="10" id="product_name" name="product_name"></textarea>
|
50 |
-
<input type="hidden" id="product_id" name="product_id"></input>
|
|
|
|
|
51 |
name="form_key" type="hidden"
|
52 |
value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
|
53 |
<button type="submit" onclick="productMsgValidation()">Push</button>
|
@@ -62,6 +95,10 @@ jQuery(document).ready(function(){
|
|
62 |
|
63 |
jQuery(".PushnoteProducts").click(function(){
|
64 |
|
|
|
|
|
|
|
|
|
65 |
var inputIframe = jQuery(this).attr("id");
|
66 |
var inputName = jQuery(this).attr("name");
|
67 |
jQuery("#product_name").val(inputName);
|
25 |
*/
|
26 |
?>
|
27 |
|
28 |
+
<!--
|
29 |
+
<p class="switcher">
|
30 |
+
<label for="store_switcher">Choose Store View:</label>
|
31 |
+
<select name="store_switcher" id="store_switcher">
|
32 |
+
<option value="0">All Store Views</option>
|
33 |
+
<?php
|
34 |
+
foreach ( Mage::app ()->getWebsites () as $website ) { ?>
|
35 |
+
<optgroup label=<?php echo $website->getName();?>></optgroup>
|
36 |
+
<?php
|
37 |
+
foreach ( $website->getGroups () as $group ) { ?>
|
38 |
+
<optgroup label=" "<?php echo $group->getName();?>>
|
39 |
+
<?php
|
40 |
+
$stores = $group->getStores ();
|
41 |
+
foreach ( $stores as $store ) {?>
|
42 |
+
<option value=<?php echo $store->getId ()?>> <?php echo $store->getName ()?>
|
43 |
+
</option>
|
44 |
+
<?php }?>
|
45 |
+
</optgroup>
|
46 |
+
|
47 |
+
<?php }
|
48 |
+
}
|
49 |
+
?>
|
50 |
+
|
51 |
+
</select>
|
52 |
+
|
53 |
+
</p>
|
54 |
+
-->
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
<?php echo $this->getChildHtml('store_switcher');?>
|
59 |
<?php
|
60 |
/* Added simplemodal js for showing iframe code in a pop-up - contus groupclone manage deals grid */
|
61 |
$mainjsUrl = Mage::getBaseUrl ( Mage_Core_Model_Store::URL_TYPE_JS ) . 'iframe/jquery-2.1.1.min.js';
|
78 |
method="post">
|
79 |
<label>Enter your message to push</label> <span class="required">*</span><br />
|
80 |
<textarea rows="5" cols="10" id="product_name" name="product_name"></textarea>
|
81 |
+
<input type="hidden" id="product_id" name="product_id"></input>
|
82 |
+
<input type="hidden" id="store_id" name="store_id"></input>
|
83 |
+
<input
|
84 |
name="form_key" type="hidden"
|
85 |
value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
|
86 |
<button type="submit" onclick="productMsgValidation()">Push</button>
|
95 |
|
96 |
jQuery(".PushnoteProducts").click(function(){
|
97 |
|
98 |
+
var store_switcher = document.getElementById("store_switcher");
|
99 |
+
var store_id = store_switcher.options[store_switcher.selectedIndex].value;
|
100 |
+
jQuery("#store_id").val(store_id);
|
101 |
+
// alert(store_id);
|
102 |
var inputIframe = jQuery(this).attr("id");
|
103 |
var inputName = jQuery(this).attr("name");
|
104 |
jQuery("#product_name").val(inputName);
|
app/etc/modules/ContusRestapi_Contactus.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<ContusRestapi_Contactus>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>local</codePool>
|
7 |
+
</ContusRestapi_Contactus>
|
8 |
+
</modules>
|
9 |
+
</config>
|
app/etc/modules/ContusRestapi_Sellers.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<ContusRestapi_Sellers>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>local</codePool>
|
7 |
+
</ContusRestapi_Sellers>
|
8 |
+
</modules>
|
9 |
+
</config>
|
app/etc/modules/ContusRestapi_Splashpage.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<ContusRestapi_SplashPage>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>local</codePool>
|
7 |
+
</ContusRestapi_SplashPage>
|
8 |
+
</modules>
|
9 |
+
</config>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Contus_Mcomm</name>
|
4 |
-
<version>1.0.
|
5 |
<stability>stable</stability>
|
6 |
<license>OSL v3.0</license>
|
7 |
<channel>community</channel>
|
@@ -11,9 +11,9 @@
|
|
11 |
<notes>Contus M-Comm, a ready to go solution to build native Magento mobile apps for your store across all devices.
|
12 |
</notes>
|
13 |
<authors><author><name>contus</name><user>contus</user><email>developers@contus.in</email></author></authors>
|
14 |
-
<date>2015-
|
15 |
-
<time>
|
16 |
-
<contents><target name="mageetc"><dir><dir name="modules"><file name="Contus_Offers.xml" hash="9eb0553e491ea8d5e446e7cc558cb58b"/><file name="Contus_Configuration.xml" hash="41fb04ff499bda81e9bfc3464312de5c"/><file name="Contus_Pushnoteorders.xml" hash="04990a32246dce9b672de674213ebee5"/><file name="Contus_Pushnoteproducts.xml" hash="148b2b106ef411de65569bccdccc30f0"/><file name="ContusRestapi_AddressBook.xml" hash="fda5174d2aea353c844a42f27ab989eb"/><file name="ContusRestapi_ApplyCoupon.xml" hash="633db3d6edd00c396c99296a6fdd4902"/><file name="ContusRestapi_CartAddressapi.xml" hash="dd8f64f45e6575a833431905619604f5"/><file name="ContusRestapi_Cartapi.xml" hash="30793aaf7eda767f1bb667c58d2f68a6"/><file name="ContusRestapi_Filters.xml" hash="1450296e437b3112f007896af955f424"/><file name="ContusRestapi_HomePageapi.xml" hash="08814a3f0c9d073f1bea7895e89bc059"/><file name="ContusRestapi_Login.xml" hash="f77221543e7ff841c3706a99b73e937c"/><file name="ContusRestapi_MultiCartapi.xml" hash="85d05924d95011d58daae2114992483e"/><file name="ContusRestapi_MyOrders.xml" hash="49e029267031a0aa61b7c09e1155bf58"/><file name="ContusRestapi_PlaceOrder.xml" hash="4e60174c9499436682c8103e112ec561"/><file name="ContusRestapi_ProductList.xml" hash="7d7f8d3f63417ad73ba0e663c37727b7"/><file name="ContusRestapi_Registration.xml" hash="76dd1182003a33b4982b156d80cf1a1b"/><file name="ContusRestapi_ReviewRating.xml" hash="d864b7d755f0a68d530a0d18d34ccd4e"/><file name="ContusRestapi_SearchProducts.xml" hash="391b8900fa5d0024011c2c1e6764b78f"/><file name="ContusRestapi_ShippingPaymentapi.xml" hash="a24e1c097d56936819b5c385b7313570"/><file name="ContusRestapi_SocialLogin.xml" hash="8812ff2f9805cbafd3dfa9b3ae74bc43"/><file name="ContusRestapi_Staticpages.xml" hash="233c3a726f75fe559fc890000ab889ba"/><file name="ContusRestapi_Wishlistapi.xml" hash="bb680accc2edf350336d681d1c7ca965"/></dir></dir></target><target name="magedesign"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="offers.xml" hash="00e36ce786fea57557de25e315ff4d44"/><file name="pushnoteproducts.xml" hash="06eee4ed043285524d70f14fb8f5190b"/><file name="pushnoteorders.xml" hash="baa5ec7f3079699b0eb340d95586016a"/></dir><dir name="template"><dir name="offers"><file name="offers.phtml" hash="39e48356b3706eb29221763b1b82c55e"/></dir><dir name="pushnoteproducts"><file name="pushnoteproducts.phtml" hash="a2dbc8159d3c97b7cb2832d3a1670c12"/></dir><dir name="pushnoteorders"><file name="pushnoteorders.phtml" hash="4673989e2102012fb24230873b99656c"/></dir></dir></dir></dir></dir></dir></target><target name="mageskin"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><file name="popup.css" hash="8cc8c3a5113d76b51ec13ade4fc41afb"/></dir></dir></dir></dir></target><target name="mage"><dir><dir name="js"><dir name="iframe"><file name="jquery-2.1.1.min.js" hash="49fffe009bd5abd3db052a50537dcbe3"/><file name="jquery.simplemodal.js" hash="b33a4bd97176d530ba43a6659daaa748"/></dir></dir><dir name="contus"><file name="Mcom_development.pem" hash="21cec017e04e0b229b9349138ed939c3"/><file name="Mcom_production.pem" hash="8e3131c3eca71a6996c346b6b1144b21"/><dir><dir name="image"><file name="splash_logo.png" hash="8ca437906154fe6b0e854764fe4991b3"/></dir></dir></dir><dir name="paypal"><file name="PaymentGateway.php" hash="276078578ddf722db13f0409e955255d"/><file name="Paypal.php" hash="ac313df2943a8424b5235d1f7d75ca39"/><file name="cancel.php" hash="d9f87387c5b8e1e9e1ad95cc661acd21"/><file name="ipn.php" hash="782cc7a4b7b8b9e53d057d2780e40285"/><file name="ipnlistener.php" hash="1f9b96d748b21dc333d5235804086981"/><file name="redirect.php" hash="950ebf702848fe0609d9bb4a3ce6f391"/><file name="success.php" hash="8d662cbefd8081db70b40444d24aa668"/></dir><dir name="rest"><file name="Rest.inc.php" hash="db6e2cdc43f08a964b1d7de82f7b5ba3"/><file name="api.php" hash="5bd85348f04269fbdd050a3c7a13d81c"/><file name=".htaccess" hash="0a6a1af3eba87f4e9dd820b01c38e766"/></dir></dir></target><target name="magelocal"><dir><dir name="ContusRestapi"><dir><dir name="AddressBook"><dir name="Model"><dir name="Api2"><dir name="AddressBook"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="fa87ce51335210432b63ee767704f48c"/></dir><dir name="Customer"><file name="V1.php" hash="ec4d710ae329f358c3eb2d902a89a853"/></dir><dir name="Guest"><file name="V1.php" hash="a8039455bfcd23ed607fa667ae7bb1c7"/></dir></dir><file name="Rest.php" hash="30e3ee96d4611f0bd792d1b10ba348d1"/></dir><file name="AddressBookapi.php" hash="3f374bbf1fb1c7577367c2477cb6f93e"/><dir name="Country"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="2c8ccecc9a2f4fdb1ca891a58df12b2e"/></dir><dir name="Customer"><file name="V1.php" hash="323672cd9e310ca58941cba073f05c23"/></dir><dir name="Guest"><file name="V1.php" hash="31056c51f9316006ddb8468c510f5f90"/></dir></dir><file name="Rest.php" hash="d3f8dd6b9172a5b3523734c18ebad887"/></dir><file name="Country.php" hash="386046a292f3089d641c23fbc13d4d03"/><dir name="State"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="069dfc1cf9158f73ad1c5803eeb1413b"/></dir><dir name="Guest"><file name="V1.php" hash="816582cd3557fe11890beadb49fb858b"/></dir></dir><file name="Rest.php" hash="b4794c183f5103bcf5e570b6777c2959"/></dir><file name="State.php" hash="973f8e8e696d4fc3751826592ad3fb06"/></dir></dir><dir name="etc"><file name="api2.xml" hash="b7a8262be03ca5c517a8b692abf84e7d"/><file name="config.xml" hash="92a63d6bdce25d58fdcad08722deb3dd"/></dir></dir><dir name="ApplyCoupon"><dir name="Model"><dir name="Api2"><dir name="ApplyCoupon"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="1a577bc661a83ee1b77cfb97367d113c"/></dir><dir name="Customer"><file name="V1.php" hash="736dc803ee29515ad32ff00afe155e46"/></dir><dir name="Guest"><file name="V1.php" hash="605595e312d8b8941e8b55a04c795f7b"/></dir></dir><file name="Rest.php" hash="0e679cf5405ac8e3b216d49cae52a67f"/></dir><file name="ApplyCouponapi.php" hash="47d9eb575987325609fd89a1b11a8b21"/></dir></dir><dir name="etc"><file name="api2.xml" hash="b7f6afd002743deab122af594a24eeb9"/><file name="config.xml" hash="d1ce73f4eeb36c9e0d2204785ddef5f3"/></dir></dir><dir name="CartAddressapi"><dir name="Model"><dir name="Api2"><dir name="CartAddressapi"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="800148a390660be0e966dab0f3f1a3b3"/></dir><dir name="Customer"><file name="V1.php" hash="c4540f56b75ca665a8771194e5b108de"/></dir><dir name="Guest"><file name="V1.php" hash="d4f6627ea61a7e3de9762e2a5730f21f"/></dir></dir><file name="Rest.php" hash="6069a2f769245b78398adc93bf01cd4e"/></dir><file name="CartAddressapi.php" hash="ff302469c5365a8f0aede220e4e4179a"/></dir></dir><dir name="etc"><file name="api2.xml" hash="d1ceb1780f9428cd2617faacce4113c2"/><file name="config.xml" hash="85b2ea62c85b6a52bf1326e7ea2e80d2"/></dir></dir><dir name="Cartapi"><dir name="Model"><dir name="Api2"><dir name="Cartapi"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="e9b2780fc6717cf4c8cd70a0996da952"/></dir><dir name="Customer"><file name="V1.php" hash="e9e27542054b1050eff94b8e24dc81f7"/></dir><dir name="Guest"><file name="V1.php" hash="e0df6d95bdca4ac73c162c72dccd3157"/></dir></dir><file name="Rest.php" hash="11089e228f3a08342bc294a55ec2a0d5"/></dir><file name="Cartapi.php" hash="79ce0dd04d329c2583d9c7f787d9b7f7"/></dir></dir><dir name="etc"><file name="api2.xml" hash="2dbf3da500930f58108bf9a9f87ec75f"/><file name="config.xml" hash="6dce6326329b06cc349316fdc7f1e8a1"/></dir></dir><dir name="Filters"><dir name="Model"><dir name="Api2"><dir name="Filters"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="9c86175283d31ad4991d3e22561c1a29"/></dir><dir name="Customer"><file name="V1.php" hash="63ae714a9128ae75fe4f0dc62f0f8212"/></dir><dir name="Guest"><file name="V1.php" hash="b04bd01daf25c8f0303fbee0601a55bc"/></dir></dir><file name="Rest.php" hash="705aadf18a53896bbb2cfce41a1b8102"/></dir><file name="Filters.php" hash="6c62d6da5fdddbcf7672c2260eb43636"/></dir></dir><dir name="etc"><file name="api2.xml" hash="c56047774d688915d3992226d395131d"/><file name="config.xml" hash="3c9507f5ba31aaf209c268557e9339b0"/></dir></dir><dir name="HomePageapi"><dir name="Model"><dir name="Api2"><dir name="HomePageapi"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="5eb5a39d75920703ef26975183a5f81d"/></dir><dir name="Customer"><file name="V1.php" hash="06e96d56de1c93c933a5c1865b0e43e7"/></dir><dir name="Guest"><file name="V1.php" hash="b76cf62bf759c748858ac11213e2d95d"/></dir></dir><file name="Rest.php" hash="764dc0c42c07a4fd35beef9159721a25"/></dir><file name="HomePageapi.php" hash="3599888ab1ba72ea10bee0793264b0fc"/></dir></dir><dir name="etc"><file name="api2.xml" hash="a7d1833752e198041c6bcb9ceac2c35f"/><file name="config.xml" hash="987e0202a5cf8d5650b2d1004277be2d"/></dir></dir><dir name="Login"><dir name="Model"><dir name="Api2"><dir name="Forgotpassword"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="ed7ecb2d101124a3af996aa68ad4ae14"/></dir><dir name="Customer"><file name="V1.php" hash="1d9dde0cbb555ed9b2763265712e16f1"/></dir><dir name="Guest"><file name="V1.php" hash="b4f685ad6006e34e7761e8db39a1601e"/></dir></dir><file name="Rest.php" hash="b80db9b5f7f413bfa636d7f4da708e12"/></dir><file name="Forgotpassword.php" hash="ac9512f4102bdeb1314cdad651a02ea6"/><dir name="Login"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="e3fb6be3b3fe28194e227ec57ad5a186"/></dir><dir name="Customer"><file name="V1.php" hash="0ed601b8c568805da9312b97615d73a3"/></dir><dir name="Guest"><file name="V1.php" hash="d9631834e143659f579642fb671efa9d"/></dir></dir><file name="Rest.php" hash="79ffc7815aa51db77b342d01c0badfd4"/></dir><file name="Login.php" hash="d5efc4d011def0681330cea3741f446c"/></dir><dir name="Methods"><file name="Functions.php" hash="2dcaeddd01dc131660c2877745d571dd"/></dir><dir name="Resource"><dir name="Token"><file name="Collection.php" hash="d23102f756323dc0fcf56e725ad3affb"/></dir><file name="Token.php" hash="ed7ceb24bc163901207ed31106aa608c"/></dir><file name="Token.php" hash="9ff569b68c7fe3891a8a0e3021e2b82a"/></dir><dir name="etc"><file name="api2.xml" hash="6046abc7493543066b1d1fa824de0c5a"/><file name="config.xml" hash="3742f5c20e70c0bec8f659843d192df7"/></dir><dir name="sql"><dir name="login_setup"><file name="install-0.0.1.php" hash="c63d2093807a82d58ff96f7ff5a619a5"/></dir></dir></dir><dir name="MultiCartapi"><dir name="Model"><dir name="Api2"><dir name="MultiCartapi"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="bdae2062576a265a2dbb4a6e5c54ee2c"/></dir><dir name="Customer"><file name="V1.php" hash="ba637aedc8caa447f09847f6ff5b10bf"/></dir><dir name="Guest"><file name="V1.php" hash="324c03fcfc448472977123bd1875276a"/></dir></dir><file name="Rest.php" hash="90acb34b0dba704008a4baed584836f7"/></dir><file name="MultiCartapi.php" hash="77ddaaa100fa0f9861a5442cc4de392c"/></dir></dir><dir name="etc"><file name="api2.xml" hash="f7667c6f9f9123e908b304aaa5c83bf2"/><file name="config.xml" hash="661ba9f4224bd74555c5526f7c41154e"/></dir></dir><dir name="MyOrders"><dir name="Model"><dir name="Api2"><dir name="MyOrderapi"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="82927b08ae221b6277cdefdb21554f89"/></dir><dir name="Customer"><file name="V1.php" hash="d75f8b2801775a0401f1ec865b09a62f"/></dir><dir name="Guest"><file name="V1.php" hash="0f9a5558397ee4c5abe68c127cc65ba6"/></dir></dir><file name="Rest.php" hash="4be3db78f9081383ad2385b22d194405"/></dir><file name="MyOrderapi.php" hash="dd44b7d0b903e748b17a309a427cdd1b"/></dir></dir><dir name="etc"><file name="api2.xml" hash="87ef0d8a9ce4889870e10191a660884e"/><file name="config.xml" hash="9d884c040632d7c1ba6b3eb7258038f0"/></dir></dir><dir name="PlaceOrder"><dir name="Model"><dir name="Api2"><dir name="PlaceOrderapi"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="c124d62195ea7a653e7579f3dd96e2b6"/></dir><dir name="Customer"><file name="V1.php" hash="71c496a9ef5230f14f3f9777b990ab19"/></dir><dir name="Guest"><file name="V1.php" hash="b7b69c391c4784f0ac353574325fba0d"/></dir></dir><file name="Rest.php" hash="7636ec8af040e665b1553031dba50f98"/></dir><file name="PlaceOrderapi.php" hash="2b1ee9d65d9fc0813b456c3a9b8b5a74"/></dir></dir><dir name="etc"><file name="api2.xml" hash="6f5ca0ce6abe55c93604f6aada67e96d"/><file name="config.xml" hash="c072fca46b706bdaa1070c1b7cfd4112"/></dir></dir><dir name="ProductList"><dir name="Model"><dir name="Api2"><dir name="ProductList"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="0a49f28a84be01e71d9c1644d95b4c2b"/></dir><dir name="Guest"><file name="V1.php" hash="729240a7ec2eeff1a39a8061345edd56"/></dir></dir><file name="Rest.php" hash="0952e8c10b0815bc13e2fdd51b1fbc3e"/></dir></dir></dir><dir name="etc"><file name="api2.xml" hash="88f6f2efd8285e34f641c3908481b0c0"/><file name="config.xml" hash="b2fef8859874c5505007f85733103c86"/></dir></dir><dir name="Registration"><dir name="Model"><dir name="Api2"><dir name="ChangePassword"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="04b3985e11a37c6f80310366d7276d4d"/></dir><dir name="Customer"><file name="V1.php" hash="df47bcb511a2c12deadfd444d1adc383"/></dir><dir name="Guest"><file name="V1.php" hash="87e0a4ff0c254135b83c810bdbd979c2"/></dir></dir><file name="Rest.php" hash="755ef8a11d74f0fca457115cd3801f6e"/></dir><dir name="Registration"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="2d960ebf6a581b3fd4ba29892f553d52"/></dir><dir name="Customer"><file name="V1.php" hash="6d81dde797e56696c5af656244dcac8b"/></dir><dir name="Guest"><file name="V1.php" hash="5d6bc426abc5c0b19c0668ccbfd3c021"/></dir></dir><file name="Rest.php" hash="c53396e643e5c25b20922b4d335bb57e"/></dir></dir></dir><dir name="etc"><file name="api2.xml" hash="67f9baac0ce159bf71f4b2f2a3566428"/><file name="config.xml" hash="3803604868540ff96f6ffdb3c7c09278"/></dir></dir><dir name="ReviewRating"><dir name="Model"><dir name="Api2"><dir name="ReviewRating"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="0b4dee4df40cebce802c92a56626d5ca"/></dir><dir name="Customer"><file name="V1.php" hash="0806b569367c814c269be3015781d65c"/></dir><dir name="Guest"><file name="V1.php" hash="57a1fa55ee5b2dba5d6d44afa7b432ec"/></dir></dir><file name="Rest.php" hash="e5812d28743261a30c30513b3b1c8d3b"/></dir><file name="ReviewRating.php" hash="fc9de1f5a5a587a2d715caf0cde60635"/></dir></dir><dir name="etc"><file name="api2.xml" hash="84d901a3715fd3c28f4214ecd4a69b42"/><file name="config.xml" hash="093a59ea31a58cb0f1ff118d86583179"/></dir></dir><dir name="SearchProducts"><dir name="Model"><dir name="Api2"><dir name="SearchProducts"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="ebe95d66e8935f824d50f10145d50a3a"/></dir><dir name="Customer"><file name="V1.php" hash="6549897f48909896ceb6f17d2544fc98"/></dir><dir name="Guest"><file name="V1.php" hash="0c333730ee604f6d9418e5452b80ad47"/></dir></dir><file name="Rest.php" hash="6b00435029dc3040d4d45717a7eaa36a"/></dir><file name="SearchProducts.php" hash="fb96c1cf81500bb23af8fd51b7a6f4f3"/></dir></dir><dir name="etc"><file name="api2.xml" hash="4e72d3f00586fea385ac425e7afc5a65"/><file name="config.xml" hash="08c2950ca36e9f719ea10a8e66b4ef36"/></dir></dir><dir name="ShippingPaymentapi"><dir name="Model"><dir name="Api2"><dir name="ShippingPaymentapi"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="a6e310b9e522eb2cba1ddca9bb01adbd"/></dir><dir name="Customer"><file name="V1.php" hash="c9b52a26bf774691a94459979d7981be"/></dir><dir name="Guest"><file name="V1.php" hash="d40b5e9c42b366e901eed11ef2bf2b50"/></dir></dir><file name="Rest.php" hash="e8ce41c58deeebaa87832c6d090594fa"/></dir><file name="ShippingPaymentapi.php" hash="6a55c62967503d7479dcd1534c26ea98"/></dir></dir><dir name="etc"><file name="api2.xml" hash="fcff0dcff1662fbc5b69d535d3865b93"/><file name="config.xml" hash="f449893d3b9ce99743f4f9df88957eee"/></dir></dir><dir name="SocialLogin"><dir name="Model"><dir name="Api2"><dir name="SocialLogin"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="504f5dacd99ab70df5fc0b977b3b1e9d"/></dir><dir name="Customer"><file name="V1.php" hash="0ed3fd7da081ddf3db38280a449df107"/></dir><dir name="Guest"><file name="V1.php" hash="a078c51f0a28754ef44ed49f22d45934"/></dir></dir><file name="Rest.php" hash="debf62f88f8eea1477ccdf7263e05839"/></dir><file name="SocialLogin.php" hash="dd17e5ddd2b8bfab2f122665a6f252bd"/></dir></dir><dir name="etc"><file name="api2.xml" hash="1ec20f146ee828ad924a8b5915186481"/><file name="config.xml" hash="bcc1a1ee0b876f6fcfa1e70533278dfc"/></dir></dir><dir name="Staticpages"><dir name="Model"><dir name="Api2"><dir name="Staticpages"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="daf94348a90bf00576d13f2395f44373"/></dir><dir name="Customer"><file name="V1.php" hash="e4345e55df3beb22a24b7a06bd0a7e60"/></dir><dir name="Guest"><file name="V1.php" hash="8d6f72cf5db3a3fe5def87cd9945e168"/></dir></dir><file name="Rest.php" hash="2d9e3ce4db5ebd695a36405918c54902"/></dir><file name="Staticpages.php" hash="a5a11a73b2941d15d7e8ca35d26984fc"/></dir></dir><dir name="etc"><file name="api2.xml" hash="a2a52f764e9020a4ae039ae0179609a7"/><file name="config.xml" hash="28491ccf1cfca21dadf91257cfbbbed4"/></dir></dir><dir name="Wishlistapi"><dir name="Model"><dir name="Api2"><dir name="Wishlist"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="f651beba4be1bc71ca9f67d8cb10cab3"/></dir><dir name="Customer"><file name="V1.php" hash="562cfde7040cfed53b787b0eab9e2a22"/></dir><dir name="Guest"><file name="V1.php" hash="851ad054c968702c9867cbe40570c434"/></dir></dir><file name="Rest.php" hash="53ee075545cb61fd4f24d5b83a03306f"/></dir><file name="Wishlist.php" hash="7fa68433ba0334c40fecb2893c557f46"/></dir></dir><dir name="etc"><file name="api2.xml" hash="77537ed8a65c37ade93c8eb13085e1b5"/><file name="config.xml" hash="d57983e6481f0bf170e8855ce56b673c"/></dir></dir></dir></dir><dir name="Contus"><dir name="Configuration"><dir><dir name="Block"><dir name="Adminhtml"><file name="About.php" hash="481fb6808dc558341b193c23139a2696"/></dir></dir><dir name="Helper"><file name="Data.php" hash="589c315c38ae37d76bb93b644d27738f"/></dir><dir name="Model"><dir name="Adminhtml"><file name="Count.php" hash="01b7f7216f1a0ebc0997ba3f753296a0"/><file name="Homelist.php" hash="44d04a9f483e83d6273ed45694451630"/></dir><file name="Config.php" hash="9711c2896ebd37631855d03a4c5466f2"/></dir><dir name="etc"><file name="adminhtml.xml" hash="2ab511bfbb24399f66f92c5e129e93ed"/><file name="config.xml" hash="868cc56a8ba9fae0d4b5ca0ee3ea74e5"/><file name="system.xml" hash="c688db0d103e81e1cc8a0fb58b49f147"/></dir></dir></dir><dir name="Offers"><dir><dir name="Block"><dir name="Adminhtml"><dir name="Offers"><dir name="Edit"><file name="Form.php" hash="ecc572cb365ef62b9658d0c7f67721f5"/><dir name="Tab"><file name="Form.php" hash="63e0168a8d5e7098bd8bac54dee15e96"/><file name="Productlist.php" hash="7aba8bae660fef8b16d37ecea0343a13"/></dir><file name="Tabs.php" hash="a357a8b708ab7c96f1f5200f7828f03f"/></dir><file name="Edit.php" hash="f3e49391b8b03a845b37cda0dcd8c616"/><file name="Grid.php" hash="e724024aea678311111d801b94696998"/><dir name="Renderer"><file name="Image.php" hash="cc37093e5c80cef280088d58c82b6470"/><file name="Notification.php" hash="c727f9a4fc45748c1c5bb53be3f78f06"/><file name="View.php" hash="a818c7e6c82efb3852e85cfc01103109"/></dir></dir><file name="Offers.php" hash="9a2d5c00bb5cfaf04fae9b0e1bf37813"/></dir><file name="Offers.php" hash="24ad7397a1a83adccfa81ab1b86546c4"/></dir><dir name="Helper"><file name="Data.php" hash="3400397d268933f11bb5f6b5ad745eaf"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Offers"><file name="Collection.php" hash="0b45658ccbd52447163e50a73bda2fdb"/></dir><file name="Offers.php" hash="a9cb9633c24d9e9283298fe865fbd926"/></dir><file name="Offers.php" hash="6178200d641970fc870d0c1869dfbcac"/><file name="Status.php" hash="74f9c981477bc89ec5cf8902c6a829d1"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="OffersController.php" hash="d55933d6fa8a9bb7dab6078c01353db2"/></dir><file name="IndexController.php" hash="8ad61469cb056026c9450c550063d7ce"/></dir><dir name="etc"><file name="adminhtml.xml" hash="a66266c8ea8f62aaea031291382eb000"/><file name="config.xml" hash="177be990abafa805f035ba2169db3a56"/></dir><dir name="sql"><dir name="offers_setup"><file name="mysql4-install-0.1.0.php" hash="9981e09f5acaafe1906875cdfb7b9258"/></dir></dir></dir></dir><dir name="Pushnoteorders"><dir><dir name="Block"><dir name="Adminhtml"><dir name="Pushnoteorders"><file name="Edit.php" hash="1bddef98ed3cbb6c2257082c815dec1a"/><file name="Grid.php" hash="d8fc00d43a5187f3af89da63f9e404b6"/><dir name="Renderer"><file name="Notification.php" hash="79f97835ef176565e47ad19ada958e22"/><file name="View.php" hash="12034fa2c7178b6fe898d60b46fcb61f"/></dir></dir><file name="Pushnoteorders.php" hash="a7c1a0a2e5f5b39d8e5c781e508f9f56"/></dir><file name="Pushnoteorders.php" hash="0b16da26a98412686c1b9a4f762f1285"/></dir><dir name="Helper"><file name="Data.php" hash="e731245220b7b38db9f0fd31a40ae39e"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="PushnoteordersController.php" hash="4ffeb67950d98498615412d31414c450"/></dir><file name="IndexController.php" hash="a36f49a983432759ba209b2d0b335bd6"/></dir><dir name="etc"><file name="adminhtml.xml" hash="1ae517a1e0c037dfb43a50a9917e7c97"/><file name="config.xml" hash="fb2714db776c5a1021eb440317828d92"/></dir></dir></dir><dir name="Pushnoteproducts"><dir><dir name="Block"><dir name="Adminhtml"><dir name="Pushnoteproducts"><file name="Edit.php" hash="cdf5a1dcbce0ad048faa1e9a33a8cdc9"/><file name="Grid.php" hash="ecf2f79fb04c2df52b99849b64244a07"/><dir name="Renderer"><file name="Notification.php" hash="7dbf8c30708cfa1d15a9cf941dfe0d97"/><file name="View.php" hash="f5cc64c42c5caf364921d51177f865d2"/></dir></dir><file name="Pushnoteproducts.php" hash="eb399595756eb635c1390ae985d2fb1d"/></dir><file name="Pushnoteproducts.php" hash="b9d833bc77da69e92098e3d9dadaddff"/></dir><dir name="Helper"><file name="Data.php" hash="8ffd99731b3d4a5dd12fa062f6b1db16"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="PushnoteproductsController.php" hash="51b598caaecce3fe928d80e8364f2328"/></dir><file name="IndexController.php" hash="3cf009c3f2125552591c0c0558018297"/></dir><dir name="etc"><file name="config.xml" hash="384b48e0d97d58aad7bc4268aadee828"/></dir></dir></dir></dir></dir></target></contents>
|
17 |
<compatible/>
|
18 |
-
<dependencies><required><php><min>5.
|
19 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Contus_Mcomm</name>
|
4 |
+
<version>1.0.1</version>
|
5 |
<stability>stable</stability>
|
6 |
<license>OSL v3.0</license>
|
7 |
<channel>community</channel>
|
11 |
<notes>Contus M-Comm, a ready to go solution to build native Magento mobile apps for your store across all devices.
|
12 |
</notes>
|
13 |
<authors><author><name>contus</name><user>contus</user><email>developers@contus.in</email></author></authors>
|
14 |
+
<date>2015-11-03</date>
|
15 |
+
<time>06:29:24</time>
|
16 |
+
<contents><target name="mageetc"><dir><dir name="modules"><file name="Contus_Offers.xml" hash="9eb0553e491ea8d5e446e7cc558cb58b"/><file name="Contus_Configuration.xml" hash="41fb04ff499bda81e9bfc3464312de5c"/><file name="Contus_Pushnoteorders.xml" hash="04990a32246dce9b672de674213ebee5"/><file name="Contus_Pushnoteproducts.xml" hash="148b2b106ef411de65569bccdccc30f0"/><file name="ContusRestapi_AddressBook.xml" hash="fda5174d2aea353c844a42f27ab989eb"/><file name="ContusRestapi_ApplyCoupon.xml" hash="633db3d6edd00c396c99296a6fdd4902"/><file name="ContusRestapi_CartAddressapi.xml" hash="dd8f64f45e6575a833431905619604f5"/><file name="ContusRestapi_Cartapi.xml" hash="30793aaf7eda767f1bb667c58d2f68a6"/><file name="ContusRestapi_Filters.xml" hash="1450296e437b3112f007896af955f424"/><file name="ContusRestapi_HomePageapi.xml" hash="08814a3f0c9d073f1bea7895e89bc059"/><file name="ContusRestapi_Login.xml" hash="f77221543e7ff841c3706a99b73e937c"/><file name="ContusRestapi_MultiCartapi.xml" hash="85d05924d95011d58daae2114992483e"/><file name="ContusRestapi_MyOrders.xml" hash="49e029267031a0aa61b7c09e1155bf58"/><file name="ContusRestapi_PlaceOrder.xml" hash="4e60174c9499436682c8103e112ec561"/><file name="ContusRestapi_ProductList.xml" hash="7d7f8d3f63417ad73ba0e663c37727b7"/><file name="ContusRestapi_Registration.xml" hash="76dd1182003a33b4982b156d80cf1a1b"/><file name="ContusRestapi_ReviewRating.xml" hash="d864b7d755f0a68d530a0d18d34ccd4e"/><file name="ContusRestapi_SearchProducts.xml" hash="391b8900fa5d0024011c2c1e6764b78f"/><file name="ContusRestapi_ShippingPaymentapi.xml" hash="a24e1c097d56936819b5c385b7313570"/><file name="ContusRestapi_SocialLogin.xml" hash="8812ff2f9805cbafd3dfa9b3ae74bc43"/><file name="ContusRestapi_Staticpages.xml" hash="233c3a726f75fe559fc890000ab889ba"/><file name="ContusRestapi_Wishlistapi.xml" hash="bb680accc2edf350336d681d1c7ca965"/><file name="ContusRestapi_Sellers.xml" hash="63dfcfe6f63d8f8ff0d49e085bfd0977"/><file name="ContusRestapi_Splashpage.xml" hash="e447d6be8c8983cbc18470d3d315116c"/><file name="ContusRestapi_Contactus.xml" hash="1a6a729e29ab9c15f7104d186d1be059"/></dir></dir></target><target name="magedesign"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="offers.xml" hash="1e8a43b7aa70a085e4bd0668f033937f"/><file name="pushnoteproducts.xml" hash="9b89a4d51a49e5a1b43c6b4e227b4439"/><file name="pushnoteorders.xml" hash="baa5ec7f3079699b0eb340d95586016a"/></dir><dir name="template"><dir name="offers"><file name="offers.phtml" hash="39e48356b3706eb29221763b1b82c55e"/></dir><dir name="pushnoteproducts"><file name="pushnoteproducts.phtml" hash="b76c98fcadc7ae3a640e4490563ff4f5"/></dir><dir name="pushnoteorders"><file name="pushnoteorders.phtml" hash="4673989e2102012fb24230873b99656c"/></dir></dir></dir></dir></dir></dir></target><target name="mageskin"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><file name="popup.css" hash="8cc8c3a5113d76b51ec13ade4fc41afb"/></dir></dir></dir></dir></target><target name="mage"><dir><dir name="js"><dir name="iframe"><file name="jquery-2.1.1.min.js" hash="49fffe009bd5abd3db052a50537dcbe3"/><file name="jquery.simplemodal.js" hash="b33a4bd97176d530ba43a6659daaa748"/></dir></dir><dir name="contus"><file name="Mcom_development.pem" hash="21cec017e04e0b229b9349138ed939c3"/><file name="Mcom_production.pem" hash="8e3131c3eca71a6996c346b6b1144b21"/><dir><dir name="image"><file name="splash_logo.png" hash="8ca437906154fe6b0e854764fe4991b3"/></dir></dir></dir><dir name="paypal"><file name="PaymentGateway.php" hash="276078578ddf722db13f0409e955255d"/><file name="Paypal.php" hash="ac313df2943a8424b5235d1f7d75ca39"/><file name="cancel.php" hash="d9f87387c5b8e1e9e1ad95cc661acd21"/><file name="ipn.log" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="ipn.php" hash="2f2623b62891a10ed6da42efe97db0ae"/><file name="ipnlistener.php" hash="1f9b96d748b21dc333d5235804086981"/><file name="redirect.php" hash="af5cddf3babd37d373725d026f165273"/><file name="success.php" hash="26cc7e9aaad82415d6b8005f64c11397"/></dir><dir name="rest"><file name="Rest.inc.php" hash="db6e2cdc43f08a964b1d7de82f7b5ba3"/><file name="api.php" hash="77738aaaeff9fc9dc7353ec519b47d60"/><file name=".htaccess" hash="0a6a1af3eba87f4e9dd820b01c38e766"/></dir></dir></target><target name="magelocal"><dir><dir name="ContusRestapi"><dir><dir name="AddressBook"><dir name="Model"><dir name="Api2"><dir name="AddressBook"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="fa87ce51335210432b63ee767704f48c"/></dir><dir name="Customer"><file name="V1.php" hash="ec4d710ae329f358c3eb2d902a89a853"/></dir><dir name="Guest"><file name="V1.php" hash="a8039455bfcd23ed607fa667ae7bb1c7"/></dir></dir><file name="Rest.php" hash="30e3ee96d4611f0bd792d1b10ba348d1"/></dir><file name="AddressBookapi.php" hash="3f374bbf1fb1c7577367c2477cb6f93e"/><dir name="Country"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="2c8ccecc9a2f4fdb1ca891a58df12b2e"/></dir><dir name="Customer"><file name="V1.php" hash="323672cd9e310ca58941cba073f05c23"/></dir><dir name="Guest"><file name="V1.php" hash="31056c51f9316006ddb8468c510f5f90"/></dir></dir><file name="Rest.php" hash="d3f8dd6b9172a5b3523734c18ebad887"/></dir><file name="Country.php" hash="386046a292f3089d641c23fbc13d4d03"/><dir name="State"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="069dfc1cf9158f73ad1c5803eeb1413b"/></dir><dir name="Guest"><file name="V1.php" hash="816582cd3557fe11890beadb49fb858b"/></dir></dir><file name="Rest.php" hash="b4794c183f5103bcf5e570b6777c2959"/></dir><file name="State.php" hash="973f8e8e696d4fc3751826592ad3fb06"/></dir></dir><dir name="etc"><file name="api2.xml" hash="b7a8262be03ca5c517a8b692abf84e7d"/><file name="config.xml" hash="92a63d6bdce25d58fdcad08722deb3dd"/></dir></dir><dir name="ApplyCoupon"><dir name="Model"><dir name="Api2"><dir name="ApplyCoupon"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="1a577bc661a83ee1b77cfb97367d113c"/></dir><dir name="Customer"><file name="V1.php" hash="736dc803ee29515ad32ff00afe155e46"/></dir><dir name="Guest"><file name="V1.php" hash="605595e312d8b8941e8b55a04c795f7b"/></dir></dir><file name="Rest.php" hash="0e679cf5405ac8e3b216d49cae52a67f"/></dir><file name="ApplyCouponapi.php" hash="7656406039aa7480ebda723d9601bda1"/></dir></dir><dir name="etc"><file name="api2.xml" hash="b7f6afd002743deab122af594a24eeb9"/><file name="config.xml" hash="d1ce73f4eeb36c9e0d2204785ddef5f3"/></dir></dir><dir name="CartAddressapi"><dir name="Model"><dir name="Api2"><dir name="CartAddressapi"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="800148a390660be0e966dab0f3f1a3b3"/></dir><dir name="Customer"><file name="V1.php" hash="c4540f56b75ca665a8771194e5b108de"/></dir><dir name="Guest"><file name="V1.php" hash="d4f6627ea61a7e3de9762e2a5730f21f"/></dir></dir><file name="Rest.php" hash="6069a2f769245b78398adc93bf01cd4e"/></dir><file name="CartAddressapi.php" hash="d110499f2030021bdbb3806f2c366a8a"/></dir></dir><dir name="etc"><file name="api2.xml" hash="befd046b18b2af80752001f8fec335e3"/><file name="config.xml" hash="85b2ea62c85b6a52bf1326e7ea2e80d2"/></dir></dir><dir name="Cartapi"><dir name="Model"><dir name="Api2"><dir name="Cartapi"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="e9b2780fc6717cf4c8cd70a0996da952"/></dir><dir name="Customer"><file name="V1.php" hash="e9e27542054b1050eff94b8e24dc81f7"/></dir><dir name="Guest"><file name="V1.php" hash="e0df6d95bdca4ac73c162c72dccd3157"/></dir></dir><file name="Rest.php" hash="11089e228f3a08342bc294a55ec2a0d5"/></dir><file name="Cartapi.php" hash="aa9241db8185cbf058c967fa190e3304"/></dir></dir><dir name="etc"><file name="api2.xml" hash="2dbf3da500930f58108bf9a9f87ec75f"/><file name="config.xml" hash="6dce6326329b06cc349316fdc7f1e8a1"/></dir></dir><dir name="Contactus"><dir name="Model"><dir name="Api2"><dir name="Contactus"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="1e9ae009d6e700b776f9e3ee741956fa"/></dir><dir name="Customer"><file name="V1.php" hash="837272b6d62cb4cc1666d16df28c79c4"/></dir><dir name="Guest"><file name="V1.php" hash="eacf81f1e8d866681d39d9ea23829438"/></dir></dir><file name="Rest.php" hash="9afc6e3e49fba4bb27d38823aa6c2c9f"/></dir><file name="Contactus.php" hash="d1825621d086281d5155a8c9fc30cb46"/></dir></dir><dir name="etc"><file name="api2.xml" hash="4face9e5a65e6b5f50118ff4b83b3137"/><file name="config.xml" hash="cfa64206e4e39784963b2936826517cc"/></dir></dir><dir name="Filters"><dir name="Model"><dir name="Api2"><dir name="Filters"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="9c86175283d31ad4991d3e22561c1a29"/></dir><dir name="Customer"><file name="V1.php" hash="63ae714a9128ae75fe4f0dc62f0f8212"/></dir><dir name="Guest"><file name="V1.php" hash="b04bd01daf25c8f0303fbee0601a55bc"/></dir></dir><file name="Rest.php" hash="705aadf18a53896bbb2cfce41a1b8102"/></dir><file name="Filters.php" hash="ddfd094d721e92f2848ccce352ecd356"/></dir></dir><dir name="etc"><file name="api2.xml" hash="c56047774d688915d3992226d395131d"/><file name="config.xml" hash="3c9507f5ba31aaf209c268557e9339b0"/></dir></dir><dir name="HomePageapi"><dir name="Model"><dir name="Api2"><dir name="HomePageapi"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="5eb5a39d75920703ef26975183a5f81d"/></dir><dir name="Customer"><file name="V1.php" hash="06e96d56de1c93c933a5c1865b0e43e7"/></dir><dir name="Guest"><file name="V1.php" hash="b76cf62bf759c748858ac11213e2d95d"/></dir></dir><file name="Rest.php" hash="764dc0c42c07a4fd35beef9159721a25"/></dir><file name="HomePageapi.php" hash="6bddfb217922358e2bda21b6fca5dbba"/></dir></dir><dir name="etc"><file name="api2.xml" hash="de09034be003e6f56d992a939310a526"/><file name="config.xml" hash="987e0202a5cf8d5650b2d1004277be2d"/></dir></dir><dir name="Login"><dir name="Model"><dir name="Api2"><dir name="Forgotpassword"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="ed7ecb2d101124a3af996aa68ad4ae14"/></dir><dir name="Customer"><file name="V1.php" hash="1d9dde0cbb555ed9b2763265712e16f1"/></dir><dir name="Guest"><file name="V1.php" hash="b4f685ad6006e34e7761e8db39a1601e"/></dir></dir><file name="Rest.php" hash="b80db9b5f7f413bfa636d7f4da708e12"/></dir><file name="Forgotpassword.php" hash="ac9512f4102bdeb1314cdad651a02ea6"/><dir name="Login"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="e3fb6be3b3fe28194e227ec57ad5a186"/></dir><dir name="Customer"><file name="V1.php" hash="0ed601b8c568805da9312b97615d73a3"/></dir><dir name="Guest"><file name="V1.php" hash="d9631834e143659f579642fb671efa9d"/></dir></dir><file name="Rest.php" hash="79ffc7815aa51db77b342d01c0badfd4"/></dir><file name="Login.php" hash="d5efc4d011def0681330cea3741f446c"/></dir><dir name="Methods"><file name="Functions.php" hash="ea031035f09eeced4e7753001dec28c1"/></dir><dir name="Resource"><dir name="Token"><file name="Collection.php" hash="d23102f756323dc0fcf56e725ad3affb"/></dir><file name="Token.php" hash="ed7ceb24bc163901207ed31106aa608c"/></dir><file name="Token.php" hash="0416f836810f585d0c6d3bfc34458e74"/></dir><dir name="etc"><file name="api2.xml" hash="6046abc7493543066b1d1fa824de0c5a"/><file name="config.xml" hash="930efb74ee0009c517be54e7a46b8682"/></dir><dir name="sql"><dir name="login_setup"><file name="install-0.0.1.php" hash="c679b4891e8185837d2a31b655544f56"/></dir></dir></dir><dir name="MultiCartapi"><dir name="Model"><dir name="Api2"><dir name="MultiCartapi"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="bdae2062576a265a2dbb4a6e5c54ee2c"/></dir><dir name="Customer"><file name="V1.php" hash="ba637aedc8caa447f09847f6ff5b10bf"/></dir><dir name="Guest"><file name="V1.php" hash="324c03fcfc448472977123bd1875276a"/></dir></dir><file name="Rest.php" hash="90acb34b0dba704008a4baed584836f7"/></dir><file name="MultiCartapi.php" hash="029c5afa495ac58422fe3a1868a13f7d"/></dir></dir><dir name="etc"><file name="api2.xml" hash="796bf74bd3d6ffd2b257fc712aa75293"/><file name="config.xml" hash="661ba9f4224bd74555c5526f7c41154e"/></dir></dir><dir name="MyOrders"><dir name="Model"><dir name="Api2"><dir name="MyOrderapi"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="82927b08ae221b6277cdefdb21554f89"/></dir><dir name="Customer"><file name="V1.php" hash="d75f8b2801775a0401f1ec865b09a62f"/></dir><dir name="Guest"><file name="V1.php" hash="0f9a5558397ee4c5abe68c127cc65ba6"/></dir></dir><file name="Rest.php" hash="4be3db78f9081383ad2385b22d194405"/></dir><file name="MyOrderapi.php" hash="f853e6f0f0d893d2c7159ea6fa5ae978"/></dir></dir><dir name="etc"><file name="api2.xml" hash="9a1f53f2bca4cdbf265131cb02d6c1d9"/><file name="config.xml" hash="9d884c040632d7c1ba6b3eb7258038f0"/></dir></dir><dir name="PlaceOrder"><dir name="Model"><dir name="Api2"><dir name="PlaceOrderapi"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="c124d62195ea7a653e7579f3dd96e2b6"/></dir><dir name="Customer"><file name="V1.php" hash="71c496a9ef5230f14f3f9777b990ab19"/></dir><dir name="Guest"><file name="V1.php" hash="b7b69c391c4784f0ac353574325fba0d"/></dir></dir><file name="Rest.php" hash="7636ec8af040e665b1553031dba50f98"/></dir><file name="PlaceOrderapi.php" hash="17ad99a808e2165e49da9f743e045ee5"/></dir><dir name="Sales"><dir name="Quote"><dir name="Address"><dir name="Total"><file name="Deliverycost.php" hash="31ba8f80dad4f1d0f716db025435c166"/></dir></dir></dir></dir></dir><dir name="etc"><file name="api2.xml" hash="712a8e25671eb16572711b509e73b821"/><file name="config.xml" hash="f01c49a0c0aadac2fc13bde5fb2e5200"/></dir></dir><dir name="ProductList"><dir name="Model"><dir name="Api2"><dir name="ProductList"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="0a49f28a84be01e71d9c1644d95b4c2b"/></dir><dir name="Guest"><file name="V1.php" hash="729240a7ec2eeff1a39a8061345edd56"/></dir></dir><file name="Rest.php" hash="8d2aa86f54a5c70a83c35a5745c6e40e"/></dir></dir></dir><dir name="etc"><file name="api2.xml" hash="f8af0474306df872255cc344f9a2ec8e"/><file name="config.xml" hash="b2fef8859874c5505007f85733103c86"/></dir></dir><dir name="Products"><dir name="Model"><dir name="Api2"><dir name="Products"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="9c2194537ab4238463d25689bb795859"/></dir><dir name="Customer"><file name="V1.php" hash="76fc3d511de93e77e19eb10f79255b3a"/></dir><dir name="Guest"><file name="V1.php" hash="46a08ead683b1db61255d2e724ba40c9"/></dir></dir><file name="Rest.php" hash="2353a5b01a29321fbe41bba402a1527b"/></dir><file name="Products.php" hash="12f0a11f926d79f858b4094cce0164cc"/></dir></dir><dir name="etc"><file name="api2.xml" hash="38bcc882b9abec04e9b7ee0c0f829b4d"/><file name="config.xml" hash="542a17c4294f57d19f617a88526a0cc1"/></dir></dir><dir name="Registration"><dir name="Model"><dir name="Api2"><dir name="ChangePassword"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="04b3985e11a37c6f80310366d7276d4d"/></dir><dir name="Customer"><file name="V1.php" hash="df47bcb511a2c12deadfd444d1adc383"/></dir><dir name="Guest"><file name="V1.php" hash="87e0a4ff0c254135b83c810bdbd979c2"/></dir></dir><file name="Rest.php" hash="755ef8a11d74f0fca457115cd3801f6e"/></dir><dir name="Registration"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="2d960ebf6a581b3fd4ba29892f553d52"/></dir><dir name="Customer"><file name="V1.php" hash="6d81dde797e56696c5af656244dcac8b"/></dir><dir name="Guest"><file name="V1.php" hash="5d6bc426abc5c0b19c0668ccbfd3c021"/></dir></dir><file name="Rest.php" hash="c53396e643e5c25b20922b4d335bb57e"/></dir></dir></dir><dir name="etc"><file name="api2.xml" hash="67f9baac0ce159bf71f4b2f2a3566428"/><file name="config.xml" hash="3803604868540ff96f6ffdb3c7c09278"/></dir></dir><dir name="ReviewRating"><dir name="Model"><dir name="Api2"><dir name="ReviewRating"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="0b4dee4df40cebce802c92a56626d5ca"/></dir><dir name="Customer"><file name="V1.php" hash="0806b569367c814c269be3015781d65c"/></dir><dir name="Guest"><file name="V1.php" hash="57a1fa55ee5b2dba5d6d44afa7b432ec"/></dir></dir><file name="Rest.php" hash="e5812d28743261a30c30513b3b1c8d3b"/></dir><file name="ReviewRating.php" hash="6122f474cfe935e7042aa5b86e65a6b1"/></dir></dir><dir name="etc"><file name="api2.xml" hash="6335c4bd2f69469b0aa29c5ebcf89bed"/><file name="config.xml" hash="093a59ea31a58cb0f1ff118d86583179"/></dir></dir><dir name="SearchProducts"><dir name="Model"><dir name="Api2"><dir name="SearchProducts"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="ebe95d66e8935f824d50f10145d50a3a"/></dir><dir name="Customer"><file name="V1.php" hash="6549897f48909896ceb6f17d2544fc98"/></dir><dir name="Guest"><file name="V1.php" hash="0c333730ee604f6d9418e5452b80ad47"/></dir></dir><file name="Rest.php" hash="6b00435029dc3040d4d45717a7eaa36a"/></dir><file name="SearchProducts.php" hash="9388ba20a3fb3c7fd6749f17721b1ef2"/></dir></dir><dir name="etc"><file name="api2.xml" hash="0e72f61046c90d4ffb0072e9258e020a"/><file name="config.xml" hash="08c2950ca36e9f719ea10a8e66b4ef36"/></dir></dir><dir name="Sellers"><dir name="Model"><dir name="Api2"><dir name="Sellers"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="dfe3bdf81a1370e88dc28bfe4ea71fe4"/></dir><dir name="Customer"><file name="V1.php" hash="c54541164694ab3d80717ec10cf60717"/></dir><dir name="Guest"><file name="V1.php" hash="0bb1875cb68c1fe79e8fe1f26a7d565c"/></dir></dir><file name="Rest.php" hash="20e088f5ae3bee521911426b12e2c015"/></dir><file name="Sellers.php" hash="fcb163aaf560c18d86ea5e3864cfe6c9"/></dir></dir><dir name="etc"><file name="api2.xml" hash="1491a6919c7fb0ba2bf4833001fcc284"/><file name="config.xml" hash="d0a64a395daa18cf67c2889a698b297f"/></dir></dir><dir name="ShippingPaymentapi"><dir name="Model"><dir name="Api2"><dir name="ShippingPaymentapi"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="a6e310b9e522eb2cba1ddca9bb01adbd"/></dir><dir name="Customer"><file name="V1.php" hash="c9b52a26bf774691a94459979d7981be"/></dir><dir name="Guest"><file name="V1.php" hash="d40b5e9c42b366e901eed11ef2bf2b50"/></dir></dir><file name="Rest.php" hash="e8ce41c58deeebaa87832c6d090594fa"/></dir><file name="ShippingPaymentapi.php" hash="6a55c62967503d7479dcd1534c26ea98"/></dir></dir><dir name="etc"><file name="api2.xml" hash="fcff0dcff1662fbc5b69d535d3865b93"/><file name="config.xml" hash="f449893d3b9ce99743f4f9df88957eee"/></dir></dir><dir name="SocialLogin"><dir name="Model"><dir name="Api2"><dir name="SocialLogin"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="504f5dacd99ab70df5fc0b977b3b1e9d"/></dir><dir name="Customer"><file name="V1.php" hash="0ed3fd7da081ddf3db38280a449df107"/></dir><dir name="Guest"><file name="V1.php" hash="a078c51f0a28754ef44ed49f22d45934"/></dir></dir><file name="Rest.php" hash="debf62f88f8eea1477ccdf7263e05839"/></dir><file name="SocialLogin.php" hash="f607bd8205c08ac09f6078995576a808"/></dir></dir><dir name="etc"><file name="api2.xml" hash="3aeb29aec4aed541ce804a9f9b0c1ba1"/><file name="config.xml" hash="bcc1a1ee0b876f6fcfa1e70533278dfc"/></dir></dir><dir name="SplashPage"><dir name="Model"><dir name="Api2"><dir name="SplashPage"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="cdb0e541805b56f6236003c562fd0a8e"/></dir><dir name="Customer"><file name="V1.php" hash="ee0636cfbc11895e40642b0c4ae062a5"/></dir><dir name="Guest"><file name="V1.php" hash="844b0ffa26a14b3e6ed53925e8c9404e"/></dir></dir><file name="Rest.php" hash="b59f933f7226f963fea83d6732f99756"/></dir><file name="SplashPage.php" hash="0dd5bf29f89db98aad67195d2136564c"/></dir></dir><dir name="etc"><file name="api2.xml" hash="de87249b97bd26ba33cd1b60476bcfae"/><file name="config.xml" hash="92d9dbf8efe9b6915afd950e05e6d35e"/></dir></dir><dir name="Staticpages"><dir name="Model"><dir name="Api2"><dir name="Staticpages"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="daf94348a90bf00576d13f2395f44373"/></dir><dir name="Customer"><file name="V1.php" hash="e4345e55df3beb22a24b7a06bd0a7e60"/></dir><dir name="Guest"><file name="V1.php" hash="8d6f72cf5db3a3fe5def87cd9945e168"/></dir></dir><file name="Rest.php" hash="2d9e3ce4db5ebd695a36405918c54902"/></dir><file name="Staticpages.php" hash="a5a11a73b2941d15d7e8ca35d26984fc"/></dir></dir><dir name="etc"><file name="api2.xml" hash="a2a52f764e9020a4ae039ae0179609a7"/><file name="config.xml" hash="28491ccf1cfca21dadf91257cfbbbed4"/></dir></dir><dir name="Wishlistapi"><dir name="Model"><dir name="Api2"><dir name="Wishlist"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="f651beba4be1bc71ca9f67d8cb10cab3"/></dir><dir name="Customer"><file name="V1.php" hash="562cfde7040cfed53b787b0eab9e2a22"/></dir><dir name="Guest"><file name="V1.php" hash="851ad054c968702c9867cbe40570c434"/></dir></dir><file name="Rest.php" hash="53ee075545cb61fd4f24d5b83a03306f"/></dir><file name="Wishlist.php" hash="7fa68433ba0334c40fecb2893c557f46"/></dir></dir><dir name="etc"><file name="api2.xml" hash="77537ed8a65c37ade93c8eb13085e1b5"/><file name="config.xml" hash="d57983e6481f0bf170e8855ce56b673c"/></dir></dir></dir></dir><dir name="Contus"><dir name="Configuration"><dir><dir name="Block"><dir name="Adminhtml"><file name="About.php" hash="88af7c68874f53c6b8fa50e3555251d2"/></dir></dir><dir name="Helper"><file name="Data.php" hash="589c315c38ae37d76bb93b644d27738f"/></dir><dir name="Model"><dir name="Adminhtml"><file name="Cmspages.php" hash="42af747d56480ae715bb8cfc7d646a10"/><file name="Count.php" hash="01b7f7216f1a0ebc0997ba3f753296a0"/><file name="Homelist.php" hash="44d04a9f483e83d6273ed45694451630"/></dir><file name="Config.php" hash="88960f2c66da08aadbbfe362be1df3bb"/></dir><dir name="etc"><file name="adminhtml.xml" hash="2ab511bfbb24399f66f92c5e129e93ed"/><file name="config.xml" hash="39c1b50e8ec60245d815ae66680eb1a9"/><file name="system.xml" hash="c0858f20cb21461d4ad242d96e611829"/></dir></dir></dir><dir name="Offers"><dir><dir name="Block"><dir name="Adminhtml"><dir name="Offers"><dir name="Edit"><file name="Form.php" hash="ecc572cb365ef62b9658d0c7f67721f5"/><dir name="Tab"><file name="Form.php" hash="6aab97bca2574d005f969714e5aa4dda"/><file name="Productlist.php" hash="7aba8bae660fef8b16d37ecea0343a13"/></dir><file name="Tabs.php" hash="a357a8b708ab7c96f1f5200f7828f03f"/></dir><file name="Edit.php" hash="f3e49391b8b03a845b37cda0dcd8c616"/><file name="Grid.php" hash="0d1de4b914f43354f119f5b7826532e1"/><dir name="Renderer"><file name="Image.php" hash="cc37093e5c80cef280088d58c82b6470"/><file name="Notification.php" hash="c727f9a4fc45748c1c5bb53be3f78f06"/><file name="View.php" hash="a818c7e6c82efb3852e85cfc01103109"/></dir></dir><file name="Offers.php" hash="9a2d5c00bb5cfaf04fae9b0e1bf37813"/></dir><file name="Offers.php" hash="24ad7397a1a83adccfa81ab1b86546c4"/></dir><dir name="Helper"><file name="Data.php" hash="3400397d268933f11bb5f6b5ad745eaf"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Offers"><file name="Collection.php" hash="0b45658ccbd52447163e50a73bda2fdb"/></dir><file name="Offers.php" hash="a9cb9633c24d9e9283298fe865fbd926"/></dir><file name="Offers.php" hash="6178200d641970fc870d0c1869dfbcac"/><file name="Status.php" hash="74f9c981477bc89ec5cf8902c6a829d1"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="OffersController.php" hash="7c7983850767c8f0d4282b1cab070ad7"/></dir><file name="IndexController.php" hash="8ad61469cb056026c9450c550063d7ce"/></dir><dir name="etc"><file name="adminhtml.xml" hash="a66266c8ea8f62aaea031291382eb000"/><file name="config.xml" hash="6bd00eedfc3c0bc6977ce36b22c695f9"/></dir><dir name="sql"><dir name="offers_setup"><file name="mysql4-install-0.1.0.php" hash="f7c43d483d274a4113ec5660ef13ab2d"/></dir></dir></dir></dir><dir name="Pushnoteorders"><dir><dir name="Block"><dir name="Adminhtml"><dir name="Pushnoteorders"><file name="Edit.php" hash="1bddef98ed3cbb6c2257082c815dec1a"/><file name="Grid.php" hash="d8fc00d43a5187f3af89da63f9e404b6"/><dir name="Renderer"><file name="Notification.php" hash="79f97835ef176565e47ad19ada958e22"/><file name="View.php" hash="12034fa2c7178b6fe898d60b46fcb61f"/></dir></dir><file name="Pushnoteorders.php" hash="a7c1a0a2e5f5b39d8e5c781e508f9f56"/></dir><file name="Pushnoteorders.php" hash="0b16da26a98412686c1b9a4f762f1285"/></dir><dir name="Helper"><file name="Data.php" hash="e731245220b7b38db9f0fd31a40ae39e"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="PushnoteordersController.php" hash="e06154a15e95c03eaccc8aef5e820ca4"/></dir><file name="IndexController.php" hash="a36f49a983432759ba209b2d0b335bd6"/></dir><dir name="etc"><file name="adminhtml.xml" hash="1ae517a1e0c037dfb43a50a9917e7c97"/><file name="config.xml" hash="fb2714db776c5a1021eb440317828d92"/></dir></dir></dir><dir name="Pushnoteproducts"><dir><dir name="Block"><dir name="Adminhtml"><dir name="Pushnoteproducts"><file name="Edit.php" hash="cdf5a1dcbce0ad048faa1e9a33a8cdc9"/><file name="Grid.php" hash="ecf2f79fb04c2df52b99849b64244a07"/><dir name="Renderer"><file name="Notification.php" hash="7dbf8c30708cfa1d15a9cf941dfe0d97"/><file name="View.php" hash="f5cc64c42c5caf364921d51177f865d2"/></dir></dir><file name="Pushnoteproducts.php" hash="eb399595756eb635c1390ae985d2fb1d"/></dir><file name="Pushnoteproducts.php" hash="b9d833bc77da69e92098e3d9dadaddff"/></dir><dir name="Helper"><file name="Data.php" hash="8ffd99731b3d4a5dd12fa062f6b1db16"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="PushnoteproductsController.php" hash="d9a3821703fea674c724b8a190f5cd7a"/></dir><file name="IndexController.php" hash="3cf009c3f2125552591c0c0558018297"/></dir><dir name="etc"><file name="config.xml" hash="384b48e0d97d58aad7bc4268aadee828"/></dir></dir></dir></dir></dir></target></contents>
|
17 |
<compatible/>
|
18 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
19 |
</package>
|
paypal/ipn.log
ADDED
File without changes
|
paypal/ipn.php
CHANGED
@@ -147,14 +147,14 @@ if (strcmp ( $res, "VERIFIED" ) == 0) {
|
|
147 |
*/
|
148 |
|
149 |
// Check Number 1 ------------------------------------------------------------------------------------------------------------
|
150 |
-
$receiver_email = $_POST ['receiver_email'];
|
151 |
if ($receiver_email != "subhasini@contus.in") {
|
152 |
fwrite ( $fh, 'business email returned is not your business email' );
|
153 |
$verified = false;
|
154 |
// handle the wrong business url
|
155 |
} else {
|
156 |
$verified = true;
|
157 |
-
}
|
158 |
|
159 |
// Check number 2 ------------------------------------------------------------------------------------------------------------
|
160 |
$order = Mage::getModel ( 'sales/order' )->loadByIncrementId ( $order_id );
|
147 |
*/
|
148 |
|
149 |
// Check Number 1 ------------------------------------------------------------------------------------------------------------
|
150 |
+
/* $receiver_email = $_POST ['receiver_email'];
|
151 |
if ($receiver_email != "subhasini@contus.in") {
|
152 |
fwrite ( $fh, 'business email returned is not your business email' );
|
153 |
$verified = false;
|
154 |
// handle the wrong business url
|
155 |
} else {
|
156 |
$verified = true;
|
157 |
+
} */
|
158 |
|
159 |
// Check number 2 ------------------------------------------------------------------------------------------------------------
|
160 |
$order = Mage::getModel ( 'sales/order' )->loadByIncrementId ( $order_id );
|
paypal/redirect.php
CHANGED
@@ -18,7 +18,7 @@ $order = Mage::getModel('sales/order')->loadByIncrementId($order_Id);
|
|
18 |
|
19 |
$orderId = $order->getIncrementId ();
|
20 |
|
21 |
-
$result = $order->
|
22 |
|
23 |
$currency_code = $order ['base_currency_code'];
|
24 |
|
@@ -27,8 +27,10 @@ $weight = round ( $order ['Weight'], 2 );
|
|
27 |
$ship_method = $order ['Shipping_description'];
|
28 |
$tax = trim ( round ( $order ['tax_amount'], 2 ) );
|
29 |
$discountAmount = $order ['discount_amount'];
|
30 |
-
|
31 |
-
|
|
|
|
|
32 |
$amount = round ( $order ['grand_total'], 2 );
|
33 |
|
34 |
$customerid = $order ['customer_id'];
|
@@ -110,7 +112,6 @@ $redirecturl = $baseUrl . "paypal/";
|
|
110 |
<input id="amount" name="amount" value="<?php echo $amount;?>" type="hidden" />
|
111 |
<input id="tax" name="tax" value="<?php echo number_format($tax, 2, '.', '');?>" type="hidden" />
|
112 |
<input id="shipping1" name="shipping1" value="<?php echo sprintf("%.2f", $shipping);?>" type="hidden" />
|
113 |
-
<input id="discount_amount" name="discount_amount" value="<?php echo number_format($discountAmount, 2, '.', '');?>" type="hidden" />
|
114 |
|
115 |
|
116 |
<input type="hidden" name="rm" value="2">
|
@@ -129,7 +130,7 @@ foreach ($result as $key => $item) { ?>
|
|
129 |
<?php } //exit;?>
|
130 |
|
131 |
<input id="shipping_1" name="shipping_1" value="<?php echo sprintf("%.2f", $shipping);?>" type="hidden" />
|
132 |
-
|
133 |
<input id="cmd" name="cmd" value="_cart" type="hidden" />
|
134 |
<input id="upload" name="upload" value="1" type="hidden" />
|
135 |
|
18 |
|
19 |
$orderId = $order->getIncrementId ();
|
20 |
|
21 |
+
$result = $order->getAllVisibleItems ();
|
22 |
|
23 |
$currency_code = $order ['base_currency_code'];
|
24 |
|
27 |
$ship_method = $order ['Shipping_description'];
|
28 |
$tax = trim ( round ( $order ['tax_amount'], 2 ) );
|
29 |
$discountAmount = $order ['discount_amount'];
|
30 |
+
$discountAmount = number_format($discountAmount, 2, '.', '');
|
31 |
+
if($discountAmount){
|
32 |
+
$discountAmount = $discountAmount *(-1);
|
33 |
+
}
|
34 |
$amount = round ( $order ['grand_total'], 2 );
|
35 |
|
36 |
$customerid = $order ['customer_id'];
|
112 |
<input id="amount" name="amount" value="<?php echo $amount;?>" type="hidden" />
|
113 |
<input id="tax" name="tax" value="<?php echo number_format($tax, 2, '.', '');?>" type="hidden" />
|
114 |
<input id="shipping1" name="shipping1" value="<?php echo sprintf("%.2f", $shipping);?>" type="hidden" />
|
|
|
115 |
|
116 |
|
117 |
<input type="hidden" name="rm" value="2">
|
130 |
<?php } //exit;?>
|
131 |
|
132 |
<input id="shipping_1" name="shipping_1" value="<?php echo sprintf("%.2f", $shipping);?>" type="hidden" />
|
133 |
+
|
134 |
<input id="cmd" name="cmd" value="_cart" type="hidden" />
|
135 |
<input id="upload" name="upload" value="1" type="hidden" />
|
136 |
|
paypal/success.php
CHANGED
@@ -6,18 +6,172 @@ $_SERVER ['SCRIPT_NAME'] = str_replace ( basename ( __FILE__ ), 'index.php', $_S
|
|
6 |
$_SERVER ['SCRIPT_FILENAME'] = str_replace ( basename ( __FILE__ ), 'index.php', $_SERVER ['SCRIPT_FILENAME'] );
|
7 |
|
8 |
|
9 |
-
|
10 |
mail("vinotha.a@contus.in",'paypal', $txnid);
|
11 |
$transaction_id = $_POST ['verify_sign'];
|
12 |
$order_id = $_POST ['invoice'];
|
13 |
-
$status = $_POST ['payment_status'];
|
14 |
$email = $_POST ['payer_email'];
|
15 |
$name = $_POST ['first_name'];
|
16 |
$pendingreason = $_POST ['pending_reason'];
|
17 |
|
18 |
$mcgross = $_POST ['mc_gross'];
|
19 |
$refundreason = $_POST ['reason_code'];
|
|
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
?>
|
22 |
<script language="javascript">
|
23 |
function showAndroidToast(toast) {
|
@@ -33,7 +187,7 @@ $refundreason = $_POST ['reason_code'];
|
|
33 |
name='viewport' />
|
34 |
</head>
|
35 |
|
36 |
-
<body
|
37 |
<input id="txnid" name="txnid" value="<?php echo $txnid;?>" type="hidden" />
|
38 |
<center>
|
39 |
<h2>Order Placed successfully.</h2>
|
6 |
$_SERVER ['SCRIPT_FILENAME'] = str_replace ( basename ( __FILE__ ), 'index.php', $_SERVER ['SCRIPT_FILENAME'] );
|
7 |
|
8 |
|
9 |
+
$txnid = $_REQUEST ['txn_id'];
|
10 |
mail("vinotha.a@contus.in",'paypal', $txnid);
|
11 |
$transaction_id = $_POST ['verify_sign'];
|
12 |
$order_id = $_POST ['invoice'];
|
13 |
+
$status = $_POST ['payment_status'];
|
14 |
$email = $_POST ['payer_email'];
|
15 |
$name = $_POST ['first_name'];
|
16 |
$pendingreason = $_POST ['pending_reason'];
|
17 |
|
18 |
$mcgross = $_POST ['mc_gross'];
|
19 |
$refundreason = $_POST ['reason_code'];
|
20 |
+
/*onload="showAndroidToast('<?php echo $txnid; ?>')" */
|
21 |
|
22 |
+
|
23 |
+
$verified = false;
|
24 |
+
// Check to see there are posted variables coming into the script
|
25 |
+
if ($_SERVER ['REQUEST_METHOD'] != "POST")
|
26 |
+
die ( "No Post Variables" );
|
27 |
+
|
28 |
+
// CONFIG: Enable debug mode. This means we'll log requests into 'ipn.log' in the same directory.
|
29 |
+
// Especially useful if you encounter network errors or other intermittent problems with IPN (validation).
|
30 |
+
// Set this to 0 once you go live or don't require logging.
|
31 |
+
define ( "DEBUG", 1 );
|
32 |
+
// Set to 0 once you're ready to go live
|
33 |
+
define ( "USE_SANDBOX", 1 );
|
34 |
+
define ( "LOG_FILE", "./ipn.log" );
|
35 |
+
// Read POST data
|
36 |
+
// reading posted data directly from $_POST causes serialization
|
37 |
+
// issues with array data in POST. Reading raw POST data from input stream instead.
|
38 |
+
$raw_post_data = file_get_contents ( 'php://input' );
|
39 |
+
$raw_post_array = explode ( '&', $raw_post_data );
|
40 |
+
$myPost = array ();
|
41 |
+
foreach ( $raw_post_array as $keyval ) {
|
42 |
+
$keyval = explode ( '=', $keyval );
|
43 |
+
if (count ( $keyval ) == 2)
|
44 |
+
$myPost [$keyval [0]] = urldecode ( $keyval [1] );
|
45 |
+
}
|
46 |
+
// read the post from PayPal system and add 'cmd'
|
47 |
+
$req = 'cmd=_notify-validate';
|
48 |
+
if (function_exists ( 'get_magic_quotes_gpc' )) {
|
49 |
+
$get_magic_quotes_exists = true;
|
50 |
+
}
|
51 |
+
foreach ( $myPost as $key => $value ) {
|
52 |
+
if ($get_magic_quotes_exists == true && get_magic_quotes_gpc () == 1) {
|
53 |
+
$value = urlencode ( stripslashes ( $value ) );
|
54 |
+
} else {
|
55 |
+
$value = urlencode ( $value );
|
56 |
+
}
|
57 |
+
$req .= "&$key=$value";
|
58 |
+
}
|
59 |
+
// Post IPN data back to PayPal to validate the IPN data is genuine
|
60 |
+
// Without this step anyone can fake IPN data
|
61 |
+
if (USE_SANDBOX == true) {
|
62 |
+
$paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
|
63 |
+
} else {
|
64 |
+
$paypal_url = "https://www.paypal.com/cgi-bin/webscr";
|
65 |
+
}
|
66 |
+
$ch = curl_init ( $paypal_url );
|
67 |
+
if ($ch == FALSE) {
|
68 |
+
return FALSE;
|
69 |
+
$verified = false;
|
70 |
+
}
|
71 |
+
curl_setopt ( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
|
72 |
+
curl_setopt ( $ch, CURLOPT_POST, 1 );
|
73 |
+
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
|
74 |
+
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $req );
|
75 |
+
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
|
76 |
+
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
|
77 |
+
curl_setopt ( $ch, CURLOPT_FORBID_REUSE, 1 );
|
78 |
+
if (DEBUG == true) {
|
79 |
+
curl_setopt ( $ch, CURLOPT_HEADER, 1 );
|
80 |
+
curl_setopt ( $ch, CURLINFO_HEADER_OUT, 1 );
|
81 |
+
}
|
82 |
+
// CONFIG: Optional proxy configuration
|
83 |
+
// curl_setopt($ch, CURLOPT_PROXY, $proxy);
|
84 |
+
// curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
|
85 |
+
// Set TCP timeout to 30 seconds
|
86 |
+
curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
|
87 |
+
curl_setopt ( $ch, CURLOPT_HTTPHEADER, array (
|
88 |
+
'Connection: Close'
|
89 |
+
) );
|
90 |
+
// CONFIG: Please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
|
91 |
+
// of the certificate as shown below. Ensure the file is readable by the webserver.
|
92 |
+
// This is mandatory for some environments.
|
93 |
+
// $cert = __DIR__ . "./cacert.pem";
|
94 |
+
// curl_setopt($ch, CURLOPT_CAINFO, $cert);
|
95 |
+
$res = curl_exec ( $ch );
|
96 |
+
if (curl_errno ( $ch ) != 0) // cURL error
|
97 |
+
{
|
98 |
+
if (DEBUG == true) {
|
99 |
+
error_log ( date ( '[Y-m-d H:i e] ' ) . "Can't connect to PayPal to validate IPN message: " . curl_error ( $ch ) . PHP_EOL, 3, LOG_FILE );
|
100 |
+
}
|
101 |
+
curl_close ( $ch );
|
102 |
+
$verified = false;
|
103 |
+
} else {
|
104 |
+
// Log the entire HTTP response if debug is switched on.
|
105 |
+
if (DEBUG == true) {
|
106 |
+
error_log ( date ( '[Y-m-d H:i e] ' ) . "HTTP request of validation request:" . curl_getinfo ( $ch, CURLINFO_HEADER_OUT ) . " for IPN payload: $req" . PHP_EOL, 3, LOG_FILE );
|
107 |
+
error_log ( date ( '[Y-m-d H:i e] ' ) . "HTTP response of validation request: $res" . PHP_EOL, 3, LOG_FILE );
|
108 |
+
}
|
109 |
+
curl_close ( $ch );
|
110 |
+
}
|
111 |
+
// Inspect IPN validation result and act accordingly
|
112 |
+
// Split response headers and payload, a better way for strcmp
|
113 |
+
$tokens = explode ( "\r\n\r\n", trim ( $res ) );
|
114 |
+
$res = trim ( end ( $tokens ) );
|
115 |
+
if (strcmp ( $res, "VERIFIED" ) == 0) {
|
116 |
+
// check whether the payment_status is Completed
|
117 |
+
// check that txn_id has not been previously processed
|
118 |
+
// check that receiver_email is your PayPal email
|
119 |
+
// check that payment_amount/payment_currency are correct
|
120 |
+
// process payment and mark item as paid.
|
121 |
+
// assign posted variables to local variables
|
122 |
+
|
123 |
+
|
124 |
+
if (DEBUG == true) {
|
125 |
+
error_log ( date ( '[Y-m-d H:i e] ' ) . "Verified IPN: $req " . PHP_EOL, 3, LOG_FILE );
|
126 |
+
}
|
127 |
+
$verified = true;
|
128 |
+
} else if (strcmp ( $res, "INVALID" ) == 0) {
|
129 |
+
|
130 |
+
// log for manual investigation
|
131 |
+
// Add business logic here which deals with invalid IPN messages
|
132 |
+
if (DEBUG == true) {
|
133 |
+
error_log ( date ( '[Y-m-d H:i e] ' ) . "Invalid IPN: $req" . PHP_EOL, 3, LOG_FILE );
|
134 |
+
}
|
135 |
+
$verified = false;
|
136 |
+
} else {
|
137 |
+
$verified = false;
|
138 |
+
|
139 |
+
error_log ( date ( '[Y-m-d H:i e] ' ) . "Error IPN: $req" . PHP_EOL, 3, LOG_FILE );
|
140 |
+
}
|
141 |
+
|
142 |
+
/*
|
143 |
+
* CHECK THESE 4 THINGS BEFORE PROCESSING THE TRANSACTION, HANDLE THEM AS YOU WISH 1. Make sure that business email returned is your business email 2. Make sure that the transaction�s payment status is �completed� 3. Make sure there are no duplicate txn_id 4. Make sure the payment amount matches what you charge for items. (Defeat Price-Jacking)
|
144 |
+
*/
|
145 |
+
|
146 |
+
// Check Number 1 ------------------------------------------------------------------------------------------------------------
|
147 |
+
/* $receiver_email = $_POST ['receiver_email'];
|
148 |
+
if ($receiver_email != "subhasini@contus.in") {
|
149 |
+
fwrite ( $fh, 'business email returned is not your business email' );
|
150 |
+
$verified = false;
|
151 |
+
// handle the wrong business url
|
152 |
+
} else {
|
153 |
+
$verified = true;
|
154 |
+
} */
|
155 |
+
|
156 |
+
// Check number 2 ------------------------------------------------------------------------------------------------------------
|
157 |
+
$order = Mage::getModel ( 'sales/order' )->loadByIncrementId ( $order_id );
|
158 |
+
|
159 |
+
if ($verified) {
|
160 |
+
|
161 |
+
if ($order->getId ()) {
|
162 |
+
|
163 |
+
if (! $order->getEmailSent ()) {
|
164 |
+
$order->sendNewOrderEmail ();
|
165 |
+
$order->setEmailSent ( true );
|
166 |
+
$order->save ();
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
$payment = $order->getPayment ();
|
171 |
+
|
172 |
+
$myvalue = " case==>" . $status;
|
173 |
+
fwrite ( $fh, $myvalue );
|
174 |
+
}
|
175 |
?>
|
176 |
<script language="javascript">
|
177 |
function showAndroidToast(toast) {
|
187 |
name='viewport' />
|
188 |
</head>
|
189 |
|
190 |
+
<body >
|
191 |
<input id="txnid" name="txnid" value="<?php echo $txnid;?>" type="hidden" />
|
192 |
<center>
|
193 |
<h2>Order Placed successfully.</h2>
|
rest/api.php
CHANGED
@@ -10,1624 +10,1943 @@
|
|
10 |
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
11 |
|
12 |
*/
|
13 |
-
|
14 |
require_once ("Rest.inc.php");
|
15 |
$mageFilename = '../app/Mage.php';
|
16 |
require_once $mageFilename;
|
17 |
class API extends REST {
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
}
|
194 |
-
|
195 |
-
|
196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
'new_password' => $this->_request ['new_signature'],
|
234 |
-
'token' => $this->_request ['token']
|
235 |
-
) );
|
236 |
-
$headers = array (
|
237 |
-
'Content-Type' => 'application/json',
|
238 |
-
'Accept' => '*/*'
|
239 |
-
);
|
240 |
-
$resourceUrl = "$apiUrl/customer/changepassword/";
|
241 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
242 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
243 |
-
|
244 |
-
if (! $result ['isValidToken']) {
|
245 |
-
$this->sendResponse ( 401, json_encode ( array (
|
246 |
-
'error' => true,
|
247 |
-
'message' => 'Unauthorized'
|
248 |
-
) ) );
|
249 |
-
} else {
|
250 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
251 |
-
}
|
252 |
-
}
|
253 |
-
break;
|
254 |
-
|
255 |
-
case "customer_register" :
|
256 |
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
|
|
288 |
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
case "personal_detail" :
|
326 |
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
|
|
|
|
|
|
358 |
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
'quote_id' => ( int ) $this->_request ['quote_id'],
|
403 |
-
'qty' => ( int ) $this->_request ['qty'],
|
404 |
-
'currencyCode' => $this->_request ['currencyCode'],
|
405 |
-
'super_attribute' => json_decode ( $this->_request ['super_attribute'] ),
|
406 |
-
'links' => ( $this->_request ['links'] ),
|
407 |
-
'custom_option' => json_decode ( $this->_request ['custom_option'] )
|
408 |
-
) );
|
409 |
-
|
410 |
-
$resourceUrl = "$apiUrl/cart/add/";
|
411 |
-
$headers = array (
|
412 |
-
'Content-Type' => 'application/json',
|
413 |
-
'Accept' => '*/*'
|
414 |
-
);
|
415 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
416 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
417 |
-
if (! $result ['isValidToken']) {
|
418 |
-
$this->sendResponse ( 401, json_encode ( array (
|
419 |
-
'error' => true,
|
420 |
-
'message' => 'Unauthorized'
|
421 |
-
) ) );
|
422 |
-
} else {
|
423 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
424 |
-
}
|
425 |
-
}
|
426 |
-
break;
|
427 |
-
case "cart_list" :
|
428 |
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
|
|
|
|
464 |
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
$customer_id = '';
|
536 |
-
}
|
537 |
-
if ($this->_request ['custom_option'] && $this->_request ['custom_option'] != '') {
|
538 |
-
$custom_option = ($this->_request ['custom_option']);
|
539 |
-
foreach ((json_decode($custom_option)) as $key => $option){
|
540 |
-
if(is_string($option)){
|
541 |
-
$option = str_replace(' ','$$$$', $option);
|
542 |
-
}
|
543 |
-
$new_option [$key] = $option;
|
544 |
-
|
545 |
-
}
|
546 |
-
$custom_option = json_encode($new_option);
|
547 |
-
} else {
|
548 |
-
$custom_option = '';
|
549 |
-
}
|
550 |
-
|
551 |
-
if ($this->_request ['super_attribute'] && $this->_request ['super_attribute'] != '') {
|
552 |
-
$super_attribute = ($this->_request ['super_attribute']);
|
553 |
-
} else {
|
554 |
-
$super_attribute = '';
|
555 |
-
}
|
556 |
-
if ($this->_request ['links'] && $this->_request ['links'] != '') {
|
557 |
-
$links = ($this->_request ['links']);
|
558 |
-
} else {
|
559 |
-
$links = '';
|
560 |
-
}
|
561 |
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
}
|
579 |
-
}
|
580 |
-
break;
|
581 |
-
|
582 |
-
case "cart_count" :
|
583 |
-
if ($this->get_request_method () != "POST") {
|
584 |
-
$this->sendResponse ( 400, json_encode ( array (
|
585 |
-
'error' => true,
|
586 |
-
'message' => 'Bad Request'
|
587 |
-
) ) );
|
588 |
-
} else {
|
589 |
-
|
590 |
-
$requestData = array (
|
591 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
592 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
593 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
594 |
-
'token' => $this->_request ['token']
|
595 |
-
);
|
596 |
-
$headers = array (
|
597 |
-
'Content-Type' => 'application/json',
|
598 |
-
'Accept' => '*/*'
|
599 |
-
);
|
600 |
-
|
601 |
-
$resourceUrl = "$apiUrl/cart/item_count/";
|
602 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
603 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
604 |
-
if (! $result ['isValidToken']) {
|
605 |
-
$this->sendResponse ( 401, json_encode ( array (
|
606 |
-
'error' => true,
|
607 |
-
'message' => 'Unauthorized'
|
608 |
-
) ) );
|
609 |
-
} else {
|
610 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
611 |
-
}
|
612 |
-
}
|
613 |
-
break;
|
614 |
-
case "searchproducts" :
|
615 |
-
$search_term = str_replace ( ' ','%20', $this->_request ['search_term'] );
|
616 |
-
if ($this->get_request_method () != "GET") {
|
617 |
-
$this->sendResponse ( 400, json_encode ( array (
|
618 |
-
'error' => true,
|
619 |
-
'message' => 'Bad Request'
|
620 |
-
) ) );
|
621 |
-
} else {
|
622 |
-
$requestData = array (
|
623 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
624 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
625 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
626 |
-
'category_id' => ( int ) $this->_request ['category_id'],
|
627 |
-
|
628 |
-
'search_term' => $this->_request ['search_term'],
|
629 |
-
'page' => $this->_request ['page'],
|
630 |
-
'limit' => $this->_request ['limit'] ,
|
631 |
-
'image_size' => (int) $this->_request ['image_size']
|
632 |
-
);
|
633 |
-
$headers = array (
|
634 |
-
'Content-Type' => 'application/json',
|
635 |
-
'Accept' => '*/*'
|
636 |
-
);
|
637 |
-
$oauthClient->fetch ( "$apiUrl/search/products/", $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
638 |
-
|
639 |
-
$result = $oauthClient->getLastResponse ();
|
640 |
-
|
641 |
-
$this->sendResponse ( 200, json_decode ( $result ) );
|
642 |
-
}
|
643 |
-
break;
|
644 |
-
|
645 |
-
case "country" :
|
646 |
-
if ($this->get_request_method () != "GET") {
|
647 |
-
$this->sendResponse ( 400, json_encode ( array (
|
648 |
-
'error' => true,
|
649 |
-
'message' => 'Bad Request'
|
650 |
-
) ) );
|
651 |
-
} else {
|
652 |
-
$headers = array (
|
653 |
-
'Content-Type' => 'application/json',
|
654 |
-
'Accept' => '*/*'
|
655 |
-
);
|
656 |
-
|
657 |
-
$oauthClient->fetch ( "$apiUrl/countrycollection/", array(), OAUTH_HTTP_METHOD_GET, $headers );
|
658 |
-
$result = $oauthClient->getLastResponse ();
|
659 |
-
$result = $oauthClient->getLastResponse ();
|
660 |
-
|
661 |
-
$this->sendResponse ( 200, json_decode ( $result ) );
|
662 |
-
}
|
663 |
-
break;
|
664 |
-
|
665 |
-
case "state" :
|
666 |
-
if ($this->get_request_method () != "GET") {
|
667 |
-
$this->sendResponse ( 400, json_encode ( array (
|
668 |
-
'error' => true,
|
669 |
-
'message' => 'Bad Request'
|
670 |
-
) ) );
|
671 |
-
} else {
|
672 |
-
if ($this->_request ['countrycode'] && $this->_request ['countrycode'] != '') {
|
673 |
-
$countryCode = $this->_request ['countrycode'];
|
674 |
-
} else {
|
675 |
-
$countryCode = '';
|
676 |
-
}
|
677 |
-
$headers = array (
|
678 |
-
'Content-Type' => 'application/json',
|
679 |
-
'Accept' => '*/*'
|
680 |
-
);
|
681 |
-
$oauthClient->fetch ( "$apiUrl/statecollection/$countryCode" , array(), OAUTH_HTTP_METHOD_GET, $headers );
|
682 |
-
$result = $oauthClient->getLastResponse ();
|
683 |
-
|
684 |
-
$this->sendResponse ( 200, json_decode ( $result ) );
|
685 |
-
}
|
686 |
-
break;
|
687 |
-
|
688 |
-
case "address_collection" :
|
689 |
-
if ($this->get_request_method () != "POST") {
|
690 |
-
$this->sendResponse ( 400, json_encode ( array (
|
691 |
-
'error' => true,
|
692 |
-
'message' => 'Bad Request'
|
693 |
-
) ) );
|
694 |
-
} else {
|
695 |
-
$requestData = array (
|
696 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
697 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
698 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
699 |
-
'token' => $this->_request ['token']
|
700 |
-
);
|
701 |
-
$headers = array (
|
702 |
-
'Content-Type' => 'application/json',
|
703 |
-
'Accept' => '*/*'
|
704 |
-
);
|
705 |
-
$oauthClient->fetch ( "$apiUrl/addressbook/", $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
706 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
707 |
-
$result1 = json_decode ( $result, true );
|
708 |
-
|
709 |
-
if (! $result1 ['isValidToken']) {
|
710 |
-
$this->sendResponse ( 401, json_encode ( array (
|
711 |
-
'error' => true,
|
712 |
-
'message' => 'Unauthorized'
|
713 |
-
) ) );
|
714 |
-
} else {
|
715 |
-
$this->sendResponse ( 200, ($result) );
|
716 |
-
}
|
717 |
-
}
|
718 |
-
break;
|
719 |
-
|
720 |
-
case "address_add" :
|
721 |
-
if ($this->get_request_method () != "POST") {
|
722 |
-
$this->sendResponse ( 400, json_encode ( array (
|
723 |
-
'error' => true,
|
724 |
-
'message' => 'Bad Request'
|
725 |
-
) ) );
|
726 |
-
} else {
|
727 |
-
$requestData = json_encode ( array (
|
728 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
729 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
730 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
731 |
-
'token' => $this->_request ['token'],
|
732 |
-
'firstname' => $this->_request ['firstname'],
|
733 |
-
'lastname' => $this->_request ['lastname'],
|
734 |
-
'street' => $this->_request ['street'],
|
735 |
-
'city' => $this->_request ['city'],
|
736 |
-
'region' => $this->_request ['region'],
|
737 |
-
'country_id' => $this->_request ['country_id'],
|
738 |
-
'postcode' => $this->_request ['postcode'],
|
739 |
-
'telephone' => $this->_request ['telephone'],
|
740 |
-
'is_default_billing' => ( int ) $this->_request ['is_default_billing'],
|
741 |
-
'is_default_shipping' => ( int ) $this->_request ['is_default_shipping']
|
742 |
-
) );
|
743 |
-
$resourceUrl = "$apiUrl/addressbook/add/";
|
744 |
-
$headers = array (
|
745 |
-
'Content-Type' => 'application/json',
|
746 |
-
'Accept' => '*/*'
|
747 |
-
);
|
748 |
-
|
749 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
750 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
751 |
-
if (! $result ['isValidToken']) {
|
752 |
-
$this->sendResponse ( 401, json_encode ( array (
|
753 |
-
'error' => true,
|
754 |
-
'message' => 'Unauthorized'
|
755 |
-
) ) );
|
756 |
-
} else {
|
757 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
758 |
-
}
|
759 |
-
}
|
760 |
-
break;
|
761 |
-
|
762 |
-
case "address_detail" :
|
763 |
-
|
764 |
-
if ($this->get_request_method () != "POST") {
|
765 |
-
$this->sendResponse ( 400, json_encode ( array (
|
766 |
-
'error' => true,
|
767 |
-
'message' => 'Bad Request'
|
768 |
-
) ) );
|
769 |
-
} else {
|
770 |
-
$requestData = (array (
|
771 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
772 |
-
'token' => $this->_request ['token'],
|
773 |
-
'id' => ( int ) $this->_request ['address_id']
|
774 |
-
));
|
775 |
-
$headers = array (
|
776 |
-
'Content-Type' => 'application/json',
|
777 |
-
'Accept' => '*/*'
|
778 |
-
);
|
779 |
-
$resourceUrl = "$apiUrl/address_detail/";
|
780 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
781 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
782 |
-
if (! $result ['isValidToken']) {
|
783 |
-
$this->sendResponse ( 401, json_encode ( array (
|
784 |
-
'error' => true,
|
785 |
-
'message' => 'Unauthorized'
|
786 |
-
) ) );
|
787 |
-
} else {
|
788 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
789 |
-
}
|
790 |
-
}
|
791 |
-
break;
|
792 |
-
case "address_update" :
|
793 |
-
if ($this->get_request_method () != "POST") {
|
794 |
-
$this->sendResponse ( 400, json_encode ( array (
|
795 |
-
'error' => true,
|
796 |
-
'message' => 'Bad Request'
|
797 |
-
) ) );
|
798 |
-
} else {
|
799 |
-
$requestData = json_encode ( array (
|
800 |
-
'address_id' => ( int ) $this->_request ['address_id'],
|
801 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
802 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
803 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
804 |
-
'token' => $this->_request ['token'],
|
805 |
-
'firstname' => $this->_request ['firstname'],
|
806 |
-
'lastname' => $this->_request ['lastname'],
|
807 |
-
'street' => $this->_request ['street'],
|
808 |
-
'city' => $this->_request ['city'],
|
809 |
-
'region' => $this->_request ['region'],
|
810 |
-
'country_id' => $this->_request ['country_id'],
|
811 |
-
'postcode' => $this->_request ['postcode'],
|
812 |
-
'telephone' => $this->_request ['telephone'],
|
813 |
-
'is_default_billing' => ( int ) $this->_request ['is_default_billing'],
|
814 |
-
'is_default_shipping' => ( int ) $this->_request ['is_default_shipping']
|
815 |
-
) );
|
816 |
-
$resourceUrl = "$apiUrl/addressbook/update/";
|
817 |
-
$headers = array (
|
818 |
-
'Content-Type' => 'application/json',
|
819 |
-
'Accept' => '*/*'
|
820 |
-
);
|
821 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_PUT, $headers );
|
822 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
823 |
-
if (! $result ['isValidToken']) {
|
824 |
-
$this->sendResponse ( 401, json_encode ( array (
|
825 |
-
'error' => true,
|
826 |
-
'message' => 'Unauthorized'
|
827 |
-
) ) );
|
828 |
-
} else {
|
829 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
830 |
-
}
|
831 |
-
}
|
832 |
-
break;
|
833 |
-
case "address_delete" :
|
834 |
-
|
835 |
-
if ($this->get_request_method () != "DELETE") {
|
836 |
-
$this->sendResponse ( 400, json_encode ( array (
|
837 |
-
'error' => true,
|
838 |
-
'message' => 'Bad Request'
|
839 |
-
) ) );
|
840 |
-
} else {
|
841 |
-
|
842 |
-
$storeId = $this->_request ['store_id'];
|
843 |
-
$websiteId = $this->_request ['website_id'];
|
844 |
-
|
845 |
-
if ($this->_request ['customer_id'] && $this->_request ['customer_id'] != '') {
|
846 |
-
$customerId = $this->_request ['customer_id'];
|
847 |
-
} else {
|
848 |
-
$customerId = '';
|
849 |
-
}
|
850 |
-
|
851 |
-
if ($this->_request ['address_id'] && $this->_request ['address_id'] != '') {
|
852 |
-
$addressId = $this->_request ['address_id'];
|
853 |
-
} else {
|
854 |
-
$addressId = '';
|
855 |
-
}
|
856 |
-
$token = $this->_request ['token'];
|
857 |
-
|
858 |
-
$resourceUrl = "$apiUrl/addressbook/delete/address_id/$addressId/customer_id/$customerId/store_id/$storeId/website_id/$websiteId/token/$token";
|
859 |
-
$headers = array (
|
860 |
-
'Content-Type' => 'application/json',
|
861 |
-
'Accept' => '*/*'
|
862 |
-
);
|
863 |
-
$oauthClient->fetch ( $resourceUrl, '', OAUTH_HTTP_METHOD_DELETE, $headers );
|
864 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
865 |
-
if (! $result ['isValidToken']) {
|
866 |
-
$this->sendResponse ( 401, json_encode ( array (
|
867 |
-
'error' => true,
|
868 |
-
'message' => 'Unauthorized'
|
869 |
-
) ) );
|
870 |
-
} else {
|
871 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
872 |
-
}
|
873 |
-
}
|
874 |
-
break;
|
875 |
-
case "apply_coupon" :
|
876 |
-
if ($this->get_request_method () != "POST") {
|
877 |
-
$this->sendResponse ( 400, json_encode ( array (
|
878 |
-
'error' => true,
|
879 |
-
'message' => 'Bad Request'
|
880 |
-
) ) );
|
881 |
-
} else {
|
882 |
-
$requestData = json_encode ( array (
|
883 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
884 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
885 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
886 |
-
'token' => $this->_request ['token'],
|
887 |
-
'quote_id' => ( int ) $this->_request ['quote_id'],
|
888 |
-
'coupon_code' => $this->_request ['coupon_code']
|
889 |
-
) );
|
890 |
-
$resourceUrl = "$apiUrl/coupon/apply/";
|
891 |
-
$headers = array (
|
892 |
-
'Content-Type' => 'application/json',
|
893 |
-
'Accept' => '*/*'
|
894 |
-
);
|
895 |
-
|
896 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
897 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
898 |
-
if (! $result ['isValidToken']) {
|
899 |
-
$this->sendResponse ( 401, json_encode ( array (
|
900 |
-
'error' => true,
|
901 |
-
'message' => 'Unauthorized'
|
902 |
-
) ) );
|
903 |
-
} else {
|
904 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
905 |
-
}
|
906 |
-
}
|
907 |
-
break;
|
908 |
-
|
909 |
-
case "cancel_coupon" :
|
910 |
-
if ($this->get_request_method () != "POST") {
|
911 |
-
$this->sendResponse ( 400, json_encode ( array (
|
912 |
-
'error' => true,
|
913 |
-
'message' => 'Bad Request'
|
914 |
-
) ) );
|
915 |
-
} else {
|
916 |
-
$requestData = json_encode ( array (
|
917 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
918 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
919 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
920 |
-
'token' => $this->_request ['token'],
|
921 |
-
'quote_id' => ( int ) $this->_request ['quote_id']
|
922 |
-
) );
|
923 |
-
$resourceUrl = "$apiUrl/coupon/cancel/";
|
924 |
-
$headers = array (
|
925 |
-
'Content-Type' => 'application/json',
|
926 |
-
'Accept' => '*/*'
|
927 |
-
);
|
928 |
-
|
929 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_PUT, $headers );
|
930 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
931 |
-
if (! $result ['isValidToken']) {
|
932 |
-
$this->sendResponse ( 401, json_encode ( array (
|
933 |
-
'error' => true,
|
934 |
-
'message' => 'Unauthorized'
|
935 |
-
) ) );
|
936 |
-
} else {
|
937 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
938 |
-
}
|
939 |
-
}
|
940 |
-
break;
|
941 |
-
|
942 |
-
case "add_address_tocart" :
|
943 |
-
if ($this->get_request_method () != "POST") {
|
944 |
-
$this->sendResponse ( 400, json_encode ( array (
|
945 |
-
'error' => true,
|
946 |
-
'message' => 'Bad Request'
|
947 |
-
) ) );
|
948 |
-
} else {
|
949 |
-
$requestData = json_encode ( array (
|
950 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
951 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
952 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
953 |
-
'token' => $this->_request ['token'],
|
954 |
-
'quote_id' => ( int ) $this->_request ['quote_id'],
|
955 |
-
'billing_address_id' => ( int ) $this->_request ['billing_address_id'],
|
956 |
-
'shipping_address_id' => ( int ) $this->_request ['shipping_address_id']
|
957 |
-
) );
|
958 |
-
$headers = array (
|
959 |
-
'Content-Type' => 'application/json',
|
960 |
-
'Accept' => '*/*'
|
961 |
-
);
|
962 |
-
$resourceUrl = "$apiUrl/cart_address/add/";
|
963 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
964 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
965 |
-
if (! $result ['isValidToken']) {
|
966 |
-
$this->sendResponse ( 401, json_encode ( array (
|
967 |
-
'error' => true,
|
968 |
-
'message' => 'Unauthorized'
|
969 |
-
) ) );
|
970 |
-
} else {
|
971 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
972 |
-
}
|
973 |
-
}
|
974 |
-
break;
|
975 |
-
|
976 |
-
case "add_shipping_payment_tocart" :
|
977 |
-
|
978 |
-
if ($this->get_request_method () != "POST") {
|
979 |
-
$this->sendResponse ( 400, json_encode ( array (
|
980 |
-
'error' => true,
|
981 |
-
'message' => 'Bad Request'
|
982 |
-
) ) );
|
983 |
-
} else {
|
984 |
-
$requestData = json_encode ( array (
|
985 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
986 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
987 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
988 |
-
'token' => $this->_request ['token'],
|
989 |
-
'quote_id' => ( int ) $this->_request ['quote_id'],
|
990 |
-
'shipping_method' => $this->_request ['shipping_method'],
|
991 |
-
'payment_method' => $this->_request ['payment_method']
|
992 |
-
) );
|
993 |
-
$headers = array (
|
994 |
-
'Content-Type' => 'application/json',
|
995 |
-
'Accept' => '*/*'
|
996 |
-
);
|
997 |
-
$oauthClient->fetch ( "$apiUrl/cart/add_shipping_payment/", $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
998 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
999 |
-
if (! $result ['isValidToken']) {
|
1000 |
-
$this->sendResponse ( 401, json_encode ( array (
|
1001 |
-
'error' => true,
|
1002 |
-
'message' => 'Unauthorized'
|
1003 |
-
) ) );
|
1004 |
-
} else {
|
1005 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
1006 |
-
}
|
1007 |
-
}
|
1008 |
-
break;
|
1009 |
-
case "place_order" :
|
1010 |
-
|
1011 |
-
if ($this->get_request_method () != "POST") {
|
1012 |
-
$this->sendResponse ( 400, json_encode ( array (
|
1013 |
-
'error' => true,
|
1014 |
-
'message' => 'Bad Request'
|
1015 |
-
) ) );
|
1016 |
-
} else {
|
1017 |
-
$requestData = json_encode ( array (
|
1018 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
1019 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
1020 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1021 |
-
'token' => $this->_request ['token'],
|
1022 |
-
'quote_id' => ( int ) $this->_request ['quote_id'],
|
1023 |
-
'shipping_method' => $this->_request ['shipping_method'],
|
1024 |
-
'payment_method' => $this->_request ['payment_method']
|
1025 |
-
) );
|
1026 |
-
$headers = array (
|
1027 |
-
'Content-Type' => 'application/json',
|
1028 |
-
'Accept' => '*/*'
|
1029 |
-
);
|
1030 |
-
$resourceUrl = "$apiUrl/place_order/";
|
1031 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
1032 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1033 |
-
if (! $result ['isValidToken']) {
|
1034 |
-
$this->sendResponse ( 401, json_encode ( array (
|
1035 |
-
'error' => true,
|
1036 |
-
'message' => 'Unauthorized'
|
1037 |
-
) ) );
|
1038 |
-
} else {
|
1039 |
-
|
1040 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
1041 |
-
}
|
1042 |
-
}
|
1043 |
-
break;
|
1044 |
-
|
1045 |
-
case "paypal_standard" :
|
1046 |
-
|
1047 |
-
if ($this->get_request_method () != "POST") {
|
1048 |
-
$this->sendResponse ( 400, json_encode ( array (
|
1049 |
-
'error' => true,
|
1050 |
-
'message' => 'Bad Request'
|
1051 |
-
) ) );
|
1052 |
-
} else {
|
1053 |
-
$requestData = (array (
|
1054 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
1055 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
1056 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1057 |
-
'token' => $this->_request ['token'],
|
1058 |
-
'quote_id' => ( int ) $this->_request ['quote_id'],
|
1059 |
-
'shipping_method' => $this->_request ['shipping_method'],
|
1060 |
-
'payment_method' => $this->_request ['payment_method']
|
1061 |
-
));
|
1062 |
-
$headers = array (
|
1063 |
-
'Content-Type' => 'application/json',
|
1064 |
-
'Accept' => '*/*'
|
1065 |
-
);
|
1066 |
-
$resourceUrl = "$apiUrl/paypal_standard/place_order/";
|
1067 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1068 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1069 |
-
if (! $result ['isValidToken']) {
|
1070 |
-
$this->sendResponse ( 401, json_encode ( array (
|
1071 |
-
'error' => true,
|
1072 |
-
'message' => 'Unauthorized'
|
1073 |
-
) ) );
|
1074 |
-
} else {
|
1075 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
1076 |
-
}
|
1077 |
-
}
|
1078 |
-
break;
|
1079 |
-
|
1080 |
-
case "myorders_list" :
|
1081 |
-
if ($this->get_request_method () != "POST") {
|
1082 |
-
$this->sendResponse ( 400, json_encode ( array (
|
1083 |
-
'error' => true,
|
1084 |
-
'message' => 'Bad Request'
|
1085 |
-
) ) );
|
1086 |
-
} else {
|
1087 |
-
$page = (( int ) $this->_request ['page'] > 0 ? ( int ) $this->_request ['page'] : 1);
|
1088 |
-
$limit = (( int ) $this->_request ['limit'] > 0 ? ( int ) $this->_request ['limit'] : 10);
|
1089 |
-
$requestData = (array (
|
1090 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
1091 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
1092 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1093 |
-
'token' => $this->_request ['token'],
|
1094 |
-
'page' => $page,
|
1095 |
-
'limit' => $limit
|
1096 |
-
));
|
1097 |
-
$headers = array (
|
1098 |
-
'Content-Type' => 'application/json',
|
1099 |
-
'Accept' => '*/*'
|
1100 |
-
);
|
1101 |
-
$oauthClient->fetch ( "$apiUrl/myorders/", $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1102 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1103 |
-
$result1 = json_decode ( $result, true );
|
1104 |
-
if (! $result1 ['isValidToken']) {
|
1105 |
-
$this->sendResponse ( 401, json_encode ( array (
|
1106 |
-
'error' => true,
|
1107 |
-
'message' => 'Unauthorized'
|
1108 |
-
) ) );
|
1109 |
-
} else {
|
1110 |
-
|
1111 |
-
$this->sendResponse ( 200, (($result)) );
|
1112 |
-
}
|
1113 |
-
}
|
1114 |
-
break;
|
1115 |
-
|
1116 |
-
case "myorder_detail" :
|
1117 |
-
if ($this->get_request_method () != "POST") {
|
1118 |
-
$this->sendResponse ( 400, json_encode ( array (
|
1119 |
-
'error' => true,
|
1120 |
-
'message' => 'Bad Request'
|
1121 |
-
) ) );
|
1122 |
-
} else {
|
1123 |
-
$requestData = (array (
|
1124 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
1125 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
1126 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1127 |
-
'token' => $this->_request ['token'],
|
1128 |
-
'id' => ( int ) $this->_request ['order_id']
|
1129 |
-
));
|
1130 |
-
$headers = array (
|
1131 |
-
'Content-Type' => 'application/json',
|
1132 |
-
'Accept' => '*/*'
|
1133 |
-
);
|
1134 |
-
$oauthClient->fetch ( "$apiUrl/myorder_detail/", $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1135 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1136 |
-
$result1 = json_decode ( $result, true );
|
1137 |
-
if (! $result1 ['isValidToken']) {
|
1138 |
-
$this->sendResponse ( 401, json_encode ( array (
|
1139 |
-
'error' => true,
|
1140 |
-
'message' => 'Unauthorized'
|
1141 |
-
) ) );
|
1142 |
-
} else {
|
1143 |
-
|
1144 |
-
$this->sendResponse ( 200, ($result) );
|
1145 |
-
}
|
1146 |
-
}
|
1147 |
-
break;
|
1148 |
-
|
1149 |
-
case "add_wishlist" :
|
1150 |
-
if ($this->get_request_method () != "POST") {
|
1151 |
-
$this->sendResponse ( 400, json_encode ( array (
|
1152 |
-
'error' => true,
|
1153 |
-
'message' => 'Bad Request'
|
1154 |
-
) ) );
|
1155 |
-
} else {
|
1156 |
-
$requestData = json_encode ( array (
|
1157 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
1158 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
1159 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1160 |
-
'token' => $this->_request ['token'],
|
1161 |
-
'product_id' => ( int ) $this->_request ['product_id'],
|
1162 |
-
'qty' => ( int ) $this->_request ['qty']
|
1163 |
-
) );
|
1164 |
-
$headers = array (
|
1165 |
-
'Content-Type' => 'application/json',
|
1166 |
-
'Accept' => '*/*'
|
1167 |
-
);
|
1168 |
-
$resourceUrl = "$apiUrl//wishlist/add/";
|
1169 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
1170 |
-
|
1171 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1172 |
-
|
1173 |
-
if (! $result ['isValidToken']) {
|
1174 |
-
$this->sendResponse ( 401, json_encode ( array (
|
1175 |
-
'error' => true,
|
1176 |
-
'message' => 'Unauthorized'
|
1177 |
-
) ) );
|
1178 |
-
} else {
|
1179 |
-
|
1180 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
1181 |
-
}
|
1182 |
-
}
|
1183 |
-
break;
|
1184 |
-
case "wishlist_list" :
|
1185 |
-
if ($this->get_request_method () != "POST") {
|
1186 |
-
$this->sendResponse ( 400, json_encode ( array (
|
1187 |
-
'error' => true,
|
1188 |
-
'message' => 'Bad Request'
|
1189 |
-
) ) );
|
1190 |
-
} else {
|
1191 |
-
$requestData = (array (
|
1192 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
1193 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
1194 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1195 |
-
'token' => $this->_request ['token'],
|
1196 |
-
'page' => ( int ) $this->_request ['page'],
|
1197 |
-
'limit' => ( int ) $this->_request ['limit'],
|
1198 |
-
'image_size' => (int) $this->_request ['image_size']
|
1199 |
-
));
|
1200 |
-
$headers = array (
|
1201 |
-
'Content-Type' => 'application/json',
|
1202 |
-
'Accept' => '*/*'
|
1203 |
-
);
|
1204 |
-
$resourceUrl = "$apiUrl/wishlist/productlist/";
|
1205 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1206 |
-
|
1207 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1208 |
-
if (! $result ['isValidToken']) {
|
1209 |
-
$this->sendResponse ( 401, json_encode ( array (
|
1210 |
-
'error' => true,
|
1211 |
-
'message' => 'Unauthorized'
|
1212 |
-
) ) );
|
1213 |
-
} else {
|
1214 |
-
|
1215 |
-
$this->sendResponse ( 200, ($result) );
|
1216 |
-
}
|
1217 |
-
}
|
1218 |
-
break;
|
1219 |
-
|
1220 |
-
case "delete_wishlist" :
|
1221 |
-
if ($this->get_request_method () != "DELETE") {
|
1222 |
-
$this->sendResponse ( 400, json_encode ( array (
|
1223 |
-
'error' => true,
|
1224 |
-
'message' => 'Bad Request'
|
1225 |
-
) ) );
|
1226 |
-
} else {
|
1227 |
-
|
1228 |
-
$storeId = $this->_request ['store_id'];
|
1229 |
-
$websiteId = $this->_request ['website_id'];
|
1230 |
-
|
1231 |
-
if ($this->_request ['customer_id'] && $this->_request ['customer_id'] != '') {
|
1232 |
-
$customerId = $this->_request ['customer_id'];
|
1233 |
-
} else {
|
1234 |
-
$customerId = '';
|
1235 |
-
}
|
1236 |
-
|
1237 |
-
if ($this->_request ['product_id'] && $this->_request ['product_id'] != '') {
|
1238 |
-
$productId = $this->_request ['product_id'];
|
1239 |
-
} else {
|
1240 |
-
$productId = '';
|
1241 |
-
}
|
1242 |
-
$token = $this->_request ['token'];
|
1243 |
-
|
1244 |
-
$resourceUrl = "$apiUrl/wishlist/delete/token/$token/product_id/$productId/customer_id/$customerId/store_id/$storeId/website_id/$websiteId/";
|
1245 |
-
$headers = array (
|
1246 |
-
'Content-Type' => 'application/json',
|
1247 |
-
'Accept' => '*/*'
|
1248 |
-
);
|
1249 |
-
$oauthClient->fetch ( $resourceUrl, '', OAUTH_HTTP_METHOD_DELETE, $headers );
|
1250 |
-
|
1251 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1252 |
-
if (! $result ['isValidToken']) {
|
1253 |
-
$this->sendResponse ( 401, json_encode ( array (
|
1254 |
-
'error' => true,
|
1255 |
-
'message' => 'Unauthorized'
|
1256 |
-
) ) );
|
1257 |
-
} else {
|
1258 |
-
|
1259 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
1260 |
-
}
|
1261 |
-
}
|
1262 |
-
break;
|
1263 |
-
|
1264 |
-
case "add_review" :
|
1265 |
-
if ($this->get_request_method () != "POST") {
|
1266 |
-
$this->sendResponse ( 400, json_encode ( array (
|
1267 |
-
'error' => true,
|
1268 |
-
'message' => 'Bad Request'
|
1269 |
-
) ) );
|
1270 |
-
} else {
|
1271 |
-
$requestData = json_encode ( array (
|
1272 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
1273 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
1274 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1275 |
-
'token' => $this->_request ['token'],
|
1276 |
-
'product_id' => ( int ) $this->_request ['product_id'],
|
1277 |
-
'customer_name' => $this->_request ['customer_name'],
|
1278 |
-
'review_title' => $this->_request ['review_title'],
|
1279 |
-
'review_description' => $this->_request ['review_description'],
|
1280 |
-
'review_status' => ( int ) $this->_request ['review_status'],
|
1281 |
-
'rating' => $this->_request ['rating']
|
1282 |
-
) );
|
1283 |
-
$headers = array (
|
1284 |
-
'Content-Type' => 'application/json',
|
1285 |
-
'Accept' => '*/*'
|
1286 |
-
);
|
1287 |
-
$resourceUrl = "$apiUrl/add/reviews/";
|
1288 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
1289 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1290 |
-
if (! $result ['isValidToken']) {
|
1291 |
-
$this->sendResponse ( 401, json_encode ( array (
|
1292 |
-
'error' => true,
|
1293 |
-
'message' => 'Unauthorized'
|
1294 |
-
) ) );
|
1295 |
-
} else {
|
1296 |
-
|
1297 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
1298 |
-
}
|
1299 |
-
}
|
1300 |
-
break;
|
1301 |
-
|
1302 |
-
case "reviews_list" :
|
1303 |
-
if ($this->get_request_method () != "GET") {
|
1304 |
-
$this->sendResponse ( 400, json_encode ( array (
|
1305 |
-
'error' => true,
|
1306 |
-
'message' => 'Bad Request'
|
1307 |
-
) ) );
|
1308 |
-
} else {
|
1309 |
-
$requestData = (array (
|
1310 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
1311 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
1312 |
-
'product_id' => ( int ) $this->_request ['product_id'],
|
1313 |
-
'page' => ( int ) $this->_request ['page'],
|
1314 |
-
'limit' => ( int ) $this->_request ['limit']
|
1315 |
-
));
|
1316 |
-
$headers = array (
|
1317 |
-
'Content-Type' => 'application/json',
|
1318 |
-
'Accept' => '*/*'
|
1319 |
-
);
|
1320 |
-
$resourceUrl = "$apiUrl/reviews/list/";
|
1321 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1322 |
-
$result = $oauthClient->getLastResponse ();
|
1323 |
-
$this->sendResponse ( 200, ($result) );
|
1324 |
-
}
|
1325 |
-
break;
|
1326 |
|
1327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1328 |
|
1329 |
-
|
1330 |
-
|
1331 |
-
|
1332 |
-
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
1349 |
-
|
1350 |
-
|
1351 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1352 |
|
1353 |
-
|
1354 |
-
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
-
|
1359 |
-
|
1360 |
-
|
1361 |
-
|
1362 |
-
|
1363 |
-
|
1364 |
-
|
1365 |
-
|
1366 |
-
|
1367 |
-
|
1368 |
-
|
1369 |
-
|
1370 |
-
|
1371 |
-
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
1376 |
-
|
1377 |
-
|
1378 |
-
|
1379 |
-
|
1380 |
-
|
1381 |
-
|
1382 |
-
|
1383 |
-
|
1384 |
-
|
1385 |
-
|
1386 |
-
|
1387 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
1388 |
-
}
|
1389 |
-
}
|
1390 |
-
break;
|
1391 |
-
|
1392 |
-
case "bulk_add_tocart" :
|
1393 |
-
|
1394 |
-
if ($this->get_request_method () != "POST") {
|
1395 |
-
$this->sendResponse ( 400, json_encode ( array (
|
1396 |
-
'error' => true,
|
1397 |
-
'message' => 'Bad Request'
|
1398 |
-
) ) );
|
1399 |
-
} else {
|
1400 |
-
$requestData = json_encode ( array (
|
1401 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
1402 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
1403 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1404 |
-
'token' => $this->_request ['token'],
|
1405 |
-
'currencyCode' => $this->_request ['currencyCode'],
|
1406 |
-
'detail' => json_decode($this->_request ['detail']),
|
1407 |
-
|
1408 |
-
) );
|
1409 |
-
|
1410 |
-
$resourceUrl = "$apiUrl/cart/bulk_add/";
|
1411 |
-
$headers = array (
|
1412 |
-
'Content-Type' => 'application/json',
|
1413 |
-
'Accept' => '*/*'
|
1414 |
-
);
|
1415 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
1416 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1417 |
-
if (! $result ['isValidToken']) {
|
1418 |
-
$this->sendResponse ( 401, json_encode ( array (
|
1419 |
-
'error' => true,
|
1420 |
-
'message' => 'Unauthorized'
|
1421 |
-
) ) );
|
1422 |
-
} else {
|
1423 |
-
|
1424 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
1425 |
-
}
|
1426 |
-
}
|
1427 |
-
break;
|
1428 |
-
|
1429 |
-
case "bulk_update_cart" :
|
1430 |
-
|
1431 |
-
if ($this->get_request_method () != "POST") {
|
1432 |
-
$this->sendResponse ( 400, json_encode ( array (
|
1433 |
-
'error' => true,
|
1434 |
-
'message' => 'Bad Request'
|
1435 |
-
) ) );
|
1436 |
-
} else {
|
1437 |
-
$requestData = json_encode ( array (
|
1438 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
1439 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
1440 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1441 |
-
'token' => $this->_request ['token'],
|
1442 |
-
'quote_id' => ( int ) $this->_request ['quote_id'],
|
1443 |
-
'currencyCode' => $this->_request ['currencyCode'],
|
1444 |
-
'detail' => json_decode($this->_request ['detail']),
|
1445 |
-
|
1446 |
-
) );
|
1447 |
-
|
1448 |
-
$resourceUrl = "$apiUrl/cart/bulk_update/";
|
1449 |
-
$headers = array (
|
1450 |
-
'Content-Type' => 'application/json',
|
1451 |
-
'Accept' => '*/*'
|
1452 |
-
);
|
1453 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_PUT, $headers );
|
1454 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1455 |
-
if (! $result ['isValidToken']) {
|
1456 |
-
$this->sendResponse ( 401, json_encode ( array (
|
1457 |
-
'error' => true,
|
1458 |
-
'message' => 'Unauthorized'
|
1459 |
-
) ) );
|
1460 |
-
} else {
|
1461 |
-
|
1462 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
1463 |
-
}
|
1464 |
-
}
|
1465 |
-
break;
|
1466 |
-
|
1467 |
-
case "cart_add_address" :
|
1468 |
-
if ($this->get_request_method () != "POST") {
|
1469 |
-
$this->sendResponse ( 400, json_encode ( array (
|
1470 |
-
'error' => true,
|
1471 |
-
'message' => 'Bad Request'
|
1472 |
-
) ) );
|
1473 |
-
} else {
|
1474 |
-
$requestData = json_encode ( array (
|
1475 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
1476 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
1477 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1478 |
-
'token' => $this->_request ['token'],
|
1479 |
-
'quote_id' => ( int ) $this->_request ['quote_id'],
|
1480 |
-
'billing_address_id' => ( int ) $this->_request ['billing_address_id'],
|
1481 |
-
'shipping_address_id' => ( int ) $this->_request ['shipping_address_id']
|
1482 |
-
) );
|
1483 |
-
$headers = array (
|
1484 |
-
'Content-Type' => 'application/json',
|
1485 |
-
'Accept' => '*/*'
|
1486 |
-
);
|
1487 |
-
$resourceUrl = "$apiUrl/cart_add_address/";
|
1488 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
1489 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1490 |
-
if (! $result ['isValidToken']) {
|
1491 |
-
$this->sendResponse ( 401, json_encode ( array (
|
1492 |
-
'error' => true,
|
1493 |
-
'message' => 'Unauthorized'
|
1494 |
-
) ) );
|
1495 |
-
} else {
|
1496 |
-
|
1497 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
1498 |
-
}
|
1499 |
-
}
|
1500 |
-
break;
|
1501 |
-
|
1502 |
-
case "clear_wishlist" :
|
1503 |
-
|
1504 |
-
if ($this->get_request_method () != "POST") {
|
1505 |
-
$this->sendResponse ( 400, json_encode ( array (
|
1506 |
-
'error' => true,
|
1507 |
-
'message' => 'Bad Request'
|
1508 |
-
) ) );
|
1509 |
-
} else {
|
1510 |
-
|
1511 |
-
$requestData = json_encode ( array (
|
1512 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
1513 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
1514 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1515 |
-
'token' => $this->_request ['token'],
|
1516 |
-
) );
|
1517 |
-
|
1518 |
-
$resourceUrl = "$apiUrl/wishlist/clear/";
|
1519 |
-
$headers = array (
|
1520 |
-
'Content-Type' => 'application/json',
|
1521 |
-
'Accept' => '*/*'
|
1522 |
-
);
|
1523 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_PUT, $headers );
|
1524 |
-
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1525 |
-
if (! $result ['isValidToken']) {
|
1526 |
-
$this->sendResponse ( 401, json_encode ( array (
|
1527 |
-
'error' => true,
|
1528 |
-
'message' => 'Unauthorized'
|
1529 |
-
) ) );
|
1530 |
-
} else {
|
1531 |
-
$this->sendResponse ( 200, json_encode ( $result ) );
|
1532 |
-
}
|
1533 |
-
}
|
1534 |
-
break;
|
1535 |
|
1536 |
-
|
1537 |
-
|
1538 |
-
|
1539 |
-
|
1540 |
-
|
1541 |
-
|
1542 |
-
|
1543 |
-
|
1544 |
-
|
1545 |
-
|
1546 |
-
|
1547 |
-
|
1548 |
-
|
1549 |
-
|
1550 |
-
|
1551 |
-
|
1552 |
-
|
1553 |
-
|
1554 |
-
|
1555 |
-
|
1556 |
-
|
1557 |
-
|
1558 |
-
|
1559 |
-
|
1560 |
-
|
1561 |
-
|
1562 |
-
|
1563 |
-
|
1564 |
-
|
1565 |
-
|
1566 |
-
|
1567 |
-
|
1568 |
-
|
1569 |
-
if ($this->get_request_method () != "POST") {
|
1570 |
-
$this->sendResponse ( 400, json_encode ( array (
|
1571 |
-
'error' => true,
|
1572 |
-
'message' => 'Bad Request'
|
1573 |
-
) ) );
|
1574 |
-
} else {
|
1575 |
-
$requestData = json_encode ( array (
|
1576 |
-
'website_id' => ( int ) $this->_request ['website_id'],
|
1577 |
-
'store_id' => ( int ) $this->_request ['store_id'],
|
1578 |
-
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1579 |
-
'device_token' => $this->_request ['device_token'],
|
1580 |
-
'device_type' => $this->_request ['device_type']
|
1581 |
-
|
1582 |
-
) );
|
1583 |
-
|
1584 |
-
$resourceUrl = "$apiUrl/customer/gcmtoken_update/";
|
1585 |
-
$headers = array (
|
1586 |
-
'Content-Type' => 'application/json',
|
1587 |
-
'Accept' => '*/*'
|
1588 |
-
);
|
1589 |
-
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_PUT, $headers );
|
1590 |
-
$this->sendResponse ( 200, $oauthClient->getLastResponse());
|
1591 |
-
}
|
1592 |
-
break;
|
1593 |
-
|
1594 |
-
default :
|
1595 |
-
$this->sendResponse ( 405, json_encode ( array (
|
1596 |
-
'error' => true,
|
1597 |
-
'message' => 'Method Not Allowed'
|
1598 |
) ) );
|
1599 |
-
|
1600 |
-
|
1601 |
-
|
1602 |
-
|
1603 |
-
|
1604 |
-
|
1605 |
-
|
1606 |
-
|
1607 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1608 |
'error' => true,
|
1609 |
-
'message' =>
|
1610 |
-
|
1611 |
-
|
1612 |
}
|
1613 |
-
|
|
|
1614 |
$errorMessage = json_decode ( $e->lastResponse );
|
1615 |
$error ['message'] = $errorMessage->messages->error [0]->message;
|
1616 |
$error ['code'] = $errorMessage->messages->error [0]->code;
|
|
|
1617 |
$this->sendResponse ( $error ['code'], json_encode ( array (
|
1618 |
-
|
1619 |
-
|
1620 |
-
|
1621 |
) ) );
|
1622 |
-
|
1623 |
-
|
1624 |
-
|
1625 |
-
|
1626 |
-
|
1627 |
-
|
1628 |
-
|
1629 |
-
|
1630 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1631 |
}
|
1632 |
// instantiated Library
|
1633 |
$api = new API ();
|
10 |
* @license http://www.apptha.com/LICENSE.txt Open Software License ("OSL") v. 3.0
|
11 |
|
12 |
*/
|
|
|
13 |
require_once ("Rest.inc.php");
|
14 |
$mageFilename = '../app/Mage.php';
|
15 |
require_once $mageFilename;
|
16 |
class API extends REST {
|
17 |
+
public $data = "";
|
18 |
+
public function __construct() {
|
19 |
+
parent::__construct (); // Init parent constructor
|
20 |
+
}
|
21 |
+
|
22 |
+
// Public method for access api.
|
23 |
+
// This method dynamically call the method based on the query string
|
24 |
+
public function processApi() {
|
25 |
+
$func = strtolower ( trim ( str_replace ( "/", "", $_REQUEST ['req'] ) ) );
|
26 |
+
if (( int ) method_exists ( $this, $func ) > 0)
|
27 |
+
$this->$func ();
|
28 |
+
else
|
29 |
+
$this->sendResponse ( 404, json_encode ( array (
|
30 |
+
'error' => true,
|
31 |
+
'message' => 'Not Found'
|
32 |
+
) ) );
|
33 |
+
// If the method not exist with in this class, response would be "Page not found".
|
34 |
+
}
|
35 |
+
private function api() {
|
36 |
+
// $callbackUrl is a path to your file with OAuth authentication example for the Admin user
|
37 |
+
$baseUrl = Mage::getBaseUrl ( Mage_Core_Model_Store::URL_TYPE_WEB );
|
38 |
+
|
39 |
+
$callbackUrl = $baseUrl . "rest/api.php";
|
40 |
+
$temporaryCredentialsRequestUrl = $baseUrl . "oauth/initiate?oauth_callback=" . urlencode ( $callbackUrl );
|
41 |
+
$adminAuthorizationUrl = $baseUrl . 'oauth/authorize';
|
42 |
+
$accessTokenRequestUrl = $baseUrl . 'oauth/token';
|
43 |
+
$apiUrl = $baseUrl . 'api/rest';
|
44 |
+
// get rest key and secretkey
|
45 |
+
$consumerKey = Mage::getStoreConfig ( 'contus/mcomapp_about/rest_apikey' );
|
46 |
+
$consumerSecret = Mage::getStoreConfig ( 'contus/mcomapp_about/rest_secretkey' );
|
47 |
+
|
48 |
+
session_start ();
|
49 |
+
|
50 |
+
try {
|
51 |
+
$oauthClient = new OAuth ( $consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI );
|
52 |
+
$oauthClient->enableDebug ();
|
53 |
+
|
54 |
+
if (! isset ( $_GET ['oauth_token'] )) {
|
55 |
+
$requestToken = $oauthClient->getRequestToken ( $temporaryCredentialsRequestUrl );
|
56 |
+
$_SESSION ['secret'] = $requestToken ['oauth_token_secret'];
|
57 |
+
$_SESSION ['token'] = $requestToken ['oauth_token'];
|
58 |
+
$_SESSION ['state'] = 1;
|
59 |
+
}
|
60 |
+
|
61 |
+
$oauthClient->setToken ( $_SESSION ['token'], $_SESSION ['secret'] );
|
62 |
+
|
63 |
+
$action = $this->_request ['action'];
|
64 |
+
try {
|
65 |
+
switch ($action) {
|
66 |
+
|
67 |
+
case "splashpage" :
|
68 |
+
|
69 |
+
if ($this->get_request_method () != "GET") {
|
70 |
+
$this->sendResponse ( 400, json_encode ( array (
|
71 |
+
'error' => true,
|
72 |
+
'message' => 'Bad Request'
|
73 |
+
) ) );
|
74 |
+
} else {
|
75 |
+
|
76 |
+
$headers = array (
|
77 |
+
'Content-Type' => 'application/json',
|
78 |
+
'Accept' => '*/*'
|
79 |
+
);
|
80 |
+
$resourceUrl = "$apiUrl/splashpage/";
|
81 |
+
$oauthClient->fetch ( $resourceUrl, array (), OAUTH_HTTP_METHOD_GET, $headers );
|
82 |
+
$result = $oauthClient->getLastResponse ();
|
83 |
+
$this->sendResponse ( 200, json_decode ( $result ) );
|
84 |
+
}
|
85 |
+
break;
|
86 |
+
|
87 |
+
case "homepage" :
|
88 |
+
|
89 |
+
if ($this->get_request_method () != "GET") {
|
90 |
+
$this->sendResponse ( 400, json_encode ( array (
|
91 |
+
'error' => true,
|
92 |
+
'message' => 'Bad Request'
|
93 |
+
) ) );
|
94 |
+
} else {
|
95 |
+
$requestData = array (
|
96 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
97 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
98 |
+
'image_size' => ( int ) $this->_request ['image_size'],
|
99 |
+
'city' => ( int ) $this->_request ['city']
|
100 |
+
);
|
101 |
+
$headers = array (
|
102 |
+
'Content-Type' => 'application/json',
|
103 |
+
'Accept' => '*/*'
|
104 |
+
);
|
105 |
+
$resourceUrl = "$apiUrl/homepage/";
|
106 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
107 |
+
$result = $oauthClient->getLastResponse ();
|
108 |
+
$this->sendResponse ( 200, json_decode ( $result ) );
|
109 |
+
}
|
110 |
+
break;
|
111 |
+
|
112 |
+
case "category_products" :
|
113 |
+
|
114 |
+
$requestData = array (
|
115 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
116 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
117 |
+
'page' => ( int ) $this->_request ['page'],
|
118 |
+
'limit' => ( int ) $this->_request ['limit'],
|
119 |
+
'category_id' => ( int ) $this->_request ['category_id'],
|
120 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
121 |
+
'orderby' => $this->_request ['orderby'],
|
122 |
+
'sortby' => $this->_request ['sortby'],
|
123 |
|
124 |
+
'filters' => $this->_request ['filters'],
|
125 |
+
'image_size' => ( int ) $this->_request ['image_size'],
|
126 |
+
'city' => ( int ) $this->_request ['city']
|
127 |
+
);
|
128 |
+
$headers = array (
|
129 |
+
'Content-Type' => 'application/json',
|
130 |
+
'Accept' => '*/*'
|
131 |
+
);
|
132 |
+
$resourceUrl = "$apiUrl/products_list/";
|
133 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
134 |
+
$result = $oauthClient->getLastResponse ();
|
135 |
+
|
136 |
+
$this->sendResponse ( 200, json_decode ( $result ) );
|
137 |
+
break;
|
138 |
+
|
139 |
+
case "productdetail" :
|
140 |
+
if ($this->get_request_method () != "GET") {
|
141 |
+
$this->sendResponse ( 400, json_encode ( array (
|
142 |
+
'error' => true,
|
143 |
+
'message' => 'Bad Request'
|
144 |
+
) ) );
|
145 |
+
} else {
|
146 |
+
|
147 |
+
$requestData = array (
|
148 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
149 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
150 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
151 |
+
'id' => ( int ) $this->_request ['product_id'],
|
152 |
+
'image_size' => ( int ) $this->_request ['image_size']
|
153 |
+
);
|
154 |
+
$headers = array (
|
155 |
+
'Content-Type' => 'application/json',
|
156 |
+
'Accept' => '*/*'
|
157 |
+
);
|
158 |
+
$resourceUrl = "$apiUrl/product_detail/";
|
159 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
160 |
+
$result = $oauthClient->getLastResponse ();
|
161 |
+
$this->sendResponse ( 200, ($result) );
|
162 |
+
}
|
163 |
+
break;
|
164 |
+
|
165 |
+
case "static_page" :
|
166 |
+
if ($this->get_request_method () != "GET") {
|
167 |
+
$this->sendResponse ( 400, json_encode ( array (
|
168 |
+
'error' => true,
|
169 |
+
'message' => 'Bad Request'
|
170 |
+
) ) );
|
171 |
+
} else {
|
172 |
+
|
173 |
+
$requestData = array (
|
174 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
175 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
176 |
+
'page_key' => $this->_request ['page_key']
|
177 |
+
);
|
178 |
+
$headers = array (
|
179 |
+
'Content-Type' => 'application/json',
|
180 |
+
'Accept' => '*/*'
|
181 |
+
);
|
182 |
+
$resourceUrl = "$apiUrl/staticpages";
|
183 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
184 |
+
$result = $oauthClient->getLastResponse ();
|
185 |
+
$this->sendResponse ( 200, json_decode ( $result ) );
|
186 |
+
}
|
187 |
+
break;
|
188 |
+
|
189 |
+
case "login" :
|
190 |
+
if ($this->get_request_method () != "POST") {
|
191 |
+
$this->sendResponse ( 400, json_encode ( array (
|
192 |
+
'error' => true,
|
193 |
+
'message' => 'Bad Request'
|
194 |
+
) ) );
|
195 |
+
} else {
|
196 |
+
|
197 |
+
$requestData = json_encode ( array (
|
198 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
199 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
200 |
+
'email' => $this->_request ['email'],
|
201 |
+
'password' => $this->_request ['login_signature'],
|
202 |
+
'device_token' => $this->_request ['device_token'],
|
203 |
+
'device_type' => $this->_request ['device_type']
|
204 |
+
) );
|
205 |
+
$headers = array (
|
206 |
+
'Content-Type' => 'application/json',
|
207 |
+
'Accept' => '*/*'
|
208 |
+
);
|
209 |
+
$resourceUrl = "$apiUrl/customer/login/";
|
210 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
211 |
+
$result = $oauthClient->getLastResponse ();
|
212 |
+
$this->sendResponse ( 200, ($result) );
|
213 |
+
}
|
214 |
+
break;
|
215 |
+
|
216 |
+
case "forgot_signature" :
|
217 |
+
|
218 |
+
if ($this->get_request_method () != "POST") {
|
219 |
+
$this->sendResponse ( 400, json_encode ( array (
|
220 |
+
'error' => true,
|
221 |
+
'message' => 'Bad Request'
|
222 |
+
) ) );
|
223 |
+
} else {
|
224 |
+
|
225 |
+
$requestData = json_encode ( array (
|
226 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
227 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
228 |
+
'email' => $this->_request ['email']
|
229 |
+
) );
|
230 |
+
$headers = array (
|
231 |
+
'Content-Type' => 'application/json',
|
232 |
+
'Accept' => '*/*'
|
233 |
+
);
|
234 |
+
$oauthClient->fetch ( "$apiUrl/customer/forgotpassword/", $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
235 |
+
$result = $oauthClient->getLastResponse ();
|
236 |
+
$this->sendResponse ( 200, ($result) );
|
237 |
+
}
|
238 |
+
break;
|
239 |
+
|
240 |
+
case "change_signature" :
|
241 |
+
if ($this->get_request_method () != "POST") {
|
242 |
+
$this->sendResponse ( 400, json_encode ( array (
|
243 |
+
'error' => true,
|
244 |
+
'message' => 'Bad Request'
|
245 |
+
) ) );
|
246 |
+
} else {
|
247 |
+
|
248 |
+
$requestData = json_encode ( array (
|
249 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
250 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
251 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
252 |
+
'old_password' => $this->_request ['old_signature'],
|
253 |
+
'new_password' => $this->_request ['new_signature'],
|
254 |
+
'token' => $this->_request ['token']
|
255 |
+
) );
|
256 |
+
$headers = array (
|
257 |
+
'Content-Type' => 'application/json',
|
258 |
+
'Accept' => '*/*'
|
259 |
+
);
|
260 |
+
$resourceUrl = "$apiUrl/customer/changepassword/";
|
261 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
262 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
263 |
+
|
264 |
+
if (! $result ['isValidToken']) {
|
265 |
+
$this->sendResponse ( 401, json_encode ( array (
|
266 |
+
'error' => true,
|
267 |
+
'message' => 'Unauthorized'
|
268 |
+
) ) );
|
269 |
+
} else {
|
270 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
271 |
+
}
|
272 |
+
}
|
273 |
+
break;
|
274 |
+
|
275 |
+
case "customer_register" :
|
276 |
+
|
277 |
+
if ($this->get_request_method () != "POST") {
|
278 |
+
$this->sendResponse ( 400, json_encode ( array (
|
279 |
+
'error' => true,
|
280 |
+
'message' => 'Bad Request'
|
281 |
+
) ) );
|
282 |
+
} else {
|
283 |
+
|
284 |
+
$requestData = json_encode ( array (
|
285 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
286 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
287 |
+
'email' => $this->_request ['email'],
|
288 |
+
'password' => $this->_request ['login_signature'],
|
289 |
+
'firstname' => $this->_request ['firstname'],
|
290 |
+
'lastname' => $this->_request ['lastname'],
|
291 |
+
'newsletter' => ( int ) $this->_request ['newsletter'],
|
292 |
+
'dob' => $this->_request ['dob'],
|
293 |
+
'group_id' => ( int ) $this->_request ['group_id'],
|
294 |
+
'device_token' => $this->_request ['device_token'],
|
295 |
+
'device_type' => $this->_request ['device_type']
|
296 |
+
) );
|
297 |
+
$headers = array (
|
298 |
+
'Content-Type' => 'application/json',
|
299 |
+
'Accept' => '*/*'
|
300 |
+
);
|
301 |
+
$oauthClient->fetch ( "$apiUrl/customer/register/", $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
302 |
+
$result = $oauthClient->getLastResponse ();
|
303 |
+
$this->sendResponse ( 200, ($result) );
|
304 |
+
}
|
305 |
+
break;
|
306 |
+
|
307 |
+
case "customer_update" :
|
308 |
+
|
309 |
+
if ($this->get_request_method () != "POST") {
|
310 |
+
$this->sendResponse ( 400, json_encode ( array (
|
311 |
+
'error' => true,
|
312 |
+
'message' => 'Bad Request'
|
313 |
+
) ) );
|
314 |
+
} else {
|
315 |
+
|
316 |
+
$requestData = json_encode ( array (
|
317 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
318 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
319 |
+
'email' => $this->_request ['email'],
|
320 |
+
'firstname' => $this->_request ['firstname'],
|
321 |
+
'lastname' => $this->_request ['lastname'],
|
322 |
+
'newsletter' => ( int ) $this->_request ['newsletter'],
|
323 |
+
'dob' => $this->_request ['dob'],
|
324 |
+
'token' => $this->_request ['token']
|
325 |
+
) );
|
326 |
+
|
327 |
+
$customerId = ( int ) $this->_request ['customer_id'];
|
328 |
+
$headers = array (
|
329 |
+
'Content-Type' => 'application/json',
|
330 |
+
'Accept' => '*/*'
|
331 |
+
);
|
332 |
+
$oauthClient->fetch ( "$apiUrl/customer/update/$customerId", $requestData, OAUTH_HTTP_METHOD_PUT, $headers );
|
333 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
334 |
+
if (! $result ['isValidToken']) {
|
335 |
+
$this->sendResponse ( 401, json_encode ( array (
|
336 |
+
'error' => true,
|
337 |
+
'message' => 'Unauthorized'
|
338 |
+
) ) );
|
339 |
+
} else {
|
340 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
341 |
+
}
|
342 |
+
}
|
343 |
+
break;
|
344 |
+
|
345 |
+
case "personal_detail" :
|
346 |
+
|
347 |
+
if ($this->get_request_method () != "POST") {
|
348 |
+
$this->sendResponse ( 400, json_encode ( array (
|
349 |
+
'error' => true,
|
350 |
+
'message' => 'Bad Request'
|
351 |
+
) ) );
|
352 |
+
} else {
|
353 |
+
|
354 |
+
$requestData = array (
|
355 |
+
'id' => ( int ) $this->_request ['customer_id'],
|
356 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
357 |
+
'token' => $this->_request ['token']
|
358 |
+
);
|
359 |
+
$headers = array (
|
360 |
+
'Content-Type' => 'application/json',
|
361 |
+
'Accept' => '*/*'
|
362 |
+
);
|
363 |
+
$resourceUrl = "$apiUrl/customer/detail/";
|
364 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
365 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
366 |
+
if (! $result ['isValidToken']) {
|
367 |
+
$this->sendResponse ( 401, json_encode ( array (
|
368 |
+
'error' => true,
|
369 |
+
'message' => 'Unauthorized'
|
370 |
+
) ) );
|
371 |
+
} else {
|
372 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
373 |
+
}
|
374 |
+
}
|
375 |
+
break;
|
376 |
+
|
377 |
+
case "social_login" :
|
378 |
+
|
379 |
+
if ($this->get_request_method () != "POST") {
|
380 |
+
$this->sendResponse ( 400, json_encode ( array (
|
381 |
+
'error' => true,
|
382 |
+
'message' => 'Bad Request'
|
383 |
+
) ) );
|
384 |
+
} else {
|
385 |
+
$requestData = json_encode ( array (
|
386 |
+
'email' => $this->_request ['email'],
|
387 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
388 |
+
'firstname' => $this->_request ['firstname'],
|
389 |
+
'lastname' => $this->_request ['lastname'],
|
390 |
+
'confirmation' => FALSE,
|
391 |
+
'newsletter' => $this->_request ['newsletter'],
|
392 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
393 |
+
'dob' => $this->_request ['dob'],
|
394 |
+
'device_token' => $this->_request ['device_token'],
|
395 |
+
'device_type' => $this->_request ['device_type']
|
396 |
+
) );
|
397 |
+
$headers = array (
|
398 |
+
'Content-Type' => 'application/json',
|
399 |
+
'Accept' => '*/*'
|
400 |
+
);
|
401 |
+
$resourceUrl = "$apiUrl/customer/social_login/";
|
402 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
403 |
+
$result = $oauthClient->getLastResponse ();
|
404 |
+
|
405 |
+
$this->sendResponse ( 200, ($result) );
|
406 |
+
}
|
407 |
+
break;
|
408 |
+
|
409 |
+
case "add_tocart" :
|
410 |
+
|
411 |
+
if ($this->get_request_method () != "POST") {
|
412 |
+
$this->sendResponse ( 400, json_encode ( array (
|
413 |
+
'error' => true,
|
414 |
+
'message' => 'Bad Request'
|
415 |
+
) ) );
|
416 |
+
} else {
|
417 |
+
$requestData = json_encode ( array (
|
418 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
419 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
420 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
421 |
+
'product_id' => ( int ) $this->_request ['product_id'],
|
422 |
+
'token' => $this->_request ['token'],
|
423 |
+
'quote_id' => ( int ) $this->_request ['quote_id'],
|
424 |
+
'qty' => ( int ) $this->_request ['qty'],
|
425 |
+
'currencyCode' => $this->_request ['currencyCode'],
|
426 |
+
'super_attribute' => json_decode ( $this->_request ['super_attribute'] ),
|
427 |
+
'links' => ($this->_request ['links']),
|
428 |
+
'custom_option' => json_decode ( $this->_request ['custom_option'] )
|
429 |
+
) );
|
430 |
+
|
431 |
+
$resourceUrl = "$apiUrl/cart/add/";
|
432 |
+
$headers = array (
|
433 |
+
'Content-Type' => 'application/json',
|
434 |
+
'Accept' => '*/*'
|
435 |
+
);
|
436 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
437 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
438 |
+
if (! $result ['isValidToken']) {
|
439 |
+
$this->sendResponse ( 401, json_encode ( array (
|
440 |
+
'error' => true,
|
441 |
+
'message' => 'Unauthorized'
|
442 |
+
) ) );
|
443 |
+
} else {
|
444 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
445 |
+
}
|
446 |
+
}
|
447 |
+
break;
|
448 |
+
case "cart_list" :
|
449 |
+
|
450 |
+
if ($this->get_request_method () != "POST") {
|
451 |
+
$this->sendResponse ( 400, json_encode ( array (
|
452 |
+
'error' => true,
|
453 |
+
'message' => 'Bad Request'
|
454 |
+
) ) );
|
455 |
+
} else {
|
456 |
+
|
457 |
+
$requestData = array (
|
458 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
459 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
460 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
461 |
+
'token' => $this->_request ['token']
|
462 |
+
);
|
463 |
+
|
464 |
+
$resourceUrl = "$apiUrl/cart/productlist/";
|
465 |
+
|
466 |
+
$headers = array (
|
467 |
+
'Content-Type' => 'application/json',
|
468 |
+
'Accept' => '*/*'
|
469 |
+
);
|
470 |
+
|
471 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
472 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
473 |
+
if (! $result ['isValidToken']) {
|
474 |
+
$this->sendResponse ( 401, json_encode ( array (
|
475 |
+
'error' => true,
|
476 |
+
'message' => 'Unauthorized'
|
477 |
+
) ) );
|
478 |
+
} else {
|
479 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
480 |
+
}
|
481 |
+
}
|
482 |
+
break;
|
483 |
+
|
484 |
+
case "update_cart" :
|
485 |
+
|
486 |
+
if ($this->get_request_method () != "POST") {
|
487 |
+
$this->sendResponse ( 400, json_encode ( array (
|
488 |
+
'error' => true,
|
489 |
+
'message' => 'Bad Request'
|
490 |
+
) ) );
|
491 |
+
} else {
|
492 |
+
$requestData = json_encode ( array (
|
493 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
494 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
495 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
496 |
+
'product_id' => ( int ) $this->_request ['product_id'],
|
497 |
+
'token' => $this->_request ['token'],
|
498 |
+
'quote_id' => ( int ) $this->_request ['quote_id'],
|
499 |
+
'qty' => ( int ) $this->_request ['qty'],
|
500 |
+
'currencyCode' => $this->_request ['currencyCode'],
|
501 |
+
'super_attribute' => json_decode ( $this->_request ['super_attribute'] ),
|
502 |
+
'custom_option' => json_decode ( $this->_request ['custom_option'] ),
|
503 |
+
'links' => ($this->_request ['links'])
|
504 |
+
) );
|
505 |
+
|
506 |
+
$resourceUrl = "$apiUrl/cart/update/";
|
507 |
+
$headers = array (
|
508 |
+
'Content-Type' => 'application/json',
|
509 |
+
'Accept' => '*/*'
|
510 |
+
);
|
511 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_PUT, $headers );
|
512 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
513 |
+
|
514 |
+
if (! $result ['isValidToken']) {
|
515 |
+
$this->sendResponse ( 401, json_encode ( array (
|
516 |
+
'error' => true,
|
517 |
+
'message' => 'Unauthorized'
|
518 |
+
) ) );
|
519 |
+
} else {
|
520 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
521 |
+
}
|
522 |
+
}
|
523 |
+
break;
|
524 |
+
case "deletefromcart" :
|
525 |
+
|
526 |
+
if ($this->get_request_method () != "DELETE") {
|
527 |
+
$this->sendResponse ( 400, json_encode ( array (
|
528 |
+
'error' => true,
|
529 |
+
'message' => 'Bad Request'
|
530 |
+
) ) );
|
531 |
+
} else {
|
532 |
+
|
533 |
+
if ($this->_request ['website_id'] && $this->_request ['website_id'] != '') {
|
534 |
+
$websiteId = $this->_request ['website_id'];
|
535 |
+
} else {
|
536 |
+
$websiteId = Mage::app ()->getWebsite ( 'base' )->getId ();
|
537 |
+
}
|
538 |
+
if ($this->_request ['store_id'] && $this->_request ['store_id'] != '') {
|
539 |
+
$storeId = $this->_request ['store_id'];
|
540 |
+
} else {
|
541 |
+
$storeId = Mage::app ()->getWebsite ( $websiteId )->getDefaultGroup ()->getDefaultStoreId ();
|
542 |
+
}
|
543 |
+
if ($this->_request ['quote_id'] && $this->_request ['quote_id'] != '') {
|
544 |
+
$quote_id = $this->_request ['quote_id']; // asc desc
|
545 |
+
} else {
|
546 |
+
$quote_id = '';
|
547 |
+
}
|
548 |
+
if ($this->_request ['product_id'] && $this->_request ['product_id'] != '') {
|
549 |
+
$product_id = $this->_request ['product_id'];
|
550 |
+
} else {
|
551 |
+
$product_id = '';
|
552 |
+
}
|
553 |
+
if ($this->_request ['customer_id'] && $this->_request ['customer_id'] != '') {
|
554 |
+
$customer_id = $this->_request ['customer_id'];
|
555 |
+
} else {
|
556 |
+
$customer_id = '';
|
557 |
+
}
|
558 |
+
if ($this->_request ['custom_option'] && $this->_request ['custom_option'] != '') {
|
559 |
+
$custom_option = ($this->_request ['custom_option']);
|
560 |
+
foreach ( (json_decode ( $custom_option )) as $key => $option ) {
|
561 |
+
if (is_string ( $option )) {
|
562 |
+
$option = str_replace ( ' ', '$$$$', $option );
|
563 |
+
}
|
564 |
+
$new_option [$key] = $option;
|
565 |
}
|
566 |
+
$custom_option = json_encode ( $new_option );
|
567 |
+
} else {
|
568 |
+
$custom_option = '';
|
569 |
+
}
|
570 |
+
|
571 |
+
if ($this->_request ['super_attribute'] && $this->_request ['super_attribute'] != '') {
|
572 |
+
$super_attribute = ($this->_request ['super_attribute']);
|
573 |
+
} else {
|
574 |
+
$super_attribute = '';
|
575 |
+
}
|
576 |
+
if ($this->_request ['links'] && $this->_request ['links'] != '') {
|
577 |
+
$links = ($this->_request ['links']);
|
578 |
+
} else {
|
579 |
+
$links = '';
|
580 |
+
}
|
581 |
+
|
582 |
+
$token = $this->_request ['token'];
|
583 |
+
$resourceUrl = "$apiUrl/cart/delete/links/" . $links . "/super_attribute/" . $super_attribute . "/custom_option/" . $custom_option . "/quote_id/" . $quote_id . "/product_id/" . $product_id . "/customer_id/" . $customer_id . "/store_id/" . $storeId . "/website_id/" . $websiteId . "/token/" . $token;
|
584 |
+
|
585 |
+
$headers = array (
|
586 |
+
'Content-Type' => 'application/json',
|
587 |
+
'Accept' => '*/*'
|
588 |
+
);
|
589 |
+
$oauthClient->fetch ( $resourceUrl, '', OAUTH_HTTP_METHOD_DELETE, $headers );
|
590 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
591 |
+
if (! $result ['isValidToken']) {
|
592 |
+
$this->sendResponse ( 401, json_encode ( array (
|
593 |
+
'error' => true,
|
594 |
+
'message' => 'Unauthorized'
|
595 |
+
) ) );
|
596 |
+
} else {
|
597 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
598 |
+
}
|
599 |
+
}
|
600 |
+
break;
|
601 |
+
|
602 |
+
case "cart_count" :
|
603 |
+
if ($this->get_request_method () != "POST") {
|
604 |
+
$this->sendResponse ( 400, json_encode ( array (
|
605 |
+
'error' => true,
|
606 |
+
'message' => 'Bad Request'
|
607 |
+
) ) );
|
608 |
+
} else {
|
609 |
+
|
610 |
+
$requestData = array (
|
611 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
612 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
613 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
614 |
+
'token' => $this->_request ['token']
|
615 |
+
);
|
616 |
+
$headers = array (
|
617 |
+
'Content-Type' => 'application/json',
|
618 |
+
'Accept' => '*/*'
|
619 |
+
);
|
620 |
+
|
621 |
+
$resourceUrl = "$apiUrl/cart/item_count/";
|
622 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
623 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
624 |
+
if (! $result ['isValidToken']) {
|
625 |
+
$this->sendResponse ( 401, json_encode ( array (
|
626 |
+
'error' => true,
|
627 |
+
'message' => 'Unauthorized'
|
628 |
+
) ) );
|
629 |
+
} else {
|
630 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
631 |
+
}
|
632 |
+
}
|
633 |
+
break;
|
634 |
+
case "searchproducts" :
|
635 |
+
$search_term = str_replace ( ' ', '%20', $this->_request ['search_term'] );
|
636 |
+
if ($this->get_request_method () != "GET") {
|
637 |
+
$this->sendResponse ( 400, json_encode ( array (
|
638 |
+
'error' => true,
|
639 |
+
'message' => 'Bad Request'
|
640 |
+
) ) );
|
641 |
+
} else {
|
642 |
+
$requestData = array (
|
643 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
644 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
645 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
646 |
+
'category_id' => ( int ) $this->_request ['category_id'],
|
647 |
+
|
648 |
+
'search_term' => $this->_request ['search_term'],
|
649 |
+
'page' => $this->_request ['page'],
|
650 |
+
'limit' => $this->_request ['limit'],
|
651 |
+
'image_size' => ( int ) $this->_request ['image_size'],
|
652 |
+
'city' => ( int ) $this->_request ['city']
|
653 |
+
);
|
654 |
+
$headers = array (
|
655 |
+
'Content-Type' => 'application/json',
|
656 |
+
'Accept' => '*/*'
|
657 |
+
);
|
658 |
+
$oauthClient->fetch ( "$apiUrl/search/products/", $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
659 |
+
|
660 |
+
$result = $oauthClient->getLastResponse ();
|
661 |
+
|
662 |
+
$this->sendResponse ( 200, json_decode ( $result ) );
|
663 |
+
}
|
664 |
+
break;
|
665 |
+
|
666 |
+
case "country" :
|
667 |
+
if ($this->get_request_method () != "GET") {
|
668 |
+
$this->sendResponse ( 400, json_encode ( array (
|
669 |
+
'error' => true,
|
670 |
+
'message' => 'Bad Request'
|
671 |
+
) ) );
|
672 |
+
} else {
|
673 |
+
$headers = array (
|
674 |
+
'Content-Type' => 'application/json',
|
675 |
+
'Accept' => '*/*'
|
676 |
+
);
|
677 |
+
|
678 |
+
$oauthClient->fetch ( "$apiUrl/countrycollection/", array (), OAUTH_HTTP_METHOD_GET, $headers );
|
679 |
+
$result = $oauthClient->getLastResponse ();
|
680 |
+
$result = $oauthClient->getLastResponse ();
|
681 |
+
|
682 |
+
$this->sendResponse ( 200, json_decode ( $result ) );
|
683 |
+
}
|
684 |
+
break;
|
685 |
+
|
686 |
+
case "state" :
|
687 |
+
if ($this->get_request_method () != "GET") {
|
688 |
+
$this->sendResponse ( 400, json_encode ( array (
|
689 |
+
'error' => true,
|
690 |
+
'message' => 'Bad Request'
|
691 |
+
) ) );
|
692 |
+
} else {
|
693 |
+
if ($this->_request ['countrycode'] && $this->_request ['countrycode'] != '') {
|
694 |
+
$countryCode = $this->_request ['countrycode'];
|
695 |
+
} else {
|
696 |
+
$countryCode = '';
|
697 |
+
}
|
698 |
+
$headers = array (
|
699 |
+
'Content-Type' => 'application/json',
|
700 |
+
'Accept' => '*/*'
|
701 |
+
);
|
702 |
+
$oauthClient->fetch ( "$apiUrl/statecollection/$countryCode", array (), OAUTH_HTTP_METHOD_GET, $headers );
|
703 |
+
$result = $oauthClient->getLastResponse ();
|
704 |
+
|
705 |
+
$this->sendResponse ( 200, json_decode ( $result ) );
|
706 |
+
}
|
707 |
+
break;
|
708 |
+
|
709 |
+
case "address_collection" :
|
710 |
+
if ($this->get_request_method () != "POST") {
|
711 |
+
$this->sendResponse ( 400, json_encode ( array (
|
712 |
+
'error' => true,
|
713 |
+
'message' => 'Bad Request'
|
714 |
+
) ) );
|
715 |
+
} else {
|
716 |
+
$requestData = array (
|
717 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
718 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
719 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
720 |
+
'token' => $this->_request ['token']
|
721 |
+
);
|
722 |
+
$headers = array (
|
723 |
+
'Content-Type' => 'application/json',
|
724 |
+
'Accept' => '*/*'
|
725 |
+
);
|
726 |
+
$oauthClient->fetch ( "$apiUrl/addressbook/", $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
727 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
728 |
+
$result1 = json_decode ( $result, true );
|
729 |
+
|
730 |
+
if (! $result1 ['isValidToken']) {
|
731 |
+
$this->sendResponse ( 401, json_encode ( array (
|
732 |
+
'error' => true,
|
733 |
+
'message' => 'Unauthorized'
|
734 |
+
) ) );
|
735 |
+
} else {
|
736 |
+
$this->sendResponse ( 200, ($result) );
|
737 |
+
}
|
738 |
+
}
|
739 |
+
break;
|
740 |
+
|
741 |
+
case "address_add" :
|
742 |
+
if ($this->get_request_method () != "POST") {
|
743 |
+
$this->sendResponse ( 400, json_encode ( array (
|
744 |
+
'error' => true,
|
745 |
+
'message' => 'Bad Request'
|
746 |
+
) ) );
|
747 |
+
} else {
|
748 |
+
$requestData = json_encode ( array (
|
749 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
750 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
751 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
752 |
+
'token' => $this->_request ['token'],
|
753 |
+
'firstname' => $this->_request ['firstname'],
|
754 |
+
'lastname' => $this->_request ['lastname'],
|
755 |
+
'street' => $this->_request ['street'],
|
756 |
+
'city' => $this->_request ['city'],
|
757 |
+
'region' => $this->_request ['region'],
|
758 |
+
'country_id' => $this->_request ['country_id'],
|
759 |
+
'postcode' => $this->_request ['postcode'],
|
760 |
+
'telephone' => $this->_request ['telephone'],
|
761 |
+
'is_default_billing' => ( int ) $this->_request ['is_default_billing'],
|
762 |
+
'is_default_shipping' => ( int ) $this->_request ['is_default_shipping']
|
763 |
+
) );
|
764 |
+
$resourceUrl = "$apiUrl/addressbook/add/";
|
765 |
+
$headers = array (
|
766 |
+
'Content-Type' => 'application/json',
|
767 |
+
'Accept' => '*/*'
|
768 |
+
);
|
769 |
+
|
770 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
771 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
772 |
+
if (! $result ['isValidToken']) {
|
773 |
+
$this->sendResponse ( 401, json_encode ( array (
|
774 |
+
'error' => true,
|
775 |
+
'message' => 'Unauthorized'
|
776 |
+
) ) );
|
777 |
+
} else {
|
778 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
779 |
+
}
|
780 |
+
}
|
781 |
+
break;
|
782 |
+
|
783 |
+
case "address_detail" :
|
784 |
+
|
785 |
+
if ($this->get_request_method () != "POST") {
|
786 |
+
$this->sendResponse ( 400, json_encode ( array (
|
787 |
+
'error' => true,
|
788 |
+
'message' => 'Bad Request'
|
789 |
+
) ) );
|
790 |
+
} else {
|
791 |
+
$requestData = (array (
|
792 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
793 |
+
'token' => $this->_request ['token'],
|
794 |
+
'id' => ( int ) $this->_request ['address_id']
|
795 |
+
));
|
796 |
+
$headers = array (
|
797 |
+
'Content-Type' => 'application/json',
|
798 |
+
'Accept' => '*/*'
|
799 |
+
);
|
800 |
+
$resourceUrl = "$apiUrl/address_detail/";
|
801 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
802 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
803 |
+
if (! $result ['isValidToken']) {
|
804 |
+
$this->sendResponse ( 401, json_encode ( array (
|
805 |
+
'error' => true,
|
806 |
+
'message' => 'Unauthorized'
|
807 |
+
) ) );
|
808 |
+
} else {
|
809 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
810 |
+
}
|
811 |
+
}
|
812 |
+
break;
|
813 |
+
case "address_update" :
|
814 |
+
if ($this->get_request_method () != "POST") {
|
815 |
+
$this->sendResponse ( 400, json_encode ( array (
|
816 |
+
'error' => true,
|
817 |
+
'message' => 'Bad Request'
|
818 |
+
) ) );
|
819 |
+
} else {
|
820 |
+
$requestData = json_encode ( array (
|
821 |
+
'address_id' => ( int ) $this->_request ['address_id'],
|
822 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
823 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
824 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
825 |
+
'token' => $this->_request ['token'],
|
826 |
+
'firstname' => $this->_request ['firstname'],
|
827 |
+
'lastname' => $this->_request ['lastname'],
|
828 |
+
'street' => $this->_request ['street'],
|
829 |
+
'city' => $this->_request ['city'],
|
830 |
+
'region' => $this->_request ['region'],
|
831 |
+
'country_id' => $this->_request ['country_id'],
|
832 |
+
'postcode' => $this->_request ['postcode'],
|
833 |
+
'telephone' => $this->_request ['telephone'],
|
834 |
+
'is_default_billing' => ( int ) $this->_request ['is_default_billing'],
|
835 |
+
'is_default_shipping' => ( int ) $this->_request ['is_default_shipping']
|
836 |
+
) );
|
837 |
+
$resourceUrl = "$apiUrl/addressbook/update/";
|
838 |
+
$headers = array (
|
839 |
+
'Content-Type' => 'application/json',
|
840 |
+
'Accept' => '*/*'
|
841 |
+
);
|
842 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_PUT, $headers );
|
843 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
844 |
+
if (! $result ['isValidToken']) {
|
845 |
+
$this->sendResponse ( 401, json_encode ( array (
|
846 |
+
'error' => true,
|
847 |
+
'message' => 'Unauthorized'
|
848 |
+
) ) );
|
849 |
+
} else {
|
850 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
851 |
+
}
|
852 |
+
}
|
853 |
+
break;
|
854 |
+
case "address_delete" :
|
855 |
+
|
856 |
+
if ($this->get_request_method () != "DELETE") {
|
857 |
+
$this->sendResponse ( 400, json_encode ( array (
|
858 |
+
'error' => true,
|
859 |
+
'message' => 'Bad Request'
|
860 |
+
) ) );
|
861 |
+
} else {
|
862 |
+
|
863 |
+
$storeId = $this->_request ['store_id'];
|
864 |
+
$websiteId = $this->_request ['website_id'];
|
865 |
+
|
866 |
+
if ($this->_request ['customer_id'] && $this->_request ['customer_id'] != '') {
|
867 |
+
$customerId = $this->_request ['customer_id'];
|
868 |
+
} else {
|
869 |
+
$customerId = '';
|
870 |
+
}
|
871 |
+
|
872 |
+
if ($this->_request ['address_id'] && $this->_request ['address_id'] != '') {
|
873 |
+
$addressId = $this->_request ['address_id'];
|
874 |
+
} else {
|
875 |
+
$addressId = '';
|
876 |
+
}
|
877 |
+
$token = $this->_request ['token'];
|
878 |
+
|
879 |
+
$resourceUrl = "$apiUrl/addressbook/delete/address_id/$addressId/customer_id/$customerId/store_id/$storeId/website_id/$websiteId/token/$token";
|
880 |
+
$headers = array (
|
881 |
+
'Content-Type' => 'application/json',
|
882 |
+
'Accept' => '*/*'
|
883 |
+
);
|
884 |
+
$oauthClient->fetch ( $resourceUrl, '', OAUTH_HTTP_METHOD_DELETE, $headers );
|
885 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
886 |
+
if (! $result ['isValidToken']) {
|
887 |
+
$this->sendResponse ( 401, json_encode ( array (
|
888 |
+
'error' => true,
|
889 |
+
'message' => 'Unauthorized'
|
890 |
+
) ) );
|
891 |
+
} else {
|
892 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
893 |
+
}
|
894 |
+
}
|
895 |
+
break;
|
896 |
+
case "apply_coupon" :
|
897 |
+
if ($this->get_request_method () != "POST") {
|
898 |
+
$this->sendResponse ( 400, json_encode ( array (
|
899 |
+
'error' => true,
|
900 |
+
'message' => 'Bad Request'
|
901 |
+
) ) );
|
902 |
+
} else {
|
903 |
+
$requestData = json_encode ( array (
|
904 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
905 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
906 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
907 |
+
'token' => $this->_request ['token'],
|
908 |
+
'quote_id' => ( int ) $this->_request ['quote_id'],
|
909 |
+
'coupon_code' => $this->_request ['coupon_code']
|
910 |
+
) );
|
911 |
+
$resourceUrl = "$apiUrl/coupon/apply/";
|
912 |
+
$headers = array (
|
913 |
+
'Content-Type' => 'application/json',
|
914 |
+
'Accept' => '*/*'
|
915 |
+
);
|
916 |
+
|
917 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
918 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
919 |
+
if (! $result ['isValidToken']) {
|
920 |
+
$this->sendResponse ( 401, json_encode ( array (
|
921 |
+
'error' => true,
|
922 |
+
'message' => 'Unauthorized'
|
923 |
+
) ) );
|
924 |
+
} else {
|
925 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
926 |
+
}
|
927 |
+
}
|
928 |
+
break;
|
929 |
+
|
930 |
+
case "cancel_coupon" :
|
931 |
+
if ($this->get_request_method () != "POST") {
|
932 |
+
$this->sendResponse ( 400, json_encode ( array (
|
933 |
+
'error' => true,
|
934 |
+
'message' => 'Bad Request'
|
935 |
+
) ) );
|
936 |
+
} else {
|
937 |
+
$requestData = json_encode ( array (
|
938 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
939 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
940 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
941 |
+
'token' => $this->_request ['token'],
|
942 |
+
'quote_id' => ( int ) $this->_request ['quote_id']
|
943 |
+
) );
|
944 |
+
$resourceUrl = "$apiUrl/coupon/cancel/";
|
945 |
+
$headers = array (
|
946 |
+
'Content-Type' => 'application/json',
|
947 |
+
'Accept' => '*/*'
|
948 |
+
);
|
949 |
+
|
950 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_PUT, $headers );
|
951 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
952 |
+
if (! $result ['isValidToken']) {
|
953 |
+
$this->sendResponse ( 401, json_encode ( array (
|
954 |
+
'error' => true,
|
955 |
+
'message' => 'Unauthorized'
|
956 |
+
) ) );
|
957 |
+
} else {
|
958 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
959 |
+
}
|
960 |
+
}
|
961 |
+
break;
|
962 |
+
|
963 |
+
case "add_address_tocart" :
|
964 |
+
if ($this->get_request_method () != "POST") {
|
965 |
+
$this->sendResponse ( 400, json_encode ( array (
|
966 |
+
'error' => true,
|
967 |
+
'message' => 'Bad Request'
|
968 |
+
) ) );
|
969 |
+
} else {
|
970 |
+
$requestData = json_encode ( array (
|
971 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
972 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
973 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
974 |
+
'token' => $this->_request ['token'],
|
975 |
+
'quote_id' => ( int ) $this->_request ['quote_id'],
|
976 |
+
'billing_address_id' => ( int ) $this->_request ['billing_address_id'],
|
977 |
+
'shipping_address_id' => ( int ) $this->_request ['shipping_address_id']
|
978 |
+
) );
|
979 |
+
$headers = array (
|
980 |
+
'Content-Type' => 'application/json',
|
981 |
+
'Accept' => '*/*'
|
982 |
+
);
|
983 |
+
$resourceUrl = "$apiUrl/cart_address/add/";
|
984 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
985 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
986 |
+
if (! $result ['isValidToken']) {
|
987 |
+
$this->sendResponse ( 401, json_encode ( array (
|
988 |
+
'error' => true,
|
989 |
+
'message' => 'Unauthorized'
|
990 |
+
) ) );
|
991 |
+
} else {
|
992 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
993 |
+
}
|
994 |
+
}
|
995 |
+
break;
|
996 |
+
|
997 |
+
case "add_shipping_payment_tocart" :
|
998 |
+
|
999 |
+
if ($this->get_request_method () != "POST") {
|
1000 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1001 |
+
'error' => true,
|
1002 |
+
'message' => 'Bad Request'
|
1003 |
+
) ) );
|
1004 |
+
} else {
|
1005 |
+
$requestData = json_encode ( array (
|
1006 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1007 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1008 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1009 |
+
'token' => $this->_request ['token'],
|
1010 |
+
'quote_id' => ( int ) $this->_request ['quote_id'],
|
1011 |
+
'shipping_method' => $this->_request ['shipping_method'],
|
1012 |
+
'payment_method' => $this->_request ['payment_method']
|
1013 |
+
) );
|
1014 |
+
$headers = array (
|
1015 |
+
'Content-Type' => 'application/json',
|
1016 |
+
'Accept' => '*/*'
|
1017 |
+
);
|
1018 |
+
$oauthClient->fetch ( "$apiUrl/cart/add_shipping_payment/", $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
1019 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1020 |
+
if (! $result ['isValidToken']) {
|
1021 |
+
$this->sendResponse ( 401, json_encode ( array (
|
1022 |
+
'error' => true,
|
1023 |
+
'message' => 'Unauthorized'
|
1024 |
+
) ) );
|
1025 |
+
} else {
|
1026 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
1027 |
+
}
|
1028 |
+
}
|
1029 |
+
break;
|
1030 |
+
case "place_order" :
|
1031 |
+
|
1032 |
+
if ($this->get_request_method () != "POST") {
|
1033 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1034 |
+
'error' => true,
|
1035 |
+
'message' => 'Bad Request'
|
1036 |
+
) ) );
|
1037 |
+
} else {
|
1038 |
+
$surprise_gift = (( int ) $this->_request ['surprise_gift'] == 1 ? ( int ) $this->_request ['surprise_gift'] : NULL);
|
1039 |
+
$requestData = json_encode ( array (
|
1040 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1041 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1042 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1043 |
+
'token' => $this->_request ['token'],
|
1044 |
+
'quote_id' => ( int ) $this->_request ['quote_id'],
|
1045 |
+
'shipping_method' => $this->_request ['shipping_method'],
|
1046 |
+
'payment_method' => $this->_request ['payment_method'],
|
1047 |
+
'currencyCode' => $this->_request ['currencyCode'],
|
1048 |
+
'delivery_schedule_types' => $this->_request ['delivery_schedule_types'],
|
1049 |
+
'shipping_delivery_time' => $this->_request ['shipping_delivery_time'],
|
1050 |
+
'shipping_delivery_cost' => $this->_request ['shipping_delivery_cost'],
|
1051 |
+
'shipping_delivery_date' => $this->_request ['shipping_delivery_date'],
|
1052 |
+
'shipping_delivery_comments' => $this->_request ['shipping_delivery_comments'],
|
1053 |
+
'delivery_time' => $this->_request ['delivery_time'],
|
1054 |
+
'surprise_gift' => $surprise_gift,
|
1055 |
+
'gift_message' => $this->_request ['gift_message']
|
1056 |
+
) );
|
1057 |
+
$headers = array (
|
1058 |
+
'Content-Type' => 'application/json',
|
1059 |
+
'Accept' => '*/*'
|
1060 |
+
);
|
1061 |
+
$resourceUrl = "$apiUrl/place_order/";
|
1062 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
1063 |
+
// echo $oauthClient->getLastResponse (); exit;
|
1064 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1065 |
+
if (! $result ['isValidToken']) {
|
1066 |
+
$this->sendResponse ( 401, json_encode ( array (
|
1067 |
+
'error' => true,
|
1068 |
+
'message' => 'Unauthorized'
|
1069 |
+
) ) );
|
1070 |
+
} else {
|
1071 |
|
1072 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
1073 |
+
}
|
1074 |
+
}
|
1075 |
+
break;
|
1076 |
+
|
1077 |
+
case "myorders_list" :
|
1078 |
+
if ($this->get_request_method () != "POST") {
|
1079 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1080 |
+
'error' => true,
|
1081 |
+
'message' => 'Bad Request'
|
1082 |
+
) ) );
|
1083 |
+
} else {
|
1084 |
+
$page = (( int ) $this->_request ['page'] > 0 ? ( int ) $this->_request ['page'] : 1);
|
1085 |
+
$limit = (( int ) $this->_request ['limit'] > 0 ? ( int ) $this->_request ['limit'] : 10);
|
1086 |
+
$requestData = (array (
|
1087 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1088 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1089 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1090 |
+
'token' => $this->_request ['token'],
|
1091 |
+
'page' => $page,
|
1092 |
+
'limit' => $limit
|
1093 |
+
));
|
1094 |
+
$headers = array (
|
1095 |
+
'Content-Type' => 'application/json',
|
1096 |
+
'Accept' => '*/*'
|
1097 |
+
);
|
1098 |
+
$oauthClient->fetch ( "$apiUrl/myorders/", $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1099 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1100 |
+
$result1 = json_decode ( $result, true );
|
1101 |
+
if (! $result1 ['isValidToken']) {
|
1102 |
+
$this->sendResponse ( 401, json_encode ( array (
|
1103 |
+
'error' => true,
|
1104 |
+
'message' => 'Unauthorized'
|
1105 |
+
) ) );
|
1106 |
+
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1107 |
|
1108 |
+
$this->sendResponse ( 200, (($result)) );
|
1109 |
+
}
|
1110 |
+
}
|
1111 |
+
break;
|
1112 |
+
|
1113 |
+
case "myorder_detail" :
|
1114 |
+
if ($this->get_request_method () != "POST") {
|
1115 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1116 |
+
'error' => true,
|
1117 |
+
'message' => 'Bad Request'
|
1118 |
+
) ) );
|
1119 |
+
} else {
|
1120 |
+
$requestData = (array (
|
1121 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1122 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1123 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1124 |
+
'token' => $this->_request ['token'],
|
1125 |
+
'id' => ( int ) $this->_request ['order_id']
|
1126 |
+
));
|
1127 |
+
$headers = array (
|
1128 |
+
'Content-Type' => 'application/json',
|
1129 |
+
'Accept' => '*/*'
|
1130 |
+
);
|
1131 |
+
$oauthClient->fetch ( "$apiUrl/myorder_detail/", $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1132 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1133 |
+
$result1 = json_decode ( $result, true );
|
1134 |
+
if (! $result1 ['isValidToken']) {
|
1135 |
+
$this->sendResponse ( 401, json_encode ( array (
|
1136 |
+
'error' => true,
|
1137 |
+
'message' => 'Unauthorized'
|
1138 |
+
) ) );
|
1139 |
+
} else {
|
1140 |
|
1141 |
+
$this->sendResponse ( 200, ($result) );
|
1142 |
+
}
|
1143 |
+
}
|
1144 |
+
break;
|
1145 |
+
|
1146 |
+
case "add_wishlist" :
|
1147 |
+
if ($this->get_request_method () != "POST") {
|
1148 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1149 |
+
'error' => true,
|
1150 |
+
'message' => 'Bad Request'
|
1151 |
+
) ) );
|
1152 |
+
} else {
|
1153 |
+
$requestData = json_encode ( array (
|
1154 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1155 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1156 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1157 |
+
'token' => $this->_request ['token'],
|
1158 |
+
'product_id' => ( int ) $this->_request ['product_id'],
|
1159 |
+
'qty' => ( int ) $this->_request ['qty']
|
1160 |
+
) );
|
1161 |
+
$headers = array (
|
1162 |
+
'Content-Type' => 'application/json',
|
1163 |
+
'Accept' => '*/*'
|
1164 |
+
);
|
1165 |
+
$resourceUrl = "$apiUrl//wishlist/add/";
|
1166 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
1167 |
+
|
1168 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1169 |
+
|
1170 |
+
if (! $result ['isValidToken']) {
|
1171 |
+
$this->sendResponse ( 401, json_encode ( array (
|
1172 |
+
'error' => true,
|
1173 |
+
'message' => 'Unauthorized'
|
1174 |
+
) ) );
|
1175 |
+
} else {
|
|
|
|
|
1176 |
|
1177 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
1178 |
+
}
|
1179 |
+
}
|
1180 |
+
break;
|
1181 |
+
case "wishlist_list" :
|
1182 |
+
if ($this->get_request_method () != "POST") {
|
1183 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1184 |
+
'error' => true,
|
1185 |
+
'message' => 'Bad Request'
|
1186 |
+
) ) );
|
1187 |
+
} else {
|
1188 |
+
$requestData = (array (
|
1189 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1190 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1191 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1192 |
+
'token' => $this->_request ['token'],
|
1193 |
+
'page' => ( int ) $this->_request ['page'],
|
1194 |
+
'limit' => ( int ) $this->_request ['limit'],
|
1195 |
+
'image_size' => ( int ) $this->_request ['image_size']
|
1196 |
+
));
|
1197 |
+
$headers = array (
|
1198 |
+
'Content-Type' => 'application/json',
|
1199 |
+
'Accept' => '*/*'
|
1200 |
+
);
|
1201 |
+
$resourceUrl = "$apiUrl/wishlist/productlist/";
|
1202 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1203 |
+
|
1204 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1205 |
+
if (! $result ['isValidToken']) {
|
1206 |
+
$this->sendResponse ( 401, json_encode ( array (
|
1207 |
+
'error' => true,
|
1208 |
+
'message' => 'Unauthorized'
|
1209 |
+
) ) );
|
1210 |
+
} else {
|
1211 |
|
1212 |
+
$this->sendResponse ( 200, ($result) );
|
1213 |
+
}
|
1214 |
+
}
|
1215 |
+
break;
|
1216 |
+
|
1217 |
+
case "delete_wishlist" :
|
1218 |
+
if ($this->get_request_method () != "DELETE") {
|
1219 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1220 |
+
'error' => true,
|
1221 |
+
'message' => 'Bad Request'
|
1222 |
+
) ) );
|
1223 |
+
} else {
|
1224 |
+
|
1225 |
+
$storeId = $this->_request ['store_id'];
|
1226 |
+
$websiteId = $this->_request ['website_id'];
|
1227 |
+
|
1228 |
+
if ($this->_request ['customer_id'] && $this->_request ['customer_id'] != '') {
|
1229 |
+
$customerId = $this->_request ['customer_id'];
|
1230 |
+
} else {
|
1231 |
+
$customerId = '';
|
1232 |
+
}
|
1233 |
+
|
1234 |
+
if ($this->_request ['product_id'] && $this->_request ['product_id'] != '') {
|
1235 |
+
$productId = $this->_request ['product_id'];
|
1236 |
+
} else {
|
1237 |
+
$productId = '';
|
1238 |
+
}
|
1239 |
+
$token = $this->_request ['token'];
|
1240 |
+
|
1241 |
+
$resourceUrl = "$apiUrl/wishlist/delete/token/$token/product_id/$productId/customer_id/$customerId/store_id/$storeId/website_id/$websiteId/";
|
1242 |
+
$headers = array (
|
1243 |
+
'Content-Type' => 'application/json',
|
1244 |
+
'Accept' => '*/*'
|
1245 |
+
);
|
1246 |
+
$oauthClient->fetch ( $resourceUrl, '', OAUTH_HTTP_METHOD_DELETE, $headers );
|
1247 |
+
|
1248 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1249 |
+
if (! $result ['isValidToken']) {
|
1250 |
+
$this->sendResponse ( 401, json_encode ( array (
|
1251 |
+
'error' => true,
|
1252 |
+
'message' => 'Unauthorized'
|
1253 |
+
) ) );
|
1254 |
+
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1255 |
|
1256 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
1257 |
+
}
|
1258 |
+
}
|
1259 |
+
break;
|
1260 |
+
|
1261 |
+
case "add_review" :
|
1262 |
+
if ($this->get_request_method () != "POST") {
|
1263 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1264 |
+
'error' => true,
|
1265 |
+
'message' => 'Bad Request'
|
1266 |
+
) ) );
|
1267 |
+
} else {
|
1268 |
+
$requestData = json_encode ( array (
|
1269 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1270 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1271 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1272 |
+
'token' => $this->_request ['token'],
|
1273 |
+
'product_id' => ( int ) $this->_request ['product_id'],
|
1274 |
+
'customer_name' => $this->_request ['customer_name'],
|
1275 |
+
'review_title' => $this->_request ['review_title'],
|
1276 |
+
'review_description' => $this->_request ['review_description'],
|
1277 |
+
'review_status' => ( int ) $this->_request ['review_status'],
|
1278 |
+
'rating' => $this->_request ['rating']
|
1279 |
+
) );
|
1280 |
+
$headers = array (
|
1281 |
+
'Content-Type' => 'application/json',
|
1282 |
+
'Accept' => '*/*'
|
1283 |
+
);
|
1284 |
+
$resourceUrl = "$apiUrl/add/reviews/";
|
1285 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
1286 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1287 |
+
if (! $result ['isValidToken']) {
|
1288 |
+
$this->sendResponse ( 401, json_encode ( array (
|
1289 |
+
'error' => true,
|
1290 |
+
'message' => 'Unauthorized'
|
1291 |
+
) ) );
|
1292 |
+
} else {
|
1293 |
|
1294 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
1295 |
+
}
|
1296 |
+
}
|
1297 |
+
break;
|
1298 |
+
|
1299 |
+
case "reviews_list" :
|
1300 |
+
if ($this->get_request_method () != "GET") {
|
1301 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1302 |
+
'error' => true,
|
1303 |
+
'message' => 'Bad Request'
|
1304 |
+
) ) );
|
1305 |
+
} else {
|
1306 |
+
$requestData = (array (
|
1307 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1308 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1309 |
+
'product_id' => ( int ) $this->_request ['product_id'],
|
1310 |
+
'page' => ( int ) $this->_request ['page'],
|
1311 |
+
'limit' => ( int ) $this->_request ['limit']
|
1312 |
+
));
|
1313 |
+
$headers = array (
|
1314 |
+
'Content-Type' => 'application/json',
|
1315 |
+
'Accept' => '*/*'
|
1316 |
+
);
|
1317 |
+
$resourceUrl = "$apiUrl/reviews/list/";
|
1318 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1319 |
+
$result = $oauthClient->getLastResponse ();
|
1320 |
+
$this->sendResponse ( 200, ($result) );
|
1321 |
+
}
|
1322 |
+
break;
|
1323 |
+
|
1324 |
+
case "filters" :
|
1325 |
+
|
1326 |
+
if ($this->get_request_method () != "GET") {
|
1327 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1328 |
+
'error' => true,
|
1329 |
+
'message' => 'Bad Request'
|
1330 |
+
) ) );
|
1331 |
+
} else {
|
1332 |
+
$requestData = array (
|
1333 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1334 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1335 |
+
'category_id' => ( int ) $this->_request ['category_id']
|
1336 |
+
);
|
1337 |
+
$headers = array (
|
1338 |
+
'Content-Type' => 'application/json',
|
1339 |
+
'Accept' => '*/*'
|
1340 |
+
);
|
1341 |
+
$resourceUrl = "$apiUrl/category/filters/";
|
1342 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1343 |
+
$result = $oauthClient->getLastResponse ();
|
1344 |
+
|
1345 |
+
$this->sendResponse ( 200, json_decode ( $result ) );
|
1346 |
+
}
|
1347 |
+
break;
|
1348 |
+
|
1349 |
+
case "my_downloadable" :
|
1350 |
+
|
1351 |
+
$page = (( int ) $this->_request ['page'] > 0 ? ( int ) $this->_request ['page'] : 1);
|
1352 |
+
$limit = (( int ) $this->_request ['limit'] > 0 ? ( int ) $this->_request ['limit'] : 10);
|
1353 |
+
if ($this->get_request_method () != "POST") {
|
1354 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1355 |
+
'error' => true,
|
1356 |
+
'message' => 'Bad Request'
|
1357 |
+
) ) );
|
1358 |
+
} else {
|
1359 |
+
$requestData = json_encode ( array (
|
1360 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1361 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1362 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1363 |
+
'token' => $this->_request ['token'],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1364 |
|
1365 |
+
'page' => $page,
|
1366 |
+
'limit' => $limit
|
1367 |
+
) );
|
1368 |
+
$headers = array (
|
1369 |
+
'Content-Type' => 'application/json',
|
1370 |
+
'Accept' => '*/*'
|
1371 |
+
);
|
1372 |
+
$resourceUrl = "$apiUrl/my_download/products/";
|
1373 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
1374 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1375 |
+
if (! $result ['isValidToken']) {
|
1376 |
+
$this->sendResponse ( 401, json_encode ( array (
|
1377 |
+
'error' => true,
|
1378 |
+
'message' => 'Unauthorized'
|
1379 |
+
) ) );
|
1380 |
+
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1381 |
|
1382 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
1383 |
+
}
|
1384 |
+
}
|
1385 |
+
break;
|
1386 |
+
|
1387 |
+
case "bulk_add_tocart" :
|
1388 |
+
|
1389 |
+
if ($this->get_request_method () != "POST") {
|
1390 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1391 |
+
'error' => true,
|
1392 |
+
'message' => 'Bad Request'
|
1393 |
+
) ) );
|
1394 |
+
} else {
|
1395 |
+
$requestData = json_encode ( array (
|
1396 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1397 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1398 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1399 |
+
'token' => $this->_request ['token'],
|
1400 |
+
'quote_id' => ( int ) $this->_request ['quote_id'],
|
1401 |
+
'currencyCode' => $this->_request ['currencyCode'],
|
1402 |
+
'detail' => json_decode ( $this->_request ['detail'] )
|
1403 |
+
) );
|
1404 |
+
|
1405 |
+
$resourceUrl = "$apiUrl/cart/bulk_add/";
|
1406 |
+
$headers = array (
|
1407 |
+
'Content-Type' => 'application/json',
|
1408 |
+
'Accept' => '*/*'
|
1409 |
+
);
|
1410 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
1411 |
+
// echo $oauthClient->getLastResponse (); exit;
|
1412 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1413 |
+
if (! $result ['isValidToken']) {
|
1414 |
+
$this->sendResponse ( 401, json_encode ( array (
|
1415 |
+
'error' => true,
|
1416 |
+
'message' => 'Unauthorized'
|
1417 |
+
) ) );
|
1418 |
+
} else {
|
1419 |
|
1420 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
1421 |
+
}
|
1422 |
+
}
|
1423 |
+
break;
|
1424 |
+
|
1425 |
+
case "bulk_update_cart" :
|
1426 |
+
|
1427 |
+
if ($this->get_request_method () != "POST") {
|
1428 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1429 |
+
'error' => true,
|
1430 |
+
'message' => 'Bad Request'
|
1431 |
+
) ) );
|
1432 |
+
} else {
|
1433 |
+
$requestData = json_encode ( array (
|
1434 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1435 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1436 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1437 |
+
'token' => $this->_request ['token'],
|
1438 |
+
'quote_id' => ( int ) $this->_request ['quote_id'],
|
1439 |
+
'currencyCode' => $this->_request ['currencyCode'],
|
1440 |
+
'detail' => json_decode ( $this->_request ['detail'] )
|
1441 |
+
) );
|
1442 |
+
|
1443 |
+
$resourceUrl = "$apiUrl/cart/bulk_update/";
|
1444 |
+
$headers = array (
|
1445 |
+
'Content-Type' => 'application/json',
|
1446 |
+
'Accept' => '*/*'
|
1447 |
+
);
|
1448 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_PUT, $headers );
|
1449 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1450 |
+
if (! $result ['isValidToken']) {
|
1451 |
+
$this->sendResponse ( 401, json_encode ( array (
|
1452 |
+
'error' => true,
|
1453 |
+
'message' => 'Unauthorized'
|
1454 |
+
) ) );
|
1455 |
+
} else {
|
1456 |
|
1457 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
1458 |
+
}
|
1459 |
+
}
|
1460 |
+
break;
|
1461 |
+
|
1462 |
+
case "cart_add_address" :
|
1463 |
+
if ($this->get_request_method () != "POST") {
|
1464 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1465 |
+
'error' => true,
|
1466 |
+
'message' => 'Bad Request'
|
1467 |
+
) ) );
|
1468 |
+
} else {
|
1469 |
+
$requestData = json_encode ( array (
|
1470 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1471 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1472 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1473 |
+
'token' => $this->_request ['token'],
|
1474 |
+
'quote_id' => ( int ) $this->_request ['quote_id'],
|
1475 |
+
'billing_address_id' => ( int ) $this->_request ['billing_address_id'],
|
1476 |
+
'shipping_address_id' => ( int ) $this->_request ['shipping_address_id']
|
1477 |
+
) );
|
1478 |
+
$headers = array (
|
1479 |
+
'Content-Type' => 'application/json',
|
1480 |
+
'Accept' => '*/*'
|
1481 |
+
);
|
1482 |
+
$resourceUrl = "$apiUrl/cart_add_address/";
|
1483 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
1484 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1485 |
+
if (! $result ['isValidToken']) {
|
1486 |
+
$this->sendResponse ( 401, json_encode ( array (
|
1487 |
+
'error' => true,
|
1488 |
+
'message' => 'Unauthorized'
|
1489 |
+
) ) );
|
1490 |
+
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1491 |
|
1492 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
1493 |
+
}
|
1494 |
+
}
|
1495 |
+
break;
|
1496 |
+
|
1497 |
+
case "clear_wishlist" :
|
1498 |
+
|
1499 |
+
if ($this->get_request_method () != "POST") {
|
1500 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1501 |
+
'error' => true,
|
1502 |
+
'message' => 'Bad Request'
|
1503 |
+
) ) );
|
1504 |
+
} else {
|
1505 |
+
|
1506 |
+
$requestData = json_encode ( array (
|
1507 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1508 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1509 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1510 |
+
'token' => $this->_request ['token']
|
1511 |
+
) );
|
1512 |
+
|
1513 |
+
$resourceUrl = "$apiUrl/wishlist/clear/";
|
1514 |
+
$headers = array (
|
1515 |
+
'Content-Type' => 'application/json',
|
1516 |
+
'Accept' => '*/*'
|
1517 |
+
);
|
1518 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_PUT, $headers );
|
1519 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1520 |
+
if (! $result ['isValidToken']) {
|
1521 |
+
$this->sendResponse ( 401, json_encode ( array (
|
1522 |
+
'error' => true,
|
1523 |
+
'message' => 'Unauthorized'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1524 |
) ) );
|
1525 |
+
} else {
|
1526 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
1527 |
+
}
|
1528 |
+
}
|
1529 |
+
break;
|
1530 |
+
|
1531 |
+
case "offer_products" :
|
1532 |
+
|
1533 |
+
if ($this->get_request_method () != "GET") {
|
1534 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1535 |
+
'error' => true,
|
1536 |
+
'message' => 'Bad Request'
|
1537 |
+
) ) );
|
1538 |
+
} else {
|
1539 |
+
|
1540 |
+
$requestData = array (
|
1541 |
+
'offer_id' => ( int ) $this->_request ['offer_id'],
|
1542 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1543 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1544 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1545 |
+
'page' => ( int ) $this->_request ['page'],
|
1546 |
+
'limit' => ( int ) $this->_request ['limit'],
|
1547 |
+
'image_size' => ( int ) $this->_request ['image_size'],
|
1548 |
+
'city' => ( int ) $this->_request ['city']
|
1549 |
+
);
|
1550 |
+
$headers = array (
|
1551 |
+
'Content-Type' => 'application/json',
|
1552 |
+
'Accept' => '*/*'
|
1553 |
+
);
|
1554 |
+
$resourceUrl = "$apiUrl/offer_products/";
|
1555 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1556 |
+
|
1557 |
+
$this->sendResponse ( 200, $oauthClient->getLastResponse () );
|
1558 |
+
}
|
1559 |
+
break;
|
1560 |
+
|
1561 |
+
case "gcmtoken_update" :
|
1562 |
+
|
1563 |
+
if ($this->get_request_method () != "POST") {
|
1564 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1565 |
+
'error' => true,
|
1566 |
+
'message' => 'Bad Request'
|
1567 |
+
) ) );
|
1568 |
+
} else {
|
1569 |
+
$requestData = json_encode ( array (
|
1570 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1571 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1572 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1573 |
+
'device_token' => $this->_request ['device_token'],
|
1574 |
+
'device_type' => $this->_request ['device_type']
|
1575 |
+
) );
|
1576 |
+
|
1577 |
+
$resourceUrl = "$apiUrl/customer/gcmtoken_update/";
|
1578 |
+
$headers = array (
|
1579 |
+
'Content-Type' => 'application/json',
|
1580 |
+
'Accept' => '*/*'
|
1581 |
+
);
|
1582 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_PUT, $headers );
|
1583 |
+
$this->sendResponse ( 200, $oauthClient->getLastResponse () );
|
1584 |
+
}
|
1585 |
+
break;
|
1586 |
+
case "contact_details" :
|
1587 |
+
|
1588 |
+
if ($this->get_request_method () != "GET") {
|
1589 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1590 |
+
'error' => true,
|
1591 |
+
'message' => 'Bad Request'
|
1592 |
+
) ) );
|
1593 |
+
} else {
|
1594 |
+
|
1595 |
+
$requestData = array (
|
1596 |
+
|
1597 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1598 |
+
'store_id' => ( int ) $this->_request ['store_id']
|
1599 |
+
);
|
1600 |
+
$headers = array (
|
1601 |
+
'Content-Type' => 'application/json',
|
1602 |
+
'Accept' => '*/*'
|
1603 |
+
);
|
1604 |
+
$resourceUrl = "$apiUrl/contact_details/";
|
1605 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1606 |
+
|
1607 |
+
$this->sendResponse ( 200, $oauthClient->getLastResponse () );
|
1608 |
+
}
|
1609 |
+
break;
|
1610 |
+
case "contact_form" :
|
1611 |
+
|
1612 |
+
if ($this->get_request_method () != "POST") {
|
1613 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1614 |
+
'error' => true,
|
1615 |
+
'message' => 'Bad Request'
|
1616 |
+
) ) );
|
1617 |
+
} else {
|
1618 |
+
$requestData = json_encode ( array (
|
1619 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1620 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1621 |
+
'email' => $this->_request ['email'],
|
1622 |
+
'name' => $this->_request ['name'],
|
1623 |
+
'telephone' => $this->_request ['telephone'],
|
1624 |
+
'comment' => $this->_request ['comment']
|
1625 |
+
) );
|
1626 |
+
$headers = array (
|
1627 |
+
'Content-Type' => 'application/json',
|
1628 |
+
'Accept' => '*/*'
|
1629 |
+
);
|
1630 |
+
$resourceUrl = "$apiUrl/contactus/";
|
1631 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
1632 |
+
$result = $oauthClient->getLastResponse ();
|
1633 |
+
$this->sendResponse ( 200, ($result) );
|
1634 |
+
}
|
1635 |
+
break;
|
1636 |
+
|
1637 |
+
case "reorder" :
|
1638 |
+
|
1639 |
+
if ($this->get_request_method () != "POST") {
|
1640 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1641 |
+
'error' => true,
|
1642 |
+
'message' => 'Bad Request'
|
1643 |
+
) ) );
|
1644 |
+
} else {
|
1645 |
+
$requestData = json_encode ( array (
|
1646 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1647 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1648 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1649 |
+
'token' => $this->_request ['token'],
|
1650 |
+
'order_id' => $this->_request ['order_id']
|
1651 |
+
) );
|
1652 |
+
|
1653 |
+
$resourceUrl = "$apiUrl/reorder/";
|
1654 |
+
$headers = array (
|
1655 |
+
'Content-Type' => 'application/json',
|
1656 |
+
'Accept' => '*/*'
|
1657 |
+
);
|
1658 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_PUT, $headers );
|
1659 |
+
// echo $oauthClient->getLastResponse (); exit;
|
1660 |
+
$result = json_decode ( $oauthClient->getLastResponse (), true );
|
1661 |
+
if (! $result ['isValidToken']) {
|
1662 |
+
$this->sendResponse ( 401, json_encode ( array (
|
1663 |
+
'error' => true,
|
1664 |
+
'message' => 'Unauthorized'
|
1665 |
+
) ) );
|
1666 |
+
} else {
|
1667 |
+
$this->sendResponse ( 200, json_encode ( $result ) );
|
1668 |
+
}
|
1669 |
+
}
|
1670 |
+
break;
|
1671 |
+
|
1672 |
+
case "seller_info" :
|
1673 |
+
|
1674 |
+
if ($this->get_request_method () != "GET") {
|
1675 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1676 |
+
'error' => true,
|
1677 |
+
'message' => 'Bad Request'
|
1678 |
+
) ) );
|
1679 |
+
} else {
|
1680 |
+
$page = (( int ) $this->_request ['page'] > 0 ? ( int ) $this->_request ['page'] : 1);
|
1681 |
+
$limit = (( int ) $this->_request ['limit'] > 0 ? ( int ) $this->_request ['limit'] : 10);
|
1682 |
+
$requestData = array (
|
1683 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1684 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1685 |
+
'seller_id' => ( int ) $this->_request ['seller_id'],
|
1686 |
+
'image_size' => ( int ) $this->_request ['image_size'],
|
1687 |
+
'city' => ( int ) $this->_request ['city'],
|
1688 |
+
'page' => $page,
|
1689 |
+
'limit' => $limit
|
1690 |
+
);
|
1691 |
+
$headers = array (
|
1692 |
+
'Content-Type' => 'application/json',
|
1693 |
+
'Accept' => '*/*'
|
1694 |
+
);
|
1695 |
+
$resourceUrl = "$apiUrl/sellers/profile/";
|
1696 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1697 |
+
if (Mage::getStoreConfig ( 'marketplace/marketplace/activate' )) {
|
1698 |
+
$result = $oauthClient->getLastResponse ();
|
1699 |
+
} else {
|
1700 |
+
$result ['error'] = true;
|
1701 |
+
$result ['success'] = 0;
|
1702 |
+
$result ['total_count'] = 0;
|
1703 |
+
$result ['message'] = "Enable the market place";
|
1704 |
+
$result ['result'] = [ ];
|
1705 |
+
echo $result = json_encode ( $result );
|
1706 |
+
}
|
1707 |
+
$this->sendResponse ( 200, json_decode ( $result ) );
|
1708 |
+
}
|
1709 |
+
break;
|
1710 |
+
|
1711 |
+
case "sellerslist" :
|
1712 |
+
$page = (( int ) $this->_request ['page'] > 0 ? ( int ) $this->_request ['page'] : 1);
|
1713 |
+
$limit = (( int ) $this->_request ['limit'] > 0 ? ( int ) $this->_request ['limit'] : 10);
|
1714 |
+
if ($this->get_request_method () != "GET") {
|
1715 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1716 |
+
'error' => true,
|
1717 |
+
'message' => 'Bad Request'
|
1718 |
+
) ) );
|
1719 |
+
} else {
|
1720 |
+
|
1721 |
+
$requestData = array (
|
1722 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1723 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1724 |
+
'page' => $page,
|
1725 |
+
'limit' => $limit
|
1726 |
+
);
|
1727 |
+
$headers = array (
|
1728 |
+
'Content-Type' => 'application/json',
|
1729 |
+
'Accept' => '*/*'
|
1730 |
+
);
|
1731 |
+
|
1732 |
+
$resourceUrl = "$apiUrl/sellers/list/";
|
1733 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1734 |
+
if (Mage::getStoreConfig ( 'marketplace/marketplace/activate' )) {
|
1735 |
+
$result = $oauthClient->getLastResponse ();
|
1736 |
+
} else {
|
1737 |
+
// echo $result = "Enable the market place";
|
1738 |
+
$result ['error'] = true;
|
1739 |
+
$result ['success'] = 0;
|
1740 |
+
$result ['total_count'] = 0;
|
1741 |
+
$result ['message'] = "Enable the market place";
|
1742 |
+
$result ['result'] = [ ];
|
1743 |
+
echo $result = json_encode ( $result );
|
1744 |
+
}
|
1745 |
+
$this->sendResponse ( 200, json_decode ( $result ) );
|
1746 |
+
}
|
1747 |
+
break;
|
1748 |
+
|
1749 |
+
case "sellerreview" :
|
1750 |
+
|
1751 |
+
if ($this->get_request_method () != "POST") {
|
1752 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1753 |
+
'error' => true,
|
1754 |
+
'message' => 'Bad Request'
|
1755 |
+
) ) );
|
1756 |
+
} else {
|
1757 |
+
$requestData = json_encode ( array (
|
1758 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1759 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1760 |
+
'seller_id' => ( int ) $this->_request ['seller_id'],
|
1761 |
+
'ratings' => ( int ) $this->_request ['ratings'],
|
1762 |
+
'feedback' => $this->_request ['feedback'],
|
1763 |
+
'product_id' => ( int ) $this->_request ['product_id'],
|
1764 |
+
'customer_id' => ( int ) $this->_request ['customer_id']
|
1765 |
+
) );
|
1766 |
+
|
1767 |
+
$resourceUrl = "$apiUrl/sellers/rating/";
|
1768 |
+
$headers = array (
|
1769 |
+
'Content-Type' => 'application/json',
|
1770 |
+
'Accept' => '*/*'
|
1771 |
+
);
|
1772 |
+
|
1773 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_POST, $headers );
|
1774 |
+
if (Mage::getStoreConfig ( 'marketplace/marketplace/activate' )) {
|
1775 |
+
$result = $oauthClient->getLastResponse ();
|
1776 |
+
} else {
|
1777 |
+
$result ['error'] = true;
|
1778 |
+
$result ['success'] = 0;
|
1779 |
+
|
1780 |
+
$result ['message'] = "Enable the market place";
|
1781 |
+
$result ['result'] = [ ];
|
1782 |
+
echo $result = json_encode ( $result );
|
1783 |
+
}
|
1784 |
+
$this->sendResponse ( 200, ($result) );
|
1785 |
+
}
|
1786 |
+
break;
|
1787 |
+
|
1788 |
+
case "sellerreview_list" :
|
1789 |
+
|
1790 |
+
if ($this->get_request_method () != "GET") {
|
1791 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1792 |
+
'error' => true,
|
1793 |
+
'message' => 'Bad Request'
|
1794 |
+
) ) );
|
1795 |
+
} else {
|
1796 |
+
$page = (( int ) $this->_request ['page'] > 0 ? ( int ) $this->_request ['page'] : 1);
|
1797 |
+
$limit = (( int ) $this->_request ['limit'] > 0 ? ( int ) $this->_request ['limit'] : 10);
|
1798 |
+
$requestData = array (
|
1799 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1800 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1801 |
+
'seller_id' => ( int ) $this->_request ['seller_id'],
|
1802 |
+
'page' => $page,
|
1803 |
+
'limit' => $limit
|
1804 |
+
);
|
1805 |
+
$headers = array (
|
1806 |
+
'Content-Type' => 'application/json',
|
1807 |
+
'Accept' => '*/*'
|
1808 |
+
);
|
1809 |
+
$resourceUrl = "$apiUrl/seller/reviews/list/";
|
1810 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1811 |
+
if (Mage::getStoreConfig ( 'marketplace/marketplace/activate' )) {
|
1812 |
+
$result = $oauthClient->getLastResponse ();
|
1813 |
+
} else {
|
1814 |
+
$result ['error'] = true;
|
1815 |
+
$result ['success'] = 0;
|
1816 |
+
$result ['message'] = "Enable the market place";
|
1817 |
+
$result ['result'] = [ ];
|
1818 |
+
echo $result = json_encode ( $result );
|
1819 |
+
}
|
1820 |
+
$this->sendResponse ( 200, json_decode ( $result ) );
|
1821 |
+
}
|
1822 |
+
break;
|
1823 |
+
|
1824 |
+
case "pre_search" :
|
1825 |
+
$search_term = str_replace ( ' ', '%20', $this->_request ['search_term'] );
|
1826 |
+
if ($this->get_request_method () != "GET") {
|
1827 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1828 |
+
'error' => true,
|
1829 |
+
'message' => 'Bad Request'
|
1830 |
+
) ) );
|
1831 |
+
} else {
|
1832 |
+
$requestData = array (
|
1833 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1834 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1835 |
+
// 'category_id' => ( int ) $this->_request ['category_id'],
|
1836 |
+
|
1837 |
+
'search_term' => $this->_request ['search_term']
|
1838 |
+
// 'page' => $this->_request ['page'],
|
1839 |
+
// 'limit' => $this->_request ['limit'],
|
1840 |
+
// 'image_size' => ( int ) $this->_request ['image_size']
|
1841 |
+
);
|
1842 |
+
$headers = array (
|
1843 |
+
'Content-Type' => 'application/json',
|
1844 |
+
'Accept' => '*/*'
|
1845 |
+
);
|
1846 |
+
|
1847 |
+
$resourceUrl = "$apiUrl/predictive/search/";
|
1848 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1849 |
+
$result = $oauthClient->getLastResponse ();
|
1850 |
+
|
1851 |
+
$this->sendResponse ( 200, ($result) );
|
1852 |
+
}
|
1853 |
+
break;
|
1854 |
+
|
1855 |
+
case "delivery_info" :
|
1856 |
+
|
1857 |
+
if ($this->get_request_method () != "GET") {
|
1858 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1859 |
+
'error' => true,
|
1860 |
+
'message' => 'Bad Request'
|
1861 |
+
) ) );
|
1862 |
+
} else {
|
1863 |
+
$requestData = (array (
|
1864 |
+
|
1865 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1866 |
+
'store_id' => ( int ) $this->_request ['store_id']
|
1867 |
+
));
|
1868 |
+
$headers = array (
|
1869 |
+
'Content-Type' => 'application/json',
|
1870 |
+
'Accept' => '*/*'
|
1871 |
+
);
|
1872 |
+
$resourceUrl = "$apiUrl/delivery/info/";
|
1873 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1874 |
+
$result = $oauthClient->getLastResponse ();
|
1875 |
+
// echo $oauthClient->getLastResponse (); exit;
|
1876 |
+
|
1877 |
+
$this->sendResponse ( 200, ($result) );
|
1878 |
+
}
|
1879 |
+
break;
|
1880 |
+
|
1881 |
+
case "products" :
|
1882 |
+
|
1883 |
+
if ($this->get_request_method () != "GET") {
|
1884 |
+
$this->sendResponse ( 400, json_encode ( array (
|
1885 |
+
'error' => true,
|
1886 |
+
'message' => 'Bad Request'
|
1887 |
+
) ) );
|
1888 |
+
} else {
|
1889 |
+
$requestData = array (
|
1890 |
+
'store_id' => ( int ) $this->_request ['store_id'],
|
1891 |
+
'website_id' => ( int ) $this->_request ['website_id'],
|
1892 |
+
'page' => ( int ) $this->_request ['page'],
|
1893 |
+
'limit' => ( int ) $this->_request ['limit'],
|
1894 |
+
'category_id' => ( int ) $this->_request ['category_id'],
|
1895 |
+
'customer_id' => ( int ) $this->_request ['customer_id'],
|
1896 |
+
'orderby' => $this->_request ['orderby'],
|
1897 |
+
'sortby' => $this->_request ['sortby'],
|
1898 |
+
|
1899 |
+
'filters' => $this->_request ['filters'],
|
1900 |
+
'image_size' => ( int ) $this->_request ['image_size']
|
1901 |
+
);
|
1902 |
+
$headers = array (
|
1903 |
+
'Content-Type' => 'application/json',
|
1904 |
+
'Accept' => '*/*'
|
1905 |
+
);
|
1906 |
+
$resourceUrl = "$apiUrl/productlist/";
|
1907 |
+
$oauthClient->fetch ( $resourceUrl, $requestData, OAUTH_HTTP_METHOD_GET, $headers );
|
1908 |
+
$result = $oauthClient->getLastResponse ();
|
1909 |
+
$this->sendResponse ( 200, json_decode ( $result ) );
|
1910 |
+
}
|
1911 |
+
break;
|
1912 |
+
|
1913 |
+
default :
|
1914 |
+
$this->sendResponse ( 405, json_encode ( array (
|
1915 |
'error' => true,
|
1916 |
+
'message' => 'Method Not Allowed'
|
1917 |
+
) ) );
|
1918 |
+
break;
|
1919 |
}
|
1920 |
+
} catch ( OAuthException $e ) {
|
1921 |
+
|
1922 |
$errorMessage = json_decode ( $e->lastResponse );
|
1923 |
$error ['message'] = $errorMessage->messages->error [0]->message;
|
1924 |
$error ['code'] = $errorMessage->messages->error [0]->code;
|
1925 |
+
|
1926 |
$this->sendResponse ( $error ['code'], json_encode ( array (
|
1927 |
+
'error' => true,
|
1928 |
+
'message' => (isset ( $error ['message'] )) ? $error ['message'] : $e->getMessage (),
|
1929 |
+
'success' => 0
|
1930 |
) ) );
|
1931 |
+
}
|
1932 |
+
} catch ( OAuthException $e ) {
|
1933 |
+
$errorMessage = json_decode ( $e->lastResponse );
|
1934 |
+
$error ['message'] = $errorMessage->messages->error [0]->message;
|
1935 |
+
$error ['code'] = $errorMessage->messages->error [0]->code;
|
1936 |
+
$this->sendResponse ( $error ['code'], json_encode ( array (
|
1937 |
+
'error' => true,
|
1938 |
+
'message' => (isset ( $error ['message'] )) ? $error ['message'] : $e->getMessage (),
|
1939 |
+
'success' => 0
|
1940 |
+
) ) );
|
1941 |
+
}
|
1942 |
+
}
|
1943 |
+
|
1944 |
+
// Encode array into JSON
|
1945 |
+
private function json($data) {
|
1946 |
+
if (is_array ( $data )) {
|
1947 |
+
return json_encode ( $data );
|
1948 |
+
}
|
1949 |
+
}
|
1950 |
}
|
1951 |
// instantiated Library
|
1952 |
$api = new API ();
|