Esempio n. 1
0
function woo_pi_create_product_details()
{
    global $wpdb, $product, $import, $user_ID;
    woo_pi_upload_directories();
    // Insert SKU
    if ($product->sku !== null) {
        if (WOO_PI_DEBUG !== true) {
            update_post_meta($product->ID, '_sku', $product->sku);
        }
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . sprintf(__('Setting SKU: %s', 'woo_pi'), $product->sku);
        } else {
            $import->log .= "<br />>>>>>> " . __('Setting SKU', 'woo_pi');
        }
    } else {
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . __('Skipping SKU', 'woo_pi');
        }
    }
    // Insert Price
    if ($product->price !== null) {
        if (WOO_PI_DEBUG !== true) {
            update_post_meta($product->ID, '_regular_price', $product->price);
            update_post_meta($product->ID, '_price', $product->price);
        }
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . sprintf(__('Setting Price: %s', 'woo_pi'), $product->price);
        } else {
            $import->log .= "<br />>>>>>> " . __('Setting Price', 'woo_pi');
        }
    } else {
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . __('Skipping Price', 'woo_pi');
        }
    }
    // Insert Sale Price
    if ($product->sale_price !== null) {
        if (WOO_PI_DEBUG !== true) {
            update_post_meta($product->ID, '_sale_price', $product->sale_price);
            update_post_meta($product->ID, '_price', $product->sale_price);
        }
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . sprintf(__('Setting Sale Price: %s', 'woo_pi'), $product->sale_price);
        } else {
            $import->log .= "<br />>>>>>> " . __('Setting Sale Price', 'woo_pi');
        }
    } else {
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . __('Skipping Sale Price', 'woo_pi');
        }
    }
    // Insert Weight
    if ($product->weight !== null) {
        if (WOO_PI_DEBUG !== true) {
            update_post_meta($product->ID, '_weight', $product->weight);
        }
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . sprintf(__('Setting Weight: %s', 'woo_pi'), $product->weight);
        } else {
            $import->log .= "<br />>>>>>> " . __('Setting Weight', 'woo_pi');
        }
    } else {
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . __('Skipping Weight', 'woo_pi');
        }
    }
    // Insert Dimensions
    if ($product->length !== null || $product->width !== null || $product->height !== null) {
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . sprintf(__('Setting Dimensions: %d%s x %d%s x %d%s', 'woo_pi'), $product->height, $product->height_unit, $product->width, $product->width_unit, $product->length, $product->length_unit);
        } else {
            $import->log .= "<br />>>>>>> " . __('Setting Dimensions', 'woo_pi');
        }
        if ($product->length !== null) {
            if (WOO_PI_DEBUG !== true) {
                update_post_meta($product->ID, '_length', $product->length);
            }
            if ($import->advanced_log) {
                $import->log .= "<br />>>>>>>>>> " . sprintf(__('Length: %s%s', 'woo_pi'), $product->length, $import->default_measurement_unit);
            }
        } else {
            if ($import->advanced_log) {
                $import->log .= "<br />>>>>>>>>> " . __('Skipping Length', 'woo_pi');
            }
        }
        if ($product->width !== null) {
            if (WOO_PI_DEBUG !== true) {
                update_post_meta($product->ID, '_width', $product->width);
            }
            if ($import->advanced_log) {
                $import->log .= "<br />>>>>>>>>> " . sprintf(__('Width: %s%s', 'woo_pi'), $product->width, $import->default_measurement_unit);
            }
        } else {
            if ($import->advanced_log) {
                $import->log .= "<br />>>>>>>>>> " . __('Skipping Width', 'woo_pi');
            }
        }
        if ($product->height !== null) {
            if (WOO_PI_DEBUG !== true) {
                update_post_meta($product->ID, '_height', $product->height);
            }
            if ($import->advanced_log) {
                $import->log .= "<br />>>>>>>>>> " . sprintf(__('Height: %s%s', 'woo_pi'), $product->height, $import->default_measurement_unit);
            }
        } else {
            if ($import->advanced_log) {
                $import->log .= "<br />>>>>>>>>> " . __('Skipping Height', 'woo_pi');
            }
        }
    } else {
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . __('Skipping Dimensions', 'woo_pi');
        }
    }
    // Insert Category
    $term_taxonomy = 'product_cat';
    if (!empty($product->category_term_id)) {
        $term_taxonomy_ids = wp_set_object_terms($product->ID, array_unique(array_map('intval', $product->category_term_id)), $term_taxonomy);
        if ($import->advanced_log) {
            if (count($product->category_term_id) == 1) {
                $import->log .= "<br />>>>>>> " . sprintf(__('Linking Category: %s', 'woo_pi'), $product->category);
            } else {
                $import->log .= "<br />>>>>>> " . sprintf(__('Linking Categories: %s', 'woo_pi'), $product->category);
            }
        } else {
            if (count($product->category_term_id) == 1) {
                $import->log .= "<br />>>>>>> " . __('Linking Category', 'woo_pi');
            } else {
                $import->log .= "<br />>>>>>> " . __('Linking Categories', 'woo_pi');
            }
        }
    } else {
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . __('Skipping Category', 'woo_pi');
        }
    }
    // Insert Tag
    $term_taxonomy = 'product_tag';
    if (!empty($product->tag_term_id)) {
        $term_taxonomy_ids = wp_set_object_terms($product->ID, array_unique(array_map('intval', $product->tag_term_id)), $term_taxonomy);
        if ($import->advanced_log) {
            if (count($product->tag_term_id) == 1) {
                $import->log .= "<br />>>>>>> " . sprintf(__('Linking Tag: %s', 'woo_pi'), $product->tag);
            } else {
                $import->log .= "<br />>>>>>> " . sprintf(__('Linking Tags: %s', 'woo_pi'), $product->tag);
            }
        } else {
            if (count($product->tag_term_id) == 1) {
                $import->log .= "<br />>>>>>> " . __('Linking Tag', 'woo_pi');
            } else {
                $import->log .= "<br />>>>>>> " . __('Linking Tags', 'woo_pi');
            }
        }
    } else {
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . __('Skipping Tag', 'woo_pi');
        }
    }
    // Insert Quantity
    if ($product->quantity !== null) {
        if (WOO_PI_DEBUG !== true) {
            update_post_meta($product->ID, '_stock', $product->quantity);
        }
        // Override that enables Manage Stock if a value is set for Quantity
        if (!$product->manage_stock) {
            if (WOO_PI_DEBUG !== true) {
                update_post_meta($product->ID, '_manage_stock', 'yes');
            }
        }
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . sprintf(__('Setting Quantity: %s', 'woo_pi'), $product->quantity);
            if (!$product->manage_stock) {
                $import->log .= "<br />>>>>>> " . sprintf(__('Setting Manage Stock: %s', 'woo_pi'), 'yes');
            }
        } else {
            $import->log .= "<br />>>>>>> " . __('Setting Quantity', 'woo_pi');
            if (!$product->manage_stock) {
                $import->log .= "<br />>>>>>> " . __('Setting Manage Stock', 'woo_pi');
            }
        }
    } else {
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . __('Skipping Quantity', 'woo_pi');
        }
    }
    // Insert Sort Order
    if ($product->sort !== null) {
        $post_data = array('ID' => $product->ID, 'menu_order' => $product->sort);
        if (WOO_PI_DEBUG !== true) {
            $response = wp_update_post($post_data, true);
        } else {
            $response = true;
        }
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . sprintf(__('Setting Sort: %s', 'woo_pi'), $product->sort);
        } else {
            $import->log .= "<br />>>>>>> " . __('Setting Sort Order', 'woo_pi');
        }
        if (is_wp_error($response)) {
            if ($import->advanced_log) {
                $import->log .= "<br />>>>>>>>>> " . sprintf(__('Could not set Sort Order using wp_update_post(): %s - Error: %s', 'woo_pi'), $product->sort, $response->get_error_message());
            } else {
                $import->log .= "<br />>>>>>>>>> " . __('Could not set Sort Order wp_update_post()', 'woo_pi');
            }
            woo_pi_force_update_post($product->ID, 'menu_order', $product->sort);
            if ($import->advanced_log) {
                $import->log .= "<br />>>>>>>>>> " . sprintf(__('Force set Sort Order: %s', 'woo_pi'), $product->sort);
            } else {
                $import->log .= "<br />>>>>>>>>> " . __('Force set Sort Order', 'woo_pi');
            }
        }
    } else {
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . __('Skipping Sort Order', 'woo_pi');
        }
    }
    // Insert Product Status
    if ($product->status !== null) {
        $post_data = array('ID' => $product->ID, 'post_status' => $product->status);
        if (WOO_PI_DEBUG !== true) {
            $response = wp_update_post($post_data, true);
        } else {
            $response = true;
        }
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . sprintf(__('Setting Product Status: %s', 'woo_pi'), $product->status);
        } else {
            $import->log .= "<br />>>>>>> " . __('Setting Product Status', 'woo_pi');
        }
        if (is_wp_error($response)) {
            if ($import->advanced_log) {
                $import->log .= "<br />>>>>>>>>> " . sprintf(__('Could not set Product Status using wp_update_post(): %s - Error: %s', 'woo_pi'), $product->status, $response->get_error_message());
            } else {
                $import->log .= "<br />>>>>>>>>> " . __('Could not set Product Status using wp_update_post()', 'woo_pi');
            }
            woo_pi_force_update_post($product->ID, 'post_status', $product->status);
            if ($import->advanced_log) {
                $import->log .= "<br />>>>>>>>>> " . sprintf(__('Force set Product Status: %s', 'woo_pi'), $product->status);
            } else {
                $import->log .= "<br />>>>>>>>>> " . __('Force set Product Status', 'woo_pi');
            }
        }
    } else {
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . __('Skipping Product Status', 'woo_pi');
        }
    }
    // Insert Enable Reviews
    if ($product->comment_status !== null) {
        $post_data = array('ID' => $product->ID, 'comment_status' => $product->comment_status);
        if (WOO_PI_DEBUG !== true) {
            $response = wp_update_post($post_data, true);
        } else {
            $response = true;
        }
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . sprintf(__('Setting Enable Reviews: %s', 'woo_pi'), $product->comment_status);
        } else {
            $import->log .= "<br />>>>>>> " . __('Setting Enable Reviews', 'woo_pi');
        }
        if (is_wp_error($response)) {
            if ($import->advanced_log) {
                $import->log .= "<br />>>>>>>>>> " . sprintf(__('Could not set Enable Reviews using wp_update_post(): %s - Error: %s', 'woo_pi'), $product->comment_status, $response->get_error_message());
            } else {
                $import->log .= "<br />>>>>>>>>> " . __('Could not set Enable Reviews using wp_update_post()', 'woo_pi');
            }
            woo_pi_force_update_post($product->ID, 'comment_status', $product->comment_status);
            if ($import->advanced_log) {
                $import->log .= "<br />>>>>>>>>> " . sprintf(__('Force set Enable Reviews: %s', 'woo_pi'), $product->comment_status);
            } else {
                $import->log .= "<br />>>>>>>>>> " . __('Force set Enable Reviews', 'woo_pi');
            }
        }
    } else {
        if ($import->advanced_log) {
            $import->log .= "<br />>>>>>> " . __('Skipping Enable Reviews', 'woo_pi');
        }
    }
    // Allow Plugin/Theme authors to add support for additional Product details
    $product = apply_filters('woo_pi_create_product_addons', $product, $import);
    $import = apply_filters('woo_pi_create_product_log_addons', $import, $product);
    // Insert Sample Product Meta
    /*
    	if( $product->sample !== null ) {
    		if( WOO_PI_DEBUG !== true )
    			update_post_meta( $product->ID, '_sample', $product->sample );
    		if( $import->advanced_log )
    			$import->log .= "<br />>>>>>> " . sprintf( __( 'Setting Sample Product Meta: %s', 'woo_pi' ), $product->sample );
    		else
    			$import->log .= "<br />>>>>>> " . __( 'Setting Sample Product Meta', 'woo_pi' );
    	} else if( $import->advanced_log ) {
    		$import->log .= "<br />>>>>>> " . __( 'Skipping Sample Product Meta', 'woo_pi' );
    	}
    */
}
 function woo_pi_html_page()
 {
     global $import;
     $action = woo_get_action();
     $title = __('Product Importer', 'woo_pi');
     if (in_array($action, array('upload', 'save')) && !$import->cancel_import) {
         if ($file = woo_pi_get_option('csv')) {
             $title .= ': <em>' . basename($file) . '</em>';
         }
     }
     $troubleshooting_url = 'http://www.visser.com.au/woocommerce/documentation/plugins/product-importer-deluxe/usage/';
     $woo_pd_url = 'http://www.visser.com.au/woocommerce/plugins/product-importer-deluxe/';
     $woo_pd_link = sprintf('<a href="%s" target="_blank">' . __('Product Importer Deluxe', 'woo_pi') . '</a>', $woo_pd_url);
     woo_pi_template_header($title);
     woo_pi_support_donate();
     woo_pi_upload_directories();
     switch ($action) {
         case 'upload':
             if (isset($import->file)) {
                 $file = $import->file;
             } else {
                 $file = array('size' => 0);
             }
             /*
             				if( $file['size'] == 0 ) {
             					$message = __( '', 'woo_pi' );
             					woo_pi_admin_notice( '' );
             					$import->cancel_import = true;
             				}
             */
             // Display the opening Import tab if the import fails
             if ($import->cancel_import) {
                 woo_pi_manage_form();
                 return;
             }
             $upload_dir = wp_upload_dir();
             if ($file) {
                 woo_pi_prepare_data();
                 $i = 0;
                 $products = woo_pi_return_product_count();
                 // Override the default import method if no Products exist
                 if (!$products) {
                     $import->import_method = 'new';
                 }
                 $import->options = woo_pi_product_fields();
                 $import->options_size = count($import->options);
                 $first_row = array();
                 $second_row = array();
                 if (isset($import->lines)) {
                     // Detect character encoding and compare to selected file encoding
                     $auto_encoding = mb_detect_encoding($import->raw);
                     if ($auto_encoding !== false) {
                         if (strtolower($auto_encoding) != strtolower($import->encoding)) {
                             woo_pi_update_option('encoding', $auto_encoding);
                             $message = sprintf(__('It seems the character encoding provided under General Settings on the Settings tab - <code>%s</code> - didn\'t match this import file so we automatically detected the character encoding for you to <code>%s</code>.', 'woo_pi'), $import->encoding, $auto_encoding);
                             // Force the message to the screen as we are post-init
                             woo_pi_admin_notice_html($message);
                         }
                     }
                     $first_row = str_getcsv($import->lines[0], $import->delimiter);
                     $import->columns = count($first_row);
                     // If we only detect a single column then the delimiter may be wrong
                     if ($import->columns == 1) {
                         $auto_delimiter = woo_pi_detect_file_delimiter((string) $first_row[0]);
                         if ($import->delimiter != $auto_delimiter) {
                             $import->delimiter = $auto_delimiter;
                             $first_row = str_getcsv($import->lines[0], $import->delimiter);
                             $import->columns = count($first_row);
                             // If the column count is unchanged then the CSV either has only a single column (which won't work) or we've failed our job
                             $priority = 'updated';
                             if ($import->columns > 1) {
                                 $message = sprintf(__('It seems the field delimiter provided under Import Options - <code>%s</code> - didn\'t match this CSV so we automatically detected the CSV delimiter for you to <code>%s</code>.', 'woo_pi'), woo_pi_get_option('delimiter', ','), $auto_delimiter);
                                 woo_pi_update_option('delimiter', $import->delimiter);
                             } else {
                                 $priority = 'error';
                                 $message = __('It seems either this CSV has only a single column or we were unable to automatically detect the CSV delimiter.', 'woo_pi') . ' <a href="' . $troubleshooting_url . '" target="_blank">' . __('Need help?', 'woo_pi') . '</a>';
                             }
                             // Force the message to the screen as we are post-init
                             woo_pi_admin_notice_html($message, $priority);
                         }
                         unset($auto_delimiter);
                     }
                     $second_row = str_getcsv($import->lines[1], $import->delimiter);
                     unset($import->lines);
                 }
                 foreach ($first_row as $key => $cell) {
                     for ($k = 0; $k < $import->options_size; $k++) {
                         if (woo_pi_format_column($import->options[$k]['label']) == woo_pi_format_column($cell)) {
                             $import->skip_first = true;
                             break;
                         }
                     }
                     if (!isset($second_row[$key])) {
                         $second_row[$key] = '';
                     }
                 }
                 include_once WOO_PI_PATH . 'templates/admin/import_upload.php';
             }
             break;
         case 'save':
             // Display the opening Import tab if the import fails
             if ($import->cancel_import == false) {
                 include_once WOO_PI_PATH . 'templates/admin/import_save.php';
             } else {
                 woo_pi_manage_form();
                 return;
             }
             break;
         default:
             woo_pi_manage_form();
             break;
     }
     woo_pi_template_footer();
 }
