本文整理汇总了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());
}
示例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;
}
示例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();
}
示例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());
}
示例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;
}
示例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;
}