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


PHP Cart::addItem方法代码示例

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


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

示例1: testCreateInitPayment

 public function testCreateInitPayment()
 {
     $cart = new Cart(new Currency(Currency::CZK));
     $cart->addItem('Nákup na vasobchodcz', 1, 1789600, 'Lenovo ThinkPad Edge E540');
     $cart->addItem('Poštovné', 1, 0, 'Doprava PPL');
     $request = $this->requestFactory->createInitPayment('5547', new PayOperation(PayOperation::PAYMENT), new PayMethod(PayMethod::CARD), true, 'https://vasobchod.cz/gateway-return', new HttpMethod(HttpMethod::POST), $cart, 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)', 'some-base64-encoded-merchant-data', '123', new Language(Language::CZ), 1800, 1, 1);
     $this->assertInstanceOf(InitPaymentRequest::class, $request);
 }
开发者ID:slevomat,项目名称:csob-gateway,代码行数:8,代码来源:RequestFactoryTest.php

示例2: add_cart

 public function add_cart()
 {
     import('Think.ORG.Cart');
     // 导入分页类
     $cart = new Cart();
     $goodId = $this->_post('goodId', 'intval');
     //商品ID
     $quantity = $this->_post('quantity', 'intval');
     //购买数量
     $item = M('item')->field('id,title,img,price,goods_stock')->find($goodId);
     if (!is_array($item)) {
         $data = array('status' => 0, 'msg' => '不存在该商品', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } elseif ($item['goods_stock'] < $quantity) {
         $data = array('status' => 0, 'msg' => '没有足够的库存', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } else {
         $result = $cart->addItem($item['id'], $item['title'], $item['price'], $quantity, $item['img']);
         if ($result == 1) {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '该商品已经存在购物车');
         } else {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '商品已成功添加到购物车');
         }
     }
     //$data=array('status'=>2);
     echo json_encode($data);
 }
开发者ID:dlpc,项目名称:weixin_shop,代码行数:25,代码来源:shopcartAction.class.php

示例3: add_cart

 public function add_cart()
 {
     header("content-Type: text/html; charset=Utf-8");
     import('Think.ORG.Cart');
     // 导入分页类
     $cart = new Cart();
     $goodId = $this->_post('goodId', 'intval');
     //商品ID
     $quantity = $this->_post('quantity', 'intval');
     //购买数量
     $size = $this->_post('size', 'intval');
     //大小
     $color = $this->_post('color', 'trim');
     //颜色
     $item = M('item')->field('id,title,img,price,goods_stock,tokenTall,free,pingyou,kuaidi,ems')->find($goodId);
     $item['size'] = $size;
     $item['color'] = $color;
     //mb_convert_encoding($color, "UTF-8", "GBK");
     if (!is_array($item)) {
         $data = array('status' => 0, 'msg' => '不存在该商品', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } elseif ($item['goods_stock'] < $quantity) {
         $data = array('status' => 0, 'msg' => '没有足够的库存', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } else {
         $result = $cart->addItem($item['id'], $item['title'], $item['price'], $quantity, $item['img'], $item['size'], $item['color'], $item['tokenTall'], $item['free'], $item['pingyou'], $item['kuaidi'], $item['ems']);
         if ($result == 1) {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '该商品已经存在购物车');
         } else {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '商品已成功添加到购物车');
         }
     }
     //$data=array('status'=>2);
     echo json_encode($data);
 }
开发者ID:jackycgq,项目名称:weixinshop,代码行数:33,代码来源:shopcartAction.class.php

示例4: update

 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);
     }
 }
开发者ID:JJmaz,项目名称:dp,代码行数:9,代码来源:PresentListener.php