Esempio n. 3
0
function woo_pi_tab_template($tab = '')
{
    global $import;
    if (!$tab) {
        $tab = 'overview';
    }
    // Product Importer Deluxe
    $woo_pd_url = 'http://www.visser.com.au/woocommerce/plugins/product-importer-deluxe/';
    $woo_pd_link = sprintf('<a href="%s" target="_blank">' . __('Product Importer Deluxe', 'woo_pi') . '</a>', $woo_pd_url);
    $troubleshooting_url = 'http://www.visser.com.au/documentation/product-importer/';
    switch ($tab) {
        case 'overview':
            $skip_overview = woo_pi_get_option('skip_overview', false);
            break;
        case 'import':
            woo_pi_upload_directories();
            $upload_dir = wp_upload_dir();
            $max_upload = (int) ini_get('upload_max_filesize');
            $max_post = (int) ini_get('post_max_size');
            $memory_limit = (int) ini_get('memory_limit');
            $wp_upload_limit = round(wp_max_upload_size() / 1024 / 1024, 2);
            $upload_mb = min($max_upload, $max_post, $memory_limit, $wp_upload_limit);
            $file_path = $upload_dir['basedir'] . '/';
            $file_path_relative = 'imports/store-a.csv';
            $file_url = 'http://www.domain.com/wp-content/uploads/imports/store-a.jpg';
            $file_ftp_host = 'ftp.domain.com';
            $file_ftp_user = '******';
            $file_ftp_pass = '******';
            $file_ftp_port = '';
            $file_ftp_path = 'wp-content/uploads/imports/store-a.jpg';
            $file_ftp_timeout = '';
            if (isset($_POST['csv_file_path'])) {
                $file_path_relative = $_POST['csv_file_path'];
            }
            $modules = woo_pi_modules_list();
            $csv_sample_link = 'http://www.visser.com.au/woocommerce/plugins/product-importer-deluxe/#sample-csv';
            $csv_template_link = 'http://www.visser.com.au/woocommerce/plugins/product-importer-deluxe/#blank-csv';
            if (isset($_GET['import']) && $_GET['import'] == WOO_PI_PREFIX) {
                $url = 'import';
            }
            if (isset($_GET['page']) && $_GET['page'] == WOO_PI_PREFIX) {
                $url = 'page';
            }
            break;
        case 'settings':
            $delete_file = woo_pi_get_option('delete_file', 0);
            $timeout = woo_pi_get_option('timeout', 0);
            $encoding = woo_pi_get_option('encoding', 'UTF-8');
            $delimiter = woo_pi_get_option('delimiter', ',');
            $category_separator = woo_pi_get_option('category_separator', '|');
            $parent_child_delimiter = woo_pi_get_option('parent_child_delimiter', '>');
            $secret_key = woo_pi_get_option('secret_key', '');
            $file_encodings = function_exists('mb_list_encodings') ? mb_list_encodings() : false;
            break;
        case 'tools':
            // Store Exporter
            $woo_ce_url = 'http://www.visser.com.au/woocommerce/plugins/exporter/';
            $woo_ce_target = ' target="_blank"';
            if (function_exists('woo_ce_export_dataset')) {
                $woo_ce_url = add_query_arg(array('page' => 'woo_ce', 'tab' => null));
                $woo_ce_target = false;
            }
            // Store Toolkit
            $woo_st_url = 'http://www.visser.com.au/woocommerce/plugins/store-toolkit/';
            $woo_st_target = ' target="_blank"';
            if (function_exists('woo_st_admin_init')) {
                $woo_st_url = add_query_arg(array('page' => 'woo_st', 'tab' => null));
                $woo_st_target = false;
            }
            break;
    }
    if ($tab) {
        if (file_exists(WOO_PI_PATH . 'templates/admin/tabs-' . $tab . '.php')) {
            include_once WOO_PI_PATH . 'templates/admin/tabs-' . $tab . '.php';
        } else {
            $message = sprintf(__('We couldn\'t load the export template file <code>%s</code> within <code>%s</code>, this file should be present.', 'woo_pi'), 'tabs-' . $tab . '.php', WOO_PI_PATH . 'templates/admin/...');
            woo_pi_admin_notice_html($message, 'error');
            ob_start();
            ?>
<p><?php 
            _e('You can see this error for one of a few common reasons', 'woo_pi');
            ?>
:</p>
<ul class="ul-disc">
	<li><?php 
            _e('WordPress was unable to create this file when the Plugin was installed or updated', 'woo_pi');
            ?>
</li>
	<li><?php 
            _e('The Plugin files have been recently changed and there has been a file conflict', 'woo_pi');
            ?>
</li>
	<li><?php 
            _e('The Plugin file has been locked and cannot be opened by WordPress', 'woo_pi');
            ?>
</li>
</ul>
<p><?php 
            _e('Jump onto our website and download a fresh copy of this Plugin as it might be enough to fix this issue. If this persists get in touch with us.', 'woo_pi');
            ?>
</p>
<?php 
            ob_end_flush();
        }
    }
}