Permalink
Browse files

Merge pull request #1 from interchange/schema_work

Schema work
  • Loading branch information...
2 parents 2580f8f + 0a9557a commit 244e52a9dc5bbc9e3d90f5e5fba8ac2988b6936d Richard Templet committed Nov 6, 2013
View
@@ -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;
View
@@ -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;
}
View
@@ -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;
View
No changes.
View
No changes.
View
@@ -2,28 +2,28 @@
<div class="main-product">
<div class="crumbs">
- <a href="">Domov</a> > <a href="">Priložnosti</a> > <a href="">Rojstni dan</a> > Two dozen red roses
+ <a href="">Domov</a> > <a href="">Priložnosti</a> > <a href="">Rojstni dan</a> > <span class="crumb"> Two dozen red roses </span>
</div>
<h1 class="name">Two Dozen red Roses</h1>
<div class="product-gallery">
- <img src="img/img_big.jpg" class="product-image" width="360" height="360"/>
+ <img src="/img/img_big.jpg" class="product-image" width="360" height="360"/>
<div class="thumbs">
<div class="thumb">
- <a href=""><img src="img/img_thumb1.jpg" /></a>
+ <a href=""><img src="/img/img_thumb1.jpg" /></a>
</div>
<div class="thumb">
- <a href=""><img src="img/img_thumb1.jpg" /></a>
+ <a href=""><img src="/img/img_thumb1.jpg" /></a>
</div>
<div class="thumb">
- <a href=""><img src="img/img_thumb1.jpg" /></a>
+ <a href=""><img src="/img/img_thumb1.jpg" /></a>
</div>
<div class="thumb last">
- <a href=""><img src="img/img_thumb1.jpg" /></a>
+ <a href=""><img src="/img/img_thumb1.jpg" /></a>
</div>
</div>
View
@@ -1,6 +1,7 @@
<specification>
<value name="sku"/>
<value name="name"/>
+<value name="short_description" class="crumb"/>
<value name="product-image" field="sku" filter="image" target="src"/>
<value name="description" class="product-teaser"/>
<list name="options" class="product-options-item" iterator="options">

0 comments on commit 244e52a

Please sign in to comment.