register_productPostType(); $this->register_filter(); $enableProductpages = atkp_options::$loader->get_product_enabled(); if ( $enableProductpages ) { add_filter( 'the_content', array( &$this, 'my_the_content_filter' ), 0 ); } if ( is_admin() ) { add_action( 'add_meta_boxes', array( &$this, 'product_boxes' ) ); add_action( 'save_post', array( &$this, 'product_detail_save' ) ); add_thickbox(); ATKPTools::add_column( ATKP_PRODUCT_POSTTYPE, __( 'Status', ATKP_PLUGIN_PREFIX ), function ( $post_id ) { $selectedshopid = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_shopid' ); try { if ( $selectedshopid != '' && atkp_shop::exists( $selectedshopid ) ) { $shps = atkp_shop::load( $selectedshopid, false ); } } catch ( Exception $ex ) { echo 'parent shop not found. '; $shps = null; } echo '' . __( 'ID', ATKP_PLUGIN_PREFIX ) . ': ' . $post_id . ', '; if ( ! isset( $shps ) || $shps == null ) { echo '' . __( 'Manual product', ATKP_PLUGIN_PREFIX ) . ''; } else { echo '' . __( 'Shop', ATKP_PLUGIN_PREFIX ) . ': ' . $shps->title . ''; } $updatedon = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_updatedon' ); if ( isset( $updatedon ) && $updatedon != '' ) { $infotext = __( '%refresh_date% at %refresh_time%', ATKP_PLUGIN_PREFIX ); $infotext = str_replace( '%refresh_date%', ATKPTools::get_formatted_date( $updatedon ), $infotext ); $infotext = str_replace( '%refresh_time%', ATKPTools::get_formatted_time( $updatedon ), $infotext ); echo '
' . __( 'Updated on', ATKP_PLUGIN_PREFIX ) . ': ' . $infotext . ''; } $asin = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_asin' ); $asintype = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_asintype' ); if ( $asin != '' ) { echo '
' . __( 'Key', ATKP_PLUGIN_PREFIX ) . ': ' . $asin . ''; echo ', ' . __( 'Type', ATKP_PLUGIN_PREFIX ) . ': '; if ( $asintype == 'TITLE' ) { echo __( 'Title', ATKP_PLUGIN_PREFIX ); } else if ( $asintype == 'EAN' ) { echo __( 'EAN', ATKP_PLUGIN_PREFIX ); } else if ( $asintype == 'ARTICLENUMBER' ) { echo __( 'Articlenumber', ATKP_PLUGIN_PREFIX ); } else { echo __( 'Unique productid', ATKP_PLUGIN_PREFIX ); } echo ''; } $producturl = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_producturl' ); if ( $producturl != '' ) { $title = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_title' ); $access_website = $selectedshopid != '' ? ATKPTools::get_post_setting( $selectedshopid, ATKP_SHOP_POSTTYPE . '_access_website' ) : ''; echo '
' . __( 'Go to product', ATKP_PLUGIN_PREFIX ) . ''; if ( $access_website != '' ) { echo ' | ' . __( 'Search @ Amazon', ATKP_PLUGIN_PREFIX ) . ''; } } $message = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_message' ); $woomessage = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_woomessage' ); if ( isset( $message ) && $message != '' ) { echo '
' . __( 'Message', ATKP_PLUGIN_PREFIX ) . ': ' . esc_html( $message ) . ''; } if ( isset( $woomessage ) && $woomessage != '' ) { echo '
' . __( 'WooCommerce', ATKP_PLUGIN_PREFIX ) . ': ' . esc_html( $woomessage ) . ''; } }, 3 ); add_action( 'admin_enqueue_scripts', array( $this, 'image_enqueue' ) ); add_action( 'admin_head', array( $this, 'hidey_admin_head' ) ); ATKPTools::add_column( ATKP_PRODUCT_POSTTYPE, __( 'Main image', ATKP_PLUGIN_PREFIX ), function ( $post_id ) { $imageurl = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_smallimageurl' ); 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 . '_largeimageurl' ); } if ( $imageurl != '' ) { echo ''; } }, 1 ); add_action( 'before_delete_post', 'atkp_delete_images' ); function atkp_delete_images( $post_id ) { // We check if the global post type isn't ours and just return global $post_type; if ( $post_type == ATKP_PRODUCT_POSTTYPE ) { if ( has_post_thumbnail( $post_id ) ) { $attachment_id = get_post_thumbnail_id( $post_id ); if ( $attachment_id ) { wp_delete_attachment( $attachment_id, true ); } } //get woocommerce product and delete image if ( class_exists( 'WooCommerce' ) ) { try { $mode = atkp_options::$loader->get_woo_mode(); if ( $mode != '' ) { $woo_product = atkp_product::get_woo_product( $post_id ); if ( has_post_thumbnail( $woo_product->ID ) ) { $attachment_id = get_post_thumbnail_id( $woo_product->ID ); } wp_delete_post( $woo_product->ID, true ); if ( $attachment_id ) { wp_delete_attachment( $attachment_id, true ); } } } catch ( Exception $e ) { //TODO: log } } } } } } function hidey_admin_head() { echo ''; } /** * Loads the image management javascript */ function image_enqueue() { global $typenow; if ( $typenow == ATKP_PRODUCT_POSTTYPE ) { wp_enqueue_media(); // Registers and enqueues the required javascript. wp_register_script( 'meta-box-image', plugin_dir_url( ATKP_PLUGIN_FILE ) . 'js/meta-box-image.js', array( 'jquery' ) ); wp_localize_script( 'meta-box-image', 'meta_image', array( 'title' => __( 'Choose or Upload an image', ATKP_PLUGIN_PREFIX ), 'button' => __( 'Use this image', ATKP_PLUGIN_PREFIX ), ) ); wp_enqueue_script( 'meta-box-image' ); } } function register_filter() { add_filter( 'parse_query', array( &$this, 'admin_posts_filter' ) ); add_action( 'restrict_manage_posts', array( &$this, 'admin_posts_filter_restrict_manage_posts' ) ); } function admin_posts_filter( $query ) { $filterfield = ATKPTools::get_get_parameter( ATKP_PLUGIN_PREFIX . '_filterfield', 'string' ); $posttype = ATKPTools::get_get_parameter( 'post_type', 'string' ); if ( $posttype == ATKP_PRODUCT_POSTTYPE && ! atkp_posttypes_product::$overridefilter ) { global $pagenow; if ( is_admin() && $pagenow == 'edit.php' && isset( $filterfield ) && $filterfield != '' ) { if ( $filterfield == 'filter_error' ) { $query->query_vars['meta_key'] = ATKP_PRODUCT_POSTTYPE . '_message'; $query->query_vars['meta_value'] = ''; $query->query_vars['meta_compare'] = 'EXISTS'; } else { $parts = explode( '_', $filterfield ); $query->set( 'meta_query', array( array( 'key' => ATKP_PRODUCT_POSTTYPE . '_shopid', 'value' => isset( $parts[1] ) ? $parts[1] : '', 'compare' => isset( $parts[1] ) && $parts[1] != '' ? '=' : 'NOT EXISTS' ) ) ); } } } } private static $overridefilter; function admin_posts_filter_restrict_manage_posts() { $posttype = ATKPTools::get_get_parameter( 'post_type', 'string' ); if ( $posttype != ATKP_PRODUCT_POSTTYPE ) { return; } atkp_posttypes_product::$overridefilter = true; $shops = atkp_shop::get_list( '', true ); atkp_posttypes_product::$overridefilter = false; ?> __( 'Products', ATKP_PLUGIN_PREFIX ), 'singular_name' => __( 'Product', ATKP_PLUGIN_PREFIX ), 'add_new_item' => __( 'Add new Product', ATKP_PLUGIN_PREFIX ), 'edit_item' => __( 'Edit Product', ATKP_PLUGIN_PREFIX ), 'new_item' => __( 'New Product', ATKP_PLUGIN_PREFIX ), 'all_items' => __( 'Products', ATKP_PLUGIN_PREFIX ), 'view_item' => __( 'View Product', ATKP_PLUGIN_PREFIX ), 'search_items' => __( 'Search Products', ATKP_PLUGIN_PREFIX ), 'not_found' => __( 'No products found', ATKP_PLUGIN_PREFIX ), 'not_found_in_trash' => __( 'No products found in the Trash', ATKP_PLUGIN_PREFIX ), 'parent_item_colon' => '', 'menu_name' => __( 'AT Products', ATKP_PLUGIN_PREFIX ), ); $enableProductpages = atkp_options::$loader->get_product_enabled(); $enableComments = atkp_options::$loader->get_product_commentenabled(); $productslug = atkp_options::$loader->get_product_slug(); $importProductimage = atkp_options::$loader->get_product_importimage(); if ( $productslug == '' ) { $productslug = 'product'; } $rewrite = false; $supports = array( 'title' ); if ( $importProductimage ) { $supports = array( 'title', 'thumbnail' ); } if ( $enableProductpages ) { $rewrite = array( 'slug' => $productslug, 'with_front' => true, 'pages' => true, 'feeds' => true, ); if ( $enableComments ) { $supports = array( 'title', 'comments', 'author', 'trackbacks', 'editor', 'thumbnail' ); } else { $supports = array( 'title', 'author', 'editor', 'thumbnail' ); } } $args = array( 'labels' => $labels, 'description' => 'Holds our products and product specific data', 'public' => $enableProductpages, // it's not public, it shouldn't have it's own permalink, and so on 'publicly_queriable' => $enableProductpages, // you should be able to query it 'show_ui' => true, // you should be able to edit it in wp-admin 'exclude_from_search' => ! $enableProductpages, // you should exclude it from search results 'show_in_nav_menus' => true, // you shouldn't be able to add it to menus 'has_archive' => (bool) $enableProductpages, // it shouldn't have archive page 'rewrite' => $rewrite, 'taxonomies' => array(), 'query_var' => true, 'menu_position' => 20, 'supports' => $supports, 'capability_type' => 'post', 'menu_icon' => plugin_dir_url( ATKP_PLUGIN_FILE ) . '/images/affiliate_toolkit_menu.png', ); $args = apply_filters( 'atkp_product_register_post_type', $args ); register_post_type( ATKP_PRODUCT_POSTTYPE, $args ); $taxonomies = atkp_udtaxonomy::load_taxonomies(); if ( $taxonomies != null ) { foreach ( $taxonomies as $taxonomy ) { //falls taxonomie bereits von anderem plugin installiert wurde if ( taxonomy_exists( $taxonomy->name ) || $taxonomy->name == '' ) { continue; } if ( $taxonomy->caption == '' ) { $taxonomy->caption = $taxonomy->name; } if ( $taxonomy->captionplural == '' ) { $taxonomy->captionplural = $taxonomy->caption; } $labels = array( 'name' => $taxonomy->captionplural, 'singular_name' => $taxonomy->caption, 'search_items' => sprintf( __( 'Search %s', ATKP_PLUGIN_PREFIX ), $taxonomy->captionplural ), 'all_items' => sprintf( __( 'All %s', ATKP_PLUGIN_PREFIX ), $taxonomy->captionplural ), 'edit_item' => sprintf( __( 'Edit %s', ATKP_PLUGIN_PREFIX ), $taxonomy->caption ), 'update_item' => sprintf( __( 'Update %s', ATKP_PLUGIN_PREFIX ), $taxonomy->caption ), 'add_new_item' => sprintf( __( 'Add New %s', ATKP_PLUGIN_PREFIX ), $taxonomy->caption ), 'new_item_name' => sprintf( __( 'New %s', ATKP_PLUGIN_PREFIX ), $taxonomy->caption ), 'menu_name' => $taxonomy->captionplural ); // register taxonomy if ( $taxonomy->isproductgroup && atkp_options::$loader->get_fieldgroups_enabled() ) { $taxs = array( ATKP_PRODUCT_POSTTYPE, ATKP_FIELDGROUP_POSTTYPE ); } else { $taxs = array( ATKP_PRODUCT_POSTTYPE ); } $taxs = apply_filters( 'atkp_taxonomy_posttypes', $taxs, $taxonomy->name ); $taxargs = array( 'taxonomies' => $taxs, 'hierarchical' => true, 'labels' => $labels, 'query_var' => true, 'show_admin_column' => false, 'show_ui' => $taxonomy->showui, 'public' => $enableProductpages, 'update_count_callback' => '_update_post_term_count', 'capabilities' => array( 'manage_terms' => 'edit_posts', 'edit_terms' => 'edit_posts', 'delete_terms' => 'edit_posts', 'assign_terms' => 'edit_posts' ) ); $taxargs = apply_filters( 'atkp_register_taxonomy', $taxargs, $taxonomy->name ); register_taxonomy( $taxonomy->name, $taxs, $taxargs ); } } } function my_the_content_filter( $content ) { global $post; if ( ATKP_PRODUCT_POSTTYPE == get_post_type() ) { if ( is_single() ) { $producttemplate = stripslashes( atkp_options::$loader->get_product_template() ); if ( $producttemplate != '' ) { $producttemplate = str_replace( '%content%', $content, $producttemplate ); return html_entity_decode( $producttemplate ); } } else if ( is_archive() ) { $producttemplate = stripslashes( atkp_options::$loader->get_product_archivetemplate() ); if ( $producttemplate != '' ) { $producttemplate = str_replace( '%content%', $content, $producttemplate ); return do_shortcode( html_entity_decode( $producttemplate ) ); } } } // otherwise returns the database content return $content; } function product_boxes() { add_meta_box( ATKP_PRODUCT_POSTTYPE . '_shop_box', __( 'Shop Information', ATKP_PLUGIN_PREFIX ), array( &$this, 'product_shop_box_content' ), ATKP_PRODUCT_POSTTYPE, 'normal', 'default' ); add_meta_box( ATKP_PRODUCT_POSTTYPE . '_detail_box', __( 'Detailed information', ATKP_PLUGIN_PREFIX ), array( &$this, 'product_detail_box_content' ), ATKP_PRODUCT_POSTTYPE, 'normal', 'default' ); if ( atkp_options::$loader->get_fieldgroups_enabled() ) { add_meta_box( ATKP_PRODUCT_POSTTYPE . '_import_box', __( 'Import tools', ATKP_PLUGIN_PREFIX ), array( &$this, 'product_import_box_content' ), ATKP_PRODUCT_POSTTYPE, 'side', 'default' ); } } function product_import_box_content( $post ) { ?>
ID, ATKP_PRODUCT_POSTTYPE . '_updatedon', true ); $message = ATKPTools::get_post_setting( $post->ID, ATKP_PRODUCT_POSTTYPE . '_message', true ); $woomessage = ATKPTools::get_post_setting( $post->ID, ATKP_PRODUCT_POSTTYPE . '_woomessage' ); ?>


' . esc_html( $message ) . ''; ?> WooCommerce: ' . esc_html( $woomessage ) . ''; } ?>
get_woo_enabled(); if ( $wooenabled ) { ?> get_product_importimage(); if ( $importProductimage || $wooenabled != '' ) { ?>
>
ID, ATKP_PRODUCT_POSTTYPE . '_description', true ), ATKP_PRODUCT_POSTTYPE . '_description', array( 'media_buttons' => false, 'textarea_name' => ATKP_PRODUCT_POSTTYPE . '_description', 'textarea_rows' => 10, ) ); ?>
ID, ATKP_PRODUCT_POSTTYPE . '_features', true ), ATKP_PRODUCT_POSTTYPE . '_features', array( 'media_buttons' => false, 'textarea_name' => ATKP_PRODUCT_POSTTYPE . '_features', 'textarea_rows' => 10, ) ); ?>
ID, ATKP_PRODUCT_POSTTYPE . '_postid' ); if ( $postid != null ) { if ( is_array( $postid ) ) { foreach ( $postid as $p ) { $title = get_the_title( $p ); if ( ! isset( $title ) || $title == '' ) { $title = __( 'edit post', ATKP_PLUGIN_PREFIX ); } echo sprintf( __( '%s ', ATKP_PLUGIN_PREFIX ), get_edit_post_link( $p ), $title ); } } else { $title = get_the_title( $postid ); if ( ! isset( $title ) || $title == '' ) { $title = __( 'edit post', ATKP_PLUGIN_PREFIX ); } echo sprintf( __( '%s', ATKP_PLUGIN_PREFIX ), get_edit_post_link( $postid ), $title ); } } else { _e( 'This Product is not used as a main product in any contribution.', ATKP_PLUGIN_PREFIX ); } ?>
ID, ATKP_PRODUCT_POSTTYPE . '_disablehoverlink' ), true ); ?>>
ID, ATKP_PRODUCT_POSTTYPE . '_iswoocommerce' ), true ); ?>>
ID, ATKP_PRODUCT_POSTTYPE . '_dontimportmainimage' ), false ); ?>>
ID, ATKP_PRODUCT_POSTTYPE . '_outputashtml' ), true ); ?>>
>
ID, ATKP_PRODUCT_POSTTYPE . '_refreshproducturlregulary' ), true ); ?>>
ID, ATKP_PRODUCT_POSTTYPE . '_isownreview' ), true ); ?>>
>
ID, ATKP_PRODUCT_POSTTYPE . '_refreshreviewinforegulary' ), true ); ?>>
ID ); ?>
>
ID, ATKP_PRODUCT_POSTTYPE . '_refreshimagesregulary' ), true ); ?>>
ID, ATKP_PRODUCT_POSTTYPE . '_mediumimageurl', true ); if ( $imageurl == '' ) { $imageurl = ATKPTools::get_post_setting( $post->ID, ATKP_PRODUCT_POSTTYPE . '_smallimageurl', true ); } if ( $imageurl == '' ) { $imageurl = ATKPTools::get_post_setting( $post->ID, ATKP_PRODUCT_POSTTYPE . '_largeimageurl', true ); } ?>
>
ID, ATKP_PRODUCT_POSTTYPE . '_refreshpriceinforegulary' ), true ); ?>>
ID, ATKP_PRODUCT_POSTTYPE . '_listprice', true ) != '' ) { ?> (ID, ATKP_PRODUCT_POSTTYPE . '_listpricefloat', true ); ?>)
ID, ATKP_PRODUCT_POSTTYPE . '_amountsaved', true ) != '' ) { ?> (ID, ATKP_PRODUCT_POSTTYPE . '_amountsavedfloat', true ); ?>)
ID, ATKP_PRODUCT_POSTTYPE . '_saleprice', true ) != '' ) { ?> (ID, ATKP_PRODUCT_POSTTYPE . '_salepricefloat', true ); ?>)
ID, ATKP_PRODUCT_POSTTYPE . '_shipping', true ) != '' ) { ?> (ID, ATKP_PRODUCT_POSTTYPE . '_shippingfloat', true ); ?>)
ID, ATKP_PRODUCT_POSTTYPE . '_isprime' ), true ); ?>>
= 30 ) { ?>
name; ?> ID ); foreach ( $groups as $group ) { ?> ID, ATKP_FIELDGROUP_POSTTYPE . '_fields' ); foreach ( $fields as $field ) { if ( $field->type != 6 ) { ?>
create_control( $newfield, ATKP_PRODUCT_POSTTYPE . '_' . $fieldname, ATKPTools::get_post_setting( $post->ID, ATKP_PRODUCT_POSTTYPE . '_' . $fieldname ) ); ?>
post_title ?>
create_control( $field, ATKP_PRODUCT_POSTTYPE . '_cf_' . $field->name, ATKPTools::get_post_setting( $post->ID, ATKP_PRODUCT_POSTTYPE . '_cf_' . $field->name ), true ); ?>
>
>
ID ); usort( $offers, array( $this, "atkp_offercompare" ) ); if ( is_array( $offers ) ) { foreach ( $offers as $offer ) { ?>
'; ?>
Shipping
Availability', ATKP_PLUGIN_PREFIX ) ?>
 
 
title; ?>
id . '" name="' . ATKP_PRODUCT_POSTTYPE . '_offer_id_' . $offer->id . '" value="' . $offer->id . '">'; foreach ( $shps as $shop ) { if ( $offer->shopid == $shop->id || $offer->oldid == $shop->id ) { echo esc_attr( $shop->title ); break; } } ?>: number; ?>
price; ?> price != '' ) { ?> (pricefloat; ?>)
shipping; ?> shipping != '' ) { ?> (shippingfloat; ?>)
availability; ?>
type == 1 ) { ?> hideoffer ) ?> /> updatedon == null ? __( 'marked for price update', ATKP_PLUGIN_PREFIX ) : 'last update: ' . $offer->updatedon ) . '
'; echo( $offer->message != '' && strlen( $offer->message ) > 183 ? substr( $offer->message, 0, 180 ) . '...' : $offer->message ); ?>
type == 1 ? 'disabled' : '' ); ?> id="removeoffer-button_id ?>" class="button remove-offer" value=""/>
>
ID, ATKP_PRODUCT_POSTTYPE . '_variations' ); $variationname = ATKPTools::get_post_setting( $post->ID, ATKP_PRODUCT_POSTTYPE . '_variationname' ); if ( isset( $variations ) && is_array( $variations ) ) { ?>
$value ) { array_push( $displaylist, htmlentities( $value ) ); } echo implode( ' → ', $displaylist ); ?>
asin; ?> variationname as $key => $value ) { array_push( $displaylist, htmlentities( $value ) ); } echo implode( ' → ', $displaylist ); ?> producturl . '" target="blank">' . $variation->title . ''; ?>
id == $b->id ) { return 0; } return ( $a->id < $b->id ) ? - 1 : 1; } function substr_startswith( $haystack, $needle ) { return substr( $haystack, 0, strlen( $needle ) ) === $needle; } function product_detail_save( $post_id ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } $nounce = ATKPTools::get_post_parameter( 'product_detail_box_content_nonce', 'string' ); if ( ! wp_verify_nonce( $nounce, plugin_basename( __FILE__ ) ) ) { return; } $post = get_post( $post_id ); $posttype = $post->post_type; //ATKPTools::get_post_parameter('post_type', 'string'); if ( ATKP_PRODUCT_POSTTYPE != $posttype ) { return; } $shopid = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_shopid', 'string' ); $title = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_title', 'string' ); $description = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_description', 'html' ); $disablehoverlink = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_disablehoverlink', 'bool' ); $refreshproductinfo = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_refreshproductinfo', 'bool' ); $refreshpriceinfo = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_refreshpriceinfo', 'bool' ); $refreshreviewinfo = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_refreshreviewinfo', 'bool' ); $refreshimages = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_refreshimages', 'bool' ); $refreshproducturl = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_refreshproducturl', 'bool' ); $refreshvariations = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_refreshvariations', 'bool' ); $refreshimagesregulary = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_refreshimagesregulary', 'bool' ); $refreshreviewinforegulary = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_refreshreviewinforegulary', 'bool' ); $refreshpriceinforegulary = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_refreshpriceinforegulary', 'bool' ); $refreshproducturlregulary = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_refreshproducturlregulary', 'bool' ); $outputashtml = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_outputashtml', 'bool' ); $asin = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_asin', 'string' ); $asintype = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_asintype', 'string' ); $ean = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_ean', 'string' ); $isbn = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_isbn', 'string' ); $mpn = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_mpn', 'string' ); $brand = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_brand', 'string' ); $productgroup = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_productgroup', 'string' ); $releasedate = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_releasedate', 'string' ); $producturl = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_producturl', 'url' ); $addtocarturl = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_addtocarturl', 'url' ); $customerreviewurl = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_customerreviewsurl', 'url' ); $overridemainimage = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_overridemainimage', 'string' ); $smallimageurl = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_smallimageurl', 'url' ); $mediumimageurl = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_mediumimageurl', 'url' ); $largeimageurl = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_largeimageurl', 'url' ); $manufacturer = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_manufacturer', 'string' ); $author = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_author', 'string' ); $numberofpages = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_numberofpages', 'int' ); $features = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_features', 'html' ); $isownreview = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_isownreview', 'bool' ); $rating = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_rating', 'double' ); $reviewcount = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_reviewcount', 'int' ); $reviewsurl = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_reviewsurl', 'url' ); $listprice = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_listprice', 'string' ); $amountsaved = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_amountsaved', 'string' ); $percentagesaved = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_percentagesaved', 'string' ); $saleprice = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_saleprice', 'string' ); $availability = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_availability', 'string' ); $shipping = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_shipping', 'string' ); $isprime = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_isprime', 'bool' ); $predicate = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_predicate', 'string' ); $testdate = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_testdate', 'string' ); $testrating = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_testrating', 'string' ); $testresult = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_testresult', 'string' ); $reviewtext = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_reviewtext', 'string' ); $pro = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_pro', 'multistring' ); $contra = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_contra', 'multistring' ); $iswoocommerce = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_iswoocommerce', 'bool' ); $dontimportmainimage = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_dontimportmainimage', 'bool' ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_overridemainimage', $overridemainimage ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_dontimportmainimage', $dontimportmainimage ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_iswoocommerce', $iswoocommerce ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_pro', $pro ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_contra', $contra ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_predicate', $predicate ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_testdate', $testdate ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_testrating', $testrating ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_testresult', $testresult ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_reviewtext', $reviewtext ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_outputashtml', $outputashtml ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_shopid', $shopid ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_title', $title ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_description', $description ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_asin', $asin ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_asintype', $asintype ); $eanchanged = false; $eanold = ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_ean' ); if ( $eanold != $ean ) { $eanchanged = true; } ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_ean', $ean ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_isbn', $isbn ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_mpn', $mpn ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_brand', $brand ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_productgroup', $productgroup ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_releasedate', $releasedate ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_manufacturer', $manufacturer ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_author', $author ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_numberofpages', $numberofpages ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_features', $features ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_disablehoverlink', $disablehoverlink ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_refreshreviewinforegulary', $refreshreviewinforegulary ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_refreshpriceinforegulary', $refreshpriceinforegulary ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_refreshproducturlregulary', $refreshproducturlregulary ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_refreshimagesregulary', $refreshimagesregulary ); if ( ! $refreshproducturlregulary ) { ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_producturl', $producturl ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_addtocarturl', $addtocarturl ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_customerreviewsurl', $customerreviewurl ); } ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_isownreview', $isownreview ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_reviewsurl', $reviewsurl ); if ( ! $refreshimagesregulary ) { ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_smallimageurl', $smallimageurl ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_mediumimageurl', $mediumimageurl ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_largeimageurl', $largeimageurl ); } if ( ! $refreshreviewinforegulary ) { ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_rating', $rating ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_reviewcount', $reviewcount ); } if ( ! $refreshpriceinforegulary ) { $salepricefloat = ATKPTools::price_to_float( $saleprice ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_listprice', $listprice ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_amountsaved', $amountsaved ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_percentagesaved', $percentagesaved ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_saleprice', $saleprice ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_availability', $availability ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_shipping', $shipping ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_isprime', $isprime ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_listpricefloat', ATKPTools::price_to_float( $listprice ) ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_amountsavedfloat', ATKPTools::price_to_float( $amountsaved ) ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_salepricefloat', $salepricefloat ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_shippingfloat', ATKPTools::price_to_float( $shipping ) ); if(atkp_options::$loader->get_pricehistory_enabled()) { $history = new atkp_pricehistorytable_helper(); $history->create_history_entry($post_id, $shopid, $saleprice, $salepricefloat); } } //offers $refreshmoreoffersregulary = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_refreshmoreoffersregulary', 'bool' ); $refreshmoreoffers = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_refreshmoreoffers', 'bool' ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_refreshmoreoffersregulary', $refreshmoreoffersregulary ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_refreshmoreoffers', $refreshmoreoffers ); $offerschanged = ATKPTools::get_post_parameter( 'atkp_offerschanged', 'bool' ); if ( $offerschanged != '0' ) { $offers = atkp_product_offer::load_offers( $post_id ); $offersnew = array(); //TODO: wie änderung mitbekommen? hidden feld setzen? und nur dann überschreiben... foreach ( $_POST as $key => $value ) { $key = sanitize_text_field( $key ); $value = sanitize_text_field( $value ); $id = str_replace( 'atkp_product_offer_id_', '', $key ); $id = str_replace( 'atkp_product_offer_hide_', '', $id ); $id = str_replace( 'atkp_product_offer_shopid_', '', $id ); $id = str_replace( 'atkp_product_offer_number_', '', $id ); $udf = new atkp_product_offer(); $udf->type = 2; $udf->id = $id; $checkit = 0; $add = 1; foreach ( $offersnew as $offer ) { if ( $offer->id == $udf->id ) { $udf = $offer; $add = 0; break; } } if ( $this->substr_startswith( $key, 'atkp_product_offer_id_' ) ) { $checkit = 1; $udf->id = $value; } else if ( $this->substr_startswith( $key, 'atkp_product_offer_shopid_' ) ) { $checkit = 1; $udf->shopid = $value; } else if ( $this->substr_startswith( $key, 'atkp_product_offer_number_' ) ) { $checkit = 1; $udf->number = $value; } else if ( $this->substr_startswith( $key, 'atkp_product_offer_hide_' ) ) { $checkit = 1; $udf->hideoffer = ATKPTools::get_post_parameter( $key, 'bool' ); } if ( $checkit && $add ) { array_push( $offersnew, $udf ); } } $mergedoffers = array(); foreach ( $offersnew as $udf ) { $mergedoffer = $udf; foreach ( $offers as $offer ) { if ( $offer->id == $udf->id ) { $mergedoffer = $offer; $mergedoffer->hideoffer = $udf->hideoffer; break; } } array_push( $mergedoffers, $mergedoffer ); } $offertablehelper = new atkp_offertable_helper(); $offertablehelper->update_offers_by_productid( $post_id, $mergedoffers, true ); //ATKPTools::set_post_setting($post_id, ATKP_PRODUCT_POSTTYPE.'_offers', $mergedoffers); $refreshmoreoffers = 1; } //offers //imagegallery if ( ! $refreshimagesregulary ) { $images = array(); //echo serialize($_POST); foreach ( $_POST as $key => $value ) { $key = sanitize_text_field( $key ); $value = sanitize_text_field( $value ); $id = str_replace( 'atkp_product_largeimageurl_gallery_', '', $key ); $id = str_replace( 'atkp_product_smallimageurl_gallery_', '', $id ); $id = str_replace( 'atkp_product_mediumimageurl_gallery_', '', $id ); $checkit = 0; $add = 1; $udf = new atkp_product_image(); $udf->id = $id; foreach ( $images as $image ) { if ( $image->id == $udf->id ) { $udf = $image; $add = 0; break; } } if ( $this->substr_startswith( $key, 'atkp_product_largeimageurl_gallery' ) ) { $checkit = 1; $udf->largeimageurl = $value; } else if ( $this->substr_startswith( $key, 'atkp_product_smallimageurl_gallery' ) ) { $checkit = 1; $udf->smallimageurl = $value; } else if ( $this->substr_startswith( $key, 'atkp_product_mediumimageurl_gallery' ) ) { $checkit = 1; $udf->mediumimageurl = $value; } if ( $checkit && $add ) { array_push( $images, $udf ); } } ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_images', $images ); } //imagegallery //benutzerdefinierte felder speichern if ( ATKP_PLUGIN_VERSION >= 30 ) { $newfields = atkp_udfield::load_fields(); $helper = new atkp_control_helper(); $allfields = array(); foreach ( $newfields as $newfield ) { $fieldname = 'customfield_' . $newfield->name; $fieldvalue = $helper->read_control_value( $newfield, $fieldname ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_' . $fieldname, $fieldvalue ); //array_push($allfields, $newfield); } $groups = ATKPTools::get_fieldgroups_by_productid( $post_id ); foreach ( $groups as $group ) { $fields = ATKPTools::get_post_setting( $group->ID, ATKP_FIELDGROUP_POSTTYPE . '_fields' ); foreach ( $fields as $newfield ) { if ( $newfield->type != 6 ) { $fieldname = 'cf_' . $newfield->name; $fieldvalue = $helper->read_control_value( $newfield, $fieldname ); ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_' . $fieldname, $fieldvalue ); } array_push( $allfields, $newfield ); } } $importurl = ATKPTools::get_post_parameter( ATKP_PRODUCT_POSTTYPE . '_importurl', 'html' ); if ( $importurl != null ) { //parse url and update values... $parser = new atkp_url_scraper(); $newfields = $parser->get_rows( $importurl ); foreach ( $newfields as $nfield ) { try { $udf = null; foreach ( $allfields as $field ) { if ( $field->caption == sanitize_text_field( $nfield['name'] ) ) { $udf = $field; break; } } if ( $udf == null ) { continue; } $fieldvalue = sanitize_text_field( $nfield['caption'] ); if ( $udf->type == 6 ) { //update taxonomy ATKPTools::check_taxonomy( $post_id, $udf->name, $fieldvalue, false ); } else { $fieldname = 'cf_' . $udf->name; if ( $udf->format == 'number' ) { //extract number from string $fieldvalue = preg_replace( "/[^0-9]/", "", $fieldvalue ); $fieldvalue = intval( $fieldvalue ); } //$oldval =ATKPTools::get_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE.'_'.$fieldname); //if($oldval == '') ATKPTools::set_post_setting( $post_id, ATKP_PRODUCT_POSTTYPE . '_' . $fieldname, $fieldvalue ); } } catch ( Exception $e ) { } } } } $productservice = new atkp_productservice( array() ); $productservice->update_product_categories( $post_id ); $shop = $shopid != '' ? atkp_shop::load( $shopid, true ) : null; //erzweingt das update falls ean oder ähnliches geändert wurde if ( $eanchanged ) { $refreshmoreoffers = true; } $productservice->update_products( $shop, array( $post_id ), $asintype, false, $refreshproductinfo, $refreshpriceinfo, $refreshvariations, $refreshreviewinfo, $refreshimages, $refreshproducturl, $refreshmoreoffers ); if ( $iswoocommerce ) { $productservice->export_products( array( $post_id ) ); } } } ?>