本文整理汇总了PHP中ShoppingCart类的典型用法代码示例。如果您正苦于以下问题:PHP ShoppingCart类的具体用法?PHP ShoppingCart怎么用?PHP ShoppingCart使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ShoppingCart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Confirm
/**
*
*/
public function Confirm()
{
$auth = new Auth();
$shop = new ShoppingCart();
$user = $auth->id();
$myShop = $shop->all();
$objDetails = new DetalleCompra();
$total = 0;
if (empty($myShop)) {
return false;
}
foreach ($myShop as $key => $val) {
$total += $val->precio * $val->cantidad;
}
$result_insert = $this->create($user, $total);
if ($result_insert->success) {
foreach ($myShop as $k => $v) {
try {
$objDetails->create($result_insert->id, $v->id_prod, $v->name, $v->cantidad, $v->precio, $v->talle, $v->color);
//$stock = new TempStock();
//echo $stock->removeTempStock($user,$v->id_prod,$v->id_talle,$v->id_color,$v->type);
} catch (Exception $e) {
echo $e->getMessage();
}
}
$auth->restPoints($total);
$auth->sumConsumed($total);
$shop->removeAll();
return true;
}
}
示例2: render
public function render()
{
if (isset($_POST["clearCart"])) {
setcookie("shoppingCart", "");
}
if (isset($_GET["remove"])) {
$myArray = json_decode($_COOKIE["shoppingCart"]);
$i = 0;
foreach ($myArray as $index) {
if ($index->ID == $_GET["remove"]) {
unset($myArray[$i]);
$myArray = array_values($myArray);
break;
}
$i++;
}
setcookie("shoppingCart", json_encode($myArray));
}
$htmlcontent = "Der Warenkorb enthält keine Produkte";
if (isset($_COOKIE["shoppingCart"])) {
$myArray = json_decode($_COOKIE["shoppingCart"]);
//$htmlcontent = $htmlcontent. "Warenkorb:" .print_r(array_values($myArray));
include_once 'classes/class.shoppingcart.php';
$myCart = new ShoppingCart($myArray);
$htmlcontent = $myCart->displayCart();
}
return $htmlcontent;
}
示例3: testComputesReducedVatForTheRightCountry
public function testComputesReducedVatForTheRightCountry()
{
$shoppingCart = new ShoppingCart(new Austria());
$article = new Article(new ArticleName('Test'), new ArticleDescription(''), new Euro(1000), new ArticleTypeReduced());
$shoppingCart->add($article);
$shoppingCart->add($article);
$this->assertEquals(new Money(2200, new Currency('EUR')), $shoppingCart->total());
}
示例4: createCartWithItems
/**
* Create a {@link ShoppingCart} object and give
* it some test {@link OrderItem} objects.
*
* @return object ShoppingCart
*/
public static function createCartWithItems()
{
$item1 = new ProductVariation_OrderItem(array('ProductVariationID' => 2, 'Version' => 1));
$item2 = new ProductVariation_OrderItem(array('ProductVariationID' => 1, 'Version' => 1));
$cart = new ShoppingCart();
$cart->addItem(2, $item1);
$cart->addItem(1, $item2);
return $cart;
}
示例5: actionAddToCart
public function actionAddToCart($id)
{
$cart = new ShoppingCart();
$model = Product::findOne($id);
if ($model) {
$cart->put($model, 1);
return $this->redirect(['cart-view']);
}
throw new NotFoundHttpException();
}
示例6: checkPoints
public function checkPoints()
{
$user = Auth::User();
$ShoppingCart = new ShoppingCart();
$ShoppingCart->all();
$credit = $user->dblCredito;
$total = $ShoppingCart->getTotal();
if ($credit - $total < 0) {
return false;
} else {
return true;
}
}
示例7: setStoreInfo
function setStoreInfo($storeID, $storeInfo)
{
if (class_exists("ShoppingCart")) {
$Store = new ShoppingCart();
$Store->setStoreID($storeID);
$storeInfo = $Store->getStoreInformation();
return $storeInfo;
} else {
$ErrorMsgs[] = "The ShoppingCart class is not available!";
echo '<p>' . $ErrorMsgs[0] . '</p>';
return NULL;
}
}
示例8: afterLogin
protected function afterLogin($fromCookie)
{
if (!$fromCookie) {
// Assign the user to the cart, if logged in
Yii::app()->shoppingcart->assignCustomer(Yii::app()->user->id);
// If the user is not a guest user, then update the tax destination
// for the user's cart to display correct product prices. We can't
// do this for guest users since it will reset their cart to the
// store default, which is generally not what we want, especially
// not in tax-inclusive environments when the shipping destination
// is in a notax region.
if ($this->getIsGuest() !== true) {
Yii::app()->shoppingcart->setTaxCodeByDefaultShippingAddress();
}
// Since we have successfully logged in, see if we have a cart in progress
$cartInProgressFound = Yii::app()->shoppingcart->loginMerge();
// Recalculate and update the cart if prices of any cart items have changed
if ($cartInProgressFound === true) {
Yii::app()->shoppingcart->verifyPrices();
Yii::log("Cart ID is " . Yii::app()->shoppingcart->id, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
}
// Display no-tax message if the customer's default shipping address is
// in no-tax destination in tax-inclusive mode
if (Yii::app()->params['TAX_INCLUSIVE_PRICING'] == 1) {
ShoppingCart::displayNoTaxMessage();
}
} else {
Yii::log("User Login using cookie", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
}
}
示例9: testCalculations
function testCalculations()
{
$mp3player = $this->objFromFixture('Product', 'mp3player');
$this->get(ShoppingCart::add_item_link($mp3player->ID));
$cart = ShoppingCart::current_order();
$this->assertEquals($cart->Total(), 215);
}
示例10: doAddItemToCart
public function doAddItemToCart($data)
{
$product = Product::get()->byID($data['ProductID']);
$customisations = array();
foreach ($data as $key => $value) {
if (!(strpos($key, 'customise') === false) && $value) {
$custom_data = explode("_", $key);
if ($custom_item = ProductCustomisation::get()->byID($custom_data[1])) {
$modify_price = 0;
// Check if the current selected option has a price modification
if ($custom_item->Options()->exists()) {
$option = $custom_item->Options()->filter("Title", $value)->first();
$modify_price = $option ? $option->ModifyPrice : 0;
}
$customisations[] = array("Title" => $custom_item->Title, "Value" => $value, "ModifyPrice" => $modify_price);
}
}
}
if ($product) {
$cart = ShoppingCart::create();
$cart->add($product, $data['Quantity'], $customisations);
$cart->save();
// Clear any postage data that has been set
Session::clear("Commerce.PostageID");
$message = _t('Commerce.AddedItemToCart', 'Added item to your shopping cart');
$message .= ' <a href="' . $cart->Link() . '">';
$message .= _t('Commerce.ViewCart', 'View cart');
$message .= '</a>';
$this->controller->setSessionMessage("success", $message);
}
return $this->controller->redirectBack();
}
示例11: checkoutconfig
protected function checkoutconfig()
{
$config = new CheckoutComponentConfig(ShoppingCart::curr(), true);
$config->addComponent($comp = new CouponCheckoutComponent());
$comp->setValidWhenBlank(true);
return $config;
}
示例12: dopayment
function dopayment($data, $form)
{
$SQLData = Convert::raw2sql($data);
if (isset($SQLData['OrderID'])) {
if ($orderID = intval($SQLData['OrderID'])) {
$order = Order::get_by_id_if_can_view($orderID);
if ($order && $order->canPay()) {
if (EcommercePayment::validate_payment($order, $form, $data)) {
$payment = EcommercePayment::process_payment_form_and_return_next_step($order, $form, $data);
}
if ($payment) {
ShoppingCart::singleton()->submit();
$order->tryToFinaliseOrder();
return $payment;
} else {
//error messages are set in validation
return $this->controller->redirectBack();
}
} else {
$form->sessionMessage(_t('OrderForm.NO_PAYMENTS_CAN_BE_MADE_FOR_THIS_ORDER', 'No payments can be made for this order.'), 'bad');
return $this->controller->redirectBack();
}
}
}
$form->sessionMessage(_t('OrderForm.COULDNOTPROCESSPAYMENT', 'Sorry, we could not find the Order for payment.'), 'bad');
$this->controller->redirectBack();
return false;
}
示例13: testProductVersionDoesNotExist
/**
* Tries to create an order item with a non-existent version.
*/
function testProductVersionDoesNotExist()
{
$currentorder = ShoppingCart::current_order();
$brokenitem = new Product_OrderItem(array("ProductID" => $productSocks->ID, "ProductVersion" => 99999));
$this->assertEquals($brokenitem->UnitPrice(), null);
//TODO: what should happen here???
}
示例14: memberLoggedOut
/**
* Clear the cart, and session variables on member logout
*/
public function memberLoggedOut()
{
if (Member::config()->login_joins_cart) {
ShoppingCart::singleton()->clear();
OrderManipulation::clear_session_order_ids();
}
}
示例15: addtocart
/**
* Handles form submission
* @param array $data
* @return bool|\SS_HTTPResponse
*/
public function addtocart(array $data)
{
$groupedProduct = $this->getController()->data();
if (empty($data) || empty($data['Product']) || !is_array($data['Product'])) {
$this->sessionMessage(_t('GroupedCartForm.EMPTY', 'Please select at least one product.'), 'bad');
$this->extend('updateErrorResponse', $this->request, $response, $groupedProduct, $data, $this);
return $response ? $response : $this->controller->redirectBack();
}
$cart = ShoppingCart::singleton();
foreach ($data['Product'] as $id => $prodReq) {
if (!empty($prodReq['Quantity']) && $prodReq['Quantity'] > 0) {
$prod = Product::get()->byID($id);
if ($prod && $prod->exists()) {
$saveabledata = !empty($this->saveablefields) ? Convert::raw2sql(array_intersect_key($data, array_combine($this->saveablefields, $this->saveablefields))) : $prodReq;
$buyable = $prod;
if (isset($prodReq['Attributes'])) {
$buyable = $prod->getVariationByAttributes($prodReq['Attributes']);
if (!$buyable || !$buyable->exists()) {
$this->sessionMessage("{$prod->InternalItemID} is not available with the selected options.", "bad");
$this->extend('updateErrorResponse', $this->request, $response, $groupedProduct, $data, $this);
return $response ? $response : $this->controller->redirectBack();
}
}
if (!$cart->add($buyable, (int) $prodReq['Quantity'], $saveabledata)) {
$this->sessionMessage($cart->getMessage(), $cart->getMessageType());
$this->extend('updateErrorResponse', $this->request, $response, $groupedProduct, $data, $this);
return $response ? $response : $this->controller->redirectBack();
}
}
}
}
$this->extend('updateGroupCartResponse', $this->request, $response, $groupedProduct, $data, $this);
return $response ? $response : ShoppingCart_Controller::direct($cart->getMessageType());
}
开发者ID:helpfulrobot,项目名称:markguinn-silverstripe-shop-groupedproducts,代码行数:39,代码来源:GroupedCartForm.php