From d8422f18967861d62587d032212cf43bc32c7fb6 Mon Sep 17 00:00:00 2001 From: bMancone Date: Wed, 28 Dec 2011 14:58:55 +0000 Subject: [PATCH] // SupplyOrder reference is now unique git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11854 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/stock/SupplyOrder.php | 18 ++++++++++++++++++ .../admin/AdminSupplyOrdersController.php | 12 ++++++++++++ install-dev/sql/upgrade/1.5.0.3.sql | 4 ++++ 3 files changed, 34 insertions(+) diff --git a/classes/stock/SupplyOrder.php b/classes/stock/SupplyOrder.php index ca2ef483d..8346a6201 100755 --- a/classes/stock/SupplyOrder.php +++ b/classes/stock/SupplyOrder.php @@ -429,6 +429,24 @@ class SupplyOrderCore extends ObjectModel return ($res > 0); } + /** + * For a given id or reference, tells if the supply order exists + * @param int|string $match + */ + public static function exists($match) + { + if (!$match) + return false; + + $query = new DbQuery(); + $query->select('id_supply_order'); + $query->from('supply_order', 'so'); + $query->where('so.id_supply_order = '.(int)$match.' OR so.reference = "'.pSQL($match).'"'); + + $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); + return ($res > 0); + } + /** * Webservice : gets the ids supply_order_detail associated to this order * @return array diff --git a/controllers/admin/AdminSupplyOrdersController.php b/controllers/admin/AdminSupplyOrdersController.php index e925bfc06..e8c7d749b 100644 --- a/controllers/admin/AdminSupplyOrdersController.php +++ b/controllers/admin/AdminSupplyOrdersController.php @@ -936,6 +936,18 @@ class AdminSupplyOrdersControllerCore extends AdminController $this->_errors[] = Tools::displayError($this->l('You do not have the required permission to add a supply order.')); if (Tools::isSubmit('submitBulkUpdatesupply_order_detail') && !($this->tabAccess['edit'] === '1')) $this->_errors[] = Tools::displayError($this->l('You do not have the required permission to edit an order.')); + + // checks if supply order reference is unique + if (Tools::isSubmit('reference')) + { + $ref = pSQL(Tools::getValue('reference')); + if (SupplyOrder::exists($ref)) + $this->_errors[] = Tools::displayError($this->l('The reference has to be unique.')); + } + + if ($this->_errors) + return; + // Global checks when add / update a supply order if (Tools::isSubmit('submitAddsupply_order') || Tools::isSubmit('submitAddsupply_orderAndStay')) { diff --git a/install-dev/sql/upgrade/1.5.0.3.sql b/install-dev/sql/upgrade/1.5.0.3.sql index 80551dd82..2caa8222e 100644 --- a/install-dev/sql/upgrade/1.5.0.3.sql +++ b/install-dev/sql/upgrade/1.5.0.3.sql @@ -2,3 +2,7 @@ SET NAMES 'utf8'; ALTER TABLE PREFIX_theme ADD COLUMN directory varchar(64) NOT NULL; +/* Supply Order modification as of 1.5.0.3 */ +ALTER TABLE `PREFIX_supply_order` DROP INDEX `reference`; +ALTER TABLE `PREFIX_supply_order` ADD UNIQUE (`reference`); +