Skip to content

Instantly share code, notes, and snippets.

@NateJLewis
Created May 16, 2015 00:42
Show Gist options
  • Save NateJLewis/a5016426025981a97e34 to your computer and use it in GitHub Desktop.
Save NateJLewis/a5016426025981a97e34 to your computer and use it in GitHub Desktop.
This is the old cart...if you look on line 47 you can see where I started editing it...maybe I should continue down that road??
public function add() {
$this->load->language('checkout/cart');
$json = array();
if (isset($this->request->post['product_id'])) {
$product_id = (int)$this->request->post['product_id'];
} else {
$product_id = 0;
}
$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
if (isset($this->request->post['quantity'])) {
$quantity = (int)$this->request->post['quantity'];
} else {
$quantity = 1;
}
// Get Product Sizes according to product ID
if (isset($this->request->post['product_size'])) {
$product_size = $this->request->post['product_size'];
} else {
$product_size = array();
}
$product_size = $this->model_catalog_product->getProductSize($this->request->post['product_id']);
// Get Product Color according to product ID
if (isset($this->request->post['product_color'])) {
$product_color = $this->request->post['product_color'];
} else {
$product_color = array();
}
$product_color = $this->model_catalog_product->getProductColor($this->request->post['product_id']);
// Get Product Style according to product ID
if (isset($this->request->post['product_style'])) {
$product_style = $this->request->post['product_style'];
} else {
$product_style = array();
}
$product_style = $this->model_catalog_product->getProductStyle($this->request->post['product_id']);
if (isset($this->request->post['recurring_id'])) {
$recurring_id = $this->request->post['recurring_id'];
} else {
$recurring_id = 0;
}
$recurrings = $this->model_catalog_product->getProfiles($product_info['product_id']);
if ($recurrings) {
$recurring_ids = array();
foreach ($recurrings as $recurring) {
$recurring_ids[] = $recurring['recurring_id'];
}
if (!in_array($recurring_id, $recurring_ids)) {
$json['error']['recurring'] = $this->language->get('error_recurring_required');
}
}
if (!$json) {
$this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $option, $recurring_id);
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('checkout/cart'));
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
// Totals
$this->load->model('extension/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_extension_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);
}
$json['total'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total));
} else {
$json['redirect'] = str_replace('&', '&', $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']));
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment