public function createSet($name) { $id = str_replace('-', '_', shopHelper::transliterate($name)); $id = $this->set_model->suggestUniqueId($id); if (empty($name)) { $name = _w('(no-name)'); } return $this->set_model->add(array('id' => $id, 'name' => $name)); }
public function execute() { $id = $this->get('id', true); $set_model = new shopSetModel(); $set = $set_model->getById($id); if (!$set) { throw new waAPIException('invalid_param', 'Set not found', 404); } $this->response = $set; }
public function execute() { $id = $this->post('id', true); $name = $this->post('name', true); $set_model = new shopSetModel(); if ($set_model->idExists($id)) { throw new waAPIException('invalid_param', 'ID ' . $id . ' already exists'); } if ($set_model->add(array('id' => $id, 'name' => $name))) { $_GET['id'] = $id; $method = new shopSetGetInfoMethod(); $this->response = $method->getResponse(true); } else { throw new waAPIException('server_error', 500); } }
public function execute() { $id = $this->get('id', true); $this->getProduct($id); $set_id = $this->post('set_id', true); $set_model = new shopSetModel(); $set = $set_model->getById($set_id); if (!$set) { throw new waAPIException('invalid_param', 'Set not found', 404); } if ($set['type'] == shopSetModel::TYPE_DYNAMIC) { throw new waAPIException('invalid_param', 'Set type must be static'); } $set_products_model = new shopSetProductsModel(); $this->response = $set_products_model->deleteProducts($set_id, $id); }
public function execute() { $id = $this->get('id', true); $set_model = new shopSetModel(); $set = $set_model->getById($id); if (!$set) { throw new waAPIException('invalid_param', 'Set not found', 404); } $data = array(); foreach (array('id', 'name') as $k) { if (waRequest::post($k)) { $data[$k] = waRequest::post($k); } } if (!$data) { throw new waAPIException('invalid_param', 'Required parameter is missing: id or name', 400); } $set_model->update($id, $data); $method = new shopSetGetInfoMethod(); $this->response = $method->getResponse(true); }
public function move($type, $id, $before_id, $parent_id) { if ($type == 'category') { $category_model = new shopCategoryModel(); if (!$category_model->move($id, $before_id, $parent_id)) { $this->errors = array('Error when move'); } else { if ($parent_id) { $parent = $category_model->getById($parent_id); $this->response['count'] = array('count' => $parent['count'], 'subtree' => $category_model->getTotalProductsCount($parent_id)); } } } else { if ($type == 'set') { $set_model = new shopSetModel(); if (!$set_model->move($id, $before_id)) { $this->errors = array('Error when move'); } } else { throw new waException('Unknown list type: ' . $type); } } }
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)); }
/** * @param int $id - ID of the set * @param bool $auto_title */ protected function setPrepare($id, $auto_title = true) { $set_model = new shopSetModel(); $set = $set_model->getById($id); if (!$set) { $this->where[] = '0'; return; } $this->info = $set; $this->info['hash'] = 'set'; if ($auto_title) { $this->addTitle($set['name']); } if ($set['type'] == shopSetModel::TYPE_STATIC) { $alias = $this->addJoin('shop_set_products', null, ":table.set_id = '" . $set_model->escape($id) . "'"); if (!waRequest::get('sort') || waRequest::get('sort') == 'sort') { $this->order_by = $alias . '.sort ASC'; } } else { if (!waRequest::get('sort') && !empty($set['rule'])) { $this->order_by = $set['rule']; } } }
private function getSetSettings($id) { $set_model = new shopSetModel(); $settings = $set_model->getById($id); /** * @event backend_set_dialog * @param array $set * @return array[string][string] $return[%plugin_id%] html output for dialog */ $this->view->assign('event_dialog', wa()->event('backend_set_dialog', $settings)); return $settings ? $settings : array(); }
public function execute() { $set_model = new shopSetModel(); $this->response = $set_model->getAll(); }
private function setup() { if ($country = waRequest::post('country')) { if (!empty($this->countries[$country])) { $path = $this->getConfig()->getConfigPath('data/welcome/', false); $country_data = (include $path . "country_{$country}.php"); # Main country setting $model = new waAppSettingsModel(); $model->set('shop', 'country', $country); #currency if (!empty($country_data['currency'])) { $currency_model = new shopCurrencyModel(); $sort = 0; foreach ($country_data['currency'] as $code => $rate) { // delete old currency info is exists $currency_model->deleteById($code); $currency_model->insert(array('code' => $code, 'rate' => $rate, 'sort' => $sort++), 2); if ($sort == 1) { $model->set('shop', 'currency', $code); } } } #taxes if (!empty($country_data['taxes'])) { foreach ($country_data['taxes'] as $tax_data) { shopTaxes::save($tax_data); } } #custom code $function = 'shopWelcome' . ucfirst($country); if (function_exists($function)) { try { call_user_func_array($function, array()); } catch (Exception $ex) { //TODO } } } } if (!empty($this->types)) { $type_model = new shopTypeModel(); $type_features_model = new shopTypeFeaturesModel(); $types = waRequest::post('types'); if (empty($types)) { if (!$type_features_model->countAll()) { $types[] = 'default'; } } if ($types) { foreach ($types as $type) { $type_model->insertTemplate($type); } } } $set_model = new shopSetModel(); $set_model->add(array('id' => 'promo', 'name' => _w('Featured on homepage'), 'type' => shopSetModel::TYPE_STATIC)); $set_model->add(array('id' => 'bestsellers', 'name' => _w('Bestsellers'), 'type' => shopSetModel::TYPE_DYNAMIC, 'count' => 8, 'rule' => 'rating DESC')); // notifications $notifications_model = new shopNotificationModel(); if ($notifications_model->countAll() == 0) { $notifications_action = new shopSettingsNotificationsAddAction(); $notifications = $notifications_action->getTemplates(); $params_model = new shopNotificationParamsModel(); $events = $notifications_action->getEvents(); foreach ($notifications as $event => $n) { if ($event == 'order') { continue; } $data = array('name' => $events[$event]['name'] . ' (' . _w('Customer') . ')', 'event' => $event, 'transport' => 'email', 'status' => 1); $id = $notifications_model->insert($data); $params = $n; $params['to'] = 'customer'; $params_model->save($id, $params); if ($event == 'order.create') { $data['name'] = $events[$event]['name'] . ' (' . _w('Store admin') . ')'; $id = $notifications_model->insert($data); $params['to'] = 'admin'; $params_model->save($id, $params); } } } /* !!! import commented out on welcome screen switch (waRequest::post('import')) { case 'demo': //TODO create demoproducts $this->redirect('?action=products'); break; case 'migrate': $plugins = $this->getConfig()->getPlugins(); if (empty($plugins['migrate'])) { $url = $this->getConfig()->getBackendUrl(true).'installer/?module=update&action=manager&install=1&app_id[shop/plugins/migrate]=webasyst'; } else { $url = '?action=importexport#/migrate/'; } $this->redirect($url); break; case 'scratch': default: */ $this->redirect('?action=products#/welcome/'); // break; //} }
public function execute() { $set_model = new shopSetModel(); $this->view->assign('sets', $set_model->select('*')->where('type = ' . shopSetModel::TYPE_STATIC)->order('sort')->fetchAll('id')); }
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())); }
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); }