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


PHP Cart::add_item方法代码示例

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


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

示例1: add_items_to_cart

function add_items_to_cart($id, $count)
{
    if (empty($_SESSION['simple_cart']) || !isset($_SESSION['simple_cart'])) {
        $c = new Cart();
        $c->add_item($id, $count);
        $_SESSION['simple_cart'] = $c;
    } else {
        $_SESSION['simple_cart']->add_item($id, $count);
    }
}
开发者ID:nitzanb,项目名称:Simple-Cart,代码行数:10,代码来源:simple_cart.php

示例2: create_from_signup

 public static function create_from_signup($signup, $note = "")
 {
     $hash = self::hash_items($signup);
     $cart = Cart::find("carts.hash = '{$hash}' AND carts.hash IS NOT NULL");
     if ($cart) {
         return $cart;
     }
     $cart = new Cart();
     $cart->user_id = $signup->user->id;
     $cart->note = $note;
     $cart->hash = $hash;
     if ($cart->save()) {
         // Add Signup
         $added = false;
         if (!$signup->paid) {
             $cart->add_item($signup);
             $added = true;
         }
         foreach ($signup->event_services() as $service) {
             if (!$service->paid) {
                 $cart->add_item($service);
                 $added = true;
             }
         }
         $cart = Cart::find_by_id($cart->id);
         if ($added) {
             return $cart;
         } else {
             $cart->destroy();
             return false;
         }
     }
     return false;
 }
开发者ID:ItsHaden,项目名称:epicLanBootstrap,代码行数:34,代码来源:cart.model.php

示例3: Cart

    function remove_item($artnr, $num)
    {
        if ($this->items[$artnr] > $num) {
            $this->items[$artnr] -= $num;
            return true;
        } else {
            return false;
        }
    }
}
?>

<?php 
error_reporting(E_ALL & ~E_NOTICE);
$cart = new Cart();
$cart->add_item("10", 1);
$another_cart = new Cart();
$another_cart->add_item("0815", 3);
?>

<?php 
// correct, single $
$cart->items = array("10" => 2);
var_dump($cart->items);
// invalid, because $cart->$items becomes $cart->""
//$cart->$items = array("10" => 1);
// correct, but may or may not be what was intended:
// $cart->$myvar becomes $cart->items
$myvar = 'items';
$cart->{$myvar} = array("10" => 1);
var_dump($cart->items);
开发者ID:dw4dev,项目名称:Phalanger,代码行数:31,代码来源:test124.php

示例4: offset

[expect] Undefined offset (1)
[expect] 1

[file]
<?php 
class Cart
{
    var $items;
    // Items in our shopping cart
    // Add $num articles of $artnr to the cart
    function add_item($artnr, $num)
    {
        $this->items[$artnr] += $num;
    }
    // Take $num articles of $artnr out of the cart
    function remove_item($artnr, $num)
    {
        if ($this->items[$artnr] > $num) {
            $this->items[$artnr] -= $num;
            return true;
        } else {
            return false;
        }
    }
}
$c = new Cart();
$c->add_item(1, 5);
$b = $c->remove_item(1, 6);
echo $b;
$b = $c->remove_item(1, 4);
echo $b;
开发者ID:dw4dev,项目名称:Phalanger,代码行数:31,代码来源:test122.php

