The class Product represents a generic item to be sold. More...
#include <Product.h>
Public Member Functions | |
Product () | |
Default constructor. | |
Product (Row &aRow) | |
Construct a Product with values contained in a mysqlpp::Row. | |
~Product () | |
Default destructor. | |
auto_ptr< Category > | getCategory () |
Returns product category. | |
float | getPrice () |
Return the price. | |
int | getAvailability () |
Return stock availability. | |
string | primaryKey () |
Primary key. | |
Static Public Member Functions | |
static Product * | factory (string aName, int aCid, float aPrice, string aDescr="empty", int aQty=0, bool isDel=false) |
New product creation. | |
static Product * | productByID (int aPid) |
Returns a product with given ID. | |
static void | showCompatibleProducts (int aPid) |
Show all configurations which include a given product. | |
Friends | |
ostream & | operator<< (ostream &, Product &) |
The class Product represents a generic item to be sold.
As the ER model states, each product logical belongs to a category, i.e. a family of products of the same nature, such as monitor, accessories and so on. The class Product of course need to implements virtual methods of base class ManagedObject, its use is similar to previous classes described so far: the methods factory() allows to create a new instance of product, as well as productByID() fetches a product from the persistent store based on the specified criteria and catalog() returns the entire list of available products.
Product::Product | ( | ) |
Product::Product | ( | Row & | aRow | ) |
Product::~Product | ( | ) |
Default destructor.
Product * Product::factory | ( | string | aName, | |
int | aCid, | |||
float | aPrice, | |||
string | aDescr = "empty" , |
|||
int | aQty = 0 , |
|||
bool | isDel = false | |||
) | [static] |
New product creation.
Static method to create a new product (without saving into the database): product details are filled with given parameters.
[in] | aName | Product name |
[in] | aCid | Category ID |
[in] | aPrice | Product price |
[in] | aDescr | Product detailed description |
[in] | aQty | Number of stocked items |
[in] | isDel | True if the product is not available |
References KEY_PRD_AVAILABILITY, KEY_PRD_CID, KEY_PRD_DELETED, KEY_PRD_DESCR, KEY_PRD_NAME, KEY_PRD_PID, KEY_PRD_PRICE, Product(), ManagedObject::setBoolForKey(), ManagedObject::setFloatForKey(), ManagedObject::setIntForKey(), and ManagedObject::setValueForKey().
Referenced by UserMenu::addNewProduct().
int Product::getAvailability | ( | ) |
Return stock availability.
References ManagedObject::intForKey(), and KEY_PRD_AVAILABILITY.
Referenced by Basket::addProduct().
auto_ptr< Category > Product::getCategory | ( | ) |
Returns product category.
References Category::categoryByID(), ManagedObject::intForKey(), and KEY_PRD_CID.
Referenced by ProductProxy::getCategory(), and operator<<().
float Product::getPrice | ( | ) |
Return the price.
References ManagedObject::floatForKey(), and KEY_PRD_PRICE.
Referenced by Basket::addProduct(), and ProductProxy::getPrice().
string Product::primaryKey | ( | ) | [virtual] |
Primary key.
Returns the primary for entity "products" (KEY_PRD_PID)
Implements ManagedObject.
References KEY_PRD_PID.
Referenced by Basket::addProduct(), and Basket::removeProduct().
Product * Product::productByID | ( | int | aPid | ) | [static] |
Returns a product with given ID.
[in] | aPid | The requested product ID |
References Database::getConnection(), Singleton< Database >::instance(), Product(), and SQL_PRODUCT_PROXY.
Referenced by UserMenu::changeProductDetail().
void Product::showCompatibleProducts | ( | int | aPid | ) | [static] |
Show all configurations which include a given product.
[in] | aPid | Given product ID |
References Database::getConnection(), Singleton< Database >::instance(), and Database::printResult().
Referenced by UserMenu::showConfigurationByProduct().
ostream& operator<< | ( | ostream & | aStream, | |
Product & | p | |||
) | [friend] |