|
Shop_CheckoutData class
Contains information collected during the checkout process.
The class acts as an internal checkout data storage. It has methods for setting and loading the checkout information,
along with a method for placing a new order. It allows to implement custom checkout scenarios. The default actions
use this class internally.
See AlsoPublic methods
Method details¶ calculate_totals() methodpublic static mixed calculate_totals(string $cart_name='main')
Returns checkout totals information.
The information is calculated basing on the checkout data set with
set_billing_info(),
set_shipping_info(),
set_shipping_method(),
set_payment_method() methods or basing on default
values if possible.
The method returns an object with the following fields:
¶ copy_billing_to_shipping() methodpublic static void copy_billing_to_shipping()
Copies the billing address information into the shipping address information.
¶ display_prices_incl_tax() methodpublic static boolean display_prices_incl_tax(Shop_Order $order=NULL)
Determines whether prices should be displayed with taxes included.
Use this method to determine whether prices should be displayed with tax included
in tax inclusive environments.
By default the method loads the customer's location from the currently logged in customer,
but if the $order parameter is provided, the customer data is loaded from that object.
¶ flatten_shipping_options() methodpublic static array flatten_shipping_options(array $shipping_options)
Converts multi-option shipping options to single-option options.
Flat shipping option lists simplify front-end coding.
¶ get_billing_info() methodpublic static Shop_CheckoutAddressInfo get_billing_info()
Returns the billing address information.
If the billing address information is not set in the checkout data,
it can be loaded from the default shipping location.
See Also¶ get_cart_id() methodpublic static string get_cart_id()
Returns the shopping cart content identifier saved in the beginning of the checkout process.
Comparing the result of this method with the result of the Shop_Cart::get_content_id() allows
to recognize whether the shopping cart content was changed during the checkout process.
See Also¶ get_coupon_code() methodpublic static string get_coupon_code()
Returns a coupon code previously set with set_coupon_code() method.
¶ get_customer_notes() methodpublic static string get_customer_notes()
Returns the customer notes string previously set with set_customer_notes() method.
¶ get_payment_method() methodpublic static mixed get_payment_method()
Returns a payment method information previously set with set_payment_method() method.
The method returns an object with the following fields:
¶ get_shipping_info() methodpublic static Shop_CheckoutAddressInfo get_shipping_info()
Returns the shipping address information.
If the shipping address information is not set in the checkout data,
it can be loaded from the default shipping location.
See Also¶ get_shipping_method() methodpublic static mixed get_shipping_method()
Returns a shipping method information previously set with set_shipping_method() method.
The method returns an object with the following fields:
¶ list_available_shipping_options() methodpublic static array list_available_shipping_options(Shop_Customer $customer, string $cart_name='main')
Returns a list of available shipping methods.
The list of available shipping methods is based on the customer's shipping location
and the cart contents. The method returns a list of Shop_ShippingOption objects. The Shop_ShippingOption
class has the following properties which are required for displaying a list of available options:
See Also¶ load_from_customer() methodpublic static void load_from_customer(Shop_Customer $customer, boolean $force=false)
Loads shipping and billing address information from a customer object.
By default this method doesn't update the address information if it
has already been set in the checkout data object. Pass TRUE value
to the $force parameter to override any existing data.
¶ place_order() methodpublic static Shop_Order place_order(Shop_Customer $customer, boolean $register_customer=false, string $cart_name='main', boolean $empty_cart=true)
Creates a new order order.
The checkout information must be prepared with
set_billing_info(),
set_shipping_info(),
set_shipping_method(),
set_payment_method() methods before this method is called.
¶ reset_all() methodpublic static void reset_all()
Removes any checkout data from the session.
¶ reset_shipping_method() methodpublic static void reset_shipping_method()
Deletes the shipping method information from the checkout data.
¶ set_billing_info() methodpublic static void set_billing_info(Shop_Customer $customer, Shop_CheckoutAddressInfo $info=NULL)
Sets billing address information from POST fields or from Shop_CheckoutAddressInfo object.
If the $info parameter is empty, the address information is
loaded from POST data using Shop_CheckoutAddressInfo::set_from_post() method.
If the $info parameter is not empty, the data is loaded from it.
¶ set_coupon_code() methodpublic static void set_coupon_code(string $code)
Sets a specific coupon code.
This method doesn't checks whether the coupon code exists or valid.
¶ set_customer_notes() methodpublic static void set_customer_notes(string $notes)
Sets customer notes string.
Customer notes are saved to the order record.
¶ set_payment_method() methodpublic static void set_payment_method(integer $payment_method_id=NULL)
Sets a payment method.
You can use the Shop_PaymentMethod::find_by_api_code() method for finding a specific payment method.
Shop_CheckoutData::set_payment_method(Shop_PaymentMethod::find_by_api_code('card')->id); ¶ set_shipping_info() methodpublic static void set_shipping_info(Shop_CheckoutAddressInfo $info=NULL)
Sets shipping address information from POST fields or from Shop_CheckoutAddressInfo object.
If the $info parameter is empty, the address information is
loaded from POST data using Shop_CheckoutAddressInfo::set_from_post() method.
If the $info parameter is not empty, the data is loaded from it.
¶ set_shipping_location() methodpublic static void set_shipping_location(integer $country_id, integer $state_id, string $zip)
Sets shipping country, state and ZIP/postal code.
This method allows to override the shipping
country, state and ZIP/postal code components of the shipping address.
¶ set_shipping_method() methodpublic static void set_shipping_method(string $shipping_method_id=NULL, string $cart_name='main')
Sets a shipping method.
You can use the Shop_ShippingOption::find_by_api_code() method for finding a specific shipping method.
Shop_CheckoutData::set_shipping_method(Shop_ShippingOption::find_by_api_code('default')->id); See Also¶ shipping_required() methodpublic static boolean shipping_required(string $cart_name='main')
Determines whether the shopping cart contains any shippable items.
By default shippable items are those items which belong to the Goods product type.
If the cart contains only downloadable or service-type products the method returns FALSE.
|