本文整理汇总了PHP中Cart::getItem方法的典型用法代码示例。如果您正苦于以下问题:PHP Cart::getItem方法的具体用法?PHP Cart::getItem怎么用?PHP Cart::getItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cart
的用法示例。
在下文中一共展示了Cart::getItem方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: change_quantity
public function change_quantity()
{
import('@.ORG.Cart');
$cart = new \Cart();
$goodId = I('post.itemId', '', 'intval');
$quantity = I('post.quantity', '', 'intval');
$item = api('Document/get_detail', array('id' => $goodId));
if ($item['shop_goods_stock'] < $quantity) {
$data = array('status' => 0, 'msg' => '该商品的库存不足');
} else {
$cart->modNum($goodId, $quantity);
$data = array('status' => 1, 'item' => $cart->getItem($goodId), 'sumPrice' => $cart->getPrice());
}
echo json_encode($data);
}
示例2: change_quantity
public function change_quantity()
{
import('Think.ORG.Cart');
// 导入购物车类
$cart = new Cart();
$itemId = $this->_post('itemId', 'intval');
//商品ID
$quantity = $this->_post('quantity', 'intval');
//购买数量
$item = M('item')->field('goods_stock')->find($itemId);
if ($item['goods_stock'] < $quantity) {
$data = array('status' => 0, 'msg' => '该商品的库存不足');
} else {
$cart->modNum($itemId, $quantity);
$data = array('status' => 1, 'item' => $cart->getItem($itemId), 'sumPrice' => $cart->getPrice());
}
echo json_encode($data);
}
示例3: add
function add($item_id, $item_table, $qty = false, $table = false)
{
global $CFG;
$table = $table ? $table : 'cart';
$item = DB::getRecord($item_table, $item_id, false, true);
$item_name = $item['name'];
if (!($item_id > 0) && !$item) {
$errors[$item_id] = $CFG->cart_item_error;
Errors::merge($errors);
return false;
}
if (empty($item_table)) {
$errors[$item_id] = $CFG->cart_table_error;
Errors::merge($errors);
return false;
}
if (!($qty > 0)) {
$errors[$item_id] = $CFG->cart_qty_error;
Errors::merge($errors);
return false;
}
if ($c_item = Cart::getItem($item_id, $item_table, $table)) {
return Cart::update($item_id, $item_table, $c_item['qty'] + $qty, $table);
}
if (User::isLoggedIn()) {
$id = DB::insert($table, array('item_id' => $item_id, 'item_table' => $item_table, 'qty' => $qty, 'user_id' => User::$info['id']));
$messages[$item_name] = str_ireplace('[qty]', $qty, $CFG->cart_add_message);
Messages::merge($messages);
return $id;
} else {
$_SESSION['cart'][$item_table . '_' . $item_id] = array('item_id' => $item_id, 'item_table' => $item_table, 'qty' => $qty);
$messages[$item_name] = str_ireplace('[qty]', $qty, $CFG->cart_add_message);
Messages::merge($messages);
return true;
}
}
示例4: cartdetailsAction
/**
* Controller action to manage the details of the cart.
* Update/delete items or load the list.
*
* @return void
*/
public function cartdetailsAction()
{
$account = Cible_FunctionsGeneral::getAuthentication();
if (!$account) {
$this->_redirect(Cible_FunctionsPages::getPageNameByID(1, Zend_Registry::get('languageID')));
}
$productData = array();
$cart = new Cart();
if ($this->_isXmlHttpRequest) {
$this->disableLayout();
$this->disableView();
$action = $this->_getParam('do');
$productId = $this->_getParam('pId');
$itemId = $this->_getParam('itemId');
$quantity = $this->_getParam('quantity');
$size = $this->_getParam('size');
$category = $this->_getParam('category');
$disable = $this->_getParam('disable');
$cartId = $this->_getParam('cartItemsId');
if ($action == 'update' && !empty($productId)) {
if (!empty($size)) {
$cart->updateItem($productId, -1, array('CI_TailleID' => $size, 'CI_ItemID' => $itemId, 'CI_CartItemsID' => $cartId));
} elseif (!empty($category)) {
$cart->updateItem($productId, -1, array('CI_CatTailleID' => $category, 'CI_ItemID' => $itemId, 'CI_CartItemsID' => $cartId));
} else {
$oItem = new ItemsObject();
$oItem->setId($itemId);
$amount = $oItem->getPrice($quantity);
$cart->updateItem($productId, $quantity, array('CI_ItemID' => $itemId, 'CI_Total' => $amount, 'CI_CartItemsID' => $cartId));
}
echo 'updated';
} elseif ($action == 'delete' && !empty($productId)) {
if ($itemId && $cartId) {
$cart->updateItem($productId, 0, array('CI_ItemID' => $itemId, 'CI_CartItemsID' => $cartId));
echo 'deletedRow';
} else {
$cart->updateItem($productId);
echo 'deleted';
}
} elseif ($action == 'disable' && !empty($productId)) {
$cart->updateItem($productId, -1, array('CI_IsToSend' => $disable, 'CI_ItemID' => $itemId));
} elseif ($action == 'addSize' && !empty($productId)) {
$lastId = $cart->addSize(array('CI_ID' => $productId, 'CI_Quantity' => 1, 'CI_CatTailleID' => $category, 'CI_ItemID' => $itemId));
} elseif ($action == 'getSizes' && !empty($category)) {
$oSize = new TailleObject();
$langId = $this->_getParam('langId');
$size = $oSize->getDataByCategoryTailleId($category, $langId);
echo json_encode($size);
exit;
}
} else {
$url = $this->view->absolute_web_root . $this->getRequest()->getPathInfo();
$exclude = preg_match('/resume-order/', $url);
if (!$exclude) {
Cible_View_Helper_LastVisited::saveThis($url);
}
$urlBack = '';
$urlNextStep = '';
$urls = Cible_View_Helper_LastVisited::getLastVisited();
if (count($urls) > 1) {
$urlBack = $urls[1];
}
$account = Cible_FunctionsGeneral::getAuthentication();
$profile = new MemberProfile();
$memberData = $profile->findMember(array('email' => $account['email']));
$memberData = $profile->addTaxRate($memberData);
// if ($memberData['validatedEmail'] == '')
// $this->view->assign('valide', true);
// else
// $this->view->assign('valide', false);
$cartData = $cart->getAllIds();
$allIds = $cartData['cartId'];
if (count($allIds)) {
$urlNextStep = $this->view->baseUrl() . '/' . Cible_FunctionsPages::getPageNameByID($this->_orderPageId, Zend_Registry::get('languageID')) . '/auth-order/';
}
$this->view->assign('itemCount', count($allIds));
$this->view->assign('cartTotal', $cart->getTotalItem());
$oProduct = new ProductsCollection();
// $orderPageId = Cible_FunctionsCategories::getPagePerCategoryView(0, 'order', 17);
$resume = false;
if ($this->_registry->pageID == $this->_orderPageId) {
$resume = true;
}
foreach ($allIds as $key => $id) {
$itemId = $cartData['itemId'][$key];
$prodId = $cartData['prodId'][$key];
$productData[$id] = $oProduct->getDetails($prodId, $itemId, $resume);
$cartDetails = $cart->getItem($id, $itemId);
if ($resume) {
$renderItem = $cart->renderResume($cartDetails, $itemId);
} else {
$renderItem = $cart->renderCartLine($cartDetails, $itemId);
}
$productData[$id]['items']['render'] = $renderItem;
//.........这里部分代码省略.........
示例5: change_quantity
public function change_quantity()
{
import('Think.ORG.Cart');
// 导入购物车类
$cart = new Cart();
$itemId = $this->_post('itemId', 'intval');
//商品ID
$quantity = $this->_post('quantity', 'intval');
//购买数量
$spec_id = $this->_post('spec_id', 'intval');
//购买数量
$goods_stock = 0;
$spec_1 = '';
$spec_2 = '';
$price = 0;
$item = M('item')->field('id,title,img,price,goods_stock')->find($itemId);
if (!is_array($item)) {
$data = array('status' => 0, 'msg' => '不存在该商品', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
}
if ($spec_id == 0) {
$goods_stock = $item['goods_stock'];
$price = $item['price'];
} else {
$item_spec = M('item_spec')->field('spec_1,spec_2,price,stock')->find($spec_id);
$goods_stock = $item_spec['stock'];
$price = $item_spec['price'];
$spec_1 = $item_spec['spec_1'];
$spec_2 = $item_spec['spec_2'];
}
if ($goods_stock < $quantity) {
$data = array('status' => 0, 'msg' => '没有足够的库存', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
} else {
$cart->modNum($itemId, $spec_id, $quantity);
$data = array('status' => 1, 'item' => $cart->getItem($itemId, $spec_id), 'sumPrice' => $cart->getPrice());
}
echo json_encode($data);
}
示例6: calculateTotal
/**
* Calculation of taxes and amounts for orders rendrering.
*
* @param array $memberInfos
* @param bool $lines
*
* @return array
*/
public function calculateTotal($memberInfos, $lines = false)
{
$session = new Zend_Session_Namespace('order');
$data = array();
$oCart = new Cart();
$oItem = new ItemsObject();
$oProd = new ProductsCollection();
$subTotProv = 0;
$subTotFed = 0;
$subTot = 0;
$total = 0;
$taxProv = 0;
$taxFed = 0;
$tmpSum = 0;
$nbPoint = 0;
$cartData = $oCart->getAllIds();
$orderParams = Cible_FunctionsGeneral::getParameters();
if (!$memberInfos['noFedTax'] && $session->stateId == 11) {
foreach ($cartData['cartId'] as $key => $id) {
$itemId = $cartData['itemId'][$key];
$prodId = $cartData['prodId'][$key];
$itemDetails = $oItem->getAll(null, true, $itemId);
$cartDetails = $oCart->getItem($id, $itemId, true);
if ($itemDetails[0]['I_TaxFed']) {
$subTotFed += $cartDetails['Total'];
}
}
$addShipFee = Cible_FunctionsGeneral::compareFloats($subTotFed, '<', $orderParams['CP_ShippingFeesLimit'], 2);
if ($addShipFee) {
$subTotFed += $orderParams['CP_ShippingFees'];
}
if (isset($session->order['cod'])) {
$subTotFed += $orderParams['CP_MontantFraisCOD'];
}
$taxFed = Cible_FunctionsGeneral::federalTax($subTotFed);
}
if (!$memberInfos['noProvTax']) {
foreach ($cartData['cartId'] as $key => $id) {
$itemId = $cartData['itemId'][$key];
$prodId = $cartData['prodId'][$key];
$itemDetails = $oItem->getAll(null, true, $itemId);
$cartDetails = $oCart->getItem($id, $itemId, true);
if ($itemDetails[0]['I_TaxProv']) {
$subTotProv += $cartDetails['Total'];
}
}
$addShipFee = Cible_FunctionsGeneral::compareFloats($subTotProv, '<', $orderParams['CP_ShippingFeesLimit'], 2);
if ($addShipFee) {
$subTotProv += $orderParams['CP_ShippingFees'];
}
if (isset($session->order['cod'])) {
$subTotProv += $orderParams['CP_MontantFraisCOD'];
}
$taxProv = Cible_FunctionsGeneral::provinceTax($subTotProv);
}
foreach ($cartData['cartId'] as $key => $id) {
$itemId = $cartData['itemId'][$key];
$prodId = $cartData['prodId'][$key];
$productData = $oProd->getDetails($prodId);
$cartDetails = $oCart->getItem($id, $itemId, true);
$subTot += $cartDetails['Total'];
if ($oProd->getBonus()) {
$nbPoint += ceil($cartDetails['Total'] * $orderParams['CP_BonusPointDollar']);
}
}
$addShipFee = Cible_FunctionsGeneral::compareFloats($subTot, '<', $orderParams['CP_ShippingFeesLimit'], 2);
if ($addShipFee) {
$tmpSum += $orderParams['CP_ShippingFees'];
}
if (isset($session->order['cod'])) {
$tmpSum += $orderParams['CP_MontantFraisCOD'];
}
$total = $subTot + $tmpSum + round($taxFed, 2) + round($taxProv, 2);
$data = array('subTotProv' => $subTotProv, 'subTotFed' => $subTotFed, 'subTot' => $subTot, 'total' => $total, 'taxProv' => $taxProv, 'nbPoint' => $nbPoint, 'taxFed' => $taxFed);
return $data;
}