Jump to content

[SOLVED : MADE A MODULE]Is there a module for favorite products for a customer or a list of his bought products?


Recommended Posts

Hi guys,

a question.
on my site I have over 15.320 products online.
Now I have some clients that order always the same 40 products.

Is there a module where - after a customer has been logged in - the customer can see a list of products he/she bought with a direct link to this product?
or that the customer can add products to a favorite list?

I think this would be amazing for customers to do a quick order.(Version 1.3.11 :-) )

any clue, tip?

thx

Link to comment
Share on other sites

PrestaShop comes with a viewed products block that displays products the customer has viewed and there is a cross-selling module that displays products that other customers who bought the current product also bought, but there is no module I'm aware of that displays products bought by the currently-logged-in customer. It would be pretty easy to do though. You'd just need to copy a module like the best sellers module or specials module and use the following query to get the bought products and pass them in to the TPL:

$result = Db::getInstance()->executeS('SELECT DISTINCT p.`id_product`, p.`price`, pl.`name`, pl.`description_short` FROM `'._DB_PREFIX_.'order_detail` od LEFT JOIN `'._DB_PREFIX_.'orders` o ON (od.`id_order` = o.`id_order`) LEFT JOIN `'._DB_PREFIX_.'product` p ON (od.`product_id` = p.`id_product`) LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product`) WHERE o.`id_customer` = '.intval($cookie->id_customer).' AND pl.`id_lang` = '.intval($cookie->id_lang));

Link to comment
Share on other sites

Hi rocky,

you again who answers me :-)

ps : how can I make sure the module will only be displayed the moment the customer is logged in.
if normal visitors are on my site, I don't want them to show this list.

any idea?

thx m8

Link to comment
Share on other sites

You can add code like the following in the PHP file to prevent the SQL query being run:

if ($cookie->id_customer > 0)



and use code like the following at the start of the TPL file:

{if $logged}



and the following at the bottom:

{/if}



so that the code is only displayed when a customer is logged in.

Link to comment
Share on other sites

Try changing the hookRightColumn function to:

function hookRightColumn($params)
{
   global $smarty, $cookie;

   $best_sellers = array();

   if ($cookie->id_customer)
       $best_sellers = Product::getProductsProperties(intval($cookie->id_lang), 
           Db::getInstance()->executeS('
               SELECT DISTINCT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`
               FROM `'._DB_PREFIX_.'orders` o 
               LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order` = o.`id_order`)
               LEFT JOIN `'._DB_PREFIX_.'product` p ON (od.`product_id` = p.`id_product`)
               LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($cookie->id_lang).')
               LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
               LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.intval($cookie->id_lang).')
               LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = p.`id_tax`)
               WHERE o.`id_customer` = '.intval($cookie->id_customer).' AND pl.`id_lang` = '.intval($cookie->id_lang).'
               ORDER BY RAND()
               LIMIT 0, 15'));

   $smarty->assign(array(
       'best_sellers' => $best_sellers,
       'mediumSize' => Image::getSize('medium')));
   return $this->display(__FILE__, 'blockbestsellers.tpl');
}

Link to comment
Share on other sites

Hi Rocky

I just changed as test the bestsellers, and in the .bestsellers.php I changed the code you pasted here.
but I seems to be a problem.

Now I just bought something on my test account :-)
the product is now properly displayed.
but I miss a picture??? (see pictures)
the link of the missing picture is : -medium.jpg
so it seems to look for a product but does not know what.
and the moment I click on the button (all best sellers) I don't get the customers list but an other list...

and clicking on the product link (Köning internet radio) gets me the account page?

any clue?

26038_7k6YyWZ6vvgrBmYl72oG_t

Link to comment
Share on other sites

Rocky indeed,

this is working better.

only the button : all bestsellers should be a total list of the customers products....any idea how to achieve this?
or will this not be possible?

I also did a test to order over 100 products...the list is then very large, no option to show only last 10 products and by clicking the link : all products, we must have his list...

i'm not very easy hey :-)

Link to comment
Share on other sites

Try creating a new file called bought.php and paste the following:

<?php

include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/header.php');
include(dirname(__FILE__).'/product-sort.php');

$best_sellers = array();

if ($cookie->id_customer)
       $best_sellers = Product::getProductsProperties(intval($cookie->id_lang), 
           Db::getInstance()->executeS('
               SELECT DISTINCT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`
               FROM `'._DB_PREFIX_.'orders` o 
               LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order` = o.`id_order`)
               LEFT JOIN `'._DB_PREFIX_.'product` p ON (od.`product_id` = p.`id_product`)
               LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($cookie->id_lang).')
               LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
               LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.intval($cookie->id_lang).')
               LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = p.`id_tax`)
               WHERE o.`id_customer` = '.intval($cookie->id_customer).' AND pl.`id_lang` = '.intval($cookie->id_lang)));

