SilverShop\Cart\ShoppingCart
Encapsulated manipulation of the current order using a singleton pattern.
Ensures that an order is only started (persisted to DB) when necessary,
and all future changes are on the same order, until the order has is placed.
The requirement for starting an order is to adding an item to the cart.
Synopsis
class ShoppingCart
{
- // members
- private static string $cartid_session_name = 'SilverShop.shoppingcartid';
- private Order $order;
- private boolean $calculateonce = false;
- private $message;
- private $type;
- // methods
- public static Order curr()
- public Order current()
- public ShoppingCart setCurrent()
- protected Order findOrMake()
- public boolean|OrderItem add()
- public boolean remove()
- public boolean removeOrderItem()
- public boolean|OrderItem setQuantity()
- public boolean updateOrderItemQuantity()
- private OrderItem findOrMakeItem()
- public OrderItem get()
- public Buyable getCorrectBuyable()
- public void archiveorderid()
- public bool clear()
- protected void error()
- protected void message()
- public void getMessage()
- public void getMessageType()
- public void clearMessage()
- public void __clone()
- public void __wakeup()
Hierarchy
Uses
- SilverStripe\Core\Injector\Injectable
- SilverStripe\Core\Config\Configurable
Tasks
Line | Task |
---|---|
203 | There should be a rollback |
Members
private
- $calculateonce
- $cartid_session_name
- $message
- $order — SilverShop\Model\Order
- $type
Methods
private
- findOrMakeItem() — Finds or makes an order item for a given product + filter.
protected
- error() — Store a new error.
- findOrMake() — Helper that only allows orders to be started internally.
- message() — Store a message to be fed back to user.
public
- __clone()
- __wakeup()
- add() — Adds an item to the cart
- archiveorderid() — Store old cart id in session order history
- clear() — Empty / abandon the entire cart.
- clearMessage()
- curr() — Shortened alias for ShoppingCart::singleton()->current()
- current() — Get the current order, or return null if it doesn't exist.
- get() — Finds an existing order item.
- getCorrectBuyable() — Ensure the proper buyable will be returned for a given buyable… This is being used to ensure a product with variations cannot be added to the cart… a Variation has to be added instead!
- getMessage()
- getMessageType()
- remove() — Remove an item from the cart.
- removeOrderItem() — Remove a specific order item from cart
- setCurrent() — Set the current cart
- setQuantity() — Sets the quantity of an item in the cart.
- updateOrderItemQuantity() — Update quantity of a given order item