Jump to content

Allow only one product in cart (order.php)


ramin

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, 

Link to comment
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

Link to comment
Share on other sites

  • 7 months later...
  • 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
×
×
  • Create New...