示例5: addToCart

 function addToCart()
 {
     $dealId = JRequest::getVar('dealId');
     $referralId = JRequest::getVar('referralid');
     $bBuy4friend = JRequest::getVar('buy4friend', 0);
     $deal = JModel::getInstance('deal', 'enmasseModel')->getById($dealId);
     //*************************************************************************************
     // check Deal
     $now = DatetimeWrapper::getDatetimeOfNow();
     if ($now < $deal->start_at) {
         $msg = JText::_("DEAL_NOT_READY");
         $link = JRoute::_("index.php?option=com_enmasse&controller=deal&task=view&id=" . $deal->id, false);
         JFactory::getApplication()->redirect($link, $msg);
     } elseif (time() > strtotime($deal->end_at) + 24 * 60 * 60) {
         $msg = JText::_("DEAL_END_MSG");
         $link = JRoute::_("index.php?option=com_enmasse&controller=deal&task=view&id=" . $deal->id, false);
         JFactory::getApplication()->redirect($link, $msg);
     } elseif ($deal->published == false) {
         $msg = JText::_("DEAL_NOLONGER_PUBLISH");
         $link = JRoute::_("index.php?option=com_enmasse&controller=deal&task=view&id=" . $deal->id, false);
         JFactory::getApplication()->redirect($link, $msg);
     } elseif ($deal->status == "Voided") {
         $msg = JText::_("DEAL_HAVE_BEEN_VOID");
         $link = JRoute::_("index.php?option=com_enmasse&controller=deal&task=view&id=" . $deal->id, false);
         JFactory::getApplication()->redirect($link, $msg);
     } else {
         // add to cart
         /*
         $cart = unserialize(JFactory::getSession()->get('cart'));
         if (empty($cart))
         $cart = new Cart();
         */
         // We only allow 1 item per cart from now one...
         $cart = new Cart();
         $cart->addItem($deal);
         //Set sesstion for referral ID
         if ($referralId != '') {
             $cart->setReferralId($referralId);
         }
         JFactory::getSession()->set('cart', serialize($cart));
         $dealName = $deal->name;
         $cartItemCount = $cart->getItem($dealId)->getCount();
         $msg = $dealName . " " . JText::_("DEAL_ADD_TO_CART");
         $link = JRoute::_("index.php?option=com_enmasse&controller=shopping&task=checkout&buy4friend={$bBuy4friend}", false);
         JFactory::getApplication()->redirect($link, $msg);
     }
 }
开发者ID:marsa1985,项目名称:kazabiz,代码行数:47,代码来源:shopping.php

示例6: ajaxAction

 /**
  * Get the action type sent via ajax and update the total of items in the
  * cart.
  * Gets parameters from POST
  *
  * @return void
  */
 public function ajaxAction()
 {
     $this->getHelper('viewRenderer')->setNoRender();
     $action = $this->_getParam('actionAjax');
     $langId = $this->_getParam('langId');
     if ($action == 'updateCart') {
         $cart = new Cart();
         $cartItems = $cart->getTotalItem();
         $nbItems = $cartItems['Quantity'];
         $subTotal = $cartItems['Subtotal'];
         echo json_encode($cart->getTotalItem());
     } elseif ($action == 'addToCart') {
         $cart = new Cart();
         if (!$this->_isXmlHttpRequest) {
             $itemID = $this->_getParam('p_id');
             $session = new Zend_Session_Namespace();
             $langId = $session->languageId;
             $srcOriginal = "../www/" . "data/images/catalog/originals/" . $itemID . ".png";
             $width = $this->_config->cart->image->thumb->maxWidth;
             $height = $this->_config->cart->image->thumb->maxHeight;
             Cible_FunctionsImageResampler::resampled(array('src' => $srcOriginal, 'maxWidth' => $width, 'maxHeight' => $height));
         } else {
             $itemID = $this->_getParam('itemID');
         }
         if ($itemID != '') {
             $cart->addItem($itemID, 1, array('langId' => $langId));
         }
     } elseif ($action == 'update') {
         $cart = new Cart();
         $itemId = $this->_getParam('itemId');
         $id = $this->_getParam('cartItemsId');
         $cartItem = $cart->getItem($id, $itemId);
         echo json_encode($cartItem['Total']);
     } else {
         echo 'null';
     }
     if (!$this->_isXmlHttpRequest) {
         $config = Zend_Registry::get('config');
         $pageId = $config->cartPageId;
         $url = $this->_registry->absolute_web_root . "/" . Cible_FunctionsPages::getPageNameByID($pageId, $langId);
         $this->_redirect($url);
     }
 }
开发者ID:anunay,项目名称:stentors,代码行数:50,代码来源:IndexController.php

示例7: testAddItem

 public function testAddItem()
 {
     $item = \App\Models\Commodity::find(1);
     $item2 = \App\Models\Commodity::find(2);
     Cart::addItem($item);
     $this->assertEquals(Cart::getItems()->count(), 1);
     $this->assertEquals(Cart::getTotalCost(), $item->getPrice());
     Cart::removeItemsById($item->getIdentifer());
     $this->assertEquals(Cart::getItems()->count(), 0);
     $this->assertEquals(Cart::getTotalCost(), 0);
     Cart::addItem($item);
     Cart::addItem($item2);
     Cart::addItem($item);
     $this->assertEquals(Cart::getItems()->count(), 2);
     $this->assertEquals(Cart::getTotalCost(), $item->getPrice() * 2 + $item2->getPrice());
     Cart::removeItems(['name' => $item->getName()]);
     $this->assertEquals(Cart::getItems()->count(), 1);
     $this->assertEquals(Cart::getTotalCost(), $item2->getPrice());
 }
