10 * 60,
'display' => __( 'Every 10 minutes', ATKP_PLUGIN_PREFIX )
);
return $schedules;
}
public function my_activation() {
$crontype = atkp_options::$loader->get_crontype();
switch ( $crontype ) {
default:
case 'wpcron':
//$inittime = strtotime('00:00:00');
//$key = ATKP_PLUGIN_PREFIX.'_'.(ATKPSettings::$access_cache_duration);
wp_schedule_event( time(), ATKP_PLUGIN_PREFIX . '_10', ATKP_EVENT );
//$key = ATKP_PLUGIN_PREFIX.'_'.(ATKPSettings::$notification_interval);
//wp_schedule_event( $inittime, $key, ATKP_CHECK);
//$key = ATKP_PLUGIN_PREFIX.'_'.(ATKPSettings::$access_csv_intervall);
//wp_schedule_event( $inittime, $key, ATKP_CSVIMPORT);
break;
case 'external':
case 'externaloutput':
//external cronjob? nothing todo...
break;
}
}
public function my_deactivation() {
wp_clear_scheduled_hook( ATKP_EVENT );
//wp_clear_scheduled_hook(ATKP_CHECK);
//wp_clear_scheduled_hook(ATKP_CSVIMPORT);
}
public function my_update() {
$this->my_deactivation();
$this->my_activation();
}
public function new_cronjob() {
try {
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( '*** wp internal event started ***' );
}
$crontype = atkp_options::$loader->get_crontype();
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( 'crontyp: '.$crontype );
}
switch ( $crontype ) {
default:
case 'wpcron':
//wp cron.. everything ok
$cronjob = new atkp_cronjob_new( false );
$cronjob->do_work(true);
break;
case 'external':
case 'externaloutput':
//external? nothing todo...
return;
}
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( '*** wp internal event finished ***' );
}
} catch ( Exception $e ) {
ATKPLog::LogError( $e->getMessage() );
}
}
public function do_this_weekly( $overrideSending = false ) {
try {
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( '*** cronjob for datacheck started ***' );
}
//prüfe auf shop-warnung
//prüfe auf listen und produktwarnung
//prüfe ob dynamische listen leer sind
if ( ! $overrideSending ) {
if ( ! ATKPSettings::$check_enabled ) {
return;
}
}
$recipient = ATKPSettings::$email_recipient;
if ( $recipient == '' ) {
$recipient = get_bloginfo( 'admin_email' );
}
$errors = array();
$posts_found = get_posts( array(
'posts_per_page' => 250,
'post_status' => array( 'publish', 'draft' ),
'post_type' => ATKP_SHOP_POSTTYPE,
'suppress_filters' =>true,
'meta_query' => array(
//comparison between the inner meta fields conditionals
'relation' => 'OR',
//meta field condition one
array(
'key' => ATKP_SHOP_POSTTYPE . '_access_message',
'compare' => 'EXISTS',
)
),
) );
foreach ( $posts_found as $prdpost ) {
try {
$selwebservice = ATKPTools::get_post_setting( $prdpost->ID, ATKP_SHOP_POSTTYPE . '_access_webservice' );
if ( $selwebservice != ATKP_SUBSHOPTYPE ) {
$access_test = ATKPTools::get_post_setting( $prdpost->ID, ATKP_SHOP_POSTTYPE . '_access_message' );
if ( $access_test != '' ) {
$link = '' . $prdpost->ID . '';
array_push( $errors, 'Shop ' . $prdpost->post_title . ' (' . $link . '): ' . "
" . $access_test );
}
}
} catch ( Exception $e ) {
array_push( $errors, 'Shop ' . $prdpost->post_title . ' (' . $prdpost->ID . '): ' . "
" . 'Exception ' . $e->getMessage() );
}
}
$posts_found = get_posts( array(
'posts_per_page' => 250,
'post_status' => array( 'draft', 'publish' ),
'post_type' => ATKP_PRODUCT_POSTTYPE,
'suppress_filters' =>true,
'meta_query' => array(
//comparison between the inner meta fields conditionals
'relation' => 'OR',
//meta field condition one
array(
'key' => ATKP_PRODUCT_POSTTYPE . '_message',
'compare' => 'EXISTS',
),
//meta field condition one
array(
'key' => ATKP_PRODUCT_POSTTYPE . '_woomessage',
'compare' => 'EXISTS',
)
),
) );
foreach ( $posts_found as $prdpost ) {
try {
$message = ATKPTools::get_post_setting( $prdpost->ID, ATKP_PRODUCT_POSTTYPE . '_message' );
$woomessage = ATKPTools::get_post_setting( $prdpost->ID, ATKP_PRODUCT_POSTTYPE . '_woomessage' );
if ( $message != '' ) {
$link = '' . $prdpost->ID . '';
array_push( $errors, 'Product ' . $prdpost->post_title . ' (' . $link . '): ' . "
" . $message );
}
if ( $woomessage != '' ) {
$link = '' . $prdpost->ID . '';
array_push( $errors, 'Product ' . $prdpost->post_title . ' (' . $link . '), WooCommerce: ' . "
" . $woomessage );
}
} catch ( Exception $e ) {
array_push( $errors, 'Product ' . $prdpost->post_title . ' (' . $prdpost->ID . '): ' . "
" . 'Exception ' . $e->getMessage() );
}
}
$posts_found = get_posts( array(
'posts_per_page' => 250,
'post_status' => array( 'publish', 'draft' ),
'post_type' => ATKP_LIST_POSTTYPE,
'suppress_filters' =>true,
'meta_query' => array(
//comparison between the inner meta fields conditionals
'relation' => 'OR',
//meta field condition one
array(
'key' => ATKP_LIST_POSTTYPE . '_message',
'compare' => 'EXISTS',
)
),
) );
foreach ( $posts_found as $prdpost ) {
try {
$message = ATKPTools::get_post_setting( $prdpost->ID, ATKP_LIST_POSTTYPE . '_message' );
if ( $message != '' ) {
$link = '' . $prdpost->ID . '';
array_push( $errors, 'List ' . $prdpost->post_title . ' (' . $link . '): ' . "
" . $message );
}
} catch ( Exception $e ) {
array_push( $errors, 'List ' . $prdpost->post_title . ' (' . $prdpost->ID . '): ' . "
" . 'Exception ' . $e->getMessage() );
}
}
$headers = array('From: ' . get_bloginfo( 'name' ) . ' <' . get_bloginfo( 'admin_email' ) . '>', 'Content-Type: text/html; charset=UTF-8');
//TODO: einschalten
//TODO: empfänger
//TODO: Betreff
if ( sizeof( $errors ) > 0 || $overrideSending ) {
wp_mail( $recipient, __( 'Affiliate Toolkit Report', ATKP_PLUGIN_PREFIX ), __( 'Following messages are currently stored in your records: ', ATKP_PLUGIN_PREFIX ) . "
" . implode( "
", $errors ), $headers );
};
ATKPLog::LogDebug( 'mail sent: ' . ( sizeof( $errors ) > 0 ) );
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( '*** cronjob for datacheck finished ***' );
}
} catch ( Exception $e ) {
ATKPLog::LogError( $e->getMessage() );
}
}
public function do_this_hourly() {
// do something every hour
try {
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( '*** cronjob started ***' );
}
$errors = array();
$posts_found = get_posts( array(
'posts_per_page' => 500,
'post_status' => array( 'draft', 'publish' ),
'post_type' => ATKP_PRODUCT_POSTTYPE
) );
foreach ( $posts_found as $prdpost ) {
try {
$this->update_product( $prdpost->ID, false, false, false, false, false, false, true );
//Delay damit nicht zu viele Request hintereinander kommen
//sleep(1);
} catch ( Exception $e ) {
array_push( $errors, 'Product ' . $prdpost->ID . ': ' . $e->getMessage() );
ATKPLog::LogError( $e->getMessage() );
}
}
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( '*** products updated ***' );
}
$posts_found = get_posts( array(
'posts_per_page' => 500,
'post_status' => array( 'publish', 'draft' ),
'post_type' => ATKP_LIST_POSTTYPE
) );
foreach ( $posts_found as $prdpost ) {
try {
$this->update_list( $prdpost->ID, true );
//Delay damit nicht zu viele Request hintereinander kommen
//sleep(1);
} catch ( Exception $e ) {
array_push( $errors, 'List ' . $prdpost->ID . ': ' . $e->getMessage() );
ATKPLog::LogError( $e->getMessage() );
}
}
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( '*** lists updated ***' );
}
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( '*** cronjob finished ***' );
}
} catch ( Exception $e ) {
ATKPLog::LogError( $e->getMessage() );
}
}
public function do_this_daily() {
try {
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( '*** csv cronjob for datacheck started ***' );
}
$posts_found = get_posts( array(
'posts_per_page' => 500,
'post_status' => array( 'publish', 'draft' ),
'post_type' => ATKP_SHOP_POSTTYPE,
'meta_query' => array(
array(
'key' => ATKP_SHOP_POSTTYPE . '_access_webservice',
'value' => '7',
)
)
) );
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( 'csv posts found: ' . serialize( $posts_found ) );
}
//wenn csv feeds vorhanden sind, dann initialisiere den csv cronjob.
if ( $posts_found && count( $posts_found ) > 0 ) {
foreach ( $posts_found as $csvimport ) {
try {
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( 'import csv: ' . $csvimport->ID );
}
$csvprovider = new atkp_shop_provider_csv();
$csvprovider->import_csv( $csvimport->ID, true );
unset( $csvprovider );
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( 'import finished csv: ' . $csvimport->ID );
}
} catch ( Exception $e ) {
ATKPLog::LogError( 'import csv error (' . $csvimport->ID . ') ' . $e->getMessage() );
}
}
}
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( '*** csv cronjob finished ***' );
}
} catch ( Exception $e ) {
ATKPLog::LogError( $e->getMessage() );
}
}
public function update_product( $post_id, $refreshproductinfo, $refreshpriceinfo, $refreshreviewinfo, $refreshimages, $refreshproducturl, $refreshmoreoffers, $iscron = false, $dontUpdatetitle = false ) {
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( '*** update_product ***' );
ATKPLog::LogDebug( '$post_id: ' . $post_id );
ATKPLog::LogDebug( '$iscron: ' . $iscron );
}
$refreshreviewinforegulary = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_refreshreviewinforegulary' );
$refreshpriceinforegulary = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_refreshpriceinforegulary' );
$refreshproducturlregulary = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_refreshproducturlregulary' );
$refreshimagesregulary = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_refreshimagesregulary' );
$refreshmoreoffersregulary = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_refreshmoreoffersregulary' );
$iswoocommerce = (bool) ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_iswoocommerce' );
$shopid = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_shopid' );
$asin = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_asin' );
$asintype = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_asintype' );
if ( $asintype == null || $asintype == '' ) {
$asintype = 'ASIN';
}
if ( $iscron ) {
if ( ! $refreshreviewinforegulary && ! $refreshpriceinforegulary && ! $refreshproducturlregulary && ! $refreshimagesregulary && ! $refreshmoreoffersregulary ) {
return;
}
if ( $refreshreviewinforegulary ) {
$refreshreviewinfo = true;
}
if ( $refreshpriceinforegulary ) {
$refreshpriceinfo = true;
}
if ( $refreshproducturlregulary ) {
$refreshproducturl = true;
}
if ( $refreshimagesregulary ) {
$refreshimages = true;
}
if ( $refreshmoreoffersregulary ) {
$refreshmoreoffers = true;
}
$refreshproductinfo = false;
} else {
if ( $refreshproductinfo ) {
$refreshproducturl = true;
}
}
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( '$refreshproductinfo: ' . $refreshproductinfo );
ATKPLog::LogDebug( '$refreshpriceinfo: ' . $refreshpriceinfo );
ATKPLog::LogDebug( '$refreshreviewinfo: ' . $refreshreviewinfo );
ATKPLog::LogDebug( '$refreshimages: ' . $refreshimages );
ATKPLog::LogDebug( '$refreshproducturl: ' . $refreshproducturl );
ATKPLog::LogDebug( '$refreshmoreoffers: ' . $refreshmoreoffers );
}
ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_updatedon', ATKPTools::get_current_utc() );
if ( $shopid == '' || $asin == '' ) {
//Änderung: manuelles produkt wird im normalen Zyklus aktualisiert weil es auch weitereangebote enthalten kann if(!$iscron) {
ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_message', null );
//}
} else {
if ( $refreshproductinfo == true || $refreshpriceinfo == true || $refreshreviewinfo == true || $refreshimages == true || $refreshproducturl == true ) {
try {
$shop = atkp_shop::load( $shopid );
} catch ( Exception $e ) {
$shop = null;
}
if ( $shop == null || $shop->provider == null ) {
ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_message', 'shop not found' );
return;
}
$message = $shop->provider->checklogon( $shop );
//wenn die Extension nicht geladen ist, kann das Plugin nicht arbeiten
//Wenn keine Einstellungen definiert wurden um Daten zu laden, keine Liste generieren
if ( $message != '' ) {
ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_message', 'Shop connection invalid: ' . $message );
} else {
$product = $shop->provider->retrieve_product( $asin, $asintype );
$this->xx_update( $product );
}
}
}
$manufacturer = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_manufacturer' );
$author = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_author' );
$brand = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_brand' );
$manufacturerType = atkp_options::$loader->get_product_manufacturer_taxonomy();
$authorType = atkp_options::$loader->get_product_author_taxonomy();
$brandType = atkp_options::$loader->get_product_brand_taxonomy();
ATKPTools::check_taxonomy( $post_id, $manufacturerType, $manufacturer );
ATKPTools::check_taxonomy( $post_id, $brandType, $brand );
ATKPTools::check_taxonomy( $post_id, $authorType, $author );
if ( $refreshmoreoffers == true ) {
$product = atkp_product::load( $post_id );
$this->update_offers( $product );
//ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE.'_offers', $product->offers);
}
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( 'woo export isenabled: ' . $iswoocommerce );
ATKPLog::LogDebug( 'WooCommerce installed: ' . class_exists( 'WooCommerce' ) );
}
$dontimportimage = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_dontimportmainimage' );
$importProductimage = atkp_options::$loader->get_product_importimage();
$productpageenabled = atkp_options::$loader->get_product_enabled();
$poststatus = get_post_status( $post_id );
if ( ! $dontimportimage && $importProductimage != 0 && ( $poststatus == 'publish' || $poststatus == 'draft' ) ) {
switch ( $importProductimage ) {
case 1:
//importiert das bild in die bibliothek
$title = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_title' );
$imageurl = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_largeimageurl' );
if ( $imageurl == '' ) {
$imageurl = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_mediumimageurl' );
}
if ( $imageurl == '' ) {
$imageurl = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_smallimageurl' );
}
if ( $imageurl != '' && $title != '' ) {
ATKPTools::set_featured_image( $imageurl, $title, $post_id );
}
break;
case 2:
//verlinkt das bild mit dem externen bild
$featuredimage = new atkp_external_featuredimage();
$featuredimage->set_external_postimage( $post_id );
break;
default:
throw new exception( 'unknown imagemode: ' . $importProductimage );
}
}
ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_woomessage', null );
if ( $iswoocommerce == true && atkp_options::$loader->get_woo_enabled() ) {
$mode = atkp_options::$loader->get_woo_mode();
if ( $mode != '' ) {
//if($mess == '' || $mess == null) - exportieren auch wenn fehler auftritt
try {
$export = atkp_export_provider_base::get_provider( 'woo' );
$message = $export->checklogon();
if ( $message != '' ) {
ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_woomessage', $message );
} else {
$export->export_product( $post_id );
}
} catch ( Exception $e ) {
ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_woomessage', $e->getMessage() );
}
}
}
do_action( 'atkp_product_updated', $post_id );
}
private function str_contains( $string, $array, $caseSensitive = true ) {
$strfound = false;
$containsPosFilter = false;
foreach ( $array as $txt ) {
$startswith = substr( $txt, 0, 1 );
if ( $startswith == '-' ) {
$txt = substr( $txt, 1 );
} else {
$containsPosFilter = true;
}
if ( stripos( $string, $txt ) !== false ) {
$strfound = true;
}
if ( $strfound && $startswith == '-' ) {
return false;
}
}
return $containsPosFilter ? $strfound : true;
//$stripedString = $caseSensitive ? str_replace($array, '', $string) : str_ireplace($array, '', $string);
//return strlen($stripedString) !== strlen($string);
}
public function update_list( $post_id, $iscron = false ) {
if ( ATKPLog::$logenabled ) {
ATKPLog::LogDebug( '*** update_list ***' );
ATKPLog::LogDebug( '$post_id: ' . $post_id );
}
ATKPTools::set_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_updatedon', ATKPTools::get_current_utc() );
$shopid = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_shopid' );
$productlist = array();
//listtype == dynamic list
if ( $shopid != '' ) {
try {
$shop = atkp_shop::load( $shopid );
} catch ( Exception $e ) {
$shop = null;
}
if ( $shop == null || $shop->provider == null ) {
ATKPTools::set_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_message', 'shop not found' );
return;
}
$message = $shop->provider->checklogon( $shop );
if ( $message != '' ) {
ATKPTools::set_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_message', 'Shop connection invalid: ' . $message );
} else {
$source = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_source' );
$preferlocalproduct = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_preferlocalproduct' );
$autoimportproducts = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_autoimportproducts' );
$loadmoreoffers = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_loadmoreoffers' );
$extendedsearchlimit = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_extendedsearch_limit' );
$searchlimit = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_search_limit' );
$searchttitlefilter = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_search_titelfilter' );
$searchdepartment = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_search_department' );
$searchkeyword = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_search_keyword' );
$searchorderby = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_search_orderby' );
$nodeid = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_node_id' );
$keyword = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_keyword' );
$productid = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_productid' );
$filterfield1 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filterfield1' );
$filtertext1 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filtertext1' );
$filterfield2 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filterfield2' );
$filtertext2 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filtertext2' );
$filterfield3 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filterfield3' );
$filtertext3 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filtertext3' );
$filterfield4 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filterfield4' );
$filtertext4 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filtertext4' );
$filterfield5 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filterfield5' );
$filtertext5 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filtertext5' );
$filterfield6 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filterfield6' );
$filtertext6 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filtertext6' );
$filterfield7 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filterfield7' );
$filtertext7 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filtertext7' );
$filterfield8 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filterfield8' );
$filtertext8 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filtertext8' );
$filterfield9 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filterfield9' );
$filtertext9 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filtertext9' );
$filterfield10 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filterfield10' );
$filtertext10 = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_filtertext10' );
try {
ATKPTools::set_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_node_caption', '' );
$requestType = 'Search';
$sortOrder = '';
$keyword = '';
$maxCount = 20;
$asin = '';
$filter = array();
$producttitle = '';
switch ( $source ) {
case 10:
$requestType = 'TopSellers';
break;
case 11:
$requestType = 'NewReleases';
break;
case 20:
$keyword = $searchkeyword;;
$sortOrder = $searchorderby;
if ( $searchdepartment == '' ) {
$nodeid = 'All';
} else {
$nodeid = $searchdepartment;
}
$maxCount = $searchlimit;
break;
case 30:
if ( $filterfield1 != '' ) {
$filter[ $filterfield1 ] = $filtertext1;
}
if ( $filterfield2 != '' ) {
$filter[ $filterfield2 ] = $filtertext2;
}
if ( $filterfield3 != '' ) {
$filter[ $filterfield3 ] = $filtertext3;
}
if ( $filterfield4 != '' ) {
$filter[ $filterfield4 ] = $filtertext4;
}
if ( $filterfield5 != '' ) {
$filter[ $filterfield5 ] = $filtertext5;
}
if ( $filterfield6 != '' ) {
$filter[ $filterfield6 ] = $filtertext6;
}
if ( $filterfield7 != '' ) {
$filter[ $filterfield7 ] = $filtertext7;
}
if ( $filterfield8 != '' ) {
$filter[ $filterfield8 ] = $filtertext8;
}
if ( $filterfield9 != '' ) {
$filter[ $filterfield9 ] = $filtertext9;
}
if ( $filterfield10 != '' ) {
$filter[ $filterfield10 ] = $filtertext10;
}
$maxCount = $extendedsearchlimit;
$nodeid = 'All';
break;
case 40:
$requestType = 'Similarity';
$value = atkp_product::load( $productid );
$asin = $value->asin;
$producttitle = $value->title;
break;
}
$mylist = $shop->provider->retrieve_list( $requestType, $nodeid, $keyword, $asin, $maxCount, $sortOrder, $filter );
$titlekeywords = null;
if ( $searchttitlefilter != null ) {
$titlekeywords = array_map( 'strtolower', explode( "\n", $searchttitlefilter ) );
}
$atkp_offertable_helper = new atkp_offertable_helper();
$atkp_offertable_helper->clear_offers_by_listid( $post_id );
$globaltools = new atkp_global_tools();
if ( $mylist->products != null ) {
foreach ( $mylist->products as $azproduct ) {
if ( $titlekeywords != null && count( $titlekeywords ) > 0 ) {
if ( ! $this->str_contains( $azproduct->title, $titlekeywords, false ) ) {
continue;
}
}
$item = array();
$item['type'] = 'product';
$item['value'] = $azproduct;
$azproduct->producturl = $this->shorten_url( '', $shopid, $azproduct->producturl );
$azproduct->addtocarturl = $this->shorten_url( '', $shopid, $azproduct->addtocarturl );
$azproduct->customerreviewurl = $this->shorten_url( '', $shopid, $azproduct->customerreviewurl );
if ( $loadmoreoffers ) {
$this->update_offers( $azproduct, $post_id );
}
array_push( $productlist, $item );
}
}
foreach ( $productlist as $item ) {
if ( $autoimportproducts ) {
$azproduct = $item['value'];
$prdfound = atkp_product::loadbyasin( $azproduct->asin );
if ( $prdfound == null ) {
//import product
//$post_id = ATKPTools::create_product($azproduct->title,$shopid,$azproduct->asin, 'publish', 'ASIN');
$gif_data = $globaltools->atkp_import_product( $shopid, $azproduct->asin, 'ASIN', $azproduct->title, 'publish', '', $azproduct->brand, $azproduct->mpn );
}
}
}
ATKPTools::set_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_listurl', $mylist->listurl );
ATKPTools::set_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_node_caption', $mylist->browsenodename );
$post_loaded = get_post( $post_id );
if ( $post_loaded->post_title == '' ) {
$newtitle = '';
switch ( $source ) {
case 10:
$newtitle = __( 'Topseller', ATKP_PLUGIN_PREFIX ) . ' ' . $mylist->browsenodename;
break;
case 11:
$newtitle = __( 'Latest releases', ATKP_PLUGIN_PREFIX ) . ' ' . $mylist->browsenodename;
break;
case 20:
$newtitle = __( 'Search for ', ATKP_PLUGIN_PREFIX ) . ' ' . $keyword . __( ' order by ', ATKP_PLUGIN_PREFIX ) . $searchorderby . ' (' . $searchdepartment . ')';
break;
case 30:
$newtitle = __( 'Extended Search', ATKP_PLUGIN_PREFIX );
break;
case 40:
$newtitle = __( 'Similar products', ATKP_PLUGIN_PREFIX ) . __( ' for ', ATKP_PLUGIN_PREFIX ) . $producttitle;
break;
}
global $wpdb;
$wpdb->update( $wpdb->posts, array( 'post_title' => $newtitle ), array( 'ID' => $post_id ) );
}
if ( $mylist->products == null || count( $mylist->products ) == 0 ) {
ATKPTools::set_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_message', 'list has no entries' );
} else {
ATKPTools::set_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_message', null );
}
} catch ( Exception $e ) {
ATKPTools::set_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_message', 'Error: ' . $e->getMessage() );
}
}
} else {
try {
$products = ATKPTools::get_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_products' );
foreach ( explode( "\n", $products ) as $productid ) {
$item = array();
$item['type'] = 'productid';
$item['value'] = $productid;
array_push( $productlist, $item );
}
ATKPTools::set_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_message', null );
} catch ( Exception $e ) {
ATKPTools::set_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_message', 'Error: ' . $e->getMessage() );
}
}
if ( sizeof( $productlist ) == 0 ) {
ATKPTools::set_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_productlist', null );
} else {
ATKPTools::set_post_setting( $post_id, ATKP_LIST_POSTTYPE . '_productlist', $productlist );
}
do_action( 'atkp_list_updated', $post_id );
//pause für eine sekunde
sleep( 1 );
}
}