feed-builder/ build.php ← اسکریپت اصلی torob-feed.xml google-feed.xml feed-log.txt last-hash.txt createElement($tag); $el->appendChild($dom->createTextNode($value)); $parent->appendChild($el); } // ======================================= // ساخت فید ترب // ======================================= $dom_torob = new DOMDocument("1.0", "UTF-8"); $dom_torob->formatOutput = true; $root_torob = $dom_torob->createElement("products"); foreach ($products as $p) { if (($p['status'] ?? "") !== "active") continue; if (($p['stock'] ?? 0) <= 0) continue; $item = $dom_torob->createElement("product"); xml_add($dom_torob, $item, "id", $p['id']); xml_add($dom_torob, $item, "name", $p['title']); xml_add($dom_torob, $item, "price", $p['price']); xml_add($dom_torob, $item, "brand", $p['brand']); xml_add($dom_torob, $item, "category", $p['category']); xml_add($dom_torob, $item, "url", $p['link']); xml_add($dom_torob, $item, "image", $p['image']); xml_add($dom_torob, $item, "availability", "instock"); $root_torob->appendChild($item); } $dom_torob->appendChild($root_torob); $dom_torob->save($torob_feed_file); log_msg("INFO", "Torob feed generated."); // ======================================= // ساخت فید گوگل (Google Merchant Center) // ======================================= $dom_google = new DOMDocument("1.0", "UTF-8"); $dom_google->formatOutput = true; $rss = $dom_google->createElement("rss"); $rss->setAttribute("version", "2.0"); $rss->setAttribute("xmlns:g", "http://base.google.com/ns/1.0"); $channel = $dom_google->createElement("channel"); xml_add($dom_google, $channel, "title", "LavasemKhangi Feed"); xml_add($dom_google, $channel, "link", "https://lavasemkhangi.ir"); xml_add($dom_google, $channel, "description", "Google Feed for store"); foreach ($products as $p) { if (($p['status'] ?? "") !== "active") continue; if (($p['stock'] ?? 0) <= 0) continue; $item = $dom_google->createElement("item"); xml_add($dom_google, $item, "g:id", $p['id']); xml_add($dom_google, $item, "g:title", $p['title']); xml_add($dom_google, $item, "g:description", $p['title']); xml_add($dom_google, $item, "g:link", $p['link']); xml_add($dom_google, $item, "g:image_link", $p['image']); xml_add($dom_google, $item, "g:brand", $p['brand']); xml_add($dom_google, $item, "g:price", $p['price'] . " IRR"); xml_add($dom_google, $item, "g:availability", "in stock"); $channel->appendChild($item); } $rss->appendChild($channel); $dom_google->appendChild($rss); $dom_google->save($google_feed_file); log_msg("INFO", "Google feed generated."); // ======================================= // ارسال به ترب // ======================================= $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $torob_api, CURLOPT_POST => true, CURLOPT_POSTFIELDS => [ 'feed_file' => new CURLFile($torob_feed_file) ], CURLOPT_RETURNTRANSFER => true ]); $res = curl_exec($ch); $err = curl_error($ch); curl_close($ch); if ($err) { log_msg("ERROR", "Torob upload failed: $err"); exit("Torob upload error"); } log_msg("INFO", "Torob feed uploaded. Response: $res"); // ======================================= // پینگ گوگل → اطلاع‌رسانی بروزرسانی فید // ======================================= $google_ping = "https://www.google.com/ping?sitemap=" . urlencode("https://lavasemkhangi.ir/google-feed.xml"); file_get_contents($google_ping); log_msg("INFO", "Google Merchant ping sent."); echo "Feed updated, uploaded to Torob, and Google notified."; ?> connect_error){ die("Connection failed: " . $conn->connect_error); } $conn->set_charset("utf8"); // ------------------ گرفتن محصولات ------------------ $sql = "SELECT * FROM products WHERE status=1"; $result = $conn->query($sql); // ------------------ ایجاد فید شبانه ------------------ $file = fopen("torob-feed-power.php","w"); // بازنویسی فایل اصلی fwrite($file, "';\n"); fwrite($file, "echo '';\n"); while($row = $result->fetch_assoc()){ $link = "https://lavasemkhangi.ir/product/".$row['slug']; $title = str_replace(['خرید','ارزان','اصل','اورجینال','قیمت','جدید','ارسال سریع','با گارانتی'],'',$row['title']); preg_match('/[A-Za-z0-9\-]{3,}/', $title, $matches); $model = $matches[0] ?? ''; $final_title = $row['brand'].' '.$title; if($model != '') $final_title .= ' مدل '.$model; $productXML = " {$row['id']} {$link} https://lavasemkhangi.ir/uploads/{$row['image']} {$row['price']} IRR ".($row['stock']>0?'in stock':'out of stock')." \n"; fwrite($file, "echo '".addslashes($productXML)."';\n"); } fwrite($file, "echo '';\n"); fwrite($file, "?>"); fclose($file); $conn->close(); ?> getMessage()); } // گرفتن محصولات فعال $stmt = $pdo->prepare("SELECT id, name, price, stock, description, image, category, brand FROM products WHERE status='active'"); $stmt->execute(); $products = $stmt->fetchAll(PDO::FETCH_ASSOC); // شروع XML echo ''; echo ""; foreach($products as $p) { echo ""; echo "{$p['id']}"; echo ""; echo "{$p['price']}"; echo "{$p['stock']}"; echo "https://lavasemkhangi.ir/product.php?id={$p['id']}"; echo "{$p['image']}"; echo ""; echo ""; echo ""; echo ""; } echo ""; ?>
جاروبرقی بوش BGL8PRO5 اصل آلمان | 1800 وات | 5 لیتری | HEPA | کم‌صدا | ارسال فوری
23,320,000
خردکن دالتون دو کاسه | قیمت روز + خرید خردکن Dalton با موتور قدرتمند
4,620,000
null
خردکن فیلیپس philips حجم 3.8 لیتری 6 تیغه
3,850,000
🍟 سرخ‌کن ۱۵ لیتری Silver Cerast | مدل SC‑8040 | تبلتی، دو المنت، پریز ۳ شاخه
9,790,000
null
خردکن سیلور کرست 2 کاسه 3.8 لیتری
3,850,000
💓💓 سرخ‌کن بدون روغن گاسونیک مدل 847 💓💓

