本文整理汇总了PHP中ShoppingCart::has_items方法的典型用法代码示例。如果您正苦于以下问题:PHP ShoppingCart::has_items方法的具体用法?PHP ShoppingCart::has_items怎么用?PHP ShoppingCart::has_items使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShoppingCart
的用法示例。
在下文中一共展示了ShoppingCart::has_items方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processOrder
/**
* Process the items in the shopping cart from session,
* creating a new {@link Order} record, and updating the
* customer's details {@link Member} record.
*
* {@link Payment} instance is created, linked to the order,
* and payment is processed {@link Payment::processPayment()}
*
* @param array $data Form request data submitted from OrderForm
* @param Form $form Form object for this action
* @param HTTPRequest $request Request object for this action
*/
function processOrder($data, $form, $request)
{
$paymentClass = !empty($data['PaymentMethod']) ? $data['PaymentMethod'] : null;
$payment = class_exists($paymentClass) ? new $paymentClass() : null;
if (!($payment && $payment instanceof Payment)) {
user_error(get_class($payment) . ' is not a valid Payment object!', E_USER_ERROR);
}
if (!ShoppingCart::has_items()) {
$form->sessionMessage('Please add some items to your cart', 'bad');
Director::redirectBack();
return false;
}
// Create new OR update logged in {@link Member} record
$member = EcommerceRole::createOrMerge($data);
if (!$member) {
$form->sessionMessage(_t('OrderForm.MEMBEREXISTS', 'Sorry, a member already exists with that email address.
If this is your email address, please log in first before placing your order.'), 'bad');
Director::redirectBack();
return false;
}
$member->write();
$member->logIn();
// Create new Order from shopping cart, discard cart contents in session
$order = ShoppingCart::save_current_order();
ShoppingCart::clear();
// Write new record {@link Order} to database
$form->saveInto($order);
$order->write();
// Save payment data from form and process payment
$form->saveInto($payment);
$payment->OrderID = $order->ID;
$payment->Amount = $order->Total();
$payment->write();
// Process payment, get the result back
$result = $payment->processPayment($data, $form);
// isProcessing(): Long payment process redirected to another website (PayPal, Worldpay)
if ($result->isProcessing()) {
return $result->getValue();
}
if ($result->isSuccess()) {
$order->sendReceipt();
}
Director::redirect($order->Link());
return true;
}
示例2: processOrder
/**
* Process the items in the shopping cart from session,
* creating a new {@link Order} record, and updating the
* customer's details {@link Member} record.
*
* {@link Payment} instance is created, linked to the order,
* and payment is processed {@link Payment::processPayment()}
*
* @param array $data Form request data submitted from OrderForm
* @param Form $form Form object for this action
* @param HTTPRequest $request Request object for this action
*/
function processOrder($data, $form, $request)
{
$paymentClass = !empty($data['PaymentMethod']) ? $data['PaymentMethod'] : null;
$payment = class_exists($paymentClass) ? new $paymentClass() : null;
if (!($payment && $payment instanceof Payment)) {
user_error(get_class($payment) . ' is not a valid Payment object!', E_USER_ERROR);
//TODO: be more graceful with errors
}
$this->saveDataToSession($data);
//save for later if necessary
//check for cart items
if (!ShoppingCart::has_items()) {
$form->sessionMessage(_t('OrderForm.NoItemsInCart', 'Please add some items to your cart'), 'bad');
Director::redirectBack();
return false;
}
//check that price hasn't changed
$oldtotal = ShoppingCart::current_order()->Total();
// Create new Order from shopping cart, discard cart contents in session
$order = ShoppingCart::current_order();
if ($order->Total() != $oldtotal) {
$form->sessionMessage(_t('OrderForm.PriceUpdated', 'The order price has been updated'), 'warning');
Director::redirectBack();
return false;
}
$member = Member::currentUser();
if (!$member) {
if (self::$user_membership_optional) {
if ($this->userWantsToBecomeMember($data, $form)) {
$member = EcommerceRole::ecommerce_create_or_merge($data);
}
//otherwise we assume they don't want to become a member
} elseif (self::$force_membership) {
//create member
$member = EcommerceRole::ecommerce_create_or_merge($data);
}
}
//if they are a member, or if they have filled out the member fields (password, save my details)
// Create new OR update logged in {@link Member} record
if ($member === false) {
$form->sessionMessage(_t('OrderForm.MEMBEREXISTS', 'Sorry, a member already exists with that email address.
If this is your email address, please log in first before placing your order.' . ' <a href="Security/lostpassword">Recover password.</a>'), 'bad');
Director::redirectBack();
return false;
}
//assiciate member with order, if there is a member now
if ($member) {
$member->write();
$member->logIn();
if ($member) {
$payment->PaidByID = $member->ID;
}
$order->MemberID = $member->ID;
}
// Write new record {@link Order} to database
$form->saveInto($order);
$order->save();
//sets status to 'Unpaid' //is it even necessary to have it's own function? ..just legacy code.
$this->clearSessionData();
//clears the stored session form data that might have been needed if validation failed
// Save payment data from form and process payment
$form->saveInto($payment);
$payment->OrderID = $order->ID;
$payment->PaidForID = $order->ID;
$payment->PaidForClass = $order->class;
$payment->Amount->Amount = $order->Total();
$payment->write();
//prepare $data - ie put into the $data array any fields that may need to be there for payment
// Process payment, get the result back
$result = $payment->processPayment($data, $form);
// isProcessing(): Long payment process redirected to another website (PayPal, Worldpay)
if ($result->isProcessing()) {
return $result->getValue();
}
if ($result->isSuccess()) {
$order->sendReceipt();
}
Director::redirect($order->Link());
return true;
}