You are currently viewing Opencart Google merchant

Opencart Google merchant

Merhabalar bugün sizlere Opencart Google merchant kurulumu ve Türkçe karakter sorunlarında bahsedeceğim.

Müşterimin özel olarak anlaşmış olduğu bir reklam ajansının özellikle istemiş olduğu google merhant ile reklamcılık doğrultusunda yapmam gereken bir xml servisi yazmaktı. Düşük bütçeli verdiğim hizmet açısından pek mümkün olmasa da kolları sıvayıp neler var opencart’ ta hazır pluginler var mı bakayım istedim, birçok plugin uçuyor yükseklerde :)). Biraz daha araştırma sonucunda google base özelliğini kurarak üstünde bir kaç değişiklik yaparak google merchant hizmetini sağlayacak xml servisi hazır olmuş oluyor.

Google Merchant Nedir ?

Bilmeyenler için kısaca google merchant nedir ?; Google Merchant Center, mağaza ve ürün verilerinizi Google’ a yüklemenize ve söz konusu verileri Google Alışveriş ve diğer Google hizmetlerine sunmanıza yardımcı olan bir araçtır. Google Merchant Center’ı kullanmaya başlama hakkında daha fazla bilgi edinin.

kısaca bir bilgi sonrasında devam edelim :).

Google Base Nasıl Aktif Edilir ?

1 .Opencart panelinize giriş yapın

2. Eklentiler Kısmında > Ürün Beslemelerine Gelin

3. Google Base kur butonuna basıp kurulumu yapın

4. Düzenle diyerek Durum kısmını aktif olarak seçin ve kayıt edin

5 . http://siteadresiniz/index.php?route=feed/google_base adresinden çıktıya artık ulaşabiliyorsunuz.

Şimdi bu aşamalardan sonra google base kurulup aktif edilmiş durumdadur. Şimdi gelelim türkçe karakter sorunu ve google merchant istediği çıktı kısmına. Bu kısımda aşağıda bulacaksanız.

Google Base Türkçe Karakter Sorunu ve Çözümü

1. ilk olarak ftp adresinize bağlanın

2. catalog > controller > feed > google_base.php dosyanızı açın ve orjinal halini yedekleyin

3. tüm içeriği silip aşağıdaki kodu aynı şekilde yapıştırın.

