├── README ├── catalog └── controller │ └── api │ ├── store.php │ ├── information.php │ ├── category.php │ ├── customer.php │ └── product.php └── README.md /README: -------------------------------------------------------------------------------- 1 | Opencart API 2 | ================ 3 | 4 | Opencart extension based in opencart-webapi (ethernet1), using functions list from API2CART. 5 | 6 | Functions 7 | ------- 8 | 9 | Product Management Functions 10 | product.get 11 | Return full product information (by ID or SKU). 12 | product.list 13 | Return products list with limited information (ID, Name, Price, Thumbnail). Set optional parameter category_id to get products list into the specified category. 14 | product.count 15 | Return store products count. Set optional parameter category_id to get products count into the specified category. 16 | 17 | Category Management Functions 18 | category.get 19 | Return full Category information (by ID). 20 | category.list 21 | Get categories list with limited information (ID, Name, Description, Href, Image). 22 | category.count 23 | Return shopping cart categories count. 24 | 25 | Roadmap 26 | ------- 27 | 28 | Customer Management Functions 29 | Store Management Functions 30 | Order Management Functions 31 | 32 | License 33 | ------- 34 | 35 | This software is distributed under the [GNU GPL V3](http://www.gnu.org/licenses/gpl.html) License. -------------------------------------------------------------------------------- /catalog/controller/api/store.php: -------------------------------------------------------------------------------- 1 | load->model('setting/setting'); 9 | $json = array('success' => true); 10 | 11 | # -- $_GET params ------------------------------ 12 | 13 | if (isset($this->request->get['store'])) { 14 | $store_id = $this->request->get['store']; 15 | } else { 16 | $store_id = 0; 17 | } 18 | 19 | # -- End $_GET params -------------------------- 20 | 21 | $store = $this->model_setting_setting->getSetting('config'); 22 | 23 | $json['store'] = $store; 24 | 25 | 26 | if ($this->debug) { 27 | echo '
';
28 | print_r($json);
29 | } else {
30 | $this->response->setOutput(json_encode($json));
31 | }
32 | }
33 |
34 | function __call( $methodName, $arguments ) {
35 | //call_user_func(array($this, str_replace('.', '_', $methodName)), $arguments);
36 | call_user_func(array($this, "_$methodName"), $arguments);
37 | }
38 |
39 | }
40 |
41 | ?>
--------------------------------------------------------------------------------
/catalog/controller/api/information.php:
--------------------------------------------------------------------------------
1 | load->model('catalog/information');
9 | $json = array('success' => true);
10 |
11 | # -- $_GET params ------------------------------
12 |
13 | if (isset($this->request->get['id'])) {
14 | $information_id = $this->request->get['id'];
15 | } else {
16 | $information_id = 0;
17 | }
18 |
19 | # -- End $_GET params --------------------------
20 |
21 | $information_info = $this->model_catalog_information->getInformation($information_id);
22 |
23 | $json['result'] = $information_info;
24 |
25 | if ($this->debug) {
26 | echo '';
27 | print_r($json);
28 | } else {
29 | $this->response->setOutput(json_encode($json));
30 | }
31 | }
32 |
33 | function __call( $methodName, $arguments ) {
34 | //call_user_func(array($this, str_replace('.', '_', $methodName)), $arguments);
35 | call_user_func(array($this, "_$methodName"), $arguments);
36 | }
37 |
38 | }
39 |
40 | ?>
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Opencart API
2 | ================
3 |
4 | Opencart extension for remotely work with the OpenCart 1.5.+ via the REST API, coding style based in opencart-webapi (ethernet1), using functions list style from API2CART.
5 |
6 | Functions
7 | -------
8 |
9 | Product Management Functions
10 |
11 | * `product.get`: Return full product information (by ID or SKU).
12 | * `product.list`: Return products list with limited information (ID, Name, Price, Thumbnail). Set optional parameter category_id to get products list into the specified category.
13 | * `product.count`: Return store products count. Set optional parameter category_id to get products count into the specified category.
14 |
15 | Category Management Functions
16 |
17 | * `category.get`: Return full Category information (by ID).
18 | * `category.list`: Get categories list with limited information (ID, Name, Description, Href, Image).
19 | * `category.count`: Return shopping cart categories count.
20 |
21 | Customer Management Functions
22 |
23 | * `customer.get`: Return full Customer information (by ID, Email or Token).
24 | * `customer.add`: Add new customer to the store. Return ID.
25 |
26 | Store Management Functions
27 |
28 | * `store.get`: Return store config parameters.
29 |
30 | Information Management Functions
31 |
32 | * `information.get`: Return information from page by ID
33 |
34 | Roadmap
35 | -------
36 |
37 | Product Management Functions
38 |
39 | * `product.add`: Add new product to the shopping cart.
40 | * `product.update`: Update price and stock for a specific product
41 | * `product.delete`: Remove specified product from the shopping cart (by ID or SKU)
42 | * `product.latest`
43 | * `product.popular`
44 | * `product.bestseller`
45 |
46 | Customer Management Functions
47 |
48 | * `customer.list`: Get customers list with limited information.
49 |
50 | Cart Management Functions
51 |
52 | Order Management Functions
53 |
54 | * `order.get`
55 | * `order.list`
56 | * `order.count`
57 | * `order.add`
58 | * `order.update`
59 |
60 | License
61 | -------
62 |
63 | This software is distributed under the [GNU GPL V3](http://www.gnu.org/licenses/gpl.html) License.
--------------------------------------------------------------------------------
/catalog/controller/api/category.php:
--------------------------------------------------------------------------------
1 | load->model('catalog/category');
9 | $this->load->model('tool/image');
10 |
11 | $result = array();
12 |
13 | $categories = $this->model_catalog_category->getCategories($parent);
14 |
15 | if ($categories && $level > 0) {
16 | $level--;
17 |
18 | foreach ($categories as $category) {
19 |
20 | if ($category['image']) {
21 | $image = $this->model_tool_image->resize($category['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
22 | } else {
23 | $image = false;
24 | }
25 |
26 | $result[] = array(
27 | 'category_id' => $category['category_id'],
28 | 'parent_id' => $category['parent_id'],
29 | 'name' => $category['name'],
30 | 'image' => $image,
31 | 'href' => $this->url->link('product/category', 'category_id=' . $category['category_id']),
32 | 'categories' => $this->getCategoriesTree($category['category_id'], $level)
33 | );
34 | }
35 |
36 | return $result;
37 | }
38 | }
39 |
40 | public function _get() {
41 | $this->load->model('catalog/category');
42 | $this->load->model('tool/image');
43 |
44 | $json = array('success' => true);
45 |
46 | # -- $_GET params ------------------------------
47 |
48 | if (isset($this->request->get['id'])) {
49 | $category_id = $this->request->get['id'];
50 | } else {
51 | $category_id = 0;
52 | }
53 |
54 | # -- End $_GET params --------------------------
55 |
56 | $category = $this->model_catalog_category->getCategory($category_id);
57 |
58 | $json['category'] = array(
59 | 'id' => $category['category_id'],
60 | 'name' => $category['name'],
61 | 'description' => $category['description'],
62 | 'href' => $this->url->link('product/category', 'category_id=' . $category['category_id']),
63 | 'image' => $category['image']
64 | );
65 |
66 | if ($this->debug) {
67 | echo '';
68 | print_r($json);
69 | } else {
70 | $this->response->setOutput(json_encode($json));
71 | }
72 | }
73 |
74 | public function _list() {
75 | $this->load->model('catalog/category');
76 | $json = array('success' => true);
77 |
78 | # -- $_GET params ------------------------------
79 |
80 | if (isset($this->request->get['parent'])) {
81 | $parent = $this->request->get['parent'];
82 | } else {
83 | $parent = 0;
84 | }
85 |
86 | if (isset($this->request->get['level'])) {
87 | $level = $this->request->get['level'];
88 | } else {
89 | $level = 1;
90 | }
91 |
92 | # -- End $_GET params --------------------------
93 |
94 | $json['categories'] = $this->getCategoriesTree($parent, $level);
95 |
96 | if ($this->debug) {
97 | echo '';
98 | print_r($json);
99 | } else {
100 | $this->response->setOutput(json_encode($json));
101 | }
102 | }
103 |
104 | public function _count() {
105 | $this->load->model('catalog/category');
106 | $this->load->model('tool/image');
107 | $json = array('success' => true, 'result' => '');
108 |
109 | # -- $_GET params ------------------------------
110 | if (isset($this->request->get['parent'])) {
111 | $parent = $this->request->get['parent'];
112 | } else {
113 | $parent = 0;
114 | }
115 | # -- End $_GET params --------------------------
116 |
117 | $categories = $this->model_catalog_category->getTotalCategoriesByCategoryId($parent);
118 |
119 | $json['result'] = $categories;
120 |
121 | $this->response->setOutput(json_encode($json));
122 | }
123 |
124 | function __call( $methodName, $arguments ) {
125 | //call_user_func(array($this, str_replace('.', '_', $methodName)), $arguments);
126 | call_user_func(array($this, "_$methodName"), $arguments);
127 | }
128 |
129 | }
130 |
131 | ?>
--------------------------------------------------------------------------------
/catalog/controller/api/customer.php:
--------------------------------------------------------------------------------
1 | load->model('account/customer');
9 | $json = array('success' => true);
10 |
11 | # -- $_GET params ------------------------------
12 |
13 | if (isset($this->request->get['id'])) {
14 | $customer = $this->model_account_customer->getCustomer($this->request->get['id']);
15 | } else if (isset($this->request->get['email'])) {
16 | $customer = $this->model_account_customer->getCustomerByEmail($this->request->get['email']);
17 | } else if (isset($this->request->get['token'])) {
18 | $customer = $this->model_account_customer->getCustomerByToken($this->request->get['token']);
19 | } else {
20 | $customer = $this->model_account_customer->getCustomer(0);
21 | }
22 |
23 | # -- End $_GET params --------------------------
24 |
25 | $json['customer'] = array(
26 | 'customer_id' => $customer['customer_id'],
27 | 'store_id' => $customer['store_id'],
28 | 'firstname' => $customer['firstname'],
29 | 'lastname' => $customer['lastname'],
30 | 'email' => $customer['email'],
31 | 'telephone' => $customer['telephone'],
32 | 'fax' => $customer['fax'],
33 | 'password' => $customer['password'],
34 | 'salt' => $customer['salt'],
35 | // 'cart' => $customer['cart'],
36 | // 'wishlist' => $customer['wishlist'],
37 | // 'newsletter' => $customer['newsletter'],
38 | // 'address_id' => $customer['address_id'],
39 | // 'customer_group_id' => $customer['customer_group_id'],
40 | // 'ip' => $customer['ip'],
41 | // 'status' => $customer['status'],
42 | // 'approved' => $customer['approved'],
43 | // 'token' => $customer['token'],
44 | // 'date_added' => $customer['date_added'],
45 | );
46 |
47 |
48 | if ($this->debug) {
49 | echo '';
50 | print_r($json);
51 | } else {
52 | $this->response->setOutput(json_encode($json));
53 | }
54 | }
55 |
56 | public function _list() {
57 | $this->load->model('sale/customer');
58 | $json = array('success' => true, 'customers' => array());
59 |
60 | # -- $_GET params ------------------------------
61 | if (isset($this->request->get['category'])) {
62 | $category_id = $this->request->get['category'];
63 | } else {
64 | $category_id = 0;
65 | }
66 | # -- End $_GET params --------------------------
67 |
68 | $customers = $this->model_sale_customer->getCustomers(array(
69 | //'filter_name' => ''
70 | ));
71 |
72 | foreach ($customers as $customer) {
73 | $json['customers'][] = array(
74 | 'id' => $customer['customer_id'],
75 | 'firstname' => $customer['firstname'],
76 | 'lastname' => $customer['lastname'],
77 | 'email' => $customer['email'],
78 | );
79 | }
80 |
81 | $this->response->setOutput(json_encode($json));
82 | }
83 |
84 | public function _add() {
85 | $this->load->model('account/customer');
86 | $json = array('success' => true, 'result' => array());
87 |
88 | # -- $_GET params ------------------------------
89 | if (isset($this->request->get['firstname'])) {
90 | $data['firstname'] = $this->request->get['firstname'];
91 | }
92 | if (isset($this->request->get['lastname'])) {
93 | $data['lastname'] = $this->request->get['lastname'];
94 | }
95 | if (isset($this->request->get['email'])) {
96 | $data['email'] = $this->request->get['email'];
97 | }
98 | if (isset($this->request->get['password'])) {
99 | $data['password'] = $this->request->get['password'];
100 | }
101 | $data['telephone'] = '';
102 | $data['fax'] = '';
103 | $data['company'] = '';
104 | $data['company_id'] = '';
105 | $data['tax_id'] = '';
106 | $data['address_1'] = '';
107 | $data['address_2'] = '';
108 | $data['city'] = '';
109 | $data['postcode'] = '';
110 | $data['country_id'] = '';
111 | $data['zone_id'] = '';
112 | # -- End $_GET params --------------------------
113 |
114 | if ($data) {
115 | $this->model_account_customer->addCustomer($data);
116 | $customer = $this->model_account_customer->getCustomerByEmail($data['email']);
117 | $json['result'] = $customer['customer_id'];
118 | }
119 |
120 | $this->response->setOutput(json_encode($json));
121 | }
122 |
123 | function __call( $methodName, $arguments ) {
124 | //call_user_func(array($this, str_replace('.', '_', $methodName)), $arguments);
125 | call_user_func(array($this, "_$methodName"), $arguments);
126 | }
127 |
128 | }
129 |
130 | ?>
--------------------------------------------------------------------------------
/catalog/controller/api/product.php:
--------------------------------------------------------------------------------
1 | 'Product Name Here',
10 | // 'model' => 'ABC123',
11 | // ...
12 | //);
13 |
14 | // Load model into memory if it isn't already
15 | $this->load->model('catalog/product');
16 |
17 | // Attempt to pass the assoc array to the add Product method
18 | $this->model_catalog_product->addProduct($productData);
19 | }
20 |
21 | public function _get() {
22 | $this->load->model('catalog/product');
23 | $this->load->model('tool/image');
24 | $json = array('success' => true);
25 |
26 | # -- $_GET params ------------------------------
27 |
28 | if (isset($this->request->get['id'])) {
29 | $product_id = $this->request->get['id'];
30 | } else {
31 | $product_id = 0;
32 | }
33 |
34 | # -- End $_GET params --------------------------
35 |
36 | $product = $this->model_catalog_product->getProduct($product_id);
37 |
38 | # product image
39 | if ($product['image']) {
40 | $image = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
41 | } else {
42 | $image = '';
43 | }
44 |
45 | #additional images
46 | $additional_images = $this->model_catalog_product->getProductImages($product['product_id']);
47 | $images = array();
48 |
49 | foreach ($additional_images as $additional_image) {
50 | $images[] = $this->model_tool_image->resize($additional_image, $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'));
51 | }
52 |
53 | #specal
54 | if ((float)$product['special']) {
55 | $special = $this->currency->format($this->tax->calculate($product['special'], $product['tax_class_id'], $this->config->get('config_tax')));
56 | } else {
57 | $special = false;
58 | }
59 |
60 | #discounts
61 | $discounts = array();
62 | $data_discounts = $this->model_catalog_product->getProductDiscounts($product['product_id']);
63 |
64 | foreach ($data_discounts as $discount) {
65 | $discounts[] = array(
66 | 'quantity' => $discount['quantity'],
67 | 'price' => $this->currency->format($this->tax->calculate($discount['price'], $product['tax_class_id'], $this->config->get('config_tax')))
68 | );
69 | }
70 |
71 | // options
72 | $options = array();
73 |
74 | foreach ($this->model_catalog_product->getProductOptions($product['product_id']) as $option) {
75 | if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') {
76 | $option_value_data = array();
77 |
78 | foreach ($option['option_value'] as $option_value) {
79 | if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
80 | if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
81 | $price = $this->currency->format($this->tax->calculate($option_value['price'], $product['tax_class_id'], $this->config->get('config_tax')));
82 | } else {
83 | $price = false;
84 | }
85 |
86 | $option_value_data[] = array(
87 | 'product_option_value_id' => $option_value['product_option_value_id'],
88 | 'option_value_id' => $option_value['option_value_id'],
89 | 'name' => $option_value['name'],
90 | 'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
91 | 'price' => $price,
92 | 'price_prefix' => $option_value['price_prefix']
93 | );
94 | }
95 | }
96 |
97 | $options[] = array(
98 | 'product_option_id' => $option['product_option_id'],
99 | 'option_id' => $option['option_id'],
100 | 'name' => $option['name'],
101 | 'type' => $option['type'],
102 | 'option_value' => $option_value_data,
103 | 'required' => $option['required']
104 | );
105 | } elseif ($option['type'] == 'text' || $option['type'] == 'textarea' || $option['type'] == 'file' || $option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') {
106 | $options[] = array(
107 | 'product_option_id' => $option['product_option_id'],
108 | 'option_id' => $option['option_id'],
109 | 'name' => $option['name'],
110 | 'type' => $option['type'],
111 | 'option_value' => $option['option_value'],
112 | 'required' => $option['required']
113 | );
114 | }
115 | }
116 |
117 | #minimum
118 | if ($product['minimum']) {
119 | $minimum = $product['minimum'];
120 | } else {
121 | $minimum = 1;
122 | }
123 |
124 | $json['product'] = array(
125 | 'id' => $product['product_id'],
126 | 'name' => $product['name'],
127 | 'description' => html_entity_decode($product['description'], ENT_QUOTES, 'UTF-8'),
128 | 'meta_description' => $product['meta_description'],
129 | 'meta_keyword' => $product['meta_keyword'],
130 | 'tag' => $product['tag'],
131 | 'model' => $product['model'],
132 | 'sku' => $product['sku'],
133 | 'upc' => $product['upc'],
134 | 'ean' => $product['ean'],
135 | 'jan' => $product['jan'],
136 | 'isbn' => $product['isbn'],
137 | 'mpn' => $product['mpn'],
138 | 'location' => $product['location'],
139 | 'quantity' => $product['quantity'],
140 | 'stock_status' => $product['stock_status'],
141 | 'image' => $image,
142 | 'images' => $images,
143 | 'manufacturer_id' => $product['manufacturer_id'],
144 | 'manufacturer' => $product['manufacturer'],
145 | // $product['price'];
146 | 'price' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))),
147 | // $product['special'];
148 | 'special' => $special,
149 | 'reward' => $product['reward'],
150 | 'points' => $product['points'],
151 | 'tax_class_id' => $product['tax_class_id'],
152 | 'date_available' => $product['date_available'],
153 | 'weight' => $product['weight'],
154 | 'weight_class_id' => $product['weight_class_id'],
155 | 'length' => $product['length'],
156 | 'width' => $product['width'],
157 | 'height' => $product['height'],
158 | 'length_class_id' => $product['length_class_id'],
159 | 'subtract' => $product['subtract'],
160 | 'rating' => (int)$product['rating'],
161 | 'reviews' => (int)$product['reviews'],
162 | 'minimum' => $minimum,
163 | 'sort_order' => $product['sort_order'],
164 | 'status' => $product['status'],
165 | 'date_added' => $product['date_added'],
166 | 'date_modified' => $product['date_modified'],
167 | 'viewed' => $product['viewed'],
168 | 'discounts' => $discounts,
169 | 'options' => $options,
170 | 'attribute_groups' => $this->model_catalog_product->getProductAttributes($product['product_id'])
171 | );
172 |
173 |
174 | if ($this->debug) {
175 | echo '';
176 | print_r($json);
177 | } else {
178 | $this->response->setOutput(json_encode($json));
179 | }
180 | }
181 |
182 | public function _list() {
183 | $this->load->model('catalog/product');
184 | $this->load->model('tool/image');
185 | $json = array('success' => true, 'products' => array());
186 |
187 | // -- $_GET params ------------------------------
188 | if (isset($this->request->get['category'])) {
189 | $category_id = $this->request->get['category'];
190 | } else {
191 | $category_id = 0;
192 | }
193 | # -- End $_GET params --------------------------
194 |
195 | $products = $this->model_catalog_product->getProducts(array(
196 | 'filter_category_id' => $category_id
197 | ));
198 |
199 | foreach ($products as $product) {
200 |
201 | if ($product['image']) {
202 | $image = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
203 | } else {
204 | $image = false;
205 | }
206 |
207 | $json['products'][] = array(
208 | 'id' => $product['product_id'],
209 | 'name' => $product['name'],
210 | 'price' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))),
211 | 'thumb' => $image,
212 | );
213 | }
214 |
215 | $this->response->setOutput(json_encode($json));
216 | }
217 |
218 | public function _count() {
219 | $this->load->model('catalog/product');
220 | $this->load->model('tool/image');
221 | $json = array('success' => true, 'result' => '');
222 |
223 | // -- $_GET params ------------------------------
224 | if (isset($this->request->get['category'])) {
225 | $category_id = $this->request->get['category'];
226 | } else {
227 | $category_id = 0;
228 | }
229 | // -- End $_GET params --------------------------
230 |
231 | $products = $this->model_catalog_product->getTotalProducts(array(
232 | 'filter_category_id' => $category_id
233 | ));
234 |
235 | $json['result'] = $products;
236 |
237 | $this->response->setOutput(json_encode($json));
238 | }
239 |
240 | function __call( $methodName, $arguments ) {
241 | //call_user_func(array($this, str_replace('.', '_', $methodName)), $arguments);
242 | call_user_func(array($this, "_$methodName"), $arguments);
243 | }
244 | }
245 |
--------------------------------------------------------------------------------