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


PHP Cart::get_current_order方法代码示例

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


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

示例1: testCheckoutWithoutPaymentGateway

 /**
  * Try checking out an order without specifying a payment gateway
  */
 function testCheckoutWithoutPaymentGateway()
 {
     $productA = $this->objFromFixture('Product', 'productA');
     $this->loginAs('admin');
     $productA->doPublish();
     $this->logOut();
     $buyer = $this->objFromFixture('Customer', 'buyer');
     $this->assertEquals(1, $buyer->Orders()->Count());
     $this->loginAs($this->objFromFixture('Customer', 'buyer'));
     $productALink = $productA->Link();
     $this->get(Director::makeRelative($productALink));
     $this->submitForm('ProductForm_ProductForm', null, array('Quantity' => 1));
     $order = Cart::get_current_order();
     $items = $order->Items();
     $this->assertEquals(1, $items->Count());
     $checkoutPage = DataObject::get_one('CheckoutPage');
     $this->get(Director::makeRelative($checkoutPage->Link()));
     //Submit the form without restrictions on what can be POST'd
     $data = $this->getFormData('OrderForm_OrderForm');
     $data['PaymentMethod'] = '';
     $this->post(Director::absoluteURL('/checkout/OrderForm'), $data);
     $this->assertEquals(1, $buyer->Orders()->Count());
 }
开发者ID:vinstah,项目名称:body,代码行数:26,代码来源:CheckoutTest.php

示例2: validate

 /**
  * Validate this field, check that the current {@link Item} is in the current 
  * {@Link Order} and is valid for adding to the cart.
  * 
  * @see FormField::validate()
  * @return Boolean
  */
 function validate($validator)
 {
     $valid = true;
     $item = $this->Item();
     $currentOrder = Cart::get_current_order();
     $items = $currentOrder->Items();
     $quantity = $this->Value();
     $removingItem = false;
     if ($quantity <= 0) {
         $removingItem = true;
     }
     //Check that item exists and is in the current order
     if (!$item || !$item->exists() || !$items->find('ID', $item->ID)) {
         $errorMessage = _t('Form.ITEM_IS_NOT_IN_ORDER', 'This product is not in the Cart.');
         if ($msg = $this->getCustomValidationMessage()) {
             $errorMessage = $msg;
         }
         $validator->validationError($this->getName(), $errorMessage, "error");
         $valid = false;
     } else {
         if ($item) {
             //If removing item, cannot subtract past 0
             if ($removingItem) {
                 if ($quantity < 0) {
                     $errorMessage = _t('Form.ITEM_QUANTITY_LESS_ONE', 'The quantity must be at least 0');
                     if ($msg = $this->getCustomValidationMessage()) {
                         $errorMessage = $msg;
                     }
                     $validator->validationError($this->getName(), $errorMessage, "error");
                     $valid = false;
                 }
             } else {
                 //If quantity is invalid
                 if ($quantity == null || !is_numeric($quantity)) {
                     $errorMessage = _t('Form.ITEM_QUANTITY_INCORRECT', 'The quantity must be a number');
                     if ($msg = $this->getCustomValidationMessage()) {
                         $errorMessage = $msg;
                     }
                     $validator->validationError($this->getName(), $errorMessage, "error");
                     $valid = false;
                 } else {
                     if ($quantity > 2147483647) {
                         $errorMessage = _t('Form.ITEM_QUANTITY_INCORRECT', 'The quantity must be less than 2,147,483,647');
                         if ($msg = $this->getCustomValidationMessage()) {
                             $errorMessage = $msg;
                         }
                         $validator->validationError($this->getName(), $errorMessage, "error");
                         $valid = false;
                     }
                 }
                 $validation = $item->validateForCart();
                 if (!$validation->valid()) {
                     $errorMessage = $validation->message();
                     if ($msg = $this->getCustomValidationMessage()) {
                         $errorMessage = $msg;
                     }
                     $validator->validationError($this->getName(), $errorMessage, "error");
                     $valid = false;
                 }
             }
         }
     }
     return $valid;
 }
