/** * Add a new product attribute * * @param integer $id [empty to create a new record] * @param string $code * @param string $label * @param string $type * @param integer $language_id * @param integer $position * @param boolean $active * @param string $prefix * @param string $suffix * @param string $description * @param boolean $is_visible_on_front * @param boolean $is_system_var * @param string $system_var * @param string $defaultvalue * @param boolean $is_required * @param boolean $is_comparable * @param boolean $on_product_listing */ public static function addNew($id = NULL, $code, $label, $type, $language_id = 1, $position = 0, $active = 1, $prefix = NULL, $suffix = NULL, $description = NULL, $is_visible_on_front = 1, $is_system_var = 0, $system_var = NULL, $defaultvalue = NULL, $is_required = 0, $is_comparable = 0, $on_product_listing = 0) { $productsattributes = new ProductsAttributes(); // Set the new values if (is_numeric($id)) { $productsattributes = Doctrine::getTable('ProductsAttributes')->find($id); } // format the attribute code $code = Shineisp_Commons_Utilities::format($code); // Check if the code has been already used before $thecode = self::getAttributebyCode($code); // If the record is in Update mode if (is_numeric($id)) { if (!empty($thecode) && count($thecode) > 1) { return false; } } else { // If the record is new if (!empty($thecode) && count($thecode) > 0) { return false; } } $productsattributes['code'] = $code; $productsattributes['position'] = $position; $productsattributes['is_visible_on_front'] = $is_visible_on_front; $productsattributes['active'] = $active; $productsattributes['system'] = $is_system_var; $productsattributes['system_var'] = $system_var; $productsattributes['defaultvalue'] = $defaultvalue; $productsattributes['type'] = $type; $productsattributes['is_required'] = $is_required; $productsattributes['is_comparable'] = $is_comparable; $productsattributes['on_product_listing'] = $on_product_listing; $productsattributes->save(); $productsattributesdata = Doctrine::getTable('ProductsAttributesData')->createQuery('pad')->where('pad.attribute_id = ?', $productsattributes['attribute_id'])->andWhere('pad.language_id = ?', $language_id)->fetchOne(); if (empty($productsattributesdata)) { $productsattributesdata = new ProductsAttributesData(); } $productsattributesdata['attribute_id'] = $productsattributes['attribute_id']; $productsattributesdata['language_id'] = $language_id; $productsattributesdata['label'] = $label; $productsattributesdata['prefix'] = $prefix; $productsattributesdata['suffix'] = $suffix; $productsattributesdata['description'] = $description; $productsattributesdata->save(); return $productsattributes['attribute_id']; }