当前位置: 首页>>代码示例>>PHP>>正文


PHP ShoppingCart::removeProduct方法代码示例

本文整理汇总了PHP中ShoppingCart::removeProduct方法的典型用法代码示例。如果您正苦于以下问题:PHP ShoppingCart::removeProduct方法的具体用法?PHP ShoppingCart::removeProduct怎么用?PHP ShoppingCart::removeProduct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ShoppingCart的用法示例。


在下文中一共展示了ShoppingCart::removeProduct方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ShoppingCart

 } else {
     $shopping_cart = new ShoppingCart($_SESSION["username"]);
 }
 /* if there are any shopping_cart actions, do it now */
 $form_action = var_get_post("action", "");
 if ($form_action == "add_product_to_cart") {
     $form_product_id = var_get_post("product_id", "");
     $form_product_amount = var_get_post("amount", "");
     $form_product_amount = str_replace(',', '.', $form_product_amount);
     if ($form_product_id != "" && $form_product_amount != "") {
         $shopping_cart->addProduct($form_product_id, $form_product_amount, "");
     }
 } elseif ($form_action == "remove_product_from_cart") {
     $form_product_id = var_get_post("product_id", "");
     if ($form_product_id != "") {
         $shopping_cart->removeProduct($form_product_id);
     }
 } elseif ($form_action == "edit_product_amount") {
     $form_product_id = var_get_post("product_id", "");
     $form_product_amount = var_get_post("product_amount", "");
     $form_product_amount = str_replace(',', '.', $form_product_amount);
     $form_product_hint = var_get_post("product_hint", "");
     if ($form_product_id != "" && $form_product_amount != "") {
         $shopping_cart->editProduct($form_product_id, $form_product_amount, $form_product_hint);
     }
 } elseif ($form_action == "create_bill") {
     if ($shopping_cart->createBill() == 0) {
         $shopping_cart->clearShoppingCart();
     }
 } elseif ($form_action == "set_template") {
     $shopping_cart->saveTemplate();
开发者ID:nebulade,项目名称:faursprung_website,代码行数:31,代码来源:shoppingcart_action.php

示例2: removeProduct

        echo "Adding " . $product_id . " x " . $qt . "<br>";
        $old_qt = 0;
        if (array_key_exists($product_id, $_SESSION['products'])) {
            $old_qt = $_SESSION['products'][$product_id];
        }
        $_SESSION['products'][$product_id] = $old_qt + $qt;
    }
    function removeProduct($product_id)
    {
        echo "Removing " . $product_id . "<br>";
        if (array_key_exists($product_id, $_SESSION['products'])) {
            unset($_SESSION['products'][$product_id]);
        }
    }
    function listProducts()
    {
        echo "Listing products" . "<br>";
        foreach ($_SESSION['products'] as $product_id => $qt) {
            echo $product_id . " x " . $qt . "<br>";
        }
    }
}
// init session
session_start();
// Testing
$sh = new ShoppingCart();
$sh->addProduct("123", 2);
$sh->addProduct("345", 1);
$sh->addProduct("678", 1);
$sh->removeProduct("345");
$sh->listProducts();
开发者ID:kbalog,项目名称:web-programming,代码行数:31,代码来源:exercise8.php

示例3: provideDescriptionForProductType

            throw new Exception("No size entered");
        } else {
            return $this->size;
        }
    }
    public function provideDescriptionForProductType()
    {
        return 'This is a ' . $this->getSize() . ' ' . $this->getBrand() . ' ' . $this->getname() . ' ' . $this->getDisplayType() . ' Television <br />';
    }
}
$itemDescriber = new ItemDescriber();
$cart = new ShoppingCart();
$hoodie = new Clothing("Hoodie", "Nike", 19.99, "large", "red", "shirt", "male");
$plasma = new Television("Plasma", "Sony", 1000.0, plasma, "50in");
$cart->addProduct($hoodie);
$cart->addProduct($plasma);
echo implode('<br />', $cart->provideDescription());
echo "<br />";
echo $cart->getTotalPrice();
echo "<br />";
$cart->removeProduct($hoodie);
foreach ($cart->provideDescription() as $productDescription) {
    echo $productDescription;
    echo '<br />';
}
var_dump($cart->findProductByName("Plasma"));
var_dump($itemDescriber->outputDescription($cart));
?>
    </p>
  </body>
</html>
开发者ID:ChuckPavlick,项目名称:challenges,代码行数:31,代码来源:01_medium.php


注:本文中的ShoppingCart::removeProduct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。