Christopher H. Laco > Mango-0.01000_13 > Mango::Provider::Products

Download:
Mango-0.01000_13.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

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

SYNOPSIS ^

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

DESCRIPTION ^

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

CONSTRUCTOR ^

new

Arguments: \%options

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.

METHODS ^

add_attributes

Arguments: $product, @attributes

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, ...)

add_attribute

Same as add_attributes.

add_tags

Arguments: $product, @tags

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, ...)

add_tag

Same as add_tags.

create

Arguments: \%data

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:

attributes

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
        ]
    });
tags

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
        ]
    });

delete

Arguments: \%filter

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:

user

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.

delete_attributes

Arguments: $product, $filter

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'});

delete_tags

Arguments: $product, $filter

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/]});

get_by_id

Arguments: $id

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.

get_by_sku

Arguments: $sku

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.

search

Arguments: \%filter, \%options

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:

tags

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.

search_attributes

Arguments: $product, $filter, $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'%});

search_tags

Arguments: $product, $filter, $options

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/]});

tags

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:

products

This is a hash containing a filter applied against products before returning those products tags.

    my $tags = $provider->tags({
        products => {
            sku => 'A%'
        }
    });

related_tags

Arguments: \%filter

Returns a list or iterator of tags related to the specified products/tags, excluding the already selected tags.

update

Arguments: $product

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);

update_attribute

Arguments: $attribute

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);

SEE ALSO ^

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

AUTHOR ^

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