public function execute()
 {
     $type_model = new shopTypeModel();
     $types = $type_model->getAll('id');
     $category_model = new shopCategoryModel();
     $categories = $category_model->getFullTree('id, name, depth', true);
     $features_model = new shopFeatureModel();
     $features = $features_model->getAll('id');
     $data = array();
     $type_values = array();
     foreach ($types as $type_id => $type) {
         $type_values[] = array($type_id, $type['name']);
         $data[$type_id]['price'] = array('feature' => 'price');
         $data[$type_id]['type_id'] = array('feature' => 'type_id');
         $data[$type_id]['tag'] = array('feature' => 'tag');
     }
     $type_features_model = new shopTypeFeaturesModel();
     $rows = $type_features_model->getAll();
     foreach ($rows as $row) {
         if (isset($features[$row['feature_id']])) {
             $code = $features[$row['feature_id']]['code'];
             $data[$row['type_id']][$code] = array('feature' => $code, 'feature_id' => $row['feature_id']);
         }
     }
     $type_upselling_model = new shopTypeUpsellingModel();
     $rows = $type_upselling_model->getAll();
     foreach ($rows as $row) {
         $data[$row['type_id']][$row['feature']] = array('feature_id' => $row['feature_id'], 'feature' => $row['feature'], 'cond' => $row['cond'], 'value' => $row['value']);
     }
     foreach ($data as &$row) {
         $row = array_values($row);
     }
     unset($row);
     foreach ($types as &$type) {
         if ($type['upselling']) {
             $type['upselling_html'] = self::getConditionHTML($data[$type['id']], $features);
         }
     }
     unset($type);
     $fids = array();
     foreach ($features as $f_key => $f) {
         $features[$f_key]['selectable'] = (int) $f['selectable'];
         $features[$f_key]['multiple'] = (int) $f['multiple'];
         if ($f['selectable']) {
             $fids[$f['id']] = $f;
         }
     }
     if ($fids) {
         $fids = $features_model->getValues($fids);
         foreach ($fids as $feature_id => $f) {
             foreach ($f['values'] as $value_id => $value) {
                 $features[$feature_id]['values'][] = array($value_id, $value);
             }
         }
         unset($fids);
     }
     $features['type_id'] = array('name' => _w('Type'), 'type' => 'varchar', 'selectable' => 1, 'values' => $type_values);
     $this->view->assign(array('types' => $types, 'categories' => $categories, 'features' => $features, 'data' => $data));
 }
 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()
 {
     $asm = new waAppSettingsModel();
     if (waRequest::post()) {
         $conf = waRequest::post('conf');
         if ($conf && is_array($conf)) {
             $conf['affiliate_credit_rate'] = str_replace(',', '.', (double) str_replace(',', '.', ifset($conf['affiliate_credit_rate'], '0')));
             $conf['affiliate_usage_rate'] = str_replace(',', '.', (double) str_replace(',', '.', ifset($conf['affiliate_usage_rate'], '0')));
             foreach ($conf as $k => $v) {
                 $asm->set('shop', $k, $v);
             }
         }
     }
     $enabled = shopAffiliate::isEnabled();
     $def_cur = waCurrency::getInfo(wa()->getConfig()->getCurrency());
     $tm = new shopTypeModel();
     $product_types = $tm->getAll();
     $conf = $asm->get('shop');
     if (!empty($conf['affiliate_product_types'])) {
         $conf['affiliate_product_types'] = array_fill_keys(explode(',', $conf['affiliate_product_types']), true);
     } else {
         $conf['affiliate_product_types'] = array();
     }
     $this->view->assign('conf', $conf);
     $this->view->assign('enabled', $enabled);
     $this->view->assign('product_types', $product_types);
     $this->view->assign('def_cur_sym', ifset($def_cur['sign'], wa()->getConfig()->getCurrency()));
     /**
      * Backend affiliate settings
      *
      * Plugins are expected to return one item or a list of items to to add to affiliate menu.
      * Each item is represented by an array:
      * array(
      *   'id'   => string,  // Required.
      *   'name' => string,  // Required.
      *   'url'  => string,  // Required (unless you hack into JS using 'html' parameter). Content for settings page is fetched from this URL.
      * )
      *
      * @event backend_settings_discounts
      */
     $plugins = wa()->event('backend_settings_affiliate');
     $config = wa('shop')->getConfig();
     foreach ($plugins as $k => &$p) {
         if (substr($k, -7) == '-plugin') {
             $plugin_id = substr($k, 0, -7);
             $plugin_info = $config->getPluginInfo($plugin_id);
             $p['img'] = $plugin_info['img'];
         }
     }
     $this->view->assign('plugins', $plugins);
     $this->view->assign('installer', $this->getUser()->getRights('installer', 'backend'));
 }
 public function execute()
 {
     $id = waRequest::get('id', null, waRequest::TYPE_INT);
     $service_model = new shopServiceModel();
     $service = array();
     $services = $service_model->getAll('id');
     if ($id !== 0) {
         if (!empty($services)) {
             if ($id && isset($services[$id])) {
                 $service = $services[$id];
             } else {
                 $service = current($services);
             }
         }
     }
     // blank area for adding new service
     if (!$service) {
         $services[] = $this->getEmptyService();
         $type_model = new shopTypeModel();
         $this->assign(array('services' => $services, 'types' => $type_model->getAll(), 'count' => $service_model->countAll(), 'taxes' => $this->getTaxes()));
         return;
     }
     $service_variants_model = new shopServiceVariantsModel();
     $variants = $service_variants_model->get($service['id']);
     $type_services_model = new shopTypeServicesModel();
     $types = $type_services_model->getTypes($service['id']);
     $products_count = 0;
     $selected_types = array();
     foreach ($types as $type) {
         if ($type['type_id']) {
             $selected_types[] = $type['type_id'];
         }
     }
     if (!empty($selected_types)) {
         $product_model = new shopProductModel();
         $products_count = $product_model->countByField(array('type_id' => $selected_types));
     }
     $product_services_model = new shopProductServicesModel();
     $this->assign(array('services' => $services, 'service' => $service, 'products' => $product_services_model->getProducts($service['id']), 'types' => $types, 'products_count' => $products_count, 'variants' => $variants, 'count' => $service_model->countAll(), 'taxes' => $this->getTaxes()));
 }
 public function execute()
 {
     if ($id = waRequest::get('id', 0, waRequest::TYPE_INT)) {
         #load product
         $this->view->assign('product', $product = new shopProduct($id));
         #load product types
         $type_model = new shopTypeModel();
         $this->view->assign('product_types', $product_types = $type_model->getAll($type_model->getTableId(), true));
         if ($param = waRequest::request('param', array(), waRequest::TYPE_ARRAY_INT)) {
             $type_id = reset($param);
             if (!isset($product_types[$type_id])) {
                 $type_id = $product->type_id;
             }
         } else {
             $type_id = $product->type_id;
         }
         $this->view->assign('type_id', $type_id);
         #load feature's values
         $model = new shopFeatureModel();
         $changed_features = array();
         if ($data = waRequest::post('product')) {
             $changed_features = empty($data['features']) || !is_array($data['features']) ? array() : $data['features'];
             foreach ($changed_features as $code => $value) {
                 if (isset($product->features[$code])) {
                     if (is_array($value)) {
                         $intersect = array_unique(array_merge($value, (array) $product->features[$code]));
                         if (count($value) == count($intersect)) {
                             unset($changed_features[$code]);
                         }
                     } elseif ($value === $product->features[$code]) {
                         unset($changed_features[$code]);
                     }
                 }
             }
         }
         #load changed feature's values
         $this->view->assign('changed_features', $changed_features);
         $codes = array_keys($product->features);
         foreach ($changed_features as $code => $value) {
             if ($value !== '') {
                 $codes[] = $code;
             }
         }
         $codes = array_unique($codes);
         $features = $model->getByType($type_id, 'code');
         foreach ($features as $code => &$feature) {
             $feature['internal'] = true;
             $key = array_search($code, $codes);
             if ($key !== false) {
                 unset($codes[$key]);
             }
         }
         unset($feature);
         if ($codes) {
             $features += $model->getByField('code', $codes, 'code');
         }
         foreach ($features as $code => &$feature) {
             $feature['feature_id'] = intval($feature['id']);
         }
         unset($feature);
         $features = $model->getValues($features);
         $this->view->assign('features', $features);
     }
 }
 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);
 }
 public function getTypes()
 {
     $model = new shopTypeModel();
     return $model->getAll('id');
 }