Jump to content

Modifier le fichier CartController à l'aide d'un override


Recommended Posts

Bonjour,

 

Je souhaite ajouter cette fonction au fichier CartController.php afin de gérer les quantités de vente minimale par multiple.

 

if ((int)$idProductAttribute)
				    $minimal_quantity = Attribute::getAttributeMinimalQty((int)$idProductAttribute);
				 else
				    $minimal_quantity = $producToAdd->minimal_quantity;				 
				 if ($qty % $minimal_quantity != 0)
				 {
				    $this->errors[] = Tools::displayError('You can only only add this item to your cart with a quantity multiple of ').' '.$minimal_quantity;
				 }

 

Cet ajout se fait après les lignes

if (!sizeof($this->errors))
		   {
			  if ($add AND $qty >= 0)
			  {

 

Et avant les lignes

/* Product addition to the cart */
				 if (!isset(self::$cart->id) OR !self::$cart->id)
				 {

 

Comme je ne comprend pas la méthode de création d'un fichier override, quelqu’un peut'il me donner la solution.

 

Merci de votre aide.

Link to comment
Share on other sites

Bonjour,

I faut créer un fichier CartController dans le dossier override/controller

 

Dedans il y a juste besoin de mettre :

class CartController extends CartControllerCore{
public function preProcess(){
 // méthode complète avec tes modifs
  }
}

 

Par héritage le reste des méthodes et attributs est repris de la classe overridée.

 

Cordialement

Link to comment
Share on other sites

Je n'y arrive pas.

 

Voila mon code override.


<?php
class CartController extends CartControllerCore{
public function preProcess(){
 // méthode complète avec tes modifs
 if ((int)$idProductAttribute)
				    $minimal_quantity = Attribute::getAttributeMinimalQty((int)$idProductAttribute);
				 else
				    $minimal_quantity = $producToAdd->minimal_quantity;				 
				 if ($qty % $minimal_quantity != 0)
				 {
				    $this->errors[] = Tools::displayError('You can only only add this item to your cart with a quantity multiple of ').' '.$minimal_quantity;
				 }
  }
}

 

Résultat, ma page panier est blanche.

Qu'est-je oublié.

 

merci

Link to comment
Share on other sites

Je n'ai pas compris ta réponse.

 

Comme indiqué dans le post #1, je veux intégrer ce code entre les 2 lignes indiqué.

if ((int)$idProductAttribute)
									    $minimal_quantity = Attribute::getAttributeMinimalQty((int)$idProductAttribute);
									 else
									    $minimal_quantity = $producToAdd->minimal_quantity;						 
									 if ($qty % $minimal_quantity != 0)
									 {
									    $this->errors[] = Tools::displayError('You can only only add this item to your cart with a quantity multiple of ').' '.$minimal_quantity;
									 }

 

Pour ce faire, j'ai pris ton code et est ajouté mon code après:

// méthode complète avec tes modifs

Qu'entend-tu par

Tu as recopié toute la fonction preProcess et tu l'as mis dans ton override

Merci

Link to comment
Share on other sites

Il faut le code complet de 'function preProcess' de la classe toute faite de prestashop, le coller dans l'override de preProcess et là, tu modifies le conportement de cette fonction.

 

L'override c'est :je charge la classe 'standard', si je trouve un override, les 'fonctions overridées' remplacent celle de la classe standard. Tu as donc besoin et du code de la classe de prestashop et de tes modifs, les 2 doivent former une seule fonction preProcess complète (dans ton cas) dans ton override.

 

Mokay ?

Edited by math_php (see edit history)
Link to comment
Share on other sites

Rien ne marche.

Je ne comprend pas le php, c'est donc du chinois pour moi.

 

voici le code CartController.php de base

<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2011 PrestaShop SA
*  @version  Release: $Revision: 6594 $
*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
class CartControllerCore extends FrontController
{
public function run()
{
 $this->init();
 $this->preProcess();
 if (Tools::getValue('ajax') == 'true')
 {
  if (Tools::getIsset('summary'))
  {
   if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1)
   {
 if (self::$cookie->id_customer)
 {
  $customer = new Customer((int)(self::$cookie->id_customer));
  $groups = $customer->getGroups();
 }
 else
  $groups = array(1);
 if ((int)self::$cart->id_address_delivery)
  $deliveryAddress = new Address((int)self::$cart->id_address_delivery);
 $result = array('carriers' => Carrier::getCarriersForOrder((int)Country::getIdZone((isset($deliveryAddress) AND (int)$deliveryAddress->id) ? (int)$deliveryAddress->id_country : (int)Configuration::get('PS_COUNTRY_DEFAULT')), $groups));
   }
   $result['summary'] = self::$cart->getSummaryDetails();
   $result['customizedDatas'] = Product::getAllCustomizedDatas((int)(self::$cart->id));
   $result['HOOK_SHOPPING_CART'] = Module::hookExec('shoppingCart', $result['summary']);
   $result['HOOK_SHOPPING_CART_EXTRA'] = Module::hookExec('shoppingCartExtra', $result['summary']);
   die(Tools::jsonEncode($result));
  }
  else
   $this->includeCartModule();
 }
 else
 {
  $this->setMedia();
  $this->displayHeader();
  $this->process();
  $this->displayContent();
  $this->displayFooter();
 }
}
public function includeCartModule()
{
 require_once(_PS_MODULE_DIR_.'/blockcart/blockcart-ajax.php');
}
public function preProcess()
{
 parent::preProcess();
 $orderTotal = self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
 $this->cartDiscounts = self::$cart->getDiscounts();
 foreach ($this->cartDiscounts AS $k => $this->cartDiscount)
  if ($error = self::$cart->checkDiscountValidity(new Discount((int)($this->cartDiscount['id_discount'])), $this->cartDiscounts, $orderTotal, self::$cart->getProducts()))
   self::$cart->deleteDiscount((int)($this->cartDiscount['id_discount']));
 $add = Tools::getIsset('add') ? 1 : 0;
 $delete = Tools::getIsset('delete') ? 1 : 0;
 if (Configuration::get('PS_TOKEN_ENABLE') == 1 &&
  strcasecmp(Tools::getToken(false), strval(Tools::getValue('token'))) &&
  self::$cookie->isLogged() === true)
  $this->errors[] = Tools::displayError('Invalid token');
 // Update the cart ONLY if $this->cookies are available, in order to avoid ghost carts created by bots
 if (($add OR Tools::getIsset('update') OR $delete) AND isset(self::$cookie->date_add))
 {
  //get the values
  $idProduct = (int)(Tools::getValue('id_product', NULL));
  $idProductAttribute = (int)(Tools::getValue('id_product_attribute', Tools::getValue('ipa')));
  $customizationId = (int)(Tools::getValue('id_customization', 0));
  $qty = (int)(abs(Tools::getValue('qty', 1)));
  if ($qty == 0)
   $this->errors[] = Tools::displayError('Null quantity');
  elseif (!$idProduct)
   $this->errors[] = Tools::displayError('Product not found');
  else
  {
   $producToAdd = new Product((int)($idProduct), true, (int)(self::$cookie->id_lang));
   if ((!$producToAdd->id OR !$producToAdd->active) AND !$delete)
 if (Tools::getValue('ajax') == 'true')
  die('{"hasError" : true, "errors" : ["'.Tools::displayError('Pproduct is no longer available.', false).'"]}');
 else
  $this->errors[] = Tools::displayError('Pproduct is no longer available.', false);
   else
   {
 /* Check the quantity availability */
 if ($idProductAttribute AND is_numeric($idProductAttribute))
 {
  if (!$delete AND !$producToAdd->isAvailableWhenOutOfStock($producToAdd->out_of_stock) AND !Attribute::checkAttributeQty((int)$idProductAttribute, (int)$qty))
   if (Tools::getValue('ajax') == 'true')
    die('{"hasError" : true, "errors" : ["'.Tools::displayError('There is not enough product in stock.', false).'"]}');
   else
    $this->errors[] = Tools::displayError('There is not enough product in stock.');
 }
 elseif ($producToAdd->hasAttributes() AND !$delete)
 {
  $idProductAttribute = Product::getDefaultAttribute((int)$producToAdd->id, (int)$producToAdd->out_of_stock == 2 ? !(int)Configuration::get('PS_ORDER_OUT_OF_STOCK') : !(int)$producToAdd->out_of_stock);
  if (!$idProductAttribute)
   Tools::redirectAdmin($link->getProductLink($producToAdd));
  elseif (!$delete AND !$producToAdd->isAvailableWhenOutOfStock($producToAdd->out_of_stock) AND !Attribute::checkAttributeQty((int)$idProductAttribute, (int)$qty))
   if (Tools::getValue('ajax') == 'true')
    die('{"hasError" : true, "errors" : ["'.Tools::displayError('There is not enough product in stock.', false).'"]}');
   else
    $this->errors[] = Tools::displayError('There is not enough product in stock.');
 }
 elseif (!$delete AND !$producToAdd->checkQty((int)$qty))
  if (Tools::getValue('ajax') == 'true')
    die('{"hasError" : true, "errors" : ["'.Tools::displayError('There is not enough product in stock.').'"]}');
   else
    $this->errors[] = Tools::displayError('There is not enough product in stock.');
 /* Check vouchers compatibility */
 if ($add AND (($producToAdd->specificPrice AND (float)($producToAdd->specificPrice['reduction'])) OR $producToAdd->on_sale))
 {
  $discounts = self::$cart->getDiscounts();
  $hasUndiscountedProduct = null;
  foreach($discounts as $discount)
  {
   if(is_null($hasUndiscountedProduct))
   {
    $hasUndiscountedProduct = false;
    foreach(self::$cart->getProducts() as $product)
	 if($product['reduction_applies'] === false)
	 {
	  $hasUndiscountedProduct = true;
	  break;
	 }
   }
   if (!$discount['cumulable_reduction'] && ($discount['id_discount_type'] != 1 || !$hasUndiscountedProduct))
    if (Tools::getValue('ajax') == 'true')
	 die('{"hasError" : true, "errors" : ["'.Tools::displayError('Cannot add this product because current voucher does not allow additional discounts.').'"]}');
    else
	 $this->errors[] = Tools::displayError('Cannot add this product because current voucher does not allow additional discounts.');

  }
 }
 if (!sizeof($this->errors))
 {
  if ($add AND $qty >= 0)
  {
   /* Product addition to the cart */
   if (!isset(self::$cart->id) OR !self::$cart->id)
   {
    self::$cart->add();
    if (self::$cart->id)
	 self::$cookie->id_cart = (int)(self::$cart->id);
   }
   if ($add AND !$producToAdd->hasAllRequiredCustomizableFields() AND !$customizationId)
    $this->errors[] = Tools::displayError('Please fill in all required fields, then save the customization.');
   if (!sizeof($this->errors))
   {
    $updateQuantity = self::$cart->updateQty((int)($qty), (int)($idProduct), (int)($idProductAttribute), $customizationId, Tools::getValue('op', 'up'));
    if ($updateQuantity < 0)
    {
	 /* if product has attribute, minimal quantity is set with minimal quantity of attribute*/
	 if ((int)$idProductAttribute)
	  $minimal_quantity = Attribute::getAttributeMinimalQty((int)$idProductAttribute);
	 else
	  $minimal_quantity = $producToAdd->minimal_quantity;
	 if (Tools::getValue('ajax') == 'true')
	  die('{"hasError" : true, "errors" : ["'.Tools::displayError('You must add', false).' '.$minimal_quantity.' '.Tools::displayError('Minimum quantity', false).'"]}');
	 else
	  $this->errors[] = Tools::displayError('You must add').' '.$minimal_quantity.' '.Tools::displayError('Minimum quantity')
	  .((isset($_SERVER['HTTP_REFERER']) AND basename($_SERVER['HTTP_REFERER']) == 'order.php' OR (!Tools::isSubmit('ajax') AND substr(basename($_SERVER['REQUEST_URI']),0, strlen('cart.php')) == 'cart.php')) ? ('<script language="javascript">setTimeout("history.back()",5000);</script><br />- '.
	  Tools::displayError('You will be redirected to your cart in a few seconds.')) : '');
    }
    elseif (!$updateQuantity)
    {
	 if (Tools::getValue('ajax') == 'true')
	  die('{"hasError" : true, "errors" : ["'.Tools::displayError('You already have the maximum quantity available for this product.', false).'"]}');
	 else
	  $this->errors[] = Tools::displayError('You already have the maximum quantity available for this product.')
	  .((isset($_SERVER['HTTP_REFERER']) AND basename($_SERVER['HTTP_REFERER']) == 'order.php' OR (!Tools::isSubmit('ajax') AND substr(basename($_SERVER['REQUEST_URI']),0, strlen('cart.php')) == 'cart.php')) ? ('<script language="javascript">setTimeout("history.back()",5000);</script><br />- '.
	  Tools::displayError('You will be redirected to your cart in a few seconds.')) : '');
    }
   }
  }
  elseif ($delete)
  {
   if (self::$cart->deleteProduct((int)($idProduct), (int)($idProductAttribute), (int)($customizationId)))
    if (!Cart::getNbProducts((int)(self::$cart->id)))
    {
	 self::$cart->id_carrier = 0;
	 self::$cart->gift = 0;
	 self::$cart->gift_message = '';
	 self::$cart->update();
    }
  }
 }
 $discounts = self::$cart->getDiscounts();
 foreach($discounts AS $discount)
 {
  $discountObj = new Discount((int)($discount['id_discount']), (int)(self::$cookie->id_lang));
  if ($error = self::$cart->checkDiscountValidity($discountObj, $discounts, self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS), self::$cart->getProducts()))
  {
   self::$cart->deleteDiscount((int)($discount['id_discount']));
   self::$cart->update();
   $errors[] = $error;
  }
 }
 if (!sizeof($this->errors))
 {
  $queryString = Tools::safeOutput(Tools::getValue('query', NULL));
  if ($queryString AND !Configuration::get('PS_CART_REDIRECT'))
   Tools::redirect('search.php?search='.$queryString);
  if (isset($_SERVER['HTTP_REFERER']))
  {
   // Redirect to previous page
   preg_match('!http(s?)://(.*)/(.*)!', $_SERVER['HTTP_REFERER'], $regs);
   if (isset($regs[3]) AND !Configuration::get('PS_CART_REDIRECT') AND Tools::getValue('ajax') != 'true')
    Tools::redirect($_SERVER['HTTP_REFERER']);
  }
 }
   }
   if (Tools::getValue('ajax') != 'true' AND !sizeof($this->errors))
 Tools::redirect('order.php?'.(isset($idProduct) ? 'ipa='.(int)($idProduct) : ''));
  }
 }
}
public function displayContent()
{
 parent::displayContent();
 self::$smarty->display(_PS_THEME_DIR_.'errors.tpl');
}
}

 

 

Voici le code à rajouter dans la fonction preProcess juste après la ligne 170 :

 

if ((int)$idProductAttribute)
									    $minimal_quantity = Attribute::getAttributeMinimalQty((int)$idProductAttribute);
									 else
									    $minimal_quantity = $producToAdd->minimal_quantity;						 
									 if ($qty % $minimal_quantity != 0)
									 {
									    $this->errors[] = Tools::displayError('You can only only add this item to your cart with a quantity multiple of ').' '.$minimal_quantity;
									 }

 

Je demande juste le code complet de l'override car je n'y arriverais pas comme ça.

Je n'ai pas les bases du php, il me faut donc l'exemple du fichier pour en comprendre le mécanisme, c'est comme ça que j'ai appris à manier le css et bien d'autres choses.

 

Merci

Link to comment
Share on other sites

Ton override complet :

 

class CartControllerCore extends FrontController
{
public function preProcess()
{
 parent::preProcess();
 $orderTotal = self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
 $this->cartDiscounts = self::$cart->getDiscounts();
 foreach ($this->cartDiscounts AS $k => $this->cartDiscount)
  if ($error = self::$cart->checkDiscountValidity(new Discount((int)($this->cartDiscount['id_discount'])), $this->cartDiscounts, $orderTotal, self::$cart->getProducts()))
   self::$cart->deleteDiscount((int)($this->cartDiscount['id_discount']));
 $add = Tools::getIsset('add') ? 1 : 0;
 $delete = Tools::getIsset('delete') ? 1 : 0;
 if (Configuration::get('PS_TOKEN_ENABLE') == 1 &&
  strcasecmp(Tools::getToken(false), strval(Tools::getValue('token'))) &&
  self::$cookie->isLogged() === true)
  $this->errors[] = Tools::displayError('Invalid token');
 // Update the cart ONLY if $this->cookies are available, in order to avoid ghost carts created by bots
 if (($add OR Tools::getIsset('update') OR $delete) AND isset(self::$cookie->date_add))
 {
  //get the values
  $idProduct = (int)(Tools::getValue('id_product', NULL));
  $idProductAttribute = (int)(Tools::getValue('id_product_attribute', Tools::getValue('ipa')));
  $customizationId = (int)(Tools::getValue('id_customization', 0));
  $qty = (int)(abs(Tools::getValue('qty', 1)));
  if ($qty == 0)
   $this->errors[] = Tools::displayError('Null quantity');
  elseif (!$idProduct)
   $this->errors[] = Tools::displayError('Product not found');
  else
  {
   $producToAdd = new Product((int)($idProduct), true, (int)(self::$cookie->id_lang));
   if ((!$producToAdd->id OR !$producToAdd->active) AND !$delete)
	 if (Tools::getValue('ajax') == 'true')
	  die('{"hasError" : true, "errors" : ["'.Tools::displayError('Pproduct is no longer available.', false).'"]}');
	 else
	  $this->errors[] = Tools::displayError('Pproduct is no longer available.', false);
   else
   {
	 /* Check the quantity availability */
	 if ($idProductAttribute AND is_numeric($idProductAttribute))
	 {
	  if (!$delete AND !$producToAdd->isAvailableWhenOutOfStock($producToAdd->out_of_stock) AND !Attribute::checkAttributeQty((int)$idProductAttribute, (int)$qty))
	   if (Tools::getValue('ajax') == 'true')
	    die('{"hasError" : true, "errors" : ["'.Tools::displayError('There is not enough product in stock.', false).'"]}');
	   else
	    $this->errors[] = Tools::displayError('There is not enough product in stock.');
	 }
	 elseif ($producToAdd->hasAttributes() AND !$delete)
	 {
	  $idProductAttribute = Product::getDefaultAttribute((int)$producToAdd->id, (int)$producToAdd->out_of_stock == 2 ? !(int)Configuration::get('PS_ORDER_OUT_OF_STOCK') : !(int)$producToAdd->out_of_stock);
	  if (!$idProductAttribute)
	   Tools::redirectAdmin($link->getProductLink($producToAdd));
	  elseif (!$delete AND !$producToAdd->isAvailableWhenOutOfStock($producToAdd->out_of_stock) AND !Attribute::checkAttributeQty((int)$idProductAttribute, (int)$qty))
	   if (Tools::getValue('ajax') == 'true')
	    die('{"hasError" : true, "errors" : ["'.Tools::displayError('There is not enough product in stock.', false).'"]}');
	   else
	    $this->errors[] = Tools::displayError('There is not enough product in stock.');
	 }
	 elseif (!$delete AND !$producToAdd->checkQty((int)$qty))
	  if (Tools::getValue('ajax') == 'true')
	    die('{"hasError" : true, "errors" : ["'.Tools::displayError('There is not enough product in stock.').'"]}');
	   else
	    $this->errors[] = Tools::displayError('There is not enough product in stock.');
	 /* Check vouchers compatibility */
	 if ($add AND (($producToAdd->specificPrice AND (float)($producToAdd->specificPrice['reduction'])) OR $producToAdd->on_sale))
	 {
	  $discounts = self::$cart->getDiscounts();
	  $hasUndiscountedProduct = null;
	  foreach($discounts as $discount)
	  {
	   if(is_null($hasUndiscountedProduct))
	   {
	    $hasUndiscountedProduct = false;
	    foreach(self::$cart->getProducts() as $product)
			 if($product['reduction_applies'] === false)
			 {
			  $hasUndiscountedProduct = true;
			  break;
			 }
	   }
	   if (!$discount['cumulable_reduction'] && ($discount['id_discount_type'] != 1 || !$hasUndiscountedProduct))
	    if (Tools::getValue('ajax') == 'true')
			 die('{"hasError" : true, "errors" : ["'.Tools::displayError('Cannot add this product because current voucher does not allow additional discounts.').'"]}');
	    else
			 $this->errors[] = Tools::displayError('Cannot add this product because current voucher does not allow additional discounts.');

	  }
	 }
if ((int)$idProductAttribute)
																			    $minimal_quantity = Attribute::getAttributeMinimalQty((int)$idProductAttribute);
																			 else
																			    $minimal_quantity = $producToAdd->minimal_quantity;										 
																			 if ($qty % $minimal_quantity != 0)
																			 {
																			    $this->errors[] = Tools::displayError('You can only only add this item to your cart with a quantity multiple of ').' '.$minimal_quantity;
																			 }
	 if (!sizeof($this->errors))
	 {
	  if ($add AND $qty >= 0)
	  {
	   /* Product addition to the cart */
	   if (!isset(self::$cart->id) OR !self::$cart->id)
	   {
	    self::$cart->add();
	    if (self::$cart->id)
			 self::$cookie->id_cart = (int)(self::$cart->id);
	   }
	   if ($add AND !$producToAdd->hasAllRequiredCustomizableFields() AND !$customizationId)
	    $this->errors[] = Tools::displayError('Please fill in all required fields, then save the customization.');
	   if (!sizeof($this->errors))
	   {
	    $updateQuantity = self::$cart->updateQty((int)($qty), (int)($idProduct), (int)($idProductAttribute), $customizationId, Tools::getValue('op', 'up'));
	    if ($updateQuantity < 0)
	    {
			 /* if product has attribute, minimal quantity is set with minimal quantity of attribute*/
			 if ((int)$idProductAttribute)
			  $minimal_quantity = Attribute::getAttributeMinimalQty((int)$idProductAttribute);
			 else
			  $minimal_quantity = $producToAdd->minimal_quantity;
			 if (Tools::getValue('ajax') == 'true')
			  die('{"hasError" : true, "errors" : ["'.Tools::displayError('You must add', false).' '.$minimal_quantity.' '.Tools::displayError('Minimum quantity', false).'"]}');
			 else
			  $this->errors[] = Tools::displayError('You must add').' '.$minimal_quantity.' '.Tools::displayError('Minimum quantity')
			  .((isset($_SERVER['HTTP_REFERER']) AND basename($_SERVER['HTTP_REFERER']) == 'order.php' OR (!Tools::isSubmit('ajax') AND substr(basename($_SERVER['REQUEST_URI']),0, strlen('cart.php')) == 'cart.php')) ? ('<script language="javascript">setTimeout("history.back()",5000);</script><br />- '.
			  Tools::displayError('You will be redirected to your cart in a few seconds.')) : '');
	    }
	    elseif (!$updateQuantity)
	    {
			 if (Tools::getValue('ajax') == 'true')
			  die('{"hasError" : true, "errors" : ["'.Tools::displayError('You already have the maximum quantity available for this product.', false).'"]}');
			 else
			  $this->errors[] = Tools::displayError('You already have the maximum quantity available for this product.')
			  .((isset($_SERVER['HTTP_REFERER']) AND basename($_SERVER['HTTP_REFERER']) == 'order.php' OR (!Tools::isSubmit('ajax') AND substr(basename($_SERVER['REQUEST_URI']),0, strlen('cart.php')) == 'cart.php')) ? ('<script language="javascript">setTimeout("history.back()",5000);</script><br />- '.
			  Tools::displayError('You will be redirected to your cart in a few seconds.')) : '');
	    }
	   }
	  }
	  elseif ($delete)
	  {
	   if (self::$cart->deleteProduct((int)($idProduct), (int)($idProductAttribute), (int)($customizationId)))
	    if (!Cart::getNbProducts((int)(self::$cart->id)))
	    {
			 self::$cart->id_carrier = 0;
			 self::$cart->gift = 0;
			 self::$cart->gift_message = '';
			 self::$cart->update();
	    }
	  }
	 }
	 $discounts = self::$cart->getDiscounts();
	 foreach($discounts AS $discount)
	 {
	  $discountObj = new Discount((int)($discount['id_discount']), (int)(self::$cookie->id_lang));
	  if ($error = self::$cart->checkDiscountValidity($discountObj, $discounts, self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS), self::$cart->getProducts()))
	  {
	   self::$cart->deleteDiscount((int)($discount['id_discount']));
	   self::$cart->update();
	   $errors[] = $error;
	  }
	 }
	 if (!sizeof($this->errors))
	 {
	  $queryString = Tools::safeOutput(Tools::getValue('query', NULL));
	  if ($queryString AND !Configuration::get('PS_CART_REDIRECT'))
	   Tools::redirect('search.php?search='.$queryString);
	  if (isset($_SERVER['HTTP_REFERER']))
	  {
	   // Redirect to previous page
	   preg_match('!http(s?)://(.*)/(.*)!', $_SERVER['HTTP_REFERER'], $regs);
	   if (isset($regs[3]) AND !Configuration::get('PS_CART_REDIRECT') AND Tools::getValue('ajax') != 'true')
	    Tools::redirect($_SERVER['HTTP_REFERER']);
	  }
	 }
   }
   if (Tools::getValue('ajax') != 'true' AND !sizeof($this->errors))
	 Tools::redirect('order.php?'.(isset($idProduct) ? 'ipa='.(int)($idProduct) : ''));
  }
 }
}
}

 

