本文整理汇总了PHP中ShoppingCart::curr方法的典型用法代码示例。如果您正苦于以下问题:PHP ShoppingCart::curr方法的具体用法?PHP ShoppingCart::curr怎么用?PHP ShoppingCart::curr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShoppingCart
的用法示例。
在下文中一共展示了ShoppingCart::curr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkoutconfig
protected function checkoutconfig()
{
$config = new CheckoutComponentConfig(ShoppingCart::curr(), true);
$config->addComponent($comp = new CouponCheckoutComponent());
$comp->setValidWhenBlank(true);
return $config;
}
示例2: Cart
/**
* Get the cart, and do last minute calculation if necessary.
*/
public function Cart()
{
$order = ShoppingCart::curr();
if (!$order || !$order->Items() || !$order->Items()->exists()) {
return false;
}
return $order;
}
示例3: onAfterInit
/**
* Redirect back to start of checkout if no cart started
*/
public function onAfterInit()
{
$action = $this->owner->getRequest()->param('Action');
$steps = $this->getSteps();
if (!ShoppingCart::curr() && !empty($action) && isset($steps[$action])) {
Controller::curr()->redirect($this->owner->Link());
return;
}
}
示例4: ConfirmationForm
public function ConfirmationForm()
{
$config = new CheckoutComponentConfig(ShoppingCart::curr(), false);
$config->addComponent(new NotesCheckoutComponent());
$config->addComponent(new TermsCheckoutComponent());
$form = new PaymentForm($this->owner, "ConfirmationForm", $config);
$form->setFailureLink($this->owner->Link('summary'));
$this->owner->extend('updateConfirmationForm', $form);
return $form;
}
示例5: 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());
}
示例6: updatecart
/**
* Update the cart using data collected
*/
public function updatecart($data, $form)
{
$items = $this->cart->Items();
$updatecount = $removecount = 0;
$request = $this->getRequest();
$order = ShoppingCart::curr();
if ($request && $request->isAjax() && $order) {
ShopTools::install_locale($order->Locale);
}
$messages = array();
if (isset($data['Items']) && is_array($data['Items'])) {
foreach ($data['Items'] as $itemid => $fields) {
$item = $items->byID($itemid);
if (!$item) {
continue;
}
//delete lines
if (isset($fields['Remove']) || isset($fields['Quantity']) && (int) $fields['Quantity'] <= 0) {
$items->remove($item);
$removecount++;
continue;
}
//update quantities
if (isset($fields['Quantity']) && ($quantity = Convert::raw2sql($fields['Quantity']))) {
$item->Quantity = $quantity;
}
//update variations
if (isset($fields['ProductVariationID']) && ($id = Convert::raw2sql($fields['ProductVariationID']))) {
if ($item->ProductVariationID != $id) {
$item->ProductVariationID = $id;
}
}
//TODO: make updates through ShoppingCart class
//TODO: combine with items that now match exactly
//TODO: validate changes
if ($item->isChanged()) {
$item->write();
$updatecount++;
}
}
}
if ($removecount) {
$messages['remove'] = _t('CartForm.REMOVED_ITEMS', "Removed {count} items.", "count is the amount that was removed", array('count' => $removecount));
}
if ($updatecount) {
$messages['updatecount'] = _t('CartForm.UPDATED_ITEMS', "Updated {count} items.", "count is the amount that was updated", array('count' => $updatecount));
}
if (count($messages)) {
$form->sessionMessage(implode(" ", $messages), "good");
}
$this->extend('updateCartFormResponse', $request, $response, $form);
return $response ? $response : $this->controller->redirectBack();
}
示例7: registerconfig
public function registerconfig()
{
$order = ShoppingCart::curr();
//hack to make components work when there is no order
if (!$order) {
$order = Order::create();
}
$config = new CheckoutComponentConfig($order, false);
$config->addComponent(new CustomerDetailsCheckoutComponent());
$config->addComponent(new MembershipCheckoutComponent());
return $config;
}
示例8: get
public static function get($order = null)
{
if ($order === null) {
$order = ShoppingCart::curr();
//roll back to current cart
}
if ($order->exists() && $order->isInDB()) {
//check if order can go through checkout
return new Checkout($order);
}
return false;
}
示例9: ContactDetailsForm
public function ContactDetailsForm()
{
$cart = ShoppingCart::curr();
if (!$cart) {
return false;
}
$config = new CheckoutComponentConfig(ShoppingCart::curr());
$config->addComponent(CustomerDetailsCheckoutComponent::create());
$form = CheckoutForm::create($this->owner, 'ContactDetailsForm', $config);
$form->setRedirectLink($this->NextStepLink());
$form->setActions(FieldList::create(FormAction::create("checkoutSubmit", _t('CheckoutStep.Continue', "Continue"))));
$this->owner->extend('updateContactDetailsForm', $form);
return $form;
}
示例10: onBeforeInit
/**
* Global setup
*/
public function onBeforeInit()
{
Requirements::css('shop_livepub/css/shoplivepub.css');
LivePubHelper::add_template_path('shop_livepub/templates/php');
if (!empty($_REQUEST['flushsessioncart']) || !empty($_REQUEST['flush'])) {
$cart = ShoppingCart::curr();
if ($cart) {
$cart->rebuildSessionCart();
}
}
if (!empty($_REQUEST['debugsessioncart'])) {
Debug::dump(Session::get('Cart'));
}
}
示例11: testCheckoutForm
public function testCheckoutForm()
{
$order = ShoppingCart::curr();
$config = new SinglePageCheckoutComponentConfig($order);
$form = new CheckoutForm($this->checkoutcontroller, "OrderForm", $config);
$data = array("CustomerDetailsCheckoutComponent_FirstName" => "Jane", "CustomerDetailsCheckoutComponent_Surname" => "Smith", "CustomerDetailsCheckoutComponent_Email" => "janesmith@example.com", "ShippingAddressCheckoutComponent_Country" => "NZ", "ShippingAddressCheckoutComponent_Address" => "1234 Green Lane", "ShippingAddressCheckoutComponent_AddressLine2" => "Building 2", "ShippingAddressCheckoutComponent_City" => "Bleasdfweorville", "ShippingAddressCheckoutComponent_State" => "Trumpo", "ShippingAddressCheckoutComponent_PostalCode" => "4123", "ShippingAddressCheckoutComponent_Phone" => "032092277", "BillingAddressCheckoutComponent_Country" => "NZ", "BillingAddressCheckoutComponent_Address" => "1234 Green Lane", "BillingAddressCheckoutComponent_AddressLine2" => "Building 2", "BillingAddressCheckoutComponent_City" => "Bleasdfweorville", "BillingAddressCheckoutComponent_State" => "Trumpo", "BillingAddressCheckoutComponent_PostalCode" => "4123", "BillingAddressCheckoutComponent_Phone" => "032092277", "PaymentCheckoutComponent_PaymentMethod" => "Dummy", "NotesCheckoutComponent_Notes" => "Leave it around the back", "TermsCheckoutComponent_ReadTermsAndConditions" => "1");
$form->loadDataFrom($data, true);
$valid = $form->validate();
$errors = $form->getValidator()->getErrors();
$this->assertTrue($valid);
$form->checkoutSubmit($data, $form);
$this->assertEquals("Jane", $order->FirstName);
$shipping = $order->ShippingAddress();
$this->assertEquals("NZ", $shipping->Country);
$this->assertEquals("Cart", $order->Status);
$this->markTestIncomplete('test invalid data');
$this->markTestIncomplete('test components individually');
}
示例12: updateGroupCartResponse
/**
* @param SS_HTTPRequest $request
* @param AjaxHTTPResponse $response
* @param GroupedProduct $groupedProduct
* @param array $data
* @param GroupedCartForm $form [optional]
*/
public function updateGroupCartResponse(&$request, &$response, $groupedProduct, $data, $form = null)
{
if ($request->isAjax() && $this->owner->getController()->hasExtension('AjaxControllerExtension')) {
if (!$response) {
$response = $this->owner->getController()->getAjaxResponse();
}
$this->setupRenderContexts($response, $groupedProduct, $form);
// Because ShoppingCart::current() calculates the order once and
// then remembers the total, and that was called BEFORE the product
// was added, we need to recalculate again here. Under non-ajax
// requests the redirect eliminates the need for this but under
// ajax the total lags behind the subtotal without this.
$order = ShoppingCart::curr();
$order->calculate();
$response->pushRegion('SideCart', $this->owner->getController());
$response->triggerEvent('cartadd');
$response->triggerEvent('cartchange', array('action' => 'add'));
}
}
示例13: testCheckoutFormForSingleCountrySiteWithReadonlyFieldsForCountry
public function testCheckoutFormForSingleCountrySiteWithReadonlyFieldsForCountry()
{
// Set as a single country site
$this->loadFixture("shop/tests/fixtures/singlecountry.yml");
$singlecountry = SiteConfig::current_site_config();
$this->assertEquals("NZ", $singlecountry->getSingleCountry(), "Confirm that website is setup as a single country site");
$order = ShoppingCart::curr();
$config = new SinglePageCheckoutComponentConfig($order);
$form = new CheckoutForm($this->checkoutcontroller, "OrderForm", $config);
// no country fields due to readonly field
$dataCountryAbsent = array("CustomerDetailsCheckoutComponent_FirstName" => "Jane", "CustomerDetailsCheckoutComponent_Surname" => "Smith", "CustomerDetailsCheckoutComponent_Email" => "janesmith@example.com", "ShippingAddressCheckoutComponent_Address" => "1234 Green Lane", "ShippingAddressCheckoutComponent_AddressLine2" => "Building 2", "ShippingAddressCheckoutComponent_City" => "Bleasdfweorville", "ShippingAddressCheckoutComponent_State" => "Trumpo", "ShippingAddressCheckoutComponent_PostalCode" => "4123", "ShippingAddressCheckoutComponent_Phone" => "032092277", "BillingAddressCheckoutComponent_Address" => "1234 Green Lane", "BillingAddressCheckoutComponent_AddressLine2" => "Building 2", "BillingAddressCheckoutComponent_City" => "Bleasdfweorville", "BillingAddressCheckoutComponent_State" => "Trumpo", "BillingAddressCheckoutComponent_PostalCode" => "4123", "BillingAddressCheckoutComponent_Phone" => "032092277", "PaymentCheckoutComponent_PaymentMethod" => "Dummy", "NotesCheckoutComponent_Notes" => "Leave it around the back", "TermsCheckoutComponent_ReadTermsAndConditions" => "1");
$form->loadDataFrom($dataCountryAbsent, true);
$valid = $form->validate();
$errors = $form->getValidator()->getErrors();
$this->assertTrue($valid, print_r($errors, true));
$this->assertTrue($form->Fields()->fieldByName("ShippingAddressCheckoutComponent_Country_readonly")->isReadonly(), "Shipping Address Country field is readonly");
$this->assertTrue($form->Fields()->fieldByName("BillingAddressCheckoutComponent_Country_readonly")->isReadonly(), "Billing Address Country field is readonly");
$form->checkoutSubmit($dataCountryAbsent, $form);
$shipping = $order->ShippingAddress();
$this->assertEquals("NZ", $shipping->Country);
$billing = $order->BillingAddress();
$this->assertEquals("NZ", $billing->Country);
}
示例14: CouponForm
public function CouponForm()
{
if ($cart = ShoppingCart::curr()) {
return new CouponForm($this->owner, "CouponForm", $cart);
}
}
示例15: testCartSingleton
public function testCartSingleton()
{
$this->assertTrue((bool) $this->cart->add($this->product), "add one item");
$order = $this->cart->current();
$this->assertEquals($order->ID, ShoppingCart::curr()->ID, "if singleton order ids will match");
}