]> git.imager.perl.org - bse.git/blobdiff - site/cgi-bin/modules/BSE/UI/Shop.pm
on order build, retrieve pricing from the cart rather than recalculating it
[bse.git] / site / cgi-bin / modules / BSE / UI / Shop.pm
index 9922288b4723ef70b43e65ea0f92408a5f92cddd..e03e7dd4f73b6f087a241db9f706e56234892e66 100644 (file)
@@ -9,7 +9,7 @@ use BSE::CfgInfo qw(custom_class credit_card_class bse_default_country);
 use BSE::TB::Orders;
 use BSE::TB::OrderItems;
 use BSE::Util::Tags qw(tag_error_img tag_hash tag_article);
-use Products;
+use BSE::TB::Products;
 use BSE::TB::Seminars;
 use DevHelp::Validate qw(dh_validate dh_validate_hash);
 use Digest::MD5 'md5_hex';
@@ -18,7 +18,7 @@ use BSE::Countries qw(bse_country_code);
 use BSE::Util::Secure qw(make_secret);
 use BSE::Template;
 
-our $VERSION = "1.045";
+our $VERSION = "1.051";
 
 =head1 NAME
 
@@ -111,10 +111,7 @@ sub req_cart {
   # my %custom_state = %{$req->session->{custom}};
 
   # $cust_class->enter_cart(\@cart, \@cart_prods, \%custom_state, $req->cfg);
-  $msg = '' unless defined $msg;
-  $msg = escape_html($msg);
-
-  $msg ||= $req->message;
+  $msg = $req->message($msg);
   
   my %acts;
   %acts =
@@ -554,7 +551,7 @@ sub req_checkout {
   my @items = @{$cart->items};
 
   if ($cart->need_logon) {
-    my ($msg, $id) = $cart->need_logon_reason;
+    my ($msg, $id) = $cart->need_logon_message;
     return $class->_refresh_logon($req, $msg, $id);
   }
 
@@ -758,7 +755,7 @@ sub req_remove_item {
   my @cart = @{$req->session->{cart}};
   if ($index >= 0 && $index < @cart) {
     my ($item) = splice(@cart, $index, 1);
-    my $product = Products->getByPkey($item->{productId});
+    my $product = BSE::TB::Products->getByPkey($item->{productId});
     $req->flash_notice("msg:bse/shop/cart/remove", [ $product ]);
   }
   $req->session->{cart} = \@cart;
@@ -1360,10 +1357,10 @@ sub req_orderdone {
   my $order = BSE::TB::Orders->getByPkey($id)
     or return $class->req_cart($req);
   my @items = $order->items;
-  my @products = map { Products->getByPkey($_->{productId}) } @items;
+  my @products = map { BSE::TB::Products->getByPkey($_->{productId}) } @items;
 
   my @item_cols = BSE::TB::OrderItem->columns;
-  my %copy_cols = map { $_ => 1 } Product->columns;
+  my %copy_cols = map { $_ => 1 } BSE::TB::Product->columns;
   delete @copy_cols{@item_cols};
   my @copy_cols = keys %copy_cols;
   my @showitems;
@@ -1709,7 +1706,7 @@ sub _refresh_logon {
   if ($msgid) {
     $msg = $req->cfg->entry('messages', $msgid, $msg);
   }
-  $parms{message} = $msg if $msg;
+  $parms{m} = $msg if $msg;
   $parms{mid} = $msgid if $msgid;
   $url .= "?" . join("&", map "$_=".escape_uri($parms{$_}), keys %parms);
   
@@ -1786,7 +1783,7 @@ sub _build_items {
   my @cart = @{$req->session->{cart}}
     or return;
   my @items;
-  my @prodcols = Product->columns;
+  my @prodcols = BSE::TB::Product->columns;
   my @newcart;
   my $today = now_sqldate();
   for my $item ($cart->items) {
@@ -1804,10 +1801,20 @@ sub _build_items {
       for my $col (@prodcols) {
        $work{$col} = $product->$col() unless exists $work{$col};
       }
-      $work{price} = $product->price(user => scalar $req->siteuser);
-      $work{extended_retailPrice} = $work{units} * $work{price};
-      $work{extended_gst} = $work{units} * $work{gst};
-      $work{extended_wholesale} = $work{units} * $work{wholesalePrice};
+      my ($price, $tier) = $product->price(user => scalar $req->siteuser);
+      $work{price} = $item->price;
+      $work{tier_id} = $item->tier_id;
+      $work{extended_retailPrice} = $item->extended_retailPrice;
+      $work{extended_gst} = $item->extended_gst;
+      $work{extended_wholesale} = $item->extended_wholesale;
+      if ($cart->coupon_active) {
+       $work{product_discount} = $item->product_discount;
+       $work{product_discount_units} = $item->product_discount_units;
+      }
+      else {
+       $work{product_discount} = 0;
+       $work{product_discount_units} = 0;
+      }
       
       push @newcart, \%work;
     }
@@ -1893,9 +1900,13 @@ sub _fillout_order {
   }
   if ($cart->coupon_active) {
     $values->{coupon_id} = $cart->coupon->id;
+    $values->{coupon_description} = $cart->coupon_description;
+    $values->{coupon_cart_wide} = $cart->coupon_cart_wide;
   }
   else {
     $values->{coupon_id} = undef;
+    $values->{coupon_description} = "";
+    $values->{coupon_cart_wide} = 0;
   }
   $cart->set_shipping_cost($values->{shipping_cost});
   $cart->set_shipping_method($values->{shipping_method});
@@ -1903,6 +1914,7 @@ sub _fillout_order {
   $cart->set_delivery_in($values->{delivery_in});
 
   $values->{coupon_code_discount_pc} = $cart->coupon_code_discount_pc;
+  $values->{product_cost_discount} = $cart->product_cost_discount;
   $values->{total} = $cart->total;
 
   my $cust_class = custom_class($cfg);
@@ -1983,7 +1995,7 @@ sub _validate_add_by_id {
   my $product;
   if ($addid) {
     $product = BSE::TB::Seminars->getByPkey($addid);
-    $product ||= Products->getByPkey($addid);
+    $product ||= BSE::TB::Products->getByPkey($addid);
   }
   unless ($product) {
     $$error = "Cannot find product $addid";
@@ -1999,7 +2011,7 @@ sub _validate_add_by_code {
   my $product;
   if (defined $code) {
     $product = BSE::TB::Seminars->getBy(product_code => $code);
-    $product ||= Products->getBy(product_code => $code);
+    $product ||= BSE::TB::Products->getBy(product_code => $code);
   }
   unless ($product) {
     $$error = "Cannot find product code $code";
@@ -2312,7 +2324,7 @@ sub _refresh_cart {
 
   for my $item (@$cart) {
     if (!$item->{user} || $item->{user} != $user->id) {
-      my $product = Products->getByPkey($item->{productId})
+      my $product = BSE::TB::Products->getByPkey($item->{productId})
        or next;
       my ($price, $tier) = $product->price(user => $user);
       $item->{price} = $price;