:::: MENU ::::
Browsing posts in: Prestashop

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


PrestaShop get current user information

Today we talk about PrestaShop get current user information. In this tutorial, we focus on how to get customer information. User email, User name, User id, and other users related information.
You can get the context variable by following.

in the Controller file.

 $contextObject = $this->context;

Other files

 $contextObject = Context::getContext();

You can get the following user information using the $contextObject.

$contextObject->customer->id;
$contextObject->customer->firstname
$contextObject->customer->lastname
$contextObject->customer->email
Author: Qaisar Satti
Category: Prestashop
Last Modified: November 28, 2019


PrestaShop database configuration

Today we talk about how in PrestaShop database configuration work. Sometimes you need to edit database connection manually for moving one server to another or local server to live server. I recently find difficulty to find the database configuration. SO we focus on where the PrestaShop database connection file exists or edit from the back office. There are two ways to way to change the database configuration.

Admin Panel

Login to the back office.You can go to Preferences > Database to change the database settings

Database Configuration file in 1.6

Location of file in following directory.

config/settings.inc.php

Database Configuration in file 1.7

Location of file in following directory.

app/config/parameters.php
Author: Qaisar Satti
Category: Prestashop
Last Modified: November 28, 2019


PrestaShop change APE length

A few days ago I faced the problem regarding PrestaShop change APE length. So I think it will be better to share the solution with you all. There are no ways to change the APE length from PHP file you have to change the length. You need to modify the default PrestaShop table ps_customer. Running the following query will change the length of the APE field.

Run following SQL query and change the length accordingly. I am setting the length to 16.

ALTER TABLE `ps_customer` CHANGE `ape` `ape` VARCHAR( 16 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL

That’s it from this article. I strongly believe there is always room for improvement. So I am open to any suggestion and feedback. Please feel free to leave what you are thinking in the comments section below. Cheers.

Author: Qaisar Satti
Category: Prestashop
Last Modified: September 27, 2019


PrestaShop change SIRET Length

Today we talk about PrestaShop change SIRET length. There is not only one way to change the SIRET length from PHP file you have to change the length. You need to modify the default PrestaShop table ps_customer.

First, you have to change the length in PHP file. The class path is following. and Search for function isSiret.

classes/Validate.php

public static function isSiret($siret)
{
 

if (Tools::strlen($siret) != 16)
return false;
$sum = 0;
for ($i = 0; $i != 16; $i++)
{
$tmp = ((($i + 1) % 2) + 1) * intval($siret[$i]);
if ($tmp >= 10)
$tmp -= 9;
$sum += $tmp;
}
return ($sum % 10 === 0);

}

Run following SQL query and change the length accordingly. I am setting the length to 16.

        ALTER TABLE  `ps_customer` CHANGE  `siret`  `siret` VARCHAR( 16 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL

That’s it from this article. I strongly believe there is always room for improvement. So I am open to any suggestion and feedback. Please feel free to leave what you are thinking in the comments section below. Cheers.

Author: Qaisar Satti
Category: Prestashop
Last Modified: September 27, 2019


Pages:12