Tag: Prestashop

  • PrestaShop Admin Auto Log Out

    PrestaShop Admin Auto Log Out

    After migrating a PrestaShop site to a new server, logging in to the admin area shows the dashboard, and when I click any link, I get redirected to the login page.

    Initially, I suspended the problem due to the PHP session not working properly, to verify, I created a file with the following content.

    
    

    Accessing the page, I can see the count increase every time I refresh the page, which confirms the PHP session is working.

    The site was using cloudflare CDN. This made IP of the visitor change. To fix this, I enabled remoteip module in Apache. You can find instructions for enabling the remoteip module at Cloudflare Show Real IP Address on CentOS Plesk Server

    Another solution is to disable IP checking in PrestaShop with the following SQL

    UPDATE ps_configuration SET value='0' WHERE name='PS_COOKIE_CHECKIP';
    

    Back to PrestaShop

  • PrestaShop clean MySQL database tables

    PrestaShop clean MySQL database tables

    On a PrestaShop site, queries like the following get stuck forever

    SELECT c.id_guest, c.ip_address, c.date_add, c.http_referer, "-" as page FROM `ps_connections` c INNER JOIN `ps_guest` g ON c.id_guest = g.id_guest WHERE (g.id_customer IS NULL OR g.id_customer = 0) AND c.id_shop IN (1) AND TIME_TO_SEC(TIMEDIFF('2022-08-14 21:31:00', c.`date_add`)) < 900 AND c.ip_address NOT IN (1522500673,858191475) ORDER BY c.date_add DESC;
    

    This is because PrestaShop database table ps_connections grow too large. This table had 6,67,557 records. This table record every visit to the website.

    I removed entries from the table and a few other tables to fix it.

    TRUNCATE TABLE ps_connections;
    TRUNCATE TABLE ps_connections_page;
    TRUNCATE TABLE ps_connections_source;
    TRUNCATE TABLE ps_pagenotfound;
    TRUNCATE TABLE ps_statssearch;
    

    See PrestaShop

  • PrestaShop Customer Service Page not working

    PrestaShop Customer Service Page not working

    On a PrestaShop site on clicking Customer Service link on the left menu, the page failed to load, it stuck at loading for a while, then show error message,

    PrestaShop Customer Service Page

    This is because a connection to the IMAP server is not able to establish. To fix the error modify IMAP-related entries in ps_configuration table.

    To list all IMAP related entries, run

    select * from gult_configuration where name like 'PS_SAV_IMAP%';
    

    To remove values for IMAP settings, run the following SQL commands.

    update ps_configuration set value='' where name='PS_SAV_IMAP_URL';
    update ps_configuration set value='' where name='PS_SAV_IMAP_PORT';
    update ps_configuration set value='' where name='PS_SAV_IMAP_USER';
    update ps_configuration set value='' where name='PS_SAV_IMAP_PWD';
    

    Once you removed IMAP related entries, you can reconfigure IMAP by going to

    PrestaShop Admin >  Customer Service >  Customer Service 
    

    Scroll down, you will see Customer service options.

    Back to PrestaShop

  • PrestaShop Enable Memcached

    PrestaShop Enable Memcached

    You need to install the memcached daemon and PHP module on the server before you can configure it in PrestaSop. You can find instructions for doing this in

    Once you have Memcached installed, you can enable it in the PrestaShop Admin area. Go to

    PrestaShop administrator > Advanced Parameters > Performance
    

    In the Performance page, scroll down to the CACHING. Set “Use Cache” to Yes.

    Enable memcached in PrestaShop

    Select the Memcached option. Click on Add Server. Enter IP address and port of your Memcached installation. This is usually 127.0.0.1 and 11211.

    See PrestaShop

  • PrestaShop show order comment in PDF invoice

    PrestaShop show order comment in PDF invoice

    To show user comment in PrestaShop PDF invoice

    Edit file classes/pdf/HTMLTemplateInvoice.php

    vi classes/pdf/HTMLTemplateInvoice.php
    

    Inside function getContent(), find around line 161

    $carrier = new Carrier((int) $this->order->id_carrier);
    

    Add below

    $sokOrderComment = $this->order->getFirstMessage();
    

    In the same file, around line 333, find the $array variable, inside it, add

    'sokOrderComment' => $sokOrderComment,
    

    PrestaShop order comment in invoice

    Edit file pdf/invoice.tpl

    vi pdf/invoice.tpl 
    

    Find

    {$legal_free_text|escape:'html':'UTF-8'|nl2br}
    

    Add above

    {$sokOrderComment}

    To show total weight in PDF invoice, see PrestaShop show total product weight in PDF invoice

    Back to PrestaShop

  • PrestaShop show total product weight in PDF invoice

    PrestaShop show total product weight in PDF invoice

    To show total product weight in PrestaShop PDF invoice, edit file.

    vi classes/pdf/HTMLTemplateInvoice.php
    

    Inside function getContent(), on line 166, find

             foreach ($order_details as $id => &$order_detail) {
    

    Replace with

            $sokTotalWeight = 0;
            foreach ($order_details as $id => &$order_detail) {
                $sokTotalWeight += $order_detail["product_weight"] * $order_detail["product_quantity"]; 
    

    On around line 332, find

            $data = array(
                'order' => $this->order,
                'order_invoice' => $this->order_invoice,
                'order_details' => $order_details,
                'carrier' => $carrier,
                'cart_rules' => $cart_rules,
                'delivery_address' => $formatted_delivery_address,
                'invoice_address' => $formatted_invoice_address,
                'addresses' => array('invoice' => $invoice_address, 'delivery' => $delivery_address),
                'tax_excluded_display' => $tax_excluded_display,
                'display_product_images' => $display_product_images,
                'layout' => $layout,
                'tax_tab' => $this->getTaxTabContent(),
                'customer' => $customer,
                'footer' => $footer,
                'ps_price_compute_precision' => _PS_PRICE_COMPUTE_PRECISION_,
                'round_type' => $round_type,
                'legal_free_text' => $legal_free_text,
            );  
    

    Show weight in prestashop invoice

    Above $data line, add

            $sokTotalWeight = $sokTotalWeight . ' '  . Configuration::get('PS_WEIGHT_UNIT');
    

    Inside the array, add

                'sokTotalWeight' => $sokTotalWeight,
    

    Now we need to edit the PDF template file.

    vi pdf/invoice.tpl 
    

    Inside the file, find

    {$legal_free_text|escape:'html':'UTF-8'|nl2br}

    Add above

    Total Weight: {$sokTotalWeight}

    You can place this text in any place in the document based on where you need it to show in your PDF document.

    To show order comment in PDF invoice, see PrestaShop show order comment in PDF invoice

    Back to PrestaShop

  • PrestaShop add customer email to invoice

    PrestaShop add customer email to invoice

    PrestaShop PDF invoice won’t show customer email address by default for some strange reason. To show the email address in the Invoice, we need to manually modify PrestaShop files. This instruction is tested on PrestaShop version 1.7.6.7.

    To show customer email address in PrestaShop PDF invoice, edit file

    vi classes/pdf/HTMLTemplateInvoice.php
    

    On line 329, find

            $data = array(
                'order' => $this->order,
                'order_invoice' => $this->order_invoice,
                'order_details' => $order_details,
                'carrier' => $carrier,
                'cart_rules' => $cart_rules,
                'delivery_address' => $formatted_delivery_address,
                'invoice_address' => $formatted_invoice_address,
                'addresses' => array('invoice' => $invoice_address, 'delivery' => $delivery_address),
                'tax_excluded_display' => $tax_excluded_display,
                'display_product_images' => $display_product_images,
                'layout' => $layout,
                'tax_tab' => $this->getTaxTabContent(),
                'customer' => $customer,
                'footer' => $footer,
                'ps_price_compute_precision' => _PS_PRICE_COMPUTE_PRECISION_,
                'round_type' => $round_type,
                'legal_free_text' => $legal_free_text,
            );  
    

    Inside the array, add

    'customer_email' => $customer->email,
    

    PrestaShop show customer email

    Now edit file pdf/invoice.addresses-tab.tpl

    vi pdf/invoice.addresses-tab.tpl
    

    Find

    {$delivery_address}
    

    Add below


    {$customer_email}

    Here is the modified content

    {if $delivery_address}{l s='Delivery Address' d='Shop.Pdf' pdf='true'}

    {$delivery_address}
    {$customer_email} {/if}
    {l s='Billing Address' d='Shop.Pdf' pdf='true'}

    {$invoice_address}
    {$customer_email}

    Now if you download an invoice, the email address will show below the customer Delivery and Billing Address.

    Back to PrestaShop

  • PrestaShop Error Declaration of Cart::getPackageShippingCost

    On a PrestaShop site, i get error message

    (1/1) ContextErrorException
    Warning: Declaration of Cart::getPackageShippingCost($id_carrier = NULL, $use_tax = true, ?Country $default_country = NULL, $product_list = NULL, $id_zone = NULL) should be compatible with CartCore::getPackageShippingCost($id_carrier = NULL, $use_tax = true, ?Country $default_country = NULL, $product_list = NULL, $id_zone = NULL, bool $keepOrderPrices = false)
    
    in Cart.php line 1021
    at ErrorHandler->handleError(2, 'Declaration of Cart::getPackageShippingCost($id_carrier = NULL, $use_tax = true, ?Country $default_country = NULL, $product_list = NULL, $id_zone = NULL) should be compatible with CartCore::getPackageShippingCost($id_carrier = NULL, $use_tax = true, ?Country $default_country = NULL, $product_list = NULL, $id_zone = NULL, bool $keepOrderPrices = false)', '/var/www/vhosts/site.com/httpdocs/override/classes/Cart.php', 1021, array('className' => 'Cart', 'classDir' => '/var/www/vhosts/site.com/httpdocs/'))
    in PrestaShopAutoload.php line 152
    

    PrestaShop error

    To fix this error, edit the file (location of the file depends on your hosting provider, on cpanel servers, it is public_html folder, on Plesk servers, it is httpdocs).

    override/classes/Cart.php
    

    Find line

    public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null)
    

    Replace with

    public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null, $keepOrderPrices = false)
    

    This is because orderide class have improper function definiation, this may be due to some outdated PrestaShop modules.

    See PrestaShop

  • Nginx upstream sent too big header

    Nginx upstream sent too big header

    When I log in to a PrestaShop website, I get an error on a Plesk server.

    502 Bad Gateway
    

    On checking error login for the site in folder /var/www/vhosts/domain.com/logs/proxy_error_log, I found the following error message

    proxy_error_log:2020/11/25 19:41:41 [error] 1809#0: *39664 upstream sent too big header while reading response header from upstream, client: 59.92.71.53, server: tulivesi.com, request: “POST /en/login?back=my-account HTTP/2.0”, upstream: “https://shop.serverok.in:7081/en/login?back=my-account”, host: “shop.serverok.in”, referrer: “https://shop.serverok.in/en/login?back=my-account”

    To fix, add the following to Nginx config.

    If Nginx works as a reverse proxy to another application server.

    proxy_buffer_size          128k;
    proxy_buffers              4 256k;
    proxy_busy_buffers_size    256k;
    

    If Nginx serve pages using FastCGI/fpm.

    fastcgi_buffers 16 16k; 
    fastcgi_buffer_size 32k;
    

    On Plesk Server

    On Plesk, go to the domain name, then click “Apache & nginx Settings”. On next page add the following code and click OK.

    proxy_buffer_size          128k;
    proxy_buffers              4 256k;
    proxy_busy_buffers_size    256k;
    

    Plesk Nginx

    See Nginx

  • Enable SSL in PrestaShop 1.7

    To enable SSL in PrestaShop 1.7, go to

    Admin > Shop Parameters > General
    

    On this page, you need to set YES for Enable SSL. After saving, you can enable “Enable SSL on all pages”.

    PrestaShop SSL

    Using phpMyAdmin/MySQL

    You can run following SQL query to enable SSL.

    select * from ps_configuration where name="PS_SSL_ENABLED";
    select * from ps_configuration where name="PS_SSL_ENABLED_EVERYWHERE";
    update ps_configuration set value="1" where name="PS_SSL_ENABLED";
    update ps_configuration set value="1" where name="PS_SSL_ENABLED_EVERYWHERE";
    

    See PrestaShop

  • PrestaShop Product Images not showing

    PrestaShop Product Images not showing

    After migrating a PrestaShop 1.7 web site to another domain, site did not show product images.

    PrestaShop Product Image missing

    To fix this, you need to regenerate .htaccess by disabling and enabling “Friendly URL”.

    Login to PrestaShop Admin area, go to

    CONFIGURE > Shop Parameters >  Traffic & SEO
    

    On this page, scroll down to “Set up URLs” section.

    PrestaShop SEO URL configuration

    Select NO for “Friendly URL”, then click “Save” button.

    Now images will work on product pages. Lets set “Friendly URL” back to YES and click Save to re-enable SEO urls. Images will work now.

    PrestaShop Product images

    Back to PrestaShop

  • Enable Debug in PrestaShop

    To enable debug mode in Prestashop, edit the file

    vi config/defines.inc.php

    Find

    define('_PS_MODE_DEV_', false);

    Replace with

    define('_PS_MODE_DEV_', true);

    Enable debug mode only for your IP

    Find

    if (!defined('_PS_MODE_DEV_')) {
    define('_PS_MODE_DEV_', false);
    }

    Add above.

    if ($_SERVER['REMOTE_ADDR'] == '51.38.246.115') {
        define('_PS_MODE_DEV_', true);
    }

    51.38.246.115 – replace with your IP address.

    Back to PrestaShop