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() { $tag_model = new shopTagModel(); $limit = waRequest::get('limit', 100, 'int'); if ($limit < 0) { throw new waAPIException('invalid_param', 'Param limit must be greater than or equal to zero'); } if ($limit > 1000) { throw new waAPIException('invalid_param', 'Param limit must be less or equal 1000'); } $this->response = $tag_model->getCloud(null, $limit); }
public function execute() { $tag_model = new shopTagModel(); $product_tags_model = new shopProductTagsModel(); $delete_tags = waRequest::post('delete_tags', array(), waRequest::TYPE_ARRAY_INT); $tags = waRequest::post('tags', '', waRequest::TYPE_STRING_TRIM); $tags = $tags ? explode(',', $tags) : array(); if (!$delete_tags && !$tags) { return; } $hash = waRequest::post('hash', ''); // delete tags of selected products if (!$hash) { $product_ids = waRequest::post('product_id', array(), waRequest::TYPE_ARRAY_INT); if (!$product_ids) { return; } // delete tags of selected products if ($delete_tags) { $product_tags_model->delete($product_ids, $delete_tags); } // assign tags to selected products if ($tags) { $tag_ids = $tag_model->getIds($tags); $product_tags_model->assign($product_ids, $tag_ids); } } else { // maintain all products of collection with this hash $collection = new shopProductsCollection($hash); $offset = 0; $count = 100; $total_count = $collection->count(); $tag_ids = array(); if ($offset < $total_count) { $tag_ids = $tag_model->getIds($tags); } while ($offset < $total_count) { $product_ids = array_keys($collection->getProducts('*', $offset, $count)); // delete tags if ($delete_tags) { $product_tags_model->delete($product_ids, $delete_tags); } // assign tags if ($tag_ids) { $product_tags_model->assign($product_ids, $tag_ids); } $offset += count($product_ids); } } $this->response['cloud'] = $tag_model->getCloud('id'); }
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)); }
private function getCategorySettings($id) { $category_model = new shopCategoryModel(); $category_params_model = new shopCategoryParamsModel(); $settings = $category_model->getById($id); if (!$settings) { return array(); } /** * @event backend_category_dialog * @param array $category * @return array[string][string] $return[%plugin_id%] html output for dialog */ $this->view->assign('event_dialog', wa()->event('backend_category_dialog', $settings)); $category_routes_model = new shopCategoryRoutesModel(); $settings['routes'] = $category_routes_model->getRoutes($id); $settings['frontend_urls'] = array(); foreach ($category_model->getFrontendUrls($id) as $frontend_url) { $pos = strrpos($frontend_url, $settings['url']); $settings['frontend_urls'][] = array('url' => $frontend_url, 'base' => $pos !== false ? rtrim(substr($frontend_url, 0, $pos), '/') . '/' : ''); } $settings['params'] = $category_params_model->get($id); if (isset($settings['params']['enable_sorting'])) { $settings['enable_sorting'] = 1; unset($settings['params']['enable_sorting']); } else { $settings['enable_sorting'] = 0; } $feature_model = new shopFeatureModel(); $selectable_and_boolean_features = $feature_model->select('*')->where("(selectable=1 OR type='boolean' OR type='double' OR type LIKE 'dimension\\.%' OR type LIKE 'range\\.%') AND parent_id IS NULL")->fetchAll('id'); if ($settings['type'] == shopCategoryModel::TYPE_DYNAMIC) { if ($settings['conditions']) { $settings['conditions'] = shopProductsCollection::parseConditions($settings['conditions']); } else { $settings['conditions'] = array(); } $tag_model = new shopTagModel(); $cloud = $tag_model->getCloud('name'); if (!empty($settings['conditions']['tag'][1])) { foreach ($settings['conditions']['tag'][1] as $tag_name) { $cloud[$tag_name]['checked'] = true; } } $settings['cloud'] = $cloud; // extract conditions for features foreach ($settings['conditions'] as $name => $value) { if (substr($name, -9) === '.value_id') { unset($settings['conditions'][$name]); $settings['conditions']['feature'][substr($name, 0, -9)] = $value; } } $settings['custom_conditions'] = $this->extractCustomConditions($settings['conditions']); $settings['features'] = $selectable_and_boolean_features; $settings['features'] = $feature_model->getValues($settings['features']); } $filter = $settings['filter'] !== null ? explode(',', $settings['filter']) : null; $feature_filter = array(); $features['price'] = array('id' => 'price', 'name' => 'Price'); $features += $selectable_and_boolean_features; if (!empty($filter)) { foreach ($filter as $feature_id) { $feature_id = trim($feature_id); if (isset($features[$feature_id])) { $feature_filter[$feature_id] = $features[$feature_id]; $feature_filter[$feature_id]['checked'] = true; unset($features[$feature_id]); } } } $settings['allow_filter'] = (bool) $filter; $settings['filter'] = $feature_filter + $features; return $settings; }
public function tags($limit = 50) { if ($limit == 50 && ($cache = $this->wa->getCache())) { $tags = $cache->get('tags'); if ($tags !== null) { return $tags; } } $tag_model = new shopTagModel(); $tags = $tag_model->getCloud(null, $limit); if (!empty($cache)) { $cache->set('tags', $tags, 7200); } return $tags; }