9,350,000 1%

9,240,000
خردکن برقی سان لایف ۳.۳ لیتر | ۶ تیغه استیل | کاسه پیرکس | ۱۸۰۰ وات | مناسب سبزیجات، میوه، آجیل و گوشت
3,300,000
سرویس پذیراییناموجود

لوازم خانگی

<?php

/* =====================================================

   Intelligent Feed Generator for Torob + Google Merchant

   Optimized & Auto‑Update with Hash Cache

   Author: YourSystem

===================================================== */

 

// ========================

// تنظیمات

// ========================

$mixins_json_url = "https://lavasemkhangi.ir/mixin-products.json";

$torob_api = "https://seller.torob.com/api/upload_feed?token=YOUR_API_TOKEN";

 

$torob_feed_file = __DIR__ . "/torob-feed.xml";

$google_feed_file = __DIR__ . "/google-feed.xml";

$log_file = __DIR__ . "/feed-log.txt";

$hash_file = __DIR__ . "/last-hash.txt";

 

 

// ========================

// تابع لاگ‌نویسی سطحی

// ========================

function log_msg($level, $msg) {

    global $log_file;

    $line = "[" . date("Y-m-d H:i:s") . "] [$level] $msg\n";

    file_put_contents($log_file, $line, FILE_APPEND);

}

 

 

// ========================

// دریافت JSON محصولات

// ========================

$json = @file_get_contents($mixins_json_url);

 

if ($json === false) {

    log_msg("ERROR", "Cannot fetch JSON.");

    exit("JSON fetch failed.");

}

 

$products = json_decode($json, true);

if (!is_array($products)) {

    log_msg("ERROR", "Invalid JSON structure.");

    exit("JSON invalid.");

}

 

 

// ========================

// کش هوشمند برای جلوگیری از کار اضافه

// ========================

$new_hash = md5($json);

$old_hash = file_exists($hash_file) ? trim(file_get_contents($hash_file)) : "";

 

