Sunnysideup\Ecommerce\Api\ShoppingCart
Synopsis
class ShoppingCart
{
- // members
- protected array $messages = ;
- protected null|Order $order;
- protected bool $requireSavedOrder = false;
- private static array $session_variable_names = ;
- private static string $session_code = 'EcommerceShoppingCart';
- private static bool $cleanup_every_time = true;
- private static array $default_param_filters = ;
- private static string $response_class = CartResponse::class;
- private static $_singletoncart;
- private static $_allow_writes_cache;
- // methods
- public static ShoppingCart singleton()
- public static Order current_order()
- public static void reset_order_reference()
- public static int; current_order_id()
- public static void session_order()
- public Order setOrder()
- public Order currentOrder()
- public string Link()
- public bool|OrderItem addBuyable()
- public bool|OrderItem setQuantity()
- public bool|OrderItem decrementBuyable()
- public bool|OrderItem deleteBuyable()
- public DataObject prepareOrderItem()
- public float prepareQuantity()
- public bool|OrderItem findOrMakeItem()
- public bool submit()
- public null|bool save()
- public bool clear()
- public void reset()
- public null|bool removeModifier()
- public bool addModifier()
- public bool loadOrder()
- public null|false|Order copyOrder()
- public Order CopyOrderOnly()
- public Order CopyBuyablesToNewOrder()
- public bool setCountry()
- public bool setRegion()
- public bool setCurrency()
- public void debug()
- public void addMessage()
- public array getMessages()
- public void setMessageAndReturn()
- protected bool allowWrites()
- protected null|OrderItem getExistingItem()
- protected array cleanParameters()
- protected void parametersToSQL()
- protected void StoreMessagesInSession()
- protected string sessionVariableName()
Hierarchy
Uses
- SilverStripe\Core\Extensible
- SilverStripe\Core\Injector\Injectable
- SilverStripe\Core\Config\Configurable
Tasks
Line | Task |
---|---|
570+ | : what does this method do??? |
1094 | remove the awkward replace |
1146 | handle passing back multiple messages |
1153 | handle passing a message back to a form->sessionMessage |
Members
private
- $_allow_writes_cache
- $_singletoncart
—
This is where we hold the (singleton) Shoppingcart. - $cleanup_every_time — Sunnysideup\Ecommerce\Api\bool
- $default_param_filters — array
- $response_class — string
- $session_code — string
- $session_variable_names
—
array
List of names that can be used as session variables.
protected
- $messages
—
array
Feedback message to user (e.g. cart updated, could not delete item, someone in standing behind you). - $order
—
Sunnysideup\Ecommerce\Api\null|Order
stores a reference to the current order object. - $requireSavedOrder
—
Sunnysideup\Ecommerce\Api\bool
This variable is set to YES when we actually need an order (i.e. write it).
Methods
protected
- StoreMessagesInSession() — Saves current messages in session for retrieving them later.
- allowWrites() — can the current user use sessions and therefore write to cart??? the method also returns true if an order has explicitely been set.
- cleanParameters() — Removes parameters that aren't in the default array, merges with default parameters, and converts raw2SQL.
- getExistingItem() — Gets an existing order item based on buyable and passed parameters.
- parametersToSQL() — Converts parameter array to SQL query filter.
- sessionVariableName() — Return the name of the session variable that should be used.
public
- CopyBuyablesToNewOrder() — Add buyables into new Order.
- CopyOrderOnly()
- Link() — Allows access to the current order from anywhere in the code..
- addBuyable() — Adds any number of items to the cart.
- addMessage() — Stores a message that can later be returned via ajax or to $form->sessionMessage();.
- addModifier() — Removes a modifier from the cart.
- clear() — Clears the cart contents completely by removing the orderID from session, and thus creating a new cart on next request.
- copyOrder() — NOTE: tried to copy part to the Order Class - but that was not much of a go-er.
- currentOrder() — Gets or creates the current order.
- current_order() — Allows access to the current order from anywhere in the code..
- current_order_id() — looks up current order id.
- debug() — Produces a debug of the shopping cart.
- decrementBuyable() — Removes any number of items from the cart.
- deleteBuyable() — Delete item from the cart.
- findOrMakeItem() — Helper function for making / retrieving order items.
- getMessages() — Retrieves all good, bad, and ugly messages that have been produced during the current request.
- loadOrder() — Sets an order as the current order.
- prepareOrderItem() — Checks and prepares variables for a quantity change (add, edit, remove) for an Order Item.
- prepareQuantity()
- removeModifier() — Removes a modifier from the cart It does not actually remove it, but it just sets it as "removed", to avoid that it is being added again.
- reset() — alias for clear.
- reset_order_reference() — useful when the order has been updated ...
- save() — returns null if the current user does not allow order manipulation or saving (e.g. session disabled).
- session_order() — Allows access to the current order from anywhere in the code..
- setCountry() — sets country in order so that modifiers can be recalculated, etc...
- setCurrency() — sets the display currency for the cart.
- setMessageAndReturn() — This method is used to return data after an ajax call was made.
- setOrder() — set a specific order, other than the one from session ....
- setQuantity() — Sets quantity for an item in the cart.
- setRegion() — sets region in order so that modifiers can be recalculated, etc...
- singleton() — Allows access to the cart from anywhere in code.
- submit() — submit the order so that it is no longer available in the cart but will continue its journey through the order steps.