include 'terminal.php'; include 'inventory.php'; // Initialize inventory, listings, and terminal objects. $product_inventory = new Inventory(); // add products and prices here. $product_inventory->add("A", 2.0, [4 => '7.00']); $product_inventory->add("B", 12.0); $product_inventory->add("C", 1.25, [6 => 6.0]); $product_inventory->add("D", 0.15); $product_listing = new Listing($product_inventory); $terminal = new Terminal($product_listing); //$terminal->setUnitPricing("A", 3.50); //$terminal->setVolumePricing("A", [2=>2.40, 7=>10.00]); // process form data if (isset($_POST["submit"])) { $products = $_POST["product_txt"]; for ($i = 0; $i < strlen($products); $i++) { if ($products[$i] != " ") { $scannable = $terminal->scan($products[$i]); } // did the product go into the system? if (!$scannable) { echo "Unable to get price for: " . $products[$i] . "<br>"; } } echo "<b>The total cost of: " . $products . " is: \$" . number_format($terminal->getTotalCost(), 2, '.', ',') . "</b>"; } ?> </div> </body> </html>
<?php include 'terminal.php'; include 'inventory.php'; // Initialize inventory, listings, and terminal objects. $product_inventory = new Inventory(); // add products and prices here. $product_inventory->add("A", 2.0, [4 => 7.0]); $product_inventory->add("B", 12.0); $product_inventory->add("C", 1.25, [6 => 6.0]); $product_inventory->add("D", 0.15); $product_listing = new Listing($product_inventory); $terminal = new Terminal($product_listing); // scan products if (isset($_POST["data"])) { $result = $terminal->scan($_POST["data"]); if ($result) { echo "Product " . $_POST["data"] . " is scanned"; } else { echo "Product " . $_POST["data"] . " cannot be scanned"; } } if (isset($_GET["type"])) { if ($_GET["type"] == "totalprice") { echo $terminal->getTotalPrice(); } }