Plugin Directory

Changeset 3429012


Ignore:
Timestamp:
12/29/2025 11:09:45 AM (3 months ago)
Author:
brksoft
Message:

2.0.0 version upload

Location:
trendyol-entegrasyonu-brksoft
Files:
5 added
5 edited

Legend:

Unmodified
Added
Removed
  • trendyol-entegrasyonu-brksoft/tags/1.0.1/readme.txt

    r3237254 r3429012  
    11=== Trendyol Entegrasyonu - Brksoft ===
    22Contributors: brksoft
    3 Donate link: https://brksoft.com/
    4 Tags: Trendyol, WooCommerce, Trendyol entegrasyon
    5 Requires at least: 5.0
     3Donate link: https://brksoft.com/tr/
     4Tags: trendyol, woocommerce, trendyol entegrasyon, e-ticaret, entegrasyon
     5Requires at least: 5.8
    66Tested up to: 6.7
    77Requires PHP: 7.4
    8 Stable tag: 1.0.1
     8Stable tag: 2.0.0
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1111
    12 WordPress ve WooCommerce için Trendyol Entegrasyonu. Sipariş sonrası stok güncelleme, çift yönlü entegrasyon ve otomatik senkronizasyon sağlayın.
     12WooCommerce mağazanız için Trendyol entegrasyonu. Sipariş geldiğinde otomatik stok senkronizasyonu.
    1313
    1414== Description ==
    1515
    16 https://www.youtube.com/watch?v=qPeWXCz9UjA
     16**Trendyol Entegrasyonu**, WooCommerce mağazanızı Trendyol hesabınıza entegre ederek stok yönetimini otomatikleştirir.
    1717
    18 **BRK Trendyol Entegrasyonu**, WooCommerce mağazanızı Trendyol hesabınıza entegre ederek e-ticaret işinizi bir üst seviyeye taşır. Temel özellikleri şunlardır:
     18= Ücretsiz Sürüm Özellikleri =
    1919
    20 - Trendyol siparişlerini alarak WooCommerce stoklarınızı otomatik günceller.
    21 - WooCommerce'den gelen siparişlerle Trendyol stoklarını eşitler.
    22 - Trendyol ürün fiyatlarını ve stok miktarlarını API aracılığıyla senkronize eder.
    23 - Kolay kurulum ve kullanım için sade bir ayar paneli sunar.
     20* ✅ WooCommerce sipariş geldiğinde Trendyol stoğunu otomatik güncelleme
     21* ✅ Trendyol webhook desteği ile çift yönlü stok senkronizasyonu
     22* ✅ API bağlantı testi
     23* ✅ Basit ve kullanımı kolay arayüz
     24* ✅ WooCommerce HPOS uyumlu
    2425
    25 Eklenti, küçük ve orta ölçekli e-ticaret işletmeleri için özel olarak tasarlanmıştır.
     26= Ücretsiz Sürüm Kısıtlamaları =
    2627
    27 Premium Sürümü Satın Almak İçin: [Trendyol Entegrasyonu Premium](https://tr.brksoft.com/urun/trenyol-entegrasyonu-premium/ "trendyol premium")
     28* ❌ Sadece **basit ürünler** desteklenir (varyasyonlu ürünler hariç)
     29* ❌ Fiyat senkronizasyonu yok
     30* ❌ Trendyol'dan ürün çekme yok
     31* ❌ Trendyol'a ürün yükleme yok
     32* ❌ Sipariş aktarımı yok
     33
     34= Premium Sürüm Özellikleri =
     35
     36Tüm ücretsiz özelliklere ek olarak:
     37
     38* ⭐ **Varyasyonlu ürün desteği** (beden, renk vb.)
     39* ⭐ **Fiyat senkronizasyonu** (komisyon oranı ile)
     40* ⭐ **Trendyol'dan ürün çekme** ve WooCommerce'e aktarma
     41* ⭐ **WooCommerce'den Trendyol'a ürün yükleme**
     42* ⭐ **Sipariş aktarımı** (Trendyol → WooCommerce)
     43* ⭐ **Kategori eşleştirme** sistemi
     44* ⭐ **Attribute eşleştirme**
     45* ⭐ **Excel import** (API alternatifi)
     46* ⭐ **Kapsamlı loglama** ve debug araçları
     47* ⭐ **Öncelikli destek**
     48
     49[Premium Sürümü İncele](https://brksoft.com/tr/urun/trenyol-entegrasyonu-premium/)
     50
     51= Nasıl Çalışır? =
     52
     531. Trendyol Satıcı Paneli'nden API bilgilerinizi alın
     542. Eklenti ayarlarına API Key, API Secret ve Supplier ID girin
     553. WooCommerce ürünlerinizin SKU'larının Trendyol barcode'ları ile aynı olduğundan emin olun
     564. Sipariş geldiğinde stoklar otomatik senkronize edilir
     57
     58= Webhook Kurulumu =
     59
     60Trendyol'dan gelen stok güncellemelerini almak için:
     61
     621. Trendyol Satıcı Paneli → Entegrasyon → Webhook Ayarları
     632. Webhook URL olarak şunu girin: `https://siteniz.com/wp-json/brkti/v1/webhook`
     643. Artık Trendyol'dan gelen güncellemeler WooCommerce'e yansıyacak
    2865
    2966== Installation ==
    3067
    31 1. Eklentiyi WordPress panosundan yükleyin veya dosyayı `/wp-content/plugins/` dizinine yükleyin.
    32 2. Eklentiyi etkinleştirin.
    33 3. Ayarlar > Trendyol Entegrasyonu menüsünden API bilgilerinizi girin:
    34    - **API Key**
    35    - **API Secret**
    36    - **Satıcı ID**
    37 4. WooCommerce ile Trendyol entegrasyonu artık hazır!
     681. Eklentiyi WordPress panosundan yükleyin veya `/wp-content/plugins/` dizinine yükleyin
     692. Eklentiler sayfasından "Trendyol Entegrasyonu" eklentisini etkinleştirin
     703. Sol menüden "Trendyol" sayfasına gidin
     714. API bilgilerinizi girin:
     72   - **Supplier ID**: Trendyol satıcı numaranız
     73   - **API Key**: Trendyol API anahtarınız
     74   - **API Secret**: Trendyol API secret'ınız
     755. "API Bağlantısını Test Et" butonuna tıklayarak bağlantıyı doğrulayın
     766. Ayarları kaydedin
    3877
    3978== Frequently Asked Questions ==
    4079
    41 = Trendyol API bilgilerini nasıl alabilirim? =
    42 Trendyol satıcı paneline giriş yaparak API bilgileriniz için "Ayarlar > API Bilgileri" sekmesini kontrol edin.
     80= Trendyol API bilgilerini nereden alabilirim? =
    4381
    44 = Ücretsiz sürüm hangi özellikleri sunuyor? =
    45 Ücretsiz sürümde sadece sipariş bazlı stok güncellemeleri yapılır. Çift yönlü entegrasyon gibi gelişmiş özellikler için Pro sürümü kullanabilirsiniz.
     82Trendyol Satıcı Paneli → Entegrasyon → API Bilgileri bölümünden alabilirsiniz.
    4683
    47 = Eklenti hangi durumlarda stok güncellemesi yapar? =
    48 Sipariş tamamlandığında veya manuel güncelleme yapıldığında Trendyol ile stoklar senkronize edilir.
     84= Varyasyonlu ürünler destekleniyor mu? =
     85
     86Ücretsiz sürümde sadece basit ürünler desteklenir. Varyasyonlu ürünler için Premium sürüm gereklidir.
     87
     88= Stok güncellemesi ne zaman yapılır? =
     89
     90WooCommerce'den sipariş geldiğinde (ödeme tamamlandığında veya sipariş işleme alındığında) otomatik olarak Trendyol'a stok güncellemesi gönderilir.
     91
     92= SKU eşleştirmesi nasıl çalışır? =
     93
     94WooCommerce ürününüzün SKU'su ile Trendyol'daki ürünün barcode'u aynı olmalıdır. Sistem bu eşleşmeyi kullanarak stok güncellemesi yapar.
     95
     96= Webhook ne işe yarar? =
     97
     98Webhook sayesinde Trendyol'dan gelen siparişlerde de WooCommerce stokları otomatik güncellenir (çift yönlü senkronizasyon).
     99
     100= Premium sürümde neler var? =
     101
     102Premium sürümde varyasyonlu ürün desteği, fiyat senkronizasyonu, Trendyol'dan ürün çekme, ürün yükleme, sipariş aktarımı, kategori eşleştirme ve daha birçok özellik bulunur.
    49103
    50104== Screenshots ==
    51105
    52 1. **Eklenti Ayarları** - API bilgilerinizi girebileceğiniz Trendyol entegrasyon ayarları.
     1061. Eklenti ana ayarlar sayfası
     1072. API bağlantı testi
    53108
    54109== Changelog ==
    55110
     111= 2.0.0 =
     112* Tamamen yeniden yazıldı
     113* Modern ve kullanıcı dostu arayüz
     114* API bağlantı testi eklendi
     115* Durum göstergeleri eklendi
     116* WooCommerce HPOS uyumluluğu
     117* Geliştirilmiş güvenlik (nonce kontrolü)
     118* Senkronizasyon istatistikleri
     119* Premium sürüm bilgilendirmesi
     120
    56121= 1.0.1 =
    57 * İlk sürüm.
    58 * Sipariş bazlı stok güncellemesi.
    59 * Trendyol ile WooCommerce entegrasyonu.
     122* İlk sürüm
     123* Sipariş bazlı stok güncellemesi
     124* Temel Trendyol entegrasyonu
    60125
    61126== Upgrade Notice ==
    62127
    63 = 1.0.1 =
    64 İlk sürüm: Temel özelliklerle Trendyol entegrasyonunu sağlayın.
     128= 2.0.0 =
     129Yeni arayüz, bağlantı testi ve geliştirilmiş özellikler. Güncellemeniz önerilir.
    65130
    66 == External services ==
     131== External Services ==
    67132
    68 This plugin connects to the Trendyol API to manage product stock and prices in WooCommerce.
     133Bu eklenti aşağıdaki harici servislerle iletişim kurar:
    69134
    70 - **Service:** Trendyol API
    71 - **Purpose:** Updates stock and price information for WooCommerce products.
    72 - **Data Sent:** Seller ID, API Key, API Secret, and product details are sent during stock and price updates.
    73 - **Terms and Privacy Policy:** [Trendyol Terms of Use](https://developers.trendyol.com/int/docs/intro) | [Trendyol Privacy Policy](https://www.trendyol.com/kisisel_verilerin_korunmasi)
     135**Trendyol API**
     136
     137* Amaç: Ürün stok bilgilerini senkronize etmek
     138* Gönderilen veriler: Satıcı ID, API kimlik bilgileri, ürün SKU/barcode ve stok miktarı
     139* Ne zaman: WooCommerce siparişi tamamlandığında
     140* Kullanım koşulları: [Trendyol Geliştirici Portalı](https://developers.trendyol.com/)
     141* Gizlilik politikası: [Trendyol Gizlilik Politikası](https://www.trendyol.com/kisisel_verilerin_korunmasi)
    74142
    75143== Tags ==
    76 Trendyol entegrasyonu, WooCommerce Trendyol, Stok senkronizasyonu, Otomatik güncelleme
     144trendyol, woocommerce, stok senkronizasyonu, e-ticaret, entegrasyon, marketplace, pazaryeri
  • trendyol-entegrasyonu-brksoft/tags/1.0.1/trendyol-entegrasyonu-brksoft.php

    r3226778 r3429012  
    22/**
    33 * Plugin Name: Trendyol Entegrasyonu - Brksoft
    4  * Description: WooCommerce mağazaları için Trendyol entegrasyonu.
    5  * Version: 1.0.1
     4 * Description: WooCommerce mağazaları için Trendyol entegrasyonu. Sipariş geldiğinde otomatik stok senkronizasyonu.
     5 * Version: 2.0.0
    66 * Author: Brksoft
    77 * Author URI: https://brksoft.com/
     
    99 * Domain Path: /languages
    1010 * Requires Plugins: woocommerce
    11  * WC requires at least: 4.0
     11 * Requires at least: 5.8
     12 * Tested up to: 6.7
     13 * Requires PHP: 7.4
     14 * WC requires at least: 5.0
    1215 * WC tested up to: 9.4
    1316 * License: GPL-2.0+
     
    1720defined('ABSPATH') || exit;
    1821
    19 // WooCommerce compatibility
    20 add_action('before_woocommerce_init', function () {
     22// Sürüm
     23define('BRKTI_FREE_VERSION', '2.0.0');
     24
     25/**
     26 * WooCommerce HPOS uyumluluğu
     27 */
     28add_action('before_woocommerce_init', function() {
    2129    if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
    2230        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
     
    2432});
    2533
    26 // Admin menu for settings
    27 function brkti_menu() {
     34/**
     35 * Admin menü
     36 */
     37add_action('admin_menu', 'brkti_free_admin_menu');
     38function brkti_free_admin_menu() {
    2839    add_menu_page(
    2940        'Trendyol Entegrasyonu',
    30         __('Trendyol Entegrasyonu', 'trendyol-entegrasyonu-brksoft'),
    31         'edit_posts',
     41        'Trendyol',
     42        'manage_woocommerce',
    3243        'brkti_settings',
    33         'brkti_menu_callback',
    34         'dashicons-update'
     44        'brkti_free_settings_page',
     45        'dashicons-update',
     46        56
    3547    );
    3648}
    37 add_action('admin_menu', 'brkti_menu');
    38 
    39 // Admin menu callback
    40 function brkti_menu_callback() {
     49
     50/**
     51 * Ayarları kaydet
     52 */
     53add_action('admin_init', 'brkti_free_register_settings');
     54function brkti_free_register_settings() {
     55    register_setting('brkti_free_options', 'brkti_supplier_id', ['sanitize_callback' => 'sanitize_text_field']);
     56    register_setting('brkti_free_options', 'brkti_api_key', ['sanitize_callback' => 'sanitize_text_field']);
     57    register_setting('brkti_free_options', 'brkti_api_secret', ['sanitize_callback' => 'sanitize_text_field']);
     58    register_setting('brkti_free_options', 'brkti_auto_sync', ['sanitize_callback' => 'absint']);
     59}
     60
     61/**
     62 * Ayarlar sayfası
     63 */
     64function brkti_free_settings_page() {
     65    $supplier_id = get_option('brkti_supplier_id', '');
     66    $api_key = get_option('brkti_api_key', '');
     67    $api_secret = get_option('brkti_api_secret', '');
     68    $auto_sync = get_option('brkti_auto_sync', '1');
     69    $last_sync = get_option('brkti_last_sync', '');
     70    $sync_count = get_option('brkti_sync_count_' . date('Y-m-d'), 0);
     71   
     72    // Ayarlar kaydedildi mi?
     73    $saved = isset($_GET['settings-updated']) && $_GET['settings-updated'] === 'true';
    4174    ?>
    42     <h1><?php echo esc_html__('Trendyol Entegrasyonu', 'trendyol-entegrasyonu-brksoft'); ?></h1>
    43     <form action="options.php" method="post">
    44         <?php
    45         settings_fields('brkti_menu_options');
    46         $apikey_value = get_option('brkti_apikey_input', '');
    47         $sellerid_value = get_option('brkti_sellerid_input', '');
    48         $apisecret_value = get_option('brkti_apisecret_input', '');
    49 
    50         ?>
    51 
    52         <h3><?php echo esc_html__( 'Nasil Çalışır?', 'trendyol-entegrasyonu-brksoft' ); ?></h3>
    53         <p><?php echo esc_html__( 'İlk olarak trendyol satıcı panelinizden entegrasyon bilgilerinizi alıp aşşağıdaki yere yapıştırıp kaydedin.', 'trendyol-entegrasyonu-brksoft' ); ?></p>
    54         <p><?php echo esc_html__( 'Bunu yapmanız ardından artık her yeni sipariş geldiğinde stok kodu aynı olan ürünleri sistem otomatik olarak bulucak ve hem WooCommerce sitenizde hem Trendyol hesabınızda çift taraflı olarak güncelleyecektir.', 'trendyol-entegrasyonu-brksoft' ); ?></p>
    55         <h3><?php echo esc_html__( 'Eklentimiz ücretsiz sürümde sadece basit ürünler için çalışmaktadır ve sadece stok senkronizasyonu sağlar.', 'trendyol-entegrasyonu-brksoft' ); ?></h3>
    56         <h3><?php echo esc_html__( '• Varyasyonlu ürünler için senkronizasyon yapmak', 'trendyol-entegrasyonu-brksoft' ); ?></h3>
    57         <h3><?php echo esc_html__( '• Toplu fiyat senkronizasyonları yapmak ', 'trendyol-entegrasyonu-brksoft' ); ?></h3>
    58         <h3><?php echo esc_html__( '• Stok güncellendiğinde stokları eşitlemek', 'trendyol-entegrasyonu-brksoft' ); ?></h3>
    59         <h3><?php echo esc_html__( 'gibi çeşitli özelliklere de erişmek için eklentimizin ücretli sürümünü sitemizden satın alabilirsiniz.', 'trendyol-entegrasyonu-brksoft' ); ?></h3>
    60 
    61         <a href="https://tr.brksoft.com/urun/trenyol-entegrasyonu-premium/" target="_blank" style="font-size: 17px;" ><?php echo esc_html__( 'Ücretli Sürümü Satın Al', 'trendyol-entegrasyonu-brksoft' ); ?></a>
    62 
    63         <br><br>
    64 
    65         <label for="brkti_apikey_input">API Key:</label>
    66         <input type="text" id="brkti_apikey_input" name="brkti_apikey_input" value="<?php echo esc_html( $apikey_value );  ?>">
    67         <br><br>
    68         <label for="brkti_sellerid_input">Seller ID:</label>
    69         <input type="text" id="brkti_sellerid_input" name="brkti_sellerid_input" value="<?php echo esc_html( $sellerid_value ) ; ?>">
    70         <br><br>
    71         <label for="brkti_apisecret_input">API Secret:</label>
    72         <input type="text" id="brkti_apisecret_input" name="brkti_apisecret_input" value="<?php echo esc_html( $apisecret_value ) ; ?>">
    73         <?php submit_button(); ?>
    74     </form>
     75    <div class="wrap">
     76        <h1>🟠 Trendyol Entegrasyonu</h1>
     77       
     78        <style>
     79            .brkti-wrap { max-width: 800px; }
     80            .brkti-card { background: #fff; border: 1px solid #ddd; border-radius: 8px; padding: 20px; margin: 20px 0; }
     81            .brkti-card h2 { margin-top: 0; padding-bottom: 10px; border-bottom: 1px solid #eee; }
     82            .brkti-premium-card { background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%); color: #fff; }
     83            .brkti-premium-card h2 { color: #fff; border-bottom-color: rgba(255,255,255,0.3); }
     84            .brkti-premium-card a { color: #fff; font-weight: bold; }
     85            .brkti-form-table th { width: 150px; padding: 15px 10px 15px 0; }
     86            .brkti-form-table td { padding: 10px 0; }
     87            .brkti-form-table input[type="text"] { width: 100%; max-width: 400px; padding: 8px 12px; }
     88            .brkti-status { display: inline-flex; align-items: center; gap: 8px; padding: 8px 15px; border-radius: 5px; margin: 10px 0; }
     89            .brkti-status.success { background: #d4edda; color: #155724; }
     90            .brkti-status.warning { background: #fff3cd; color: #856404; }
     91            .brkti-status.error { background: #f8d7da; color: #721c24; }
     92            .brkti-features { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 15px 0; }
     93            .brkti-features li { display: flex; align-items: center; gap: 8px; }
     94            .brkti-test-result { margin-top: 15px; padding: 15px; border-radius: 5px; display: none; }
     95            .brkti-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin: 15px 0; }
     96            .brkti-stat { text-align: center; padding: 15px; background: #f8f9fa; border-radius: 5px; }
     97            .brkti-stat .number { font-size: 24px; font-weight: bold; color: #0073aa; }
     98            .brkti-stat .label { font-size: 12px; color: #666; }
     99        </style>
     100       
     101        <div class="brkti-wrap">
     102           
     103            <?php if ($saved): ?>
     104            <div class="notice notice-success is-dismissible">
     105                <p><strong>Ayarlar kaydedildi!</strong></p>
     106            </div>
     107            <?php endif; ?>
     108           
     109            <!-- Premium Banner -->
     110            <div class="brkti-card brkti-premium-card">
     111                <h2>⭐ Premium Sürüme Yükseltin</h2>
     112                <p>Ücretsiz sürümde sadece <strong>basit ürünler</strong> için sipariş bazlı stok senkronizasyonu yapılır.</p>
     113               
     114                <ul class="brkti-features" style="list-style:none; padding:0; margin:15px 0;">
     115                    <li>✖️ Varyasyonlu ürün desteği</li>
     116                    <li>✖️ Fiyat senkronizasyonu</li>
     117                    <li>✖️ Trendyol'dan ürün çekme</li>
     118                    <li>✖️ Trendyol'a ürün yükleme</li>
     119                    <li>✖️ Sipariş aktarımı</li>
     120                    <li>✖️ Kategori eşleştirme</li>
     121                    <li>✖️ Webhook desteği</li>
     122                    <li>✖️ Excel import</li>
     123                </ul>
     124               
     125                <p>
     126                    <a href="https://brksoft.com/tr/urun/trenyol-entegrasyonu-premium/" target="_blank" style="background:#fff; color:#f7931e; padding:12px 25px; border-radius:5px; text-decoration:none; display:inline-block; font-size:16px;">
     127                        🚀 Premium Sürümü İncele
     128                    </a>
     129                </p>
     130            </div>
     131           
     132            <!-- API Ayarları -->
     133            <div class="brkti-card">
     134                <h2>🔗 API Ayarları</h2>
     135                <p>Trendyol Satıcı Paneli → Entegrasyon → API Bilgileri bölümünden bilgilerinizi alabilirsiniz.</p>
     136               
     137                <form method="post" action="options.php">
     138                    <?php settings_fields('brkti_free_options'); ?>
     139                   
     140                    <table class="form-table brkti-form-table">
     141                        <tr>
     142                            <th><label for="brkti_supplier_id">Satıcı ID (Supplier ID)</label></th>
     143                            <td>
     144                                <input type="text" id="brkti_supplier_id" name="brkti_supplier_id" value="<?php echo esc_attr($supplier_id); ?>" placeholder="123456">
     145                            </td>
     146                        </tr>
     147                        <tr>
     148                            <th><label for="brkti_api_key">API Key</label></th>
     149                            <td>
     150                                <input type="text" id="brkti_api_key" name="brkti_api_key" value="<?php echo esc_attr($api_key); ?>" placeholder="xxxxxxxx">
     151                            </td>
     152                        </tr>
     153                        <tr>
     154                            <th><label for="brkti_api_secret">API Secret</label></th>
     155                            <td>
     156                                <input type="text" id="brkti_api_secret" name="brkti_api_secret" value="<?php echo esc_attr($api_secret); ?>" placeholder="xxxxxxxx">
     157                            </td>
     158                        </tr>
     159                        <tr>
     160                            <th><label for="brkti_auto_sync">Otomatik Senkronizasyon</label></th>
     161                            <td>
     162                                <label>
     163                                    <input type="checkbox" id="brkti_auto_sync" name="brkti_auto_sync" value="1" <?php checked($auto_sync, '1'); ?>>
     164                                    WooCommerce sipariş geldiğinde Trendyol stoğunu otomatik güncelle
     165                                </label>
     166                                <p class="description">Sadece basit ürünler için çalışır. Varyasyonlu ürünler için Premium sürüm gereklidir.</p>
     167                            </td>
     168                        </tr>
     169                    </table>
     170                   
     171                    <?php submit_button('Ayarları Kaydet'); ?>
     172                </form>
     173               
     174                <!-- Bağlantı Testi -->
     175                <hr style="margin: 20px 0;">
     176                <h3>🔌 Bağlantı Testi</h3>
     177                <button type="button" class="button button-secondary" id="brkti_test_connection">API Bağlantısını Test Et</button>
     178                <div id="brkti_test_result" class="brkti-test-result"></div>
     179            </div>
     180           
     181            <!-- Durum -->
     182            <div class="brkti-card">
     183                <h2>📊 Durum</h2>
     184               
     185                <?php
     186                $has_credentials = !empty($supplier_id) && !empty($api_key) && !empty($api_secret);
     187                ?>
     188               
     189                <?php if ($has_credentials): ?>
     190                    <div class="brkti-status success">
     191                        ✅ API bilgileri ayarlandı
     192                    </div>
     193                <?php else: ?>
     194                    <div class="brkti-status warning">
     195                        ⚠️ API bilgilerini girin
     196                    </div>
     197                <?php endif; ?>
     198               
     199                <?php if ($auto_sync): ?>
     200                    <div class="brkti-status success">
     201                        ✅ Otomatik senkronizasyon aktif
     202                    </div>
     203                <?php else: ?>
     204                    <div class="brkti-status warning">
     205                        ⚠️ Otomatik senkronizasyon kapalı
     206                    </div>
     207                <?php endif; ?>
     208               
     209                <div class="brkti-stats">
     210                    <div class="brkti-stat">
     211                        <div class="number"><?php echo intval($sync_count); ?></div>
     212                        <div class="label">Bugün Senkronize</div>
     213                    </div>
     214                    <div class="brkti-stat">
     215                        <div class="number"><?php echo $last_sync ? date('H:i', strtotime($last_sync)) : '-'; ?></div>
     216                        <div class="label">Son Senkronizasyon</div>
     217                    </div>
     218                    <div class="brkti-stat">
     219                        <div class="number"><?php
     220                            global $wpdb;
     221                            $simple_count = $wpdb->get_var("
     222                                SELECT COUNT(*) FROM {$wpdb->posts} p
     223                                INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id
     224                                WHERE p.post_type = 'product'
     225                                AND p.post_status = 'publish'
     226                                AND pm.meta_key = '_sku'
     227                                AND pm.meta_value != ''
     228                            ");
     229                            echo intval($simple_count);
     230                        ?></div>
     231                        <div class="label">SKU'lu Ürün</div>
     232                    </div>
     233                </div>
     234            </div>
     235           
     236            <!-- Nasıl Çalışır -->
     237            <div class="brkti-card">
     238                <h2>❓ Nasıl Çalışır?</h2>
     239                <ol>
     240                    <li><strong>API Bilgilerini Girin:</strong> Trendyol Satıcı Paneli'nden Supplier ID, API Key ve API Secret bilgilerinizi alın.</li>
     241                    <li><strong>SKU Eşleştirmesi:</strong> WooCommerce ürünlerinizin SKU'ları ile Trendyol'daki barcode'ların aynı olduğundan emin olun.</li>
     242                    <li><strong>Otomatik Güncelleme:</strong> WooCommerce'den sipariş geldiğinde, aynı SKU'ya sahip Trendyol ürününün stoğu otomatik güncellenir.</li>
     243                </ol>
     244               
     245                <p><strong>⚠️ Not:</strong> Ücretsiz sürümde sadece <u>basit ürünler</u> desteklenir. Varyasyonlu ürünler için Premium sürüm gereklidir.</p>
     246            </div>
     247           
     248            <!-- Destek -->
     249            <div class="brkti-card">
     250                <h2>💬 Destek</h2>
     251                <p>Sorularınız için: <a href="https://brksoft.com/tr/iletisim/" target="_blank">brksoft.com/tr/iletisim</a></p>
     252            </div>
     253           
     254        </div>
     255       
     256        <script>
     257        jQuery(document).ready(function($) {
     258            $('#brkti_test_connection').on('click', function() {
     259                var btn = $(this);
     260                var result = $('#brkti_test_result');
     261               
     262                btn.prop('disabled', true).text('Test ediliyor...');
     263                result.hide();
     264               
     265                $.post(ajaxurl, {
     266                    action: 'brkti_free_test_connection',
     267                    nonce: '<?php echo wp_create_nonce('brkti_free_nonce'); ?>'
     268                }, function(response) {
     269                    btn.prop('disabled', false).text('API Bağlantısını Test Et');
     270                   
     271                    if (response.success) {
     272                        result.css('background', '#d4edda').css('color', '#155724');
     273                        result.html('✅ ' + response.data.message);
     274                    } else {
     275                        result.css('background', '#f8d7da').css('color', '#721c24');
     276                        result.html('❌ ' + response.data.message);
     277                    }
     278                    result.show();
     279                }).fail(function() {
     280                    btn.prop('disabled', false).text('API Bağlantısını Test Et');
     281                    result.css('background', '#f8d7da').css('color', '#721c24');
     282                    result.html('❌ AJAX hatası');
     283                    result.show();
     284                });
     285            });
     286        });
     287        </script>
     288    </div>
    75289    <?php
    76290}
    77291
    78 // Register settings
    79 function brkti_save_menu() {
    80     register_setting(
    81         'brkti_menu_options',
    82         'brkti_sellerid_input',
    83         array(
    84             'type'              => 'string',
    85             'sanitize_callback' => 'sanitize_text_field',
    86         )
    87     );
    88     register_setting(
    89         'brkti_menu_options',
    90         'brkti_apikey_input',
    91         array(
    92             'type'              => 'string',
    93             'sanitize_callback' => 'sanitize_text_field',
    94         )
    95     );
    96     register_setting(
    97         'brkti_menu_options',
    98         'brkti_apisecret_input',
    99         array(
    100             'type'              => 'string',
    101             'sanitize_callback' => 'sanitize_text_field',
    102         )
    103     );
    104 }
    105 add_action('admin_init', 'brkti_save_menu');
    106 
    107 // Create a Trendyol webhook endpoint
    108 function brkti_register_trendyol_webhook_route() {
    109     register_rest_route('brkti/v1', '/webhook', array(
    110         'methods'  => 'POST',
    111         'callback' => 'brkti_handle_trendyol_webhook',
    112     ));
    113 }
    114 add_action('rest_api_init', 'brkti_register_trendyol_webhook_route');
    115 
    116 // Trendyol webhook data processing
    117 function brkti_handle_trendyol_webhook(WP_REST_Request $request) {
    118     // Gelen veriyi alın
    119     $data = $request->get_json_params();
    120 
    121     if (empty($data['lines'])) {
    122         return wp_send_json_error('Geçersiz veri: Sipariş bilgisi yok.', 400);
    123     }
    124 
    125     // Update WooCommerce stocks
    126     foreach ($data['lines'] as $line) {
    127         $barcode = $line['barcode'];
    128         $quantity = $line['quantity'];
    129 
    130         // Find WooCommerce products by barcode
    131         $args = array(
    132             'limit' => -1,
    133             'status' => 'publish',
    134         );
    135         $all_products = wc_get_products($args);
    136 
    137         foreach ($all_products as $each_product) {
    138             $each_product_sku = $each_product->get_sku();
    139             if ($each_product_sku === $barcode) {
    140                 // We found the product, update stock
    141                 $current_stock = $each_product->get_stock_quantity();
    142                 $new_stock = $quantity;
    143                 $each_product->set_stock_quantity($new_stock);
    144                 $each_product->save(); // Save changes
    145                 break; // Match found, no need to look at other products
    146             }
    147         }
    148     }
    149 
    150     return wp_send_json_success('Sipariş verisi işlendi ve stoklar güncellendi.');
    151 }
    152 
    153 // Token verification for security (optional)
    154 function brkti_validate_trendyol_webhook(WP_REST_Request $request) {
    155     $headers = $request->get_headers();
    156     $expected_token = 'your_expected_token'; // Token provided by Trendyol
    157     $received_token = isset($headers['authorization'][0]) ? $headers['authorization'][0] : '';
    158 
    159     if ($received_token !== $expected_token) {
    160         return false;
    161     }
    162     return true;
    163 }
    164 
    165 // Update trendyol stocks when order is received from Woodan
    166 function brkti_update_trendyol_stock($order_id) {
    167     if (!$order_id) {
     292/**
     293 * AJAX: Bağlantı testi
     294 */
     295add_action('wp_ajax_brkti_free_test_connection', 'brkti_free_test_connection');
     296function brkti_free_test_connection() {
     297    check_ajax_referer('brkti_free_nonce', 'nonce');
     298   
     299    if (!current_user_can('manage_woocommerce')) {
     300        wp_send_json_error(['message' => 'Yetkiniz yok.']);
     301    }
     302   
     303    $supplier_id = get_option('brkti_supplier_id', '');
     304    $api_key = get_option('brkti_api_key', '');
     305    $api_secret = get_option('brkti_api_secret', '');
     306   
     307    if (empty($supplier_id) || empty($api_key) || empty($api_secret)) {
     308        wp_send_json_error(['message' => 'API bilgileri eksik. Lütfen tüm alanları doldurun.']);
     309    }
     310   
     311    // Trendyol API'ye test isteği
     312    $url = 'https://apigw.trendyol.com/integration/product/sellers/' . $supplier_id . '/products?page=0&size=1';
     313   
     314    $response = wp_remote_get($url, [
     315        'headers' => [
     316            'Authorization' => 'Basic ' . base64_encode($api_key . ':' . $api_secret),
     317            'User-Agent' => $supplier_id . ' - SelfIntegration',
     318            'Content-Type' => 'application/json',
     319            'Accept' => 'application/json',
     320        ],
     321        'timeout' => 30,
     322        'sslverify' => true,
     323    ]);
     324   
     325    if (is_wp_error($response)) {
     326        wp_send_json_error(['message' => 'Bağlantı hatası: ' . $response->get_error_message()]);
     327    }
     328   
     329    $code = wp_remote_retrieve_response_code($response);
     330    $body = wp_remote_retrieve_body($response);
     331   
     332    if ($code === 200) {
     333        $data = json_decode($body, true);
     334        $total = $data['totalElements'] ?? 0;
     335        wp_send_json_success(['message' => 'Bağlantı başarılı! Trendyol\'da ' . $total . ' ürün bulundu.']);
     336    } elseif ($code === 401) {
     337        wp_send_json_error(['message' => 'Kimlik doğrulama hatası. API Key ve Secret bilgilerini kontrol edin.']);
     338    } elseif ($code === 403) {
     339        wp_send_json_error(['message' => 'Erişim reddedildi. Supplier ID\'yi kontrol edin.']);
     340    } else {
     341        wp_send_json_error(['message' => 'HTTP Hata: ' . $code]);
     342    }
     343}
     344
     345/**
     346 * WooCommerce sipariş tamamlandığında Trendyol stoğunu güncelle
     347 */
     348add_action('woocommerce_order_status_processing', 'brkti_free_sync_stock_on_order');
     349add_action('woocommerce_order_status_completed', 'brkti_free_sync_stock_on_order');
     350add_action('woocommerce_payment_complete', 'brkti_free_sync_stock_on_order');
     351
     352function brkti_free_sync_stock_on_order($order_id) {
     353    // Otomatik senkronizasyon kapalıysa çık
     354    if (get_option('brkti_auto_sync', '1') !== '1') {
    168355        return;
    169356    }
    170 
    171     // Take the order
     357   
     358    // Tekrar çalışmasını engelle
     359    if (get_transient('brkti_sync_lock_' . $order_id)) {
     360        return;
     361    }
     362    set_transient('brkti_sync_lock_' . $order_id, true, 60);
     363   
    172364    $order = wc_get_order($order_id);
    173 
    174365    if (!$order) {
    175366        return;
    176367    }
    177 
    178     // Trendyol API credentials
    179     $seller_id = get_option('brkti_sellerid_input', '');
    180     $apikey = get_option('brkti_apikey_input', '');
    181     $apisecret = get_option('brkti_apisecret_input', '');
    182 
    183     $url = "https://api.trendyol.com/sapigw/suppliers/" . $seller_id . "/products/price-and-inventory";
    184 
    185     // Receive all order products
    186     $orders = $order->get_items();
    187 
    188     // Prepare data to be sent to Trendyol API
     368   
     369    // API bilgileri
     370    $supplier_id = get_option('brkti_supplier_id', '');
     371    $api_key = get_option('brkti_api_key', '');
     372    $api_secret = get_option('brkti_api_secret', '');
     373   
     374    if (empty($supplier_id) || empty($api_key) || empty($api_secret)) {
     375        return;
     376    }
     377   
     378    // Siparişteki ürünleri topla
    189379    $items = [];
    190     foreach ($orders as $each_order) {
    191         $each_product = $each_order->get_product();
    192 
    193         if ($each_product && $each_product->get_type() === 'simple') { // Sadece basit ürünleri kontrol et
    194             $sku = $each_product->get_sku(); // Product SKU
    195             $current_stock = $each_product->get_stock_quantity(); // Current WooCommerce stock quantity
    196 
    197             // Calculate the current stock quantity for Trendyol
    198             $new_stock = $current_stock;
    199 
    200             // Product information to be sent to Trendyol API
    201             $items[] = [
    202                 'barcode' => $sku,
    203                 'quantity' => $new_stock,
    204             ];
    205         }
    206     }
    207 
    208     // Check for product availability before making an API call
     380   
     381    foreach ($order->get_items() as $item) {
     382        $product = $item->get_product();
     383       
     384        if (!$product) {
     385            continue;
     386        }
     387       
     388        // Sadece basit ürünler (varyasyonlar hariç)
     389        if ($product->get_type() !== 'simple') {
     390            continue;
     391        }
     392       
     393        $sku = $product->get_sku();
     394        if (empty($sku)) {
     395            continue;
     396        }
     397       
     398        $stock = $product->get_stock_quantity();
     399        if ($stock === null) {
     400            $stock = 0;
     401        }
     402       
     403        $items[] = [
     404            'barcode' => $sku,
     405            'quantity' => max(0, intval($stock)),
     406        ];
     407    }
     408   
    209409    if (empty($items)) {
    210         echo 'Gönderilecek ürün bulunamadı.';
    211410        return;
    212411    }
    213 
    214     // Send stock update request to Trendyol API
    215     $args = [
     412   
     413    // Trendyol API'ye gönder
     414    $url = 'https://apigw.trendyol.com/integration/inventory/sellers/' . $supplier_id . '/products/price-and-inventory';
     415   
     416    $response = wp_remote_post($url, [
    216417        'headers' => [
    217             "Authorization" => "Basic " . base64_encode($apikey . ':' . $apisecret),
    218             "Content-Type"  => "application/json",
     418            'Authorization' => 'Basic ' . base64_encode($api_key . ':' . $api_secret),
     419            'User-Agent' => $supplier_id . ' - SelfIntegration',
     420            'Content-Type' => 'application/json',
     421            'Accept' => 'application/json',
    219422        ],
    220423        'body' => wp_json_encode(['items' => $items]),
    221         'method' => 'POST',
    222     ];
    223 
    224     $response = wp_remote_request($url, $args);
    225 
    226 }
    227 
    228 // Trendyol stock update when WooCommerce order is completed
    229 add_action('woocommerce_thankyou', 'brkti_update_trendyol_stock', 10, 1);
     424        'timeout' => 30,
     425        'sslverify' => true,
     426    ]);
     427   
     428    // Başarılı ise sayacı güncelle
     429    if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) === 200) {
     430        $count = get_option('brkti_sync_count_' . date('Y-m-d'), 0);
     431        update_option('brkti_sync_count_' . date('Y-m-d'), $count + count($items));
     432        update_option('brkti_last_sync', current_time('mysql'));
     433    }
     434}
     435
     436/**
     437 * Trendyol Webhook endpoint (ücretsiz sürümde sadece stok güncelleme)
     438 */
     439add_action('rest_api_init', 'brkti_free_register_webhook');
     440function brkti_free_register_webhook() {
     441    register_rest_route('brkti/v1', '/webhook', [
     442        'methods' => 'POST',
     443        'callback' => 'brkti_free_handle_webhook',
     444        'permission_callback' => '__return_true',
     445    ]);
     446}
     447
     448function brkti_free_handle_webhook(WP_REST_Request $request) {
     449    $data = $request->get_json_params();
     450   
     451    if (empty($data['lines'])) {
     452        return new WP_REST_Response(['error' => 'Geçersiz veri'], 400);
     453    }
     454   
     455    $updated = 0;
     456   
     457    foreach ($data['lines'] as $line) {
     458        $barcode = sanitize_text_field($line['barcode'] ?? '');
     459        $quantity = intval($line['quantity'] ?? 0);
     460       
     461        if (empty($barcode)) {
     462            continue;
     463        }
     464       
     465        // SKU ile ürün bul
     466        $product_id = wc_get_product_id_by_sku($barcode);
     467       
     468        if (!$product_id) {
     469            continue;
     470        }
     471       
     472        $product = wc_get_product($product_id);
     473       
     474        if (!$product || $product->get_type() !== 'simple') {
     475            continue;
     476        }
     477       
     478        // Stok güncelle
     479        $product->set_stock_quantity($quantity);
     480        $product->save();
     481        $updated++;
     482    }
     483   
     484    return new WP_REST_Response([
     485        'success' => true,
     486        'message' => $updated . ' ürün güncellendi.',
     487    ], 200);
     488}
     489
     490/**
     491 * Plugin action links
     492 */
     493add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'brkti_free_action_links');
     494function brkti_free_action_links($links) {
     495    $settings_link = '<a href="' . admin_url('admin.php?page=brkti_settings') . '">Ayarlar</a>';
     496    $premium_link = '<a href="https://brksoft.com/tr/urun/trenyol-entegrasyonu-premium/" target="_blank" style="color:#f7931e;font-weight:bold;">Premium</a>';
     497   
     498    array_unshift($links, $settings_link, $premium_link);
     499    return $links;
     500}
     501
     502/**
     503 * Aktivasyon
     504 */
     505register_activation_hook(__FILE__, 'brkti_free_activate');
     506function brkti_free_activate() {
     507    // Varsayılan ayarlar
     508    add_option('brkti_auto_sync', '1');
     509   
     510    // Flush rewrite rules for REST API
     511    flush_rewrite_rules();
     512}
     513
     514/**
     515 * Deaktivasyon
     516 */
     517register_deactivation_hook(__FILE__, 'brkti_free_deactivate');
     518function brkti_free_deactivate() {
     519    flush_rewrite_rules();
     520}
  • trendyol-entegrasyonu-brksoft/trunk/readme.txt

    r3237252 r3429012  
    11=== Trendyol Entegrasyonu - Brksoft ===
    22Contributors: brksoft
    3 Donate link: https://brksoft.com/
    4 Tags: Trendyol, WooCommerce, Trendyol entegrasyon
    5 Requires at least: 5.0
     3Donate link: https://brksoft.com/tr/
     4Tags: trendyol, woocommerce, trendyol entegrasyon, e-ticaret, entegrasyon
     5Requires at least: 5.8
    66Tested up to: 6.7
    77Requires PHP: 7.4
    8 Stable tag: 1.0.1
     8Stable tag: 2.0.0
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1111
    12 WordPress ve WooCommerce için Trendyol Entegrasyonu. Sipariş sonrası stok güncelleme, çift yönlü entegrasyon ve otomatik senkronizasyon sağlayın.
     12WooCommerce mağazanız için Trendyol entegrasyonu. Sipariş geldiğinde otomatik stok senkronizasyonu.
    1313
    1414== Description ==
    1515
    16 https://www.youtube.com/watch?v=qPeWXCz9UjA
     16**Trendyol Entegrasyonu**, WooCommerce mağazanızı Trendyol hesabınıza entegre ederek stok yönetimini otomatikleştirir.
    1717
    18 **BRK Trendyol Entegrasyonu**, WooCommerce mağazanızı Trendyol hesabınıza entegre ederek e-ticaret işinizi bir üst seviyeye taşır. Temel özellikleri şunlardır:
     18= Ücretsiz Sürüm Özellikleri =
    1919
    20 - Trendyol siparişlerini alarak WooCommerce stoklarınızı otomatik günceller.
    21 - WooCommerce'den gelen siparişlerle Trendyol stoklarını eşitler.
    22 - Trendyol ürün fiyatlarını ve stok miktarlarını API aracılığıyla senkronize eder.
    23 - Kolay kurulum ve kullanım için sade bir ayar paneli sunar.
     20* ✅ WooCommerce sipariş geldiğinde Trendyol stoğunu otomatik güncelleme
     21* ✅ Trendyol webhook desteği ile çift yönlü stok senkronizasyonu
     22* ✅ API bağlantı testi
     23* ✅ Basit ve kullanımı kolay arayüz
     24* ✅ WooCommerce HPOS uyumlu
    2425
    25 Eklenti, küçük ve orta ölçekli e-ticaret işletmeleri için özel olarak tasarlanmıştır.
     26= Ücretsiz Sürüm Kısıtlamaları =
    2627
    27 Premium Sürümü Satın Almak İçin: [Trendyol Entegrasyonu Premium](https://tr.brksoft.com/urun/trenyol-entegrasyonu-premium/ "trendyol premium")
     28* ❌ Sadece **basit ürünler** desteklenir (varyasyonlu ürünler hariç)
     29* ❌ Fiyat senkronizasyonu yok
     30* ❌ Trendyol'dan ürün çekme yok
     31* ❌ Trendyol'a ürün yükleme yok
     32* ❌ Sipariş aktarımı yok
     33
     34= Premium Sürüm Özellikleri =
     35
     36Tüm ücretsiz özelliklere ek olarak:
     37
     38* ⭐ **Varyasyonlu ürün desteği** (beden, renk vb.)
     39* ⭐ **Fiyat senkronizasyonu** (komisyon oranı ile)
     40* ⭐ **Trendyol'dan ürün çekme** ve WooCommerce'e aktarma
     41* ⭐ **WooCommerce'den Trendyol'a ürün yükleme**
     42* ⭐ **Sipariş aktarımı** (Trendyol → WooCommerce)
     43* ⭐ **Kategori eşleştirme** sistemi
     44* ⭐ **Attribute eşleştirme**
     45* ⭐ **Excel import** (API alternatifi)
     46* ⭐ **Kapsamlı loglama** ve debug araçları
     47* ⭐ **Öncelikli destek**
     48
     49[Premium Sürümü İncele](https://brksoft.com/tr/urun/trenyol-entegrasyonu-premium/)
     50
     51= Nasıl Çalışır? =
     52
     531. Trendyol Satıcı Paneli'nden API bilgilerinizi alın
     542. Eklenti ayarlarına API Key, API Secret ve Supplier ID girin
     553. WooCommerce ürünlerinizin SKU'larının Trendyol barcode'ları ile aynı olduğundan emin olun
     564. Sipariş geldiğinde stoklar otomatik senkronize edilir
     57
     58= Webhook Kurulumu =
     59
     60Trendyol'dan gelen stok güncellemelerini almak için:
     61
     621. Trendyol Satıcı Paneli → Entegrasyon → Webhook Ayarları
     632. Webhook URL olarak şunu girin: `https://siteniz.com/wp-json/brkti/v1/webhook`
     643. Artık Trendyol'dan gelen güncellemeler WooCommerce'e yansıyacak
    2865
    2966== Installation ==
    3067
    31 1. Eklentiyi WordPress panosundan yükleyin veya dosyayı `/wp-content/plugins/` dizinine yükleyin.
    32 2. Eklentiyi etkinleştirin.
    33 3. Ayarlar > Trendyol Entegrasyonu menüsünden API bilgilerinizi girin:
    34    - **API Key**
    35    - **API Secret**
    36    - **Satıcı ID**
    37 4. WooCommerce ile Trendyol entegrasyonu artık hazır!
     681. Eklentiyi WordPress panosundan yükleyin veya `/wp-content/plugins/` dizinine yükleyin
     692. Eklentiler sayfasından "Trendyol Entegrasyonu" eklentisini etkinleştirin
     703. Sol menüden "Trendyol" sayfasına gidin
     714. API bilgilerinizi girin:
     72   - **Supplier ID**: Trendyol satıcı numaranız
     73   - **API Key**: Trendyol API anahtarınız
     74   - **API Secret**: Trendyol API secret'ınız
     755. "API Bağlantısını Test Et" butonuna tıklayarak bağlantıyı doğrulayın
     766. Ayarları kaydedin
    3877
    3978== Frequently Asked Questions ==
    4079
    41 = Trendyol API bilgilerini nasıl alabilirim? =
    42 Trendyol satıcı paneline giriş yaparak API bilgileriniz için "Ayarlar > API Bilgileri" sekmesini kontrol edin.
     80= Trendyol API bilgilerini nereden alabilirim? =
    4381
    44 = Ücretsiz sürüm hangi özellikleri sunuyor? =
    45 Ücretsiz sürümde sadece sipariş bazlı stok güncellemeleri yapılır. Çift yönlü entegrasyon gibi gelişmiş özellikler için Pro sürümü kullanabilirsiniz.
     82Trendyol Satıcı Paneli → Entegrasyon → API Bilgileri bölümünden alabilirsiniz.
    4683
    47 = Eklenti hangi durumlarda stok güncellemesi yapar? =
    48 Sipariş tamamlandığında veya manuel güncelleme yapıldığında Trendyol ile stoklar senkronize edilir.
     84= Varyasyonlu ürünler destekleniyor mu? =
     85
     86Ücretsiz sürümde sadece basit ürünler desteklenir. Varyasyonlu ürünler için Premium sürüm gereklidir.
     87
     88= Stok güncellemesi ne zaman yapılır? =
     89
     90WooCommerce'den sipariş geldiğinde (ödeme tamamlandığında veya sipariş işleme alındığında) otomatik olarak Trendyol'a stok güncellemesi gönderilir.
     91
     92= SKU eşleştirmesi nasıl çalışır? =
     93
     94WooCommerce ürününüzün SKU'su ile Trendyol'daki ürünün barcode'u aynı olmalıdır. Sistem bu eşleşmeyi kullanarak stok güncellemesi yapar.
     95
     96= Webhook ne işe yarar? =
     97
     98Webhook sayesinde Trendyol'dan gelen siparişlerde de WooCommerce stokları otomatik güncellenir (çift yönlü senkronizasyon).
     99
     100= Premium sürümde neler var? =
     101
     102Premium sürümde varyasyonlu ürün desteği, fiyat senkronizasyonu, Trendyol'dan ürün çekme, ürün yükleme, sipariş aktarımı, kategori eşleştirme ve daha birçok özellik bulunur.
    49103
    50104== Screenshots ==
    51105
    52 1. **Eklenti Ayarları** - API bilgilerinizi girebileceğiniz Trendyol entegrasyon ayarları.
     1061. Eklenti ana ayarlar sayfası
     1072. API bağlantı testi
    53108
    54109== Changelog ==
    55110
     111= 2.0.0 =
     112* Tamamen yeniden yazıldı
     113* Modern ve kullanıcı dostu arayüz
     114* API bağlantı testi eklendi
     115* Durum göstergeleri eklendi
     116* WooCommerce HPOS uyumluluğu
     117* Geliştirilmiş güvenlik (nonce kontrolü)
     118* Senkronizasyon istatistikleri
     119* Premium sürüm bilgilendirmesi
     120
    56121= 1.0.1 =
    57 * İlk sürüm.
    58 * Sipariş bazlı stok güncellemesi.
    59 * Trendyol ile WooCommerce entegrasyonu.
     122* İlk sürüm
     123* Sipariş bazlı stok güncellemesi
     124* Temel Trendyol entegrasyonu
    60125
    61126== Upgrade Notice ==
    62127
    63 = 1.0.1 =
    64 İlk sürüm: Temel özelliklerle Trendyol entegrasyonunu sağlayın.
     128= 2.0.0 =
     129Yeni arayüz, bağlantı testi ve geliştirilmiş özellikler. Güncellemeniz önerilir.
    65130
    66 == External services ==
     131== External Services ==
    67132
    68 This plugin connects to the Trendyol API to manage product stock and prices in WooCommerce.
     133Bu eklenti aşağıdaki harici servislerle iletişim kurar:
    69134
    70 - **Service:** Trendyol API
    71 - **Purpose:** Updates stock and price information for WooCommerce products.
    72 - **Data Sent:** Seller ID, API Key, API Secret, and product details are sent during stock and price updates.
    73 - **Terms and Privacy Policy:** [Trendyol Terms of Use](https://developers.trendyol.com/int/docs/intro) | [Trendyol Privacy Policy](https://www.trendyol.com/kisisel_verilerin_korunmasi)
     135**Trendyol API**
     136
     137* Amaç: Ürün stok bilgilerini senkronize etmek
     138* Gönderilen veriler: Satıcı ID, API kimlik bilgileri, ürün SKU/barcode ve stok miktarı
     139* Ne zaman: WooCommerce siparişi tamamlandığında
     140* Kullanım koşulları: [Trendyol Geliştirici Portalı](https://developers.trendyol.com/)
     141* Gizlilik politikası: [Trendyol Gizlilik Politikası](https://www.trendyol.com/kisisel_verilerin_korunmasi)
    74142
    75143== Tags ==
    76 Trendyol entegrasyonu, WooCommerce Trendyol, Stok senkronizasyonu, Otomatik güncelleme
     144trendyol, woocommerce, stok senkronizasyonu, e-ticaret, entegrasyon, marketplace, pazaryeri
  • trendyol-entegrasyonu-brksoft/trunk/trendyol-entegrasyonu-brksoft.php

    r3226777 r3429012  
    22/**
    33 * Plugin Name: Trendyol Entegrasyonu - Brksoft
    4  * Description: WooCommerce mağazaları için Trendyol entegrasyonu.
    5  * Version: 1.0.1
     4 * Description: WooCommerce mağazaları için Trendyol entegrasyonu. Sipariş geldiğinde otomatik stok senkronizasyonu.
     5 * Version: 2.0.0
    66 * Author: Brksoft
    77 * Author URI: https://brksoft.com/
     
    99 * Domain Path: /languages
    1010 * Requires Plugins: woocommerce
    11  * WC requires at least: 4.0
     11 * Requires at least: 5.8
     12 * Tested up to: 6.7
     13 * Requires PHP: 7.4
     14 * WC requires at least: 5.0
    1215 * WC tested up to: 9.4
    1316 * License: GPL-2.0+
     
    1720defined('ABSPATH') || exit;
    1821
    19 // WooCommerce compatibility
    20 add_action('before_woocommerce_init', function () {
     22// Sürüm
     23define('BRKTI_FREE_VERSION', '2.0.0');
     24
     25/**
     26 * WooCommerce HPOS uyumluluğu
     27 */
     28add_action('before_woocommerce_init', function() {
    2129    if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
    2230        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
     
    2432});
    2533
    26 // Admin menu for settings
    27 function brkti_menu() {
     34/**
     35 * Admin menü
     36 */
     37add_action('admin_menu', 'brkti_free_admin_menu');
     38function brkti_free_admin_menu() {
    2839    add_menu_page(
    2940        'Trendyol Entegrasyonu',
    30         __('Trendyol Entegrasyonu', 'trendyol-entegrasyonu-brksoft'),
    31         'edit_posts',
     41        'Trendyol',
     42        'manage_woocommerce',
    3243        'brkti_settings',
    33         'brkti_menu_callback',
    34         'dashicons-update'
     44        'brkti_free_settings_page',
     45        'dashicons-update',
     46        56
    3547    );
    3648}
    37 add_action('admin_menu', 'brkti_menu');
    38 
    39 // Admin menu callback
    40 function brkti_menu_callback() {
     49
     50/**
     51 * Ayarları kaydet
     52 */
     53add_action('admin_init', 'brkti_free_register_settings');
     54function brkti_free_register_settings() {
     55    register_setting('brkti_free_options', 'brkti_supplier_id', ['sanitize_callback' => 'sanitize_text_field']);
     56    register_setting('brkti_free_options', 'brkti_api_key', ['sanitize_callback' => 'sanitize_text_field']);
     57    register_setting('brkti_free_options', 'brkti_api_secret', ['sanitize_callback' => 'sanitize_text_field']);
     58    register_setting('brkti_free_options', 'brkti_auto_sync', ['sanitize_callback' => 'absint']);
     59}
     60
     61/**
     62 * Ayarlar sayfası
     63 */
     64function brkti_free_settings_page() {
     65    $supplier_id = get_option('brkti_supplier_id', '');
     66    $api_key = get_option('brkti_api_key', '');
     67    $api_secret = get_option('brkti_api_secret', '');
     68    $auto_sync = get_option('brkti_auto_sync', '1');
     69    $last_sync = get_option('brkti_last_sync', '');
     70    $sync_count = get_option('brkti_sync_count_' . date('Y-m-d'), 0);
     71   
     72    // Ayarlar kaydedildi mi?
     73    $saved = isset($_GET['settings-updated']) && $_GET['settings-updated'] === 'true';
    4174    ?>
    42     <h1><?php echo esc_html__('Trendyol Entegrasyonu', 'trendyol-entegrasyonu-brksoft'); ?></h1>
    43     <form action="options.php" method="post">
    44         <?php
    45         settings_fields('brkti_menu_options');
    46         $apikey_value = get_option('brkti_apikey_input', '');
    47         $sellerid_value = get_option('brkti_sellerid_input', '');
    48         $apisecret_value = get_option('brkti_apisecret_input', '');
    49 
    50         ?>
    51 
    52         <h3><?php echo esc_html__( 'Nasil Çalışır?', 'trendyol-entegrasyonu-brksoft' ); ?></h3>
    53         <p><?php echo esc_html__( 'İlk olarak trendyol satıcı panelinizden entegrasyon bilgilerinizi alıp aşşağıdaki yere yapıştırıp kaydedin.', 'trendyol-entegrasyonu-brksoft' ); ?></p>
    54         <p><?php echo esc_html__( 'Bunu yapmanız ardından artık her yeni sipariş geldiğinde stok kodu aynı olan ürünleri sistem otomatik olarak bulucak ve hem WooCommerce sitenizde hem Trendyol hesabınızda çift taraflı olarak güncelleyecektir.', 'trendyol-entegrasyonu-brksoft' ); ?></p>
    55         <h3><?php echo esc_html__( 'Eklentimiz ücretsiz sürümde sadece basit ürünler için çalışmaktadır ve sadece stok senkronizasyonu sağlar.', 'trendyol-entegrasyonu-brksoft' ); ?></h3>
    56         <h3><?php echo esc_html__( '• Varyasyonlu ürünler için senkronizasyon yapmak', 'trendyol-entegrasyonu-brksoft' ); ?></h3>
    57         <h3><?php echo esc_html__( '• Toplu fiyat senkronizasyonları yapmak ', 'trendyol-entegrasyonu-brksoft' ); ?></h3>
    58         <h3><?php echo esc_html__( '• Stok güncellendiğinde stokları eşitlemek', 'trendyol-entegrasyonu-brksoft' ); ?></h3>
    59         <h3><?php echo esc_html__( 'gibi çeşitli özelliklere de erişmek için eklentimizin ücretli sürümünü sitemizden satın alabilirsiniz.', 'trendyol-entegrasyonu-brksoft' ); ?></h3>
    60 
    61         <a href="https://tr.brksoft.com/urun/trenyol-entegrasyonu-premium/" target="_blank" style="font-size: 17px;" ><?php echo esc_html__( 'Ücretli Sürümü Satın Al', 'trendyol-entegrasyonu-brksoft' ); ?></a>
    62 
    63         <br><br>
    64 
    65         <label for="brkti_apikey_input">API Key:</label>
    66         <input type="text" id="brkti_apikey_input" name="brkti_apikey_input" value="<?php echo esc_html( $apikey_value );  ?>">
    67         <br><br>
    68         <label for="brkti_sellerid_input">Seller ID:</label>
    69         <input type="text" id="brkti_sellerid_input" name="brkti_sellerid_input" value="<?php echo esc_html( $sellerid_value ) ; ?>">
    70         <br><br>
    71         <label for="brkti_apisecret_input">API Secret:</label>
    72         <input type="text" id="brkti_apisecret_input" name="brkti_apisecret_input" value="<?php echo esc_html( $apisecret_value ) ; ?>">
    73         <?php submit_button(); ?>
    74     </form>
     75    <div class="wrap">
     76        <h1>🟠 Trendyol Entegrasyonu</h1>
     77       
     78        <style>
     79            .brkti-wrap { max-width: 800px; }
     80            .brkti-card { background: #fff; border: 1px solid #ddd; border-radius: 8px; padding: 20px; margin: 20px 0; }
     81            .brkti-card h2 { margin-top: 0; padding-bottom: 10px; border-bottom: 1px solid #eee; }
     82            .brkti-premium-card { background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%); color: #fff; }
     83            .brkti-premium-card h2 { color: #fff; border-bottom-color: rgba(255,255,255,0.3); }
     84            .brkti-premium-card a { color: #fff; font-weight: bold; }
     85            .brkti-form-table th { width: 150px; padding: 15px 10px 15px 0; }
     86            .brkti-form-table td { padding: 10px 0; }
     87            .brkti-form-table input[type="text"] { width: 100%; max-width: 400px; padding: 8px 12px; }
     88            .brkti-status { display: inline-flex; align-items: center; gap: 8px; padding: 8px 15px; border-radius: 5px; margin: 10px 0; }
     89            .brkti-status.success { background: #d4edda; color: #155724; }
     90            .brkti-status.warning { background: #fff3cd; color: #856404; }
     91            .brkti-status.error { background: #f8d7da; color: #721c24; }
     92            .brkti-features { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 15px 0; }
     93            .brkti-features li { display: flex; align-items: center; gap: 8px; }
     94            .brkti-test-result { margin-top: 15px; padding: 15px; border-radius: 5px; display: none; }
     95            .brkti-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin: 15px 0; }
     96            .brkti-stat { text-align: center; padding: 15px; background: #f8f9fa; border-radius: 5px; }
     97            .brkti-stat .number { font-size: 24px; font-weight: bold; color: #0073aa; }
     98            .brkti-stat .label { font-size: 12px; color: #666; }
     99        </style>
     100       
     101        <div class="brkti-wrap">
     102           
     103            <?php if ($saved): ?>
     104            <div class="notice notice-success is-dismissible">
     105                <p><strong>Ayarlar kaydedildi!</strong></p>
     106            </div>
     107            <?php endif; ?>
     108           
     109            <!-- Premium Banner -->
     110            <div class="brkti-card brkti-premium-card">
     111                <h2>⭐ Premium Sürüme Yükseltin</h2>
     112                <p>Ücretsiz sürümde sadece <strong>basit ürünler</strong> için sipariş bazlı stok senkronizasyonu yapılır.</p>
     113               
     114                <ul class="brkti-features" style="list-style:none; padding:0; margin:15px 0;">
     115                    <li>✖️ Varyasyonlu ürün desteği</li>
     116                    <li>✖️ Fiyat senkronizasyonu</li>
     117                    <li>✖️ Trendyol'dan ürün çekme</li>
     118                    <li>✖️ Trendyol'a ürün yükleme</li>
     119                    <li>✖️ Sipariş aktarımı</li>
     120                    <li>✖️ Kategori eşleştirme</li>
     121                    <li>✖️ Webhook desteği</li>
     122                    <li>✖️ Excel import</li>
     123                </ul>
     124               
     125                <p>
     126                    <a href="https://brksoft.com/tr/urun/trenyol-entegrasyonu-premium/" target="_blank" style="background:#fff; color:#f7931e; padding:12px 25px; border-radius:5px; text-decoration:none; display:inline-block; font-size:16px;">
     127                        🚀 Premium Sürümü İncele
     128                    </a>
     129                </p>
     130            </div>
     131           
     132            <!-- API Ayarları -->
     133            <div class="brkti-card">
     134                <h2>🔗 API Ayarları</h2>
     135                <p>Trendyol Satıcı Paneli → Entegrasyon → API Bilgileri bölümünden bilgilerinizi alabilirsiniz.</p>
     136               
     137                <form method="post" action="options.php">
     138                    <?php settings_fields('brkti_free_options'); ?>
     139                   
     140                    <table class="form-table brkti-form-table">
     141                        <tr>
     142                            <th><label for="brkti_supplier_id">Satıcı ID (Supplier ID)</label></th>
     143                            <td>
     144                                <input type="text" id="brkti_supplier_id" name="brkti_supplier_id" value="<?php echo esc_attr($supplier_id); ?>" placeholder="123456">
     145                            </td>
     146                        </tr>
     147                        <tr>
     148                            <th><label for="brkti_api_key">API Key</label></th>
     149                            <td>
     150                                <input type="text" id="brkti_api_key" name="brkti_api_key" value="<?php echo esc_attr($api_key); ?>" placeholder="xxxxxxxx">
     151                            </td>
     152                        </tr>
     153                        <tr>
     154                            <th><label for="brkti_api_secret">API Secret</label></th>
     155                            <td>
     156                                <input type="text" id="brkti_api_secret" name="brkti_api_secret" value="<?php echo esc_attr($api_secret); ?>" placeholder="xxxxxxxx">
     157                            </td>
     158                        </tr>
     159                        <tr>
     160                            <th><label for="brkti_auto_sync">Otomatik Senkronizasyon</label></th>
     161                            <td>
     162                                <label>
     163                                    <input type="checkbox" id="brkti_auto_sync" name="brkti_auto_sync" value="1" <?php checked($auto_sync, '1'); ?>>
     164                                    WooCommerce sipariş geldiğinde Trendyol stoğunu otomatik güncelle
     165                                </label>
     166                                <p class="description">Sadece basit ürünler için çalışır. Varyasyonlu ürünler için Premium sürüm gereklidir.</p>
     167                            </td>
     168                        </tr>
     169                    </table>
     170                   
     171                    <?php submit_button('Ayarları Kaydet'); ?>
     172                </form>
     173               
     174                <!-- Bağlantı Testi -->
     175                <hr style="margin: 20px 0;">
     176                <h3>🔌 Bağlantı Testi</h3>
     177                <button type="button" class="button button-secondary" id="brkti_test_connection">API Bağlantısını Test Et</button>
     178                <div id="brkti_test_result" class="brkti-test-result"></div>
     179            </div>
     180           
     181            <!-- Durum -->
     182            <div class="brkti-card">
     183                <h2>📊 Durum</h2>
     184               
     185                <?php
     186                $has_credentials = !empty($supplier_id) && !empty($api_key) && !empty($api_secret);
     187                ?>
     188               
     189                <?php if ($has_credentials): ?>
     190                    <div class="brkti-status success">
     191                        ✅ API bilgileri ayarlandı
     192                    </div>
     193                <?php else: ?>
     194                    <div class="brkti-status warning">
     195                        ⚠️ API bilgilerini girin
     196                    </div>
     197                <?php endif; ?>
     198               
     199                <?php if ($auto_sync): ?>
     200                    <div class="brkti-status success">
     201                        ✅ Otomatik senkronizasyon aktif
     202                    </div>
     203                <?php else: ?>
     204                    <div class="brkti-status warning">
     205                        ⚠️ Otomatik senkronizasyon kapalı
     206                    </div>
     207                <?php endif; ?>
     208               
     209                <div class="brkti-stats">
     210                    <div class="brkti-stat">
     211                        <div class="number"><?php echo intval($sync_count); ?></div>
     212                        <div class="label">Bugün Senkronize</div>
     213                    </div>
     214                    <div class="brkti-stat">
     215                        <div class="number"><?php echo $last_sync ? date('H:i', strtotime($last_sync)) : '-'; ?></div>
     216                        <div class="label">Son Senkronizasyon</div>
     217                    </div>
     218                    <div class="brkti-stat">
     219                        <div class="number"><?php
     220                            global $wpdb;
     221                            $simple_count = $wpdb->get_var("
     222                                SELECT COUNT(*) FROM {$wpdb->posts} p
     223                                INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id
     224                                WHERE p.post_type = 'product'
     225                                AND p.post_status = 'publish'
     226                                AND pm.meta_key = '_sku'
     227                                AND pm.meta_value != ''
     228                            ");
     229                            echo intval($simple_count);
     230                        ?></div>
     231                        <div class="label">SKU'lu Ürün</div>
     232                    </div>
     233                </div>
     234            </div>
     235           
     236            <!-- Nasıl Çalışır -->
     237            <div class="brkti-card">
     238                <h2>❓ Nasıl Çalışır?</h2>
     239                <ol>
     240                    <li><strong>API Bilgilerini Girin:</strong> Trendyol Satıcı Paneli'nden Supplier ID, API Key ve API Secret bilgilerinizi alın.</li>
     241                    <li><strong>SKU Eşleştirmesi:</strong> WooCommerce ürünlerinizin SKU'ları ile Trendyol'daki barcode'ların aynı olduğundan emin olun.</li>
     242                    <li><strong>Otomatik Güncelleme:</strong> WooCommerce'den sipariş geldiğinde, aynı SKU'ya sahip Trendyol ürününün stoğu otomatik güncellenir.</li>
     243                </ol>
     244               
     245                <p><strong>⚠️ Not:</strong> Ücretsiz sürümde sadece <u>basit ürünler</u> desteklenir. Varyasyonlu ürünler için Premium sürüm gereklidir.</p>
     246            </div>
     247           
     248            <!-- Destek -->
     249            <div class="brkti-card">
     250                <h2>💬 Destek</h2>
     251                <p>Sorularınız için: <a href="https://brksoft.com/tr/iletisim/" target="_blank">brksoft.com/tr/iletisim</a></p>
     252            </div>
     253           
     254        </div>
     255       
     256        <script>
     257        jQuery(document).ready(function($) {
     258            $('#brkti_test_connection').on('click', function() {
     259                var btn = $(this);
     260                var result = $('#brkti_test_result');
     261               
     262                btn.prop('disabled', true).text('Test ediliyor...');
     263                result.hide();
     264               
     265                $.post(ajaxurl, {
     266                    action: 'brkti_free_test_connection',
     267                    nonce: '<?php echo wp_create_nonce('brkti_free_nonce'); ?>'
     268                }, function(response) {
     269                    btn.prop('disabled', false).text('API Bağlantısını Test Et');
     270                   
     271                    if (response.success) {
     272                        result.css('background', '#d4edda').css('color', '#155724');
     273                        result.html('✅ ' + response.data.message);
     274                    } else {
     275                        result.css('background', '#f8d7da').css('color', '#721c24');
     276                        result.html('❌ ' + response.data.message);
     277                    }
     278                    result.show();
     279                }).fail(function() {
     280                    btn.prop('disabled', false).text('API Bağlantısını Test Et');
     281                    result.css('background', '#f8d7da').css('color', '#721c24');
     282                    result.html('❌ AJAX hatası');
     283                    result.show();
     284                });
     285            });
     286        });
     287        </script>
     288    </div>
    75289    <?php
    76290}
    77291
    78 // Register settings
    79 function brkti_save_menu() {
    80     register_setting(
    81         'brkti_menu_options',
    82         'brkti_sellerid_input',
    83         array(
    84             'type'              => 'string',
    85             'sanitize_callback' => 'sanitize_text_field',
    86         )
    87     );
    88     register_setting(
    89         'brkti_menu_options',
    90         'brkti_apikey_input',
    91         array(
    92             'type'              => 'string',
    93             'sanitize_callback' => 'sanitize_text_field',
    94         )
    95     );
    96     register_setting(
    97         'brkti_menu_options',
    98         'brkti_apisecret_input',
    99         array(
    100             'type'              => 'string',
    101             'sanitize_callback' => 'sanitize_text_field',
    102         )
    103     );
    104 }
    105 add_action('admin_init', 'brkti_save_menu');
    106 
    107 // Create a Trendyol webhook endpoint
    108 function brkti_register_trendyol_webhook_route() {
    109     register_rest_route('brkti/v1', '/webhook', array(
    110         'methods'  => 'POST',
    111         'callback' => 'brkti_handle_trendyol_webhook',
    112     ));
    113 }
    114 add_action('rest_api_init', 'brkti_register_trendyol_webhook_route');
    115 
    116 // Trendyol webhook data processing
    117 function brkti_handle_trendyol_webhook(WP_REST_Request $request) {
    118     // Gelen veriyi alın
    119     $data = $request->get_json_params();
    120 
    121     if (empty($data['lines'])) {
    122         return wp_send_json_error('Geçersiz veri: Sipariş bilgisi yok.', 400);
    123     }
    124 
    125     // Update WooCommerce stocks
    126     foreach ($data['lines'] as $line) {
    127         $barcode = $line['barcode'];
    128         $quantity = $line['quantity'];
    129 
    130         // Find WooCommerce products by barcode
    131         $args = array(
    132             'limit' => -1,
    133             'status' => 'publish',
    134         );
    135         $all_products = wc_get_products($args);
    136 
    137         foreach ($all_products as $each_product) {
    138             $each_product_sku = $each_product->get_sku();
    139             if ($each_product_sku === $barcode) {
    140                 // We found the product, update stock
    141                 $current_stock = $each_product->get_stock_quantity();
    142                 $new_stock = $quantity;
    143                 $each_product->set_stock_quantity($new_stock);
    144                 $each_product->save(); // Save changes
    145                 break; // Match found, no need to look at other products
    146             }
    147         }
    148     }
    149 
    150     return wp_send_json_success('Sipariş verisi işlendi ve stoklar güncellendi.');
    151 }
    152 
    153 // Token verification for security (optional)
    154 function brkti_validate_trendyol_webhook(WP_REST_Request $request) {
    155     $headers = $request->get_headers();
    156     $expected_token = 'your_expected_token'; // Token provided by Trendyol
    157     $received_token = isset($headers['authorization'][0]) ? $headers['authorization'][0] : '';
    158 
    159     if ($received_token !== $expected_token) {
    160         return false;
    161     }
    162     return true;
    163 }
    164 
    165 // Update trendyol stocks when order is received from Woodan
    166 function brkti_update_trendyol_stock($order_id) {
    167     if (!$order_id) {
     292/**
     293 * AJAX: Bağlantı testi
     294 */
     295add_action('wp_ajax_brkti_free_test_connection', 'brkti_free_test_connection');
     296function brkti_free_test_connection() {
     297    check_ajax_referer('brkti_free_nonce', 'nonce');
     298   
     299    if (!current_user_can('manage_woocommerce')) {
     300        wp_send_json_error(['message' => 'Yetkiniz yok.']);
     301    }
     302   
     303    $supplier_id = get_option('brkti_supplier_id', '');
     304    $api_key = get_option('brkti_api_key', '');
     305    $api_secret = get_option('brkti_api_secret', '');
     306   
     307    if (empty($supplier_id) || empty($api_key) || empty($api_secret)) {
     308        wp_send_json_error(['message' => 'API bilgileri eksik. Lütfen tüm alanları doldurun.']);
     309    }
     310   
     311    // Trendyol API'ye test isteği
     312    $url = 'https://apigw.trendyol.com/integration/product/sellers/' . $supplier_id . '/products?page=0&size=1';
     313   
     314    $response = wp_remote_get($url, [
     315        'headers' => [
     316            'Authorization' => 'Basic ' . base64_encode($api_key . ':' . $api_secret),
     317            'User-Agent' => $supplier_id . ' - SelfIntegration',
     318            'Content-Type' => 'application/json',
     319            'Accept' => 'application/json',
     320        ],
     321        'timeout' => 30,
     322        'sslverify' => true,
     323    ]);
     324   
     325    if (is_wp_error($response)) {
     326        wp_send_json_error(['message' => 'Bağlantı hatası: ' . $response->get_error_message()]);
     327    }
     328   
     329    $code = wp_remote_retrieve_response_code($response);
     330    $body = wp_remote_retrieve_body($response);
     331   
     332    if ($code === 200) {
     333        $data = json_decode($body, true);
     334        $total = $data['totalElements'] ?? 0;
     335        wp_send_json_success(['message' => 'Bağlantı başarılı! Trendyol\'da ' . $total . ' ürün bulundu.']);
     336    } elseif ($code === 401) {
     337        wp_send_json_error(['message' => 'Kimlik doğrulama hatası. API Key ve Secret bilgilerini kontrol edin.']);
     338    } elseif ($code === 403) {
     339        wp_send_json_error(['message' => 'Erişim reddedildi. Supplier ID\'yi kontrol edin.']);
     340    } else {
     341        wp_send_json_error(['message' => 'HTTP Hata: ' . $code]);
     342    }
     343}
     344
     345/**
     346 * WooCommerce sipariş tamamlandığında Trendyol stoğunu güncelle
     347 */
     348add_action('woocommerce_order_status_processing', 'brkti_free_sync_stock_on_order');
     349add_action('woocommerce_order_status_completed', 'brkti_free_sync_stock_on_order');
     350add_action('woocommerce_payment_complete', 'brkti_free_sync_stock_on_order');
     351
     352function brkti_free_sync_stock_on_order($order_id) {
     353    // Otomatik senkronizasyon kapalıysa çık
     354    if (get_option('brkti_auto_sync', '1') !== '1') {
    168355        return;
    169356    }
    170 
    171     // Take the order
     357   
     358    // Tekrar çalışmasını engelle
     359    if (get_transient('brkti_sync_lock_' . $order_id)) {
     360        return;
     361    }
     362    set_transient('brkti_sync_lock_' . $order_id, true, 60);
     363   
    172364    $order = wc_get_order($order_id);
    173 
    174365    if (!$order) {
    175366        return;
    176367    }
    177 
    178     // Trendyol API credentials
    179     $seller_id = get_option('brkti_sellerid_input', '');
    180     $apikey = get_option('brkti_apikey_input', '');
    181     $apisecret = get_option('brkti_apisecret_input', '');
    182 
    183     $url = "https://api.trendyol.com/sapigw/suppliers/" . $seller_id . "/products/price-and-inventory";
    184 
    185     // Receive all order products
    186     $orders = $order->get_items();
    187 
    188     // Prepare data to be sent to Trendyol API
     368   
     369    // API bilgileri
     370    $supplier_id = get_option('brkti_supplier_id', '');
     371    $api_key = get_option('brkti_api_key', '');
     372    $api_secret = get_option('brkti_api_secret', '');
     373   
     374    if (empty($supplier_id) || empty($api_key) || empty($api_secret)) {
     375        return;
     376    }
     377   
     378    // Siparişteki ürünleri topla
    189379    $items = [];
    190     foreach ($orders as $each_order) {
    191         $each_product = $each_order->get_product();
    192 
    193         if ($each_product && $each_product->get_type() === 'simple') { // Sadece basit ürünleri kontrol et
    194             $sku = $each_product->get_sku(); // Product SKU
    195             $current_stock = $each_product->get_stock_quantity(); // Current WooCommerce stock quantity
    196 
    197             // Calculate the current stock quantity for Trendyol
    198             $new_stock = $current_stock;
    199 
    200             // Product information to be sent to Trendyol API
    201             $items[] = [
    202                 'barcode' => $sku,
    203                 'quantity' => $new_stock,
    204             ];
    205         }
    206     }
    207 
    208     // Check for product availability before making an API call
     380   
     381    foreach ($order->get_items() as $item) {
     382        $product = $item->get_product();
     383       
     384        if (!$product) {
     385            continue;
     386        }
     387       
     388        // Sadece basit ürünler (varyasyonlar hariç)
     389        if ($product->get_type() !== 'simple') {
     390            continue;
     391        }
     392       
     393        $sku = $product->get_sku();
     394        if (empty($sku)) {
     395            continue;
     396        }
     397       
     398        $stock = $product->get_stock_quantity();
     399        if ($stock === null) {
     400            $stock = 0;
     401        }
     402       
     403        $items[] = [
     404            'barcode' => $sku,
     405            'quantity' => max(0, intval($stock)),
     406        ];
     407    }
     408   
    209409    if (empty($items)) {
    210         echo 'Gönderilecek ürün bulunamadı.';
    211410        return;
    212411    }
    213 
    214     // Send stock update request to Trendyol API
    215     $args = [
     412   
     413    // Trendyol API'ye gönder
     414    $url = 'https://apigw.trendyol.com/integration/inventory/sellers/' . $supplier_id . '/products/price-and-inventory';
     415   
     416    $response = wp_remote_post($url, [
    216417        'headers' => [
    217             "Authorization" => "Basic " . base64_encode($apikey . ':' . $apisecret),
    218             "Content-Type"  => "application/json",
     418            'Authorization' => 'Basic ' . base64_encode($api_key . ':' . $api_secret),
     419            'User-Agent' => $supplier_id . ' - SelfIntegration',
     420            'Content-Type' => 'application/json',
     421            'Accept' => 'application/json',
    219422        ],
    220423        'body' => wp_json_encode(['items' => $items]),
    221         'method' => 'POST',
    222     ];
    223 
    224     $response = wp_remote_request($url, $args);
    225 
    226 }
    227 
    228 // Trendyol stock update when WooCommerce order is completed
    229 add_action('woocommerce_thankyou', 'brkti_update_trendyol_stock', 10, 1);
     424        'timeout' => 30,
     425        'sslverify' => true,
     426    ]);
     427   
     428    // Başarılı ise sayacı güncelle
     429    if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) === 200) {
     430        $count = get_option('brkti_sync_count_' . date('Y-m-d'), 0);
     431        update_option('brkti_sync_count_' . date('Y-m-d'), $count + count($items));
     432        update_option('brkti_last_sync', current_time('mysql'));
     433    }
     434}
     435
     436/**
     437 * Trendyol Webhook endpoint (ücretsiz sürümde sadece stok güncelleme)
     438 */
     439add_action('rest_api_init', 'brkti_free_register_webhook');
     440function brkti_free_register_webhook() {
     441    register_rest_route('brkti/v1', '/webhook', [
     442        'methods' => 'POST',
     443        'callback' => 'brkti_free_handle_webhook',
     444        'permission_callback' => '__return_true',
     445    ]);
     446}
     447
     448function brkti_free_handle_webhook(WP_REST_Request $request) {
     449    $data = $request->get_json_params();
     450   
     451    if (empty($data['lines'])) {
     452        return new WP_REST_Response(['error' => 'Geçersiz veri'], 400);
     453    }
     454   
     455    $updated = 0;
     456   
     457    foreach ($data['lines'] as $line) {
     458        $barcode = sanitize_text_field($line['barcode'] ?? '');
     459        $quantity = intval($line['quantity'] ?? 0);
     460       
     461        if (empty($barcode)) {
     462            continue;
     463        }
     464       
     465        // SKU ile ürün bul
     466        $product_id = wc_get_product_id_by_sku($barcode);
     467       
     468        if (!$product_id) {
     469            continue;
     470        }
     471       
     472        $product = wc_get_product($product_id);
     473       
     474        if (!$product || $product->get_type() !== 'simple') {
     475            continue;
     476        }
     477       
     478        // Stok güncelle
     479        $product->set_stock_quantity($quantity);
     480        $product->save();
     481        $updated++;
     482    }
     483   
     484    return new WP_REST_Response([
     485        'success' => true,
     486        'message' => $updated . ' ürün güncellendi.',
     487    ], 200);
     488}
     489
     490/**
     491 * Plugin action links
     492 */
     493add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'brkti_free_action_links');
     494function brkti_free_action_links($links) {
     495    $settings_link = '<a href="' . admin_url('admin.php?page=brkti_settings') . '">Ayarlar</a>';
     496    $premium_link = '<a href="https://brksoft.com/tr/urun/trenyol-entegrasyonu-premium/" target="_blank" style="color:#f7931e;font-weight:bold;">Premium</a>';
     497   
     498    array_unshift($links, $settings_link, $premium_link);
     499    return $links;
     500}
     501
     502/**
     503 * Aktivasyon
     504 */
     505register_activation_hook(__FILE__, 'brkti_free_activate');
     506function brkti_free_activate() {
     507    // Varsayılan ayarlar
     508    add_option('brkti_auto_sync', '1');
     509   
     510    // Flush rewrite rules for REST API
     511    flush_rewrite_rules();
     512}
     513
     514/**
     515 * Deaktivasyon
     516 */
     517register_deactivation_hook(__FILE__, 'brkti_free_deactivate');
     518function brkti_free_deactivate() {
     519    flush_rewrite_rules();
     520}
Note: See TracChangeset for help on using the changeset viewer.