Skip to content

Commit

Permalink
Checkpoint after getting the DBIx::Class and route changes working.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Boes committed Oct 31, 2013
1 parent 2580f8f commit 39078e9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/Flowers.pm
Expand Up @@ -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;

Expand Down
41 changes: 26 additions & 15 deletions lib/Flowers/Products.pm
Expand Up @@ -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;
}

Expand Down
21 changes: 21 additions & 0 deletions 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;
12 changes: 6 additions & 6 deletions views/product.html
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions views/product.xml
@@ -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">
Expand Down

0 comments on commit 39078e9

Please sign in to comment.