Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WEB SCRIPTING (PHP) Customize the shopping cart program to add at least fifteen different products (think about any real life application shopping cart electronics items,

WEB SCRIPTING (PHP)

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.

image text in transcribed

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"]

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"]

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

Your shopping cart Caut Total: 50.00 Product list SuperWdg MegaWidger Wonderidger $19.99Add Iten 529 99Add Trem 539 99Ad em PHF PHF PHF PHF Your shopping cart Caut Total: 50.00 Product list SuperWdg MegaWidger Wonderidger $19.99Add Iten 529 99Add Trem 539 99Ad em PHF PHF PHF PHF

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

ISBN: 3319712721, 978-3319712727

More Books

Students also viewed these Databases questions

Question

Increasing investment time and money in employee training.

Answered: 1 week ago

Question

Question Can employees make contributions to a profit sharing plan?

Answered: 1 week ago