migrated webgui product
This commit is contained in:
parent
cfa77c82fa
commit
388cd8f306
4 changed files with 43 additions and 26 deletions
|
|
@ -796,6 +796,13 @@ WebGUI::Paginator API was changed to use the new session API.
|
|||
perl -pi.bak -e 's!WebGUI\:\:Paginator\-\>new\(!WebGUI::Paginator->new(\$self->session,!g' fileNameGoesHere
|
||||
|
||||
|
||||
5.23.19 WebGUI::Product API Refactored
|
||||
|
||||
WebGUI::Product now accepts session in the constructor.
|
||||
|
||||
perl -pi.bak -e 's!WebGUI\:\:Product\-\>new\(!WebGUI::Product->new(\$self->session,!g' fileNameGoesHere
|
||||
|
||||
|
||||
|
||||
6. Automatic list of Assets in Help System.
|
||||
-------------------------------------
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ sub process {
|
|||
|
||||
return WebGUI::International::get('cannot find product','Macro_Product') unless ($productId);
|
||||
|
||||
$product = WebGUI::Product->new($productId);
|
||||
$product = WebGUI::Product->new($self->session,$productId);
|
||||
|
||||
if ($variantId) {
|
||||
$variant = [ $product->getVariant($variantId) ];
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ sub www_deleteProduct {
|
|||
|
||||
return $session->privilege->insufficient unless ($session->user->isInGroup(14));
|
||||
|
||||
WebGUI::Product->new($productId)->delete;
|
||||
WebGUI::Product->new($session,$productId)->delete;
|
||||
|
||||
return WebGUI::Operation::execute('listProducts');
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ sub www_editProduct {
|
|||
$productId = $session->form->process("productId");
|
||||
|
||||
unless ($productId eq 'new') {
|
||||
$product = WebGUI::Product->new($productId)->get;
|
||||
$product = WebGUI::Product->new($session,$productId)->get;
|
||||
}
|
||||
|
||||
$f = WebGUI::HTMLForm->new($session);
|
||||
|
|
@ -169,7 +169,7 @@ sub www_editProductSave {
|
|||
return '<ul><li>'.join('</li><li>', @error).'</li></ul><br />'.WebGUI::Operation::execute('editProduct') if (@error);
|
||||
|
||||
$productId = $session->form->process("productId");
|
||||
$product = WebGUI::Product->new($productId);
|
||||
$product = WebGUI::Product->new($session,$productId);
|
||||
$product->set({
|
||||
title => $session->form->process("title"),
|
||||
description => $session->form->process("description"),
|
||||
|
|
@ -247,7 +247,7 @@ sub www_editProductParameterSave {
|
|||
|
||||
return "<ul><li>".join('</li><li>', @error)."</li></ul>".WebGUI::Operation::execute('editProductParameter') if (@error);
|
||||
|
||||
$product = WebGUI::Product->new($session->form->process("productId"));
|
||||
$product = WebGUI::Product->new($session,$session->form->process("productId"));
|
||||
$skuTemplate = $product->get('skuTemplate');
|
||||
|
||||
if ($parameterId eq 'new') {
|
||||
|
|
@ -437,7 +437,7 @@ sub www_editSkuTemplate {
|
|||
$i18n = WebGUI::International->new($session, "ProductManager");
|
||||
|
||||
$productId = $session->form->process("productId");
|
||||
$product = WebGUI::Product->new($productId);
|
||||
$product = WebGUI::Product->new($session,$productId);
|
||||
|
||||
$output .= "Available are: <br />\n";
|
||||
$output .= "<ul><li>base</li>\n";
|
||||
|
|
@ -474,7 +474,7 @@ sub www_editSkuTemplateSave {
|
|||
|
||||
return $session->privilege->insufficient unless ($session->user->isInGroup(14));
|
||||
|
||||
WebGUI::Product->new($productId)->set({
|
||||
WebGUI::Product->new($session,$productId)->set({
|
||||
skuTemplate => $session->form->process("skuTemplate"),
|
||||
});
|
||||
|
||||
|
|
@ -522,7 +522,7 @@ sub www_listProductVariants {
|
|||
|
||||
return WebGUI::Operation::execute('listProducts') if ($productId eq 'new' || !$productId);
|
||||
|
||||
$product = WebGUI::Product->new($productId);
|
||||
$product = WebGUI::Product->new($session,$productId);
|
||||
|
||||
@variants = sort {$a->{composition} cmp $b->{composition}} @{$product->getVariant};
|
||||
tie %parameters, "Tie::IxHash";
|
||||
|
|
@ -580,7 +580,7 @@ sub www_listProductVariantsSave {
|
|||
|
||||
my %availableVariants = map {$_ => 1} $session->form->selectList('available');
|
||||
|
||||
my $product = WebGUI::Product->new($session->form->process("productId"));
|
||||
my $product = WebGUI::Product->new($session,$session->form->process("productId"));
|
||||
my @variants = @{$product->getVariant};
|
||||
|
||||
foreach (@variants) {
|
||||
|
|
@ -604,7 +604,7 @@ sub www_manageProduct {
|
|||
return WebGUI::Operation::execute('listProducts') if ($productId eq 'new' || !$productId);
|
||||
$session->scratch->set('managingProduct', $productId);
|
||||
|
||||
$product = WebGUI::Product->new($productId);
|
||||
$product = WebGUI::Product->new($session,$productId);
|
||||
|
||||
$output .= "<h1>".$product->get('title')."</h1>";
|
||||
$output .= "<h2>".$i18n->get('properties').$session->icon->edit('op=editProduct;productId='.$productId)."</h2>";
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package WebGUI::Product;
|
||||
|
||||
use strict;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::Id;
|
||||
use WebGUI::Asset::Template;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -139,7 +137,7 @@ sub getByOptionId {
|
|||
|
||||
return undef unless ($productId);
|
||||
|
||||
return WebGUI::Product->new($productId);
|
||||
return WebGUI::Product->new($self->session,$productId);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -150,7 +148,7 @@ sub getByParameterId {
|
|||
|
||||
($productId) = $self->session->db->quickArray("select productId from productParameters where parameterId=".$self->session->db->quote($parameterId));
|
||||
|
||||
return WebGUI::Product->new($productId);
|
||||
return WebGUI::Product->new($self->session,$productId);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -161,7 +159,7 @@ sub getByVariantId {
|
|||
|
||||
($productId) = $self->session->db->quickArray("select productId from productVariants where variantId=".$self->session->db->quote($variantId));
|
||||
|
||||
return WebGUI::Product->new($productId);
|
||||
return WebGUI::Product->new($self->session,$productId);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -201,24 +199,22 @@ sub getVariant {
|
|||
sub new {
|
||||
my ($class, $productId, $properties, $parameters, $variants, $options, $sth, %row, $option, $new);
|
||||
$class = shift;
|
||||
my $session = shift;
|
||||
$productId = shift;
|
||||
|
||||
$self->session->errorHandler->fatal('no productId') unless ($productId);
|
||||
|
||||
$session->errorHandler->fatal('no productId') unless ($productId);
|
||||
$parameters = {};
|
||||
$variants = {};
|
||||
$options = {};
|
||||
|
||||
if ($productId eq 'new') {
|
||||
$productId = $self->session->id->generate;
|
||||
$productId = $session->id->generate;
|
||||
$properties = {productId => $productId};
|
||||
$self->session->db->write("insert into products (productId) values (".$self->session->db->quote($productId).")");
|
||||
$session->db->write("insert into products (productId) values (".$session->db->quote($productId).")");
|
||||
} else {
|
||||
$properties = $self->session->db->quickHashRef("select * from products where productId=".$self->session->db->quote($productId));
|
||||
$properties = $self->session->db->quickHashRef("select * from products where productId=".$session->db->quote($productId));
|
||||
|
||||
# fetch parameters and options
|
||||
$sth = $self->session->db->read("select opt.*, param.* from productParameters as param left join productParameterOptions as opt ".
|
||||
"on param.parameterId=opt.parameterId where param.productId=".$self->session->db->quote($productId));
|
||||
$sth = $session->db->read("select opt.*, param.* from productParameters as param left join productParameterOptions as opt ".
|
||||
"on param.parameterId=opt.parameterId where param.productId=".$session->db->quote($productId));
|
||||
while (%row = $sth->hash) {
|
||||
$parameters->{$row{parameterId}} = {
|
||||
name => $row{name},
|
||||
|
|
@ -240,7 +236,7 @@ sub new {
|
|||
}
|
||||
|
||||
# fetch variants
|
||||
$sth = $self->session->db->read("select * from productVariants where productId=".$self->session->db->quote($productId));
|
||||
$sth = $session->db->read("select * from productVariants where productId=".$session->db->quote($productId));
|
||||
while (%row = $sth->hash) {
|
||||
$variants->{$row{variantId}} = {%row};
|
||||
}
|
||||
|
|
@ -248,9 +244,23 @@ sub new {
|
|||
$new = 0;
|
||||
}
|
||||
|
||||
bless {_properties => $properties, _parameters => $parameters, _options => $options, _variants => $variants, _new => $new}, $class;
|
||||
bless {_session=> $session, _properties => $properties, _parameters => $parameters, _options => $options, _variants => $variants, _new => $new}, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head3 session
|
||||
|
||||
Returns a reference to the session.
|
||||
|
||||
=cut
|
||||
|
||||
sub session {
|
||||
my $self = shift;
|
||||
return $self->{_session};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub set {
|
||||
my ($self, $properties);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue