loading

How to Shopping Cart Implementation in CodeIgniter

How to Shopping Cart Implementation in CodeIgniter

How to Shopping Cart Implementation in CodeIgniter

0 Sales

Free

The Shopping Cart is an essential component of any e-commerce platform since it allows the user to pick things for purchase. It enables online buyers to purchase many things at the same time. The shopping cart calculates the total amount of the transaction, manages delivery, and displays the order preview during checkout. The most difficult aspect of developing an e-commerce website is integrating a shopping cart.


In PHP, the SESSION is used to create a shopping cart. A shopping cart may be simply connected using Cart Class if your application is built with CodeIgniter. CodeIgniter includes the Cart library, which aids in the integration of shopping cart functionality into the CodeIgniter framework. We will demonstrate how to construct a shopping cart in CodeIgniter in this tutorial.

This shopping cart tutorial walks you through the cart and checkout process in the CodeIgniter 3 application. The CodeIgniter Cart library will be used to create fundamental cart functionality in the sample script. Additionally, the client and order information will be saved in the MySQL database.

Before you begin, examine the CodeIgniter Shopping Cart's file structure.

codeigniter_shopping_cart/
├── application/
│   ├── controllers/
│   │   ├── Products.php
│   │   ├── Cart.php
│   │   └── Checkout.php
│   ├── models/
│   │   └── Product.php
│   └── views/
│       ├── products/
│       │   └── index.php
│       ├── cart/
│       │   └── index.php
│       └── checkout/
│           ├── index.php
│           └── order-success.php
├── uploads/
│   └── product_images/
└── assets/
    ├── css/
    │   ├── bootstrap.min.css
    │   └── style.css
    └── js/
        └── jquery.min.js

Create Database Tables

Some tables in the database must be established to record information about items, customers, and orders.

In the MySQL database, the below SQL generates a products table.

CREATE TABLE `products` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `image` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `description` text COLLATE utf8_unicode_ci NOT NULL,
 `price` float(10,2) NOT NULL,
 `created` datetime NOT NULL,
 `modified` datetime NOT NULL,
 `status` enum('1','0') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1' COMMENT '1=Active | 0=Inactive',
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

In the MySQL database, the below SQL generates a customers table.

CREATE TABLE `customers` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
 `email` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
 `phone` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
 `address` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `created` datetime NOT NULL,
 `modified` datetime NOT NULL,
 `status` enum('1','0') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1' COMMENT '1=Active | 0=Inactive',
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

The SQL below creates a table called orders in the MySQL database.

CREATE TABLE `orders` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `customer_id` int(11) NOT NULL,
 `grand_total` float(10,2) NOT NULL,
 `created` datetime NOT NULL,
 `modified` datetime NOT NULL,
 `status` enum('1','0') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1' COMMENT '1=Active | 0=Inactive',
 PRIMARY KEY (`id`),
 KEY `customer_id` (`customer_id`),
 CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

The SQL below creates a table called order items in the MySQL database.

