Sunday, December 9, 2012

Suppliers...

I wanted to show a list of Suppliers on the left and if one was clicked show a page in the center with address etc to that Supplier.
This showed to be quite a challenge.

The first obstacle was that the link on the title SUPPLIERS didn't work (this was not important, but annoying).
It turned out that I had to check Display suppliers and manufacturers in Preferences/General, which may seem natural except for the description of what that meant, which reads Display suppliers and manufacturers lists even if corresponding blocks are disabled.
My Manufacturers Block is disabled, but of course no Manufacturers showed when I ticked Yes...

No, the first obstacle was that the logos didn't show up with IE. This was because $mediumSize.width and $mediumSize.height wasn't defined, I removed that code and hardcoded a width of 200.

Then for the contact information for the Suppliers.
The module is meant to just list all products supplied by the Suppliers, I don't know why there is address etc to be filled out in the BO because AFAIK that information is never used anywhere.

I had to make the information available to themes/supplier.tpl
I inserted code in classes/supplier.php to fetch it from the database, it turned out to be the wrong place and/or file so I won't give all details but basically
$query->select ' ... a.`id_supplier.address1`');
$query->leftjoin('address', 'a', 's.`id_supplier` = a.`id_supplier`');

This turned out to make the address available to themes/supplier-list.tpl but not to themes/supplier.tpl so I did a ugly hack in suppliercontroller.php
I had the data in $suppliers but not in $this->supplier, so I looped through $suppliers and pulled the wanted fields into standalone variables, i.e.
$addr1 = $row['address1'];
and make those available with i.e.
'addr1' => $addr1

Finally I could use e.g. {$addr1} in themes/supplier.tpl


Saturday, December 8, 2012

Header stuff

I've been goofing around a bit with 1.5.2, setting up a new store where I will sell handicraft that I make.

I wasn't all too happy with the header so I made some changes, this is the header taken from the PS demo page
And this is my header


I'm not too good at logo designing so I just took a picture of wood grain and cut out a slice for a banner, and added the text with paint.net, I may have made some changes to the image, I don't remember.

The cart and possibly the search box either didn't show up clearly or was too distinct (again, I don't remember) so I added opacity, and made the text black in the CSS

filter:alpha(opacity=60);

-moz-opacity:0.6;
-khtml-opacity: 0.6;
opacity: 0.6;


color:black;
I also used opacity on the active language's flag (as opposed to the behaviour in 1.4 where the inactive language's flag(s) have opacity.)

To make the flags appear side by side, I changed modules/blocklanguages/blocklanguages.tpl
Basically, I removed the ul and li tags, this is my code after the change

<div id="languages_block_top_mod">

<div id="countries">
{foreach from=$languages key=k item=language name="languages"}
{if $language.iso_code != $lang_iso}
{assign var=indice_lang value=$language.id_lang}
{if isset($lang_rewrite_urls.$indice_lang)}
<a href="{$lang_rewrite_urls.$indice_lang|escape:htmlall}" title="{$language.name}">
{else}
<a href="{$link->getLanguageLink($language.id_lang)|escape:htmlall}" title="{$language.name}">
{/if}
{/if}
<img {if $language.iso_code == $lang_iso}class="opacity"{/if} src="{$img_lang_dir}{$language.id_lang}.jpg" alt="{$language.iso_code}" width="16" height="11" />
{if $language.iso_code != $lang_iso}
</a>
{/if}
{/foreach}
</div>
</div>


Then, for currencies, I changed modules/blockcurrencies/blockcurrencies.tpl
I removed

<form id="setCurrency" action="{$request_uri}" method="post">

<p>
<input type="hidden" name="id_currency" id="id_currency" value=""/>
<input type="hidden" name="SubmitCurrency" value="" />
{l s='Currency' mod='blockcurrencies'} : {$blockcurrencies_sign}
</p>
<ul id="first-currencies" class="currencies_ul">


and the closing form tag and the li tags.
This is how the code looks now

<div id="currencies_block_top"><b>

{foreach from=$currencies key=k item=f_currency}
{if $cookie->id_currency == $f_currency.id_currency}
<div id="selected">
{$f_currency.sign}
{else}
<div id="unselected">
<a href="javascript:setCurrency({$f_currency.id_currency});" title="{$f_currency.name}">{$f_currency.sign}</a>
{/if}
</div>










In the CSS, I changed #selected to

#selected {

background:white;
color:black;
filter:alpha(opacity=60);
-moz-opacity:0.6;
-khtml-opacity: 0.6;
opacity: 0.6;

Then I moved around the blocks a bit with CSS, but no magic in that. :-)
Not too much explaining, just some pasted code... Sorry about that, I'll try to remember more exactly what I change in the future...

Monday, December 3, 2012

PS 1.5 - warning, please wait for mature version!

Long time no blogging, I'll see if I can rectify that...

