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));
 }
 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()
 {
     $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()
 {
     $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 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()
 {
     $parent_id = waRequest::get('parent_id');
     $category_model = new shopCategoryModel();
     $cats = $category_model->getTree($parent_id, waRequest::get('depth', null, 'int'));
     $stack = array();
     $result = array();
     foreach ($cats as $c) {
         $c['categories'] = array();
         // Number of stack items
         $l = count($stack);
         // Check if we're dealing with different levels
         while ($l > 0 && $stack[$l - 1]['depth'] >= $c['depth']) {
             array_pop($stack);
             $l--;
         }
         // Stack is empty (we are inspecting the root)
         if ($l == 0) {
             // Assigning the root node
             $i = count($result);
             $result[$i] = $c;
             $stack[] =& $result[$i];
         } else {
             // Add node to parent
             $i = count($stack[$l - 1]['categories']);
             $stack[$l - 1]['categories'][$i] = $c;
             $stack[] =& $stack[$l - 1]['categories'][$i];
         }
     }
     $this->response = $result;
     $this->response['_element'] = 'category';
 }
 public function execute()
 {
     $name = $this->get('name', true);
     $category_model = new shopCategoryModel();
     $this->response = $category_model->getByName($name);
     $this->response['_element'] = 'category';
 }
 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()
 {
     $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);
     }
 }
Beispiel #10
0
 public function getRouting($route = array(), $dispatch = false)
 {
     $url_type = isset($route['url_type']) ? $route['url_type'] : 0;
     if (!isset($this->_routes[$url_type]) || $dispatch) {
         $routes = parent::getRouting($route);
         if ($routes) {
             if (isset($routes[$url_type])) {
                 $routes = $routes[$url_type];
             } else {
                 $routes = $routes[0];
             }
         }
         // for URL <category_url>/<product_url>/
         if ($dispatch && $url_type == 2) {
             $category_model = new shopCategoryModel();
             $categories = $category_model->getByRoute(wa()->getRouting()->getDomain(null, true) . '/' . $route['url']);
             $categories_routes = array();
             foreach ($categories as $c) {
                 $categories_routes[$c['full_url'] . '/'] = array('module' => 'frontend', 'action' => 'category', 'category_id' => $c['id']);
             }
             $routes = array_merge($categories_routes, $routes);
         }
         /**
          * Extend routing via plugin routes
          * @event routing
          * @param array $routes
          * @return array $routes routes collected for every plugin
          */
         $result = wa()->event(array($this->application, 'routing'), $route);
         $all_plugins_routes = array();
         foreach ($result as $plugin_id => $routing_rules) {
             if ($routing_rules) {
                 $plugin = str_replace('-plugin', '', $plugin_id);
                 /*
                 if ($url_type == 0) {
                 $routing_rules = $routing_rules[0];
                 } else {
                 $routing_rules = $routing_rules[1];
                 }
                 */
                 foreach ($routing_rules as $url => &$route) {
                     if (!is_array($route)) {
                         list($route_ar['module'], $route_ar['action']) = explode('/', $route);
                         $route = $route_ar;
                     }
                     $route['plugin'] = $plugin;
                     $all_plugins_routes[$url] = $route;
                 }
                 unset($route);
             }
         }
         $routes = array_merge($all_plugins_routes, $routes);
         if ($dispatch) {
             return $routes;
         }
         $this->_routes[$url_type] = $routes;
     }
     return $this->_routes[$url_type];
 }
 public function createCategory($name)
 {
     $url = shopHelper::transliterate($name, false);
     $url = $this->category_model->suggestUniqueUrl($url);
     if (empty($name)) {
         $name = _w('(no-name)');
     }
     return $this->category_model->add(array('name' => $name, 'url' => $url));
 }
 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());
     }
 }
 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;
 }
Beispiel #19
0
<?php

$category_model = new shopCategoryModel();
$category_model->recount();
 public function execute()
 {
     $category_model = new shopCategoryModel();
     $this->view->assign('categories', $category_model->getFullTree('', true));
 }
 public function categories($id = 0, $depth = null, $tree = false, $params = false, $route = null)
 {
     if ($id === true) {
         $id = 0;
         $tree = true;
     }
     $category_model = new shopCategoryModel();
     if ($route && !is_array($route)) {
         $route = explode('/', $route, 2);
         $route = $this->getRoute($route[0], isset($route[1]) ? $route[1] : null);
     }
     if (!$route) {
         $route = $this->getRoute();
     }
     if (!$route) {
         return array();
     }
     $cats = $category_model->getTree($id, $depth, false, $route['domain'] . '/' . $route['url']);
     $url = $this->wa->getRouteUrl('shop/frontend/category', array('category_url' => '%CATEGORY_URL%'), false, $route['domain'], $route['url']);
     $hidden = array();
     foreach ($cats as $c_id => $c) {
         if ($c['parent_id'] && $c['id'] != $id && !isset($cats[$c['parent_id']])) {
             unset($cats[$c_id]);
         } else {
             $cats[$c_id]['url'] = str_replace('%CATEGORY_URL%', isset($route['url_type']) && $route['url_type'] == 1 ? $c['url'] : $c['full_url'], $url);
             $cats[$c_id]['name'] = htmlspecialchars($cats[$c_id]['name']);
         }
     }
     if ($id && isset($cats[$id])) {
         unset($cats[$id]);
     }
     if ($params) {
         $category_params_model = new shopCategoryParamsModel();
         $rows = $category_params_model->getByField('category_id', array_keys($cats), true);
         foreach ($rows as $row) {
             $cats[$row['category_id']]['params'][$row['name']] = $row['value'];
         }
     }
     if ($tree) {
         $stack = array();
         $result = array();
         foreach ($cats as $c) {
             $c['childs'] = array();
             // Number of stack items
             $l = count($stack);
             // Check if we're dealing with different levels
             while ($l > 0 && $stack[$l - 1]['depth'] >= $c['depth']) {
                 array_pop($stack);
                 $l--;
             }
             // Stack is empty (we are inspecting the root)
             if ($l == 0) {
                 // Assigning the root node
                 $i = count($result);
                 $result[$i] = $c;
                 $stack[] =& $result[$i];
             } else {
                 // Add node to parent
                 $i = count($stack[$l - 1]['childs']);
                 $stack[$l - 1]['childs'][$i] = $c;
                 $stack[] =& $stack[$l - 1]['childs'][$i];
             }
         }
         return $result;
     } else {
         return $cats;
     }
 }
    /**
     * @param $current_stage
     * @param $count
     * @param $processed
     *
     * @usedby shopYandexmarketPluginRunController::step()
     */
    private function stepCategory(&$current_stage, &$count, &$processed)
    {
        static $categories = null;
        static $model;
        if ($categories === null) {
            $model = new shopCategoryModel();
            if (empty($this->data['export']['hidden_categories'])) {
                $categories = $model->getTree(0, null, false, $this->data['domain']);
            } else {
                $sql = <<<SQL
SELECT c.*
FROM shop_category c
LEFT JOIN shop_category_routes cr
ON (c.id = cr.category_id)
WHERE
(cr.route IS NULL) OR (cr.route = s:domain)
ORDER BY c.left_key
SQL;
                $categories = $model->query($sql, $this->data)->fetchAll($model->getTableId());
            }
            // экспортируется только список статических категорий, поэтому фильтруем данные
            foreach ($categories as $id => $category) {
                if ($category['type'] != shopCategoryModel::TYPE_STATIC) {
                    unset($categories[$id]);
                }
            }
            if ($current_stage) {
                $categories = array_slice($categories, $current_stage);
            }
        }
        $chunk = 100;
        while (--$chunk >= 0 && ($category = reset($categories))) {
            if (empty($category['parent_id']) || isset($this->data['categories'][$category['parent_id']])) {
                $category_xml = $this->dom->createElement("category", str_replace('&', '&amp;', $category['name']));
                $category['id'] = intval($category['id']);
                $category_xml->setAttribute('id', $category['id']);
                if ($category['parent_id']) {
                    $category_xml->setAttribute('parentId', $category['parent_id']);
                }
                $nodes = $this->dom->getElementsByTagName('categories');
                $nodes->item(0)->appendChild($category_xml);
                $this->data['categories'][$category['id']] = $category['id'];
                if (!empty($category['include_sub_categories']) && $category['right_key'] - $category['left_key'] > 1) {
                    //remap hidden subcategories
                    $descendants = $model->descendants($category['id'], true)->where('type = i:type', array('type' => shopCategoryModel::TYPE_STATIC))->fetchAll('id');
                    if ($descendants) {
                        $remap = array_fill_keys(array_map('intval', array_keys($descendants)), (int) $category['id']);
                        $this->data['categories'] += $remap;
                    }
                }
                ++$processed;
            }
            array_shift($categories);
            ++$current_stage;
        }
    }
Beispiel #23
0
 public function execute()
 {
     $product = new shopProduct(waRequest::get('id', 0, waRequest::TYPE_INT));
     if (!$product->id) {
         if (waRequest::get('id') == 'new') {
             $product->name = '';
             $product->id = 'new';
             $product->status = 1;
         } else {
             throw new waException("Product not found", 404);
         }
     }
     $counters = array('reviews' => 0, 'images' => 0, 'pages' => 0, 'services' => 0);
     $sidebar_counters = array();
     $config = $this->getConfig();
     /**
      * @var shopConfig $config
      */
     #load product types
     $type_model = new shopTypeModel();
     $product_types = $type_model->getTypes(true);
     $product_types_count = count($product_types);
     if (intval($product->id)) {
         # 1 fill extra product data
         # 1.1 fill product reviews
         $product_reviews_model = new shopProductReviewsModel();
         $product['reviews'] = $product_reviews_model->getReviews($product->id, 0, $config->getOption('reviews_per_page_product'), 'datetime DESC', array('is_new' => true));
         $counters['reviews'] = $product_reviews_model->count($product->id);
         $sidebar_counters['reviews'] = array('new' => $product_reviews_model->countNew());
         $counters['images'] = count($product['images']);
         $product_pages_model = new shopProductPagesModel();
         $counters['pages'] = $product_pages_model->count($product->id);
         $product_services_model = new shopProductServicesModel();
         $counters['services'] = $product_services_model->countServices($product->id);
         $product_stocks_log_model = new shopProductStocksLogModel();
         $counters['stocks_log'] = $product_stocks_log_model->countByField('product_id', $product->id);
         $this->view->assign('edit_rights', $product->checkRights());
     } else {
         $counters += array_fill_keys(array('images', 'services', 'pages', 'reviews'), 0);
         $product['images'] = array();
         reset($product_types);
         $product->type_id = 0;
         if ($product_types_count) {
             if (!$product_types) {
                 throw new waRightsException(_w("Access denied"));
             } else {
                 reset($product_types);
                 $product->type_id = key($product_types);
             }
         } elseif (!$product->checkRights()) {
             throw new waRightsException(_w("Access denied"));
         }
         $this->view->assign('edit_rights', true);
         $product['skus'] = array('-1' => array('id' => -1, 'sku' => '', 'available' => 1, 'name' => '', 'price' => 0.0, 'purchase_price' => 0.0, 'count' => null, 'stock' => array(), 'virtual' => 0));
         $product->currency = $config->getCurrency();
     }
     $this->assignReportsData($product);
     $stock_model = new shopStockModel();
     $taxes_mode = new shopTaxModel();
     $this->view->assign('stocks', $stock_model->getAll('id'));
     $this->view->assign(array('use_product_currency' => wa()->getSetting('use_product_currency'), 'currencies' => $this->getCurrencies(), 'primary_currency' => $config->getCurrency(), 'taxes' => $taxes_mode->getAll()));
     $category_model = new shopCategoryModel();
     $categories = $category_model->getFullTree('id, name, depth, url, full_url, parent_id', true);
     $frontend_urls = array();
     if (intval($product->id)) {
         $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);
                     $params = array('product_url' => $product->url);
                     if ($product->category_id && isset($categories[$product->category_id])) {
                         if (!empty($r['url_type']) && $r['url_type'] == 1) {
                             $params['category_url'] = $categories[$product->category_id]['url'];
                         } else {
                             $params['category_url'] = $categories[$product->category_id]['full_url'];
                         }
                     }
                     $frontend_url = $routing->getUrl('/frontend/product', $params, true);
                     $frontend_urls[] = array('url' => $frontend_url);
                 }
             }
         }
     } else {
         $frontend_urls[] = array('url' => wa()->getRouteUrl('/frontend/product', array('product_url' => '%product_url%'), true));
     }
     $stuff = intval($product->id) ? $product->url : '%product_url%';
     foreach ($frontend_urls as &$frontend_url) {
         $pos = strrpos($frontend_url['url'], $stuff);
         $frontend_url['base'] = $pos !== false ? rtrim(substr($frontend_url['url'], 0, $pos), '/') . '/' : $frontend_url['url'];
     }
     unset($frontend_url);
     $product_model = new shopProductModel();
     $this->view->assign('storefront_map', $product_model->getStorefrontMap($product->id));
     /**
      * Backend product profile page
      * UI hook allow extends product profile page
      * @event backend_product
      * @param shopProduct $entry
      * @return array[string][string]string $return[%plugin_id%]['title_suffix'] html output
      * @return array[string][string]string $return[%plugin_id%]['action_button'] html output
      * @return array[string][string]string $return[%plugin_id%]['toolbar_section'] html output
      * @return array[string][string]string $return[%plugin_id%]['image_li'] html output
      */
     $this->view->assign('backend_product', wa()->event('backend_product', $product));
     /**
      * @event backend_product_edit
      */
     $this->view->assign('backend_product_edit', wa()->event('backend_product_edit', $product));
     $this->view->assign('categories', $categories);
     $this->view->assign('counters', $counters);
     $this->view->assign('product', $product);
     $this->view->assign('current_author', shopProductReviewsModel::getAuthorInfo(wa()->getUser()->getId()));
     $this->view->assign('reply_allowed', true);
     $this->view->assign('review_allowed', true);
     $this->view->assign('sidebar_counters', $sidebar_counters);
     $this->view->assign('lang', substr(wa()->getLocale(), 0, 2));
     $this->view->assign('frontend_urls', $frontend_urls);
     $tag_model = new shopTagModel();
     $this->view->assign('popular_tags', $tag_model->popularTags());
     $counts = array();
     // Selectable features
     $features_selectable = $product->features_selectable;
     if (is_array($features_selectable)) {
         foreach ($features_selectable as $f) {
             if ($f['selected']) {
                 $counts[] = $f['selected'];
             }
         }
     }
     $feature_model = new shopTypeFeaturesModel();
     $features_selectable_types = $feature_model->getSkuTypeSelectableTypes();
     foreach ($product_types as $type_id => &$type) {
         $type['sku_type'] = empty($features_selectable_types[$type_id]) ? shopProductModel::SKU_TYPE_FLAT : shopProductModel::SKU_TYPE_SELECTABLE;
     }
     $this->view->assign('features', $features_selectable);
     $this->view->assign('duble', '???');
     $this->view->assign('features_counts', $counts);
     #load product types
     $this->view->assign('product_types', $product_types);
     $this->view->assign('sidebar_width', $config->getSidebarWidth());
 }
 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 setData(shopProduct $product, $data)
 {
     $data = array_unique(array_map('intval', $data));
     $key = array_search(0, $data, true);
     if ($key !== false) {
         unset($data[$key]);
     }
     $category_ids = array_keys($this->getByField('product_id', $product->id, 'category_id'));
     if ($obsolete = array_diff($category_ids, $data)) {
         $this->deleteByField(array('product_id' => $product->id, 'category_id' => $obsolete));
         // correct counter
         $category_model = new shopCategoryModel();
         $category_model->recount($obsolete);
     }
     if ($added = array_diff($data, $category_ids)) {
         $this->add($product->id, $added);
     }
     //$product_model = new shopProductModel();
     //$product_model->correctMainCategory($product->id);
     if ($data) {
         $product->category_id = reset($data);
     } else {
         $product->category_id = null;
     }
     $product_model = new shopProductModel();
     $product_model->updateById($product->id, array('category_id' => $product->category_id));
     return $data;
 }
 public function execute($n = 1)
 {
     $routes = $this->getRoutes();
     $this->app_id = wa()->getApp();
     $category_model = new shopCategoryModel();
     $product_model = new shopProductModel();
     $page_model = new shopPageModel();
     $count = 0;
     foreach ($routes as $route) {
         $this->routing->setRoute($route);
         $domain = $this->routing->getDomain(null, true);
         $route_url = $domain . '/' . $this->routing->getRoute('url');
         if ($n == 1) {
             // categories
             $sql = "SELECT c.id,c.parent_id,c.left_key,c.url,c.full_url,c.create_datetime,c.edit_datetime\n                        FROM shop_category c\n                        LEFT JOIN shop_category_routes cr ON c.id = cr.category_id\n                        WHERE c.status = 1 AND (cr.route IS NULL OR cr.route = '" . $category_model->escape($route_url) . "')\n                        ORDER BY c.left_key";
             $categories = $category_model->query($sql)->fetchAll('id');
             $category_url = $this->routing->getUrl($this->app_id . '/frontend/category', array('category_url' => '%CATEGORY_URL%'), true);
             foreach ($categories as $c_id => $c) {
                 if ($c['parent_id'] && !isset($categories[$c['parent_id']])) {
                     unset($categories[$c_id]);
                     continue;
                 }
                 if (isset($route['url_type']) && $route['url_type'] == 1) {
                     $url = $c['url'];
                 } else {
                     $url = $c['full_url'];
                 }
                 $this->addUrl(str_replace('%CATEGORY_URL%', $url, $category_url), $c['edit_datetime'] ? $c['edit_datetime'] : $c['create_datetime'], self::CHANGE_WEEKLY, 0.6);
             }
             $main_url = $this->getUrl('');
             // pages
             $sql = "SELECT full_url, url, create_datetime, update_datetime FROM " . $page_model->getTableName() . '
                     WHERE status = 1 AND domain = s:domain AND route = s:route';
             $pages = $page_model->query($sql, array('domain' => $domain, 'route' => $route['url']))->fetchAll();
             foreach ($pages as $p) {
                 $this->addUrl($main_url . $p['full_url'], $p['update_datetime'] ? $p['update_datetime'] : $p['create_datetime'], self::CHANGE_MONTHLY, 0.6);
             }
             /**
              * @event sitemap
              * @param array $route
              * @return array $urls
              */
             $plugin_urls = wa()->event(array($this->app_id, 'sitemap'), $route);
             if ($plugin_urls) {
                 foreach ($plugin_urls as $urls) {
                     foreach ($urls as $url) {
                         $this->addUrl($url['loc'], ifset($url['lastmod'], time()), ifset($url['changefreq']), ifset($url['priority']));
                     }
                 }
             }
             // main page
             $this->addUrl($main_url, time(), self::CHANGE_DAILY, 1);
         }
         // products
         $c = $this->countProductsByRoute($route);
         if ($count + $c <= ($n - 1) * $this->limit) {
             $count += $c;
             continue;
         } else {
             if ($count >= ($n - 1) * $this->limit) {
                 $offset = 0;
             } else {
                 $offset = ($n - 1) * $this->limit - $count;
             }
             $count += $offset;
             $limit = min($this->limit, $n * $this->limit - $count);
         }
         $sql = "SELECT p.url, p.create_datetime, p.edit_datetime";
         if (isset($route['url_type']) && $route['url_type'] == 2) {
             $sql .= ', c.full_url category_url';
         }
         $sql .= " FROM " . $product_model->getTableName() . ' p';
         if (isset($route['url_type']) && $route['url_type'] == 2) {
             $sql .= " LEFT JOIN " . $category_model->getTableName() . " c ON p.category_id = c.id";
         }
         $sql .= ' WHERE p.status = 1';
         if (!empty($route['type_id'])) {
             $sql .= ' AND p.type_id IN (i:type_id)';
         }
         $sql .= ' LIMIT ' . $offset . ',' . $limit;
         $products = $product_model->query($sql, $route);
         $count += $products->count();
         $product_url = $this->routing->getUrl($this->app_id . '/frontend/product', array('product_url' => '%PRODUCT_URL%', 'category_url' => '%CATEGORY_URL%'), true);
         foreach ($products as $p) {
             if (!empty($p['category_url'])) {
                 $url = str_replace(array('%PRODUCT_URL%', '%CATEGORY_URL%'), array($p['url'], $p['category_url']), $product_url);
             } else {
                 $url = str_replace(array('%PRODUCT_URL%', '/%CATEGORY_URL%'), array($p['url'], ''), $product_url);
             }
             $this->addUrl($url, $p['edit_datetime'] ? $p['edit_datetime'] : $p['create_datetime'], self::CHANGE_MONTHLY, 0.8);
         }
         if ($count >= $n * $this->limit) {
             break;
         }
     }
 }
Beispiel #27
0
 public function categoriesAction()
 {
     $model = new shopCategoryModel();
     $model->repair();
     echo "OK";
 }
Beispiel #28
0
<?php

$category_model = new shopCategoryModel();
foreach ($category_model->select('id, conditions')->where('type = 1')->fetchAll('id') as $item) {
    $conditions = preg_replace('/\\brate\\b/', 'rating', $item['conditions']);
    if ($conditions != $item['conditions']) {
        $category_model->updateById($item['id'], array('conditions' => $conditions));
    }
}
Beispiel #29
0
<?php

$category_model = new shopCategoryModel();
$category_model->repair();