NAME
Business::Cart::Generic::Database - Basic shopping cart
Synopsis
Description
Business::Cart::Generic implements parts of osCommerce and PrestaShop in Perl.
Installation
Constructor and Initialization
Parentage
This class extends Business::Cart::Generic::Base.
Using new()
new()
is called as my($obj) = Business::Cart::Generic::Database -> new(k1 => v1, k2 => v2, ...)
.
It returns a new object of type Business::Cart::Generic::Database
.
Key-value pairs accepted in the parameter list:
- o online => $zero_or_one
-
Takes an integer.
Defaults to 1.
It is set to 0 in command line code, such as when using Business::Cart::Generic::Database::Import.
This value is optional.
- o order => $order
-
Takes an object of type Business::Cart::Generic::Database::Order.
This value is set automatically at object construction time.
- o product => $product
-
Takes an object of type Business::Cart::Generic::Database::Product.
This value is set automatically at object construction time.
- o query => $query
-
Takes an object of type CGI or similar.
This key => value pair is mandatory.
- o schema => $schema
-
Takes a DBIx::Class schema object.
This value is set automatically at object construction time.
- o search => $search
-
Takes an object of type Business::Cart::Generic::Database::Search.
This value is set automatically at object construction time.
- o session => $session
-
Takes an object of type Data::Session.
This value is set automatically at object construction time when online has the value of 1 (the default).
These keys are also getter-type methods.
Methods
decrement_order_items()
Decrements the count of items in the shopping cart, as stored in the session object.
Returns the item count.
get_id2name_map($class_name, $column_list)
Returns a hashref of (id => name) mappings from the table whose class is $class_name.
$column_list is an array of column names, excluding 'id' (since 'id' is added automatically to the list).
If $class_name is 'Product', $column_list must include 'currency_id' (since the currency is used to format the price, if 'price' is in $column_list).
The reason for having a column list is so the output values ('name') can be a string of comma-separated values taken from several columns in the table.
For instance, when building a drop-down menu of products (via build_select), $column_list is [qw/name description price currency_id/].
get_special_id2name_map($class_name, $constraint_name, $constraint_value)
A limited form of get_id2name_map, returning only the 'id' and 'name' columns.
Returns a list of 2 elements:
- o A hashref of (id => name) mappings from the table whose class is $class_name
- o An integer which is the minimum value of id
-
This can be used to set the default in a drop-down HTML menu.
$constraint_name is a column name from the table, and $constraint_value is the value in that column to restrict the selection to.
For instance, to get just the zones for a given country, use get_special_id2name_map('Zone', 'country_id', $country_id).
increment_order_count()
Increments the count of orders placed by the customer, as stored in the session object.
Returns the order count.
After checking out, the customer can choose a product and click [Add to item], starting a new shopping cart. This counter tracks such activity.
reset_order()
Resets the order in the session object.
Returns nothing.
The order is a hashref, discussed in the FAQ in Business::Cart::Generic.
setup_session()
Creates a new Data::Session object.
Configuration parameters come from the return value of config().
If it's a new session, calls reset_order().
validate_country_id($id)
Called by Business::Cart::Generic::Util::Validator.
Returns 1 of the $id is valid, else 0.
validate_customer_id($id)
Called by Business::Cart::Generic::Util::Validator.
Returns 1 of the $id is valid, else 0.
validate_payment_method_id($id)
Called by Business::Cart::Generic::Util::Validator.
Returns 1 of the $id is valid, else 0.
validate_product($id, $quantity)
Called by Business::Cart::Generic::Util::Validator.
Returns 1 of the $id and $quantity are valid, else 0.
The $id has to be the id (primary key) of a product, and the quantity has to be both greater than 0, and less than or equal to max_quantity_per_order from the config file.
validate_street_address_id($id)
Called by Business::Cart::Generic::Util::Validator.
Returns 1 of the $id is valid, else 0.
validate_tax_class_id($id)
Called by Business::Cart::Generic::Util::Validator.
Returns 1 of the $id is valid, else 0.
validate_zone_id($id)
Called by Business::Cart::Generic::Util::Validator.
Returns 1 of the $id is valid, else 0.
Machine-Readable Change Log
The file CHANGES was converted into Changelog.ini by Module::Metadata::Changes.
Version Numbers
Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
Thanks
Many thanks are due to the people who chose to make osCommerce and PrestaShop, Zen Cart, etc, Open Source.
Support
Email the author, or log a bug on RT:
https://rt.cpan.org/Public/Dist/Display.html?Name=Business::Cart::Generic.
Author
Business::Cart::Generic was written by Ron Savage <ron@savage.net.au> in 2011.
Home page: http://savage.net.au/index.html.
Copyright
Australian copyright (c) 2011, Ron Savage.
All Programs of mine are 'OSI Certified Open Source Software';
you can redistribute them and/or modify them under the terms of
The Artistic License, a copy of which is available at:
http://www.opensource.org/licenses/index.html