开发者ID:vinstah,项目名称:body,代码行数:71,代码来源:CartForm.php

示例3: add

 /**
  * Add an item to the current cart ({@link Order}) for a given {@link Product}.
  * 
  * @param Array $data
  * @param Form $form
  */
 public function add(array $data, Form $form)
 {
     Cart::get_current_order(true)->addItem($this->getProduct(), $this->getVariation(), $this->getQuantity(), $this->getOptions());
     //Show feedback if redirecting back to the Product page
     if (!$this->getRequest()->requestVar('Redirect')) {
         $cartPage = DataObject::get_one('CartPage');
         $message = _t('ProductForm.PRODUCT_ADDED', 'The product was added to your cart.');
         if ($cartPage->exists()) {
             $message = _t('ProductForm.PRODUCT_ADDED_LINK', 'The product was added to {openanchor}your cart{closeanchor}.', array('openanchor' => "<a href=\"{$cartPage->Link()}\">", 'closeanchor' => "</a>"));
         }
         $form->sessionMessage(DBField::create_field("HTMLText", $message), 'good');
     }
     $this->goToNextPage();
 }
开发者ID:vinstah,项目名称:body,代码行数:20,代码来源:ProductForm.php

示例4: testAddNonPublishedProductToCart

 /**
  * Adding non published product to a cart should fail
  */
 public function testAddNonPublishedProductToCart()
 {
     $productA = $this->objFromFixture('Product', 'productA');
     $this->assertEquals(false, $productA->isPublished());
     $productALink = $productA->Link();
     $this->get(Director::makeRelative($productALink));
     $message = null;
     try {
         $this->submitForm('ProductForm_ProductForm', null, array('Quantity' => 1));
     } catch (Exception $e) {
         $message = $e->getMessage();
     }
     $this->assertStringEndsWith('Object not written.', $message);
     $order = Cart::get_current_order();
     $items = $order->Items();
     $this->assertEquals(0, $items->Count());
 }
开发者ID:vinstah,项目名称:body,代码行数:20,代码来源:CartTest.php

示例5: OrderForm

 function OrderForm()
 {
     $order = Cart::get_current_order();
     $member = Customer::currentUser() ? Customer::currentUser() : singleton('Customer');
     $form = OrderForm::create($this, 'OrderForm')->disableSecurityToken();
     //Populate fields the first time form is loaded
     $form->populateFields();
     return $form;
 }
开发者ID:vinstah,项目名称:body,代码行数:9,代码来源:CheckoutPage.php

示例6: validate

 /**
  * Validate this form field, make sure the {@link Item} exists, is in the current 
  * {@link Order} and the item is valid for adding to the cart.
  * 
  * @see FormField::validate()
  * @return Boolean
  */
 public function validate($validator)
 {
     $valid = true;
     $item = $this->Item();
     $currentOrder = Cart::get_current_order();
     $items = $currentOrder->Items();
     //Check that item exists and is in the current order
     if (!$item || !$item->exists() || !$items->find('ID', $item->ID)) {
         $errorMessage = _t('Form.ITEM_IS_NOT_IN_ORDER', 'This product is not in the Order.');
         if ($msg = $this->getCustomValidationMessage()) {
             $errorMessage = $msg;
         }
         $validator->validationError($this->getName(), $errorMessage, "error");
         $valid = false;
     } else {
         if ($item) {
             $validation = $item->validateForCart();
             if (!$validation->valid()) {
                 $errorMessage = $validation->message();
                 if ($msg = $this->getCustomValidationMessage()) {
                     $errorMessage = $msg;
                 }
                 $validator->validationError($this->getName(), $errorMessage, "error");
                 $valid = false;
             }
         }
     }
     return $valid;
 }
开发者ID:vinstah,项目名称:body,代码行数:36,代码来源:OrderForm.php


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