CREATE TABLE `order_items` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `order_id` int(11) NOT NULL,
 `product_id` int(11) NOT NULL,
 `quantity` int(5) NOT NULL,
 `sub_total` float(10,2) NOT NULL,
 PRIMARY KEY (`id`),
 KEY `order_id` (`order_id`),
 CONSTRAINT `order_items_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Config

autoload.php
Specify which libraries and helpers should be loaded by default.

$autoload['libraries'] = array('database''session');


$autoload['helper'] = array('url');

Controllers

The shopping cart, checkout, and order submission processes are handled by the controllers listed below.

1. Products.php
The Products controller is in charge of the product listing and the Add to Cart functionality.

1. __construct() – Load cart library and product model.
2. index()

 - Using the Product model's getRows() method, retrieve the products from the database.
 - Product data must be given in order to see and load a product list.

3. addToCart()

 - Get information on a certain product by ID.
 - Insert a product into the cart using the insert() function of the Cart class.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Products extends CI_Controller{
    
    function  __construct(){
        parent::__construct();
        
        // Load cart library
        $this->load->library('cart');
        
        // Load product model
        $this->load->model('product');
    }
    
    function index(){
        $data = array();
        
        // Fetch products from the database
        $data['products'] = $this->product->getRows();
        
        // Load the product list view
        $this->load->view('products/index'$data);
    }
    
    function addToCart($proID){
        
        // Fetch specific product by ID
        $product $this->product->getRows($proID);
        
        // Add product to the cart
        $data = array(
            'id'    => $product['id'],
            'qty'    => 1,
            'price'    => $product['price'],
            'name'    => $product['name'],
            'image' => $product['image']
        );
        $this->cart->insert($data);
        
        // Redirect to the cart page
        redirect('cart/');
    }
    
}

2. Cart.php
The shopping cart functionality is handled by the Cart controller.

1. __construct() – Load cart library and product model.
2. index()

 - Using the Cart class's contents() function, extract cart data from the session.
 - Load cart view and pass cart content to view.
3. updateItemQty() –  The jQuery Ajax request calls this function to change the amount of the cart item.
 - Update the item's amount based on the rowid using the Cart class's update() function.
4. removeItem() – This method is used to remove an item from the shopping basket.
 - Remove the item from the cart using the Cart class's remove() function based on the rowid.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Cart extends CI_Controller{
    
    function  __construct(){
        parent::__construct();
        
        // Load cart library
        $this->load->library('cart');
        
        // Load product model
        $this->load->model('product');
    }
    
    function index(){
        $data = array();
        
        // Retrieve cart data from the session
        $data['cartItems'] = $this->cart->contents();
        
        // Load the cart view
        $this->load->view('cart/index'$data);
    }
    
    function updateItemQty(){
        $update 0;
        
        // Get cart item info
        $rowid $this->input->get('rowid');
        $qty $this->input->get('qty');
        
        // Update item in the cart
        if(!empty($rowid) && !empty($qty)){
            $data = array(
                'rowid' => $rowid,
                'qty'   => $qty
            );
            $update $this->cart->update($data);
        }
        
        // Return response
        echo $update?'ok':'err';
    }
    
    function removeItem($rowid){
        // Remove item from cart
        $remove $this->cart->remove($rowid);
        
        // Redirect to the cart page
        redirect('cart/');
    }
    
}

3. Checkout.php

1. __construct() – Load the form library and helper, the cart library, and the product model.
2. index()

 - If the user's cart is empty, redirect them.
 - If the order request is submitted,

      - Use the Form Validation library to validate the form data.
      - Enter the consumer information into the database.
      - Using the placeOrder() method, insert order data into the database.
      - Redirect to the order completion page.
 - Using the Cart class's contents() function, you may retrieve cart data from a session.
 - Load the checkout view and pass cart stuff to it.
3. placeOrder()

 - Enter order data into the database.
 - Retrieve the contents of the shopping cart and enter the order items into the database.
 - Remove all goods from the cart and use the Cart class's destroy() function to destroy the cart's contents.
4. orderSuccess()

  - Retrieve the order information from the database.

 - Pass order data to the view, and then load the order success view.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Checkout extends CI_Controller{
    
    function  __construct(){
        parent::__construct();
        
        // Load form library & helper
        $this->load->library('form_validation');
        $this->load->helper('form');
        
        // Load cart library
        $this->load->library('cart');
        
        // Load product model
        $this->load->model('product');
        
        $this->controller 'checkout';
    }
    
    function index(){
        // Redirect if the cart is empty
        if($this->cart->total_items() <= 0){
            redirect('products/');
        }
        
        $custData $data = array();
        
        // If order request is submitted
        $submit $this->input->post('placeOrder');
        if(isset($submit)){
            // Form field validation rules
            $this->form_validation->set_rules('name''Name''required');
            $this->form_validation->set_rules('email''Email''required|valid_email');
            $this->form_validation->set_rules('phone''Phone''required');
            $this->form_validation->set_rules('address''Address''required');
            
            // Prepare customer data
            $custData = array(
                'name'     => strip_tags($this->input->post('name')),
                'email'     => strip_tags($this->input->post('email')),
                'phone'     => strip_tags($this->input->post('phone')),
                'address'=> strip_tags($this->input->post('address'))
            );
            
            // Validate submitted form data
            if($this->form_validation->run() == true){
                // Insert customer data
                $insert $this->product->insertCustomer($custData);
                
                // Check customer data insert status
                if($insert){
                    // Insert order
                    $order $this->placeOrder($insert);
                    
                    // If the order submission is successful
                    if($order){
                        $this->session->set_userdata('success_msg''Order placed successfully.');
                        redirect($this->controller.'/orderSuccess/'.$order);
                    }else{
                        $data['error_msg'] = 'Order submission failed, please try again.';
                    }
                }else{
                    $data['error_msg'] = 'Some problems occured, please try again.';
                }
            }
        }
        
        // Customer data
        $data['custData'] = $custData;
        
        // Retrieve cart data from the session
        $data['cartItems'] = $this->cart->contents();
        
        // Pass products data to the view
        $this->load->view($this->controller.'/index'$data);
    }
    
    function placeOrder($custID){
        // Insert order data
        $ordData = array(
            'customer_id' => $custID,
            'grand_total' => $this->cart->total()
        );
        $insertOrder $this->product->insertOrder($ordData);
        
        if($insertOrder){
            // Retrieve cart data from the session
            $cartItems $this->cart->contents();
            
            // Cart items
            $ordItemData = array();
            $i=0;
            foreach($cartItems as $item){
                $ordItemData[$i]['order_id']     = $insertOrder;
                $ordItemData[$i]['product_id']     = $item['id'];
                $ordItemData[$i]['quantity']     = $item['qty'];
                $ordItemData[$i]['sub_total']     = $item["subtotal"];
                $i++;
            }
            
            if(!empty($ordItemData)){
                // Insert order items
                $insertOrderItems $this->product->insertOrderItems($ordItemData);
                
                if($insertOrderItems){
                    // Remove items from the cart
                    $this->cart->destroy();
                    
                    // Return order ID
                    return $insertOrder;
                }
            }
        }
        return false;
    }
    
    function orderSuccess($ordID){
        // Fetch order data from the database
        $data['order'] = $this->product->getOrder($ordID);
        
        // Load order details view
        $this->load->view($this->controller.'/order-success'$data);
    }
    
}

Model (Product.php)

The Product model is in charge of database operations (Fetch and Insert).

  - __construct() – Enter the database table name here.
  - getRows() – Get the product information from the database. If an ID is given, a single record is returned; otherwise, all records are returned.
  - getOrder() – Using the ID, retrieve the order details from the orders table.
  - insertCustomer() – Fill in the blanks in the customers table with customer information.
  - insertOrder() – In the orders table, enter the order details.
  - insertOrderItems() – Data for order items should be entered into the order items table.

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Product extends CI_Model{
    
    function __construct() {
        $this->proTable 'products';
        $this->custTable 'customers';
        $this->ordTable 'orders';
        $this->ordItemsTable 'order_items';
    }
    
    /*
     * Fetch products data from the database
     * @param id returns a single record if specified, otherwise all records
     */
    public function getRows($id ''){
        $this->db->select('*');
        $this->db->from($this->proTable);
        $this->db->where('status''1');
        if($id){
            $this->db->where('id'$id);
            $query $this->db->get();
            $result $query->row_array();
        }else{
            $this->db->order_by('name''asc');
            $query $this->db->get();
            $result $query->result_array();
        }
        
        // Return fetched data
        return !empty($result)?$result:false;
    }
    
    /*
     * Fetch order data from the database
     * @param id returns a single record of the specified ID
     */
    public function getOrder($id){
        $this->db->select('o.*, c.name, c.email, c.phone, c.address');
        $this->db->from($this->ordTable.' as o');
        $this->db->join($this->custTable.' as c''c.id = o.customer_id''left');
        $this->db->where('o.id'$id);
        $query $this->db->get();
        $result $query->row_array();
        
        // Get order items
        $this->db->select('i.*, p.image, p.name, p.price');
        $this->db->from($this->ordItemsTable.' as i');
        $this->db->join($this->proTable.' as p''p.id = i.product_id''left');
        $this->db->where('i.order_id'$id);
        $query2 $this->db->get();
        $result['items'] = ($query2->num_rows() > 0)?$query2->result_array():array();
        
        // Return fetched data
        return !empty($result)?$result:false;
    }
    
    /*
     * Insert customer data in the database
     * @param data array
     */
    public function insertCustomer($data){
        // Add created and modified date if not included
        if(!array_key_exists("created"$data)){
            $data['created'] = date("Y-m-d H:i:s");
        }
        if(!array_key_exists("modified"$data)){
            $data['modified'] = date("Y-m-d H:i:s");
        }
        
        // Insert customer data
        $insert $this->db->insert($this->custTable$data);

        // Return the status
        return $insert?$this->db->insert_id():false;
    }
    
    /*
     * Insert order data in the database
     * @param data array
     */
    public function insertOrder($data){
        // Add created and modified date if not included
        if(!array_key_exists("created"$data)){
            $data['created'] = date("Y-m-d H:i:s");
        }
        if(!array_key_exists("modified"$data)){
            $data['modified'] = date("Y-m-d H:i:s");
        }
        
        // Insert order data
        $insert $this->db->insert($this->ordTable$data);

        // Return the status
        return $insert?$this->db->insert_id():false;
    }
    
    /*
     * Insert order items data in the database
     * @param data array
     */
    public function insertOrderItems($data = array()) {
        
        // Insert order items
        $insert $this->db->insert_batch($this->ordItemsTable$data);

        // Return the status
        return $insert?true:false;
    }
    
}

Views

1. products/index.php:

The items are listed with an Add to Cart button. The total number of things in the cart is also displayed using the Cart library's total items() function.

<h2>PRODUCTS</h2>
	
<!-- Cart basket -->
<div class="cart-view">
    <a href="<?php echo base_url('cart'); ?>" title="View Cart"><i class="icart"></i> (<?php echo ($this->cart->total_items() > 0)?$this->cart->total_items().' Items':'Empty'?>)</a>
</div>

<!-- List all products -->
<div class="row col-lg-12">
    <?php if(!empty($products)){ foreach($products as $row){ ?>
        <div class="card col-lg-3">
            <img class="card-img-top" src="<?php echo base_url('uploads/product_images/'.$row['image']); ?>" alt="">
            <div class="card-body">
                <h5 class="card-title"><?php echo $row["name"]; ?></h5>
                <h6 class="card-subtitle mb-2 text-muted">Price: <?php echo '$'.$row["price"].' USD'?></h6>
                <p class="card-text"><?php echo $row["description"]; ?></p>
                <a href="<?php echo base_url('products/addToCart/'.$row['id']); ?>" class="btn btn-primary">Add to Cart</a>
            </div>
        </div>
    <?php } }else{ ?>
        <p>Product(s) not found...</p>
    <?php ?>
</div>

2. cart/index.php:

This view shows the shopping cart, complete with product and pricing information.

 - Cart items are presented with product information (picture, name, price, and so on), quantity, subtotal, and grand total.
 - There are two buttons available:
      - Continue Shopping — Allows you to add more items to your shopping basket.
      - Checkout - Allows you to checkout from your cart and preview your order.
 - The user can change the amount and remove an item from the cart.
 - The updateCartItem() method uses jQuery to initiate an Ajax request to update the amount of the item. The rowid and quantity are given over Ajax to the Cart controller's updateItemQty() function.

<!-- Include jQuery library -->
<script src="<?php echo base_url('assets/js/jquery.min.js'); ?>"></script>

<script>
// Update item quantity
function updateCartItem(obj, rowid){
    $.get("<?php echo base_url('cart/updateItemQty/'); ?>", {rowid:rowid, qty:obj.value}, function(resp){
        if(resp == 'ok'){
            location.reload();
        }else{
            alert('Cart update failed, please try again.');
        }
    });
}
</script>

<h1>SHOPPING CART</h1>
<table class="table table-striped">
<thead>
    <tr>
        <th width="10%"></th>
        <th width="30%">Product</th>
        <th width="15%">Price</th>
        <th width="13%">Quantity</th>
        <th width="20%" class="text-right">Subtotal</th>
        <th width="12%"></th>
    </tr>
</thead>
<tbody>
    <?php if($this->cart->total_items() > 0){ foreach($cartItems as $item){    ?>
    <tr>
        <td>
            <?php $imageURL = !empty($item["image"])?base_url('uploads/product_images/'.$item["image"]):base_url('assets/images/pro-demo-img.jpeg'); ?>
            <img src="<?php echo $imageURL?>" width="50"/>
        </td>
        <td><?php echo $item["name"]; ?></td>
        <td><?php echo '$'.$item["price"].' USD'?></td>
        <td><input type="number" class="form-control text-center" value="<?php echo $item["qty"]; ?>" onchange="updateCartItem(this, '<?php echo $item["rowid"]; ?>')"></td>
        <td class="text-right"><?php echo '$'.$item["subtotal"].' USD'?></td>
        <td class="text-right"><button class="btn btn-sm btn-danger" onclick="return confirm('Are you sure to delete item?')?window.location.href='<?php echo base_url('cart/removeItem/'.$item["rowid"]); ?>':false;"><i class="itrash"></i> </button> </td>
    </tr>
    <?php } }else{ ?>
    <tr><td colspan="6"><p>Your cart is empty.....</p></td>
    <?php ?>
    <?php if($this->cart->total_items() > 0){ ?>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td><strong>Cart Total</strong></td>
        <td class="text-right"><strong><?php echo '$'.$this->cart->total().' USD'?></strong></td>
        <td></td>
    </tr>
    <?php ?>
</tbody>
</table>

3. checkout/:
3.1. index.php

This view shows a snapshot of the transaction before it is submitted.

 - The preview is provided before place the order.
 - Under the order preview, an HTML form with certain input fields is provided to provide shipping details (name, email, phone, and address).
 - The form now has validation and pre-filled data render capabilities.
 - The Place Order button allows you to submit your order.

<h1>CHECKOUT</h1>
<div class="checkout">
    <div class="row">
        <?php if(!empty($error_msg)){ ?>
        <div class="col-md-12">
            <div class="alert alert-danger"><?php echo $error_msg?></div>
        </div>
        <?php ?>
		
        <div class="col-md-4 order-md-2 mb-4">
            <h4 class="d-flex justify-content-between align-items-center mb-3">
                <span class="text-muted">Your Cart</span>
                <span class="badge badge-secondary badge-pill"><?php echo $this->cart->total_items(); ?></span>
            </h4>
            <ul class="list-group mb-3">
                <?php if($this->cart->total_items() > 0){ foreach($cartItems as $item){ ?>
                <li class="list-group-item d-flex justify-content-between lh-condensed">
                    <div>
                        <?php $imageURL = !empty($item["image"])?base_url('uploads/product_images/'.$item["image"]):base_url('assets/images/pro-demo-img.jpeg'); ?>
                        <img src="<?php echo $imageURL?>" width="75"/>
                        <h6 class="my-0"><?php echo $item["name"]; ?></h6>
                        <small class="text-muted"><?php echo '$'.$item["price"]; ?>(<?php echo $item["qty"]; ?>)</small>
                    </div>
                    <span class="text-muted"><?php echo '$'.$item["subtotal"]; ?></span>
                </li>
				            <?php } }else{ ?>
                <li class="list-group-item d-flex justify-content-between lh-condensed">
                    <p>No items in your cart...</p>
                </li>
                <?php ?>
                <li class="list-group-item d-flex justify-content-between">
                    <span>Total (USD)</span>
                    <strong><?php echo '$'.$this->cart->total(); ?></strong>
                </li>
            </ul>
            <a href="<?php echo base_url('products/'); ?>" class="btn btn-block btn-info">Add Items</a>
        </div>
        <div class="col-md-8 order-md-1">
            <h4 class="mb-3">Contact Details</h4>
            <form method="post">
                <div class="mb-3">
                    <label for="name">Name</label>
                    <input type="text" class="form-control" name="name" value="<?php echo !empty($custData['name'])?$custData['name']:''?>" placeholder="Enter name" required>
                    <?php echo form_error('name','<p class="help-block error">','</p>'); ?>
                </div>
                <div class="mb-3">
                    <label for="email">Email</label>
                    <input type="email" class="form-control" name="email" value="<?php echo !empty($custData['email'])?$custData['email']:''?>" placeholder="Enter email" required>
                    <?php echo form_error('email','<p class="help-block error">','</p>'); ?>
                </div>
                <div class="mb-3">
                    <label for="phone">Phone</label>
                    <input type="text" class="form-control" name="phone" value="<?php echo !empty($custData['phone'])?$custData['phone']:''?>" placeholder="Enter contact no" required>
                    <?php echo form_error('phone','<p class="help-block error">','</p>'); ?>
                </div>
                <div class="mb-3">
                    <label for="address">Address</label>
                    <input type="text" class="form-control" name="address" value="<?php echo !empty($custData['address'])?$custData['address']:''?>" placeholder="Enter address" required>
                    <?php echo form_error('address','<p class="help-block error">','</p>'); ?>
                </div>
                <input class="btn btn-success btn-lg btn-block" type="submit" name="placeOrder" value="Place Order">
            </form>
        </div>
    </div>
</div>

3.2. order-success.php
If the order is successfully submitted, the status is displayed along with the order data.

<h1>ORDER STATUS</h1>
<?php if(!empty($order)){ ?>
    <div class="col-md-12">
        <div class="alert alert-success">Your order has been placed successfully.</div>
    </div>
	
    <!-- Order status & shipping info -->
    <div class="row col-lg-12 ord-addr-info">
        <div class="hdr">Order Info</div>
        <p><b>Reference ID:</b> #<?php echo $order['id']; ?></p>
        <p><b>Total:</b> <?php echo '$'.$order['grand_total'].' USD'?></p>
        <p><b>Placed On:</b> <?php echo $order['created']; ?></p>
        <p><b>Buyer Name:</b> <?php echo $order['name']; ?></p>
        <p><b>Email:</b> <?php echo $order['email']; ?></p>
        <p><b>Phone:</b> <?php echo $order['phone']; ?></p>
    </div>
	
    <!-- Order items -->
    <div class="row col-lg-12">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th></th>
                    <th>Product</th>
                    <th>Price</th>
                    <th>QTY</th>
                    <th>Sub Total</th>
                </tr>
            </thead>
            <tbody>
                <?php 
                if(!empty($order['items'])){  
                    foreach($order['items'] as $item){ 
                ?>
                <tr>
                    <td>
                        <?php $imageURL = !empty($item["image"])?base_url('uploads/product_images/'.$item["image"]):base_url('assets/images/pro-demo-img.jpeg'); ?>
                        <img src="<?php echo $imageURL?>" width="75"/>
                    </td>
                    <td><?php echo $item["name"]; ?></td>
                    <td><?php echo '$'.$item["price"].' USD'?></td>
                    <td><?php echo $item["quantity"]; ?></td>
                    <td><?php echo '$'.$item["sub_total"].' USD'?></td>
                </tr>
                <?php } 
                } ?>
            </tbody>
        </table>
    </div>
<?php } }else{ ?>
<div class="col-md-12">
    <div class="alert alert-danger">Your order submission failed.</div>
</div>
<?php ?>

Conclusion

We attempted to cover the complete process of integrating shopping cart functionality into the CodeIgniter application. You may simply improve this script and incorporate extra features based on your requirements. Our sample code allows you to add shopping cart immediately in CodeIgniter framework. The Bootstrap library is used in this example to style the product list, shopping cart, checkout, and order views.

LICENSE OF USE

You can use it for personal or commercial projects. You can't resell it partially or in this form.

PRODUCT INFO

Create Date : Feb 16, 2022

Updated Date : Feb 16, 2022

Ratings

Comments : 0

Downloads : 0