[ { "id": "1234", "name": "سشوار پاناسونیک مدل X500", "url": "https://lavasemkhangi.ir/product/x500", "price": 850000, "image_url": "https://lavasemkhangi.ir/media/products/x500.jpg", "availability": true, "category": "لوازم شخصی برقی", "brand": "Panasonic", "description": "سشوار حرفه‌ای با توان 2000 وات و فناوری یونی.", "gtin": "1234567890123", "mpn": "X500", "last_update": "2026-04-30T10:45:00+03:30" } ] get_var(" SELECT MAX(UNIX_TIMESTAMP(post_modified)) FROM {$wpdb->posts} WHERE post_type='product' "); if(file_exists($cache) && (time()-filemtime($cache)<$ttl) && filemtime($cache) > $last_product_update){ readfile($cache); exit; } /* ========================= PERFORMANCE ========================= */ set_time_limit(0); ini_set('memory_limit','1024M'); /* ========================= SMART HELPERS ========================= */ function tr_clean($t){ return trim(preg_replace('/\s+/',' ',wp_strip_all_tags($t))); } function tr_price($p){ $p=floatval($p); if($p<=0) return 0; return intval(round($p/500)*500); } function tr_smart_title($product){ $title = $product->get_name(); $brand = $product->get_attribute('pa_brand'); $model = $product->get_sku(); $base = []; if($brand) $base[] = $brand; $base[] = $title; if($model) $base[] = $model; $remove=['خرید','قیمت','اورجینال','بهترین','جدید']; $out = str_replace($remove,'',' '.implode(' ',$base)); return tr_clean($out); } function tr_category_map($id){ $terms = get_the_terms($id,'product_cat'); if(!$terms) return 'عمومی'; $map = [ 'موبایل' => 'کالای دیجیتال > موبایل', 'لپ تاپ' => 'کالای دیجیتال > لپ‌تاپ', 'هدفون' => 'کالای دیجیتال > هدفون', 'ساعت هوشمند' => 'گجت > ساعت هوشمند' ]; $name = $terms[0]->name; return $map[$name] ?? $name; } function tr_image($id){ $img = wp_get_attachment_url(get_post_thumbnail_id($id)); return $img ?: site_url('/wp-content/uploads/default.jpg'); } function tr_gtin($p){ return $p->get_meta('_gtin') ?: $p->get_meta('_barcode'); } /* ========================= QUERY (LIGHT) ========================= */ $rows = $wpdb->get_results(" SELECT ID FROM {$wpdb->posts} WHERE post_type='product' AND post_status='publish' "); /* ========================= STREAM XML ========================= */ $fp = fopen($tmp,'w'); fwrite($fp,"\n\n"); $used=[]; foreach($rows as $r){ $product = wc_get_product($r->ID); if(!$product) continue; $brand = tr_clean($product->get_attribute('pa_brand')); $cat = tr_category_map($r->ID); $img = tr_image($r->ID); $url = get_permalink($r->ID); $items = []; if($product->is_type('variable')){ $items = $product->get_available_variations(); }else{ $items[]=['variation_id'=>$r->ID]; } foreach($items as $it){ $p = isset($it['variation_id']) && $it['variation_id']!=$r->ID ? wc_get_product($it['variation_id']) : $product; if(!$p || !$p->is_in_stock()) continue; $price = tr_price($p->get_price()); if($price<=0) continue; $id = $p->get_id(); if(isset($used[$id])) continue; $title = tr_smart_title($p); $sku = $p->get_sku(); $gtin = tr_gtin($p); fwrite($fp,"\n"); fwrite($fp,"{$id}\n"); fwrite($fp,"\n"); if($brand) fwrite($fp,"\n"); fwrite($fp,"\n"); fwrite($fp,"{$price}\n"); fwrite($fp,"IRR\n"); fwrite($fp,"{$url}\n"); fwrite($fp,"{$img}\n"); if($sku) fwrite($fp,"{$sku}\n"); if($gtin) fwrite($fp,"{$gtin}\n"); fwrite($fp,"instock\n"); fwrite($fp,"".get_bloginfo('name')."\n"); fwrite($fp,"\n"); $used[$id]=true; } } fwrite($fp,""); fclose($fp); /* ========================= ATOMIC SAVE ========================= */ if(file_exists($tmp) && filesize($tmp)>500){ rename($tmp,$cache); readfile($cache); }else if(file_exists($cache)){ readfile($cache); }
جستجو در محصولات
کالایی در این صفحه موجود نیست
    پروفایلسبد خریددسته‌بندیخانه