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


PHP Cart::addToCart方法代码示例

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


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

示例1: actionAdd

 public function actionAdd($serviceid)
 {
     if ($serviceid) {
         echo Cart::addToCart($serviceid);
     }
     return true;
 }
开发者ID:osovskaya,项目名称:flowershop,代码行数:7,代码来源:CartController.php

示例2: addToCart

 function addToCart()
 {
     $result = $this->Cart->Product->findById($this->p);
     if (empty($result)) {
         $this->Session->setFlash('This product was not found!');
         $this->redirect(array('action' => 'index'));
     } else {
         if ($result['Product']['pd_qty'] <= 0) {
             $this->Session->setFlash('The product you requested is out of stock!');
             $this->redirect(array('action' => 'index'));
         }
     }
     //ce je user loginan se uporablja userov ID
     if ($this->Auth->user()) {
         $sessionData = $this->Cart->getCart($this->p, $this->sid, $this->Session->read('Auth.User.id'));
         if (empty($sessionData)) {
             $this->Cart->addToCart($this->p, $this->sid, $this->Session->read('Auth.User.id'));
             $this->Session->setFlash('Product added to cart! -> through user ID / inserted');
         } else {
             $this->Cart->updateCart($this->p, $this->sid, $this->Session->read('Auth.User.id'));
             $this->Session->setFlash('Product added to cart! -> through session ID / updated');
         }
         //ce user ni prijavljen se uporablja sejni ID
     } else {
         $sessionData = $this->Cart->getCart($this->p, $this->sid);
         if (empty($sessionData)) {
             $this->Cart->addToCart($this->p, $this->sid);
             $this->Session->setFlash('Product added to cart! -> through session ID / inserted');
         } else {
             $this->Cart->updateCart($this->p, $this->sid);
             $this->Session->setFlash('Product added to cart! -> through session ID / updated');
         }
     }
     $this->Cart->cleanUp();
     $this->redirect(array('controller' => 'carts', 'action' => "index/c:{$this->c}/p:{$this->p}"));
 }
开发者ID:johnulist,项目名称:ecommerce,代码行数:36,代码来源:carts_controller.php

示例3: while

<?php

require_once 'includes/config.php';
$female = "SELECT itemId FROM items WHERE gender='f'";
$resultf = $db->query($female);
while ($rowf = $resultf->fetch()) {
    $id = $rowf['itemId'];
    $sqlItem = "SELECT * FROM items WHERE itemId={$id}";
    $item = $db->query($sqlItem);
    $i = $item->fetch();
    Cart::addToCart($i['name'], $i['price'], $i['itemID'], $i['type'], 3);
}
开发者ID:NadineMansour,项目名称:ecommerce2,代码行数:12,代码来源:session.php

