The class Basket represents the basket of the customer who wants to buy one or more products: it's intended to be used by User class only. More...
#include <Basket.h>
Public Member Functions | |
Basket () | |
Default constructor. | |
~Basket () | |
Default destructor. | |
bool | addProduct (Product *p, int aQty=1) |
Add product to basket. | |
bool | addProduct (ProductProxy *p, int aQty=1) |
Add product to basket. | |
float | total () const |
Return the total cost of the basket. | |
void | empty () |
Empty the basket. | |
void | removeProduct (Product *p, int aQty=1) |
Remove a product from the basket. | |
int | itemCount () |
Items count. | |
Private Member Functions | |
void | _realAddProduct (int pid, int qty) |
Real add product. | |
Private Attributes | |
float | _tot |
Friends | |
std::ostream & | operator<< (std::ostream &, Basket &) |
The class Basket represents the basket of the customer who wants to buy one or more products: it's intended to be used by User class only.
Basket::~Basket | ( | ) |
Default destructor.
References LOG_DTOR.
void Basket::_realAddProduct | ( | int | pid, | |
int | qty | |||
) | [private] |
Real add product.
This function must not be used directly, but only called by addProduct() - that's why it's private. It adds the chosen product and requested quantity to the map, by first looking for an equal entry: in this case only quantity is increased.
[in] | pid | Product ID to add |
[in] | qty | Requested quantity |
Referenced by addProduct().
bool Basket::addProduct | ( | ProductProxy * | p, | |
int | aQty = 1 | |||
) |
Add product to basket.
Add a product to the basket. It's possibile to specify how many pieces of the same product. A check against product availability is done before adding it to the basket.
[in] | p | An instance to ProductProxy |
[in] | aQty | How many pieces of the same product (default is 1) |
References _realAddProduct(), _tot, ProductProxy::getAvailability(), ProductProxy::getPrice(), and ProductProxy::uniqueID().
bool Basket::addProduct | ( | Product * | p, | |
int | aQty = 1 | |||
) |
Add product to basket.
Add a product to the basket. It's possibile to specify how many pieces of the same product. A check against product availability is done before adding it to the basket.
[in] | p | An instance to Product |
[in] | aQty | How many pieces of the same product (default is 1) |
References _realAddProduct(), _tot, Product::getAvailability(), Product::getPrice(), ManagedObject::intForKey(), and Product::primaryKey().
Referenced by UserMenu::placeNewOrder().
void Basket::empty | ( | ) |
Empty the basket.
References _tot.
int Basket::itemCount | ( | ) |
Items count.
Return the number of item currently present in the basket.
Referenced by UserMenu::placeNewOrder().
void Basket::removeProduct | ( | Product * | p, | |
int | aQty = 1 | |||
) |
Remove a product from the basket.
The function looks for the given product and decreases the quantity: if this value goes down below or equal to zero, the product is removed; otherwise only quantity is decreased.
[in] | p | Pointer to Product to be removed |
[in] | aQty | Requested quantity to remove |
References ManagedObject::intForKey(), and Product::primaryKey().
float Basket::total | ( | ) | const |
Return the total cost of the basket.
References _tot.
Referenced by Order::create(), and UserMenu::placeNewOrder().
std::ostream& operator<< | ( | std::ostream & | aStream, | |
Basket & | p | |||
) | [friend] |
float Basket::_tot [private] |
Referenced by addProduct(), Basket(), empty(), and total().