if (!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 ''.esc_attr($product->get_name()).''; } 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='

'.(count($offers)>1?'Porovnání aktuálních nabídek':'Aktuální nabídka').'

Jde o partnerské odkazy. Ceny mohou být v obchodě novější. Zkontrolujte je před nákupem.

'; } public static function offers_shortcode($atts) { $a=shortcode_atts(['id'=>0],$atts,'tp_nabidky');$id=absint($a['id']); if (!$id && function_exists('is_product') && is_product()) { $id=get_the_ID(); } return $id?self::render_offers($id):''; } public static function selected_shortcode($atts) { if (!class_exists('WooCommerce')) { return ''; } $a=shortcode_atts(['pocet'=>6],$atts,'tp_vyber');$limit=min(24,max(1,absint($a['pocet']))); $query=new WP_Query(['post_type'=>'product','post_status'=>'publish','posts_per_page'=>min(100,$limit*4),'meta_query'=>[['key'=>'_tpdc_managed','value'=>'yes']]]); if (!$query->have_posts()) { return '

Ověřené produkty připravujeme. Nechceme zobrazovat neaktuální nabídky.

'; } $html='
';$shown=0; foreach ($query->posts as $post) { $list=self::current_offers($post->ID,1);if (!$list) { continue; } $p=wc_get_product($post->ID); if (!$p) { continue; } $image=$p->get_image('woocommerce_thumbnail'); $shown++;$html.='
'.$image.'

'.esc_html($p->get_name()).'

Od '.esc_html(number_format_i18n((float)$list[0]->price,0)).' Kč

Detail a nabídky
'; if ($shown >= $limit) { break; } } wp_reset_postdata();return $html.'
'; } public static function history_shortcode($atts) { $a=shortcode_atts(['id'=>0],$atts,'tp_historie');$id=absint($a['id'])?:get_the_ID(); if (!$id) { return ''; } global $wpdb;$o=self::offers_table();$p=self::prices_table(); $rows=$wpdb->get_row($wpdb->prepare("SELECT MIN(p.price) lo, MAX(p.price) hi, COUNT(*) num, MIN(p.observed_at) since FROM {$p} p INNER JOIN {$o} o ON o.id=p.offer_id WHERE o.product_id=%d AND p.observed_at >= %s",$id,gmdate('Y-m-d H:i:s',time()-30*DAY_IN_SECONDS))); if (!$rows || (int)$rows->num<2) { return '

Historii 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']);
Warning: Cannot modify header information - headers already sent by (output started at /data/web/virtuals/394039/virtual/www/domains/testproduktu.cz/wp-content/plugins/testproduktu-data-core/testproduktu-data-core.php:1) in /data/web/virtuals/394039/virtual/www/domains/testproduktu.cz/wp-includes/pluggable.php on line 1539

Warning: Cannot modify header information - headers already sent by (output started at /data/web/virtuals/394039/virtual/www/domains/testproduktu.cz/wp-content/plugins/testproduktu-data-core/testproduktu-data-core.php:1) in /data/web/virtuals/394039/virtual/www/domains/testproduktu.cz/wp-includes/pluggable.php on line 1542