private function options() { $multiple = true; $translates = array(); $translates['product'] = _w('Basic fields'); $translates['sku'] = _w('SKU fields'); $translates['feature'] = _w('Add to existing'); $translates['feature+'] = _w('Add as new feature'); $options = array(); $fields = self::getMapFields(); foreach ($fields as $group => $group_fields) { foreach ($group_fields as $id => $name) { $options[] = array('group' => array('title' => ifset($translates[$group]), 'class' => $group), 'value' => $id, 'title' => ifempty($name, $id)); } } $limit = $this->getConfig()->getOption('features_per_page'); $group = 'feature'; $auto_complete = false; $feature_model = new shopFeatureModel(); if ($feature_model->countByField(array('parent_id' => null)) < $limit) { $features = $feature_model->getFeatures(true); /*, true*/ } else { $auto_complete = true; $header = array_unique(array_map('mb_strtolower', $this->reader->header())); //XXX optimize it for big tables $header = array_slice($header, 0, $limit); $features = $feature_model->getFeatures('name', $header); } foreach ($features as $id => $feature) { if ($feature['type'] == shopFeatureModel::TYPE_DIVIDER) { unset($features[$id]); } } foreach ($features as $code => $feature) { $code = $feature['code']; if (!preg_match('/\\.\\d$/', $code) && $feature['type'] != shopFeatureModel::TYPE_DIVIDER) { $options[] = array('group' => array('title' => ifset($translates[$group]), 'class' => $group), 'value' => sprintf('features:%s', $code), 'title' => $feature['name'], 'description' => $code); } } if ($auto_complete) { $options['autocomplete'] = array('group' => array('title' => ifset($translates[$group]), 'class' => $group), 'value' => 'features:%s', 'title' => _w('Select feature'), 'callback' => array()); } if ($this->getUser()->getRights('shop', 'settings')) { $group = 'feature+'; foreach (shopFeatureModel::getTypes() as $f) { if ($f['available']) { if (empty($f['subtype'])) { if ($multiple || empty($f['multiple']) && !preg_match('@^(range|2d|3d)\\.@', $f['type'])) { $options[] = array('group' => &$translates[$group], 'value' => sprintf("f+:%s:%d:%d", $f['type'], $f['multiple'], $f['selectable']), 'title' => empty($f['group']) ? $f['name'] : $f['group'] . ': ' . $f['name']); } } else { foreach ($f['subtype'] as $sf) { if ($sf['available']) { $type = str_replace('*', $sf['type'], $f['type']); if ($multiple || empty($f['multiple']) && !preg_match('@^(range|2d|3d)\\.@', $type)) { $options[] = array('group' => &$translates[$group], 'value' => sprintf("f+:%s:%d:%d", $type, $f['multiple'], $f['selectable']), 'title' => (empty($f['group']) ? $f['name'] : $f['group'] . ': ' . $f['name']) . " — {$sf['name']}"); } } } } } } } return $options; }