public function update(Cart $cart) { if ($cart->hasItem(self::PRESENT_TARGET_ITEM) && !$cart->hasItem(self::PRESENT_ITEM)) { $cart->addItem(self::PRESENT_ITEM); } if (!$cart->hasItem(self::PRESENT_TARGET_ITEM) && $cart->hasItem(self::PRESENT_ITEM)) { $cart->removeItem(self::PRESENT_ITEM); } }
public function removeItem() { if (Sessions_helper::logged_in()) { require_once '../app/models/Cart.php'; $cart = new Cart(); $cart->removeItem($_POST['productVersionId']); } else { if (array_key_exists($_POST['productVersionId'], $_SESSION['cart'])) { unset($_SESSION['cart'][$_POST['productVersionId']]); if (count($_SESSION['cart']) == 0) { unset($_SESSION['cart']); } } } $this->redirect_to('carts'); }
$page = new Page(); $page->addCSS('assets/css/shoppingCart.css'); $page->addCSS('assets/js/bootstrap-touchspin/jquery.bootstrap-touchspin.min.css'); $page->addCSS("assets/js/sweetalert/sweetalert.css"); $page->addJavascript("assets/js/sweetalert/sweetalert.min.js"); $page->addJavascript('assets/js/bootstrap-touchspin/jquery.bootstrap-touchspin.min.js'); $page->setTitle('Danh Sách Sản Phẩm'); $page->startBody(); require_once './entities/Order.php'; require_once './entities/OrderDetail.php'; date_default_timezone_set('Asia/Bangkok'); $insert = null; if (isset($_POST["txtDelProId"])) { $updProId = explode(',', $_POST["txtDelProId"]); for ($i = 0; $i < count($updProId); $i++) { Cart::removeItem($updProId[$i]); } } if (isset($_POST["txtUpdProId"])) { $updProId = explode(',', $_POST["txtUpdProId"]); $q = explode(',', $_POST["txtUpdQ"]); for ($i = 0; $i < count($updProId); $i++) { Cart::updateItem($updProId[$i], $q[$i]); } } if (isset($_POST["btnCheckout"])) { require_once 'helper/Context.php'; $total = $_POST["txtTotal"]; $ord = new Order(); $ord->setOrderDate(new DateTime()); $ord->setTotal($total);
<?php namespace DoYouPhp\PhpDesignPattern\Observer; require dirname(__DIR__) . '/vendor/autoload.php'; /** * カートの作成 */ $cart = new Cart(); /** * リスナーの登録 */ $cart->addListener(new PresentListener()); $cart->addListener(new LoggingListener()); /** * 商品を追加してみる */ $cart->addItem("Tシャツ"); $cart->addItem("ぬいぐるみ"); $cart->addItem("ぬいぐるみ"); $cart->show(); /** * プレゼント対象の商品を追加してみる */ $cart->addItem("クッキーセット"); $cart->show(); /** * プレゼント対象の商品を削除してみる */ $cart->removeItem("クッキーセット"); $cart->show();