コード例 #1
0
 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);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 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);
 }
コード例 #4
0
ファイル: PresentListener.php プロジェクト: JJmaz/dp
 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);
     }
 }
コード例 #5
0
ファイル: shopping.php プロジェクト: marsa1985/kazabiz
 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);
     }
 }
コード例 #6
0
ファイル: IndexController.php プロジェクト: anunay/stentors
 /**
  * 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);
     }
 }
コード例 #7
0
 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());
 }
コード例 #8
0
 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);
 }
コード例 #9
0
ファイル: stockin.php プロジェクト: runningjack/RobertJohnson
 /**
  * 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);
 }
コード例 #10
0
 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");
 }
コード例 #11
0
ファイル: tTopHeader.php プロジェクト: luvyatyss/nashop
<?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;
コード例 #12
0
ファイル: count.php プロジェクト: SebastianElvis/mtcds
<?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);
}
コード例 #13
0
ファイル: client.php プロジェクト: JJmaz/dp
<?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();