Jump to content

Bugs dans les classes AdminProductController, Product


Recommended Posts

Bonjour,

 

version: 1.5.1.0

 

A propos de processDelete() dans la classe AdminProductsControllerCore:

Je ne comprends pas la manière dont est codée cette fonction,

Il me semble que cela ne peut pas fonctionner !

 

 

Voici le code actuel

if (Validate::isLoadedObject($object = $this->loadObject()) && isset($this->fieldImageSettings))
{
// check if request at least one object with noZeroObject
if (isset($object->noZeroObject) && count($taxes = call_user_func(array($this->className, $object->noZeroObject))) <= 1)
 $this->errors[] = Tools::displayError('You need at least one object.').' <b>'.$this->table.'</b><br />'.Tools::displayError('You cannot delete all of the items.');
else
{
 /*
  * @since 1.5.0
  * It is NOT possible to delete a product if there are currently:
  * - physical stock for this product
  * - supply order(s) for this product
  */
 if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $object->advanced_stock_management)
 {
  $stock_manager = StockManagerFactory::getManager();
  $physical_quantity = $stock_manager->getProductPhysicalQuantities($object->id, 0);
$real_quantity = $stock_manager->getProductRealQuantities($object->id, 0);
  if ($physical_quantity > 0 || $real_quantity > $physical_quantity)
$this->errors[] = Tools::displayError('You cannot delete the product because there is physical stock left or supply orders in progress.');
 }
 if ($object->delete())
 {
  $id_category = (int)Tools::getValue('id_category');
  $category_url = empty($id_category) ? '' : '&id_category='.(int)$id_category;
  $this->redirect_after = self::$currentIndex.'&conf=1&token='.$this->token.$category_url;
 }
 $this->errors[] = Tools::displayError('An error occurred during deletion.');
}
}
else
$this->errors[] = Tools::displayError('An error occurred while deleting object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');

 

La suppression est interdite si la condition est remplie :

Sauf qu'ici quelque soit le résultat de la condition, on supprime le produit !

 

 

Ne devrait-on pas plutôt avoir :

 

if (Validate::isLoadedObject($object = $this->loadObject()) && isset($this->fieldImageSettings))
{
// check if request at least one object with noZeroObject
if (isset($object->noZeroObject) && count($taxes = call_user_func(array($this->className, $object->noZeroObject))) <= 1)
 $this->errors[] = Tools::displayError('You need at least one object.').' <b>'.$this->table.'</b><br />'.Tools::displayError('You cannot delete all of the items.');
else
{
 /*
  * @since 1.5.0
  * It is NOT possible to delete a product if there are currently:
  * - physical stock for this product
  * - supply order(s) for this product
  */
 if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $object->advanced_stock_management)
 {
  $stock_manager = StockManagerFactory::getManager();
  $physical_quantity = $stock_manager->getProductPhysicalQuantities($object->id, 0);
$real_quantity = $stock_manager->getProductRealQuantities($object->id, 0);
  if ($physical_quantity > 0 || $real_quantity > $physical_quantity)
$this->errors[] = Tools::displayError('You cannot delete the product because there is physical stock left or supply orders in progress.');
 }
 if (!empty($this->errors[]))
  if ($object->delete())
  {
$id_category = (int)Tools::getValue('id_category');
$category_url = empty($id_category) ? '' : '&id_category='.(int)$id_category;
$this->redirect_after = self::$currentIndex.'&conf=1&token='.$this->token.$category_url;
  }
  else
$this->errors[] = Tools::displayError('An error occurred during deletion.');
}
}
else
$this->errors[] = Tools::displayError('An error occurred while deleting object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');

 

 

Merci de bien vouloir en discuter

Comme c'est une fonction cœur, je trouve bizarre que personne n'ait de problème.

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

Bonjour,

Il y a une autre erreur dans la classe product :

 

public function deleteCategories($clean_positions = false)
{
 $return = Db::getInstance()->delete('category_product', 'id_product = '.(int)$this->id);
 if ($clean_positions === true)
 {
  $res = Db::getInstance()->executeS(
'SELECT `id_category`
FROM `'._DB_PREFIX_.'category_product`
WHERE `id_product` = '.(int)$this->id
  );
  foreach ($result as $row)
$this->cleanPositions((int)$row['id_category']);
 }
 return $return;

 

Cette fonction ne peut pas fonctionner.

Les lignes étant supprimées, la seconde requête ne renverra jamais de résultat.

 

 

Je propose :

 

   public function deleteCategories($clean_positions = false)
   {
       if ($clean_positions === true)
           if ($result = Db::getInstance()->executeS(
               'SELECT `id_category`
               FROM `'._DB_PREFIX_.'category_product`
               WHERE `id_product` = '.(int)$this->id) === false)
               return false;

       $res = Db::getInstance()->delete('category_product', 'id_product = '.(int)$this->id);

       if ($clean_positions === true && $result)
           foreach ($result as $row)
               $res &= $this->cleanPositions((int)$row['id_category']);

       return $res;
   }


}

Edited by chantane (see edit history)
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...