
Mango::Provider::Products - Provider class for product information

my $provider = Mango::Provider::Products->new;
my $product = $provider->get_by_id(23);

Mango::Provider::Products is the provider class responsible for creating, deleting, updating and searching product information, including product tags and attributes.

Creates a new product provider object. If options are passed to new, those are sent to setup.
my $provider = Mango::Provider::Products->new;
See "new" in Mango::Provider and "new" in Mango::Provider::DBIC for a list of other possible options.

Adds the specified attributes to the specified product. product can be a Mango::Product object or a product id. attributes can be a list of attribute data hashes or Mango::Attribute objects.
$provider->add_attributes(23, {name => 'Attribute', value => 'Value'}, $attributeobect, ...)
Same as add_attributes.
Adds the specified tags to the specified product. product can be a Mango::Product object or a product id. tags can be a list of tag strings or Mango::Tag objects.
$provider->add_tags(23, 'computer', $tagobect, ...)
Same as add_tags.
Creates a new Mango::Product object using the supplied data.
my $product = $provider->create({
sku => 'ABC-1234',
price => 2.34,
description => 'The best product ever'
});
print $role->name;
In addition to using the column names, the following special keys are available:
This can be an anonymous array containing Mango::Attribute objects or hashes of attribute data (or both):
my $product = $provider->create({
sku => 'ABC-1234',
price => 2.34,
description => 'The best product ever',
attributes => [
{name => 'Attribute1', value => 'Value1'},
$attributeobject
]
});
This can be an anonymous array containing Mango::Tag objects or tag strings (or both):
my $product = $provider->create({
sku => 'ABC-1234',
price => 2.34,
description => 'The best product ever',
tags => [
qw/computer linux/,
$tagobject
]
});
Deletes products from the provider matching the supplied filter.
$provider->delete({
id => 23
});
In addition to using the column names, the following special keys are available:
This can be a user id, or a user object for which this profile is assigned to.
$provider->delete({
user => $user
});
It is recommended that you use this key, rather than setting the foreign key column manually in case it changes later.
Deletes attributes matching the specified filter form the specified product. product can be a Mango::Product object or a product id.
$provider->delete_attributes(23, {name => 'AttributeName'});
Deletes tags matching the specified filter form the specified product. product can be a Mango::Product object or a product id.
$provider->delete_tags(23, {name => [qw/computer linux/]});
Returns a Mango::Product object matching the specified id.
my $product = $provider->get_by_id(23);
Returns undef if no matching product can be found.
Returns a Mango::PRoduct object matching the specified id.
my $product = $provider->get_by_sku('ABC-1234');
Returns undef if no matching product can be found.
Returns a list of Mango::Product objects in list context, or a Mango::Iterator in scalar context matching the specified filter.
my @products = $provider->search({
sku => 'A%'
});
my $iterator = $provider->search({
sku => 'A%'
});
In addition to using the column names, the following special keys are available:
This can be an anonymous array containing Mango::Tag objects or tag strings (or both):
my $products = $provider->search({
sku => 'A%',
tags => [
'computer',
$tagobject
]
});
See "ATTRIBUTES" in DBIx::Class::Resultset for a list of other possible options.
Returns a list of Mango::Attribute objects in list context, or a Mango::Iterator in scalar context matching the specified filter.
$provider->search_attributes(23, {name => 'A'%});
Returns a list of Mango::Tag objects in list context, or a Mango::Iterator in scalar context matching the specified filter.
$provider->search_tags(23, {name => [qw/computer linux/]});
Returns a list of Mango::Tag objects in list context, or a Mango::Iterator in scalar context matching the specified filter.
my $tags = $provider->tags;
Only tags that are assigned to at least on product are returned. In addition to using the column names, the following special keys are available:
This is a hash containing a filter applied against products before returning those products tags.
my $tags = $provider->tags({
products => {
sku => 'A%'
}
});
Returns a list or iterator of tags related to the specified products/tags, excluding the already selected tags.
Sets the 'updated' column to DateTime->now and saves any changes made to the product back to the underlying store.
my $product = $provider->create(\%data);
$product->price(10.95);
$provider->update($product);
Sets the 'updated' column to DateTime->now and saves any changes made to the product back to the underlying store.
$attribute->value('AttributeValue');
$provider->update_attribute($attribute);

Mango::Provider, Mango::Provider::DBIC, Mango::Product, Mango::Tag, Mango::Attribute, DBIx::Class

Christopher H. Laco
CPAN ID: CLACO
claco@chrislaco.com
http://today.icantfocus.com/blog/