Tag: prestashop

  • Prestashop: Stop subdomains from keep redirecting to main domain

    Source: https://www.prestashop.com/forums/topic/635858-2nd-store-redirects-to-main-store-multistore-redirection-problem/?tab=comments#comment-2634035

    After installing prestashop, created subdomains don’t work properly due to the .htaccess rewrite conditions automatically created by prestashop.

    Add the following right at the end to solve this issue

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

    //////////////////

    some additional ones to try in case doesn’t work

    Source: https://www.prestashop.com/forums/topic/635858-2nd-store-redirects-to-main-store-multistore-redirection-problem/?tab=comments#comment-3116242

    #First condition, If is HTTPS without wwww, redirects to www.
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

    #Second condition, If is not HTTPS and without www, redirects to HTTPS with WWW.
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*) https://www.%{SERVER_NAME}/$1 [R,L]

    #Third, If is not HTTPS and have www, redirects only to HTTPS
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^www\.
    RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]

  • Prestashop: Search does not index product reference numbers properly

    The native Search.php class would only index characters that appear before ‘-‘ hyphen or other punctuations, so if your products have reference numbers for example like ‘ABC-123’, only ‘ABC’ is indexed for the product. The workaround is to edit the Search.php class and use it as override.

    use class Search extends SearchCore {} as a wrapper for public static function sanitize ()

    Find $indexation and remove the hyphen from preg_replace like so:

    if ($indexation) {
    $string = preg_replace(‘/[._]+/’, ‘ ‘, $string);
    }

    Reindex the products completely after upload.

    For additional reference, the database tables to cross check are ps_search_word and ps_search_index

  • Prestashop: Layered Navigation Block – Auto Scroll to Products

    Source: https://www.prestashop.com/forums/topic/347990-layered-navigation-block-auto-scroll-to-products/

    js file under “/themes/themename/js/modules/blocklayered” called “blocklayered.js”

    Solution 1:

    Replace :

    $.scrollTo('.product_list', 400);

    by

    $.scrollTo('product_list', 0); //stop the scroll

    or

    $.scrollTo('body', 0); // brings to the top of the page instantly.

    Solution 2:

    //if(slideUp)
    	//$.scrollTo('.product_list', 400);
    //updateProductUrl();

     

  • Prestashop: delete customer’s cookies

    Solution: https://www.prestashop.com/forums/topic/364875-how-to-delete-cookies-customers/?tab=comments#comment-2348354

    Overriding the method __construct (classes/Cookie.php) changing the commented lines

    override/classes/Cookie.php

    class Cookie extends CookieCore
    {
        public function __construct($name, $path = '', $expire = null, $shared_urls = null, $standalone = false, $secure = false)
        {
            $this->_content = array();
            $this->_standalone = $standalone;
            $this->_expire = is_null($expire) ? time() + 1728000 : (int)$expire;
            $this->_path = trim(($this->_standalone ? '' : Context::getContext()->shop->physical_uri).$path, '/\\').'/';
            if ($this->_path{0} != '/') {
                $this->_path = '/'.$this->_path;
            }
            $this->_path = rawurlencode($this->_path);
            $this->_path = str_replace('%2F', '/', $this->_path);
            $this->_path = str_replace('%7E', '~', $this->_path);
            $this->_domain = $this->getDomain($shared_urls);
    
            //remove www from url > example: .domain.com
            $this->_domain =str_replace('www','', $this->_domain);
    
            //Change cookie name "PrestaShop" > "MyCookieName" This will make all your customers cookies obsolete.
            $this->_name = 'MyCookieName-'.md5(($this->_standalone ? '' : _PS_VERSION_).$name.$this->_domain);
    
            $this->_allow_writing = true;
            $this->_salt = $this->_standalone ? str_pad('', 8, md5('ps'.__FILE__)) : _COOKIE_IV_;
            if ($this->_standalone) {
                $this->_cipherTool = new Blowfish(str_pad('', 56, md5('ps'.__FILE__)), str_pad('', 56, md5('iv'.__FILE__)));
            } elseif (!Configuration::get('PS_CIPHER_ALGORITHM') || !defined('_RIJNDAEL_KEY_')) {
                $this->_cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_);
            } else {
                $this->_cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_);
            }
            $this->_secure = (bool)$secure;
    
            $this->update();
        }
    }
  • Prestashop: category pages noindex

    Due to layered navigation block disabling robots by default…

    Solution: https://www.prestashop.com/forums/topic/866411-category-pages-noindex/

    Hi, the problem comes from the “Layered navigation block” module. After the update to v2.2.1 something has changed.

    To Fix the problem for Prestashop 1.6 go to Modules and Services >> Layered navigation block >> Configure
    Scroll down to the CONFIGURATION section and set to YES the “Allow indexing robots….”
    This action will change the metatags for all category pages to “indexed, follow”

  • Prestashop: Add tags to the product list

    Source: http://nemops.com/prestashop-product-list-tags/#.XPt5M7hS-Ul

    1) Product.php class (use override)

    Insert code at the last part of public static function getProductProperties($id_lang, $row, Context $context = null)
    /* add product tags to product list */
    $row['tags'] = array();
    $tags = Tag::getProductTags($row['id_product']); //show product tags in listing
    if($tags && isset($tags[$context->language->id])) //show product tags in listing
    $row['tags'] = $tags[$context->language->id]; //show product tags in listing

    2) product-list.tpl (in theme folder)
    <div class="product-tags">{if $product.tags}{foreach from=$product.tags item=tag}<a class="btn bth-default" href="{$product.link|escape:'html':'UTF-8'}" title="{$tag|escape:'html':'UTF-8'}" >{$tag}</a>{/foreach}{/if}</div>

    3) global.js (in theme folder) add this above the product-reference html in 3 views (grid, table, list) it looks for product-tags name in div so make sure that matches in product-list.tpl
    html += '<div class="product-tags">'+$(element).find('.product-tags').html()+'</div>';

    Note: no all products have tags, so may mess up the listing layout. Add a min-height to the product-container to e.g. 500px

  • Prestashop: Remove View Grid/List buttons from Product Listing

    Source: https://www.prestashop.com/forums/topic/337353-remove-view-gridlist-bottons/

    Open themes/yourtheme/product-sort.tpl and find this code:

    <ul class="display hidden-xs">
        <li class="display-title">{l s='View:'}</li>
        <li id="grid"><a rel="nofollow" href="#" title="{l s='Grid'}"><i class="icon-th-large"></i>{l s='Grid'}</a></li>
        <li id="list"><a rel="nofollow" href="#" title="{l s='List'}"><i class="icon-th-list"></i>{l s='List'}</a></li>
    </ul>

    Delete it and buttons will gone.

  • Prestashop: fake customer registrations spam

    Source: https://www.prestashop.com/forums/topic/981159-securite-spam-customer-account-solution-13-15/

    within your class classes/Validate.php – either in the native code, or into an override, add this function

        public static function isCustomerName($name)
        {
            if (preg_match(Tools::cleanNonUnicodeSupport('/www|http/ui'),$name))
               return false;
    
            return preg_match(Tools::cleanNonUnicodeSupport('/^[^0-9!\[\]<>,;?=+()@#"°{}_$%:\/\\\*\^]*$/u'), $name);
        }

    Then modify inside classes/Customer.php

                'lastname' =>                    array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
                'firstname' =>                    array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),

    by

                'lastname' =>                    array('type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 32),
                'firstname' =>                    array('type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 32),
  • Prestashop: Searching orders by the products they contain via mysql

    Source: https://www.prestashop.com/forums/topic/437518-searching-orders-by-the-products-they-contain/?tab=comments#comment-2033625

    SELECT product_id, product_attribute_id, product_name, GROUP_CONCAT(id_order SEPARATOR ‘, ‘) AS orders FROM ps_order_detail group by product_name order by product_id, product_attribute_id

    Can add where product_id = to the number you want to narrow down the specific product

    SELECT product_id, product_attribute_id, product_name, GROUP_CONCAT(id_order SEPARATOR ‘, ‘) AS orders FROM ps_order_detail where product_id = XYZ group by product_name order by product_id, product_attribute_id

  • Prestashop: Fix pagination error on Attributes and Features in Backoffice

    https://github.com/PrestaShop/PrestaShop/pull/8638/files

    https://www.prestashop.com/forums/topic/554037-possible-bug-on-product-attributes-list-pagination-in-1616/

    https://www.prestashop.com/forums/topic/507337-backoffice-pagination-error-in-products-attribute-section/

    Hi, i fixed this by adding a short code to ‘AdminAttributesGroupsController.php’ in /controllers/admin/

        public function setRedirectAfter($url)
        {
            $addUrl = '';
            if(Tools::isSubmit('viewattribute_group') && Tools::getValue('id_attribute_group')) {
                $addUrl = '&viewattribute_group&id_attribute_group=' . Tools::getValue('id_attribute_group');
            }
    
            $this->redirect_after = $url . $addUrl;
        }

    Function fixes the bug too for Feature values. We need to create an override for ‘AdminFeaturesController.php’:

    <?php
    
    class AdminFeaturesController extends AdminFeaturesControllerCore
    {
    
       public function setRedirectAfter($url)
        {
            $addUrl = '';
            if(Tools::isSubmit('viewfeature') && Tools::getValue('id_feature')) {
                $addUrl = '&viewfeature&id_feature=' . Tools::getValue('id_feature');
            }
    
            $this->redirect_after = $url . $addUrl;
        }
    }