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


PHP Basket::clear方法代码示例

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


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

示例1: actionOrder

 public function actionOrder()
 {
     $platform = array();
     $errors = array();
     $userName = '';
     $userEmail = '';
     $userPhone = '';
     $userComment = '';
     $platform = Platform::getPlatformList();
     $result = false;
     if (isset($_POST['submit'])) {
         $userName = $_POST['name'];
         $userEmail = $_POST['email'];
         $userPhone = $_POST['phone'];
         $userComment = $_POST['message'];
         $errors = false;
         if (!User::validateUsername($userName)) {
             $errors[] = "Неверное имя";
         }
         if (!User::validateEmail($userEmail)) {
             $errors[] = "Неверный Email";
         }
         if (!User::validatePhone($userPhone)) {
             $errors[] = "Неккоректный телефон";
         }
         if ($errors == false) {
             $productsBasket = Basket::getProducts();
             if (User::isGuest()) {
                 $userId = false;
             } else {
                 $userId = User::validateLogged();
             }
             $result = Order::save($userName, $userEmail, $userPhone, $userComment, $userId, $productsBasket);
             if ($result) {
                 $adminEmail = "alexey.vnu@gmail.com";
                 $subject = "Новый заказ";
                 mail($adminEmail, $subject, $userComment);
                 Basket::clear();
             }
         } else {
             $productsInBasket = Basket::getProducts();
             $productId = array_keys($productsInBasket);
             $products = Products::getProductsByIdInBasket($productId);
             $totalPrice = Basket::getTotalPrice($products);
             $total = array_sum($totalPrice);
             $totalQuantity = Basket::countItem();
         }
     } else {
         $productsInbasket = Basket::getProducts();
         if ($productsInbasket == false) {
             header("Loaction: /");
         } else {
             $productId = array_keys($productsInbasket);
             $products = Products::getProductsByIdInBasket($productId);
             $totalPrice = Basket::getTotalPrice($products);
             $totalQuantity = Basket::countItem();
             $userName = false;
             $userEmail = false;
             $userPhone = false;
             $userComment = false;
             if (User::isGuest()) {
             } else {
                 $userId = User::validateLogged();
                 $user = User::getUserById($userId);
                 $userName = $user['name'];
                 $userEmail = $user['email'];
             }
         }
     }
     require_once ROOT . "/views/basket/order.php";
     return true;
 }
开发者ID:Evkazolinium,项目名称:Eshop_for_example,代码行数:72,代码来源:BasketController.php

