Business-Cart-Generic

 view release on metacpan or  search on metacpan

lib/Business/Cart/Generic/Controller/Order.pm  view on Meta::CPAN

package Business::Cart::Generic::Controller::Order;

use parent 'Business::Cart::Generic::Controller';
use strict;
use warnings;

use Business::Cart::Generic::Util::Validator;

use Try::Tiny;

# We don't use Moose because we isa CGI::Application.

our $VERSION = '0.85';

# -----------------------------------------------

sub add_to_cart
{
	my($self) = @_;

	$self -> log(debug => 'add_to_cart()');

	my($message);
	my($order);

	try
	{
		($order, $message) = $self -> param('db') -> connector -> txn(fixup => sub{$self -> add_to_cart_txn_1});
	}
	catch
	{
		$message = $self -> param('templater') -> render('online.order.error.tx', {});
		$message = $self -> param('view') -> format_errors({'Unable to add to cart' => [$message]});
	};

	if (! $message)
	{
		$self -> log(debug => 'Order data is valid');

		try
		{
			$message = $self -> param('db') -> connector -> txn(fixup => sub{$self -> add_to_cart_txn_2($order)});
		}
		catch
		{
			$message = $self -> param('templater') -> render('online.order.error.tx', {});
			$message = $self -> param('view') -> format_errors({'Unable to add to cart' => [$message]});
		};
	}

	return $message;

} # End of add_to_cart.

# -----------------------------------------------

sub add_to_cart_txn_1
{
	my($self) = @_;

	$self -> log(debug => 'add_to_cart_txn_1()');

	my($order) = Business::Cart::Generic::Util::Validator -> new
	(
	 db     => $self -> param('db'),
	 query  => $self -> query,
	) -> validate_order;

	my($message);



( run in 0.949 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )