|
<?php |
|
/** |
|
* ShoppingCart - provides a global way to interface with the cart (current order). |
|
* |
|
* This can be used in other code by calling $cart = ShoppingCart::singleton(); |
|
* |
|
* |
|
* This version of shopping cart has been rewritten to: |
|
* - Seperate controller from the cart functions, abstracts out and encapsulates specific functionality. |
|
* - Reduce the excessive use of static variables. |
|
* - Clearly define an API for editing the cart, trying to keep the number of functions to a minimum. |
|
* - Allow easier testing of cart functionality. |
|
* - Message handling done in one place. |
|
* This is not taking a step backward, be cause the old ShoppingCart / Controller seperation had all static variables/functions on ShoppingCart |
|
* |
|
* Note: an alternative might be to provide this functionality on the Order class. |
|
* The shopping cart would then act as a controller interface for modifying the order. |
|
* |
|
* |
|
* @author: Jeremy Shipman, Nicolaas Francken |
|
* @package: ecommerce |
|
* |
|
* @todo support buyable |
|
* @todo country selection |
|
* @todo modifiers |
|
* @todo order item parameters |
|
* @todo produce errors |
|
* @todo handle rendering? |
|
* @todo handle setting quantity |
|
*/ |
|
class ShoppingCart extends Object{ |
|
|
|
protected static $session_variable = "EcommerceShoppingCart"; //used for setting/getting cart things from the session |
|
|
|
protected static $current_order = null; //stores a reference to the current order object |
|
protected static function get_order(){ |
|
//get or make an order |
|
//store order id in session |
|
} |
|
|
|
/** |
|
* This is how you can get the cart from anywhere in code. |
|
* @return ShoppingCart Object |
|
*/ |
|
protected static $singletoncart = null; |
|
static function get(){ //could call this 'get' or something else that is short |
|
if(!self::$singletoncart){ |
|
self::$singletoncart = new ShoppingCart(); |
|
} |
|
return self::$singletoncart; |
|
} |
|
|
|
/** |
|
* Adds any number of items to the cart. |
|
* @param $buyable - the buyable (generally a product) being added to the cart. |
|
* @param $quantity - number of items add. |
|
* @param $parameters - array of parameters to target a specific order item. eg: group=1, length=5 |
|
* @return the new item or null |
|
*/ |
|
function addItem($buyable,$quantity = 1, $parameters = null){ |
|
//find existing order item or make one |
|
//check that that number can be added |
|
//save to current order |
|
|
|
} |
|
|
|
/** |
|
* Removes any number of items from the cart. |
|
* @return boolean - successfully removed |
|
*/ |
|
function removeItem($buyable,$quantity = 1, $parameters = null){ |
|
//check for existence of item |
|
if($quantity == 'all' || $quantity <= 0){ |
|
//remove all items with $productid from the current order |
|
} |
|
//otherwise only remove $quantity |
|
|
|
} |
|
|
|
/** |
|
* Clears the cart contents completely by removing the orderID from session, and thus creating a new cart on next request. |
|
*/ |
|
function clear(){ |
|
//simply clear the orderid from session |
|
} |
|
|
|
/** |
|
* Helper function for making / retrieving order items. |
|
*/ |
|
protected function findOrMakeItem($productid,$parameters){ |
|
//check for product existence & permission to do stuff |
|
} |
|
|
|
|
|
/** |
|
* Stores a message that can later be returned via ajax or to $form->sessionMessage(); |
|
* @param $message - the message, which could be a notification of successful action, or reason for failure |
|
* @param $type - please use good, bad, warning |
|
*/ |
|
protected function message($message, $type = 'good'){ |
|
|
|
} |
|
|
|
/** |
|
* Retrieves all good, bad, and ugly messages that have been produced during the current request. |
|
* @return array of messages |
|
*/ |
|
function getMessages(){ |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
* ShoppingCart_Controller |
|
* |
|
* Handles the modification of a shopping cart via http requests. |
|
* Provides links for making these modifications. |
|
* |
|
* @author: Jeremy Shipman, Nicolaas Francken |
|
* @package: ecommerce |
|
* |
|
* @todo supply links for adding, removing, and clearing cart items |
|
* @todo link for removing modifier(s) |
|
*/ |
|
class ShoppingCart_Controller extends Object{ |
|
|
|
} |