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


PHP ShoppingCart::singleton方法代码示例

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


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

示例1: addtocart

 /**
  * Adds a given product to the cart. If a hidden field is passed 
  * (ValidateVariant) then simply a validation of the user including that
  * product is done and the users cart isn't actually changed.
  *
  * @return mixed
  */
 public function addtocart($data, $form)
 {
     if ($variation = $this->getBuyable($data)) {
         $quantity = isset($data['Quantity']) && is_numeric($data['Quantity']) ? (int) $data['Quantity'] : 1;
         $cart = ShoppingCart::singleton();
         // if we are in just doing a validation step then check
         if ($this->request->requestVar('ValidateVariant')) {
             $message = '';
             $success = false;
             try {
                 $success = $variation->canPurchase(null, $data['Quantity']);
             } catch (ShopBuyableException $e) {
                 $message = get_class($e);
                 // added hook to update message
                 $this->extend('updateVariationAddToCartMessage', $e, $message, $variation);
             }
             $ret = array('Message' => $message, 'Success' => $success, 'Price' => $variation->dbObject('Price')->TrimCents());
             $this->extend('updateVariationAddToCartAjax', $ret, $variation, $form);
             return json_encode($ret);
         }
         if ($cart->add($variation, $quantity)) {
             $form->sessionMessage("Successfully added to cart.", "good");
         } else {
             $form->sessionMessage($cart->getMessage(), $cart->getMessageType());
         }
     } else {
         $variation = null;
         $form->sessionMessage("That variation is not available, sorry.", "bad");
         //validation fail
     }
     $this->extend('updateVariationAddToCart', $form, $variation);
     $request = $this->getRequest();
     $this->extend('updateVariationFormResponse', $request, $response, $variation, $quantity, $form);
     return $response ? $response : ShoppingCart_Controller::direct();
 }
开发者ID:helpfulrobot,项目名称:silvershop-core,代码行数:42,代码来源:VariationForm.php

示例2: 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

示例3: testCart

 function testCart()
 {
     $cart = $this->objFromFixture("Order", "cart");
     ShoppingCart::singleton()->setCurrent($cart);
     $page = new Page_Controller();
     $this->assertEquals("\$8.00", (string) $page->renderWith("CartTestTemplate"));
 }
开发者ID:NobrainerWeb,项目名称:silverstripe-shop,代码行数:7,代码来源:ViewableCartTest.php

示例4: 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;
 }
开发者ID:TouchtechLtd,项目名称:silverstripe-ecommerce,代码行数:28,代码来源:OrderForm_Payment.php

示例5: 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();
     }
 }
开发者ID:burnbright,项目名称:silverstripe-shop,代码行数:10,代码来源:ShopMember.php

示例6: testOffsitePaymentWithGatewayCallback

 public function testOffsitePaymentWithGatewayCallback()
 {
     //set up cart
     $cart = ShoppingCart::singleton()->setCurrent($this->objFromFixture("Order", "cart"))->current();
     //collect checkout details
     $cart->update(array('FirstName' => 'Foo', 'Surname' => 'Bar', 'Email' => 'foo@bar.com'));
     $cart->write();
     //pay for order with external gateway
     $processor = OrderProcessor::create($cart);
     $this->setMockHttpResponse('PaymentExpress/Mock/PxPayPurchaseSuccess.txt');
     $response = $processor->makePayment("PaymentExpress_PxPay", array());
     //gateway responds (in a different session)
     $oldsession = $this->mainSession;
     $this->mainSession = new TestSession();
     ShoppingCart::singleton()->clear();
     $this->setMockHttpResponse('PaymentExpress/Mock/PxPayCompletePurchaseSuccess.txt');
     $this->getHttpRequest()->query->replace(array('result' => 'abc123'));
     $identifier = $response->getPayment()->Identifier;
     $response = $this->get("paymentendpoint/{$identifier}/complete");
     //reload cart as new order
     $order = Order::get()->byId($cart->ID);
     $this->assertFalse($order->isCart(), "order is no longer in cart");
     $this->assertTrue($order->isPaid(), "order is paid");
     //bring back client session
     $this->mainSession = $oldsession;
     $response = $this->get("paymentendpoint/{$identifier}/complete");
     $this->assertNull(Session::get("shoppingcartid"), "cart session id should be removed");
     $this->assertNotEquals(404, $response->getStatusCode(), "We shouldn't get page not found");
     $this->markTestIncomplete("Should assert other things");
 }
开发者ID:helpfulrobot,项目名称:silvershop-core,代码行数:30,代码来源:ShopPaymentTest.php

示例7: setUp

 public function setUp()
 {
     parent::setUp();
     ShopTest::setConfiguration();
     //reset config
     $this->cart = ShoppingCart::singleton();
     $this->product = $this->objFromFixture('Product', 'mp3player');
     $this->product->publish('Stage', 'Live');
 }
开发者ID:helpfulrobot,项目名称:silvershop-core,代码行数:9,代码来源:ShoppingCartTest.php

