[-] BO : Fixed incorrect error message in a_s_m

[+] BO : Added support for Depends On Stock
[-] BO : Added missing check if warehouse is set in csv
This commit is contained in:
PhpMadman committed 2013-07-29 11:54:15 +02:00
1 parent 909948bfb9
commit 1dd7d6afcc
1 file changed
+51 -26
+51 -26
View File
@@ -248,7 +248,14 @@ class AdminImportControllerCore extends AdminController
'label' => $this->l('Advanced Stock Management'), 'label' => $this->l('Advanced Stock Management'),
'help' => $this->l('Enable Advanced Stock Management on product (0 = No, 1 = Yes)') 'help' => $this->l('Enable Advanced Stock Management on product (0 = No, 1 = Yes)')
), ),
'warehouse' => array('label' => $this->l('Warehouse')), 'depends_on_stock' => array(
'label' => $this->l('Depends On Stock'),
'help' => $this->l('0 = Use quantity set in product, 1 = Use quantity from Warehouse')
),
'warehouse' => array(
'label' => $this->l('Warehouse'),
'help' => $this->l('ID of the warehouse to set as storeage')
),
); );
self::$default_values = array( self::$default_values = array(
@@ -1486,7 +1493,7 @@ class AdminImportControllerCore extends AdminController
// set advanced stock managment // set advanced stock managment
if($product->advanced_stock_management) { if($product->advanced_stock_management) {
if($product->advanced_stock_management != 1 && $product->advanced_stock_management != 0) { if($product->advanced_stock_management != 1 && $product->advanced_stock_management != 0) {
$this->warnings[] = Tools::displayError('Advanced stock management has incorrect value. Not set'); $this->warnings[] = sprintf(Tools::displayError('Advanced stock management has incorrect value. Not set for product %1$s '),$product->name[$default_language_id]);
} elseif(!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management == 1) { } elseif(!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management == 1) {
$this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, can not enable on product %1$s '),$product->name[$default_language_id]); $this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, can not enable on product %1$s '),$product->name[$default_language_id]);
} else { } else {
@@ -1499,34 +1506,52 @@ class AdminImportControllerCore extends AdminController
} }
// Check if warehouse exists // Check if warehouse exists
if(Warehouse::exists($product->warehouse)) { if($product->warehouse) {
// Get already associated warehouses if(!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
$associated_warehouses_collection = WarehouseProductLocation::getCollection($product->id); $this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, warehouse not set on product %1$s '),$product->name[$default_language_id]);
} else {
// Delete any entry in warehouse for this product if(Warehouse::exists($product->warehouse)) {
foreach ($associated_warehouses_collection as $awc) // Get already associated warehouses
{ $associated_warehouses_collection = WarehouseProductLocation::getCollection($product->id);
$awc->delete();
// Delete any entry in warehouse for this product
foreach ($associated_warehouses_collection as $awc)
{
$awc->delete();
}
$warehouse_location_entity = new WarehouseProductLocation();
$warehouse_location_entity->id_product = $product->id;
$warehouse_location_entity->id_product_attribute = 0;
$warehouse_location_entity->id_warehouse = $product->warehouse;
$warehouse_location_entity->save();
StockAvailable::synchronize($product->id); // Don't know if it is needed, but it can't hurt
} else {
$this->warnings[] = sprintf(Tools::displayError('Warehouse did not exists, can not set on product %1$s '),$product->name[$default_language_id]);
}
} }
$warehouse_location_entity = new WarehouseProductLocation();
$warehouse_location_entity->id_product = $product->id;
$warehouse_location_entity->id_product_attribute = 0;
$warehouse_location_entity->id_warehouse = $product->warehouse;
$warehouse_location_entity->save();
StockAvailable::synchronize($product->id); // Don't know if it is needed, but it can't hurt
} else {
$this->warnings[] = sprintf(Tools::displayError('Warehouse did not exists, can not set on product %1$s '),$product->name[$default_language_id]);
} }
// stock available // stock available
if (Shop::isFeatureActive()) if($product->depends_on_stock) { // if not set
{ if($product->depends_on_stock != 0 && $product->depends_on_stock != 1) {
foreach ($shops as $shop) $this->warnings[] = sprintf(Tools::displayError('Incorrect value for depends on stock for product %1$s '),$product->name[$default_language_id]);
StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, (int)$shop); } elseif((!$product->advanced_stock_management || $product->advanced_stock_management == 0) && $product->depends_on_stock == 1) {
$this->warnings[] = sprintf(Tools::displayError('Advanced stock management not enabled, can not set depends on stock %1$s '),$product->name[$default_language_id]);
} else {
StockAvailable::setProductDependsOnStock($product->id, $product->depends_on_stock);
}
} else { // if not depends_on_stock set, use normal qty
if (Shop::isFeatureActive())
{
foreach ($shops as $shop)
StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, (int)$shop);
}
else
{
StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, $this->context->shop->id);
}
} }
else
StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, $this->context->shop->id);
} }