Prestashop Questions and Answers

4.3/5 - (3 votes)

Translation of errors in form fields in PrestaShop 1.7.x

It is not possible to translate these messages because these messages are set by the browser (in the browser’s set language) and not by PrestaShop.

Fortunately, they can be rewritten, check here how to Customize the Validation Messages

Assign template vars related to page content

For example how to check if a product is in a specified category?

In Controllers -> Front -> ProductController.php

In

    /**
     * Assign template vars related to page content.
     *
     * @see FrontController::initContent()
     */
    public function initContent()
    {
...
//Check if a product is in the desired category
$is_in_category = 0;
$id_category = 3;
$q = 'SELECT id_product FROM '._DB_PREFIX_.'category_product WHERE 'id_category' = $id_category AND  id_product = '.(int)$this->product->id;
$row22 = Db::getInstance()->getRow($q);            
if($row22 )   
    $is_in_category = 1;	
}
...
$this->context->smarty->assign(array(
                'priceDisplay' => $priceDisplay,
                'productPriceWithoutReduction' => $productPriceWithoutReduction,
                ...
                'is_in_category' => $is_in_category,
              ));

            // Assign attribute groups to the template
            $this->assignAttributesGroups($product_for_template);
        }

parent::initContent();
}

Then in template.tpl file

{if $is_in_category == 1}
….

How to print an array in Smarty?

{$array_name|@print_r}

E.g Get product sizes

{foreach from=$product.size_arr item=sa name=size_arr}
    <span {if $sa.qty == 0} class="lt" {/if}>{$sa.size}</span>
{/foreach}

or use {$product.size_arr|print_r} to dsiplay whole Array in the smarty file.

How to change “carriers -> Shipping locations and costs range” directly from database?

After a threshold was misspelled, the settings could no longer be accessed, the error occurs: the thresholds overlap.

shipping locations range

psat_range_price is the table that contains these thresholds in the database

As a solution you can change the thresholds directly in the psat_range_price database table.

Prestashop 1.7 Global Variables

You can access these variables in your TPL files

{$urls.base_url} -> Store address
{$urls.current_url} -> Current address (url) where we are
{$urls.shop_domain_url} -> Store domain
{$urls.img_ps_url} -> Image root directory url


{$customer.lastname} -> Customer Last Name in Prestashop 1.7
{$customer.firstname} -> Client Name Prestashop 1.7
{$customer.email} -> Prestashop Customer Email 1.7
{$customer.birthday} -> Prestashop client birthday 1.7
{$customer.newsletter} -> Subscribed to the newsletter in Prestashop 1.7 (1 subscribed / 0 unsubscribed)
{$customer.newsletter_date_add} -> Newsletter subscription date

Check complete list here Prestashop 1.7 Global Variables

How to get site baseurl?

{$urls.base_url}

Where and How to get product combinations (size,color etc)?

in Classes->Product.php

 public static function getProductProperties($id_lang, $row, Context $context = null)
    {
....

        foreach(  $combination_results  as $cr )
        {   
            
            $as  = array();
            $sql23 = 'SELECT * FROM  `'._DB_PREFIX_.'product_attribute_combination`  WHERE  id_product_attribute ='.(int)$cr['id'];
            $res = Db::getInstance()->executeS($sql23);

            $combination_r = array();

            $is_in = 0;

            $combination_r['attributes'] = array();


            foreach($res as $re)
            {
                $sql234 = 'SELECT al.name as attribute_name, agl.public_name as group_name , a.color as attribute_color   FROM  `'._DB_PREFIX_.'attribute`  a INNER JOIN  `'._DB_PREFIX_.'attribute_lang` al on a.id_attribute = al.id_attribute  INNER JOIN  `'._DB_PREFIX_.'attribute_group_lang` agl ON agl.id_attribute_group = a.id_attribute_group AND agl.id_lang = '.(int)$id_lang.'   WHERE    a.id_attribute ='.(int)$re['id_attribute'].' AND al.id_lang='.(int)$id_lang.' ORDER BY a.position ASC';
                $a = Db::getInstance()->getRow($sql234);
                
               // echo '<pre>'; print_r($a); echo '</pre>';
                $c = array();
                $c['name'] = $a['attribute_name'];
                $c['color'] = $a['attribute_color'];
                $c['group_name'] = $a['group_name'];

                if($a['group_name'] == 'Marime' || $a['group_name'] == 'Size' || $a['group_name'] == 'Selecteaza marimea' ||  $a['group_name']  =='Mărime')
                {
                    if(!in_array($a['attribute_name'], $size_tracker))
                    {
                        $size_tracker[] = $a['attribute_name'];
                        $as['size'] = $a['attribute_name'];
                        $is_in = 1;
                    }
                }

                $combination_r['attributes'][] = $c;
            }



            if($is_in == 1)
            {

                $combination_info = new Combination($cr['id']);

                $combination_r['quantity'] = Product::getQuantity($row['id_product'], $cr['id']);
                $combination_r['id_product_attribute'] = (int)$cr['id'];
                $combination_r['combination_reference'] = $combination_info->reference;
                $combination_r['default_on'] = $combination_info->default_on;

                $as['qty'] = $combination_r['quantity'];

                $size_arr[] = $as;            



                $element_arr['combinations'][] = $combination_r;

            }

        }

        /* */

        $lastvalue = end($size_arr);
        $lastkey = key($size_arr);
        $arr1 = array($lastkey=>$lastvalue);
        array_pop($size_arr);

        $size_arr = array_merge($arr1,$size_arr);



        $lastvalue = end($size_arr);
      
       if($lastvalue['size'] == 'XS')
       {
	        $lastkey = key($size_arr);
	        $arr1 = array($lastkey=>$lastvalue);
	        array_pop($size_arr);

	        $size_arr = array_merge($arr1,$size_arr);

       }

        $row['size_arr'] = $size_arr;

Hello there!

I hope you find this post useful!

I'm Mihai, a programmer and online marketing specialist, very passionate about everything that means online marketing, focused on eCommerce.

If you have a collaboration proposal or need helps with your projects feel free to contact me. I will always be glad to help you!

subscribe youtube

Leave a Comment

WebPedia.net