Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Customize the shopping cart program to add at least fifteen different products (think about any real life application shopping cart electronics items, books, consumables etc..).

Customize the shopping cart program to add at least fifteen different products (think about any real life application shopping cart electronics items, books, consumables etc..). Make sure you apply taxes to your items. You could also try to add a column of quantity next to the item. Write the changes that you have made under your program purpose.

class Product { private $productId; private $productName; private $price;

public function __construct( $productId, $productName, $price ) { $this->productId = $productId; $this->productName = $productName; $this->price = $price; }

public function getId() { return $this->productId; }

public function getName() { return $this->productName; }

public function getPrice() { return $this->price; }

}

$products = array( 1 => new Product( 1, "SuperWidget", 19.99 ), 2 => new Product( 2, "MegaWidget", 29.99 ), 3 => new Product( 3, "WonderWidget", 39.99 ) );

if ( !isset( $_SESSION["cart"] ) ) $_SESSION["cart"] = array();

if ( isset( $_GET["action"] ) and $_GET["action"] == "addItem" ) { addItem(); } elseif ( isset( $_GET["action"] ) and $_GET["action"] == "removeItem" ) { removeItem(); } else { displayCart(); }

function addItem() { global $products; if ( isset( $_GET["productId"] ) and $_GET["productId"] >= 1 and $_GET["productId"] <= 3 ) { $productId = (int) $_GET["productId"];

if ( !isset( $_SESSION["cart"][$productId] ) ) { $_SESSION["cart"][$productId] = $products[$productId]; } }

session_write_close(); header( "Location: shopping_cart.php" ); }

function removeItem() { global $products; if ( isset( $_GET["productId"] ) and $_GET["productId"] >= 1 and $_GET["productId"] <= 3 ) { $productId = (int) $_GET["productId"];

if ( isset( $_SESSION["cart"][$productId] ) ) { unset( $_SESSION["cart"][$productId] ); } }

session_write_close(); header( "Location: shopping_cart.php" ); }

function displayCart() { global $products; ?> A shopping cart using sessions

Your shopping cart

getPrice(); ?>

getName() ?>
$getPrice(), 2 ) ?> getId() ?>">Remove
Cart Total:
$

Product list

getName() ?>
$getPrice(), 2 ) ?> getId() ?>">Add Item

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions