/**
  * @return mixed
  * @throws waException
  */
 protected function getCategory()
 {
     $category_model = $this->getModel();
     $url_field = waRequest::param('url_type') == 1 ? 'url' : 'full_url';
     if (waRequest::param('category_id')) {
         $category = $category_model->getById(waRequest::param('category_id'));
         if ($category) {
             $category_url = wa()->getRouteUrl('/frontend/category', array('category_url' => $category[$url_field]));
             if (urldecode(wa()->getConfig()->getRequestUrl(false, true)) !== $category_url) {
                 $q = waRequest::server('QUERY_STRING');
                 $this->redirect($category_url . ($q ? '?' . $q : ''), 301);
             }
         }
     } else {
         $category = $category_model->getByField($url_field, waRequest::param('category_url'));
         if ($category && $category[$url_field] !== urldecode(waRequest::param('category_url'))) {
             $q = waRequest::server('QUERY_STRING');
             $this->redirect(wa()->getRouteUrl('/frontend/category', array('category_url' => $category[$url_field])) . ($q ? '?' . $q : ''), 301);
         }
     }
     $route = wa()->getRouting()->getDomain(null, true) . '/' . wa()->getRouting()->getRoute('url');
     if ($category) {
         $category_routes_model = new shopCategoryRoutesModel();
         $routes = $category_routes_model->getRoutes($category['id']);
     }
     if (!$category || $routes && !in_array($route, $routes)) {
         throw new waException('Category not found', 404);
     }
     $category['subcategories'] = $category_model->getSubcategories($category, $route);
     $category_url = wa()->getRouteUrl('shop/frontend/category', array('category_url' => '%CATEGORY_URL%'));
     foreach ($category['subcategories'] as &$sc) {
         $sc['url'] = str_replace('%CATEGORY_URL%', waRequest::param('url_type') == 1 ? $sc['url'] : $sc['full_url'], $category_url);
     }
     unset($sc);
     // params
     $category_params_model = new shopCategoryParamsModel();
     $category['params'] = $category_params_model->get($category['id']);
     // smarty description
     if ($this->getConfig()->getOption('can_use_smarty') && $category['description']) {
         $category['description'] = wa()->getView()->fetch('string:' . $category['description']);
     }
     return $category;
 }
 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;
 }
    /**
     * @param array $settings
     * @return string
     */
    public function backendCategoryDialog($settings)
    {
        if (!isset($settings['params'])) {
            if (!empty($settings['id'])) {
                $category_params_model = new shopCategoryParamsModel();
                $params = $category_params_model->get($settings['id']);
            } else {
                $params = array();
            }
        } else {
            $params = $settings['params'];
        }
        $control_params = array('namespace' => 'yandexmarket', 'value' => !empty($params['yandexmarket_group_skus']), 'title' => 'Яндекс.Маркет', 'description' => 'При экспорте в Яндекс.Маркет группировать все артикулы товаров <span class="hint">Настройка учитывается только для случая экспорта каждого артикула товара как отдельной товарной позиции на Яндекс.Маркете (настраивается в профиле экспорта)</span>', 'title_wrapper' => '%s', 'description_wrapper' => '%s', 'control_wrapper' => '<div class="name">%s</div><div class="value no-shift"><label>%s %s</label></div>');
        $control = waHtmlControl::getControl(waHtmlControl::CHECKBOX, 'group_skus', $control_params);
        return <<<HTML
<div class="field-group">
    <div class="field">
        {$control}
    </div>
</div>
HTML;
    }
Esempio n. 4
0
 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;
 }