ems badge listing now works and you can add badges
made address book address selector use callbacks so that it can be used by things other than shipping
This commit is contained in:
parent
aaac88ce6f
commit
8a07dde303
5 changed files with 155 additions and 70 deletions
|
|
@ -3,6 +3,7 @@ package WebGUI::Shop::AddressBook;
|
|||
use strict;
|
||||
|
||||
use Class::InsideOut qw{ :std };
|
||||
use JSON;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::Exception::Shop;
|
||||
use WebGUI::Form;
|
||||
|
|
@ -146,6 +147,24 @@ sub delete {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 formatCallbackForm ( callback )
|
||||
|
||||
Returns an HTML hidden form field with the callback JSON block properly escaped.
|
||||
|
||||
=head3 callback
|
||||
|
||||
A JSON string that holds the callback information.
|
||||
|
||||
=cut
|
||||
|
||||
sub formatCallbackForm {
|
||||
my ($self, $callback) = @_;
|
||||
$callback =~ s/"/'/g;
|
||||
return '<input type="hidden" name="callback" value="'.$callback.'" />';
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get ( [ property ] )
|
||||
|
||||
Returns a duplicated hash reference of this object’s data.
|
||||
|
|
@ -329,9 +348,9 @@ sub www_editAddress {
|
|||
error => $error,
|
||||
formHeader => WebGUI::Form::formHeader($session)
|
||||
.WebGUI::Form::hidden($session, {name=>"shop", value=>"address"})
|
||||
.$self->formatCallbackForm($form->get('callback'))
|
||||
.WebGUI::Form::hidden($session, {name=>"method", value=>"editAddressSave"})
|
||||
.WebGUI::Form::hidden($session, {name=>"addressId", value=>$form->get("addressId")})
|
||||
.WebGUI::Form::hidden($session, {name=>"itemId", value=>$form->get("itemId")}),
|
||||
.WebGUI::Form::hidden($session, {name=>"addressId", value=>$form->get("addressId")}),
|
||||
saveButton => WebGUI::Form::submit($session),
|
||||
formFooter => WebGUI::Form::formFooter($session),
|
||||
address1Field => WebGUI::Form::text($session, {name=>"address1", maxlength=>35, defaultValue=>($form->get("address1") || ((defined $address) ? $address->get('address1') : undef))}),
|
||||
|
|
@ -419,6 +438,13 @@ sub www_view {
|
|||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $form = $session->form;
|
||||
my $callback = $form->get('callback');
|
||||
$callback =~ s/'/"/g;
|
||||
$callback = JSON::from_json($callback);
|
||||
my $callbackForm = '';
|
||||
foreach my $param (@{$callback->{params}}) {
|
||||
$callbackForm .= WebGUI::Form::hidden($session, {name=>$param->{name}, value=>$param->{value}});
|
||||
}
|
||||
my $i18n = WebGUI::International->new($session, "Shop");
|
||||
my @addresses = ();
|
||||
foreach my $address (@{$self->getAddresses}) {
|
||||
|
|
@ -429,21 +455,19 @@ sub www_view {
|
|||
.WebGUI::Form::hidden($session, {name=>"shop", value=>"address"})
|
||||
.WebGUI::Form::hidden($session, {name=>"method", value=>"deleteAddress"})
|
||||
.WebGUI::Form::hidden($session, {name=>"addressId", value=>$address->getId})
|
||||
.WebGUI::Form::hidden($session, {name=>"itemId", value=>$form->get("itemId")})
|
||||
.$self->formatCallbackForm($form->get('callback'))
|
||||
.WebGUI::Form::submit($session, {value=>$i18n->get("delete")})
|
||||
.WebGUI::Form::formFooter($session),
|
||||
editButton => WebGUI::Form::formHeader($session)
|
||||
.WebGUI::Form::hidden($session, {name=>"shop", value=>"address"})
|
||||
.WebGUI::Form::hidden($session, {name=>"method", value=>"editAddress"})
|
||||
.WebGUI::Form::hidden($session, {name=>"addressId", value=>$address->getId})
|
||||
.WebGUI::Form::hidden($session, {name=>"itemId", value=>$form->get("itemId")})
|
||||
.$self->formatCallbackForm($form->get('callback'))
|
||||
.WebGUI::Form::submit($session, {value=>$i18n->get("edit")})
|
||||
.WebGUI::Form::formFooter($session),
|
||||
useButton => WebGUI::Form::formHeader($session)
|
||||
.WebGUI::Form::hidden($session, {name=>"shop", value=>"cart"})
|
||||
.WebGUI::Form::hidden($session, {name=>"method", value=>"setShippingAddress"})
|
||||
.WebGUI::Form::hidden($session, {name=>"shippingAddressId", value=>$address->getId})
|
||||
.WebGUI::Form::hidden($session, {name=>"itemId", value=>$form->get("itemId")})
|
||||
useButton => WebGUI::Form::formHeader($session,{action=>$callback->{url}})
|
||||
.$callbackForm
|
||||
.WebGUI::Form::hidden($session, {name=>"addressId", value=>$address->getId})
|
||||
.WebGUI::Form::submit($session, {value=>$i18n->get("use this address")})
|
||||
.WebGUI::Form::formFooter($session),
|
||||
});
|
||||
|
|
@ -453,7 +477,7 @@ sub www_view {
|
|||
addButton => WebGUI::Form::formHeader($session)
|
||||
.WebGUI::Form::hidden($session, {name=>"shop", value=>"address"})
|
||||
.WebGUI::Form::hidden($session, {name=>"method", value=>"editAddress"})
|
||||
.WebGUI::Form::hidden($session, {name=>"itemId", value=>$form->get("itemId")})
|
||||
.$self->formatCallbackForm($form->get('callback'))
|
||||
.WebGUI::Form::submit($session, {value=>$i18n->get("add a new address")})
|
||||
.WebGUI::Form::formFooter($session),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package WebGUI::Shop::Cart;
|
|||
use strict;
|
||||
|
||||
use Class::InsideOut qw{ :std };
|
||||
use JSON;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::Exception::Shop;
|
||||
use WebGUI::Form;
|
||||
|
|
@ -429,10 +430,10 @@ sub www_setShippingAddress {
|
|||
my $self = shift;
|
||||
my $form = $self->session->form;
|
||||
if ($form->get("itemId") ne "") {
|
||||
$self->getItem($form->get("itemId"))->update({shippingAddressId=>$form->get('shippingAddressId')});
|
||||
$self->getItem($form->get("itemId"))->update({shippingAddressId=>$form->get('addressId')});
|
||||
}
|
||||
else {
|
||||
$self->update({shippingAddressId=>$form->get('shippingAddressId')});
|
||||
$self->update({shippingAddressId=>$form->get('addressId')});
|
||||
}
|
||||
return $self->www_view;
|
||||
}
|
||||
|
|
@ -475,6 +476,17 @@ sub www_view {
|
|||
my $url = $session->url;
|
||||
my $i18n = WebGUI::International->new($session, "Shop");
|
||||
my @items = ();
|
||||
$session->style->setRawHeadTags(q|
|
||||
<script type="text/javascript">
|
||||
function setCallbackForAddressChooser (form, itemId) {
|
||||
form.shop.value='address';
|
||||
form.method.value='view';
|
||||
itemId = (itemId == undefined) ? 'null' : "'" + itemId + "'";
|
||||
form.callback.value='{"url":"|.$url->page.q|","params":[{"name":"shop","value":"cart"},{"name":"method","value":"setShippingAddress"},{"name":"itemId","value":'+itemId+'}]}';
|
||||
form.submit();
|
||||
}
|
||||
</script>
|
||||
|);
|
||||
foreach my $item (@{$self->getItems}) {
|
||||
my $sku = $item->getSku;
|
||||
$sku->applyOptions($item->get("options"));
|
||||
|
|
@ -489,7 +501,7 @@ sub www_view {
|
|||
removeButton => WebGUI::Form::submit($session, {value=>$i18n->get("remove button"),
|
||||
extras=>q|onclick="this.form.method.value='removeItem';this.form.itemId.value='|.$item->getId.q|';this.form.submit;"|}),
|
||||
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.itemId.value='|.$item->getId.q|';this.form.submit;"|}),
|
||||
extras=>q|onclick="setCallbackForAddressChooser(this.form,'|.$item->getId.q|');"|}),
|
||||
);
|
||||
my $address = eval { $item->getShippingAddress };
|
||||
unless (WebGUI::Error->caught) {
|
||||
|
|
@ -504,7 +516,7 @@ sub www_view {
|
|||
formHeader => WebGUI::Form::formHeader($session)
|
||||
. WebGUI::Form::hidden($session, {name=>"shop", value=>"cart"})
|
||||
. WebGUI::Form::hidden($session, {name=>"method", value=>"update"})
|
||||
. WebGUI::Form::hidden($session, {name=>"itemId", value=>""}),
|
||||
. WebGUI::Form::hidden($session, {name=>"callback", value=>""}),
|
||||
formFooter => WebGUI::Form::formFooter($session),
|
||||
updateButton => WebGUI::Form::submit($session, {value=>$i18n->get("update cart button")}),
|
||||
checkoutButton => WebGUI::Form::submit($session, {value=>$i18n->get("checkout button"),
|
||||
|
|
@ -512,9 +524,9 @@ sub www_view {
|
|||
continueShoppingButton => WebGUI::Form::submit($session, {value=>$i18n->get("continue shopping button"),
|
||||
extras=>q|onclick="this.form.method.value='continueShopping';this.form.submit;"|}),
|
||||
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="setCallbackForAddressChooser(this.form);"|}),
|
||||
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="setCallbackForAddressChooser(this.form);"|}),
|
||||
couponField => WebGUI::Form::text($session, {name=>"couponCode", value=>"", size=>20}),
|
||||
subtotalPrice => $self->formatCurrency($self->calculateSubtotal()),
|
||||
couponDiscount => $self->formatCurrency(0),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue