diff --git a/classes/Validate.php b/classes/Validate.php index 7a7b27d21..7160600b8 100644 --- a/classes/Validate.php +++ b/classes/Validate.php @@ -903,11 +903,11 @@ class ValidateCore /** * * @param array $zones - * @return array return true if array contain all value required for an image map zone + * @return boolean return true if array contain all value required for an image map zone */ public static function isSceneZones($zones) { - foreach($zones as $zone) + foreach ($zones as $zone) { if (!isset($zone['x1']) || !self::isUnsignedInt($zone['x1'])) return false; @@ -922,5 +922,17 @@ class ValidateCore } return true; } + + /** + * + * @param array $stock_management + * @return boolean return true if is a valide stock management + */ + public static function isStockManagement($stock_management) + { + if (!in_array($stock_management, array('WA', 'FIFO', 'LIFO'))) + return false; + return true; + } } diff --git a/classes/stock/StockWarehouse.php b/classes/stock/StockWarehouse.php new file mode 100644 index 000000000..589bcdc54 --- /dev/null +++ b/classes/stock/StockWarehouse.php @@ -0,0 +1,103 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +/** + * @since 1.5.0 + */ +class StockWarehouseCore extends ObjectModel +{ + public $id_address; + public $reference; + public $name; + public $id_employee; + public $stock_management; + + protected $fieldsRequired = array('id_address', 'reference', 'name', 'id_employee', 'stock_management'); + protected $fieldsSize = array('stock_management' => 32, 'reference' => 45, 'name' => 45); + + protected $fieldsValidate = array( + 'id_address' => 'isUnsignedId', + 'reference' => 'isString', + 'name' => 'isString', + 'id_employee' => 'isUnsignedId', + 'stock_management' => 'isStockManagement'); + + protected $table = 'warehouse'; + protected $identifier = 'id_warehouse'; + + public function getFields() + { + $this->validateFields(); + $fields['id_address'] = (int)$this->id_addresse; + $fields['reference'] = $this->reference; + $fields['name'] = $this->name; + $fields['id_employee'] = (int)$this->id_employee; + $fields['stock_management'] = $this->$stock_management; + return $fields; + } + + /** + * Get a list of shop ids linked to a warehouse + */ + public function getIdShopList() + { + $query = new DbQuery(); + $query->select('ws.id_shop'); + $query->from(_DB_PREFIX_.'warehouse_shop ws'); + $query->where($this->identifier.' = '.(int)$this->id); + return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($query); + } + + + /** + * Linked a list of shop ids to a warehouse + * + * @param $shopIdList List of shop ids to linked to the warehouse + */ + public function setIdShopList($id_shop_list) + { + $row_to_instert = array(); + foreach ($id_shop_list as $id_shop) + { + $row_to_instert = array( + $this->reference => $this->id, + 'id_shop' => $id_shop); + } + Db::getInstance()->ExecuteS('DELETE INTO `warehouse_shop` ws WHERE ws.'.$this->identifier.' = '.(int)$this->id); + Db::getInstance()->autoExecute('warehouse_shop', $row_to_instert, 'INSERT'); + } + + /** + * Check if a warehouse exists or not + * + * @param $id_warehouse warehouse identifier + */ + public static function exists($id_warehouse) + { + return (bool)Db::getInstance()->getValue('SELECT count(*) INTO `warehouse` w WHERE w.id_warehouse = '.(int)$id_warehouse); + } +} \ No newline at end of file