示例4: login

 public function login()
 {
     $username = $_POST['username'];
     $password = $_POST['password'];
     $user = new User($username, $password);
     /* Login call to user object - checking credentials */
     $boolean = $user->login('account');
     if ($boolean) {
         $database = new Database('localhost', 'pdo_ret', 'root', '');
         $sql = "select * from account natural join shipping_address\n            natural join address where username='{$username}';";
         $result = $database->query($sql);
         $result = $result[0];
         $address = new Address($result[7], $result[8], $result[9], $result[10]);
         $account = new Account($username, $result[2], $password, (double) $result[4], $result[5], $result[6], $address);
         /* Check for existing payment method */
         $sql = "select * from account natural join account_payment \n            natural join address where username='{$username}';";
         $result = $database->query($sql);
         if (count($result) > 0) {
             $result = $result[0];
             $paymentID = $result[6];
             $methods = array('bank_account', 'credit_card', 'paypal');
             $ids = array('acc_id', 'cc_number', 'email');
             for ($i = 0; $i < count($methods); $i++) {
                 $sql = "select * from " . $methods[$i] . " where " . $ids[$i] . "='{$paymentID}';";
                 $result = $database->query($sql);
                 if (count($result) > 0) {
                     $result = $result[0];
                     switch ($methods[$i]) {
                         case 'bank_account':
                             $sql = "select * from bank_account natural join ba_billing_address \n                                natural join address where acc_number='{$paymentID}';";
                             $result = $database->query($sql);
                             $result = $result[0];
                             $street = $result[5];
                             $city = $result[6];
                             $parish = $result[7];
                             $postal = $result[8];
                             $address = new Address($street, $city, $parish, $postal);
                             $payment = new BankAccount($result[4], $result[2], $result[3], $address);
                             $account->setPaymentMethod($payment);
                             $_SESSION['payment'] = 'yes';
                             $_SESSION['paymenttype'] = 'ba';
                             break;
                         case 'credit_card':
                             $sql = "select * from credit_card natural join cc_billing_address \n                                natural join address where cc_number='{$paymentID}';";
                             $result = $database->query($sql);
                             $result = $result[0];
                             $ccnumber = $result[1];
                             $cardholder = $result[2];
                             $street = $result[3];
                             $city = $result[4];
                             $parish = $result[5];
                             $postal = $result[6];
                             $address = new Address($street, $city, $parish, $postal);
                             $payment = new CreditCard($cardholder, $ccnumber, '', '', $address);
                             $account->setPaymentMethod($payment);
                             $_SESSION['payment'] = 'yes';
                             $_SESSION['paymenttype'] = 'cc';
                             break;
                         case 'paypal':
                             $sql = "select * from paypal where email='{$paymentID}';";
                             $result = $database->query($sql);
                             $result = $result[0];
                             $email = $result[0];
                             $password = $result[1];
                             $payment = new PayPal($email, $password);
                             $account->setPaymentMethod($payment);
                             $_SESSION['payment'] = 'yes';
                             $_SESSION['paymenttype'] = 'pp';
                             break;
                     }
                     break;
                 }
             }
         }
         /* Get cart and products in cart */
         $sql = "select cart_id from account_cart where username='{$username}';";
         $result = $database->query($sql);
         $result = $result[0];
         $cartId = $result[0];
         $cart = new Cart();
         $cart->setCartId($cartId);
         $sql = "select * from cart_product where cart_id='{$cartId}';";
         $result = $database->query($sql);
         foreach ($result as $row) {
             $productId = $row[1];
             $quantity = $row[2];
             $sql = "select * from product where product_id='{$productId}';";
             $results = $database->query($sql);
             $results = $results[0];
             $name = $results[1];
             $price = $results[3];
             $product = new Product($productId, $name, $price);
             $cart->addToCart($product, $quantity);
         }
         /* Get orders */
         $products = array();
         $sql = "select order_id from account_order where username='{$username}';";
         $result = $database->query($sql);
         foreach ($result as $row) {
             $orderId = $row[0];
//.........这里部分代码省略.........
开发者ID:keniel123,项目名称:comp2140,代码行数:101,代码来源:control_controller.php

示例5: header

<?php

//include config
require_once 'includes/config.php';
if (!$user->is_logged_in()) {
    header('Location: index.php');
}
//the cart session
if (isset($_GET['itm']) && isset($_GET['quan'])) {
    $item = $_GET['itm'];
    $quantity = $_GET['quan'];
    $sql = "SELECT * FROM items WHERE itemID={$item}";
    $result = $db->query($sql);
    $i = $result->fetch();
    Cart::addToCart($i['name'], $i['price'], $i['itemID'], $i['type'], $quantity, $i['url']);
}
//sidebar
$female = "SELECT DISTINCT type FROM items WHERE gender='f'";
$resultf = $db->query($female);
$male = "SELECT DISTINCT type FROM items WHERE gender='m'";
$resultm = $db->query($male);
?>

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
开发者ID:NadineMansour,项目名称:ecommerce2,代码行数:31,代码来源:cart.php


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