[Помогите] Мультиязык для сайтмапа опенкарт

Тема в разделе "OpenCart", создана пользователем MGT1, 4 янв 2016.

  1. MGT1

    MGT1

    Регистрация:
    5 янв 2013
    Сообщения:
    900
    Симпатии:
    218
  2. Dotrox

    Dotrox Команда форума

    Регистрация:
    27 ноя 2012
    Сообщения:
    3.198
    Симпатии:
    1.306
    Я в той теме дал ответ: https://support.google.com/webmasters/answer/2620865?hl=en
    Нужно просто переделать генератор сайтмапа, чтоб он делал файл такой стуктуры, как в доках Гугла. Других вариантов нет.
     
  3. MGT1

    MGT1

    Регистрация:
    5 янв 2013
    Сообщения:
    900
    Симпатии:
    218
    Так, на стандартном сайтмапе (точнее на немного модификованом) - подхват языка идет model/feed

     
  4. Dotrox

    Dotrox Команда форума

    Регистрация:
    27 ноя 2012
    Сообщения:
    3.198
    Симпатии:
    1.306
    Файл: catalog/model/feed

    Вот в таком варианте оно подтянет товары во всех языковых вариантах:
    PHP:
    <?php
    class ModelFeedGoogleSitemap extends Model {

        public function 
    getProducts() {

            
    $cache md5('product_sitemap');

            
    $product_data $this->cache->get('product_sitemap.' '.' . (int)$this->config->get('config_store_id') . $cache);

            if (!
    $product_data) {
                
    $product_data = array();
                
    $languages $this->db->query("SELECT language_id FROM " DB_PREFIX "language WHERE status = '1'");
      
                foreach(
    $languages->rows as $language){
                    
    $sql "SELECT p.product_id, p.date_added, p.date_modified FROM " DB_PREFIX "product p LEFT JOIN " DB_PREFIX "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " DB_PREFIX "product_to_store p2s ON (p.product_id = p2s.product_id)
                     WHERE pd.language_id = '" 
    . (int)$language['language_id'] . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'";
                     
    $sql .= " ORDER BY p.sort_order";
                     
    $sql .= " ASC";
                     
    $query $this->db->query($sql);
                    
                     
    $product_data array_merge($product_data$query->rows);        
                }

            
    $this->cache->set('product_sitemap.' '.' . (int)$this->config->get('config_store_id') . $cache$product_data);
            }

            return 
    $product_data;
        }
    }
    ?>
    Нужно только протестировать, могут понадобиться мелкие правки, я это из головы писал.
     
    Lasted edited by : 6 янв 2016
    MGT1 нравится это.
  5. MGT1

    MGT1

    Регистрация:
    5 янв 2013
    Сообщения:
    900
    Симпатии:
    218
    В Паладин Сео Менеджер включил: карту сайта, ссылку на всех языках. Ввернул код Дотрокса - и все работает.

    Теперь остается вопрос, куда вписать что бы было понятно поисковику, что это одни и те-же ссылки, только на разных языках.
    По ходу сюда-сейчас посмотрим как:
    /catalog/controller/feed

    Выходя из работы имеем следующее:
    В главный язык вносить ссылку 'ru' не имеет смысла. 2-й язык получает ссылку формата домен/ua/****.
    Соотносительно нужно сделать альтернативу главному-2-й, и обратно.
    --- Добавлено, 6 янв 2016 ---
    Возьмем на примере fast_sitemap ot Snastika
    PHP:
    <?php
    class ControllerFeedGoogleSitemap extends Controller {
        public function 
    index() {
            if (
    $this->config->get('google_sitemap_status')) {

                
    $output $this->cache->get('sitemap.'.(int)$this->config->get('config_store_id'));
       
                if (!
    $output) {
           
                
    $output  '<?xml version="1.0" encoding="UTF-8"?>';
                
    $output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

       
       
                
    $this->load->model('feed/google_sitemap');

             
    $products $this->model_feed_google_sitemap->getProducts();

                foreach (
    $products as $product) {
                    
    $output .= '<url>';
                    
    $output .= '<loc>' str_replace('&''&amp;'str_replace('&amp;''&'$this->url->link('product/product''product_id=' $product['product_id']))) . '</loc>';
                    
    $output .= '<lastmod>' substr(max($product['date_added'], $product['date_modified']), 010) . '</lastmod>';
                    
    $output .= '<changefreq>weekly</changefreq>';
                    
    $output .= '<priority>1.0</priority>';
                    
    $output .= '</url>';
                }

                
    $this->load->model('catalog/category');

                
    $output .= $this->getCategories(0);

                
    $this->load->model('catalog/manufacturer');

                
    $manufacturers $this->model_catalog_manufacturer->getManufacturers();

                foreach (
    $manufacturers as $manufacturer) {
                    
    $output .= '<url>';
                    
    $output .= '<loc>' str_replace('&''&amp;'str_replace('&amp;''&'$this->url->link('product/manufacturer/info''manufacturer_id=' $manufacturer['manufacturer_id']))) . '</loc>';
                    
    $output .= '<changefreq>weekly</changefreq>';
                    
    $output .= '<priority>0.7</priority>';
                    
    $output .= '</url>';
                }

                
    $this->load->model('catalog/information');

                
    $informations $this->model_catalog_information->getInformations();

                foreach (
    $informations as $information) {
                    
    $output .= '<url>';
                    
    $output .= '<loc>' str_replace('&''&amp;'str_replace('&amp;''&'$this->url->link('information/information''information_id=' $information['information_id']))) . '</loc>';
                    
    $output .= '<changefreq>weekly</changefreq>';
                    
    $output .= '<priority>0.5</priority>';
                    
    $output .= '</url>';
                }

                
    $output .= '</urlset>';

       
                    
    $this->cache->set('sitemap.'.(int)$this->config->get('config_store_id'), $output);
                }
       
                
    $this->response->addHeader('Content-Type: application/xml');
                
    $this->response->setOutput($output);
            }
        }

        protected function 
    getCategories($parent_id$current_path '') {
            
    $output '';

            
    $results $this->model_catalog_category->getCategories($parent_id);

            foreach (
    $results as $result) {
                if (!
    $current_path) {
                    
    $new_path $result['category_id'];
                } else {
                    
    $new_path $current_path '_' $result['category_id'];
                }

                
    $output .= '<url>';
                
    $output .= '<loc>' str_replace('&''&amp;'str_replace('&amp;''&'$this->url->link('product/category''path=' $new_path))) . '</loc>';
                
    $output .= '<lastmod>' substr(max($result['date_added'], $result['date_modified']), 010) . '</lastmod>';
                
    $output .= '<changefreq>weekly</changefreq>';
                
    $output .= '<priority>0.7</priority>';
                
    $output .= '</url>';

                
    $output .= $this->getCategories($result['category_id'], $new_path);
            }

            return 
    $output;
        }
    }
    ?>
    --- Добавлено, 6 янв 2016 ---
    Так смотрим:
    Гугл требует
    Заметки
    • Будьте уверены, чтобы указать пространство имен XHTML следующим образом:
      XMLNS: XHTML = "http://www.w3.org/1999/xhtml
    Т.е:
    <? XML версия = "1.0" кодирования = "UTF-8"?>
    <urlset XMLNS = "http://www.sitemaps.org/schemas/sitemap/0.9"
    XMLNS: XHTML = "http://www.w3.org/1999/xhtml">
    <URL>

    В нашем случаее имеем:
    $output = '<?xml version="1.0" encoding="UTF-8"?>';
    $output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

    Пробуем дописать
    $output .= '<urlset xmlns= "http://www.w3.org/1999/xhtmll">';
    --- Добавлено, 6 янв 2016 ---
    Альтернативу гугл просит вводить так:
    Код:
    <?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      xmlns:xhtml="http://www.w3.org/1999/xhtml">
      <url>
        <loc>http://www.example.com/english/</loc>
        <xhtml:link
                     rel="alternate"
                     hreflang="de"
                     href="http://www.example.com/deutsch/"
                     />
        <xhtml:link
                     rel="alternate"
                     hreflang="de-ch"
                     href="http://www.example.com/schweiz-deutsch/"
                     />
        <xhtml:link
                     rel="alternate"
                     hreflang="en"
                     href="http://www.example.com/english/"
                     />
      </url>
    
      <url>
        <loc>http://www.example.com/deutsch/</loc>
        <xhtml:link
                     rel="alternate"
                     hreflang="en"
                     href="http://www.example.com/english/"
                     />
         <xhtml:link
                     rel="alternate"
                     hreflang="de-ch"
                     href="http://www.example.com/schweiz-deutsch/"
                     />
         <xhtml:link
                     rel="alternate"
                     hreflang="de"
                     href="http://www.example.com/deutsch/"
                     />
      </url>
    
      <url>
        <loc>http://www.example.com/schweiz-deutsch/</loc>
         <xhtml:link
                     rel="alternate"
                     hreflang="de"
                     href="http://www.example.com/deutsch/"
                     />
         <xhtml:link
                     rel="alternate"
                     hreflang="en"
                     href="http://www.example.com/english/"
                     />
    <xhtml:link
                     rel="alternate"
                     hreflang="de-ch"
                     href="http://www.example.com/schweiz-deutsch/"
                     />
      </url>
    
    </urlset>
     
    Последнее редактирование: 7 янв 2016
  6. Dotrox

    Dotrox Команда форума

    Регистрация:
    27 ноя 2012
    Сообщения:
    3.198
    Симпатии:
    1.306
    Это называется гавнокод, но работать будет, хотя и никакого смысла так делать нет.

    А это вообще непонятно что. Помимо самого по себе неправильного SQL запроса, там вообще вся логика неправильная - языки в любом случае нужно обрабатывать циклом, но если есть желание гавнокодить, то можно массив $languages составить вручную, а не получить из базы.


    Если сделать так. до добавиться ещё один тег urlset, которого не должно быть.
    В примере Гугла ведь уже указано, как эта срока должна выглядеть полностью. Соответственно, нужно просто дописать xmlns:xhtml="http://www.w3.org/1999/xhtml" к тому тегу, который уже есть:
    PHP:
    $output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">';