开发者ID:KeepCalmAndPraiseTheSun,项目名称:werashop,代码行数:19,代码来源:CartTest.php

示例8: add_cart

 public function add_cart()
 {
     //导入购物车
     import('@.ORG.Cart');
     $cart = new \Cart();
     $goodId = I('post.goodId', '', 'intval');
     $quantity = I('post.quantity', '', 'intval');
     $item = api('Document/get_detail', array('id' => $goodId));
     if (empty($item)) {
         $data = array('status' => 0, 'msg' => '不存在该商品', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } elseif ($item['shop_goods_stock'] < $quantity) {
         $data = array('status' => 0, 'msg' => '没有足够的库存', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } else {
         $result = $cart->addItem($item['id'], $item['title'], $item['shop_good_price'], $quantity, $item['cover_id']);
         if ($result == 1) {
             //购物车存在该商品
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '该商品已经存在购物车');
         } else {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '商品已成功添加到购物车');
         }
     }
     echo json_encode($data);
 }
开发者ID:wmk223,项目名称:amango_V3,代码行数:23,代码来源:ShopController.class.php

示例9: doAddToCart

 /**
  * cart model to maitain items array
  * in cart befor it is been posted to 
  * the purchases table
  */
 public function doAddToCart()
 {
     $basket = new Cart();
     $mcart = "";
     $basket->addItem($_POST['ppid'], $_POST['ppname'], $_POST['pcatname'], $_POST['pqty'], $_POST['pprice']);
     $myItems = $basket->getContents();
     // the basket get arrays of items in the cart
     $quantity = $_POST['pqty'];
     $subTotal = $basket->getTotal();
     // the basket gets the total of the items as subtotal
     $vat = 0.05 * $subTotal;
     // calculates the vat
     $total = $subTotal + $vat;
     $mcart .= "<table id='minicart-a' summary='Employee Pay Sheet'>\n    <thead>\n    \t<tr>\n            <th width='10%' scope='col'>ItemID</th>\n        \t<th width='35%' scope='col' >Description</th>\n            <th width='20%' scope='col'>Qty</th>\n            <th width='10%' scope='col'>Cost</th>\n            <th width='10%' scope='col'>Total</th>\n            \n        </tr>\n    </thead>\n    <tbody>";
     //print_r($item['itemName']);
     $qt = 0;
     foreach ($myItems as $item) {
         $myproduct = Items::find_by_id($item['itemId']);
         //print_r($myproduct);
         $mcart .= "<tr>\n              \n              <td>" . $item['itemName'] . "</td>\n              <td>" . $myproduct->item_description . "</td>\n              <td><span>\n                <input type='text' name='qty' id='qty" . $qt . "' value='" . $item['itemQuantity'] . "' style='width:40px; padding:2px; height:36px; text-align:center; '  />\n              </span>&nbsp;&nbsp;<span><a href='#' class='modifyqty' prodid='" . $item['itemId'] . "' prodqty='" . $item['itemQuantity'] . "'  tprice='" . $item['itemPrice'] . "' count ='" . $qt . "' ><img src='public/icons/Refresh16.png' width='18' height='18' /></a></span>&nbsp;&nbsp;<span><a href='#' class='deleteitem' prodid='" . $item['itemId'] . "'  ><img src='public/icons/Delete16.png' width='18' height='18' /></a></span></td>\n              <td>&#8358;" . number_format($item['itemPrice'], 2, '.', ',') . "</td>\n              <td>&#8358;" . number_format($item['itemTotal'], 2, '.', ',') . "</td>\n            </tr>";
         $qt++;
     }
     /**
      * foreach($myItems as $item){
      *     	$mcart .="<tr>
      *         	<td>".$item['itemQuantity']."</td>
      *             <td>".$item['itemName']."</td>
      *             <td>&#8358;".$item['itemName']."</td>
      *             <td>".number_format($item['itemPrice'],2,'.',',')."</td>
      *             <td><span class='bold'>&#8358;".number_format($item['itemTotal'],2,'.',',')."</span></td>
      *             <td><span class='bold'>x</span></td>
      *         </tr>
      *         
      *         ";
      * 	}
      */
     $mcart .= "<tr>\n        \t<td>&nbsp;</td>\n            <td>&nbsp;</td>\n            <td>&nbsp;</td>\n            <td>&nbsp;</td>\n            <td>&nbsp;</td>\n        </tr>       \n\t    <tr>\n          <td>&nbsp;</td>\n          <td colspan='3' align='right'><h3 class='black'>SubTotal:</h3></td>\n          <td colspan='3' align='right'><span class='bold'>&#8358;" . number_format($subTotal, 2, '.', ',') . "</span></td>\n        </tr>\n        <tr>\n          <td>&nbsp;</td>\n          <td colspan='3' align='right'><h3 class='black'>VAT(5%):</h3></td>\n          <td colspan='3' align='right'><span class='bold'>&#8358;" . number_format($vat, 2, '.', ',') . "</span></td>\n        </tr>\n        <tr>\n          <td>&nbsp;</td>\n          <td colspan='3' align='right'><h3><span class='black'>Total:</span></h3></td>\n          <td colspan='3' align='right'><div class='divider'></div><h3 class='bold'>&#8358;" . number_format($total, 2, '.', ',') . "</h3><div class='divider'></div><div class='divider'></div></td>\n        </tr>\n        <tr>\n        \t<td>&nbsp;</td>\n            <td colspan='3' align='right'><span style='margin:5px'><a href='#'>view cart</a></span></td>\n            <td colspan='3'><span style='margin:5px'><a href='#'>Check out</a></span></td>\n            </tr>\n    </tbody>\n</table>";
     print_r($mcart);
 }
