This commit is contained in:
gRoussac committed 2013-12-04 18:49:34 +01:00
1 parent 7140a63272
commit ec8ca92e67
1 file changed
+23 -29
+23 -29
View File
@@ -1707,68 +1707,62 @@ 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[] = sprintf(Tools::displayError('Advanced stock management has incorrect value. Not set for product %1$s '),$product->name[$default_language_id]); $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
$product->setAdvancedStockManagement($product->advanced_stock_management); $product->setAdvancedStockManagement($product->advanced_stock_management);
}
// automaticly disable depends on stock, if a_s_m set to disabled // automaticly disable depends on stock, if a_s_m set to disabled
if (StockAvailable::dependsOnStock($product->id) == 1 && $product->advanced_stock_management == 0) { if (StockAvailable::dependsOnStock($product->id) == 1 && $product->advanced_stock_management == 0)
StockAvailable::setProductDependsOnStock($product->id, 0); StockAvailable::setProductDependsOnStock($product->id, 0);
}
} }
// Check if warehouse exists // Check if warehouse exists
if($product->warehouse) { if($product->warehouse)
if(!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { {
if(!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
$this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, warehouse not set on product %1$s '),$product->name[$default_language_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 { else
if(Warehouse::exists($product->warehouse)) { {
if(Warehouse::exists($product->warehouse))
{
// Get already associated warehouses // Get already associated warehouses
$associated_warehouses_collection = WarehouseProductLocation::getCollection($product->id); $associated_warehouses_collection = WarehouseProductLocation::getCollection($product->id);
// Delete any entry in warehouse for this product // Delete any entry in warehouse for this product
foreach ($associated_warehouses_collection as $awc) foreach ($associated_warehouses_collection as $awc)
{
$awc->delete(); $awc->delete();
}
$warehouse_location_entity = new WarehouseProductLocation(); $warehouse_location_entity = new WarehouseProductLocation();
$warehouse_location_entity->id_product = $product->id; $warehouse_location_entity->id_product = $product->id;
$warehouse_location_entity->id_product_attribute = 0; $warehouse_location_entity->id_product_attribute = 0;
$warehouse_location_entity->id_warehouse = $product->warehouse; $warehouse_location_entity->id_warehouse = $product->warehouse;
$warehouse_location_entity->save(); $warehouse_location_entity->save();
StockAvailable::synchronize($product->id); // Don't know if it is needed, but it can't hurt 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]);
} }
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($product->depends_on_stock) { // if not set if($product->depends_on_stock)
if($product->depends_on_stock != 0 && $product->depends_on_stock != 1) { {
if($product->depends_on_stock != 0 && $product->depends_on_stock != 1)
$this->warnings[] = sprintf(Tools::displayError('Incorrect value for depends on stock for product %1$s '),$product->name[$default_language_id]); $this->warnings[] = sprintf(Tools::displayError('Incorrect value for depends on stock for product %1$s '),$product->name[$default_language_id]);
} elseif((!$product->advanced_stock_management || $product->advanced_stock_management == 0) && $product->depends_on_stock == 1) { 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]); $this->warnings[] = sprintf(Tools::displayError('Advanced stock management not enabled, can not set depends on stock %1$s '),$product->name[$default_language_id]);
} else { else
StockAvailable::setProductDependsOnStock($product->id, $product->depends_on_stock); StockAvailable::setProductDependsOnStock($product->id, $product->depends_on_stock);
} }
} else { // if not depends_on_stock set, use normal qty else// if not depends_on_stock set, use normal qty
{
if (Shop::isFeatureActive()) if (Shop::isFeatureActive())
{
foreach ($shops as $shop) foreach ($shops as $shop)
StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, (int)$shop); StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, (int)$shop);
}
else else
{
StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, $this->context->shop->id); StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, $this->context->shop->id);
}
} }
} }
$this->closeCsvFile($handle); $this->closeCsvFile($handle);
} }