Convert Sku and Shelf to Moose.
This commit is contained in:
parent
c7979a137f
commit
16d9076ecd
2 changed files with 66 additions and 109 deletions
|
|
@ -16,12 +16,59 @@ package WebGUI::Asset::Sku;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Tie::IxHash;
|
use Tie::IxHash;
|
||||||
use base 'WebGUI::Asset';
|
use WebGUI::Definition::Asset;
|
||||||
|
extends 'WebGUI::Asset';
|
||||||
use WebGUI::International;
|
use WebGUI::International;
|
||||||
use WebGUI::Inbox;
|
use WebGUI::Inbox;
|
||||||
use WebGUI::Shop::Cart;
|
use WebGUI::Shop::Cart;
|
||||||
use JSON qw{ from_json to_json };
|
use JSON qw{ from_json to_json };
|
||||||
|
|
||||||
|
attribute assetName => ['assetName', 'Asset_Sku'];
|
||||||
|
attribute icon => 'Sku.gif';
|
||||||
|
attribute tableName => 'sku';
|
||||||
|
|
||||||
|
property description => (
|
||||||
|
tab => "properties",
|
||||||
|
fieldType => "HTMLArea",
|
||||||
|
default => undef,
|
||||||
|
label => ["description", 'Asset_Sku'],
|
||||||
|
hoverHelp => ["description help", 'Asset_Sku'],
|
||||||
|
);
|
||||||
|
property sku => (
|
||||||
|
tab => "shop",
|
||||||
|
fieldType => "text",
|
||||||
|
default => sub { shift->session->id->generate },
|
||||||
|
lazy => 1,
|
||||||
|
label => ["sku", 'Asset_Sku'],
|
||||||
|
hoverHelp => ["sku help", 'Asset_Sku'],
|
||||||
|
);
|
||||||
|
property displayTitle => (
|
||||||
|
tab => "display",
|
||||||
|
fieldType => "yesNo",
|
||||||
|
default => 1,
|
||||||
|
label => ["display title", 'Asset_Sku'],
|
||||||
|
hoverHelp => ["display title help", 'Asset_Sku'],
|
||||||
|
);
|
||||||
|
property vendorId => (
|
||||||
|
tab => "shop",
|
||||||
|
fieldType => "vendor",
|
||||||
|
default => 'defaultvendor000000000',
|
||||||
|
label => ["vendor", 'Asset_Sku'],
|
||||||
|
hoverHelp => ["vendor help", 'Asset_Sku'],
|
||||||
|
);
|
||||||
|
property taxConfiguration => (
|
||||||
|
noFormPost => 1,
|
||||||
|
fieldType => 'hidden',
|
||||||
|
defaultValue => '{}',
|
||||||
|
);
|
||||||
|
property shipsSeparately => (
|
||||||
|
tab => 'shop',
|
||||||
|
fieldType => 'yesNo',
|
||||||
|
default => 0,
|
||||||
|
label => ['shipsSeparately', 'Asset_Sku'],
|
||||||
|
hoverHelp => ['shipsSeparately help', 'Asset_Sku'],
|
||||||
|
);
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
Package WebGUI::Asset::Sku
|
Package WebGUI::Asset::Sku
|
||||||
|
|
@ -88,76 +135,6 @@ sub applyOptions {
|
||||||
$self->{_skuOptions} = $options;
|
$self->{_skuOptions} = $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 definition ( session, definition )
|
|
||||||
|
|
||||||
See super class.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub definition {
|
|
||||||
my $class = shift;
|
|
||||||
my $session = shift;
|
|
||||||
my $definition = shift;
|
|
||||||
my %properties;
|
|
||||||
tie %properties, 'Tie::IxHash';
|
|
||||||
|
|
||||||
my $i18n = WebGUI::International->new($session, "Asset_Sku");
|
|
||||||
%properties = (
|
|
||||||
description => {
|
|
||||||
tab => "properties",
|
|
||||||
fieldType => "HTMLArea",
|
|
||||||
defaultValue => undef,
|
|
||||||
label => $i18n->get("description"),
|
|
||||||
hoverHelp => $i18n->get("description help")
|
|
||||||
},
|
|
||||||
sku => {
|
|
||||||
tab => "shop",
|
|
||||||
fieldType => "text",
|
|
||||||
defaultValue => $session->id->generate,
|
|
||||||
label => $i18n->get("sku"),
|
|
||||||
hoverHelp => $i18n->get("sku help")
|
|
||||||
},
|
|
||||||
displayTitle => {
|
|
||||||
tab => "display",
|
|
||||||
fieldType => "yesNo",
|
|
||||||
defaultValue => 1,
|
|
||||||
label => $i18n->get("display title"),
|
|
||||||
hoverHelp => $i18n->get("display title help")
|
|
||||||
},
|
|
||||||
vendorId => {
|
|
||||||
tab => "shop",
|
|
||||||
fieldType => "vendor",
|
|
||||||
defaultValue => 'defaultvendor000000000',
|
|
||||||
label => $i18n->get("vendor"),
|
|
||||||
hoverHelp => $i18n->get("vendor help")
|
|
||||||
},
|
|
||||||
taxConfiguration => {
|
|
||||||
noFormPost => 1,
|
|
||||||
fieldType => 'hidden',
|
|
||||||
defaultValue => '{}',
|
|
||||||
},
|
|
||||||
shipsSeparately => {
|
|
||||||
tab => 'shop',
|
|
||||||
fieldType => 'yesNo',
|
|
||||||
defaultValue => 0,
|
|
||||||
label => $i18n->get('shipsSeparately'),
|
|
||||||
hoverHelp => $i18n->get('shipsSeparately help'),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
push(@{$definition}, {
|
|
||||||
assetName=>$i18n->get('assetName'),
|
|
||||||
icon=>'Sku.gif',
|
|
||||||
autoGenerateForms=>1,
|
|
||||||
tableName=>'sku',
|
|
||||||
className=>'WebGUI::Asset::Sku',
|
|
||||||
properties=>\%properties
|
|
||||||
});
|
|
||||||
return $class->SUPER::definition($session, $definition);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 getAddToCartForm ( )
|
=head2 getAddToCartForm ( )
|
||||||
|
|
@ -420,7 +397,7 @@ Adding sku as a keyword. See WebGUI::Asset::indexContent() for additonal details
|
||||||
sub indexContent {
|
sub indexContent {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $indexer = $self->SUPER::indexContent;
|
my $indexer = $self->SUPER::indexContent;
|
||||||
$indexer->addKeywords($self->get('sku'));
|
$indexer->addKeywords($self->sku);
|
||||||
return $indexer;
|
return $indexer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -667,7 +644,7 @@ false.
|
||||||
|
|
||||||
sub shipsSeparately {
|
sub shipsSeparately {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
return $self->isShippingRequired && $self->get('shipsSeparately');
|
return $self->isShippingRequired && $self->shipsSeparately;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,45 +14,25 @@ use strict;
|
||||||
use List::MoreUtils;
|
use List::MoreUtils;
|
||||||
use Tie::IxHash;
|
use Tie::IxHash;
|
||||||
use WebGUI::International;
|
use WebGUI::International;
|
||||||
use base 'WebGUI::Asset::Wobject';
|
use WebGUI::Definition::Asset;
|
||||||
|
extends 'WebGUI::Asset::Wobject';
|
||||||
use WebGUI::Text;
|
use WebGUI::Text;
|
||||||
use WebGUI::Storage;
|
use WebGUI::Storage;
|
||||||
use WebGUI::Exception::Shop;
|
use WebGUI::Exception::Shop;
|
||||||
use WebGUI::Asset::Sku::Product;
|
use WebGUI::Asset::Sku::Product;
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
attribute assetName => ['assetName', 'Asset_Shelf'];
|
||||||
|
attribute icon => 'Shelf.gif';
|
||||||
|
attribute tableName => 'Shelf';
|
||||||
|
|
||||||
=head2 definition ( )
|
property templateId => (
|
||||||
|
fieldType => "template",
|
||||||
Add our custom properties of templateId to this asset.
|
defaultValue => 'nFen0xjkZn8WkpM93C9ceQ',
|
||||||
|
tab => "display",
|
||||||
=cut
|
namespace => "Shelf",
|
||||||
|
hoverHelp => ['shelf template help', 'Asset_Shelf'],
|
||||||
sub definition {
|
label => ['shelf template', 'Asset_Shelf'],
|
||||||
my ($class, $session, $definition) = @_;
|
);
|
||||||
my $i18n = WebGUI::International->new($session, 'Asset_Shelf');
|
|
||||||
my %properties;
|
|
||||||
tie %properties, 'Tie::IxHash';
|
|
||||||
%properties = (
|
|
||||||
templateId =>{
|
|
||||||
fieldType => "template",
|
|
||||||
defaultValue => 'nFen0xjkZn8WkpM93C9ceQ',
|
|
||||||
tab => "display",
|
|
||||||
namespace => "Shelf",
|
|
||||||
hoverHelp => $i18n->get('shelf template help'),
|
|
||||||
label => $i18n->get('shelf template'),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
push(@{$definition}, {
|
|
||||||
assetName => $i18n->get('assetName'),
|
|
||||||
icon => 'Shelf.gif',
|
|
||||||
autoGenerateForms => 1,
|
|
||||||
tableName => 'Shelf',
|
|
||||||
className => 'WebGUI::Asset::Wobject::Shelf',
|
|
||||||
properties => \%properties
|
|
||||||
});
|
|
||||||
return $class->SUPER::definition($session, $definition);
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -74,7 +54,7 @@ sub exportProducts {
|
||||||
@columns = map { $_ eq 'shortdescription' ? 'shortdesc' : $_ } @columns;
|
@columns = map { $_ eq 'shortdescription' ? 'shortdesc' : $_ } @columns;
|
||||||
my $getAProduct = WebGUI::Asset::Sku::Product->getIsa($session);
|
my $getAProduct = WebGUI::Asset::Sku::Product->getIsa($session);
|
||||||
while (my $product = $getAProduct->()) {
|
while (my $product = $getAProduct->()) {
|
||||||
my $mastersku = $product->get('sku');
|
my $mastersku = $product->sku;
|
||||||
my $title = $product->getTitle;
|
my $title = $product->getTitle;
|
||||||
my $collateri = $product->getAllCollateral('variantsJSON');
|
my $collateri = $product->getAllCollateral('variantsJSON');
|
||||||
foreach my $collateral (@{ $collateri }) {
|
foreach my $collateral (@{ $collateri }) {
|
||||||
|
|
@ -260,7 +240,7 @@ See WebGUI::Asset::prepareView() for details.
|
||||||
sub prepareView {
|
sub prepareView {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
$self->SUPER::prepareView();
|
$self->SUPER::prepareView();
|
||||||
my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId"));
|
my $template = WebGUI::Asset::Template->new($self->session, $self->templateId);
|
||||||
if (!$template) {
|
if (!$template) {
|
||||||
WebGUI::Error::ObjectNotFound::Template->throw(
|
WebGUI::Error::ObjectNotFound::Template->throw(
|
||||||
error => qq{Template not found},
|
error => qq{Template not found},
|
||||||
|
|
@ -300,7 +280,7 @@ sub view {
|
||||||
my @childSkus = @{$self->getLineage(['children'],{isa=>'WebGUI::Asset::Sku'})};
|
my @childSkus = @{$self->getLineage(['children'],{isa=>'WebGUI::Asset::Sku'})};
|
||||||
|
|
||||||
# find products based upon keywords
|
# find products based upon keywords
|
||||||
my @keywords = $self->get('keywords');
|
my @keywords = $self->keywords;
|
||||||
my $keywordBasedAssetIds = WebGUI::Keyword->new($session)->getMatchingAssets({
|
my $keywordBasedAssetIds = WebGUI::Keyword->new($session)->getMatchingAssets({
|
||||||
matchAssetKeywords => $self,
|
matchAssetKeywords => $self,
|
||||||
isa => 'WebGUI::Asset::Sku',
|
isa => 'WebGUI::Asset::Sku',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue