X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;ds=sidebyside;f=lib%2FApp%2FWeb%2FOof.pm;fp=lib%2FApp%2FWeb%2FOof.pm;h=fa256a6965411da2ec9fca71097846d51960f8c0;hb=8bb7ab90a1720dcc48a016aff68cfcdfddf6f49d;hp=dffaaa57136a65d91d55151eb090fc75e2b2c775;hpb=bf8c3839b1715d687ec4fa9607164c10b225f9e3;p=app-web-oof.git diff --git a/lib/App/Web/Oof.pm b/lib/App/Web/Oof.pm index dffaaa5..fa256a6 100644 --- a/lib/App/Web/Oof.pm +++ b/lib/App/Web/Oof.pm @@ -62,6 +62,25 @@ sub make_slug { $slug } +sub product_to_schemaorg { + my ($include_url, %data) = @_; + my $stock = $data{stock} > 0 ? 'InStock' : 'OutOfStock'; + +{ + '@context' => 'http://schema.org/', + '@type' => 'Product', + name => $data{title}, + image => "/static/fullpics/$data{product}-1.jpg", + description => $data{summary}, + offers => { + '@type' => 'Offer', + price => ($data{price} =~ s/(..)$/\.$1/r), + priceCurrency => 'GBP', + availability => "http://schema.org/$stock", + ($include_url ? (url => "/details/$data{product}/" . make_slug $data{title}) : ()) + } + } +} + our %highlight; sub form_table_row { my ($data, $tr) = @_; @@ -230,14 +249,15 @@ sub details_app { $db{$$} //= DBIx::Simple->connect($ENV{OOF_DSN} // 'dbi:Pg:'); my $tree = $details->clone; my ($id) = $env->{PATH_INFO} =~ m,^/(\d+),; - my ($title, $summary) = $db{$$}->select(products => [qw/title summary/], {product => $id})->list; + my %data = %{$db{$$}->select(products => '*', {product => $id})->hash}; my @pics = ; - my $slug = make_slug $title; - $tree->find('title')->replace_content("Pictures of $title | ledparts4you"); - $tree->find('h2')->replace_content($title); - $tree->fid('summary')->replace_content($summary); + my $slug = make_slug $data{title}; + $tree->find('title')->replace_content("$data{title} | ledparts4you"); + $tree->find('h2')->replace_content($data{title}); + $tree->fid('summary')->replace_content($data{summary}); $tree->look_down(rel => 'canonical')->attr(href => "/details/$id/$slug"); $tree->fid('pictures')->find('li')->iter3(\@pics, \&details_list_element); + $tree->fid('jsonld')->replace_content(encode_json product_to_schemaorg '', %data); for my $ahref ($tree->find('a')) { $ahref->attr(href => "/form?highlight=$id") if $ahref->attr('href') eq '/';