开发者ID:runningjack,项目名称:RobertJohnson,代码行数:44,代码来源:stockin.php

示例10: item_buy

 public function item_buy()
 {
     import('Think.ORG.Cart');
     // 导入分页类
     $cart = new Cart();
     $goodId = $this->_post('goodId', 'intval');
     //商品ID
     $quantity = $this->_post('quantity', 'intval');
     //购买数量
     $size = $this->_post('size', 'intval');
     //大小
     $color = $this->_post('color', 'trim');
     //颜色
     // dump($goodId.'--'.$quantity.'--'.$size.'--'.$color);
     $item = M('item')->field('id,title,img,price,goods_stock,tokenTall,free,pingyou,kuaidi,ems')->find($goodId);
     $item['size'] = $size;
     $item['color'] = $color;
     //mb_convert_encoding($color, "UTF-8", "GBK");
     if (!is_array($item)) {
         $data = array('status' => 0, 'msg' => '不存在该商品', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } elseif ($item['goods_stock'] < $quantity) {
         $data = array('status' => 0, 'msg' => '没有足够的库存', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } else {
         $result = $cart->addItem($item['id'], $item['title'], $item['price'], $quantity, $item['img'], $item['size'], $item['color'], $item['tokenTall'], $item['free'], $item['pingyou'], $item['kuaidi'], $item['ems']);
         if ($result == 1) {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '该商品已经存在购物车');
         } else {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '商品已成功添加到购物车');
         }
     }
     $this->redirect("index");
 }
开发者ID:dlpc,项目名称:wxshoppingmall,代码行数:32,代码来源:shopcartAction.class.php

示例11: Crypter

<?php

require_once './helper/Utils.php';
require_once './helper/Context.php';
require_once './entities/User.php';
require_once './entities/Cart.php';
require_once './helper/crypter.php';
//security
if (isset($_POST["txtProID"])) {
    if (Context::IsLogged()) {
        $proID = $_POST["txtProID"];
        $quantity = 1;
        if (isset($_POST["txtOrderQ"]) && !empty($_POST["txtOrderQ"])) {
            $quantity = $_POST["txtOrderQ"];
        }
        Cart::addItem($proID, $quantity);
    } else {
        $_SESSION['showModalLogin'] = true;
    }
    //Cart::printCart();
}
if (isset($_SESSION["IsLogin"]) && $_SESSION["IsLogin"] == 1) {
    //set token
    $crypter = new Crypter("nhatanh");
    if (!isset($_SESSION["token"])) {
        $datetime = new DateTime();
        $str_datetime = date_format($datetime, 'Y-m-d H:i:s');
        $security = $str_datetime . " " . strval(rand());
        $encrypted = $crypter->Encrypt($security);
        $_SESSION["token"] = $security;
        $token = "token=" . $encrypted;
开发者ID:luvyatyss,项目名称:nashop,代码行数:31,代码来源:tTopHeader.php

示例12: Cart

<?php

session_start();
require_once './Cart.php';
$cart = new Cart(1);
if ($_GET['type'] == 1) {
    $cart->addItem($_GET['id'], 1, $_GET['price']);
} else {
    $cart->decNum($_GET['id'], 1);
}
开发者ID:SebastianElvis,项目名称:mtcds,代码行数:10,代码来源:count.php

示例13: dirname

<?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();
开发者ID:JJmaz,项目名称:dp,代码行数:31,代码来源:client.php


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