<?php 
class ControllerFeedGoogleBase extends Controller { 
public function index() { 
if ($this->config->get('google_base_status')) { 
            $output  = '<?xml version="1.0" encoding="UTF-8" ?>';
            $output .= '<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">';
            $output .= '<channel>';
            $output .= '<title>' . $this->config->get('config_name') . '</title>'; 
            $output .= '<description>' . html_entity_decode($this->replace_tr($this->config->get('config_meta_description'))) . '</description>';
            $output .= '<link>' . HTTP_SERVER . '</link>';
             
            $this->load->model('catalog/category');
             
            $this->load->model('catalog/product');
             
            $this->load->model('tool/image');
             
            $products = $this->model_catalog_product->getProducts();
             
            foreach ($products as $product) 
            {
                if ($product['description']) {
                    $output .= '<item>';
                    $output .= '<g:title>' . html_entity_decode($this->replace_tr($product['name'])) . '</g:title>';
                    $output .= '<g:link>' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . '</g:link>';
                    $output .= '<g:description>' . html_entity_decode($this->replace_tr($product['description'])) . '</g:description>';
                    $output .= '<g:brand>' . html_entity_decode($product['manufacturer'], ENT_QUOTES, 'UTF-8') . '</g:brand>';
                    $output .= '<g:condition>new</g:condition>';
                    $output .= '<g:id>' . $product['product_id'] . '</g:id>';
                     
                    if ($product['image']) {
                        $output .= '<g:image_link>' . $this->model_tool_image->resize($product['image'], 500, 500) . '</g:image_link>';
                    } else {
                        $output .= '<g:image_link>' . $this->model_tool_image->resize('no_image.jpg', 500, 500) . '</g:image_link>';
                    }
                     
                    $output .= '<g:mpn>' . $product['model'] . '</g:mpn>';
 
                    $currencies = array(
                        'USD', 
                        'EUR', 
                        'GBP'
                    );
 
                    if (in_array($this->currency->getCode(), $currencies)) {
                        $currency_code = $this->currency->getCode();
                        $currency_value = $this->currency->getValue();
                    } else {
                        $currency_code = 'USD';
                        $currency_value = $this->currency->getValue('USD');
                    }
                                     
                    if ((float)$product['special']) {
                        $output .= '<g:price>' .  $this->currency->format($this->tax->calculate($product['special'], $product['tax_class_id']), $currency_code, $currency_value, false) . '</g:price>';
                    } else {
                        $output .= '<g:price>' . $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id']), $currency_code, $currency_value, false) . '</g:price>';
                    }
                
                    $categories = $this->model_catalog_product->getCategories($product['product_id']);
                     
                    foreach ($categories as $category) {
                        $path = $this->getPath($category['category_id']);
                         
                        if ($path) {
                            $string = '';
                             
                            foreach (explode('_', $path) as $path_id) {
                                $category_info = $this->model_catalog_category->getCategory($path_id);
                                 
                                if ($category_info) {
                                    if (!$string) {
                                        $string = $category_info['name'];
                                    } else {
                                        $string .= ' &gt; ' . $category_info['name'];
                                    }
                                }
                            }
                          
                            $output .= '<g:product_type>' . html_entity_decode($this->replace_tr($string)) . '</g:product_type>';
                        }
                    }
                     
                    $output .= '<g:quantity>' . $product['quantity'] . '</g:quantity>';
                    $output .= '<g:upc>' . $product['upc'] . '</g:upc>'; 
                    $output .= '<g:weight>' . $this->weight->format($product['weight'], $product['weight_class_id']) . '</g:weight>';
                    $output .= '<g:availability>' . ($product['quantity'] ? 'in stock' : 'out of stock') . '</g:availability>';
                    $output .= '</item>';
                }
            }
             
            $output .= '</channel>'; 
            $output .= '</rss>';  
             
            $this->response->addHeader('Content-Type: application/rss+xml');
            $this->response->setOutput($output,0);
        }
    }
    public function replace_tr($text) {
        //die('geldi');
        $text = trim($text);
        $search = array('Ç','ç','Ğ','ğ','ı','İ','Ö','ö','Ş','ş','Ü','ü');
        $replace = array('C','c','G','g','i','I','O','o','S','s','U','u');
        $new_text = str_replace($search,$replace,$text);
        return $new_text;
    } 
    /*
    public function index() {
        if ($this->config->get('google_base_status')) { 
            $output  = '<?xml version="1.0" encoding="UTF-8" ?>';
            $output .= '<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">';
            $output .= '<channel>';
            $output .= '<title>' . $this->config->get('config_name') . '</title>'; 
            $output .= '<description>' . $this->config->get('config_meta_description') . '</description>';
            $output .= '<link>' . HTTP_SERVER . '</link>';
             
            $this->load->model('catalog/category');
             
            $this->load->model('catalog/product');
             
            $this->load->model('tool/image');
             
            $products = $this->model_catalog_product->getProducts();
             
            foreach ($products as $product) {
                if ($product['description']) {
                    $output .= '<item>';
                    $output .= '<title>' . $product['name'] . '</title>';
                    $output .= '<link>' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . '</link>';
                    $output .= '<description>' . $product['description'] . '</description>';
                    $output .= '<g:brand>' . html_entity_decode($product['manufacturer'], ENT_QUOTES, 'UTF-8') . '</g:brand>';
                    $output .= '<g:condition>new</g:condition>';
                    $output .= '<g:id>' . $product['product_id'] . '</g:id>';
                     
                    if ($product['image']) {
                        $output .= '<g:image_link>' . $this->model_tool_image->resize($product['image'], 500, 500) . '</g:image_link>';
                    } else {
                        $output .= '<g:image_link>' . $this->model_tool_image->resize('no_image.jpg', 500, 500) . '</g:image_link>';
                    }
                     
                    $output .= '<g:mpn>' . $product['model'] . '</g:mpn>';
 
                    $currencies = array(
                        'USD', 
                        'EUR', 
                        'GBP'
                    );
 
                    if (in_array($this->currency->getCode(), $currencies)) {
                        $currency_code = $this->currency->getCode();
                        $currency_value = $this->currency->getValue();
                    } else {
                        $currency_code = 'USD';
                        $currency_value = $this->currency->getValue('USD');
                    }
                                     
                    if ((float)$product['special']) {
                        $output .= '<g:price>' .  $this->currency->format($this->tax->calculate($product['special'], $product['tax_class_id']), $currency_code, $currency_value, false) . '</g:price>';
                    } else {
                        $output .= '<g:price>' . $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id']), $currency_code, $currency_value, false) . '</g:price>';
                    }
                
                    $categories = $this->model_catalog_product->getCategories($product['product_id']);
                     
                    foreach ($categories as $category) {
                        $path = $this->getPath($category['category_id']);
                         
                        if ($path) {
                            $string = '';
                             
                            foreach (explode('_', $path) as $path_id) {
                                $category_info = $this->model_catalog_category->getCategory($path_id);
                                 
                                if ($category_info) {
                                    if (!$string) {
                                        $string = $category_info['name'];
                                    } else {
                                        $string .= ' &gt; ' . $category_info['name'];
                                    }
                                }
                            }
                          
                            $output .= '<g:product_type>' . $string . '</g:product_type>';
                        }
                    }
                     
                    $output .= '<g:quantity>' . $product['quantity'] . '</g:quantity>';
                    $output .= '<g:upc>' . $product['upc'] . '</g:upc>'; 
                    $output .= '<g:weight>' . $this->weight->format($product['weight'], $product['weight_class_id']) . '</g:weight>';
                    $output .= '<g:availability>' . ($product['quantity'] ? 'in stock' : 'out of stock') . '</g:availability>';
                    $output .= '</item>';
                }
            }
             
            $output .= '</channel>'; 
            $output .= '</rss>';  
             
            $this->response->addHeader('Content-Type: application/rss+xml');
            $this->response->setOutput($output);
        }
    }
    */
     