if ($new_hash === $old_hash) {

    log_msg("INFO", "No data change. Skip build.");

    exit("No change — skip");

}

 

file_put_contents($hash_file, $new_hash);

log_msg("INFO", "Changes detected — rebuilding feeds.");

 

 

// ========================

// تابع کمک‌ساز XML

// ========================

function xml_add($dom, $parent, $tag, $value) {

    $el = $dom->createElement($tag);

    $el->appendChild($dom->createTextNode($value));

    $parent->appendChild($el);

}

 

 

// =====================================================

// ساخت فید مخصوص ترب

// =====================================================

$dom_t = new DOMDocument("1.0", "UTF-8");

$dom_t->formatOutput = true;

$root_t = $dom_t->createElement("products");

 

foreach ($products as $p) {

 

    if (($p['status'] ?? "") !== "active") continue;

    if (($p['stock'] ?? 0) <= 0) continue;

 

    $item = $dom_t->createElement("product");

 

    xml_add($dom_t, $item, "id", $p['id']);

    xml_add($dom_t, $item, "name", $p['title']);

    xml_add($dom_t, $item, "price", $p['price']);

    xml_add($dom_t, $item, "brand", $p['brand']);

    xml_add($dom_t, $item, "category", $p['category']);

    xml_add($dom_t, $item, "url", $p['link']);

    xml_add($dom_t, $item, "image", $p['image']);

    xml_add($dom_t, $item, "availability", "instock");

 

    $root_t->appendChild($item);

}

 

$dom_t->appendChild($root_t);

$dom_t->save($torob_feed_file);

log_msg("INFO", "Torob feed generated.");

 

 

// =====================================================

// ساخت فید گوگل Merchant Center

// =====================================================

$dom_g = new DOMDocument("1.0", "UTF-8");

$dom_g->formatOutput = true;

 

$rss = $dom_g->createElement("rss");

$rss->setAttribute("version", "2.0");

$rss->setAttribute("xmlns:g", "http://base.google.com/ns/1.0");

 

$channel = $dom_g->createElement("channel");

 

xml_add($dom_g, $channel, "title", "LavasemKhangi Product Feed");

xml_add($dom_g, $channel, "link", "https://lavasemkhangi.ir");

xml_add($dom_g, $channel, "description", "Google Shopping Feed");

 

foreach ($products as $p) {

 

    if (($p['status'] ?? "") !== "active") continue;

    if (($p['stock'] ?? 0) <= 0) continue;

 

    $item = $dom_g->createElement("item");

 

    xml_add($dom_g, $item, "g:id", $p['id']);

    xml_add($dom_g, $item, "g:title", $p['title']);

    xml_add($dom_g, $item, "g:description", $p['title']);

    xml_add($dom_g, $item, "g:link", $p['link']);

    xml_add($dom_g, $item, "g:image_link", $p['image']);

    xml_add($dom_g, $item, "g:brand", $p['brand']);

    xml_add($dom_g, $item, "g:price", $p['price'] . " IRR");

    xml_add($dom_g, $item, "g:availability", "in stock");

 

    $channel->appendChild($item);

}

 

$rss->appendChild($channel);

$dom_g->appendChild($rss);

$dom_g->save($google_feed_file);

 

log_msg("INFO", "Google feed generated.");

 

 

// =====================================================

// آپلود خودکار فید به ترب

// =====================================================

$ch = curl_init();

curl_setopt_array($ch, [

    CURLOPT_URL => $torob_api,

    CURLOPT_POST => true,

    CURLOPT_POSTFIELDS => [

        'feed_file' => new CURLFile($torob_feed_file)

    ],

    CURLOPT_RETURNTRANSFER => true

]);

 

$response = curl_exec($ch);

$error = curl_error($ch);

curl_close($ch);

 