Mokay maintenant ? ^_^

Link to comment
Share on other sites

Merci mais ça ne marche pas.

J'avais déjà essayé en reprenant tous ce code.

J'aurais tout de même compris le principe de reprendre à partir de la fonction preProcess.

 

Bref, si je comprend bien je ne pourrais pas overrider cette fonctionnalité.

Dommage

Link to comment
Share on other sites

Ouh la Gaffe math_php !!

 

L'override que tu as fourni a jomcdonald commence par :

class CartControllerCore extends FrontController

 

C'est pas un override ca, c'est la classe mère :-)

 

jomcdonald, il faut effectivement copier/coller le code de math_php, mais remplacer

class CartControllerCore extends FrontController

par

class CartController extends CartControllerCore{

 

et ca devrait tourner...

Link to comment
Share on other sites

Ce qui nous donne (pour faire un copier/coller simple pour les gens qui lisent pas le php) :

 

class CartController extends CartControllerCore{
public function preProcess() {
 parent::preProcess();
 $orderTotal = self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
 $this->cartDiscounts = self::$cart->getDiscounts();
 foreach ($this->cartDiscounts AS $k => $this->cartDiscount)
  if ($error = self::$cart->checkDiscountValidity(new Discount((int)($this->cartDiscount['id_discount'])), $this->cartDiscounts, $orderTotal, self::$cart->getProducts()))
   self::$cart->deleteDiscount((int)($this->cartDiscount['id_discount']));
 $add = Tools::getIsset('add') ? 1 : 0;
 $delete = Tools::getIsset('delete') ? 1 : 0;
 if (Configuration::get('PS_TOKEN_ENABLE') == 1 &&
  strcasecmp(Tools::getToken(false), strval(Tools::getValue('token'))) &&
  self::$cookie->isLogged() === true)
  $this->errors[] = Tools::displayError('Invalid token');
 // Update the cart ONLY if $this->cookies are available, in order to avoid ghost carts created by bots
 if (($add OR Tools::getIsset('update') OR $delete) AND isset(self::$cookie->date_add))
 {
  //get the values
  $idProduct = (int)(Tools::getValue('id_product', NULL));
  $idProductAttribute = (int)(Tools::getValue('id_product_attribute', Tools::getValue('ipa')));
  $customizationId = (int)(Tools::getValue('id_customization', 0));
  $qty = (int)(abs(Tools::getValue('qty', 1)));
  if ($qty == 0)
   $this->errors[] = Tools::displayError('Null quantity');
  elseif (!$idProduct)
   $this->errors[] = Tools::displayError('Product not found');
  else
  {
   $producToAdd = new Product((int)($idProduct), true, (int)(self::$cookie->id_lang));
   if ((!$producToAdd->id OR !$producToAdd->active) AND !$delete)
			 if (Tools::getValue('ajax') == 'true')
			  die('{"hasError" : true, "errors" : ["'.Tools::displayError('Pproduct is no longer available.', false).'"]}');
			 else
			  $this->errors[] = Tools::displayError('Pproduct is no longer available.', false);
   else
   {
			 /* Check the quantity availability */
			 if ($idProductAttribute AND is_numeric($idProductAttribute))
			 {
			  if (!$delete AND !$producToAdd->isAvailableWhenOutOfStock($producToAdd->out_of_stock) AND !Attribute::checkAttributeQty((int)$idProductAttribute, (int)$qty))
			   if (Tools::getValue('ajax') == 'true')
			    die('{"hasError" : true, "errors" : ["'.Tools::displayError('There is not enough product in stock.', false).'"]}');
			   else
			    $this->errors[] = Tools::displayError('There is not enough product in stock.');
			 }
			 elseif ($producToAdd->hasAttributes() AND !$delete)
			 {
			  $idProductAttribute = Product::getDefaultAttribute((int)$producToAdd->id, (int)$producToAdd->out_of_stock == 2 ? !(int)Configuration::get('PS_ORDER_OUT_OF_STOCK') : !(int)$producToAdd->out_of_stock);
			  if (!$idProductAttribute)
			   Tools::redirectAdmin($link->getProductLink($producToAdd));
			  elseif (!$delete AND !$producToAdd->isAvailableWhenOutOfStock($producToAdd->out_of_stock) AND !Attribute::checkAttributeQty((int)$idProductAttribute, (int)$qty))
			   if (Tools::getValue('ajax') == 'true')
			    die('{"hasError" : true, "errors" : ["'.Tools::displayError('There is not enough product in stock.', false).'"]}');
			   else
			    $this->errors[] = Tools::displayError('There is not enough product in stock.');
			 }
			 elseif (!$delete AND !$producToAdd->checkQty((int)$qty))
			  if (Tools::getValue('ajax') == 'true')
			    die('{"hasError" : true, "errors" : ["'.Tools::displayError('There is not enough product in stock.').'"]}');
			   else
			    $this->errors[] = Tools::displayError('There is not enough product in stock.');
			 /* Check vouchers compatibility */
			 if ($add AND (($producToAdd->specificPrice AND (float)($producToAdd->specificPrice['reduction'])) OR $producToAdd->on_sale))
			 {
			  $discounts = self::$cart->getDiscounts();
			  $hasUndiscountedProduct = null;
			  foreach($discounts as $discount)
			  {
			   if(is_null($hasUndiscountedProduct))
			   {
			    $hasUndiscountedProduct = false;
			    foreach(self::$cart->getProducts() as $product)
							 if($product['reduction_applies'] === false)
							 {
							  $hasUndiscountedProduct = true;
							  break;
							 }
			   }
			   if (!$discount['cumulable_reduction'] && ($discount['id_discount_type'] != 1 || !$hasUndiscountedProduct))
			    if (Tools::getValue('ajax') == 'true')
							 die('{"hasError" : true, "errors" : ["'.Tools::displayError('Cannot add this product because current voucher does not allow additional discounts.').'"]}');
			    else
							 $this->errors[] = Tools::displayError('Cannot add this product because current voucher does not allow additional discounts.');

			  }
			 }
if ((int)$idProductAttribute)
																																							    $minimal_quantity = Attribute::getAttributeMinimalQty((int)$idProductAttribute);
																																							 else
																																							    $minimal_quantity = $producToAdd->minimal_quantity;																		 
																																							 if ($qty % $minimal_quantity != 0)
																																							 {
																																							    $this->errors[] = Tools::displayError('You can only only add this item to your cart with a quantity multiple of ').' '.$minimal_quantity;
																																							 }
			 if (!sizeof($this->errors))
			 {
			  if ($add AND $qty >= 0)
			  {
			   /* Product addition to the cart */
			   if (!isset(self::$cart->id) OR !self::$cart->id)
			   {
			    self::$cart->add();
			    if (self::$cart->id)
							 self::$cookie->id_cart = (int)(self::$cart->id);
			   }
			   if ($add AND !$producToAdd->hasAllRequiredCustomizableFields() AND !$customizationId)
			    $this->errors[] = Tools::displayError('Please fill in all required fields, then save the customization.');
			   if (!sizeof($this->errors))
			   {
			    $updateQuantity = self::$cart->updateQty((int)($qty), (int)($idProduct), (int)($idProductAttribute), $customizationId, Tools::getValue('op', 'up'));
			    if ($updateQuantity < 0)
			    {
							 /* if product has attribute, minimal quantity is set with minimal quantity of attribute*/
							 if ((int)$idProductAttribute)
							  $minimal_quantity = Attribute::getAttributeMinimalQty((int)$idProductAttribute);
							 else
							  $minimal_quantity = $producToAdd->minimal_quantity;
							 if (Tools::getValue('ajax') == 'true')
							  die('{"hasError" : true, "errors" : ["'.Tools::displayError('You must add', false).' '.$minimal_quantity.' '.Tools::displayError('Minimum quantity', false).'"]}');
							 else
							  $this->errors[] = Tools::displayError('You must add').' '.$minimal_quantity.' '.Tools::displayError('Minimum quantity')
							  .((isset($_SERVER['HTTP_REFERER']) AND basename($_SERVER['HTTP_REFERER']) == 'order.php' OR (!Tools::isSubmit('ajax') AND substr(basename($_SERVER['REQUEST_URI']),0, strlen('cart.php')) == 'cart.php')) ? ('<script language="javascript">setTimeout("history.back()",5000);</script><br />- '.
							  Tools::displayError('You will be redirected to your cart in a few seconds.')) : '');
			    }
			    elseif (!$updateQuantity)
			    {
							 if (Tools::getValue('ajax') == 'true')
							  die('{"hasError" : true, "errors" : ["'.Tools::displayError('You already have the maximum quantity available for this product.', false).'"]}');
							 else
							  $this->errors[] = Tools::displayError('You already have the maximum quantity available for this product.')
							  .((isset($_SERVER['HTTP_REFERER']) AND basename($_SERVER['HTTP_REFERER']) == 'order.php' OR (!Tools::isSubmit('ajax') AND substr(basename($_SERVER['REQUEST_URI']),0, strlen('cart.php')) == 'cart.php')) ? ('<script language="javascript">setTimeout("history.back()",5000);</script><br />- '.
							  Tools::displayError('You will be redirected to your cart in a few seconds.')) : '');
			    }
			   }
			  }
			  elseif ($delete)
			  {
			   if (self::$cart->deleteProduct((int)($idProduct), (int)($idProductAttribute), (int)($customizationId)))
			    if (!Cart::getNbProducts((int)(self::$cart->id)))
			    {
							 self::$cart->id_carrier = 0;
							 self::$cart->gift = 0;
							 self::$cart->gift_message = '';
							 self::$cart->update();
			    }
			  }
			 }
			 $discounts = self::$cart->getDiscounts();
			 foreach($discounts AS $discount)
			 {
			  $discountObj = new Discount((int)($discount['id_discount']), (int)(self::$cookie->id_lang));
			  if ($error = self::$cart->checkDiscountValidity($discountObj, $discounts, self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS), self::$cart->getProducts()))
			  {
			   self::$cart->deleteDiscount((int)($discount['id_discount']));
			   self::$cart->update();
			   $errors[] = $error;
			  }
			 }
			 if (!sizeof($this->errors))
			 {
			  $queryString = Tools::safeOutput(Tools::getValue('query', NULL));
			  if ($queryString AND !Configuration::get('PS_CART_REDIRECT'))
			   Tools::redirect('search.php?search='.$queryString);
			  if (isset($_SERVER['HTTP_REFERER']))
			  {
			   // Redirect to previous page
			   preg_match('!http(s?)://(.*)/(.*)!', $_SERVER['HTTP_REFERER'], $regs);
			   if (isset($regs[3]) AND !Configuration::get('PS_CART_REDIRECT') AND Tools::getValue('ajax') != 'true')
			    Tools::redirect($_SERVER['HTTP_REFERER']);
			  }
			 }
   }
   if (Tools::getValue('ajax') != 'true' AND !sizeof($this->errors))
			 Tools::redirect('order.php?'.(isset($idProduct) ? 'ipa='.(int)($idProduct) : ''));
  }
 }
}
}

Link to comment
Share on other sites

Ouh la Gaffe math_php !!

 

L'override que tu as fourni a jomcdonald commence par :

class CartControllerCore extends FrontController

 

 

Dans mon premier post, c'était écrit correctement, effectivement à la fin ça se dégrade. <_<

Link to comment
Share on other sites

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...