    protected function getPath($parent_id, $current_path = '') {
        $category_info = $this->model_catalog_category->getCategory($parent_id);
     
        if ($category_info) {
            if (!$current_path) {
                $new_path = $category_info['category_id'];
            } else {
                $new_path = $category_info['category_id'] . '_' . $current_path;
            }   
         
            $path = $this->getPath($category_info['parent_id'], $new_path);
                     
            if ($path) {
                return $path;
            } else {
                return $new_path;
            }
        }
    }       
}
?>

Yukarıdaki işlemleri uygulamanızın ardından google merchant xml servisiniz kusursuz bir şekilde çalışır duruma gelecektir.

Google Merchant XML Çıktısı

<?xml version="1.0"?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
<channel>
<title>Site Adı</title>
<link>Site Adresi (https://www.domain.com)</link>
<description>Tanımlama (ÖRN: <![CDATA[Monte Sehpa kişiye özel ve uygun fiyatlı sehpaları ile Türkiye'nin ilk sehpa üreticisi.]]>)</description>
 
 
<!--Çoğaltılacak Öğe-->
<item>
<g:id> Ürün ID (ÖRN:<![CDATA[1]]>)</g:id>
<g:title> Ürün Adı (ÖRN:<![CDATA[Arte Orta Sehpa Dikdörtgen]]>)</g:title>
<g:description> Ürün Tanımlaması (ÖRN:<![CDATA[Arte Orta Sehpa Beyaz MonteSehpa]]>)</g:description>
<g:link> Ürün URL (ÖRN:<![CDATA[https://montesehpa.net/Urunlerimiz/Orta Sehpa/1/Arte Orta Sehpa Dikdörtgen]]>)</g:link>
<g:image_link> Ürün Resim URL (ÖRN:<![CDATA[https://montesehpa.net/Admin/Pictures/2cb40462-b6b5-411a-a83a-0f8e3eb71330arte-ortasehpa.jpg]]>)</g:image_link>
<g:condition>yeni</g:condition>
<g:availability>stokta</g:availability>
<g:price>ÜCRET (ÖRN:<![CDATA[700,00 TL]]>)</g:price>
<g:gtin>BARKOD (Eğer Yoksa Boş Bırakılabilir)</g:gtin>
<g:brand>MARKA (ÖRN:<![CDATA[Monte Sehpa]]>)</g:brand>
<g:google_product_category> Ürün Kategori (ÖRN:<![CDATA[Sehpa > Orta Sehpa]]>)</g:google_product_category>
<g:product_type>Ürün Tipi (ÖRN:Sehpa)</g:product_type>
</item>
<!-- Çoğaltılacak Öğe Sonu -->
 
 
</channel>
</rss>

Geliştirme kısmında teklifleriniz olursa paylaşırsanız sevinirim.
iyi kodlamalar.

kurtitasarim

‘’İrade ve yargıları aşan güçlü bir coşku, ihtiras" diye tanımlanır tutku. Yaptığın işi sevmek yerine, sevdiğin işi yap mottosu da benim tutku tanımım. Kod yazmak bir yana, o kodun sistem üzerindeki hareketlerini, farklı cihazlar ile etkileşimini, o noktalarda oluşan sıkıntıları görmek, çözmek ve bunu yaparken diğer kişilere yol göstermek işimin en zevkli yanı. Bu sebeple önce tutku ile yapılan iş, sonra maddiyat..

This Post Has 6 Comments

  1. Burak Huy

    Merhaba, google_base.php dosyasını sizin kodlarla değiştirdim. Sayfa boş açılmaya başladı. Bu kodlar hangi sürüm için geçerli. Benim sitenin sürümü: 2.3.0.2
    Teşekkürler

    1. kurtitasarim

      Sistem ayarlarından hata gösterimini aktif ederek çıktıyı paylaşırsanız sevinirim.

    1. kurtitasarim

      Opencart v2.0 için geçerlidir.

  2. ersin

    Merhabalar. Google base ile tüm resimleri nasıl gönderebiliriz acaba? Eklentiyi kurup çalıştırdık fakat sadece ana resmi gönderiyor. teşekkürler.

    1. kurtitasarim

      Merhaba, son güncel dökümanı ve google servislerini okumadım. Yoğunluğumdan sonra tekrar inceleyip bu konuda bilgi paylaşacağım.

Bir yanıt yazın