From 6ed48743262ed51166712eb8635a7c5a9a5b7211 Mon Sep 17 00:00:00 2001 From: rMalie Date: Thu, 19 Jan 2012 17:25:22 +0000 Subject: [PATCH] // Add support of list of values in objects definition and set default value for product->condition --- classes/ObjectModel.php | 11 +++++++++++ classes/Product.php | 10 +++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/classes/ObjectModel.php b/classes/ObjectModel.php index 4acfac74d..693c41634 100644 --- a/classes/ObjectModel.php +++ b/classes/ObjectModel.php @@ -712,6 +712,17 @@ abstract class ObjectModelCore if (Tools::isEmpty($value)) return 'Property '.get_class($this).'->'.$field.' is empty'; + // Default value + if (!$value && !empty($data['default'])) + { + $value = $data['default']; + $this->$field = $value; + } + + // Check field values + if (!empty($data['values']) && is_array($data['values']) && !in_array($value, $data['values'])) + return 'Property '.get_class($this).'->'.$field.' has bad value (allowed values are: '.implode(', ', $data['values']).')'; + // Check field size if (!empty($data['size'])) { diff --git a/classes/Product.php b/classes/Product.php index decac4f3a..2a7008ce3 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -159,14 +159,14 @@ class ProductCore extends ObjectModel /** @var integer Number of uploadable files (concerning customizable products) */ public $uploadable_files; - /** @var interger Number of text fields */ + /** @var int Number of text fields */ public $text_fields; /** @var boolean Product statuts */ - public $active = 1; + public $active = true; /** @var boolean Product available for order */ - public $available_for_order = 1; + public $available_for_order = true; /** @var string Object available order date */ public $available_date = '0000-00-00'; @@ -175,7 +175,7 @@ class ProductCore extends ObjectModel public $condition; /** @var boolean Show price of Product */ - public $show_price = 1; + public $show_price = true; public $indexed = 0; @@ -259,7 +259,7 @@ class ProductCore extends ObjectModel 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'available_for_order' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'available_date' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'), - 'condition' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'), // @todo enum ? + 'condition' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'values' => array('new', 'used', 'refurbished'), 'default' => 'new'), 'show_price' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'ean13' => array('type' => self::TYPE_STRING, 'validate' => 'isEan13', 'size' => 13), 'upc' => array('type' => self::TYPE_STRING, 'validate' => 'isUpc', 'size' => 12),