





9,350,000 1%


لوازم خانگی
<?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;
}