Interchange6::Schema::Result::Product
The products table contains three product types parent, child and single.
Parent Product A parent product is a container product in which variations of parent product or "child products" are linked.
Child Product A child product for example "Acme Pro 10lb Dumbbell" would include the canonical_sku of the parent item whose description might be something like "Acme Pro Dumbbell". In general a child product would contain attributes while a parent product would not.
Single Product A single product does not have child products and will become a parent product if a child product exists.
SKU used by shop.
Primary key.
Manufacturer's sku.
Is nullable.
The name used to identify the product.
A brief summary of the product.
Full product description.
Numeric value representing product cost. Default is 0.0.
When price is updated and product has related "discount" in Interchange6::Schema::Result::PriceModifier then also update the related "price" in Interchange6::Schema::Result::PriceModifier. This is done using the method update_price_modifiers.
price
update_price_modifiers
Unique product uri. Example "acme-pro-dumbbells". Is nullable.
Numeric weight of the product. Defaults to zero.
Display order priority.
Unique EAN or UPC type data. Is nullable.
The SKU of the main product if this product is a variant of a main product. Is nullable.
Is this product active? Default is yes.
Is this producr exempt from inventory? Default is no.
Date and time when this record was created returned as DateTime object. Value is auto-set on insert.
Date and time when this record was last modified returned as DateTime object. Value is auto-set on insert and update.
Type: belongs_to
Related object: Interchange6::Schema::Result::Product
Type: has_many
Related object: Interchange6::Schema::Result::CartProduct
Related object: Interchange6::Schema::Result::PriceModifier
Type: might_have
Related object: Interchange6::Schema::Result::Inventory
Related object: Interchange6::Schema::Result::MediaProduct
Related object: Interchange6::Schema::Result::MerchandisingProduct
Related object: Interchange6::Schema::Result::NavigationProduct
Type: many_to_many with navigation
Related object: Interchange6::Schema::Result::Orderline
Related object: Interchange6::Schema::Result::ProductAttribute
Type: many_to_many with media
Related object: Interchange6::Schema::Result::ProductReview
This is considered a private method. Please see public "product_reviews" method.
Type: many_to_many
This is considered a private method. Accessor to related Message results. Please see public "reviews" and "add_to_reviews" methods.
Attribute methods are provided by the Interchange6::Schema::Base::Attribute class.
Override inherited method to call "generate_uri" method in case "name" and "sku" have been supplied as arguments but "uri" has not.
Called when "price" is updated.
Called by "new" if no uri is given as an argument.
The following steps are taken:
1. Join $self->name and $self->uri with - and stash in $uri to allow manipulation via filters
$self->name
$self->uri
-
$uri
2. Remove leading and trailing spaces and replace remaining spaces and / with -
/
3. Search for all rows in Interchange6::Schema::Result::Setting where scope is Product and name is <generate_uri_filter>
scope
Product
name
4. For each row found eval $row->value
$row->value
5. Finally set the value of column "uri" to $uri
Filters stored in Interchange6::Schema::Result::Setting are executed via eval and have access to $uri and also the product result held in $self
$self
Examples of filters stored in Setting might be:
{ scope => 'Product', name => 'generate_uri_filter', value => '$uri =~ s/badstuff/goodstuff/gi', }, { scope => 'Product', name => 'generate_uri_filter', value => '$uri = lc($uri)', },
Produces navigation path for this product. Returns array reference in scalar context.
Uses $type to select specific taxonomy from navigation if present.
Tier pricing can be calculated for a single role and also a combination of several roles.
The method always returns the best price for specific price points including any PriceModifier rows where roles_id is undef.
my $aref = $product->tier_pricing( 'trade' ); # [ # { quantity => 1, price => 20 }, # { quantity => 10, price => 19 }, # { quantity => 100, price => 18 }, # ]
Arguments should be given as a hash reference with the following keys/values:
quantity => $quantity
roles => array reference of Role names
PriceModifier rows which have roles_is undefined are always included in the search in addition to any roles that are provided as arguments. This enables promotional prices to be specified between fixed dates in Pricing price to apply to all classes of user whether logged in or not.
roles
quantity defaults to 1 if not supplied.
quantity
Returns lowest price from "price" and Pricing price.
Throws exception on bad arguments though unexpected keys in the hash reference will be silently discarded.
If the query was constructed using "with_lowest_selling_price" in Interchange6::Schema::ResultSet::Product then the cached value will be used rather than running a new query UNLESS arguments are supplied in which case a new query is performed.
If this is a canonical product without variants or a variant product then this method will return undef. If highest price is the same as "selling_price" then we again return undef.
If the query was constructed using "with_highest_price" in Interchange6::Schema::ResultSet::Product then the cached value will be used rather than running a new query.
This method calls "variant_count" and "selling_price" so when constructing a resultset query consider also chaining the associated ResultSet methods.
Find product variant with the given attribute values in $input.
Returns variant in case of success.
Returns undef in case of failure.
You can pass an optional hash reference \%match_info which is filled with attribute matches (only valid in case of failure).
hashref => 1
Return a hashref of attributes keyed on attribute name instead of an arrayref.
selected => $sku
Set the 'selected' SKU. For a child product this is set automatically.
cond => $cond
Search condition to use. Default is:
{ 'attribute.type' => 'variant' }
order_by => $order_by
Ordering to use in query. Default is:
[ { -desc => 'attribute.priority' }, { -asc => 'attribute.title' }, { -desc => 'attribute_value.priority' }, { -asc => 'attribute_value.title' }, ]
For canonical products, it shows all the attributes of the child products.
For a child product, it shows all the attributes of the siblings.
Example of returned arrayref:
[ { attribute_values => [ { priority => 2, selected => 0, title => "Pink", value => "pink" }, { priority => 1, selected => 0, title => "Yellow", value => "yellow" } ], name => "color", priority => 2, title => "Color" }, { attribute_values => [ { priority => 2, selected => 0, title => "Small", value => "small" }, { priority => 1, selected => 0, title => "Medium", value => "medium" }, ], name => "size", priority => 1, title => "Size" } ]
Add variants from a list of hash references.
Returns product object.
Each hash reference contains attributes and column data which overrides data from the canonical product.
The canonical sku of the variant is automatically set.
Example for the hash reference (attributes in the first line):
{color => 'yellow', size => 'small', sku => 'G0001-YELLOW-S', name => 'Six Small Yellow Tulips', uri => 'six-small-yellow-tulips'}
Since there is a risk that attributes names might clash with Product column names (for example "weight") an improved syntax exists to prevent such problems. This is considered to be the preferred syntax:
{ sku => 'ROD00014-2-6-mid', uri => 'fishingrod-weight-2-length-6-flex-mid', price => 355, attributes => [ { weight => '2' }, { length => '6' }, { action => 'mid' }, ], }
If "selling_price" is lower than "price" returns the rounded percentage discount or undef.
NOTE: for parent products (products that have variants) this will always return undef.
Return a Media resultset with the related media, filtered by type (e.g. video or image). On the results you can call display_uri("type") to get the actual uri.
display_uri("type")
Reviews should only be associated with parent products. This method returns the related ProductReview records for a parent product. For a child product the ProductReview records for the parent are returned.
Reviews should only be associated with parent products. This method returns the related Message (reviews) records for a parent product. For a child product the Message records for the parent are returned.
Arguments: $cond | undef, \%attrs?
Arguments are passed as paremeters to search the related reviews.
Returns the highest-rated approved public reviews for this product. Argument is max number of reviews to return which defaults to 5.
Returns the number of variants of this product. If the query was constructed using "with_variant_count" in Interchange6::Schema::ResultSet::Product then the cached value will be used rather than running a new query.
Alias for "variant_count" for backwards-compatibility.
Returns the average rating across all public and approved product reviews or undef if there are no reviews. Optional argument number of decimal places of precision must be a positive integer less than 10 which defaults to 1.
If the query was constructed using "with_average_rating" in Interchange6::Schema::ResultSet::Product then the cached value will be used rather than running a new query.
Similar to "set_$rel" in DBIx::Class::Relationship::Base except that this method DOES delete objects in the table on the right side of the relation.
Returns undef if inventory_exempt is true and otherwise returns the quantity of the product in the inventory. For a product variant the quantity returned is for the variant itself whereas for a canonical (parent) product the quantity returned is the total for all variants.
If the query was constructed using "with_quantity_in_stock" in Interchange6::Schema::ResultSet::Product then the cached value will be used rather than running a new query.
Overload delete to force removal of any product reviews. Only parent products should have reviews so in the case of child products no attempt is made to delete reviews.
To install Interchange6::Schema, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Interchange6::Schema
CPAN shell
perl -MCPAN -e shell install Interchange6::Schema
For more information on module installation, please visit the detailed CPAN module installation guide.