OpenCart – Updating Cart Session

In a previous article we explained how the add function works for Opencart’s shopping cart. In this article we will describe how the UPDATE function works if you should have the need to update an item from your shopping cart. A page that you can perform this edit would be the main shopping cart page located at index.php?route=checkout/cart

The Cart Array

In order to update any item in the cart there must already be items present. If you attempt to travel to the shopping cart page with an empty cart it will give you a warning along with a way to get back to the home page. The cart array is always present, but must not be empty. If you are interested in how the cart array is established you can go over this in the previous article.

Setting up update

Now we will look at the UPDATE function to describe how it is going to work. Find this function in cart.php:

// Update
		if (!empty($this->request->post['quantity'])) {
			foreach ($this->request->post['quantity'] as $key => $value) {
				$this->cart->update($key, $value);

This function will update any EXISTING cart array by contacting the following function located in the system root here: /system/library/cart.php

public function update($key, $qty) {
		if ((int)$qty && ((int)$qty > 0)) {
			$this->session->data['cart'][$key] = (int)$qty;
		} else {

		$this->data = array();

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

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

Author Spotlight

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.

Leave a Reply

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