| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use WWW::Shopify; | ||
| 7 | |||
| 8 | package WWW::Shopify::Model::LinkList::Link; | ||
| 9 | use parent "WWW::Shopify::Model::NestedItem"; | ||
| 10 | |||
| 11 | my $fields; sub fields { return $fields; } | ||
| 12 | BEGIN { $fields = { | ||
| 13 | "id" => new WWW::Shopify::Field::Identifier(), | ||
| 14 | "position" => new WWW::Shopify::Field::Int(), | ||
| 15 | "subject" => new WWW::Shopify::Field::String(), | ||
| 16 | "subject_id" => new WWW::Shopify::Field::Int(), | ||
| 17 | "subject_params" => new WWW::Shopify::Field::String(), | ||
| 18 | "title" => new WWW::Shopify::Field::String(), | ||
| 19 | "link_list_id" => new WWW::Shopify::Field::Relation::Parent('WWW::Shopify::Model::LinkList'), | ||
| 20 | "link_type" => new WWW::Shopify::Field::String::Enum(["collection", "product", "frontpage", "catalog", "page", "blog", "search", "http"]) | ||
| 21 | }; } | ||
| 22 | |||
| 23 | sub creation_minimal { return qw(title link_type); } | ||
| 24 | sub creation_filled { return qw(link_list_id); } | ||
| 25 | sub update_filled { return qw(); } | ||
| 26 | |||
| 27 | sub link_model_type { | ||
| 28 | return ('WWW::Shopify::Model::CustomCollection', 'WWW::Shopify::Model::SmartCollection') if $_[0]->link_type eq 'collection'; | ||
| 29 | return 'WWW::Shopify::Model::Product' if $_[0]->link_type eq 'product'; | ||
| 30 | return 'WWW::Shopify::Model::Page' if $_[0]->link_type eq 'page'; | ||
| 31 | return 'WWW::Shopify::Model::Blog' if $_[0]->link_type eq 'blog'; | ||
| 32 | return () if wantarray; | ||
| 33 | return undef; | ||
| 34 | } | ||
| 35 | |||
| 36 | sub link_url { | ||
| 37 | return '/search' if $_[0]->link_type eq "search"; | ||
| 38 | return '/' if $_[0]->link_type eq "frontpage"; | ||
| 39 | return '/collections/all' if $_[0]->link_type eq "catalog"; | ||
| 40 | return $_[0]->subject if $_[0]->link_type eq "http"; | ||
| 41 | return '/collections/' . $_[0]->subject if $_[0]->link_type eq 'collection'; | ||
| 42 | return '/products/' . $_[0]->subject if $_[0]->link_type eq 'product'; | ||
| 43 | return '/pages/' . $_[0]->subject if $_[0]->link_type eq 'page'; | ||
| 44 | return '/blogs/' . $_[0]->subject if $_[0]->link_type eq 'blogs'; | ||
| 45 | return undef; | ||
| 46 | } | ||
| 47 | |||
| 48 | sub needs_login { return 1; } | ||
| 49 | |||
| 50 | eval(__PACKAGE__->generate_accessors); die $@ if $@; | ||
| 51 | |||
| 52 | 1; |