Jump to content

Choosing Product's attributes in Home Featured?


Juandbbam

Recommended Posts

Hello,

At the moment I can choose the default attributes for the Home Featured products. But is there a way of including a drop down menu (like in Products) where the user can choose the product's attributes also in the Home Featured area?

Thank you in advance for your help.

Link to comment
Share on other sites

  • 3 weeks later...

Since I posted in this thread, I had a go and tried to develop a module for this.

It is still under dev. and I don't have a version to release yet, but I did some nice breakthrough.

I am posting regularily on the french forum to get some help on the problems I encounter on this module:
http://www.prestashop.com/forums/viewthread/37676/

I'll update this thread as soon as I have something to release, and I'm getting there.

Link to comment
Share on other sites

As I said in a previous module, I really want to be able to have a buy button for each of the main attrubutes and prices.

So from line 235 on 'products.tpl'

I need this

{if isset($groups)}

<!-- attributes -->


{foreach from=$groups key=id_attribute_group item=group}


{$group.name|escape:'htmlall':'UTF-8'} :
{assign var='groupName' value='group_'|cat:$id_attribute_group}

{foreach from=$group.attributes key=id_attribute item=group_attribute}
{$group_attribute|escape:'htmlall':'UTF-8'}
{/foreach}


{/foreach}

{/if}



For each of the home featured items - better still a buy button for each.

Its clear to see which variables I need from here, but I'd like someone to help - I have no ideas where this comes from/inherits etc and the system is starting to baffle me a bit.

Any help would be amazing.

Cheers
Link to comment
Share on other sites

hey there,

If I got it well, I think I have what you need.

Have a look at the module attached, that I just finished a couple of minutes ago !

It is to be hooked on the home.
It is very basic in terms of layout and styling, but it shows, for each product, a list of its attributes (or to be more precise combinations) with their name and price.

But you can customize it, quite easily. You can add more information, such as quantity or weight... And from there you could add an 'add to cart' button.
Actually I'm gonna need it as well so I'll keep on working on it, but I'm not sure when I will have time, so you might want to try it yourself.

If you need to know what you can display from the template, just add:

{$product.combinaisons|print_r}




before the loop l.26

enjoy

Any help to improve it would be welcome !

homedeclinaisons.zip

  • Like 1
Link to comment
Share on other sites

Oups I was a bit too impatient to share my piece of work and I forgot what was specific to my setup of prestashop.

There is one thing you will have to setup manually in the code so that it displays products: it's a category ID, on l. 30 of homedeclinaisons.php.

here is an extract:

