diff --git a/classes/stock/SupplyOrder.php b/classes/stock/SupplyOrder.php index 8346a6201..712d8ca7f 100755 --- a/classes/stock/SupplyOrder.php +++ b/classes/stock/SupplyOrder.php @@ -447,6 +447,26 @@ class SupplyOrderCore extends ObjectModel return ($res > 0); } + /** + * For a given reference, returns the corresponding supply order + * + * @param striing $reference + * @return bool|SupplyOrder + */ + public static function getSupplyOrderByReference($reference) + { + if (!$reference) + return false; + + $query = new DbQuery(); + $query->select('id_supply_order'); + $query->from('supply_order', 'so'); + $query->where('so.reference = "'.pSQL($match).'"'); + $id = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); + + return (new SupplyOrder((int)$id)); + } + /** * Webservice : gets the ids supply_order_detail associated to this order * @return array diff --git a/controllers/admin/AdminImportController.php b/controllers/admin/AdminImportController.php index bad6d69ee..beaf20770 100644 --- a/controllers/admin/AdminImportController.php +++ b/controllers/admin/AdminImportController.php @@ -1677,15 +1677,42 @@ class AdminImportControllerCore extends AdminController */ public function supplyOrdersImport() { + // opens CSV & sets locale $this->receiveTab(); $handle = $this->openCsvFile(); self::setLocale(); + // main loop, for each lines for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++) { - //@TODO + // if convert requested + if (Tools::getValue('convert')) + $line = $this->utf8EncodeArray($line); + $info = self::getMaskedRow($line); + + // sets default values if needed + self::setDefaultValues($info); + + // if an id is set, instanciates a supply order with this id if possible + if (array_key_exists('id', $info) && (int)$info['id'] && SupplyOrder::exists((int)$info['id'])) + $supply_order = new Supplier((int)$info['id']); + // if an reference is set, instanciates a supply order with this reference if possible + else if (array_key_exists('reference', $info) && $info['reference'] && SupplyOrder::exists(pSQL($info['reference']))) + $supply_order = SupplyOrder::getSupplyOrderByReference(pSQL($info['reference'])); + else // new supply order + $supply_order = new SupplyOrder(); + + /* + * @TODO Checks $info + * + */ + + /** + * @TODO If check is OK, sets the Supply Order + */ } + // closes $this->closeCsvFile($handle); }