News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Store recently viewed produsts in cookie - not session

Started by el02154, December 20, 2020, 21:13:36 PM

Previous topic - Next topic

el02154

Hello to all,

I hope all of you are healthy :) . I would like to ask if anyone has find a way to store recently viewed products in a cookie and not session. This requiest comes from a client that wants to be able to show recently viewed products for 5-10 days after a using comes back to site. The current function is to show the products until the session ends, after that it starts counting from zero.

GJC Web Design

the browsed products are added to the session in the shop function static public function addProductToRecent ($productId)
components\com_virtuemart\helpers\shopfunctionsf.php

I guess a plugin that stores that session object vmlastvisitedproductids to a cookie
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

el02154


el02154

Hello,

Happy new year to all. If I create a new function same to this but with the only difference that instead of session I will use cookie then how I can retrieve this cookie and show the products?

el02154

In addition, I have added the following in addProductToRecent function:

      $inputCookie = JFactory::getApplication()->input->cookie;
      $inputCookie->set($name = 'vmlastvisitedproductids_cookie', $value = $products_ids, time() + (86400 * 30));

but when I try to retrieve this cookie it does not exist. Does anyone have an idea of the reason?

Studio 42

$inputCookie = JFactory::getApplication()->input->cookie;
$inputCookie->set($name = 'vmlastvisitedproductids_cookie', $products_ids);
$inputCookie->getString('vmlastvisitedproductids_cookie');

see https://api.joomla.org/cms-3/classes/Joomla.Input.Cookie.html
I dont think that a timestamp can be set
You have to convert the cookie to a string and use getString()
Or if you set an array in the cookie use getArray()
Get without filters save a command (filter is az-_  only)

el02154

#6
Thanks for the answer. I managed to create cookie but the expiration time is the same as the creation one and is marked as deleted! Can you help on this?

UPDATE: I am trying to modify "addProductToRecent" function and use cookie instead of session but nothing happens. It is like I never create the cookie...

Studio 42

please copy your code here.
I cannot know what you write wrong.