I've been playing around with PS 1.5.2 for a bit and I must say that 1.5 is not yet mature.
Some bugs I've found:
  • Installing 1.5.2 breaks other installations if same database is used! - I installed 1.5.2 and supplied db-prefix hk_, after install, all references to Swedish was wiped out from my old installation that has ps_ as db-prefix.
  • With a Swedish browser (tested with FF 16 and IE 9) and registring a new address as customer, El Salvador is proposed as country (see old blog post for plausible reason).
  • For apparently no reason, sometimes all products show up twise; if this happens, don't delete the duplicates since that removes the originals too.
  • When searching for products, either via the search box or by clicking a tag, some products are listed with a price of 0; in other views (featured, category etc) the price is shown OK). In the cart, prices are OK so no monetary risk but not very pretty.
  • The Suppliers Block is broken: The title bar is not a link, if code is changed to make it work clicking it shows "There are no suppliers." ($nbSuppliers that is supposed to hold the number of suppliers is 0 and no variables holds any supplier-info.)
  • The MoneyBookers Module has a small issue that the image that is supposed to show up has the wrong name in the code (or the image is not included/has the wrong name).
Annoyances:
  • It is getting increasingly difficult to get help via the forum.
  • I'm not sure if reporting bugs does any good since there is absolutely zero feedback.
  • Not that many Modules/Themes are ported/developed for 1.5 because, I would think, of the issues with that version.
I'll try to get back soon with some information on a couple of tweaks I've done.

Wednesday, July 6, 2011

Prestashop 1.4

Just upgraded and one important difference from earlier versions is that no(?) changes will take effect unless you first go to Preferences/Performance and change Force Compile to Yes and Cache to No.
After the code change and a verification of it being OK, don't forget to restore the settings or you will have a very slow site.

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

Tuesday, June 29, 2010

Vacation

Off to China for a little less than a month, so plolly no blogging fol a while

Thursday, June 24, 2010

Popups

In the picture in my last post there is one thing that may need extra explanation:
The texts "About the rank suggestion" and "About the book sizes" underneath the Data Sheet Tab.
They are links to pop-up windows, like this


















This is accomplished in a pretty crude way IMHO, in [themes folder]/css/global.css I added
/* pop up */
#layer1 {
position: relative;
visibility: hidden;
width: 250px;
height: 110px;
left: 0px;
top: 0px;
background-color: #fff;
border: 1px solid #000;
padding: 10px;
}
#layer2 {
position: relative;
visibility: hidden;
width: 250px;
height: 110px;
left: 0px;
top: 0px;
background-color: #fff;
border: 1px solid #000;
padding: 10px;
}
#close {
float: right;
}
/* /pop up */
then in [themes folder]/product.tpl beneath the code to display the features
<table border="0">
<tr>
<p>
<th style="text-align: left">
<a href="javascript:setVisible('layer1',true)">{l s='About the rank suggestion'}</a>
</th></p>
<th style="text-align: left">
<a href="javascript:setVisible('layer2',true)">{l s='About the book sizes'}</a>
</th>
</tr>
<tr>
<td>
<div id="layer1">
<span id="close"><a href="javascript:setVisible('layer1')" style="text-decoration: none"><strong>{l s='Hide'}</strong></a></span>
<p><br />{l s='Rank suggestions are taken from various websites and are sometimes also based on my personal ideas.'}<br />
{l s='If you have different opinions about what rank the reader should be when reading the book, please contact me!'}
<br /></p>
</div>
</td>
<td>
<div id="layer2">
<span id="close"><a href="javascript:setVisible('layer2')" style="text-decoration: none"><strong>{l s='Hide'}</strong></a></span>
<p><br />{l s='The book sizes are approximate.'}<br />
{l s='L = close to A4, about 26-28 cm high'}</br>
{l s='M = close to A5, about 19-22 cm high'}</br>
{l s='S = In-between A5 and A6, about 17-18 cm high'}</br>
{l s='XS = close to A6, about 14 cm high'}
<br /></p>
</div>
</td>
</tr>
</table>
and in [themes folder]/header.tpl
<script type="text/javascript" src="{$content_dir}/../../pop-up/popupDiv.js"></script>
And finaly in the folder directed to in header.tpl I created the file popupDic.js with the following content
/* -----------------------------------------------
Floating layer - v.1
(c) 2006 www.haan.net
contact: jeroen@haan.net
You may use this script but please leave the credits on top intact.
Please inform us of any improvements made.
When usefull we will add your credits.
------------------------------------------------ */
x = 20;
y = 70;
function setVisible(obj)
{
obj = document.getElementById(obj);
obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
}
function placeIt(obj)
{
obj = document.getElementById(obj);
if (document.documentElement)
{
theLeft = document.documentElement.scrollLeft;
theTop = document.documentElement.scrollTop;
}
else if (document.body)
{
theLeft = document.body.scrollLeft;
theTop = document.body.scrollTop;
}
theLeft += x;
theTop += y;
obj.style.left = theLeft + 'px' ;
obj.style.top = theTop + 'px' ;
setTimeout("placeIt('layer1')",500);
}
window.onscroll = setTimeout("placeIt('layer1')",500);

This solution was taken from http://javascript.internet.com/miscellaneous/popup-div.html