'.esc_html($p->get_name()).'
Od '.esc_html(number_format_i18n((float)$list[0]->price,0)).' Kč
Detail a nabídkyif (!empty($source['catalog']) && class_exists('TP_Sencor_Catalog')) { TP_Sencor_Catalog::enrich_product($product_id,$row); }
if (self::is_sencor($source)) {
$sale=(float)($row['sale_price']??0);
$base=(float)($row['price']??0);
if ($sale>0 && $base>0 && $sale<$base) { update_post_meta($product_id,'_tpdc_feed_sale_price',round($sale,2)); }
else { delete_post_meta($product_id,'_tpdc_feed_sale_price'); }
}
$touched[$product_id]=true;
}
foreach (array_keys($touched) as $product_id) { self::refresh_product($product_id); }
return 'Zdroj '.sanitize_key($source_id).': '.count($items).' nabídek, '.$new.' nových konceptů, '.$updated.' aktualizovaných, '.$ignored.' přeskočeno.';
}
private static function current_offers($product_id,$limit=10) {
global $wpdb;$offers=self::offers_table();
$cutoff=gmdate('Y-m-d H:i:s',time()-48*HOUR_IN_SECONDS);
return $wpdb->get_results($wpdb->prepare("SELECT * FROM {$offers} WHERE product_id=%d AND available=1 AND currency='CZK' AND checked_at >= %s ORDER BY price ASC LIMIT %d",(int)$product_id,$cutoff,(int)$limit));
}
private static function refresh_product($product_id) {
if (get_post_meta($product_id,'_tpdc_managed',true)!=='yes') { return; }
$p=wc_get_product($product_id); if (!$p || !$p->is_type('external')) { return; }
$best=self::current_offers($product_id,1);
if ($best) {
$regular=(float)$best[0]->price;
$sale=(float)get_post_meta($product_id,'_tpdc_feed_sale_price',true);
$p->set_regular_price((string)$regular);
if ($sale>0 && $sale<$regular) { $p->set_sale_price((string)$sale);$p->set_price((string)$sale); }
else { $p->set_sale_price('');$p->set_price((string)$regular); }
$p->set_product_url($best[0]->offer_url);$p->set_stock_status('instock');
}
else { $p->set_stock_status('outofstock'); }
$p->save();
}
public static function block_stale_purchase($purchasable, $product) {
if ($product && get_post_meta($product->get_id(), '_tpdc_managed', true) === 'yes') {
return $purchasable && (bool) self::current_offers($product->get_id(), 1);
}
return $purchasable;
}
public static function stale_price_html($html, $product) {
if ($product && get_post_meta($product->get_id(), '_tpdc_managed', true) === 'yes' && !self::current_offers($product->get_id(), 1)) {
return 'Cena momentálně není ověřena';
}
return $html;
}
public static function feed_product_image($image, $product, $size, $attr, $placeholder) {
if (!$product || $product->get_image_id() || get_post_meta($product->get_id(), '_tpdc_managed', true) !== 'yes') { return $image; }
$offers=self::current_offers($product->get_id(), 1);
if (!$offers || !$offers[0]->image_url) { return $image; }
$src=esc_url($offers[0]->image_url);
if (!$src) { return $image; }
return '';
}
public static function product_offers() {
if (!function_exists('is_product') || !is_product()) { return; }
global $product; if (!$product || get_post_meta($product->get_id(),'_tpdc_managed',true)!=='yes') { return; }
echo self::render_offers($product->get_id());
}
private static function render_offers($product_id) {
$offers=self::current_offers($product_id);
if (!$offers) { return '
Aktuální dostupná nabídka zatím není ověřena.
'; } $html='Jde o partnerské odkazy. Ceny mohou být v obchodě novější. Zkontrolujte je před nákupem.
Ověřené produkty připravujeme. Nechceme zobrazovat neaktuální nabídky.
'; } $html='Od '.esc_html(number_format_i18n((float)$list[0]->price,0)).' Kč
Detail a nabídkyHistorii cen teprve sbíráme. Zatím nemáme dost údajů.
'; } return 'Za posledních 30 dní ze zaznamenaných nabídek: minimum '.esc_html(number_format_i18n($rows->lo,0)).' Kč, maximum '.esc_html(number_format_i18n($rows->hi,0)).' Kč. Historie je úplná až po 30 dnech sběru.
'; } } register_activation_hook(__FILE__,['TP_Data_Core','activate']); register_deactivation_hook(__FILE__,['TP_Data_Core','deactivate']); require_once __DIR__ . '/includes/sencor-catalog.php'; require_once __DIR__ . '/includes/sencor-gallery.php'; require_once __DIR__ . '/includes/fast-gallery.php'; require_once __DIR__ . '/includes/sencor-publish.php'; require_once __DIR__ . '/includes/admin-overview.php'; require_once __DIR__ . '/includes/dognet-tesla.php'; add_action('plugins_loaded',['TP_Data_Core','boot']);