From 39078e944a3ca7eb801d85b3586a576ea595585a Mon Sep 17 00:00:00 2001 From: Jeff Boes Date: Thu, 31 Oct 2013 16:57:05 -0400 Subject: [PATCH] Checkpoint after getting the DBIx::Class and route changes working. --- lib/Flowers.pm | 1 + lib/Flowers/Products.pm | 41 ++++++++++++++++++++++++-------------- lib/Flowers/Routes/Item.pm | 21 +++++++++++++++++++ views/product.html | 12 +++++------ views/product.xml | 1 + 5 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 lib/Flowers/Routes/Item.pm diff --git a/lib/Flowers.pm b/lib/Flowers.pm index ba01619..3fc6c74 100644 --- a/lib/Flowers.pm +++ b/lib/Flowers.pm @@ -9,6 +9,7 @@ use Flowers::Products qw/product product_list/; use Flowers::Routes::Account; use Flowers::Routes::Checkout; +use Flowers::Routes::Item; use Flowers::Routes::Payment; use Flowers::Routes::Search; diff --git a/lib/Flowers/Products.pm b/lib/Flowers/Products.pm index 292396b..2e67747 100644 --- a/lib/Flowers/Products.pm +++ b/lib/Flowers/Products.pm @@ -7,40 +7,51 @@ use vars '@EXPORT_OK'; @EXPORT_OK = qw(product product_list); -use Dancer::Plugin::Nitesi; +use DBI; +use IC6::Schema; +use IC6::Schema::Result::Product; + +our (@connection, $db); + +BEGIN { + @connection = ('dbi:mysql:database=ic6;host=localhost;mysql_socket=/home/jeff/camp13/mysql/tmp/mysql.13.sock','ic6','woc46mij'); + + $db = IC6::Schema->connect(@connection); +} sub product { my ($path) = @_; - my ($set); - - # check whether product is available - $set = query->select(table => 'products', where => {sku => $path}); + my ($result); - if (@$set) { - return $set->[0]; - } + # check whether product is available + my $rs = $db->resultset('Product'); + $rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); + $result = $rs->search({ sku => $path, active => 1, })->next(); + return $result->{_column_data}; } =head2 product_list Returns a list of all products, ordered by priority. - + =cut - + sub product_list { my (%args) = @_; my ($order, $set); $args{sort} ||= 'priority'; - + if ($args{sort} eq 'price') { - $order = 'price ASC, priority ASC'; + $order = 'price ASC, priority ASC'; } else { - $order = 'priority ASC'; + $order = 'priority ASC'; } - - $set = query->select(table => 'products', where => {}, order => $order); + + $set = $db->resultset('Product')->search(undef, { + order_by => $order, + })->all(); return $set; } diff --git a/lib/Flowers/Routes/Item.pm b/lib/Flowers/Routes/Item.pm new file mode 100644 index 0000000..14e2da7 --- /dev/null +++ b/lib/Flowers/Routes/Item.pm @@ -0,0 +1,21 @@ +package Flowers::Routes::Item; + +use strict; +use Dancer ':syntax'; +use Flowers::Products qw(product); +use Data::Dumper; + +get '/product/:seo/:sku' => sub { + my $product = product( + uc params->{sku}, + ); + if (ref $product eq 'ARRAY') { + $product = $product->[0]; + } + + debug 'product ', join ',', %$product; + + template 'product', $product; +}; + +true; diff --git a/views/product.html b/views/product.html index ddaaa14..3f762db 100644 --- a/views/product.html +++ b/views/product.html @@ -2,28 +2,28 @@
- Domov > Priložnosti > Rojstni dan > Two dozen red roses + Domov > Priložnosti > Rojstni dan > Two dozen red roses

Two Dozen red Roses