php class shopPartsPluginFrontendModelPageAction extends waViewAction { public function execute() { $this-setLayout(new shopFrontendLayout()); $plugin = wa('shop')-getPlugin('parts'); $settings = $plugin-getSettings(); $shopPartsTypesModel = new shopPartsTypesModel('extra'); $shopPartsBrandsModel = new shopPartsBrandsModel('extra'); $shopPartsModelsModel = new shopPartsModelsModel('extra'); $mysql = new waModel(); $products = array(); $category = array(); $products_count = 0; $model_url = waRequestparam('model_url', null, 'string'); $_GET['model_url'] = $model_url; $category_url = waRequestparam('category_url', null, 'string'); $_GET['category_url'] = $category_url; $model = $shopPartsModelsModel-select()-where('url = '.$model_url.'')-fetchAssoc(); if(empty($model)) { $this-view-assign('error_message', 'Модель не знайдена!'); $this-view-assign('error_code', 404); $this-getResponse()-setStatus(404); $this-setThemeTemplate('error.html'); return $this-view-fetch($this-getTemplate()); } if(!empty($category_url)){ $category = $mysql-query(SELECT id, name, url FROM shop_category WHERE url = '.$mysql-escape($category_url).')-fetchAssoc(); if(class_exists('shopSeoPlugin')) { $seo_name = $mysql-query(SELECT value FROM shop_seo_category_settings WHERE name = 'seo_name' AND category_id = .(int)$category['id'])-fetchField(); if(!empty($seo_name)){ $category['name'] = $seo_name; } } if(!empty($category) AND class_exists('mylangViewHelper')) { $product_categories = mylangViewHelpercategories(array($category)); $category = $product_categories[0]; } } $product_ids = shopPartsPlugingetProductIdsByModelId($model['id'], $category); $product_ids_not_category = shopPartsPlugingetProductIdsByModelId($model['id']); if(!empty($product_ids)) { $collection = null; $collection = new shopProductsCollection('id'.implode(',', $product_ids)); $products = $collection-getProducts('', 0, $collection-count()); if (isset($products) && !empty($products) && count($products) 0) { $products_count = count($products); } if(!empty($category_url)){ $product_categories_links = $mysql-query(SELECT categories.id, categories.name, categories.url FROM shop_category as categories JOIN shop_product as products ON categories.id = products.category_id WHERE products.status = 1 AND products.id IN (.implode(',', $product_ids_not_category).))-fetchAll(id); if(!empty($product_categories_links) AND class_exists('mylangViewHelper')) { $product_categories_links = mylangViewHelpercategories($product_categories_links); foreach ($product_categories_links as $category_link) { if($category['url'] != $category_link['url']) { $category_links[] = [ 'url' = model$model_url.$category_link['url'], 'name' = $category_link['name'], ]; } } $category_links[] = [ 'url' = model$model_url, 'name' = 'Всі доступні запчастини', ]; } } else { $product_categories_links = $mysql-query(SELECT categories.id, categories.name, categories.url FROM shop_category as categories JOIN shop_product as products ON categories.id = products.category_id WHERE products.status = 1 AND products.id IN (.implode(',', $product_ids).))-fetchAll(id); if(!empty($product_categories_links) AND class_exists('mylangViewHelper')) { $product_categories_links = mylangViewHelpercategories($product_categories_links); foreach ($product_categories_links as $category_link) { $category_links[] = [ 'url' = model$model_url.$category_link['url'], 'name' = $category_link['name'], ]; } } } } $type = $shopPartsTypesModel-select('')-where('id = '.$model['type_id'].'')-fetchAssoc(); if(!empty($type)) { $model['type_name'] = $type['name']; $model['type_name_whom'] = $type['name_whom']; } $brand = $shopPartsBrandsModel-select('')-where('id = '.$model['brand_id'].'')-fetchAssoc(); if(!empty($brand)) { $model['brand_name'] = $brand['name']; } if (!empty($category_url)) { $collection_links = new shopProductsCollection('id'.implode(',', array_diff($product_ids_not_category, $product_ids))); $product_links = $collection_links-getProducts('', 0, $collection_links-count()); } else { $model_links = $shopPartsModelsModel-select('id, name, url')-where('brand_id = '.$model['brand_id'].' AND type_id = '.$model['type_id'].' AND id != '.$model['id'].'')-fetchAll('id'); } $model_page_title = (!empty($category_url)) $settings['model_page_title_category'] $settings['model_page_title']; $model_page_keywords = (!empty($category_url)) $settings['model_page_keywords_category'] $settings['model_page_keywords']; $model_page_description = (!empty($category_url)) $settings['model_page_description'] ''; $model_page_h1 = (!empty($category_url)) $settings['model_page_h1_category'] $settings['model_page_h1']; $model_page_contant = (!empty($category_url)) $settings['model_page_content_category'] $settings['model_page_content']; if (strlen($model_page_title) 0) $meta_title = $this-maskReplacement($model_page_title, $model, null, $category, 'title'); else $meta_title = ''; if (strlen($model_page_keywords) 0){ $meta_keywords = $this-maskReplacement($model_page_keywords, $model, null, $category); }else{ $meta_keywords = ''; } if (strlen($model_page_description) 0) $meta_description = $this-maskReplacement($model_page_description, $model, null, $category); else $meta_description = ''; if (strlen($model_page_h1) 0) $title = $this-maskReplacement($model_page_h1, $model, null, $category); else $title = 'Запчастини для '.mb_strtolower($model['type_genitive_case_name']).' '.$model['brand_name'].' '.$model['name'].((isset($model['industrial_code']) && !empty($model['industrial_code'])) ' - '.$model['industrial_code'] ''); if (strlen($model_page_contant) 0) $description = $this-maskReplacement($model_page_contant, $model, null, $category); else $description = null; $this-getResponse()-setMeta('title', $meta_title); $this-getResponse()-setMeta('keywords', $meta_keywords); $this-getResponse()-setMeta('description', $meta_description); $this-view-assign(array( 'page_description' = $description, 'model_links' = $model_links, 'product_links' = $product_links, 'category_links' = $category_links, 'model' = $model )); $this-view-assign(array( 'products' = $products, 'products_count' = $products_count )); $this-view-assign('title', $title); $this-view-assign('frontend_search', ''); $breadcrumbs = array( array( 'name' = 'Підбір запчастин по моделі', 'url' = '' ), ); $this-view-assign('breadcrumbs', $breadcrumbs); $this-setThemeTemplate('search.html'); } public function maskReplacement($string, $model, $number_name = null, $category = array(), $place = '') { if (isset($model['type_name']) && !empty($model['type_name']) && strlen($model['type_name']) 0) $type_name = $model['type_name']; else $type_name = ''; if (isset($model['type_name_whom']) && !empty($model['type_name_whom']) && strlen($model['type_name_whom']) 0) $type_name_rod = $model['type_name_whom']; else $type_name_rod = ''; if (isset($model['brand_name']) && !empty($model['brand_name']) && strlen($model['brand_name']) 0) $brand_name = $model['brand_name']; else $brand_name = ''; if (isset($model['name']) && !empty($model['name']) && strlen($model['name']) 0) { if(isset($model['industrial_code']) && !empty($model['industrial_code'])){ $model_name = $model['name']. -- .$model['industrial_code']; }else{ $model_name = $model['name']; } if(!empty($model['marketing_name'])) { $model_name .= .$model['marketing_name']; } }else $model_name = ''; if (!isset($number_name) empty($number_name)) $number_name = ''; $category_name = ifset($category['name'], ''); $region_name = ''; $region_name_2 = ''; if(class_exists('shopRegionsRouting')){ $routing = new shopRegionsRouting(); $city = $routing-getCurrentCity(); if($city) { $region_name = $city-getName(); $region_name_2 = $city-getParam(11); } } if($place == 'title') { $category_name = mb_strtolower($category_name); } $string = trim(str_replace('TYPE_NAME_ROD', mb_strtolower($type_name_rod), $string)); $string = trim(str_replace('TYPE_NAME', mb_strtolower($type_name), $string)); $string = trim(str_replace('BRAND_NAME', $brand_name, $string)); $string = trim(str_replace('MODEL_NAME', $model_name, $string)); $string = trim(str_replace('REGION_NAME_2', $region_name_2, $string)); $string = trim(str_replace('REGION_NAME', $region_name, $string)); $string = trim(str_replace('CATEGORY_NAME', $category_name, $string)); $string = $this-mb_ucfirst($string, utf-8); return $string; } public function mb_ucfirst($string, $encoding) { $strlen = mb_strlen($string, $encoding); $firstChar = mb_substr($string, 0, 1, $encoding); $then = mb_substr($string, 1, $strlen - 1, $encoding); return mb_strtoupper($firstChar, $encoding) . $then; } } Помилка #500