public function updates(array $data, array $ignores = array()) { parent::updates($data, $ignores); if (preg_match('/^.*?(\\d+[\\.\\,\\d]*).*$/', $this->value)) { $this->numeral = preg_replace('/^.*?(\\d+[\\.\\,\\d]*).*$/', '$1', $this->value); } }
/** * Create or update a new meta record * * @api * @since 1.2 * * @param int $id (required on creation/update) id of an existing meta entry, or with context the parent object of a new meta entry * @param string $context (required on update) the parent object type of the meta entry (example product, price, and more) * @param string $name (required on update) the name of the meta entry, more specific than type * @param mixed $value (optional default: false) the value stored to the meta entry * @param string $type (optional default: meta) the type or classification of the meta data * @param string $valuetype (optional default: 'value') 'numeral' or 'value', if the value is numeric, 'numeric' will store in numeric field. * @return bool true on successful save or update, fail on failure **/ function shopp_set_meta($id = false, $context = false, $name = false, $value = false, $type = 'meta', $valuetype = 'value') { if (!($id || $id && $context)) { shopp_debug(__FUNCTION__ . " failed: Must specify at least a meta id or parent id and context."); return false; } $record = array(); if ($context) { $record['context'] = $context; } if ($type) { $record['type'] = $type; } if ($name) { $record['name'] = $name; } $valuefield = array(); $valuefield['numeral' == $valuetype && is_numeric($value) ? 'numeral' : 'value'] = $value; // save existing meta record by meta id if ($id && !$context) { $meta = new ShoppMetaObject(); $meta->load($id); if (!empty($meta->id)) { $meta->updates(array_merge($record, $valuefield)); $meta->save(); return true; } else { shopp_debug(__FUNCTION__ . " failed: No metadata with id {$id}."); return false; } } // fully spec'd meta entry if ($id && $context && $type && $name) { $meta = new ShoppMetaObject(); $meta->load(array_merge($record, array('parent' => $id, 'context' => $context))); $meta->updates(array_merge(array('parent' => $id, 'context' => $context), $record, $valuefield)); $meta->save(); return true; } shopp_debug(__FUNCTION__ . ' failed: id, context, type, and name are required parameters for this context.'); return false; }