示例8: setUp

 function setUp()
 {
     parent::setUp();
     ShopTest::setConfiguration();
     $this->cartpage = $this->objFromFixture("CartPage", "cart");
     $this->cartpage->publish('Stage', 'Live');
     ShoppingCart::singleton()->setCurrent($this->objFromFixture("Order", "cart"));
     //set the current cart
 }
开发者ID:tylerkidd,项目名称:silverstripe-shop-shippingframework,代码行数:9,代码来源:ShippingEstimateFormTest.php

示例9: shippingmethod

 function shippingmethod()
 {
     $form = $this->ShippingMethodForm();
     $cart = ShoppingCart::singleton()->current();
     if ($cart->ShippingMethodID) {
         $form->loadDataFrom($cart);
     }
     return array('OrderForm' => $form);
 }
开发者ID:burnbright,项目名称:silverstripe-shop-shipping,代码行数:9,代码来源:CheckoutStep_ShippingMethod.php

示例10: testLoginDoesntJoinCart

 public function testLoginDoesntJoinCart()
 {
     Member::config()->login_joins_cart = false;
     $order = $this->objFromFixture("Order", "cart");
     ShoppingCart::singleton()->setCurrent($order);
     $member = $this->objFromFixture("Member", "jeremyperemy");
     $member->logIn();
     $this->assertEquals(0, $order->MemberID);
     $member->logOut();
     $this->assertTrue((bool) ShoppingCart::curr());
 }
开发者ID:burnbright,项目名称:silverstripe-shop,代码行数:11,代码来源:ShopMemberTest.php

示例11: setUp

 public function setUp()
 {
     parent::setUp();
     ShopTest::setConfiguration();
     Order::config()->modifiers = array("FlatTaxModifier");
     FlatTaxModifier::config()->name = "GST";
     FlatTaxModifier::config()->rate = 0.15;
     $this->cart = ShoppingCart::singleton();
     $this->mp3player = $this->objFromFixture('Product', 'mp3player');
     $this->mp3player->publish('Stage', 'Live');
 }
开发者ID:burnbright,项目名称:silverstripe-shop,代码行数:11,代码来源:FlatTaxModifierTest.php

示例12: testItem

 public function testItem()
 {
     $this->assertFalse($this->tshirt->IsInCart(), "tshirt is not in cart");
     $item = $this->tshirt->Item();
     $this->assertEquals(1, $item->Quantity);
     $this->assertEquals(0, $item->ID);
     $sc = ShoppingCart::singleton();
     $sc->add($this->tshirt, 15);
     $this->assertTrue($this->tshirt->IsInCart(), "tshirt is in cart");
     $item = $this->tshirt->Item();
     $this->assertEquals(15, $item->Quantity);
 }
开发者ID:helpfulrobot,项目名称:silvershop-core,代码行数:12,代码来源:ProductTest.php

示例13: addtocart

 public function addtocart($data, $form)
 {
     if ($buyable = $this->getBuyable($data)) {
         $cart = ShoppingCart::singleton();
         $saveabledata = !empty($this->saveablefields) ? Convert::raw2sql(array_intersect_key($data, array_combine($this->saveablefields, $this->saveablefields))) : $data;
         $quantity = isset($data['Quantity']) ? (int) $data['Quantity'] : 1;
         $cart->add($buyable, $quantity, $saveabledata);
         if (!ShoppingCart_Controller::config()->direct_to_cart_page) {
             $form->SessionMessage($cart->getMessage(), $cart->getMessageType());
         }
         ShoppingCart_Controller::direct($cart->getMessageType());
     }
 }
开发者ID:8secs,项目名称:cocina,代码行数:13,代码来源:AddProductForm.php

示例14: setUp

 public function setUp()
 {
     parent::setUp();
     ShopTest::setConfiguration();
     $this->mp3player = $this->objFromFixture('Product', 'mp3player');
     $this->mp3player->publish('Stage', 'Live');
     $this->socks = $this->objFromFixture('Product', 'socks');
     $this->socks->publish('Stage', 'Live');
     $this->beachball = $this->objFromFixture('Product', 'beachball');
     $this->beachball->publish('Stage', 'Live');
     $this->checkoutcontroller = new CheckoutPage_Controller();
     ShoppingCart::singleton()->add($this->socks);
     //start cart
 }
开发者ID:helpfulrobot,项目名称:silvershop-core,代码行数:14,代码来源:CheckoutFormTest.php

示例15: setUp

 public function setUp()
 {
     parent::setUp();
     ShopTest::setConfiguration();
     $this->mp3player = $this->objFromFixture('Product', 'mp3player');
     $this->socks = $this->objFromFixture('Product', 'socks');
     $this->beachball = $this->objFromFixture('Product', 'beachball');
     $this->hdtv = $this->objFromFixture('Product', 'hdtv');
     $this->mp3player->publish('Stage', 'Live');
     $this->socks->publish('Stage', 'Live');
     $this->beachball->publish('Stage', 'Live');
     $this->hdtv->publish('Stage', 'Live');
     $this->shoppingcart = ShoppingCart::singleton();
 }
开发者ID:helpfulrobot,项目名称:silvershop-core,代码行数:14,代码来源:OrderProcessorTest.php


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