Showing posts with label book store. Show all posts
Showing posts with label book store. Show all posts

Wednesday, July 6, 2011

Prestashop as Bookstore Part 4 - Details in product lists

I have done several modifications to make PrestaShop usable as a bookstore and I will try to sum it up in a few blog posts.

(I don't really have time for this, but a new post is overdue ++)

To put tags in the product list:
In classes/product.php, find eg

$row['features'] = Product::getFrontFeaturesStatic((int)$id_lang, $row['id_product']);

and add the line

$row['tags'] = Tag::getProductTags($row['id_product']);

In eg themes/yourtheme/product-list.tpl, find the line

title="{$product.description_short|truncate:360:'...'|strip_tags:'UTF-8'|escape:'htmlall':'UTF-8'}">{$product.description_short|truncate:360:'...'|strip_tags:'UTF-8'}</a></p>

and add

{if $product.location}
{if $product.tags}

{if $lang_iso == sv} {assign var='lng' value=4}{else} {assign var='lng' value=1} {/if}
{assign var='tag1' value=$product.tags[$lng]}
<p>
{assign var='delimiter' value=''}
{l s='Authors'}:
{foreach from=$tag1 item=tag}{$delimiter} {$tag|escape:'htmlall':'UTF-8'}{assign var='delimiter' value=','}{/foreach}
</p>

To put features at the same place
In eg themes/yourtheme/product-list.tpl, at the same place as for the tags, add

{if $product.features}

<p>
{assign var='go' value='0'}
{foreach from=$product.features item=feature}
{foreach from=$feature item=rank}
{if $go}Rank: {$rank}<br />{/if}
{if $rank == '40.Suggested rank'}{assign var='go' value='1'}
{else} {assign var='go' value='0'}
{/if}
{/foreach}
{/foreach}
</p>
{/if}

Short explanation of the code:
I use tags for authors and location to pin a item as a book, other parts of the logic may or may not be of use for you, the delimeter jazz is so that one tag appears as "foo" and tho tags as "foo, bar", ie comma separated.
The features array looks like this
Length, 10 cm, height, 2 cm, weight, 2 kg...
So I search for "Suggested rank" and print the following value. I only use one feature, but there is nothing stopping you from using more.

Edit: Forgot to add a picture of how it looks

Thursday, June 24, 2010

Prestashop as Bookstore Part 3 - Tabs

I have done several modifications to make PrestaShop usable as a bookstore and I will try to sum it up in a few blog posts.

In PrestaShop, when you view a product (click on the product from e.g. the Product List, Start Page etc) you get a view like this.





















I made some changes to the text block to the right of the picture, but recently I decided to put that extra information in a tab, so now it looks like this




















There is some extra information in the "Data Sheet" tab and a new tab called "Review"

First: To change the content of a tab, edit themes folder/product.tpl and find the line
<!-- description and features -->
Thereafter, you will find two blocks of code, the first produce the tabs and the second the tab's content.
So, basically, just add whatever you want in the correct place. E.g. to add "Facts about the product" to the Data Sheet tab first find the ID for that tab:

<li><a id="more_info_tab_data_sheet" href="#idTab2">{l s='Data sheet'}</a></li>

So the ID is idTab2, find the block for idTab2 which will look something like this:

{if $features}
<ul id="idTab2" class="bullet">
<div id="short_description_block">
{if $features}
{foreach from=$features item=feature}
<li><span>{$feature.name|escape:'htmlall':'UTF-8'}:</span> {$feature.value|escape:'htmlall':'UTF-8'}</li>
{/foreach}
{/if}
</div>
</ul>
{/if}

Change it to

{if $features}
{l s='Facts about the product'}
<ul id="idTab2" class="bullet">
<div id="short_description_block">
{if $features}
{foreach from=$features item=feature}
<li><span>{$feature.name|escape:'htmlall':'UTF-8'}:</span> {$feature.value|escape:'htmlall':'UTF-8'}</li>
{/foreach}
{/if}
</div>
</ul>
{/if}

You can use html tags to make it e.g. bold and the {l s=xxx} makes it translatable from the BO.

To add a new tab, Reviews, I added the line

{if $product->location}<li><a id="review" href="#idTab100">{l s='Reviews'}</a></li>{/if}

Right before {$HOOK_PRODUCT_TAB} to make it display last (before Comments, whose code comes even further down). Note that it is the order of these lines of code that determines where the tab goes, not the name of the ID tag.

Then, somewhere below {$HOOK_PRODUCT_TAB}, within the div add

{if $product->location}
<div id="idTab100" class="rte">
...
</div>
{/if}

where ... symbolize what you want to be shown in the tab.
I use the location field to mark the item as a book, and so the if statement makes the tab only show for books, you may use something else there, whatever fits your needs.

Saturday, June 5, 2010

Prestashop as Bookstore Part 2 - Book Series & Publishers

I have done several modifications to make PrestaShop usable as a bookstore and I will try to sum it up in a few blog posts.

Today I'll talk a little about more information I like to have in my Bookstore, eg the Publishers of the books.

I understand if my needs are not the same as most Bookstores have, but these modifications were very valuable for my needs.
First of all, listing the Publishers, to be able to find all books from a certain Publisher is almost a must for me.
And also, lots of my books are part of a series of books, so listing all books in a series is a really good thing for me.

First off I translated Manufacturers and Distributors to Publisher and Book Series.

I then used the Location field for the ISBN number and by leaving this field empty for other items I can determine if a item is a book or not (for books without ISBN I just put "none" in the field.

I put the info in the same block as the Authors, like this
(continued from last post's chunk of code, in themes/product.tpl)

{if $product->manufacturer_name}
<div id="short_description_content" class="rte align_justify">
{if $product->location}
{l s='Publisher'}:
<a href="{$link->getmanufacturerLink($product->id_manufacturer, $product->link_rewrite)|escape:'htmlall':'UTF-8'}" title="{l s='List books from'} {$product->manufacturer_name|escape:'htmlall':'UTF-8'}">{$product->manufacturer_name|escape:'htmlall':'UTF-8'}</a>
{else}
{l s='Manufacturer'}:
<a href="{$link->getmanufacture
rLink($product->id_manufacturer, $product->link_rewrite)|escape:'htmlall':'UTF-8'}" title="{l s='List items made by'} {$product->manufacturer_name|escape:'htmlall':'UTF-8'}">{$product->manufacturer_name|escape:'htmlall':'UTF-8'}</a>
{/if}
</div>
{/if}

As you may see in the code above, I later realized that I could use Manufacturers for their "real" use when not dealing with books.

{if $product->supplier_name}
<div id="short_description_content" class="rte align_justify">
{l s='Supplier'}:
<a href="{$link->getsupplierLink($product->id_supplier, $product->link_rewrite)|escape:'htmlall':'UTF-8'}" title="{l s='List books in the series'} {$product->supplier_name|escape:'htmlall':'UTF-8'}">
{$product->supplier_name|escape:'htmlall':'UTF-8'}</a>
</div>
{/if}
{if $product->location != ''}
<div id="short_description_content"
class="rte align_justify">
{l s='ISBN'}: {$product->location}
</div>
{/if}
{if $product->ean13 != ''}
<div id="short_description_content" class="rte align_justify">
{l s='EAN'}: {$product->ean13}
</div>
{/if}
</div>
</p>

And last in the block I put the ISBN and/or EAN, which tends to be the same thing for most books (but not always) so I just figured why not. More information than one needs is better than less information than one wants...

Then I modified the settings in the Manufacturers and Distributors Blocks in the Admin part of Prestashop to not use plain text but a drop-down list.

I also did some more translations so it says "Select Series" etc.



In the future I'd like to split up the Distributors Block in two so that one is for Publishers and one for Manufacturors, but right now they are mixed together.

This is how the product view looks for a book after the modifications.









and this is how it looks for a non-book.





Wednesday, June 2, 2010

Prestashop as Bookstore Part 1 - Authors

I have done several modifications to make PrestaShop usable as a bookstore and I will try to sum it up in a few blog posts.

First off I'll try to explain how I handled authors.

Some others have used eg Manufacturers for this job, renaming Manufacturers to Authors kind of does the job, but there are a couple of issues with this solution. Most important for me was that the authors of the books that I sell often work together with others, and several authors have written many books.
Basically, what I needed was a one to many relationship, ie if I chose a author I'd like to see all books that s/he has written, as a sole author as well as those together with others.
Manufacturers and Distributors don't work like this so I had to look for another solution.

I decided to use Tags. This is not optimal, but for my purposes it works quite good.

First thing to do is translate Tags to Authors (and the equivalent for other languages that you use), using Tools, Translations in the Back Office.

Then I wanted the Tags Block to look like eg the Manufacturers Block.
By looking at the code in modules/blocktags and modules/blockmanufacturer I came up with this for modules/blocktags/blocktags.tpl

<!-- Block tags module -->
<div id="tags_block_left" class="block blockmanufacturer">
<h4>{l s='Tags' mod='blocktags'}</h4>
<div class="block_content">
{if $tags}
<form action="{$smarty.server.SCRIPT_NAME}" method="get">
<p>
<select id="tags_list" onchange="autoUrl('tags_list', '');">
<option value="0">{l s='All tags' mod='blocktags'}</option>
{foreach from=$tags item=tag}
<option value="{$base_dir}search.php?tag={$tag.name|urlencode}">{$tag.name}</option>
{/foreach}
</select>
</p>
</form>
{else}
{l s='No tags specified yet' mod='blocktags'}
{/if}
</div>
</div>
<!-- /Block tags module -->

Then I wanted the author(s) to show when I view the product, in themes/prestashop (or whatever themes folder name you have)/product.tpl
After

<div id="pb-left-column">

add

<div id="short_description_block">

(This is to create a separate block where authors and other information will go, it will show right above the short description block.)

{if $product->tags}
<div id="short_description_content" class="rte align_justify">{l s='Tags'}:
{if $lang_iso == se} {assign var='lng' value=4}
{else} {assign var='lng' value=1}
{/if}
{assign var='tag1' value=$product->tags[$lng]}
{foreach from=$tag1 item=author}
<a href="{$base_dir}search.php?tag={$author}" title="{l s='List books by'} {$author}">{$author}</a>
{/foreach}
</div>
{/if}
</div>

(The last line is of course to end the block, more will be added in this block later.)

All texts inside {l s='...'} can and should be traslated in the BO.

I didn't find what variable contains the numeric code for the language, and it seems to be a great secret because nobody at the PS Forum seems to know either, so I did the ugly workaround using the if statement above.

Now I just added the authors as tags on each book.
Note that it has to be done for each language you use.

The modifications described above were made about six months ago, so I may have forgotten something in the description. Please feel free to ask if something is unclear!