Skip to content

Commit

Permalink
more api work done
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkerr committed Jun 6, 2014
1 parent eb0ae64 commit 6ac0593
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 250 deletions.
46 changes: 7 additions & 39 deletions upload/catalog/controller/api/cart.php
Expand Up @@ -88,48 +88,14 @@ public function remove() {
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['reward']);

// Totals
$this->load->model('setting/extension');

$total_data = array();
$total = 0;
$taxes = $this->cart->getTaxes();

// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$sort_order = array();

$results = $this->model_setting_extension->getExtensions('total');

foreach ($results as $key => $value) {
$sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
}

array_multisort($sort_order, SORT_ASC, $results);

foreach ($results as $result) {
if ($this->config->get($result['code'] . '_status')) {
$this->load->model('total/' . $result['code']);

$this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
}
}

$sort_order = array();

foreach ($total_data as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}

array_multisort($sort_order, SORT_ASC, $total_data);
}
}

$this->response->setOutput(json_encode($json));
}

public function product() {
$this->load->language('checkout/cart');

$json = array();

// Products
Expand Down Expand Up @@ -188,14 +154,14 @@ public function product() {
}

// Voucher
$this->session->data['vouchers'] = array();
$json['vouchers'] = array();

if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $key => $voucher) {
$json['voucher'][] = array(
'code' => $voucher['voucher_id'],
'code' => $voucher['code'],
'description' => $voucher['description'],
'code' => substr(md5(mt_rand()), 0, 10),
'code' => $voucher['code'],
'from_name' => $voucher['from_name'],
'from_email' => $voucher['from_email'],
'to_name' => $voucher['to_name'],
Expand All @@ -211,6 +177,8 @@ public function product() {
}

function total() {
$this->load->language('checkout/cart');

$json = array();

// Totals
Expand Down
95 changes: 0 additions & 95 deletions upload/catalog/controller/api/customer.php

This file was deleted.

107 changes: 69 additions & 38 deletions upload/catalog/controller/api/order.php
@@ -1,7 +1,69 @@
<?php
<?php
class ControllerApiOrder extends Controller {
public function setCustomerDetails() {
$this->load->language('api/order');

$json = array();

// Customer
if ($this->request->post['customer_id']) {
$this->load->model('account/customer');

$customer_info = $this->model_account_customer->getCustomer($this->request->post['customer_id']);

if (!$customer_info) {
$json['error']['warning'] = $this->language->get('error_customer');
}
}

if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
$json['error']['firstname'] = $this->language->get('error_firstname');
}

if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
$json['error']['lastname'] = $this->language->get('error_lastname');
}

if ((utf8_strlen($this->request->post['email']) > 96) || (!preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email']))) {
$json['error']['email'] = $this->language->get('error_email');
}

if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
$json['error']['telephone'] = $this->language->get('error_telephone');
}

// Customer Group
if (isset($this->request->post['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->post['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}

// Custom field validation
$this->load->model('account/custom_field');

$custom_fields = $this->model_account_custom_field->getCustomFields(array('filter_customer_group_id' => $customer_group_id));

foreach ($custom_fields as $custom_field) {
if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
$json['error']['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}

if (!$json) {
$this->session->data['customer'] = array(
'customer_id' => $this->request->post['customer_id'],
'customer_group_id' => $this->request->post['lastname'],
'firstname' => $this->request->post['firstname'],
'lastname' => $this->request->post['lastname'],
'email' => $this->request->post['lastname'],
'telephone' => $this->request->post['lastname'],
'fax' => $this->request->post['lastname'],
'custom_field' => unserialize($this->request->post['custom_field'])
);
}

$this->response->setOutput(json_encode($json));
}

public function setShippingAddress() {
Expand Down Expand Up @@ -211,6 +273,11 @@ public function addOrder() {

$json = array();

// Customer
if (!isset($this->session->data['customer'])) {
$json['error']['warning'] = $this->language->get('error_customer');
}

// Payment Address
if (!isset($this->session->data['payment_address'])) {
$json['error']['warning'] = $this->language->get('error_payment_address');
Expand Down Expand Up @@ -264,43 +331,11 @@ public function addOrder() {
}

if ($product['minimum'] > $product_total) {
$redirect = $this->url->link('checkout/cart');
$json['error']['warning'] = $this->language->get('error_minimum');

break;
}
}

// Customer
if ($this->request->post['customer_id']) {
$this->load->model('account/customer');

$customer_info = $this->model_account_customer->getCustomer($this->request->post['customer_id']);

if (!$customer_info) {
$json['error']['warning'] = $this->language->get('error_customer');
}
}

if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
$json['error']['firstname'] = $this->language->get('error_firstname');
}

if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
$json['error']['lastname'] = $this->language->get('error_lastname');
}

if ((utf8_strlen($this->request->post['email']) > 96) || (!preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email']))) {
$json['error']['email'] = $this->language->get('error_email');
}

if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
$json['error']['telephone'] = $this->language->get('error_telephone');
}






if (!$json) {
// Customer Group
Expand Down Expand Up @@ -482,10 +517,6 @@ public function addOrder() {
$this->response->setOutput(json_encode($json));
}

public function calculate() {

}

public function editOrder() {
// Add the coupon, vouchers and reward points back
if (isset($this->request->get['order_id'])) {
Expand Down
25 changes: 14 additions & 11 deletions upload/catalog/controller/api/payment.php
@@ -1,11 +1,13 @@
<?php
class ControllerApiPayment extends Controller {
public function index() {
$this->load->language('module/reward');

$json = array();

// Validate if payment address has been set.
// Payment Address
if (!isset($this->session->data['payment_address'])) {
$json['error']['payment_address'] = '';
$json['error']['payment_address'] = $this->language->get('error_payment_address');
}

if (!$json) {
Expand Down Expand Up @@ -34,10 +36,7 @@ public function index() {
}
}

// Payment Methods
$method_data = array();

$this->load->model('setting/extension');
$json['payment_method'] = array();

$results = $this->model_setting_extension->getExtensions('payment');

Expand All @@ -53,25 +52,29 @@ public function index() {
if ($cart_has_recurring > 0) {
if (method_exists($this->{'model_payment_' . $result['code']}, 'recurringPayments')) {
if ($this->{'model_payment_' . $result['code']}->recurringPayments() == true) {
$method_data[$result['code']] = $method;
$json['payment_method'][$result['code']] = $method;
}
}
} else {
$method_data[$result['code']] = $method;
$json['payment_method'][$result['code']] = $method;
}
}
}
}

$sort_order = array();

foreach ($method_data as $key => $value) {
foreach ($json['payment_method'] as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}

array_multisort($sort_order, SORT_ASC, $method_data);
array_multisort($sort_order, SORT_ASC, $json['payment_method']);

$this->session->data['payment_methods'] = $method_data;
if ($json['payment_method']) {
$this->session->data['payment_methods'] = $json['payment_method'];
} else {
$json['error']['payment_method'] = $this->language->get('error_no_payment');
}
}

$this->response->setOutput(json_encode($json));
Expand Down
2 changes: 1 addition & 1 deletion upload/catalog/controller/api/reward.php
Expand Up @@ -50,7 +50,7 @@ public function maximum() {
$this->response->setOutput(json_encode($json));
}

public function avaliable() {
public function available() {
$json = array();

$json['points'] = $this->customer->getRewardPoints();
Expand Down

0 comments on commit 6ac0593

Please sign in to comment.