Top 5 PrestaShop Questions and Answers of 2016 Part 2

Question no. 1: Rules for friendly URLs in PrestaShop

How can I define rules to replace these links with friendly URLs in PrestaShop, because there are broken links in the following URLs?

I want to convert this URL http://www.elektrojo.com/index.php?id_post=2&fc=module&module=nextblog&controller=nbpost to this one http://www.elektrojo.com/blog/2-second-blog

Also, these URLs to become SEO and user-friendly

http://www.elektrojo.com/index.php?fc=module&module=nextblog&controller=nblog to http://www.elektrojo.com/blog

http://www.elektrojo.com/index.php?id_collection=1&fc=module&module=nextblog&controller=nbcollection to http://www.elektrojo.com/blog/collection/1-test

http://www.elektrojo.com/index.php?year=2016&month=5&fc=module&module=nextblog&controller=nbarchive to http://www.elektrojo.com/blog/archive/2016-5

Answer no. 1: it looks like you have kept the /blog/ directory empty in the domain root. As soon as you remove the empty directory or rename it, the friendly URLs will become operational and work fine for your store.

Question no. 2: getting error while searching store by alphabetical order

When I write something in the PrestaShop search box to find products, it gives me the option to show results by alphabetical or price order. When I select a sorting order, I get an error of ‘Page Unavailable’. I think there is something wrong with the URL, because when I select display results by price, the URL appears like

buscar&search_query=game&submit_search=?orderby=price&orderway=asc&orderway=asc

whereas it needs to be                

buscar?search_query=game&submit_search=&orderby=price&orderway=asc&orderway=asc

How can I solve this issue?

Answer no. 2: such errors occur when a module has over ridded either "override/classes/Link.php" or "override/controllers/front/SearchController.php" files of your store. To solve the issue, you need to disable the overrides.

Disable the overrides by moving to Advance Parametersperformance. There, select ‘Yes’ and it will disable all the overrides. Seek guidance in the image below.

Question no. 3: Unable to display errors in PrestaShop redirection

I am developing a module that is powered by an API to help the users create an account in PrestaShop. The API is enabled with a button to call a URL that belongs to my website. this initiates a function that allows users to sign up for an account.

When all the information is correct it works well, but when could display error when a user creates an account.

I want to redirect users towards the authentication page which shows errors as well.

I gave it a try with this 

$this->context->smarty->assign('account_error', $myErrors);
Tools::redirect('index.php?controller=authentication');

The redirection works but the errors seem to be lost.

Is there a way to redirect and keep the errors ?

Thanks

Answer No. 3: Frankly, you cannot display any error after setting redirections, whereas you can utilize a controller to show errors. You can also consider using buttons that say ‘Fix Errors’ which directs users to an authorized page once they click it.

Add this to your controller 

if (empty($email))
  $this->errors[] = Tools::displayError('Email is empty.');

and in your tpl use in top
{include file="$tpl_dir./errors.tpl"}

Question no. 4: Facing problems in adding categories to new products in PrestaShop

I am facing a problem since long and unable to find an effective solution. It happens when I add new products to the database with the help of product object but unable to classify them in a category. The product adds without any problem but I fail to attach products to a category. 

$cat_ids = [];
    foreach ($value['kat_naziv'] as $cat_val) {
    $cat_ids[] = (int)$luceed->selectCategoryIds($cat_val)[$cat_val]['id_category'];
}

$product->id_category = 3;
$product->id_category_default = 3;

$product->save();

$product->addToCategories($cat_ids);

The $cat_ids is an array of integers that I got from the database whereas name is something I leave as a parameter to choose Category IDs;

My question is why the newly added products are not shown in the category I select for it? 

Answer no. 4: Once you add a new product, you can link it to categories by using the following code. 

$product->updateCategories($category_array); 

where

$category_array = array("0" => "2", "1" => "3", "4" => "6"...... );

Questions 5: Adding a list of products to my PrestaShop store

Hi,          

I am naïve in managing PrestaShop store that’s why facing difficulty in adding a list of cloth products. I tried it with the help of two CSV files (one as a list, and the other for a combination of products), but it did not work.

For product imports, I added this

http://pvmag.ro/Fisiere-directoare/IMPORT%202%20-%20Copy.csv

and for combinations, I tried this

http://pvmag.ro/Fisiere-directoare/combinations_import.csv

How to fix the issue?

Answer no. 5: Possibly, the error could be the absence of field separators. Please ensure that the separators for field and multiple values match the CVS file. We have tested (;) as a field separator and (,) for parting multiple values, and it worked well. You can also give it a try.