if ($error) {

    log_msg("ERROR", "Torob upload failed: $err<?php

/* =====================================================

   Intelligent Feed Generator for Torob + Google Merchant

   Optimized & Auto‑Update with Hash Cache

   Author: YourSystem

===================================================== */

 

// ========================

// تنظیمات

// ========================

$mixins_json_url = "https://lavasemkhangi.ir/mixin-products.json";

$torob_api = "https://seller.torob.com/api/upload_feed?token=YOUR_API_TOKEN";

 

$torob_feed_file = __DIR__ . "/torob-feed.xml";

$google_feed_file = __DIR__ . "/google-feed.xml";

$log_file = __DIR__ . "/feed-log.txt";

$hash_file = __DIR__ . "/last-hash.txt";

 

 

// ========================

// تابع لاگ‌نویسی سطحی

// ========================

function log_msg($level, $msg) {

    global $log_file;

    $line = "[" . date("Y-m-d H:i:s") . "] [$level] $msg\n";

    file_put_contents($log_file, $line, FILE_APPEND);

}

 

 

// ========================

// دریافت JSON محصولات

// ========================

$json = @file_get_contents($mixins_json_url);

 

if ($json === false) {

    log_msg("ERROR", "Cannot fetch JSON.");

    exit("JSON fetch failed.");

}

 

$products = json_decode($json, true);

if (!is_array($products)) {

    log_msg("ERROR", "Invalid JSON structure.");

    exit("JSON invalid.");

}

 

 

// ========================

// کش هوشمند برای جلوگیری از کار اضافه

// ========================

$new_hash = md5($json);

$old_hash = file_exists($hash_file) ? trim(file_get_contents($hash_file)) : "";

 

if ($new_hash === $old_hash) {

    log_msg("INFO", "No data change. Skip build.");

    exit("No change — skip");

}

 

file_put_contents($hash_file, $new_hash);

log_msg("INFO", "Changes detected — rebuilding feeds.");

 

 

// ========================

// تابع کمک‌ساز XML

// ========================

function xml_add($dom, $parent, $tag, $value) {

    $el = $dom->createElement($tag);

    $el->appendChild($dom->createTextNode($value));

    $parent->appendChild($el);

}

 

 

// =====================================================

// ساخت فید مخصوص ترب

// =====================================================

$dom_t = new DOMDocument("1.0", "UTF-8");

$dom_t->formatOutput = true;

$root_t = $dom_t->createElement("products");

 

foreach ($products as $p) {

 

    if (($p['status'] ?? "") !== "active") continue;

    if (($p['stock'] ?? 0) <= 0) continue;

 

    $item = $dom_t->createElement("product");

 

    xml_add($dom_t, $item, "id", $p['id']);

    xml_add($dom_t, $item, "name", $p['title']);

    xml_add($dom_t, $item, "price", $p['price']);

    xml_add($dom_t, $item, "brand", $p['brand']);

    xml_add($dom_t, $item, "category", $p['category']);

    xml_add($dom_t, $item, "url", $p['link']);

    xml_add($dom_t, $item, "image", $p['image']);

    xml_add($dom_t, $item, "availability", "instock");

 

    $root_t->appendChild($item);

}

 

$dom_t->appendChild($root_t);

$dom_t->save($torob_feed_file);

log_msg("INFO", "Torob feed generated.");

 

 

// =====================================================

// ساخت فید گوگل Merchant Center

// =====================================================

$dom_g = new DOMDocument("1.0", "UTF-8");

$dom_g->formatOutput = true;

 

$rss = $dom_g->createElement("rss");

$rss->setAttribute("version", "2.0");

$rss->setAttribute("xmlns:g", "http://base.google.com/ns/1.0");

 

$channel = $dom_g->createElement("channel");

 

xml_add($dom_g, $channel, "title", "LavasemKhangi Product Feed");

xml_add($dom_g, $channel, "link", "https://lavasemkhangi.ir");

xml_add($dom_g, $channel, "description", "Google Shopping Feed");

 

foreach ($products as $p) {

 

    if (($p['status'] ?? "") !== "active") continue;

    if (($p['stock'] ?? 0) <= 0) continue;

 

    $item = $dom_g->createElement("item");

 

    xml_add($dom_g, $item, "g:id", $p['id']);

    xml_add($dom_g, $item, "g:title", $p['title']);

    xml_add($dom_g, $item, "g:description", $p['title']);

    xml_add($dom_g, $item, "g:link", $p['link']);

    xml_add($dom_g, $item, "g:image_link", $p['image']);

    xml_add($dom_g, $item, "g:brand", $p['brand']);

    xml_add($dom_g, $item, "g:price", $p['price'] . " IRR");

    xml_add($dom_g, $item, "g:availability", "in stock");

 

    $channel->appendChild($item);

}

 

$rss->appendChild($channel);

$dom_g->appendChild($rss);

$dom_g->save($google_feed_file);

 

log_msg("INFO", "Google feed generated.");

 

 

// =====================================================

// آپلود خودکار فید به ترب

// =====================================================

$ch = curl_init();

curl_setopt_array($ch, [

    CURLOPT_URL => $torob_api,

    CURLOPT_POST => true,

    CURLOPT_POSTFIELDS => [

        'feed_file' => new CURLFile($torob_feed_file)

    ],

    CURLOPT_RETURNTRANSFER => true

]);

 

$response = curl_exec($ch);

$error = curl_error($ch);

curl_close($ch);

 

if ($error) {

    log_msg("ERROR", "Torob upload failed: $error");

    exit("Torob upload failed.");

}

 

log_msg("INFO", "Torob upload OK. Response: $response");

 

 

// =====================================================

// پینگ خودکار گوگل جهت بروزرسانی

// =====================================================

$ping_url = "https://www.google.com/ping?sitemap=" . urlencode("https://lavasemkhangi.ir/google-feed.xml");

@file_get_contents($ping_url);

log_msg("INFO", "Google ping sent.");

 

echo "Feed built, uploaded to Torob, and Google notified.";

?>

 

 

const response = await fetch(seoApiUrl, {

                method: "POST",

                headers: { "Content-Type": "application/json" },

                body: JSON.stringify(productDataForApi)

            });

 

            if (response.ok) {

                const seoData = await response.json();

 

                // آپدیت متا دیکریپشن و کلمات کلیدی

                let metaDesc = document.querySelector('meta[name="description"]');

                if (!metaDesc) {

                    metaDesc = document.createElement("meta");

                    metaDesc.name = "description";

                    document.head.appendChild(metaDesc);

                }

                metaDesc.content = seoData.meta_description || pageDescription; // استفاده از متا تولید شده یا قبلی

 

                let metaKeywords = document.querySelector('meta[name="keywords"]');

                if (!metaKeywords) {

                    metaKeywords = document.createElement("meta");

                    metaKeywords.name = "keywords";

                    document.head.appendChild(metaKeywords);

                }

                metaKeywords.content = seoData.seo_keywords || ""; // اضافه کردن کلمات کلیدی

 

                // آپدیت OG Description اگر API توضیحات بهتری داد

                if (seoData.description) {

                    setOGMeta("og:description", seoData.description);

                    pageDescription = seoData.description; // برای استفاده در اسکیما

                }

 

                // --- افزودن Schema Markup برای محصول ---

                const productSchema = {

                    "@context": "https://schema.org",

                    "@type": "Product",

                    "name": pageTitle,

                    "image": pageImage ? [pageImage] : [], // تصویر باید در آرایه باشد

                    "description": pageDescription,

                    "sku": seoData.sku || "", // اگر API کد SKU داد

                    "brand": {

                        "@type": "Brand",

                        "name": seoData.brand_name || "نام برند" // اگر API اسم برند داد

                    },

                    "offers": {

                        "@type": "Offer",

                        "url": url,

                        "priceCurrency": "IRR", // یا IRT

                        "price": price seoData.price "", // اول قیمت استخراج شده، بعد از API، یا خالی

                        "availability": "https://schema.org/InStock", // فرض بر موجود بودن

                        "seller": { // اضافه کردن اطلاعات فروشنده

                            "@type": "Organization",

                            "name": "نام فروشگاه شما", // اسم فروشگاه خودتان را اینجا بگذارید

                            "url": window.location.origin // آدرس سایت شما

                        }

                    },

                    // اضافه کردن ویژگی‌های دیگر محصول اگر از API گرفتید

                    // "color": seoData.color,

                    // "material": seoData.material,

                };

 

                // حذف فیلدهای خالی از اسکیما

                Object.keys(productSchema).forEach(key => {

                    if (productSchema[key] === "" || (typeof productSchema[key] === 'object' && Object.keys(productSchema[key]).length === 0 && key !== 'image')) {

                        delete productSchema[key];

                    }

                });

                 Object.keys(productSchema.offers).forEach(key => {

                    if (productSchema.offers[key] === "" || (typeof productSchema.offers[key] === 'object' && Object.keys(productSchema.offers[key]).length === 0)) {

                        delete productSchema.offers[key];

                    }

                });

                 if (productSchema.offers.seller && Object.keys(productSchema.offers.seller).length === 0) {

                    delete productSchema.offers.seller;

                }

OK. Response: $response");

 

 

// =====================================================

// پینگ خودکار گوگل جهت بروزرسانی

// =====================================================

$ping_url = "https://www.google.com/ping?sitemap=" . urlencode("https://lavasemkhangi.ir/google-feed.xml");

@file_get_contents($ping_url);

log_msg("INFO", "Google ping sent.");

 

echo "Feed built, uploaded to Torob, and Google notified.";

?>

 

 

const response = await fetch(seoApiUrl, {

                method: "POST",

                headers: { "Content-Type": "application/json" },

                body: JSON.stringify(productDataForApi)

            });

 

            if (response.ok) {

                const seoData = await response.json();

 

                // آپدیت متا دیکریپشن و کلمات کلیدی

                let metaDesc = document.querySelector('meta[name="description"]');

                if (!metaDesc) {

                    metaDesc = document.createElement("meta");

                    metaDesc.name = "description";

                    document.head.appendChild(metaDesc);

                }

                metaDesc.content = seoData.meta_description || pageDescription; // استفاده از متا تولید شده یا قبلی

 

                let metaKeywords = document.querySelector('meta[name="keywords"]');

                if (!metaKeywords) {

                    metaKeywords = document.createElement("meta");

                    metaKeywords.name = "keywords";

                    document.head.appendChild(metaKeywords);

                }

                metaKeywords.content = seoData.seo_keywords || ""; // اضافه کردن کلمات کلیدی

 

                // آپدیت OG Description اگر API توضیحات بهتری داد

                if (seoData.description) {

                    setOGMeta("og:description", seoData.description);

                    pageDescription = seoData.description; // برای استفاده در اسکیما

                }

 

                // --- افزودن Schema Markup برای محصول ---

                const productSchema = {

                    "@context": "https://schema.org",

                    "@type": "Product",

                    "name": pageTitle,

                    "image": pageImage ? [pageImage] : [], // تصویر باید در آرایه باشد

                    "description": pageDescription,

                    "sku": seoData.sku || "", // اگر API کد SKU داد

                    "brand": {

                        "@type": "Brand",

                        "name": seoData.brand_name || "نام برند" // اگر API اسم برند داد

                    },

                    "offers": {

                        "@type": "Offer",

                        "url": url,

                        "priceCurrency": "IRR", // یا IRT

                        "price": price seoData.price "", // اول قیمت استخراج شده، بعد از API، یا خالی

                        "availability": "https://schema.org/InStock", // فرض بر موجود بودن

                        "seller": { // اضافه کردن اطلاعات فروشنده

                            "@type": "Organization",

                            "name": "نام فروشگاه شما", // اسم فروشگاه خودتان را اینجا بگذارید

                            "url": window.location.origin // آدرس سایت شما

                        }

                    },

                    // اضافه کردن ویژگی‌های دیگر محصول اگر از API گرفتید

                    // "color": seoData.color,

                    // "material": seoData.material,

                };

 

                // حذف فیلدهای خالی از اسکیما

                Object.keys(productSchema).forEach(key => {

                    if (productSchema[key] === "" || (typeof productSchema[key] === 'object' && Object.keys(productSchema[key]).length === 0 && key !== 'image')) {

                        delete productSchema[key];

                    }

                });

                 Object.keys(productSchema.offers).forEach(key => {

                    if (productSchema.offers[key] === "" || (typeof productSchema.offers[key] === 'object' && Object.keys(productSchema.offers[key]).length === 0)) {

                        delete productSchema.offers[key];

                    }

                });

                 if (productSchema.offers.seller && Object.keys(productSchema.offers.seller).length === 0) {

                    delete productSchema.offers.seller;

                }

برگشت به بالا