Jump to content

[SOLVED] Variable availability


mohsart

Recommended Posts

I've looked for a solution of this for a loong time now, but just can't get it to work, and I suspect that there is something fundamental that I just don't get.
Say I'd like to show the Manufacturer in the product list, how would I do that? What code in which .php file and what code in product-list.tpl)
And the same for if I'd like to show a Feature, say Weight?

Thanks!

/Mats

Link to comment
Share on other sites

You can use {$product.manufacturer_name} and {$product.supplier_name} in product-list.tpl to display the manufacturer and supplier names. Unfortunately, product features are not available in product-list.tpl, since it is the getProducts() function in classes/Category.php that gets only some of the product information in an array, rather than as objects that contain all the data. I think this was done to reduce the load time of the product listings.

Link to comment
Share on other sites

Oh, wow. I thought I tried that, and now I cannot test it because I've got a "hack attempt"...
Anyways, regarding the features: how would I do to make them available?
Some code in classes/category.php or somewhere else?

/Mats

Link to comment
Share on other sites

Got rid of the hack attempt and it seems OK. Thanks!

A side question though: If you look on this page http://mohsart.se/lang-en/bocker-pa-engelska/234-100-tips-for-amateur-players-vol-1.html you see three links of which the two first works the same in this respect (manufacturer is shown in the results list) but the third does not.
This is not really of any interest for the functionality, but it got me kind of curious as to why. Is there another .tpl file that is called?
This is in product.tpl, of course.
Code for second link (working as expected)

{l s='Publisher'}:
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'}


Code for third link (not working as expected)

{l s='Supplier'}: 
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'}



/Mats

Link to comment
Share on other sites

The reason is that the third page is a supplier page, so it passes in $product.supplier_name instead of $product.manufacturer_name. You'll need to change line 23 of product-list.tpl from:

{l s='Publisher'}: {$product.manufacturer_name}



to:

{l s='Publisher'}: {if $page_name == 'supplier'}{$product.supplier_name}{else}{$product.manufacturer_name}{/if}



But I suppose if the supplier is different to the publisher, that won't work. You may need to modify the getProducts() function in classes/Supplier.php so that it gets the manufacturer name like the getProducts() function in classes/Manufacturer.php.

Link to comment
Share on other sites

Thanks.

I guess I need to dust off my SQL skills, was more than 10 years since I last had to do something more complicated than a simple SELECT...
You wouldn't know of somewhere this is done (or something similar) that could help me figuring out how to do it?

BTW, what I want to do, exactly, is show tags as well as one feature. Which in my case equals the Author(s) and a rating recommendation respectively for the books I'm selling.
But I guess the feature is the most complicated one, so maybe I'll start with the tags...

/Mats

Link to comment
Share on other sites

Am I on the right track with this?

category.php:

SELECT
...
tg.`name`    AS tag_name,
rk.`value`    AS rank,
...
LEFT JOIN `'._DB_PREFIX_.'product_tag` tmp ON tmp.`id_product` = p.`id_product`
LEFT JOIN `'._DB_PREFIX_.'tag` tg ON tg.`id_tag` = tmp.`id_tag`
LEFT JOIN `'._DB_PREFIX_.'feature_product` r ON r.`id_product` = p.`id_product`
LEFT JOIN `'._DB_PREFIX_.'feature_value_lang` rk ON rk.`id_feature_value` = r.`id_feature_value`
...


I suspect that it's not good enough for tags, since there can be more than one tag per product, but I expected to get something to show by using

{$product.tag_name}
{$product.rank}


in the tpl file
(I only use one feature per product)

/Mats

Link to comment
Share on other sites

That's because you forgot to include the id_lang field in the LEFT JOIN statement. You need to change:

LEFT JOIN `'._DB_PREFIX_.'tag` tg ON tg.`id_tag` = tmp.`id_tag`



to:

LEFT JOIN `'._DB_PREFIX_.'tag` tg ON (tg.`id_tag` = tmp.`id_tag` AND tg.`id_lang` = '.intval($id_lang).')



and:

LEFT JOIN `'._DB_PREFIX_.'feature_value_lang` rk ON rk.`id_feature_value` = r.`id_feature_value`



to:

LEFT JOIN `'._DB_PREFIX_.'feature_value_lang` rk ON (rk.`id_feature_value` = r.`id_feature_value` AND rk.`id_lang` = '.intval($id_lang).')

Link to comment
Share on other sites

I'll have to put the tags issue on hold for the time being. But I wonder one last thing about this.
When I do a search I don't see the feature, so I guess another .php file needs the changes also?
Also, to have it show up in the home featured page, what file should be changed?

Thanks.

/Mats

Link to comment
Share on other sites

Sorry for being such a pain in the xxx, but now that it's working in some places it's so frustrating :-/

I found another place where it doesn't work: When listing per tag. Maybe it's the same as Search?

Working: List per manufacturer, list per Supplier, list Category, Homefeatured

Not working: Search, List per tag, New Products, Specials(?)

I've looked through product-sort.tpl, search.tpl, prices-drop.tpl, search.php etc etc but cannot find any apropriate code...

/Mats

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...