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 Tie::IxHash;
|
||||
use base 'WebGUI::Asset';
|
||||
use WebGUI::Definition::Asset;
|
||||
extends 'WebGUI::Asset';
|
||||
use WebGUI::International;
|
||||
use WebGUI::Inbox;
|
||||
use WebGUI::Shop::Cart;
|
||||
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
|
||||
|
||||
Package WebGUI::Asset::Sku
|
||||
|
|
@ -88,76 +135,6 @@ sub applyOptions {
|
|||
$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 ( )
|
||||
|
|
@ -420,7 +397,7 @@ Adding sku as a keyword. See WebGUI::Asset::indexContent() for additonal details
|
|||
sub indexContent {
|
||||
my $self = shift;
|
||||
my $indexer = $self->SUPER::indexContent;
|
||||
$indexer->addKeywords($self->get('sku'));
|
||||
$indexer->addKeywords($self->sku);
|
||||
return $indexer;
|
||||
}
|
||||
|
||||
|
|
@ -667,7 +644,7 @@ false.
|
|||
|
||||
sub shipsSeparately {
|
||||
my ($self) = @_;
|
||||
return $self->isShippingRequired && $self->get('shipsSeparately');
|
||||
return $self->isShippingRequired && $self->shipsSeparately;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,45 +14,25 @@ use strict;
|
|||
use List::MoreUtils;
|
||||
use Tie::IxHash;
|
||||
use WebGUI::International;
|
||||
use base 'WebGUI::Asset::Wobject';
|
||||
use WebGUI::Definition::Asset;
|
||||
extends 'WebGUI::Asset::Wobject';
|
||||
use WebGUI::Text;
|
||||
use WebGUI::Storage;
|
||||
use WebGUI::Exception::Shop;
|
||||
use WebGUI::Asset::Sku::Product;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
attribute assetName => ['assetName', 'Asset_Shelf'];
|
||||
attribute icon => 'Shelf.gif';
|
||||
attribute tableName => 'Shelf';
|
||||
|
||||
=head2 definition ( )
|
||||
|
||||
Add our custom properties of templateId to this asset.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
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);
|
||||
}
|
||||
property templateId => (
|
||||
fieldType => "template",
|
||||
defaultValue => 'nFen0xjkZn8WkpM93C9ceQ',
|
||||
tab => "display",
|
||||
namespace => "Shelf",
|
||||
hoverHelp => ['shelf template help', 'Asset_Shelf'],
|
||||
label => ['shelf template', 'Asset_Shelf'],
|
||||
);
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -74,7 +54,7 @@ sub exportProducts {
|
|||
@columns = map { $_ eq 'shortdescription' ? 'shortdesc' : $_ } @columns;
|
||||
my $getAProduct = WebGUI::Asset::Sku::Product->getIsa($session);
|
||||
while (my $product = $getAProduct->()) {
|
||||
my $mastersku = $product->get('sku');
|
||||
my $mastersku = $product->sku;
|
||||
my $title = $product->getTitle;
|
||||
my $collateri = $product->getAllCollateral('variantsJSON');
|
||||
foreach my $collateral (@{ $collateri }) {
|
||||
|
|
@ -260,7 +240,7 @@ See WebGUI::Asset::prepareView() for details.
|
|||
sub prepareView {
|
||||
my $self = shift;
|
||||
$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) {
|
||||
WebGUI::Error::ObjectNotFound::Template->throw(
|
||||
error => qq{Template not found},
|
||||
|
|
@ -300,7 +280,7 @@ sub view {
|
|||
my @childSkus = @{$self->getLineage(['children'],{isa=>'WebGUI::Asset::Sku'})};
|
||||
|
||||
# find products based upon keywords
|
||||
my @keywords = $self->get('keywords');
|
||||
my @keywords = $self->keywords;
|
||||
my $keywordBasedAssetIds = WebGUI::Keyword->new($session)->getMatchingAssets({
|
||||
matchAssetKeywords => $self,
|
||||
isa => 'WebGUI::Asset::Sku',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue