shipping system integrated with cart, but need admin interface to test if it works
This commit is contained in:
parent
56407bdc8f
commit
8a04f5911f
6 changed files with 62 additions and 35 deletions
|
|
@ -125,6 +125,7 @@ sub migrateToNewCart {
|
||||||
cartId varchar(22) binary not null primary key,
|
cartId varchar(22) binary not null primary key,
|
||||||
sessionId varchar(22) binary not null,
|
sessionId varchar(22) binary not null,
|
||||||
shippingAddressId varchar(22) binary,
|
shippingAddressId varchar(22) binary,
|
||||||
|
shipperId varchar(22) binary,
|
||||||
couponId varchar(22) binary,
|
couponId varchar(22) binary,
|
||||||
index sessionId (sessionId)
|
index sessionId (sessionId)
|
||||||
)");
|
)");
|
||||||
|
|
|
||||||
|
|
@ -232,16 +232,9 @@ The address book that this address belongs to.
|
||||||
sub update {
|
sub update {
|
||||||
my ($self, $newProperties) = @_;
|
my ($self, $newProperties) = @_;
|
||||||
my $id = id $self;
|
my $id = id $self;
|
||||||
$properties{$id}{address2} = (exists $newProperties->{address2}) ? $newProperties->{address2} : $properties{$id}{address2};
|
foreach my $field (qw(address1 address2 address3 state code city label name country phoneNumber)) {
|
||||||
$properties{$id}{address3} = (exists $newProperties->{address3}) ? $newProperties->{address3} : $properties{$id}{address3};
|
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
|
||||||
$properties{$id}{state} = (exists $newProperties->{state}) ? $newProperties->{state} : $properties{$id}{state};
|
}
|
||||||
$properties{$id}{code} = $newProperties->{code} || $properties{$id}{code};
|
|
||||||
$properties{$id}{city} = $newProperties->{city} || $properties{$id}{city};
|
|
||||||
$properties{$id}{label} = $newProperties->{label} || $properties{$id}{label};
|
|
||||||
$properties{$id}{name} = $newProperties->{name} || $properties{$id}{name};
|
|
||||||
$properties{$id}{country} = $newProperties->{country} || $properties{$id}{country};
|
|
||||||
$properties{$id}{address1} = $newProperties->{address1} || $properties{$id}{address1};
|
|
||||||
$properties{$id}{phoneNumber} = $newProperties->{phoneNumber} || $properties{$id}{phoneNumber};
|
|
||||||
$properties{$id}{addressBookId} = $self->addressBook->getId;
|
$properties{$id}{addressBookId} = $self->addressBook->getId;
|
||||||
$self->addressBook->session->db->setRow("address","addressId",$properties{$id});
|
$self->addressBook->session->db->setRow("address","addressId",$properties{$id});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -280,10 +280,9 @@ Assign the session that owns this adress book. Will automatically be set to "" i
|
||||||
sub update {
|
sub update {
|
||||||
my ($self, $newProperties) = @_;
|
my ($self, $newProperties) = @_;
|
||||||
my $id = id $self;
|
my $id = id $self;
|
||||||
$properties{$id}{lastShipId} = $newProperties->{lastShipId} || $properties{$id}{lastShipId};
|
foreach my $field (qw(lastPayId lastShipId userId sessionId)) {
|
||||||
$properties{$id}{lastPayId} = $newProperties->{lastPayId} || $properties{$id}{lastPayId};
|
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
|
||||||
$properties{$id}{userId} = (exists $newProperties->{userId}) ? $newProperties->{userId} : $properties{$id}{userId};
|
}
|
||||||
$properties{$id}{sessionId} = (exists $newProperties->{sessionId}) ? $newProperties->{sessionId} : $properties{$id}{sessionId};
|
|
||||||
##Having both a userId and sessionId will confuse create.
|
##Having both a userId and sessionId will confuse create.
|
||||||
if ($properties{$id}{userId} ne "") {
|
if ($properties{$id}{userId} ne "") {
|
||||||
$properties{$id}{sessionId} = "";
|
$properties{$id}{sessionId} = "";
|
||||||
|
|
|
||||||
|
|
@ -295,13 +295,18 @@ The unique id for a coupon used in this cart.
|
||||||
|
|
||||||
The unique id for a shipping address attached to this cart.
|
The unique id for a shipping address attached to this cart.
|
||||||
|
|
||||||
|
=head4 shipperId
|
||||||
|
|
||||||
|
The unique id of the configured shipping driver that will be used to ship these goods.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub update {
|
sub update {
|
||||||
my ($self, $newProperties) = @_;
|
my ($self, $newProperties) = @_;
|
||||||
my $id = id $self;
|
my $id = id $self;
|
||||||
$properties{$id}{couponId} = $newProperties->{couponId} || $properties{$id}{couponId};
|
foreach my $field (qw(couponId shippingAddressId shipperId)) {
|
||||||
$properties{$id}{shippingAddressId} = $newProperties->{shippingAddressId} || $properties{$id}{shippingAddressId};
|
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
|
||||||
|
}
|
||||||
$self->session->db->setRow("cart","cartId",$properties{$id});
|
$self->session->db->setRow("cart","cartId",$properties{$id});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -315,6 +320,10 @@ Update the cart and the return the user back to the asset.
|
||||||
|
|
||||||
sub www_continueShopping {
|
sub www_continueShopping {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
my $cartView = $self->www_update;
|
||||||
|
if ($error{id $self} ne "") {
|
||||||
|
return $cartView;
|
||||||
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -429,20 +438,39 @@ sub www_view {
|
||||||
extras=>q|onclick="this.form.method.value='continueShopping';this.form.submit;"|}),
|
extras=>q|onclick="this.form.method.value='continueShopping';this.form.submit;"|}),
|
||||||
chooseShippingButton => WebGUI::Form::submit($session, {value=>$i18n->get("choose shipping button"),
|
chooseShippingButton => WebGUI::Form::submit($session, {value=>$i18n->get("choose shipping button"),
|
||||||
extras=>q|onclick="this.form.shop.value='address';this.form.method.value='view';this.form.submit;"|}),
|
extras=>q|onclick="this.form.shop.value='address';this.form.method.value='view';this.form.submit;"|}),
|
||||||
shippingOptions => "todo",
|
|
||||||
shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("ship to button"),
|
shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("ship to button"),
|
||||||
extras=>q|onclick="this.form.shop.value='address';this.form.method.value='view';this.form.submit;"|}),
|
extras=>q|onclick="this.form.shop.value='address';this.form.method.value='view';this.form.submit;"|}),
|
||||||
hasShippingAddress => ($self->get("shippingAddressId") ne ""),
|
|
||||||
couponField => WebGUI::Form::text($session, {name=>"couponCode", value=>"", size=>20}),
|
couponField => WebGUI::Form::text($session, {name=>"couponCode", value=>"", size=>20}),
|
||||||
couponDiscount => "todo",
|
|
||||||
totalPrice => "todo",
|
|
||||||
tax => $self->formatCurrency($tax->calculate($self)),
|
|
||||||
subtotalPrice => $self->formatCurrency($self->calculateSubtotal()),
|
subtotalPrice => $self->formatCurrency($self->calculateSubtotal()),
|
||||||
|
couponDiscount => $self->formatCurrency(0),
|
||||||
);
|
);
|
||||||
my $address = eval { $self->getShippingAddress };
|
my $address = eval { $self->getShippingAddress };
|
||||||
unless (WebGUI::Error->caught) {
|
if (WebGUI::Error->caught("WebGUI::Error::ObjectNotFound")) {
|
||||||
$var{shippingAddress} = $address->getHtmlFormatted;
|
# choose another address cuz we've got a problem
|
||||||
|
$self->update({shippingAddressId=>""});
|
||||||
}
|
}
|
||||||
|
if (WebGUI::Error->caught) {
|
||||||
|
$var{shippingPrice} = $var{tax} = $self->formatCurrency(0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$var{hasShippingAddress} = 1;
|
||||||
|
$var{shippingAddress} = $address->getHtmlFormatted;
|
||||||
|
$var{tax} = $self->formatCurrency($tax->calculate($self));
|
||||||
|
my $options = WebGUI::Shop::Ship->getOptions($self);
|
||||||
|
my %formOptions = ();
|
||||||
|
my $defaultOption = "";
|
||||||
|
foreach my $option (keys %{$options}) {
|
||||||
|
$defaultOption = $option;
|
||||||
|
$formOptions{$option} = $options->{$option}{label}." (".$self->formatCurrency($options->{$option}{price}).")";
|
||||||
|
}
|
||||||
|
$var{shippingOptions} = WebGUI::Form::selectBox($session, {name=>"shipperId", options=>\%formOptions, defaultValue=>$defaultOption, value=>$self->get("shipperId")});
|
||||||
|
$var{shippingPrice} = ($self->get("shipperId") ne "") ? $options->{$self->get("shipperId")}{price} : $options->{$defaultOption}{price};
|
||||||
|
$var{shippingPrice} = $self->formatCurrency($var{shippingPrice});
|
||||||
|
}
|
||||||
|
if ($self->get("couponId")) {
|
||||||
|
$var{couponDiscount} = $self->formatCurrency(0);
|
||||||
|
}
|
||||||
|
$var{totalPrice} = $self->formatCurrency($var{subtotalPrice} + $var{couponDiscount} + $var{shippingPrice} + $var{tax});
|
||||||
my $template = WebGUI::Asset::Template->new($session, $session->setting->get("shopCartTemplateId"));
|
my $template = WebGUI::Asset::Template->new($session, $session->setting->get("shopCartTemplateId"));
|
||||||
$template->prepare;
|
$template->prepare;
|
||||||
return $session->style->userStyle($template->process(\%var));
|
return $session->style->userStyle($template->process(\%var));
|
||||||
|
|
|
||||||
|
|
@ -280,12 +280,12 @@ sub update {
|
||||||
$newProperties->{assetId} = $newProperties->{asset}->getId;
|
$newProperties->{assetId} = $newProperties->{asset}->getId;
|
||||||
$newProperties->{configuredTitle} = $newProperties->{asset}->getConfiguredTitle;
|
$newProperties->{configuredTitle} = $newProperties->{asset}->getConfiguredTitle;
|
||||||
}
|
}
|
||||||
$properties{$id}{assetId} = $newProperties->{assetId} || $properties{$id}{assetId};
|
foreach my $field (qw(assetId configuredTitle shippingAddressId)) {
|
||||||
$properties{$id}{configuredTitle} = $newProperties->{configuredTitle} || $properties{$id}{configuredTitle};
|
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
|
||||||
|
}
|
||||||
if (exists $newProperties->{options} && ref($newProperties->{options}) eq "HASH") {
|
if (exists $newProperties->{options} && ref($newProperties->{options}) eq "HASH") {
|
||||||
$properties{$id}{options} = JSON::to_json($newProperties->{options});
|
$properties{$id}{options} = JSON::to_json($newProperties->{options});
|
||||||
}
|
}
|
||||||
$properties{$id}{shippingAddressId} = $newProperties->{shippingAddressId} || $properties{$id}{shippingAddressId};
|
|
||||||
$self->cart->session->db->setRow("cartItems","itemId",$properties{$id});
|
$self->cart->session->db->setRow("cartItems","itemId",$properties{$id});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ sub getDrivers {
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 getOptions ( $session, $cart )
|
=head2 getOptions ( $cart )
|
||||||
|
|
||||||
Returns a list of options for the user to ship, along with the cost of using each one. It is a hash of hashrefs,
|
Returns a list of options for the user to ship, along with the cost of using each one. It is a hash of hashrefs,
|
||||||
with the key of the primary hash being the shipperId of the driver, and sub keys of label and price.
|
with the key of the primary hash being the shipperId of the driver, and sub keys of label and price.
|
||||||
|
|
@ -101,11 +101,17 @@ A WebGUI::Session object. A WebGUI::Error::InvalidParam exception will be throw
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub getOptions {
|
sub getOptions {
|
||||||
my $class = shift;
|
my ($class, $cart) = @_;
|
||||||
my $session = shift;
|
my $session = $cart->session;
|
||||||
WebGUI::Error::InvalidParam->throw(error => q{Must provide a session variable})
|
WebGUI::Error::InvalidParam->throw(error => q{Need a cart.}) unless $cart->isa("WebGUI::Shop::Cart");
|
||||||
unless ref $session eq 'WebGUI::Session';
|
my %options = ();
|
||||||
return;
|
foreach my $shipper (@{$class->getShippers($session)}) {
|
||||||
|
$options{$shipper->getId} = {
|
||||||
|
label => $shipper->get("label"),
|
||||||
|
price => $shipper->calculate($cart),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return \%options;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -127,14 +133,14 @@ sub getShippers {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
WebGUI::Error::InvalidParam->throw(error => q{Must provide a session variable})
|
WebGUI::Error::InvalidParam->throw(error => q{Must provide a session variable})
|
||||||
unless ref $session eq 'WebGUI::Session';
|
unless ref $session eq 'WebGUI::Session';
|
||||||
my $drivers;
|
my @drivers = ();
|
||||||
my $sth = $session->db->prepare('select shipperId from shipper');
|
my $sth = $session->db->prepare('select shipperId from shipper');
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
while (my $driver = $sth->hashRef()) {
|
while (my $driver = $sth->hashRef()) {
|
||||||
push @{ $drivers }, WebGUI::Shop::Ship->new($session, $driver->{shipperId});
|
push @drivers, WebGUI::Shop::Ship->new($session, $driver->{shipperId});
|
||||||
}
|
}
|
||||||
$sth->finish;
|
$sth->finish;
|
||||||
return $drivers;
|
return \@drivers;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue