=== Futurecode Bayi Portalı for WooCommerce ===
Contributors: futurecodetr
Tags: b2b, dealer, wholesale, price list, quote
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 7.4
Requires Plugins: woocommerce
Stable tag: 1.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

B2B dealer portal: dealer applications with VKN check, group prices, hidden prices, minimum orders, quotes and quick order.

== Description ==

**English**

Bayi Portalı ("dealer portal") turns your WooCommerce shop into a B2B shop for your dealers, next to your normal retail shop. Companies apply with their tax number, you approve them into a dealer group, and from then on they see their own prices, order by SKU and ask for quotes.

**Features**

* **Dealer application:** form with company name, tax number (VKN, checked with the official algorithm; sole proprietors can use their T.C. identity number), tax office, contact person, phone, e-mail and address. Add it with the *Dealer application form* block or the `[fcbp_bayi_basvuru]` shortcode. You get an e-mail about every new application; pending applications are counted on the menu and the dashboard.
* **Approval screen:** filter, search, approve or reject with a note, choose the dealer group, bulk approve / reject / assign group. Approval creates the account if needed (the applicant sets the password from the e-mail) and gives the *Dealer* role. Applicants get an approval or rejection e-mail.
* **Dealer groups (A / B / C …):** each group has a discount percentage, a minimum order amount and a minimum quantity.
* **Dealer prices** with a clear order of precedence:
  1. **Product / variation price** — a fixed price per group on the product or on each variation (a variation without its own price uses its parent's);
  2. **Category rule** — percent off, amount off or a fixed price per group for a category and its sub-categories (when several match, the lowest price wins);
  3. **Group discount** — percent off the regular price.
  A dealer price is never higher than an active sale price.
* **Price list CSV (by SKU):** export, import and template; Turkish and English number formats; Excel-friendly (semicolon, UTF-8). Prices can also be edited in a table on the *Price list* tab or on the product screen.
* **Price display:** hide prices from visitors who are not logged in (or from everybody who is not a dealer) with a "Log in as a dealer to see prices" link; optionally no "add to cart" for them. Prices without VAT for dealers ("+ VAT"). List price shown crossed out next to the dealer price.
* **Order rules:** minimum order amount and quantity per group, pack size (koli / multiple) per product. Shown on the product page and checked on add to cart, in the cart and at checkout — classic and block cart / checkout.
* **Quotes:** a dealer turns the cart into a quote request. You edit quantities and prices, set a validity date and approve (or reject). The dealer gets an e-mail and turns the quote into an order with one click; the quoted prices are kept up to the order. Statuses: waiting, approved, turned into order, expired, rejected, cancelled.
* **Dealer panel in "My account":** my price list (search, CSV download), quick order (SKU + quantity rows or pasted CSV lines), my quotes and my orders. The panel uses your theme's styles.
* **Dealers tab and users screen:** dealer list with bulk group assignment; dealer group on the user profile and as a bulk action in *Users*.
* **Compatibility:** HPOS (high-performance order storage), block cart and block checkout, Store API (dealer prices also in blocks and headless shops). Every admin action shows a notification with a spinner.

**Page cache — please read:** dealer prices are personal. The plugin tells caches not to store pages for logged-in dealers (`DONOTCACHEPAGE` and no-cache headers), and WooCommerce's variation price cache is kept per group. If your cache plugin, server cache or CDN caches pages for logged-in users, exclude logged-in users (or at least the *Dealer* role); otherwise a dealer could be shown a page cached for somebody else. Pages for visitors who are not logged in can be cached as usual.

**Coming soon (separate Pro plugin, not part of this one):** payment on account (cari hesap) with credit limits, ERP price list sync, dealer account statements (ekstre). Nothing in this plugin is locked or limited by a licence.

**Türkçe**

Bayi Portalı, WooCommerce mağazanızı normal perakende satışın yanında bayileriniz için bir B2B mağazaya dönüştürür. Firmalar vergi numarasıyla başvurur, siz onları bir bayi grubuna onaylarsınız; o andan itibaren kendi fiyatlarını görür, stok koduyla sipariş verir ve teklif isterler.

**Özellikler**

* **Bayi başvurusu:** firma adı, resmî algoritmayla doğrulanan vergi kimlik numarası (VKN; şahıs şirketleri T.C. kimlik numarasıyla), vergi dairesi, yetkili, telefon, e-posta ve adres alanlı form. *Bayi başvuru formu* bloğuyla ya da `[fcbp_bayi_basvuru]` kısa koduyla eklenir. Her yeni başvuruda size e-posta gelir; bekleyen başvurular menüde ve başlangıç ekranında görünür.
* **Onay ekranı:** süzme, arama, notla onay ya da ret, bayi grubu seçimi, toplu onay / ret / grup atama. Onay gerekirse hesabı açar (başvuru sahibi parolasını e-postadaki bağlantıyla belirler) ve *Bayi* rolünü verir. Başvuru sahibine onay ya da ret e-postası gider.
* **Bayi grupları (A / B / C …):** her grubun indirim yüzdesi, minimum sipariş tutarı ve minimum adedi vardır.
* **Bayi fiyatları**, açık bir öncelik sırasıyla:
  1. **Ürün / varyasyon fiyatı** — üründe ya da her varyasyonda grup başına sabit fiyat (kendi fiyatı olmayan varyasyon ana ürünün fiyatını kullanır);
  2. **Kategori kuralı** — bir kategori ve alt kategorileri için grup başına yüzde indirim, tutar indirimi ya da sabit fiyat (birden çok kural uyarsa en düşük fiyat geçerli olur);
  3. **Grup indirimi** — normal fiyattan yüzde indirim.
  Bayi fiyatı, etkin bir indirimli fiyattan hiçbir zaman yüksek olmaz.
* **Fiyat listesi CSV (stok koduyla):** dışa aktarma, içe aktarma ve şablon; Türkçe ve İngilizce sayı biçimi; Excel'de doğrudan açılır (noktalı virgül, UTF-8). Fiyatlar *Fiyat listesi* sekmesindeki tabloda ya da ürün ekranında da düzenlenir.
* **Fiyat gösterimi:** giriş yapmamış ziyaretçilerden (ya da bayi olmayan herkesten) fiyatı gizleme ve yerine "Fiyat için bayi girişi yapın" bağlantısı; isterseniz bu kişiler için sepete ekleme kapalı. Bayiye KDV hariç fiyat ("+ KDV"). Liste fiyatı bayi fiyatının yanında üstü çizili.
* **Sipariş kuralları:** grup başına minimum sipariş tutarı ve adedi, ürün başına koli / çarpan adedi. Ürün sayfasında gösterilir; sepete eklemede, sepette ve ödemede denetlenir — klasik ve blok sepet / ödeme.
* **Teklif:** bayi sepeti teklif talebine çevirir. Siz adet ve fiyatları düzenler, geçerlilik tarihi koyar ve onaylarsınız (ya da reddedersiniz). Bayiye e-posta gider; teklifi tek tıkla siparişe çevirir, teklif fiyatları siparişe kadar korunur. Durumlar: bekliyor, onaylandı, siparişe dönüştü, süresi doldu, reddedildi, iptal edildi.
* **"Hesabım" altında bayi paneli:** fiyat listem (arama, CSV indirme), hızlı sipariş (stok kodu + adet satırları ya da yapıştırılan CSV), tekliflerim ve siparişlerim. Panel temanızın stilini kullanır.
* **Bayiler sekmesi ve kullanıcılar ekranı:** toplu grup atamalı bayi listesi; kullanıcı profilinde ve *Kullanıcılar* ekranında toplu işlem olarak bayi grubu.
* **Uyumluluk:** HPOS (yüksek performanslı sipariş tablosu), blok sepet ve blok ödeme, Store API (bayi fiyatları bloklarda ve headless mağazalarda da). Yönetimdeki her işlemde dönen göstergeli bildirim.

**Sayfa önbelleği — lütfen okuyun:** bayi fiyatları kişiye özeldir. Eklenti, oturum açmış bayilere giden sayfaların önbelleğe alınmamasını söyler (`DONOTCACHEPAGE` ve no-cache başlıkları); WooCommerce'in varyasyon fiyat önbelleği de gruba göre ayrı tutulur. Önbellek eklentiniz, sunucu önbelleğiniz ya da CDN'iniz oturum açmış kullanıcılara da önbellekten sayfa veriyorsa oturum açmış kullanıcıları (en azından *Bayi* rolünü) hariç tutun; yoksa bir bayiye başkası için önbelleğe alınmış sayfa gösterilebilir. Giriş yapmamış ziyaretçilerin sayfaları her zamanki gibi önbelleğe alınabilir.

**Yakında (ayrı Pro eklenti; bu eklentinin parçası değildir):** cari hesapla ödeme ve kredi limiti, ERP fiyat listesi senkronu, bayi ekstresi. Bu eklentide hiçbir özellik lisansla kilitlenmez ya da sınırlanmaz.

== External services ==

This plugin does not connect to any external service. Applications, dealer data, prices, quotes and orders stay in your own WordPress database; nothing is sent to Futurecode or to anybody else, and there is no tracking or statistics. E-mails (application, approval, rejection, quote) are sent with your site's own mail function (wp_mail) to you and to your dealers.

The "Need more?" card on the settings screen is a plain link to https://stokwerk.futurecode.com.tr/ (opened only when you click it; the card can be hidden). The Futurecode logo on the settings screen is a file inside the plugin.

**Türkçe:** Eklenti hiçbir dış servise bağlanmaz. Başvurular, bayi bilgileri, fiyatlar, teklifler ve siparişler kendi WordPress veritabanınızda kalır; Futurecode'a ya da başka birine veri gitmez, izleme ya da istatistik yoktur. E-postalar sitenizin kendi e-posta işleviyle (wp_mail) size ve bayilerinize gider. Ayarlar ekranındaki "Daha fazlası mı lazım?" kartı yalnız tıklayınca açılan bir bağlantıdır ve gizlenebilir.

== Installation ==

1. Install and activate WooCommerce, then this plugin.
2. Open *Bayi Portalı → Dealer groups*: rename the starter groups A / B / C, set their discounts, minimums and category rules.
3. Add the *Dealer application form* block (or the `[fcbp_bayi_basvuru]` shortcode) to a page.
4. On *Settings* choose how prices are shown (hidden for guests, without VAT for dealers, list price next to the dealer price) and whether quotes are on.
5. Approve applications on the *Applications* tab. Optional: fixed prices per product on the *Price list* tab or by CSV.
6. If you use a page cache, exclude logged-in users (see "Page cache" above).

**Türkçe:** WooCommerce'i ve eklentiyi etkinleştirin. *Bayi Portalı → Bayi grupları* ekranında A / B / C gruplarını adlandırın, indirim, minimum ve kategori kurallarını girin. Bir sayfaya *Bayi başvuru formu* bloğunu (ya da `[fcbp_bayi_basvuru]` kısa kodunu) ekleyin. *Ayarlar*da fiyat gösterimini ve teklifleri seçin. Başvuruları *Başvurular* sekmesinde onaylayın. Sayfa önbelleği kullanıyorsanız oturum açmış kullanıcıları hariç tutun.

== Frequently Asked Questions ==

= Hangi fiyat geçerli olur? / Which price wins? =

Önce ürün ya da varyasyondaki grup fiyatı, yoksa kategori kuralı, o da yoksa grup indirimi. Birden çok kategori kuralı uyarsa en düşük fiyat geçerlidir; bayi fiyatı etkin indirimli fiyattan yüksek olmaz. / First the group price on the product or variation, then a category rule, then the group discount. The lowest matching category rule wins; a dealer price is never above an active sale price.

= Fiyatlar KDV dahil mi? / Are prices with or without VAT? =

Bayi fiyatlarını ürün fiyatlarını girdiğiniz gibi girersiniz (WooCommerce'te "fiyatlar vergi dahil" ayarı neyse). "Bayiye KDV hariç fiyat" açıksa bayiler fiyatları KDV hariç ve "+ KDV" ekiyle görür; bunun için WooCommerce vergileri açık olmalıdır. / Enter dealer prices the same way as your product prices. With "Prices without VAT for dealers" on, dealers see prices without VAT; WooCommerce taxes must be on.

= Teklif fiyatı siparişte değişir mi? / Does the quoted price change at checkout? =

Hayır. Teklif siparişe çevrilince ürünler teklif fiyatıyla ve teklif adediyle sepete girer; adet değiştirilemez, sipariş de bu fiyatlarla oluşur. Teklifin süresi dolmuşsa sipariş verilemez. Kargo ödeme adımında eklenir. / No. The quoted items go into the cart with the quoted prices and quantities and the order keeps them. Expired quotes cannot be ordered. Shipping is added at checkout.

= Minimum sipariş tutarı neye göre hesaplanır? / How is the minimum order amount checked? =

Sepetteki ürünlerin, bayinin gördüğü şekilde (KDV dahil ya da hariç) toplamına göre; kargo dahil değildir. Onaylanmış tekliften gelen sepete grup minimumları uygulanmaz. / Against the cart's product total as the dealer sees it (with or without VAT), without shipping. Carts made from an approved quote are not checked against the group minimums.

= Önbellek eklentimle çalışır mı? / Does it work with my cache plugin? =

Evet, oturum açmış kullanıcıları önbelleğe almayan her önbellekle çalışır (çoğu eklentinin varsayılanı). Eklenti oturum açmış bayiler için `DONOTCACHEPAGE` tanımlar ve no-cache başlıkları gönderir. CDN ya da sunucu önbelleğiniz oturum açmış kullanıcıları da önbelleğe alıyorsa onları hariç tutun. / Yes, with any cache that skips logged-in users (the default of most plugins). The plugin sets `DONOTCACHEPAGE` and no-cache headers for logged-in dealers.

= Mevcut bir müşteriyi bayi yapabilir miyim? / Can I make an existing customer a dealer? =

Evet: kullanıcı profilinde "Bayi grubu" seçin ya da *Kullanıcılar* ekranında toplu işlemle gruba atayın. / Yes: choose a dealer group on the user profile or use the bulk action on the *Users* screen.

= Kaldırınca ne silinir? / What does uninstalling remove? =

Ayarlar, gruplar, kategori kuralları, başvurular, teklifler, ürünlerdeki bayi fiyatları ve koli adetleri, eklentinin kullanıcı ve sipariş alanları ve Bayi rolü (bayiler müşteri olur). Siparişler ve kullanıcı hesapları kalır. / Settings, groups, rules, applications, quotes, dealer prices and pack sizes, the plugin's user and order data and the Dealer role (dealers become customers). Orders and user accounts stay.

== Screenshots ==

1. Dealer groups: discounts, minimums, category rules and the price precedence. / Bayi grupları ve fiyat önceliği.
2. Applications: counters, filters, bulk approval and the detail panel with group and note. / Başvurular ve onay paneli.
3. Quotes: list, editable quote prices, validity date, totals and approval. / Teklif yönetimi.
4. Settings: price display, applications, quotes and order rules. / Ayarlar.
5. Price list: fixed group prices per product and variation, CSV import / export. / Fiyat listesi.
6. Dealer panel in "My account": price list, quick order, quotes and orders. / "Hesabım" altında bayi paneli.
7. Block checkout with dealer prices. / Bayi fiyatlarıyla blok ödeme sayfası.

== Changelog ==

= 1.0.1 =
* Fix: hidden prices no longer leak into the page source of block themes. Product data that WooCommerce blocks embed in the page (Interactivity API state, hydrated Store API data) loses its prices for visitors who may not see them; product JSON-LD keeps no offers.
* New: optional rounding of calculated dealer prices up to ,90 or ,99 (off by default).
* Düzeltme: gizli fiyatlar blok temalarda sayfa kaynağına sızmıyor. WooCommerce bloklarının sayfaya gömdüğü ürün verisi (Interactivity API durumu, sayfaya gömülü Store API verisi) fiyatı görmemesi gereken ziyaretçide fiyatsız; ürün JSON-LD şemasında teklif (offers) yok.
* Yeni: hesaplanan bayi fiyatına isteğe bağlı ,90 / ,99 yuvarlama (varsayılan kapalı).

= 1.0.0 =
* First release: dealer application form (block and shortcode) with VKN check, approval / rejection with e-mails and bulk actions, dealer role and groups, group discount, category rules (percent, amount, fixed), product and variation prices per group with a clear precedence, price list CSV import / export / template, hidden prices for guests or non-dealers, prices without VAT for dealers, list price next to the dealer price, minimum order amount and quantity per group, pack sizes, quotes with editable prices, validity date and one-click order with locked prices, dealer panel with price list, CSV, quick order, quotes and orders in "My account", dealer group on user profiles and bulk actions, no page cache for logged-in dealers, per-group variation price hash, HPOS, block cart / checkout and Store API compatibility.
