Taking a Deeper Look at OpenCart’s “Cart”

Yes that’s correct, you know that it works but do you know how? Most don’t and to be fair, most don’t need to know nor do they want to know. However for those that are learning the basics of how a shopping cart works then this posting is for you. I will reveal to you everything that happens from the point of pressing ADD TO CART, to viewing items that you have added. This passage will be using code taken from the latest Opencart version 1.5.4.1

Phase One (clicking the add to cart button)

For Opencart versions 1.5x, the add to cart button relies on the use of AJAX (Asynchronous JavaScript and XML) where on earlier versions it does not. Either way, both submit an HTTP POST with data to a Control file which in turn contacts a system file. All methods of adding to the cart session use the same function but the data could come from different areas in the View. For example: in catalog/view/theme/your_theme/template/product/category.tpl the add to cart buttons contact a function that is within catalog/view/javascript/common.js, where in catalog/view/theme/your_theme/template/product/product.tpl the function is embedded in the TPL itself. Both contact a Control Function entitled public function add() { which is located in catalog/controller/checkout/cart.php . During the add-to-cart process the Model is never used.

Before continuing on we want to reiterate that by default there are two JavaScript functions used to contact the Control , which in turn contacts the system file “which we will discuss later”:

  1. The JavaScript function, function addToCart(product_id, quantity) { is used mostly, and is found in catalog/view/javascript/common.js. This is used by all of the default Opencart modules that offer Add-to-cart buttons, specifically pages that have MORE THAN ONE BUTTON. With the help of AJAX, this allows many communications with the same function by passing what are called “Arguments“, instead of having a gazillion functions with different Element ID’s on the same page “which would be necessary with many buttons.” addToCart(ARGUMENT ONE, ARGUMENT TWO) – product_id & quantity.
  2. The JavaScript function, $(‘#button-cart’).bind(‘click’, function() { is used on the product details page found at the bottom of catalog/view/theme/your_theme/template/product/product.tpl. This function is for the product details page and is for ONE add-to-cart button only.

When we use the word “Control”, “Model”, and “View” we are talking about the MVC-L (the L standing for language). This article won’t be about MVC-L and what it is, but it helps to know the basics of MVC-L considering Open Cart “is” just that.

Phase Two (contacting stored procedure(s) to add to cart)

We have learned that the Add-To-Cart buttons when clicked make good use of JavaScript(with the help of AJAX) to first contact the control file, who’s function communicates with the Core Cart Function. Let’s take a closer look, starting with the JavaScript.

In catalog/view/javascript/common.js you will see the following line of code: (highlighted in red)

function addToCart(product_id, quantity) {
quantity = typeof(quantity) != ‘undefined’ ? quantity : 1;
$.ajax({
url: ‘index.php?route=checkout/cart/add’,
type: ‘post’,
data: ‘product_id=’ + product_id + ‘&quantity=’ + quantity,
dataType: ‘json’,
success: function(json) {
$(‘.success, .warning, .attention, .information, .error’).remove();
if (json['redirect']) {
location = json['redirect'];
}
if (json['success']) {
$(‘#notification’).html(‘<div style=”display: none;”>’ + json['success'] + ‘<img src=”catalog/view/theme/default/image/close.png” alt=”” /></div>’);
$(‘.success’).fadeIn(‘slow’);
$(‘#cart-total’).html(json['total']);
$(‘html, body’).animate({ scrollTop: 0 }, ‘slow’);
}
}
});
}

What you see in red is the AJAX CALL to the control file cart.php

Here is a very simplified explanation on how AJAX works with Opencart add-to-cart procedure:

In AJAX, the user sends a request that executes an action (which is a POST or a GET ) and the action’s response is shown into a layer, identified by an ID, without reloading the full page. This is why the only thing you see is the green success bar at the top. Next, in catalog/controller/checkout/cart.php you will see a function called public function add(). This is the function being called publicly by url: ‘index.php?route=checkout/cart/add’ in the Ajax. Within this function you will see this code:

if (!$json) {
$this->cart->add($this->request->post['product_id'], $quantity, $option);
$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’));

What is happening here? First, the code checks to see if there are any required fields left empty. If this checks out then it adds the item to the cart array, hence the if (!$json) {. This basically states: IF EMPTY $json , ADD TO CART. }ELSE{ send error(s) to display in the html.

Phase Three (adding to the cart array)

Now that we have pressed the add to cart button, contacted the control by means of using AJAX and passed validation, we must now contact the core system file found in system/library/cart.php Above you saw the call for $this->cart->add($this->request->post['product_id'], $quantity, $option); This is looking for a function that will be explained below.

Before I go on further to explain how this function works we need to discuss what has already happened LONG before you ever pressed the add to cart button. In a nutshell, all items along with their options are stored in a session variable. This session is started when you reach the store for the first time and does not die until you either close your browser (in which case it might still survive depending upon your browser settings) OR if you clean your cache, and lastly if you complete a checkout entirely. If you scroll to the top of system/library/cart.php you will see the following code:

if (!isset($this->session->data['cart']) || !is_array($this->session->data['cart'])) {
$this->session->data['cart'] = array();
}

This very simply states that, IF NO CART SESSION EXISTS OR IF CART SESSION IS NOT ARRAY, CREATE ONE. The array will remain empty until you start adding items.

Continuing on with the ADD function. The function looks like this:

public function add($product_id, $qty = 1, $option = array()) {
if (!$option) {
$key = (int)$product_id;
} else {
$key = (int)$product_id . ‘:’ . base64_encode(serialize($option));
}
if ((int)$qty && ((int)$qty > 0)) {
if (!isset($this->session->data['cart'][$key])) {
$this->session->data['cart'][$key] = (int)$qty;
} else {
$this->session->data['cart'][$key] += (int)$qty;
}
}$this->data = array();
}

In red I highlighted the arguments being passed to the function by the control. The arguments in the control look like this: $this->cart->add($this->request->post['product_id'], $quantity, $option) Passing arguments is a nifty way to distribute data from one function to the next and in this case we are dealing with the product_id, quantity, and options (if any). Let’s look closely at the first part of the function:

if (!$option) {
$key = (int)$product_id;
} else {
$key = (int)$product_id . ‘:’ . base64_encode(serialize($option));
}

What you are seeing is: IF NO OPTION(s) variable $key = $product_id }ELSE{ variable $key = STRING. This string is very important; it holds the product_id and the entire option array, concatenated together by a ‘:’. You will notice the $option variable is base64_encode(serialize(). Why do this? This encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean. Likewise, the serialize function is designed to keep array’s intact so you can use them again later.

And now the last part of this function:

if ((int)$qty && ((int)$qty > 0)) {
if (!isset($this->session->data['cart'][$key])) {
$this->session->data['cart'][$key] = (int)$qty;
} else {
$this->session->data['cart'][$key] += (int)$qty;
}
}$this->data = array();

And here is the function with comments to explain what is happening:

if ((int)$qty && ((int)$qty > 0)) {

//validation that quantity is greater than 0 and correct form

if (!isset($this->session->data['cart'][$key])) {

//if the product DOESN’T exist in cart with matching properties/options. We are using the variable $key to run the check

$this->session->data['cart'][$key] = (int)$qty;

//add product to cart array (new product)

} else {

$this->session->data['cart'][$key] += (int)$qty;

//this is if product DOES exist in cart with matching properties/options //Add another of the same to change quantity. This is done by (+=)
}
}

In short, we add a new item to the cart if it doesn’t already exist OR we increase the quantity of an existing item because the system has detected an identical match with the same options/properties. If you remember that we started with the session array: $this->session->data['cart'] as an empty array. Now we are filling the array with a KEY and a VALUE. The KEY is $key and the VALUE is the quantity, so it is declared here: $this->session->data['cart'][$key] =

The cart session array is now filled. It could be small or it could be VERY LARGE depending upon how many products or options you have added to those products. Displayed below is a print_r() of a cart filled with 4 items. This is so you can see what exactly is in the array. You can do this at any time by running the following line:

<?php print_r($this->session->data['cart']);?>:

The above outputs:

Array ( [44] => 1 [47:YToxOntpOjIyNTtzOjEwOiIyMDExLTA0LTIyIjt9] => 1 [40] => 1 [30:YToxOntpOjIyNjtzOjI6IjE1Ijt9] => 1 )

Notice the KEY of each position is the product_id and serialized options array, separated by a ‘:’

Now we get to the good stuff! Just how does Open Cart use this cart array to show the cart contents to the user on the front end?

Phase Four (displaying the cart contents)

The cart contents are displayed in many places throughout the customers shopping experience. For our in depth glance in how this actually happens we are going to choose the shopping cart page found at index.php?route=checkout/cart

In catalog/controller/checkout/cart.php you will see the following code

$products = $this->cart->getProducts();

This little line of code is most important in that it makes a call to the function getProducts which is a core procedure located in system/library/cart.php. The variable $products now has the entire cart array + all possible options and can be “iterated” through. To iterate means to sift through an array, gathering it’s contents or to LOOP through. Let’s take a look at what is happening in the function getProducts(); In system/library/cart.php find this function towards the top:

public function getProducts() {
if (!$this->data) {
foreach ($this->session->data['cart'] as $key => $quantity) {
$product = explode(‘:’, $key);
$product_id = $product[0];
$stock = true;// Options
if (isset($product[1])) {
$options = unserialize(base64_decode($product[1]));
} else {
$options = array();
}$product_query = $this->db->query(“SELECT * FROM ” . DB_PREFIX . “product p LEFT JOIN ” . DB_PREFIX . “product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = ‘” . (int)$product_id . “‘ AND pd.language_id = ‘” . (int)$this->config->get(‘config_language_id’) . “‘ AND p.date_available <= NOW() AND p.status = ’1′”); if ($product_query->num_rows) {
$option_price = 0;
$option_points = 0;
$option_weight = 0;$option_data = array();foreach ($options as $product_option_id => $option_value) {
$option_query = $this->db->query(“SELECT po.product_option_id, po.option_id, od.name, o.type FROM ” . DB_PREFIX . “product_option po LEFT JOIN `” . DB_PREFIX . “option` o ON (po.option_id = o.option_id) LEFT JOIN ” . DB_PREFIX . “option_description od ON (o.option_id = od.option_id) WHERE po.product_option_id = ‘” . (int)$product_option_id . “‘ AND po.product_id = ‘” . (int)$product_id . “‘ AND od.language_id = ‘” . (int)$this->config->get(‘config_language_id’) . “‘”);if ($option_query->num_rows) {
if ($option_query->row['type'] == ‘select’ || $option_query->row['type'] == ‘radio’ || $option_query->row['type'] == ‘image’) {
$option_value_query = $this->db->query(“SELECT pov.option_value_id, ovd.name, pov.quantity, pov.subtract, pov.price, pov.price_prefix, pov.points, pov.points_prefix, pov.weight, pov.weight_prefix FROM ” . DB_PREFIX . “product_option_value pov LEFT JOIN ” . DB_PREFIX . “option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN ” . DB_PREFIX . “option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_option_value_id = ‘” . (int)$option_value . “‘ AND pov.product_option_id = ‘” . (int)$product_option_id . “‘ AND ovd.language_id = ‘” . (int)$this->config->get(‘config_language_id’) . “‘”);if ($option_value_query->num_rows) {
if ($option_value_query->row['price_prefix'] == ‘+’) {
$option_price += $option_value_query->row['price'];
} elseif ($option_value_query->row['price_prefix'] == ‘-’) {
$option_price -= $option_value_query->row['price'];
}if ($option_value_query->row['points_prefix'] == ‘+’) {
$option_points += $option_value_query->row['points'];
} elseif ($option_value_query->row['points_prefix'] == ‘-’) {
$option_points -= $option_value_query->row['points'];
}if ($option_value_query->row['weight_prefix'] == ‘+’) {
$option_weight += $option_value_query->row['weight'];
} elseif ($option_value_query->row['weight_prefix'] == ‘-’) {
$option_weight -= $option_value_query->row['weight'];
}if ($option_value_query->row['subtract'] && (!$option_value_query->row['quantity'] || ($option_value_query->row['quantity'] < $quantity))) { $stock = false; } $option_data[] = array( ‘product_option_id’ => $product_option_id,
‘product_option_value_id’ => $option_value,
‘option_id’ => $option_query->row['option_id'],
‘option_value_id’ => $option_value_query->row['option_value_id'],
‘name’ => $option_query->row['name'],
‘option_value’ => $option_value_query->row['name'],
‘type’ => $option_query->row['type'],
‘quantity’ => $option_value_query->row['quantity'],
‘subtract’ => $option_value_query->row['subtract'],
‘price’ => $option_value_query->row['price'],
‘price_prefix’ => $option_value_query->row['price_prefix'],
‘points’ => $option_value_query->row['points'],
‘points_prefix’ => $option_value_query->row['points_prefix'],
‘weight’ => $option_value_query->row['weight'],
‘weight_prefix’ => $option_value_query->row['weight_prefix']
);
}
} elseif ($option_query->row['type'] == ‘checkbox’ && is_array($option_value)) {
foreach ($option_value as $product_option_value_id) {
$option_value_query = $this->db->query(“SELECT pov.option_value_id, ovd.name, pov.quantity, pov.subtract, pov.price, pov.price_prefix, pov.points, pov.points_prefix, pov.weight, pov.weight_prefix FROM ” . DB_PREFIX . “product_option_value pov LEFT JOIN ” . DB_PREFIX . “option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN ” . DB_PREFIX . “option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_option_value_id = ‘” . (int)$product_option_value_id . “‘ AND pov.product_option_id = ‘” . (int)$product_option_id . “‘ AND ovd.language_id = ‘” . (int)$this->config->get(‘config_language_id’) . “‘”);if ($option_value_query->num_rows) {
if ($option_value_query->row['price_prefix'] == ‘+’) {
$option_price += $option_value_query->row['price'];
} elseif ($option_value_query->row['price_prefix'] == ‘-’) {
$option_price -= $option_value_query->row['price'];
}if ($option_value_query->row['points_prefix'] == ‘+’) {
$option_points += $option_value_query->row['points'];
} elseif ($option_value_query->row['points_prefix'] == ‘-’) {
$option_points -= $option_value_query->row['points'];
}if ($option_value_query->row['weight_prefix'] == ‘+’) {
$option_weight += $option_value_query->row['weight'];
} elseif ($option_value_query->row['weight_prefix'] == ‘-’) {
$option_weight -= $option_value_query->row['weight'];
}if ($option_value_query->row['subtract'] && (!$option_value_query->row['quantity'] || ($option_value_query->row['quantity'] < $quantity))) { $stock = false; } $option_data[] = array( ‘product_option_id’ => $product_option_id,
‘product_option_value_id’ => $product_option_value_id,
‘option_id’ => $option_query->row['option_id'],
‘option_value_id’ => $option_value_query->row['option_value_id'],
‘name’ => $option_query->row['name'],
‘option_value’ => $option_value_query->row['name'],
‘type’ => $option_query->row['type'],
‘quantity’ => $option_value_query->row['quantity'],
‘subtract’ => $option_value_query->row['subtract'],
‘price’ => $option_value_query->row['price'],
‘price_prefix’ => $option_value_query->row['price_prefix'],
‘points’ => $option_value_query->row['points'],
‘points_prefix’ => $option_value_query->row['points_prefix'],
‘weight’ => $option_value_query->row['weight'],
‘weight_prefix’ => $option_value_query->row['weight_prefix']
);
}
}
} elseif ($option_query->row['type'] == ‘text’ || $option_query->row['type'] == ‘textarea’ || $option_query->row['type'] == ‘file’ || $option_query->row['type'] == ‘date’ || $option_query->row['type'] == ‘datetime’ || $option_query->row['type'] == ‘time’) {
$option_data[] = array(
‘product_option_id’ => $product_option_id,
‘product_option_value_id’ => ”,
‘option_id’ => $option_query->row['option_id'],
‘option_value_id’ => ”,
‘name’ => $option_query->row['name'],
‘option_value’ => $option_value,
‘type’ => $option_query->row['type'],
‘quantity’ => ”,
‘subtract’ => ”,
‘price’ => ”,
‘price_prefix’ => ”,
‘points’ => ”,
‘points_prefix’ => ”,
‘weight’ => ”,
‘weight_prefix’ => ”
);
}
}
}if ($this->customer->isLogged()) {
$customer_group_id = $this->customer->getCustomerGroupId();
} else {
$customer_group_id = $this->config->get(‘config_customer_group_id’);
}$price = $product_query->row['price'];// Product Discounts
$discount_quantity = 0;foreach ($this->session->data['cart'] as $key_2 => $quantity_2) {
$product_2 = explode(‘:’, $key_2);if ($product_2[0] == $product_id) {
$discount_quantity += $quantity_2;
}
}$product_discount_query = $this->db->query(“SELECT price FROM ” . DB_PREFIX . “product_discount WHERE product_id = ‘” . (int)$product_id . “‘ AND customer_group_id = ‘” . (int)$customer_group_id . “‘ AND quantity <= ‘” . (int)$discount_quantity . “‘ AND ((date_start = ’0000-00-00′ OR date_start < NOW()) AND (date_end = ’0000-00-00′ OR date_end > NOW())) ORDER BY quantity DESC, priority ASC, price ASC LIMIT 1″);if ($product_discount_query->num_rows) {
$price = $product_discount_query->row['price'];
}// Product Specials
$product_special_query = $this->db->query(“SELECT price FROM ” . DB_PREFIX . “product_special WHERE product_id = ‘” . (int)$product_id . “‘ AND customer_group_id = ‘” . (int)$customer_group_id . “‘ AND ((date_start = ’0000-00-00′ OR date_start < NOW()) AND (date_end = ’0000-00-00′ OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1″);

if ($product_special_query->num_rows) {
$price = $product_special_query->row['price'];
}

// Reward Points
$product_reward_query = $this->db->query(“SELECT points FROM ” . DB_PREFIX . “product_reward WHERE product_id = ‘” . (int)$product_id . “‘ AND customer_group_id = ‘” . (int)$customer_group_id . “‘”);

if ($product_reward_query->num_rows) {
$reward = $product_reward_query->row['points'];
} else {
$reward = 0;
}

// Downloads
$download_data = array();

$download_query = $this->db->query(“SELECT * FROM ” . DB_PREFIX . “product_to_download p2d LEFT JOIN ” . DB_PREFIX . “download d ON (p2d.download_id = d.download_id) LEFT JOIN ” . DB_PREFIX . “download_description dd ON (d.download_id = dd.download_id) WHERE p2d.product_id = ‘” . (int)$product_id . “‘ AND dd.language_id = ‘” . (int)$this->config->get(‘config_language_id’) . “‘”);

foreach ($download_query->rows as $download) {
$download_data[] = array(
‘download_id’ => $download['download_id'],
‘name’ => $download['name'],
‘filename’ => $download['filename'],
‘mask’ => $download['mask'],
‘remaining’ => $download['remaining']
);
}

// Stock
if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $quantity)) { $stock = false; } $this->data[$key] = array(
‘key’ => $key,
‘product_id’ => $product_query->row['product_id'],
‘name’ => $product_query->row['name'],
‘model’ => $product_query->row['model'],
‘shipping’ => $product_query->row['shipping'],
‘image’ => $product_query->row['image'],
‘option’ => $option_data,
‘download’ => $download_data,
‘quantity’ => $quantity,
‘minimum’ => $product_query->row['minimum'],
‘subtract’ => $product_query->row['subtract'],
‘stock’ => $stock,
‘price’ => ($price + $option_price),
‘total’ => ($price + $option_price) * $quantity,
‘reward’ => $reward * $quantity,
‘points’ => ($product_query->row['points'] ? ($product_query->row['points'] + $option_points) * $quantity : 0),
‘tax_class_id’ => $product_query->row['tax_class_id'],
‘weight’ => ($product_query->row['weight'] + $option_weight) * $quantity,
‘weight_class_id’ => $product_query->row['weight_class_id'],
‘length’ => $product_query->row['length'],
‘width’ => $product_query->row['width'],
‘height’ => $product_query->row['height'],
‘length_class_id’ => $product_query->row['length_class_id']
);
} else {
$this->remove($key);
}
}
}

return $this->data;
}

For the sake of time we aren’t going to go over the entire function but just give you a general idea of what is going on. Let’s just take a look at the first few lines here:
foreach ($this->session->data['cart'] as $key => $quantity) {
//loop through the entire cart array. Everything below this line will repeat itself as many times as necc.

$product = explode(‘:’, $key);
$product_id = $product[0];
$stock = true;

In foreach ($this->session->data['cart'] as $key => $quantity) {  we see a php FOREACH() which allows you to loop through the array. Each time it loops through it executes all procedures between the { and } of the for loop which in this case is a LOT OF CODE.  If you remember in our discussion about the cart array above, the $key is a string separated by a ‘:’ so let’s take that and EXPLODE it into an array so we can better deal with it.

This is being done here: $product = explode(‘:’, $key); //$product is now an array. Further explanation of explode HERE.

The first index of the array is the product_id so we declare that into a variable like this: $product_id = $product[0];

Now let’s deal with the possible options we just exploded into an array $products;

// Options//If any options at all, execute code unserialize + decode. Else, declare empty array.
if (isset($product[1])) {
$options = unserialize(base64_decode($product[1]));
} else {
$options = array();
}

In general, everything below that line gathers all data concerning the products and options found within the cart and puts them in ONE LARGE ARRAY.  During this process the database is communicated with at great length in order to gather certain item/option properties. This new array is dealt with in the control procedure $products = $this->cart->getProducts(); which we already mentioned. If you scroll to the bottom of the function we were just working with you will see the following code:

$this->data[$key] = array(
‘key’             => $key,
‘product_id’      => $product_query->row['product_id'],
‘name’            => $product_query->row['name'],
‘model’           => $product_query->row['model'],
‘shipping’        => $product_query->row['shipping'],
‘image’           => $product_query->row['image'],
‘option’          => $option_data,
‘download’        => $download_data,
‘quantity’        => $quantity,
‘minimum’         => $product_query->row['minimum'],
‘subtract’        => $product_query->row['subtract'],
‘stock’           => $stock,
‘price’           => ($price + $option_price),
‘total’           => ($price + $option_price) * $quantity,
‘reward’          => $reward * $quantity,
‘points’          => ($product_query->row['points'] ? ($product_query->row['points'] + $option_points) * $quantity : 0),
‘tax_class_id’    => $product_query->row['tax_class_id'],
‘weight’          => ($product_query->row['weight'] + $option_weight) * $quantity,
‘weight_class_id’ => $product_query->row['weight_class_id'],
‘length’          => $product_query->row['length'],
‘width’           => $product_query->row['width'],
‘height’          => $product_query->row['height'],
‘length_class_id’ => $product_query->row['length_class_id']

This is the master array that is RETURNED to $this->cart->getProducts();
Now back to catalog/controller/checkout/cart.php find this line of code:

foreach ($products as $product) {

This code is the foreach() loop set up to go through the array we just set up in system/library/cart.php. It is responsible for displaying all of the content seen in the shopping cart page along with the product options. Everything below foreach ($products as $product) { will repeat itself as many times as necessary until ALL PRODUCTS HAVE BEEN DEALT WITH IN THE ARRAY.

Product Options:

A few lines down you will find this code which allows us to iterate through the option array which was tucked inside the main array:

$option_data = array();

foreach ($product['option'] as $option) {

Now in catalog/controller/checkout/cart.php look for this code:

$this->data['products'][] = array(
‘key’      => $product['key'],
‘thumb’    => $image,
‘name’     => $product['name'],
‘model’    => $product['model'],
‘option’   => $option_data,
‘quantity’ => $product['quantity'],
‘stock’    => $product['stock'] ? true : !(!$this->config->get(‘config_stock_checkout’) || $this->config->get(‘config_stock_warning’)),
‘reward’   => ($product['reward'] ? sprintf($this->language->get(‘text_points’), $product['reward']) : ”),
‘price’    => $price,
‘total’    => $total,
‘href’     => $this->url->link(‘product/product’, ‘product_id=’ . $product['product_id']),
‘remove’   => $this->url->link(‘checkout/cart’, ‘remove=’ . $product['key'])
);

This is the array being set up to be echoed on this page: catalog/view/theme/your_theme/template/product/cart.tpl

Open catalog/view/theme/your_theme/template/product/cart.tpl and find this code:

<?php
foreach ($products as $product) {

Now we can iterate through $products and display cart contents. $products in this file = $this->data['products'][] in the control.

Looking for quality OpenCart Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , , , | Posted under OpenCart | RSS 2.0

Author Spotlight

Joe Stenhouse

Joe Stenhouse

I am a web application developer that specializes in PHP, JAVASCRIPT, MYSQL, HTML, and CSS. We manifest exciting potentials within the world wide web through means of innovation.

5 Comments on Taking a Deeper Look at OpenCart’s “Cart”

  1. Sinead says:

    Hey!

    Great post :) Thanks for posting this.

    Do you know where I could find one like this for how the ‘delete’ and ‘update’ functions work.

  2. Keith says:

    thanks for posting this. Just starting with Open Cart. Great Article. I look forward to more and agree with Sinead that the other two would be great subjects

Leave a Reply

Your email address will not be published. Required fields are marked *


− 1 = 4

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>