function hookHome($params)
   {
       global $smarty;
       $category = new Category(6); // A MODIFIER POUR FILTER LA CATEGORIE 
       $nb = 20; // AJOUT Nb de resultats retournés par default



l.30 is $category = new Category(6);
Instead of 6, put any category id featuring the products you want to show. You may not have any category with this actual ID.
The reason why products are displayed depending on one specific category is because I started to develop this module by copying the module homefeatured and then tweaking it. In this original module, products are displayed on the home page because they belong to the main category.

This variable being in the module script is a bit tricky.
This is something I will improve for my own needs. I think I'll try to improve the module so that one can select the category to display from the backoffice.

Thanks

Link to comment
Share on other sites

  • 4 weeks later...

here is the latest version (see attached) with one add to cart button per combination

In order to use the ajax cart you must add a couple of lines of code to allow the JS to spot the id_attribute from the href and use it to update the cart.

In modules/blockcart/ajax-cart.js you have (L. 10):

ajaxCart.add(idProduct, null, false, this);



you have to add instead:

var varCombinationHref = "id_product_attribute=";
var positionCombinationHref = $(this).attr('href').indexOf(varCombinationHref);
           if(positionCombinationHref != -1) {                
               var positionCombinationVar = positionCombinationHref + varCombinationHref.length;
               var positionCombinationFin = $(this).attr('href').indexOf("&",positionCombinationVar);
               var idCombination =  $(this).attr('href').substring(positionCombinationVar,positionCombinationFin);
           } else {
               idCombination = null;
           }

           ajaxCart.add(idProduct, idCombination, false, this);



and that should do it !

v3_homedeclinaisons.zip

Link to comment
Share on other sites

Fabulous - as my post suggest on the other thread open for this, I have had success in integrating parts of your code into the 'homefeatured' module on the home page - every item on homefeatured now has a button for all attributes!

NEXT hehe

does anybody have any ideas how I could get the attributes buttons on the search result pages.... for example, the page that shows when you click one of the categories down the side, such as 'laptops' - then the category.php?id_category page results of the relevant page appear.

I would ideally like to get a button for the three attributes on there too.

All help is extremely greatfully recieved!

Blake

Link to comment
Share on other sites

Hey Blake,

I haven't done this yet but I've got an idea of how you might achieve that.

All the templates and pages that list products, like te search result page and the category.php page, use themes/prestashop/product-list.tpl

The html/smarty code in there looks quite similar to the lines you can find in homefeatured.tpl (and that you modified).
so you can try and add your lines or mine and put them in there.

The tricky part is to allow the script to use our custom built function getAttributesGroups and this is something that needs to be copied and modified in the php files of each page (which doesn't sound very optimised) or in the class files... Or so I think.

I'll try this at some point. If you have any luck with this, feel free to share :)

Link to comment
Share on other sites

Hi Simon

I see where you are coming from - I thought I had it for a sec....

On line 60 of category.php, I located the smarty array, then wrapped it in a bit of code from 'homedeclinaisons' so that it looked like this::

//Boucle sur les produits pour récupérer leur déclinaisons        
       for($i=0;$i            $attributesGroups = $this->getAttributesGroups($current_id_lang,$products[$i]['id_product']);
           // Insere le tableau des combinaison dans le tableau des produits, en associant chaque produit a son tableau de combinaisons
           $products[$i]["combinaisons"] = $attributesGroups; 
       }
       $smarty->assign(array(
           'products' => (isset($cat_products) AND $cat_products) ? $cat_products : NULL,
           'id_category' => intval($category->id),
           'id_category_parent' => intval($category->id_parent),
           'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name)),
           'path' => Tools::getPath(intval($category->id), $category->name)
       ));
       // AJOUT
       function getAttributesGroups($id_lang,$id_product)
       {        
           return Db::getInstance()->ExecuteS('
           SELECT ag.`id_attribute_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name,
           a.`color` AS attribute_color, pa.`id_product_attribute`, pa.`quantity`, pa.`price`, pa.`ecotax`, pa.`weight`, pa.`default_on`, pa.`reference`
           FROM `'._DB_PREFIX_.'product_attribute` pa
           LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
           LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
           LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
           LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON a.`id_attribute` = al.`id_attribute`
           LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON ag.`id_attribute_group` = agl.`id_attribute_group`
           WHERE pa.`id_product` = '.intval($id_product).'
           AND al.`id_lang` = '.intval($id_lang).'
           AND agl.`id_lang` = '.intval($id_lang).'
           ORDER BY pa.`id_product_attribute`');
       }



I thought that i could then access 'combinaisons' in the product array in the product-list.tpl file, but I have had no joy.

Kinda moving out of my comfort zone here so any help would be amazing!

Blake

Link to comment
Share on other sites

hmm i could see that the product variable in the category.php file was actually $cat_products, so I changed the code below so that the function worked off the $cat_products class thinking that this might work...


//Boucle sur les produits pour récupérer leur déclinaisons        
       for($i=0;$i            $attributesGroups = $cat_products->getAttributesGroups($current_id_lang,$cat_products[$i]['id_product']);
           // Insere le tableau des combinaison dans le tableau des produits, en associant chaque produit a son tableau de combinaisons
           $cat_products[$i]["combinaisons"] = $attributesGroups; 
       }



No joy again though, simply won't even render the page!

Link to comment
Share on other sites

if it doesn't render, it's usually (in most of the case for me anyway) because there is flaw in the syntax

did you wrote all this code within the if () { } ?

if so I would say that you have to move the function declaration out of it.
try to put it at the very bottom of the php script.

This function shouldn't be sitting here anyway.

Link to comment
Share on other sites

The pb is definitely coming from the call of the function and its position.

It appears to me than the best position for this piece of code (the function declaration) should be in the class file ( /classes/Category.php ). Put it at the end and use this to declare it:

public function getAttributesGroups($id_lang,$id_product) {
...




Then the call of the function was wrong in your file in the for() loop (in category.php):
it was:

$attributesGroups = $cat_products->getAttributesGroups($current_id_lang,$cat_products[$i]['id_product']);


it should be:

$attributesGroups = $category->getAttributesGroups($cookie->id_lang,$cat_products[$i]['id_product']);

Link to comment
Share on other sites

Progress!

I declared a public function as you suggested at the bottom of the category class

public function getAttributesGroups($id_lang,$id_product)
       {        
           return Db::getInstance()->ExecuteS('
           SELECT ag.`id_attribute_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name,
           a.`color` AS attribute_color, pa.`id_product_attribute`, pa.`quantity`, pa.`price`, pa.`ecotax`, pa.`weight`, pa.`default_on`, pa.`reference`
           FROM `'._DB_PREFIX_.'product_attribute` pa
           LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
           LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
           LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
           LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON a.`id_attribute` = al.`id_attribute`
           LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON ag.`id_attribute_group` = agl.`id_attribute_group`
           WHERE pa.`id_product` = '.intval($id_product).'
           AND al.`id_lang` = '.intval($id_lang).'
           AND agl.`id_lang` = '.intval($id_lang).'
           ORDER BY pa.`id_product_attribute`');
       }


Then I tidied up the function call so that it now reads

for($i=0;$i            $attributesGroups = $category->getAttributesGroups($cookie->id_lang,$cat_products[$i]['id_product']);
           // Insere le tableau des combinaison dans le tableau des produits, en associant chaque produit a son tableau de combinaisons
           $cat_products[$i]["combinaisons"] = $attributesGroups; 
       }



and now if i type {$product.combinaisons|print_r} in 'product-list.tpl' it returns the relevant values!

its rough around the edges, but its a very good start! I now need to extract the correct values and pass them to the cart

(i have already managed this on the product page, so I'm hoping that it will be rudimentarily the same)

Link to comment
Share on other sites

I'm sorry to say, but you may be chasing a lost cause....

As you may know, there is a problem with attributes when you have too many combinations for one product.

What you are trying to do will potentially increase the number of combinations, so unless you plan on having very few attribute groups with very few items in them, you may end up finding out that your page will break.

Link to comment
Share on other sites

I only have one attribute group and max 3 attributes per item.

How could this cause me to have any problems? Seems to work fine so far, basically the guy I am doing it for sells health supplements - for example vitamin C - this then comes in 60, 120 & 360 tab bottles.

Basically, for all of its whistles and bells, I think that prestashop really fails in this respect - it has taken me a huge amount of time and effort to try to understand how it all workks and then hack pshop.

We all know fickle web users can be - if you don't give a person the chance to buy something the second they see it, but rather presume that a user will be willing to navigate a number of clicks into the site until they find and obscure drop down, then you don't have to be a genius to see that conversions will be harmed.

I'm quite keen to hear how other people feel about this.

Either way, I am extremely thankful to Tomer and Simonthetemp for their priceless help.

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 months later...
  • 1 month later...

Hi,

I'm changing the code to have a combo-box in the product list, to purchase the combination without enter in the product details.
It's not yet solved, but when it was, you can add this functionality to the module.

You can follow it (and may be help) in the third page of:
http://www.prestashop.com/forums/viewthread/37676/P30/modules_tiers/montrer_les_combinaisons_et_attributs_dans_les_listes_produits/

Thanks!!

Link to comment
Share on other sites

Hi everybody,

I have the combo box running in the main page (see the code ant explanation in http://www.prestashop.com/forums/viewthread/37676/P30/modules_tiers/montrer_les_combinaisons_et_attributs_dans_les_listes_produits/), but to take the selected value when you push the add-to-cart button it's impossible, once the page is displayed the parameter in the href doesn't change. I've tested referencing he DOM of the select by id in the page, but no way.

Someone have any idea how to catch, from a href, the value of the select outside the select itself?

Link to comment
Share on other sites

  • 1 month later...
Hi,

I'm changing the code to have a combo-box in the product list, to purchase the combination without enter in the product details.
It's not yet solved, but when it was, you can add this functionality to the module.

You can follow it (and may be help) in the third page of:
http://www.prestashop.com/forums/viewthread/37676/P30/modules_tiers/montrer_les_combinaisons_et_attributs_dans_les_listes_produits/

Thanks!!


SOLVED!!!

Finally I've had time enough. If someone is interested I'll tidi the code and put the files here.
Link to comment
Share on other sites

  • 4 weeks later...
Yes ! It would be appreciated by the guys here ;-) Just : is it for v1.3.1 ?

... and thanks 4 us


Yes, it's for the 1.3.1

sorry for my delay, I'm in a rush these days.

I explained le chage in french in the post http://www.prestashop.com/forums/viewthread/37676/P45/modules_tiers/montrer_les_combinaisons_et_attributs_dans_les_listes_produits/

If someone needs further explanations just ask me.

I attache the file (must do the changes of the previous posts in homedeclinaisons.php, etc..)

I hope it helps someone, thank for the module to the creators.

homedeclinaisons.txt

Link to comment
Share on other sites

  • 4 weeks later...

Someone has tried to show the product in pages?

In the php and tpl files the number of products to show it's fixed to 20.

So, I think it would be very interesting to show it like in a cathegory, it is by pages of n products per page, and the page number in the bottom.

Any ideas?

Link to comment
Share on other sites



Many Tanks, it's very interesting.
Now the choose of declinaisons is more or less solved (not the quantity, it's true) with a combo box.

I will page the results in the home page. Anyone has tried this?
Link to comment
Share on other sites

I have tried this in 1.3.2 and it works very well on the homepage , on the product-list it more difficult . Hope you can figure it out
Regards
Ken


Well, I'm not a formed programmer in php + js + tpl, so... Any clue?

I'm only interested in paging the homepage.

I supose I must chage the select that gets the products in the php to put limits, and in the tpl manage the number of items, and the limits also.
Well, before all I have to understand how to pass values between those, etc.

Advise or pieces of code are wellcome.
Link to comment
Share on other sites

  • 7 months later...
  • 3 weeks later...
  • 2 months later...
  • 6 months later...
  • 3 weeks later...
  • 3 weeks later...
  • 5 months later...
  • 1 month later...

HI.

What i want is really a simple feature, but i don't know how to do it.

 

If my products does not have attributes, you should see the button to "Add to cart".

If they have attributes, you should see a button "Configure Product" with a link to the product page.

 

 

How to achieve this?

Link to comment
Share on other sites

  • 4 years later...

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...