public function execute()
 {
     if (!$this->getUser()->isAdmin('shop') && !wa()->getUser()->getRights('shop', 'type.%')) {
         throw new waRightsException('Access denied');
     }
     $this->setLayout(new shopBackendLayout());
     $this->getResponse()->setTitle(_w('Products'));
     $this->view->assign('categories', new shopCategories());
     $tag_model = new shopTagModel();
     $this->view->assign('cloud', $tag_model->getCloud());
     $set_model = new shopSetModel();
     $this->view->assign('sets', $set_model->getAll());
     $collapse_types = wa()->getUser()->getSettings('shop', 'collapse_types');
     if (empty($collapse_types)) {
         $type_model = new shopTypeModel();
         $this->view->assign('types', $type_model->getTypes());
     } else {
         $this->view->assign('types', false);
     }
     $product_model = new shopProductModel();
     $this->view->assign('count_all', $product_model->countAll());
     $review_model = new shopProductReviewsModel();
     $this->view->assign('count_reviews', array('all' => $review_model->count(null, false), 'new' => $review_model->countNew(true)));
     $product_services = new shopServiceModel();
     $this->view->assign('count_services', $product_services->countAll());
     $config = $this->getConfig();
     $this->view->assign('default_view', $config->getOption('products_default_view'));
     /*
      * @event backend_products
      * @return array[string]array $return[%plugin_id%] array of html output
      * @return array[string][string]string $return[%plugin_id%]['sidebar_top_li'] html output
      * @return array[string][string]string $return[%plugin_id%]['sidebar_section'] html output
      */
     $this->view->assign('backend_products', wa()->event('backend_products'));
     $this->view->assign('sidebar_width', $config->getSidebarWidth());
     $this->view->assign('lang', substr(wa()->getLocale(), 0, 2));
 }
 public function execute()
 {
     $direction = waRequest::request('direction', 'import') == 'export' ? 'export' : 'import';
     $profile_helper = new shopImportexportHelper('csv:product:' . $direction);
     $this->view->assign('profiles', $profile_helper->getList());
     $profile = $profile_helper->getConfig();
     if ($direction == 'export') {
         //export section TODO
         $profile['config'] += array('encoding' => 'UTF-8', 'images' => true, 'features' => true, 'domain' => null, 'delimiter' => ';', 'hash' => '');
         $info = array();
         if (!empty($profile['id'])) {
             $path = wa()->getTempPath('csv/download/' . $profile['id']);
             $files = waFiles::listdir($path);
             foreach ($files as $file) {
                 $file_path = $path . '/' . $file;
                 $info[] = array('name' => $file, 'mtime' => filemtime($file_path), 'size' => filesize($file_path));
             }
             usort($info, create_function('$a, $b', 'return (max(-1, min(1, $a["mtime"] - $b["mtime"])));'));
         }
         $this->view->assign('info', array_slice($info, -5, 5, true));
         $set_model = new shopSetModel();
         $this->view->assign('sets', $set_model->getAll());
         $routing = wa()->getRouting();
         $settlements = array();
         $current_domain = null;
         $domain_routes = $routing->getByApp('shop');
         foreach ($domain_routes as $domain => $routes) {
             foreach ($routes as $route) {
                 $settlement = $domain . '/' . $route['url'];
                 if ($current_domain === null) {
                     $current_domain = $settlement;
                 } elseif ($settlement == $profile['config']['domain']) {
                     $current_domain = $settlement;
                 }
                 $settlements[] = $settlement;
             }
         }
         $this->view->assign('current_domain', $current_domain);
         $this->view->assign('settlements', $settlements);
     } else {
         $profile['config'] += array('encoding' => 'UTF-8', 'delimiter' => ';', 'map' => array());
         $base_path = wa()->getConfig()->getPath('root');
         $app_path = array('shop' => wa()->getDataPath(null, false, 'shop'), 'site' => wa()->getDataPath(null, true, 'site'));
         foreach ($app_path as &$path) {
             $path = preg_replace('@^([\\\\/])@', '', str_replace($base_path, '', $path . '/'));
         }
         unset($path);
         $this->view->assign('upload_path', waSystem::getSetting('csv.upload_path', 'path/to/folder/with/source/images/'));
         $this->view->assign('upload_app', waSystem::getSetting('csv.upload_app', 'shop'));
         $this->view->assign('app_path', $app_path);
     }
     $this->view->assign('profile', $profile);
     $type_model = new shopTypeModel();
     $this->view->assign('types', $type_model->getTypes());
     $encoding = array_diff(mb_list_encodings(), array('pass', 'wchar', 'byte2be', 'byte2le', 'byte4be', 'byte4le', 'BASE64', 'UUENCODE', 'HTML-ENTITIES', 'Quoted-Printable', '7bit', '8bit', 'auto'));
     $popular = array_intersect(array('UTF-8', 'Windows-1251', 'ISO-8859-1'), $encoding);
     asort($encoding);
     $encoding = array_unique(array_merge($popular, $encoding));
     $this->view->assign('encoding', $encoding);
     $plugins = wa()->getConfig()->getPlugins();
     $this->view->assign('direction', $direction);
     $this->view->assign('plugin', ifempty($plugins['csvproducts'], array()));
 }
예제 #3
0
 public function execute()
 {
     $set_model = new shopSetModel();
     $this->response = $set_model->getAll();
 }
 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);
 }