OpenCart library part 1

In this series you will learn OpenCart in built library that will be handy when  when writing your own OpenCart modules and extensions.

After working on OpenCart for more than three years I think its good to share some of my knowledge with you guys

This part will mainly deal with the library/cart/cart.php for OpenCart 3.x.

The cart.php has the following methods:
$this->cart->update($cart_id, $quantity);
Updates the quantity of a product in the cart with ID = $cart_id

$this->cart->getProducts();
Returns an array of the products in the cart and their details.

$this->cart->add($product_id, $quantity = 1, $option = array(), $recurring_id = 0);
Adds a product of ID= $product_id to the cart,

$this->cart->remove($cart_id);
Deletes the cart with ID = $cart_id.

$this->cart->clear ();
Removes all the products in the current users cart at once

$this->cart->getRecurringProducts ();
Returns an array of products that are recurring.

$this->cart->getWeight ();
Returns the sum of the weights of all products in the cart that have shipping requirement.

$this->cart->getSubtotal ();
Returns the subtotal of all the products in the cart before applying tax

$this->cart->getTaxes();
Returns an array of total taxes applied to products in the cart:

$this->cart->getTotal();
Returns the total cost of all products in the cart after applying tax:
This is normally the final amount the customer has to pay.

$this->cart->countProducts();
Returns the total number of the products in the cart:

$this->cart->hasProducts();
Returns the count of the products in the cart:

$this->cart->hasRecurringProducts();
Returns the count of the recurring products in the cart:

$this->cart->hasStock();
Returns a Boolean value indicating whether product in the cart is available (true) or the product is out of stock (false).

$this->cart->hasShipping();
Returns a Boolean value indicating whether product in the cart requires shipping.

$this->cart->hasDownload();
Returns a Boolean value indicating whether a product is downloadable or not.

Stay tuned for the next article

Huh! you dont have to remember them  all, just know they exists and they could be of help!

If its helpful consider sharing and let me know your ideas 🙂

Get Open Cart Order PDF Invoice generator

Leave a Reply

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