Jump to content

Allow only one product in cart (order.php)


ramin
 Share

Recommended Posts

  • 5 months later...
  • 3 months later...

in your prestashop filesystem in directory /controllers/ you've got file CartController.php

path: /controllers/CartController.php

 

inside this function you've got function: public function preProcess(), use there code mentioned above, 

Share this post


Link to post
Share on other sites

open file:/controllers/CartController.php

 

there is function postProcess();

 

use this one:

 

 

 

public function postProcess()
{
// Update the cart ONLY if $this->cookies are available, in order to avoid ghost carts created by bots
if ($this->context->cookie->exists() && !$this->errors && !($this->context->customer->isLogged() && !$this->isTokenValid()))
{
if (Tools::getIsset('add') || Tools::getIsset('update')){

if(count($this->context->cart->getProducts()) >= 1)
$this->errors[] = Tools::displayError('Sorry only 1 product allowed to be purchased');
else
$this->processChangeProductInCart();

}
else if (Tools::getIsset('delete'))
$this->processDeleteProductInCart();
else if (Tools::getIsset('changeAddressDelivery'))
$this->processChangeProductAddressDelivery();
else if (Tools::getIsset('allowSeperatedPackage'))
$this->processAllowSeperatedPackage();
else if (Tools::getIsset('duplicate'))
$this->processDuplicateProduct();
// Make redirection
if (!$this->errors && !$this->ajax)
{
$queryString = Tools::safeOutput(Tools::getValue('query', null));
if ($queryString && !Configuration::get('PS_CART_REDIRECT'))
Tools::redirect('index.php?controller=search&search='.$queryString);

// Redirect to previous page
if (isset($_SERVER['HTTP_REFERER']))
{

if (isset($regs[3]) && !Configuration::get('PS_CART_REDIRECT'))
Tools::redirect($_SERVER['HTTP_REFERER']);
}

Tools::redirect('index.php?controller=order&'.(isset($this->id_product) ? 'ipa='.$this->id_product : ''));
}

}
elseif (!$this->isTokenValid())
Tools::redirect('index.php');
}

 

 

 

effect:
iWkJRLU.png

Share this post


Link to post
Share on other sites

  • 7 months later...

open file:/controllers/CartController.php

 

there is function postProcess();

 

use this one:

 

 

 

 

effect:

iWkJRLU.png

 

 

 

Hi, thank you for this solution

 

But in Prestashop 1.6 it does not showing any message can you give any solution about this thankyou vekia

Edited by abugroup (see edit history)

Share this post


Link to post
Share on other sites

  • 7 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More