public function execute()
 {
     $type = waRequest::get('type', '', waRequest::TYPE_STRING_TRIM);
     $parent_id = waRequest::get('parent_id', 0, waRequest::TYPE_INT);
     if ($parent_id) {
         $category_model = new shopCategoryModel();
         $parent = $category_model->getById($parent_id);
     }
     $this->template = 'DialogProduct' . ucfirst($type) . 'Create';
     $this->view->assign(array('type' => $type, 'parent' => $parent_id ? $parent : array()));
     if ($type == 'category') {
         $tag_model = new shopTagModel();
         $stuff = '%category_url%';
         $frontend_url = wa()->getRouteUrl('/frontend/category', array('category_url' => $stuff), true);
         $pos = strrpos($frontend_url, $stuff);
         $fontend_base_url = $pos !== false ? rtrim(substr($frontend_url, 0, $pos), '/') . '/' : $frontend_url;
         $feature_model = new shopFeatureModel();
         $features = $feature_model->getFeatures('selectable', 1);
         $features += $feature_model->getFeatures('type', 'boolean');
         $features = $feature_model->getValues($features);
         $this->view->assign(array('cloud' => $tag_model->getCloud(), 'currency' => wa()->getConfig()->getCurrency(), 'frontend_base_url' => $fontend_base_url, 'lang' => substr(wa()->getLocale(), 0, 2), 'features' => $features));
     } else {
         if ($type == 'set') {
             $this->view->assign('default_count', $this->set_dynamic_default_count);
         }
     }
 }
 public function execute()
 {
     if (!$this->getUser()->getRights('shop', 'settings')) {
         throw new waRightsException(_w('Access denied'));
     }
     $types_per_page = $this->getConfig()->getOption('types_per_page');
     $values_per_feature = 7;
     $type_model = new shopTypeModel();
     $type_features_model = new shopTypeFeaturesModel();
     $feature_model = new shopFeatureModel();
     $types = $type_model->getAll($type_model->getTableId(), true);
     $type_features_model->countFeatures($types);
     $show_all_features = $feature_model->countAll() < $this->getConfig()->getOption('features_per_page');
     if ($show_all_features) {
         $feature_model = new shopFeatureModel();
         if ($features = $feature_model->getFeatures(true, null, 'id', $values_per_feature)) {
             $show_all_features = count($features);
             $type_features_model->fillTypes($features, $types);
             shopFeatureModel::appendTypeNames($features);
         }
     } else {
         $features = array();
     }
     $this->view->assign('type_templates', shopTypeModel::getTemplates());
     $this->view->assign('show_all_features', $show_all_features);
     $this->view->assign('show_all_types', count($types) - $types_per_page < 3);
     $this->view->assign('types_per_page', $types_per_page);
     $this->view->assign('values_per_feature', $values_per_feature);
     $this->view->assign('icons', (array) $this->getConfig()->getOption('type_icons'));
     $this->view->assign('product_types', $types);
     $this->view->assign('features', $features);
 }
 public function execute()
 {
     if (!$this->getUser()->getRights('shop', 'settings')) {
         throw new waRightsException(_w('Access denied'));
     }
     $feature_model = new shopFeatureModel();
     $values_per_feature = 7;
     $type = waRequest::get('type', waRequest::TYPE_STRING, '');
     if ($type_id = intval($type)) {
         $features = $feature_model->getByType($type_id, 'id', $values_per_feature);
     } else {
         if ($type === 'empty') {
             $features = $feature_model->getByType(null, 'id', $values_per_feature);
         } elseif ($type === '') {
             $features = $feature_model->getFeatures(true, null, 'id', $values_per_feature);
         } else {
             $features = $feature_model->getByType(0, 'id', $values_per_feature);
         }
     }
     if ($features) {
         shopFeatureModel::appendTypeNames($features);
         $type_features_model = new shopTypeFeaturesModel();
         $type_features_model->fillTypes($features);
     }
     $this->view->assign('features', $features);
     $this->view->assign('values_per_feature', $values_per_feature);
 }
 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;
 }
 public function execute()
 {
     $routing = wa()->getRouting();
     $settlements = array();
     $profile_helper = new shopImportexportHelper($this->plugin_id);
     $this->view->assign('profiles', $list = $profile_helper->getList());
     $profile = $profile_helper->getConfig();
     $profile['config'] += array('hash' => '', 'domain' => '', 'lifetime' => 0);
     $current_domain =& $profile['config']['domain'];
     $this->view->assign('current_domain', $current_domain);
     $domain_routes = $routing->getByApp('shop');
     foreach ($domain_routes as $domain => $routes) {
         foreach ($routes as $route) {
             $settlement = $domain . '/' . $route['url'];
             if ($settlement == $current_domain || $current_domain === '') {
                 $current_domain = $settlement;
                 $routing->setRoute($route, $domain);
                 waRequest::setParam($route);
             }
             $settlements[] = $settlement;
         }
     }
     $this->view->assign('profile', $profile);
     $info = array();
     $this->view->assign('settlements', $settlements);
     if (!empty($profile['id'])) {
         $path = shopYandexmarketPlugin::path($profile['id'] . '.xml');
         $info['exists'] = file_exists($path);
         $info['mtime'] = $info['exists'] ? filemtime($path) : null;
     } else {
         $info['mtime'] = $info['exists'] = null;
     }
     if ($info['exists']) {
         $route_params = array('plugin' => $this->plugin_id, 'hash' => $this->plugin()->getHash($profile['id']));
         $info['url'] = $routing->getUrl('shop/frontend/catalog', $route_params, true);
     } else {
         $info['url'] = null;
     }
     $this->view->assign('info', $info);
     /**
      * @var shopConfig $config ;
      */
     $config = wa('shop')->getConfig();
     $this->view->assign('primary_currency', $config->getCurrency());
     $this->view->assign('company', ifempty($profile['config']['company'], $config->getGeneralSettings('name')));
     $this->view->assign('company_name', ifempty($profile['config']['company_name'], $config->getGeneralSettings('name')));
     $type_model = new shopTypeModel();
     $this->view->assign('types', $type_model->getAll());
     $profile_map = ifset($profile['config']['map'], array());
     $export = ifset($profile['config']['export'], array());
     $set_model = new shopSetModel();
     $map = $this->plugin()->map(array(), null, true);
     $params = array();
     if ($profile_map) {
         foreach ($map as $type => &$type_map) {
             foreach ($type_map['fields'] as $field => &$info) {
                 $info['source'] = ifempty($profile_map[$type][$field], 'skip:');
                 unset($profile_map[$type][$field]);
                 unset($info);
             }
             if (!empty($type_map['fields']['param.*'])) {
                 $params[$type] = -1;
             }
             unset($type_map);
         }
         foreach ($profile_map as $type => $fields) {
             foreach ($fields as $field => $source) {
                 $info_field = strpos($field, 'param.') === 0 ? 'param.*' : $field;
                 if (isset($map[$type]['fields'][$info_field])) {
                     $info = $map[$type]['fields'][$info_field];
                     $info['source'] = ifempty($source, 'skip:');
                     $map[$type]['fields'][$field] = $info;
                     $params[$type] = max(ifset($params[$type], -1), intval(preg_replace('@\\D+@', '', $field)));
                 }
             }
         }
     }
     $this->view->assign('sets', $set_model->getAll());
     $this->view->assign('type_map', $map);
     $this->view->assign('params', array('params' => $params));
     $this->view->assign('export', $export);
     $this->view->assign('types_map', ifset($profile['config']['types'], array()));
     $app_settings_model = new waAppSettingsModel();
     $app_settings = array('ignore_stock_count' => $app_settings_model->get('shop', 'ignore_stock_count', 0));
     $this->view->assign('app_settings', $app_settings);
     $feature_model = new shopFeatureModel();
     $config = wa('shop')->getConfig();
     /**
      * @var shopConfig $config
      */
     $limit = $config->getOption('features_per_page');
     if ($feature_model->countByField(array('parent_id' => null)) < $limit) {
         $features = $feature_model->getFeatures(true);
         /*, true*/
         foreach ($features as $id => $feature) {
             if ($feature['type'] == shopFeatureModel::TYPE_DIVIDER) {
                 unset($features[$id]);
             }
         }
     } else {
         $this->view->assign('features_autocomplete', true);
         $features = array();
         foreach ($map as $type_map) {
             foreach ($type_map['fields'] as $info) {
                 if (!empty($info['source']) && preg_match('@^feature:([\\w\\d_\\-]+)$@', $info['source'], $matches)) {
                     $features[] = $matches[1];
                 }
             }
         }
         if ($features = array_unique($features)) {
             $features = $feature_model->getFeatures('code', $features);
         } else {
             $features = array();
         }
     }
     foreach ($features as $id => &$feature) {
         if (strpos($feature['type'], shopFeatureModel::TYPE_DIMENSION . '.') === 0) {
             $units = shopDimension::getUnits($feature['type']);
             $feature['units'] = array();
             foreach ($units as $unit) {
                 $feature['units'][] = $unit['title'];
             }
             $feature['units'] = implode(', ', $feature['units']);
         } elseif (preg_match('@\\(([^\\)]+)\\)$@', $feature['name'], $matches)) {
             $feature['units'] = trim($matches[1]);
         }
         unset($feature);
     }
     $this->view->assign('features', $features);
     $fields = array('name' => _w('Product name'), 'description' => _w('Description'), 'summary' => _w('Summary'), 'count' => _w('In stock'), 'sku' => _w('SKU code'));
     $this->view->assign('fields', $fields);
 }