示例2: index

 function index()
 {
     echo 'example of the usage of the cart module <BR>';
     $cart = new Basket();
     $cart->clear();
     echo 'there are ' . $cart->size() . ' items in the cart<BR>';
     assert($cart->size() == 0);
     echo 'there are ' . $cart->qty() . ' qty items in the cart<BR><BR>';
     assert($cart->qty() == 0);
     $item = new Item();
     $item->id = 2;
     $cart->add($item);
     $item = new Item();
     $item->id = 4;
     $cart->add($item);
     //adds just one product (with id of 4)
     $item = new Item();
     $item->id = 4;
     $item->qty = 2;
     $item->options = array('color' => 'red');
     $cart->add($item);
     //add the 2 of the same product but with options
     echo 'there are ' . $cart->size() . ' items in the cart<BR>';
     assert($cart->size() == 3);
     echo 'there are ' . $cart->qty() . ' qty items in the cart<BR><BR>';
     assert($cart->qty() == 4);
     $item = new Item();
     $item->id = 4;
     $item->qty = 2;
     $cart->update($item);
     //add two of product with id 2
     echo 'there are ' . $cart->size() . ' items in the cart<BR>';
     assert($cart->size() == 3);
     echo 'there are ' . $cart->qty() . ' qty items in the cart<BR><BR>';
     assert($cart->qty() == 5);
     $item = new Item();
     $item->id = 4;
     $cart->remove($item);
     //remove product 4 (only the one without any options) from the cart (along with it 2 qty)
     echo 'there are ' . $cart->size() . ' items in the cart<BR>';
     assert($cart->size() == 2);
     echo 'there are ' . $cart->qty() . ' qty items in the cart<BR><BR>';
     assert($cart->qty() == 3);
     $item = new Item();
     $item->id = 3;
     $item->qty = 2;
     $item->options = array('cool' => 'yes');
     $cart->add($item);
     //adding a item through the array method
     $i = array('id' => 4, 'qty' => 5, 'options' => array('color' => 'red'));
     $item = new Item($i);
     $cart->update($item);
     //update qty of the item given information
     /*
     //you can also use strings for the id (just remeber to have a corresponding key in your database)
     $item = new Item(array(	'id' => 'test3', 'qty'=> 2));
     $cart->update($item); //update qty of the item given information 
     */
     echo 'there are ' . $cart->size() . ' items in the cart<BR>';
     assert($cart->size() == 3);
     echo 'there are ' . $cart->qty() . ' qty items in the cart<BR><BR>';
     assert($cart->qty() == 8);
     echo '<BR>';
     if (!$cart->isEmpty()) {
         foreach ($cart->products() as $item) {
             echo $item->name . " | " . $item->key . " | " . $item->qty . " | " . $item->price . " | " . $item->total . "<br/>";
         }
     } else {
         echo 'no products<BR>';
     }
     echo '<BR>';
     echo 'cart sub-total is ' . $cart->subtotal() . "<br/>";
     // There are two methods to get the order //
     // METHOD 1 (through the order class) //
     $form->shipping->first_name = 'Joe';
     $form->shipping->last_name = 'Smith';
     $form->shipping->address1 = '10 Elm st.';
     $form->shipping->city = 'Somerville';
     $form->shipping->state = 'NH';
     $form->shipping->zip = '02145';
     $form->shipping->country = 'US';
     $form->shipping->phone = '201020277 ';
     $form->shipping->email = 'test@test.com';
     $form->shipping->method = 'ups_03_ground';
     $form->payment->method = 'card';
     //or paypal
     $form->payment->card->name = 'Joe Smith';
     $form->payment->card->type = 'V';
     $form->payment->card->card_num = '1234567890123456';
     $form->payment->card->exp_date = '0510';
     $form->payment->card->cvv = '882';
     //$form->customer->id = $user->getUserID();
     //$form->customer->ip = $input->getIPAddress();
     $order = new Order();
     $order->cart = $cart;
     $order->shipping = $form->shipping;
     //$order->billing = $form->billing;
     //$order->payment = array();
     //$order->customer = array();
     echo '<BR>Grand total is $' . $order->total() . '<BR>';
//.........这里部分代码省略.........
开发者ID:VinceOmega,项目名称:mcb-nov-build,代码行数:101,代码来源:cart.php

示例3: redirect

         Events::setSignupStatus(Session::getUser()->getId(), $ticket['eventId'], 'BACS_WAITING');
     }
     Basket::clear();
     redirect('account.php', 'Thanks, you will be marked as PAID by an admin when they receive the transfer.');
     break;
 case 'paypalFail':
     logAndRedirect('account.php', 'Paypal transaction failed.');
     break;
 case 'paypalComplete':
     logActivity('Started processing PayPal payment notification');
     foreach (Basket::getContents() as $ticket) {
         logActivity('PayPal transaction processing - setting status to PAID for event. Ticket owner _u_, event _e_', $ticket['userId'], array('event' => $ticket['eventId'], 'user' => Session::getUser()->getId()));
         Events::setSignupStatus($ticket['userId'], $ticket['eventId'], 'PAID');
     }
     logActivity('Finished processing PayPal payment notification.');
     Basket::clear();
     redirect('account.php', 'Thanks, payment complete!');
     break;
 default:
     require_once 'includes/widgets/header.php';
     require_once 'includes/widgets/sidebar.php';
     startBox();
     echo str_replace('%BASKETTOTAL%', doubleToGbp($cost), getContent('selectPaymentMethod'));
     $tpl->assign('cost', $cost);
     $tpl->assign('costPaypal', getPaypalCommission($cost));
     $tpl->assign('paypalEmail', getSiteSetting('paypalEmail'));
     $tpl->assign('listBasketContents', Basket::getContents());
     $tpl->assign('baseUrl', getSiteSetting('baseUrl'));
     $tpl->assign('currency', getSiteSetting('currency'));
     $tpl->display('checkout.tpl');
     echo getContent('commissionDisclaimer');
开发者ID:CWFranklin,项目名称:lan-party-site,代码行数:31,代码来源:checkout.php

示例4: getProducts

 private function getProducts()
 {
     $cart = new Basket();
     $cart->clear();
     $products = explode('<-|->', $_POST['products']);
     unset($products[0]);
     foreach ($products as $product) {
         $arr = explode('||', $product);
         $item = new Item();
         $item->id = $arr[0];
         $item->qty = $arr[1];
         $cart->add($item);
     }
     return $cart;
 }
开发者ID:VinceOmega,项目名称:mcb-nov-build,代码行数:15,代码来源:orders.php


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