$nbProducts = sizeof($best_sellers);
include(dirname(__FILE__).'/pagination.php');

$best_sellers = array_slice($best_sellers, (intval($p) - 1) * intval($n), intval($n));

$smarty->assign(array(
   'products' => $best_sellers,
   'nbProducts' => $nbProducts));

$smarty->display(_PS_THEME_DIR_.'best-sales.tpl');

include(dirname(__FILE__).'/footer.php');

?>



Then change the link in the TPL file to bought.php instead of best-sales.php.

Link to comment
Share on other sites

And solved.

your rocky Rocky :-)

ps : maybe I must look now to change the best_sellers name in to a new module
but I think this will not work.
I want other user to use this also but sometimes together with the best_seller module.

Do I Include one time all my files in here so you can have a look if we can change this into : blocksellhistory or something?
would be awsome for other user no?

Link to comment
Share on other sites

I've modified the module to be its own module instead of a modification of the best sellers module. I've also made it so bought.php is read from the module's directory so that it doesn't need to be copied to the root directory, so that you can just click "Install" and not have to worry about doing anything else. Let me know if it works for you.

Link to comment
Share on other sites

Hi rocky,

the file bought.php is not in the root.
and it seems that the translations can not be found in the translation backoffice;

okey found out you leave the bought.php in the module folder
only when I open the list bought I get errors :

Warning: include(/home1/eshopbel/public_html/modules/blockbought/config/config.inc.php) [function.include]: failed to open stream: No such file or directory in /home1/eshopbel/public_html/modules/blockbought/bought.php on line 3

Warning: include() [function.include]: Failed opening '/home1/eshopbel/public_html/modules/blockbought/config/config.inc.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php') in /home1/eshopbel/public_html/modules/blockbought/bought.php on line 3

Warning: include(/home1/eshopbel/public_html/modules/blockbought/header.php) [function.include]: failed to open stream: No such file or directory in /home1/eshopbel/public_html/modules/blockbought/bought.php on line 4

Warning: include() [function.include]: Failed opening '/home1/eshopbel/public_html/modules/blockbought/header.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php') in /home1/eshopbel/public_html/modules/blockbought/bought.php on line 4

Warning: include(/home1/eshopbel/public_html/modules/blockbought/product-sort.php) [function.include]: failed to open stream: No such file or directory in /home1/eshopbel/public_html/modules/blockbought/bought.php on line 5

Warning: include() [function.include]: Failed opening '/home1/eshopbel/public_html/modules/blockbought/product-sort.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php') in /home1/eshopbel/public_html/modules/blockbought/bought.php on line 5

Warning: include(/home1/eshopbel/public_html/modules/blockbought/pagination.php) [function.include]: failed to open stream: No such file or directory in /home1/eshopbel/public_html/modules/blockbought/bought.php on line 23

Warning: include() [function.include]: Failed opening '/home1/eshopbel/public_html/modules/blockbought/pagination.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php') in /home1/eshopbel/public_html/modules/blockbought/bought.php on line 23

Fatal error: Call to a member function assign() on a non-object in /home1/eshopbel/public_html/modules/blockbought/bought.php on line 27



change the link back to :

Link to comment
Share on other sites

I deleted the translations. Since I renamed "Best Sellers" to "Bought Products", those translations wouldn't have worked anyway. You'll need to retranslate the module.

I don't understand what you mean by "bought.php is not in the root". I just checked and it is in the archive in the blockbought folder. Now that the file is read from the module's directory, it doesn't need to be in the root directory of PrestaShop anymore.

Link to comment
Share on other sites

well rocky

the error I get is , that I seems that when clicking on the show all, the page must be loaded : /modules/blockbought/bought.php

but my server and my test server seems to have difficulties with the paths in the file like :
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/header.php');
include(dirname(__FILE__).'/product-sort.php');

so I think we must check if this is correct?
since the file bought.php is not longer in the root folder but in the module folder.

I tried to change this to :
include(_PS_ROOT_DIR_.'/config/config.inc.php');
include(_PS_ROOT_DIR_.'/header.php');
include(_PS_ROOT_DIR_.'/product-sort.php');

but no luck also

Link to comment
Share on other sites

well rocky

I tried several methodes in the bought.php to link the config files etc..no luck.

anyway in order to force translations, because if you open the bought.php you get the translations of the bestsellers,
I made an extra file.

I have my version here for all the others who want to use it.
just read the .txt file inside.
and you will have this running in 5 min. :-)

good luck to all

and rocky, if you know a solution to make the paths in bought.php correct, let me know.
I change this module.

greetz

blockbought.zip

Link to comment
Share on other sites

You are right. I've fixed the problem. I decided to add a configuration page to this module, brand it and release it as a free module on my website. I've sent you the module in a PM. If the module works for you, I'll release it on my website and create a separate topic for it.

Link to comment
Share on other sites

  • 3 years later...
  • 1 month 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...