Esempio n. 1
0
    }
    public function getAllProducts()
    {
        return $this->products;
    }
    public function findProductByName($name)
    {
        $productKey = null;
        foreach ($this->products as $key => $product) {
            if ($product->name == $name) {
                $productKey = $key + 1;
                return $product . ' is number ' . $productKey . ' in the Wish List. <br />';
            } else {
                throw new Exception("No product with given name found in Wish List");
            }
        }
    }
}
$itemDescriber = new ItemDescriber();
$hoodie = new Clothing("Hoodie", "Nike", 19.99, "large", "red", "shirt", "male");
$plasma = new Television("Plasma", "Sony", 1000.0, plasma, "50in");
$wishList = new WishList();
$wishList->addProduct($hoodie);
$wishList->addProduct($plasma);
$shoppingCart = $wishList->createCartFromContainer($wishList);
$wishList->provideDescription();
$shoppingCart->provideDescription();
?>
    </p>
  </body>
</html>
Esempio n. 2
-10
    {
        return $this->items;
    }
    public function findProductByName($name)
    {
        $itemKey = null;
        foreach ($this->items as $key => $item) {
            if ($name == $item->getName()) {
                $itemKey = $key + 1;
                echo "{$name} is number {$itemKey} in the array";
                break;
            }
        }
        if ($itemKey == null) {
            throw new Exception("Item was not found in cart");
        }
    }
}
$describer = new ItemDescriber();
$kramericaTV = new Television("Giant TV", "Kramerica", 3900.9, "LED", "100in");
$shirt = new Clothing("Button Down Shirt", "J Peterman", '29.88', "shirt", "medium", "red", "male");
$Wishlist = new WishList();
$Wishlist->addProduct($kramericaTV);
$Wishlist->addProduct($shirt);
$ShoppingCart = $Wishlist->createCartFromContainer($Wishlist);
$Wishlist->provideDescription();
$ShoppingCart->provideDescription();
?>
    </p>
  </body>
</html>