示例5: user_index

 public function user_index()
 {
     $user_id = mysql_real_escape_string(Site::CurrentUser()->id);
     // Code from Cart->create()			// First check CRSF
     if ($this->post) {
         // From the post data, build the cart items
         $raw_items = array();
         if (isset($_POST['items']['signups'])) {
             foreach ($_POST['items']['signups'] as $id => $value) {
                 $id = mysql_real_escape_string($id);
                 $signup = EventSignup::find("event_signups.user_id = '{$user_id}' AND event_signups.id = '{$id}'");
                 if ($signup && !$signup->paid && !$signup->is_soldout()) {
                     $raw_items[$signup->id]['signup'] = $signup;
                 }
             }
         }
         if (isset($_POST['items']['services'])) {
             $service_count = array();
             foreach ($_POST['items']['services'] as $id => $value) {
                 $id = mysql_real_escape_string($id);
                 $service = EventService::find("event_signups.user_id = '{$user_id}' AND event_services.id = '{$id}'");
                 if ($service && !$service->paid && $service->service->available()) {
                     if (isset($service_count[$service->service->id])) {
                         $service_count[$service->service->id]++;
                     } else {
                         $service_count[$service->service->id] = 1;
                     }
                     if ($service->service->available() == -1 || $service_count[$service->service->id] <= $service->service->available()) {
                         if ($service->event_signup->paid || isset($raw_items[$service->event_signup->id]['signup'])) {
                             $raw_items[$service->event_signup->id]['services'][] = $service;
                         }
                     }
                 }
             }
         }
         // Sort properly
         $items = array();
         foreach ($raw_items as $id => $parts) {
             if (isset($parts['signup'])) {
                 $items[] = $parts['signup'];
             }
             if (isset($parts['services'])) {
                 $items = array_merge($items, $parts['services']);
             }
         }
         if (count($items) == 0) {
             Site::Flash("error", "None of the items you selected could be paid for.");
             Redirect("bookings");
         }
         $hash = Cart::hash_items($items);
         $cart = Cart::find("carts.hash = '{$hash}' AND carts.hash IS NOT NULL");
         if (!$cart) {
             $cart = new Cart();
             $cart->user_id = $user_id;
             $cart->hash = $hash;
             if ($cart->save()) {
                 foreach ($items as $item) {
                     $cart->add_item($item);
                 }
             } else {
                 Site::Flash("error", "Unable to create cart.");
                 Redirect("bookings");
             }
         }
         Redirect("bookings/pay/{$cart->id}");
     } elseif ($this->post) {
         global $site;
         $site['flash']['error'] = "Invalid form submission";
     }
     // Fetch all signups in event order and iterate through them
     $items = array();
     $signups = EventSignup::find_all("event_signups.user_id = '{$user_id}' AND events.enddate >= NOW()", "events.startdate DESC");
     foreach ($signups as $signup) {
         if (!$signup->paid) {
             $items[] = $signup;
         } else {
             foreach ($signup->event_services() as $service) {
                 if (!$service->paid) {
                     $items[] = $signup;
                     break;
                 }
             }
         }
     }
     $this->assign("items", $items);
     // Traditional My Bookings Page
     $unpaid = EventSignup::find_all("event_signups.user_id = '{$user_id}' AND event_signups.paid = false", "events.startdate DESC");
     $paid = EventSignup::find_all("event_signups.user_id = '{$user_id}' AND event_signups.paid = true AND voucher = false", "events.startdate DESC");
     $vouchers = EventSignup::find_all("event_signups.user_id = '{$user_id}' AND event_signups.paid = true AND voucher = true", "events.startdate DESC");
     $this->assign("unpaid", $unpaid);
     $this->assign("paid", $paid);
     $this->assign("vouchers", $vouchers);
     $this->title = "My Bookings";
     $this->render("event_signup/user_index.tpl");
 }
开发者ID:ItsHaden,项目名称:epicLanBootstrap,代码行数:95,代码来源:event_signup.controller.php

示例6: elseif

    var $items;
    var $name;
    function __construct($myName)
    {
        echo "{$myName} 's cart, charge process: <br>";
        $this->name = $myName;
    }
    function add_item($artnr, $num)
    {
        $this->items[$artnr] += $num;
        echo "<br>add {$num} {$artnr}, {$artnr} 's total num:" . $this->items[$artnr];
    }
    function remove_item($artnr, $num)
    {
        if ($this->items[$artnr] > $num) {
            $this->items[$artnr] -= $num;
            echo "<br>remove {$num} {$artnr}, {$artnr} 's total num: " . $this->items[$artnr];
            return true;
        } elseif ($this->items[$artnr] == $num) {
            unset($this->items[$artnr]);
            echo "<br>remove {$num} {$artnr}, {$artnr} 's total num is zero";
        } else {
            return false;
        }
    }
}
$myCart = new Cart("zhang san");
$myCart->add_item("apple", 9);
$myCart->add_item("banana", 8);
$myCart->remove_item("apple", 2);
$myCart->remove_item("banana", 3);
开发者ID:netinvman,项目名称:learnphp,代码行数:31,代码来源:completeclass.php


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