// It is not possible to delete a product if there are currently physical stock/supply order(s) for this product, anymore
This commit is contained in:
+35
-18
@@ -587,31 +587,48 @@ class ProductCore extends ObjectModel
|
|||||||
|
|
||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* @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
|
||||||
|
*/
|
||||||
|
$stock_manager = StockManagerFactory::getManager();
|
||||||
|
$physical_quantity = $stock_manager->getProductPhysicalQuantities($this->id, 0);
|
||||||
|
$real_quantity = $stock_manager->getProductRealQuantities($this->id, 0);
|
||||||
|
if ($physical_quantity > 0)
|
||||||
|
return false;
|
||||||
|
if ($real_quantity > $physical_quantity)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!GroupReduction::deleteProductReduction($this->id))
|
if (!GroupReduction::deleteProductReduction($this->id))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Hook::exec('deleteProduct', array('product' => $this));
|
Hook::exec('deleteProduct', array('product' => $this));
|
||||||
if (!parent::delete() OR
|
|
||||||
!$this->deleteCategories(true) OR
|
if (!parent::delete() ||
|
||||||
!$this->deleteImages() OR
|
!$this->deleteCategories(true) ||
|
||||||
!$this->deleteProductAttributes() OR
|
!$this->deleteImages() ||
|
||||||
!$this->deleteProductFeatures() OR
|
!$this->deleteProductAttributes() ||
|
||||||
!$this->deleteTags() OR
|
!$this->deleteProductFeatures() ||
|
||||||
!$this->deleteCartProducts() OR
|
!$this->deleteTags() ||
|
||||||
!$this->deleteAttributesImpacts() OR
|
!$this->deleteCartProducts() ||
|
||||||
!$this->deleteAttachments() OR
|
!$this->deleteAttributesImpacts() ||
|
||||||
!$this->deleteCustomization() OR
|
!$this->deleteAttachments() ||
|
||||||
!SpecificPrice::deleteByProductId((int)$this->id) OR
|
!$this->deleteCustomization() ||
|
||||||
!$this->deletePack() OR
|
!SpecificPrice::deleteByProductId((int)$this->id) ||
|
||||||
!$this->deleteProductSale() OR
|
!$this->deletePack() ||
|
||||||
!$this->deleteSceneProducts() OR
|
!$this->deleteProductSale() ||
|
||||||
!$this->deleteSearchIndexes() OR
|
!$this->deleteSceneProducts() ||
|
||||||
!$this->deleteAccessories() OR
|
!$this->deleteSearchIndexes() ||
|
||||||
|
!$this->deleteAccessories() ||
|
||||||
!$this->deleteFromAccessories())
|
!$this->deleteFromAccessories())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ($id = ProductDownload::getIdFromIdProduct($this->id))
|
if ($id = ProductDownload::getIdFromIdProduct($this->id))
|
||||||
if ($productDownload = new ProductDownload($id) AND !$productDownload->delete(true))
|
if ($product_download = new ProductDownload($id) && !$product_download->delete(true))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3844,7 +3861,7 @@ class ProductCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the combination url anchor of the product
|
* Get the combination url anchor of the product
|
||||||
*
|
*
|
||||||
* @param integer $id_product_attribute
|
* @param integer $id_product_attribute
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -421,7 +421,9 @@ class StockManagerCore implements StockManagerInterface
|
|||||||
$query = new DbQuery();
|
$query = new DbQuery();
|
||||||
$query->select('SUM('.($usable ? 's.usable_quantity' : 's.physical_quantity').')');
|
$query->select('SUM('.($usable ? 's.usable_quantity' : 's.physical_quantity').')');
|
||||||
$query->from('stock s');
|
$query->from('stock s');
|
||||||
$query->where('s.id_product = '.(int)$id_product.' AND s.id_product_attribute = '.(int)$id_product_attribute);
|
$query->where('s.id_product = '.(int)$id_product);
|
||||||
|
if (0 != $id_product_attribute)
|
||||||
|
$query->where('s.id_product_attribute = '.(int)$id_product_attribute);
|
||||||
|
|
||||||
if (count($ids_warehouse))
|
if (count($ids_warehouse))
|
||||||
$query->where('s.id_warehouse IN('.implode(', ', $ids_warehouse).')');
|
$query->where('s.id_warehouse IN('.implode(', ', $ids_warehouse).')');
|
||||||
@@ -439,7 +441,9 @@ class StockManagerCore implements StockManagerInterface
|
|||||||
$query->select('SUM(od.product_quantity)');
|
$query->select('SUM(od.product_quantity)');
|
||||||
$query->from('order_detail od');
|
$query->from('order_detail od');
|
||||||
$query->leftjoin('orders o ON o.id_order = od.id_order');
|
$query->leftjoin('orders o ON o.id_order = od.id_order');
|
||||||
$query->where('od.product_id = '.(int)$id_product.' AND od.product_attribute_id = '.(int)$id_product_attribute);
|
$query->where('od.product_id = '.(int)$id_product);
|
||||||
|
if (0 != $id_product_attribute)
|
||||||
|
$query->where('od.product_attribute_id = '.(int)$id_product_attribute);
|
||||||
$query->where('o.delivery_number = 0');
|
$query->where('o.delivery_number = 0');
|
||||||
$query->where('o.valid = 1');
|
$query->where('o.valid = 1');
|
||||||
$client_orders_qty = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
$client_orders_qty = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ interface StockManagerInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* For a given product, returns its physical quantity
|
* For a given product, returns its physical quantity
|
||||||
|
* If the given product has combinations and $id_product_attribute is null, returns the sum for all combinations
|
||||||
*
|
*
|
||||||
* @param int $id_product
|
* @param int $id_product
|
||||||
* @param int $id_product_attribute
|
* @param int $id_product_attribute
|
||||||
@@ -81,6 +82,7 @@ interface StockManagerInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* For a given product, returns its real quantity
|
* For a given product, returns its real quantity
|
||||||
|
* If the given product has combinations and $id_product_attribute is null, returns the sum for all combinations
|
||||||
* Real quantity : (physical_qty + supplier_orders_qty - client_orders_qty)
|
* Real quantity : (physical_qty + supplier_orders_qty - client_orders_qty)
|
||||||
* If $usable is defined, real quantity: usable_qty + supplier_orders_qty - client_orders_qty
|
* If $usable is defined, real quantity: usable_qty + supplier_orders_qty - client_orders_qty
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -899,6 +899,8 @@ class AdminStockManagementControllerCore extends AdminController
|
|||||||
$id_product_attribute = (int)Tools::getValue('id_product_attribute', 0);
|
$id_product_attribute = (int)Tools::getValue('id_product_attribute', 0);
|
||||||
|
|
||||||
$product_is_valid = false;
|
$product_is_valid = false;
|
||||||
|
$is_pack = false;
|
||||||
|
$is_virtual = false;
|
||||||
$lang_id = $this->context->language->id;
|
$lang_id = $this->context->language->id;
|
||||||
|
|
||||||
// try to load product attribute first
|
// try to load product attribute first
|
||||||
|
|||||||
Reference in New Issue
Block a user