Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 373 Vote(s) - 3.61 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PrestaShop: Redirect to homepage if the product didn't exists

#1
i'm trying to redirect page like this :

[To see links please register here]


i want that every page, with deleted id_product - will be redirected to my homepage:

which means : i want to redirect "https://www.cdsoft.co.il/index.php?id_product=XXX"

how to do it in the htaccess file ?
Reply

#2
Maybe this will be helpful.

Edit file `controllers/front/ProductController.php`, line `91` or find `Tools::displayError('Product not found')`, and change this for this:

`header("Location: /");`
Reply

#3
I propose the @Labradorcode idea, but with the correct approach.
Make an ovverride of ProductController.php in `rootofps/override/controllers/front/ProductController.php`, so you have to create a new file in that directory (for rootofps I mean the install directory of PrestaShop), the content of that file is written below:

class ProductController extends ProductControllerCore {
public function init(){
FrontController::init();

if ($id_product = (int)Tools::getValue('id_product')) {
$this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);
}

if (!Validate::isLoadedObject($this->product)) {
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');
header('Location: '.$this->context->link->getPageLink('index', array('id_product', Tools::getValue('id_product'))));
} else {
parent::init();
}
}
}

In this case the redirect works if the product is totally removed and not if is disabled.

After you have created the file delete this file `rootofps/cache/class_index.php`
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through