:::: MENU ::::
Monthly Archives: October 2020

PrestaShop get current category information

Today we talk about how PrestaShop get current category information. You can use this code in hook related to the category page or controller and any other class. In this example, it will be shown the category name and category description, and other information. So let’s start with our example.

$categoryId = (int)Tools::getValue('id_category'); // get current category id
$categoryData = new Category ($categoryId,Context::getContext()->language->id); // get category object with id
$name    = $categoryData->name; // get category name
$description    = $categoryData->description; // get category description
Author: Qaisar Satti
Category: Prestashop
Last Modified: October 12, 2020


PrestaShop get current product information

Today we talk about how PrestaShop get current product information. You can use this code in hook related to the product page or controller and any other class. In this example, it will be shown the product name and product link, and other information. So let’s start with our example.

$productId = (int)Tools::getValue('id_product'); // get current product id
$productData = new Product($productId); // get product object with id
$name    = $productData->getProductName(); // get product name
$link    = $productData->getLink(); // get product link
Author: Qaisar Satti
Category: Prestashop
Last Modified: October 12, 2020


Prestashop session and cookies

Today we talk about how to use Prestashop session and cookies. The first thing you must know Prestashop did not use the session it is using the cookie for storing the data So let talk about the cookies. In this tutorial, we focus on set cookies, get cookies, and unset the cookies. So let’s start it.

You can get the cookie variable by following.

in the Controller file.

 $cookieObject = $this->context->cookie;

Other files

 $cookieObject = Context::getContext()->cookie;

Set Cookies

     $context->cookie->__set('simplaedata', 'abc');

To store an array in cookies you need to serialize data. an example is below.

     $array = array('a','b','c');
     $context->cookie->__set('simplaedata', serialize($array));

Get Cookies

    $context->cookie->simplaedata;

UnSet Cookies

   $context->cookie->__unset('simplaedata');
Author: Qaisar Satti
Category: Prestashop
Last Modified: October 12, 2020