private function stepExportCategory(&$current_stage, &$count, &$processed) { static $categories; if (!$categories) { $model = new shopCategoryModel(); if (preg_match('@^category/(\\d+)$@', $this->data['hash'], $matches)) { $categories = array_reverse($model->getPath($matches[1])); if ($category = $model->getById($matches[1])) { $categories[$matches[1]] = $category; } } else { $categories = $model->getFullTree('*', true); } if (count($categories) != $this->data['count'][self::STAGE_CATEGORY]) { throw new waException(sprintf('Invalid category count. Expected %d but get %d', $this->data['count'][self::STAGE_CATEGORY], count($categories))); } if ($current_stage) { $categories = array_slice($categories, $current_stage[self::STAGE_CATEGORY]); } } if ($category = reset($categories)) { $category['name'] = str_repeat('!', $category['depth']) . $category['name']; $this->writer->write($category); array_shift($categories); ++$current_stage[self::STAGE_CATEGORY]; ++$processed[self::STAGE_CATEGORY]; $this->data['map'][self::STAGE_CATEGORY] = intval($category['id']); $this->data['map'][self::STAGE_PRODUCT] = $current_stage[self::STAGE_PRODUCT]; $count[self::STAGE_PRODUCT] += $this->getCollection()->count(); } return $current_stage[self::STAGE_CATEGORY] < $count[self::STAGE_CATEGORY]; }
public function execute() { $id = $this->get('id', true); $category_model = new shopCategoryModel(); $category = $category_model->getById($id); if ($category) { $data = waRequest::post(); $exclude = array('left_key', 'right_key', 'type', 'full_url'); foreach ($exclude as $k) { if (isset($data[$k])) { unset($data[$k]); } } if (isset($data['parent_id']) && $category['parent_id'] != $data['parent_id']) { if (!$category_model->getById($data['parent_id'])) { throw new waAPIException('invalid_param', 'Parent category not found', 404); } if (!$category_model->move($id, null, $data['parent_id'])) { throw new waAPIException('server_error', 500); } } if ($category_model->update($id, $data)) { $method = new shopCategoryGetInfoMethod(); $this->response = $method->getResponse(true); } else { throw new waAPIException('server_error', 500); } } else { throw new waAPIException('invalid_param', 'Category not found', 404); } }
public function getBreadcrumbs(shopProduct $product, $product_link = false) { if ($product['category_id']) { $category_model = new shopCategoryModel(); $category = $category_model->getById($product['category_id']); $product['category_url'] = waRequest::param('url_type') == 1 ? $category['url'] : $category['full_url']; if (waRequest::param('url_type') == 2 && !waRequest::param('category_url')) { $this->redirect(wa()->getRouteUrl('/frontend/product', array('product_url' => $product['url'], 'category_url' => $product['category_url'])), 301); } $breadcrumbs = array(); $path = $category_model->getPath($category['id']); $path = array_reverse($path); $root_category_id = $category['id']; if ($path) { $temp = reset($path); $root_category_id = $temp['id']; } foreach ($path as $row) { $breadcrumbs[] = array('url' => wa()->getRouteUrl('/frontend/category', array('category_url' => waRequest::param('url_type') == 1 ? $row['url'] : $row['full_url'])), 'name' => $row['name']); } $breadcrumbs[] = array('url' => wa()->getRouteUrl('/frontend/category', array('category_url' => waRequest::param('url_type') == 1 ? $category['url'] : $category['full_url'])), 'name' => $category['name']); if ($product_link) { $breadcrumbs[] = array('url' => wa()->getRouteUrl('/frontend/product', array('product_url' => $product['url'], 'category_url' => $product['category_url'])), 'name' => $product['name']); } if ($breadcrumbs) { $this->view->assign('breadcrumbs', $breadcrumbs); } } else { $root_category_id = null; } $this->view->assign('root_category_id', $root_category_id); }
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() { $product_id = (int) waRequest::get('id'); $product = new shopProduct($product_id); $type_model = new shopTypeModel(); $type = $type_model->getById($product['type_id']); if ($product['cross_selling'] === null) { $product['cross_selling'] = $type['cross_selling'] ? 1 : 0; } if ($product['upselling'] === null) { $product['upselling'] = $type['upselling']; } // if manually if ($product['cross_selling'] == 2 || $product['upselling'] == 2) { $related_model = new shopProductRelatedModel(); $related = $related_model->getAllRelated($product_id); } else { $related = array(); } if ($type['upselling']) { $type_upselling_model = new shopTypeUpsellingModel(); $data = $type_upselling_model->getByType($type['id']); $type['upselling_html'] = shopSettingsRecommendationsAction::getConditionHTML($data); } if ($type['cross_selling'] && substr($type['cross_selling'], 0, 9) == 'category/') { $category_model = new shopCategoryModel(); $type['category'] = $category_model->getById(substr($type['cross_selling'], 9)); } $this->view->assign(array('type' => $type, 'product' => $product, 'related' => $related)); }
public function execute() { $data = waRequest::post(); $exclude = array('left_key', 'right_key', 'type', 'full_url'); foreach ($exclude as $k) { if (isset($data[$k])) { unset($data[$k]); } } // check required param name $this->post('name', true); $category_model = new shopCategoryModel(); $parent_id = waRequest::post('parent_id', 0, 'int'); if ($parent_id && !$category_model->getById($parent_id)) { throw new waAPIException('invalid_request', 'Parent category not found', 404); } if ($id = $category_model->add($data, $parent_id)) { // return info of the new category $_GET['id'] = $id; $method = new shopCategoryGetInfoMethod(); $this->response = $method->getResponse(true); } else { throw new waAPIException('server_error', 500); } }
public function execute() { $app_settings_model = new waAppSettingsModel(); $settings = $app_settings_model->get(array('shop', 'yoss')); if ($settings['status'] === 'on') { $query = waRequest::post('query', '', waRequest::TYPE_STRING_TRIM); $page = waRequest::post('page', 1, 'int'); $result = array(); $result['products'] = array(); $result['product_count'] = 0; $collection = new shopProductsCollection('search/query=' . $query); $product_limit = $settings['product_limit']; if (!$product_limit) { $product_limit = $this->getConfig()->getOption('products_per_page'); } $products = $collection->getProducts('*', ($page - 1) * $product_limit, $product_limit); if ($products) { $brands = array(); $categories = array(); $feature_model = new shopFeatureModel(); $result['searh_all_url'] = wa()->getRouteUrl('/frontend/search/query=') . '?query=' . $query; foreach ($products as $p) { $brand_feature = $feature_model->getByCode('brand'); $brand = ''; if ($brand_feature) { $feature_value_model = $feature_model->getValuesModel($brand_feature['type']); $product_brands = $feature_value_model->getProductValues($p['id'], $brand_feature['id']); $brands = array(); foreach ($product_brands as $k => $v) { $brand_id = $feature_value_model->getValueId($brand_feature['id'], $v); $brands[] = array('id' => $brand_id, 'brand' => '<a href="' . wa()->getRouteUrl('shop/frontend/brand', array('brand' => str_replace('%2F', '/', urlencode($v)))) . '">' . $v . '</a>'); } } $category_model = new shopCategoryModel(); $category = $category_model->getById($p['category_id']); $res_category = ''; if ($category) { $res_category = '<a href="' . wa()->getRouteUrl('/frontend/category', array('category_url' => $category['full_url'])) . '">' . $category['name'] . '</a>'; } $result['products'][] = array("name" => $p['name'], "url" => $p['frontend_url'], "image" => $p['image_id'] ? "<img src='" . shopImage::getUrl(array("product_id" => $p['id'], "id" => $p['image_id'], "ext" => $p['ext']), "48x48") . "' />" : "", "price" => shop_currency_html($p['price'], true), "brands" => $brands, "category" => $res_category); } $product_model = new shopProductModel(); $product_count = $collection->count(); $result['product_count'] = $product_count; if ($product_count > ($page - 1) * $product_limit + $product_limit) { $result['next_page'] = $page + 1; } else { $result['next_page'] = false; } } $this->response = $result; } else { $this->response = false; } }
public function execute() { $id = $this->get('id', true); $category_model = new shopCategoryModel(); $category = $category_model->getById((int) $id); if ($category) { $this->response = $category; } else { throw new waAPIException('invalid_request', 'Category not found', 404); } }
public function execute() { $id = $this->get('id', true); $this->getProduct($id); $category_id = $this->post('category_id', true); $category_model = new shopCategoryModel(); $category = $category_model->getById($category_id); if (!$category) { throw new waAPIException('invalid_param', 'Category not found', 404); } if ($category['type'] == shopCategoryModel::TYPE_DYNAMIC) { throw new waAPIException('invalid_param', 'Category type must be static'); } $category_products_model = new shopCategoryProductsModel(); $this->response = $category_products_model->deleteProducts($category_id, $id); }
public function execute() { $id = $this->get('id', true); $category_model = new shopCategoryModel(); $category = $category_model->getById((int) $id); if ($category) { if ($category['parent_id']) { $parents = $category_model->getPath($category['id']); if (waRequest::get('reverse')) { $parents = array_reverse($parents); } $this->response = array_values($parents); $this->response['_element'] = 'category'; } else { $this->response = array(); } } else { throw new waAPIException('invalid_request', 'Category not found', 404); } }
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 (waRequest::param('url_type') == 2) { $product_model = new shopProductModel(); if (waRequest::param('category_url')) { $category_model = new shopCategoryModel(); $c = $category_model->getByField('full_url', waRequest::param('category_url')); if ($c) { $product = $product_model->getByUrl(waRequest::param('product_url'), $c['id']); if ($product && $product['category_id'] != $c['id']) { $c = $category_model->getById($product['category_id']); if ($c) { $this->redirect(wa()->getRouteUrl('shop/frontend/product', array('category_url' => $c['full_url'], 'product_url' => $product['url']))); } else { $product = null; } } } else { $product = null; } } else { $product = $product_model->getByField('url', waRequest::param('product_url')); } if (!$product) { // try find page $url = waRequest::param('category_url'); $url_parts = explode('/', $url); waRequest::setParam('page_url', waRequest::param('product_url')); waRequest::setParam('product_url', end($url_parts)); $this->executeAction(new shopFrontendProductPageAction()); } else { $this->executeAction(new shopFrontendProductAction($product)); } } else { $this->executeAction(new shopFrontendProductAction()); } }
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 category($id) { $category_model = new shopCategoryModel(); $category = $category_model->getById($id); $route = $this->getRoute(); if (!$route) { $category['subcategories'] = array(); } else { $category['subcategories'] = $category_model->getSubcategories($category, $route['domain'] . '/' . $route['url']); $category_url = wa()->getRouteUrl('shop/frontend/category', array('category_url' => '%CATEGORY_URL%')); foreach ($category['subcategories'] as &$sc) { $sc['url'] = str_replace('%CATEGORY_URL%', isset($route['url_type']) && $route['url_type'] == 1 ? $sc['url'] : $sc['full_url'], $category_url); } unset($sc); } $category_params_model = new shopCategoryParamsModel(); $category['params'] = $category_params_model->get($category['id']); if ($this->wa->getConfig()->getOption('can_use_smarty') && $category['description']) { $category['description'] = wa()->getView()->fetch('string:' . $category['description']); } return $category; }
protected function getUrl($product) { $frontend_urls = array(); $routing = wa()->getRouting(); $domain_routes = $routing->getByApp($this->getAppId()); foreach ($domain_routes as $domain => $routes) { foreach ($routes as $r) { if (!empty($r['private'])) { continue; } if (empty($r['type_id']) || in_array($product->type_id, (array) $r['type_id'])) { $routing->setRoute($r, $domain); $url_params = array('product_url' => $product->url); if ($product->category_id) { if (empty($category_model)) { $category_model = new shopCategoryModel(); } $category = $category_model->getById($product->category_id); if ($category) { if (!empty($r['url_type']) && $r['url_type'] == 1) { $url_params['category_url'] = $category['url']; } else { $url_params['category_url'] = $category['full_url']; } } } $frontend_url = $routing->getUrl('/frontend/product', $url_params, true); $pos = strrpos($frontend_url, $product->url); $frontend_urls[] = array('url' => $frontend_url, 'base' => $pos !== false ? rtrim(substr($frontend_url, 0, $pos), '/') . '/' : $frontend_url); } } } return $frontend_urls; }