• waheed146

    (@waheed146)


    Very great plugin and helpful.
    I need help becuase the many products have same images
    can the function woocommerce_osc_import_image modified so that if image exist used their attachment id instead of upload same product for new product. please take a look the function if it works.

    function woocommerce_osc_import_image($url){
    $attach_id = 0;
    $wp_upload_dir = wp_upload_dir();

    $filename = $wp_upload_dir[‘path’].’/’.sanitize_file_name(basename($url));

    if(file_exists($filename)){
    $image_url = $filename;

    $attach_id = attachment_url_to_postid($local_url);
    require_once(ABSPATH . ‘wp-admin/includes/image.php’);
    $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
    wp_update_attachment_metadata( $attach_id, $attach_data );
    }else{
    //Encode the URL
    $base = basename($url);
    $url = str_replace($base,urlencode($base),$url);
    if($f = @file_get_contents($url)){
    file_put_contents($filename,$f);

    $wp_filetype = wp_check_filetype(basename($filename), null );

    $attachment = array(
    ‘guid’ => $wp_upload_dir[‘url’] . ‘/’ . basename( $filename ),
    ‘post_mime_type’ => $wp_filetype[‘type’],
    ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename($filename)),
    ‘post_content’ => ”,
    ‘post_status’ => ‘inherit’
    );
    $attach_id = wp_insert_attachment( $attachment, $filename, 37 );
    require_once(ABSPATH . ‘wp-admin/includes/image.php’);
    $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
    wp_update_attachment_metadata( $attach_id, $attach_data );
    }
    }
    return $attach_id;
    }

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Alejandro Aranda

    (@alexwing)

    Hi, thanks.

    It seems that the function that you attach to me would be worth replacing the name with otw_import_image, but you have to perform tests to see if it has any implication.

    Thread Starter waheed146

    (@waheed146)

    yes that was the function.
    actually i m using old version and it have modified according to my oscommerce requirements.
    please take my question and i need solution how do i use same image for different products. please recode the image upload function in a way if a product image already uploaded then use that image instead to upload same product again.
    i have disabled to use date folders.

    Thanks.

    Thread Starter waheed146

    (@waheed146)

    with the updated plugin. the gallery attached images http://prntscr.com/lbtl5d not shown where the images attached. also is there any way to if image exist then used that image instead to upload same image again.also the delete image not work properly to delete images.

    Hope to hear back from you soon.
    thanks.

    Plugin Author Alejandro Aranda

    (@alexwing)

    I have yet to update the function that uploads the images, which does not duplicate the already exist in the library.

    With respect to the other of the attachments I do not understand very well what you mean.

    Thread Starter waheed146

    (@waheed146)

    any suggestion.
    one product of oscommerce when move to woocommerce
    new product create successfully
    when i have debug I have seen
    this product have 22 attributes and 2048 combo
    it means that this product need to create 2048 new posts with product variation type
    but at the end blank screen or temporarily resources not available seen.
    and in final receive only new product in woocommerce but not attribute.
    is there any way we could create all the variations as well. can it be done by using ajax?

    please suggest

    Thanks

    Plugin Author Alejandro Aranda

    (@alexwing)

    The truth is that the part of the attributes, the inheritance of the previous developer of the plugin and I have not had time to analyze it, possibly have something that is missing but should create the products correctly.

    This is the code.

    ` if ($attributes = $oscdb->get_results(“SELECT po.products_options_name, pov.products_options_values_name FROM products_attributes pa, products_options po, products_options_values pov WHERE pa.products_id='” . $product[‘products_id’] . “‘ AND pov.products_options_values_id = pa.options_values_id AND pov.language_id=po.language_id AND pa.options_id=products_options_id”, ARRAY_A)) {
    wp_set_object_terms($product_id, ‘variable’, ‘product_type’);
    $attrib_array = array();
    $attrib_combo = array();
    $max_price = $product[‘products_price’];
    $min_price = $product[‘products_price’];
    foreach ($attributes as $attribute) {
    $slug = sanitize_title($attribute[‘products_options_name’]);
    $attrib_array[$slug] = array(‘name’ => $attribute[‘products_options_name’],
    ‘value’ => ltrim($attrib_array[$slug][‘value’] . ‘ | ‘ . $attribute[‘products_options_values_name’], ‘ | ‘),
    ‘position’ => 0,
    ‘is_visible’ => 1,
    ‘is_variation’ => 1,
    ‘is_taxonomy’ => 0);
    $attrib_combo[$slug][] = array($attribute[‘products_options_values_name’], ($attribute[‘price_prefix’] == ‘-‘ ? ‘-‘ : ”) . $attribute[‘options_values_price’]);
    }
    // Now it gets tricky…
    $combos = otw_cartesian_product($attrib_combo);
    foreach ($combos as $combo) {
    $variation_id = wp_insert_post(array(
    ‘post_title’ => ‘Product ‘ . $product_id . ‘ Variation’,
    ‘post_content’ => ”,
    ‘post_status’ => ‘publish’,
    ‘post_type’ => ‘product_variation’,
    ‘post_author’ => 1,
    ‘post_parent’ => $product_id
    ));
    $opt_price = $product[‘products_price’];
    $special_price = $special[‘specials_new_products_price’];
    foreach ($combo as $k => $v) {
    update_post_meta($variation_id, ‘attribute_’ . $k, $v[0]);
    $opt_price += $v[1];
    $special_price += $v[1];
    }
    update_post_meta($variation_id, ‘_sku’, $product[‘products_model’]);
    update_post_meta($variation_id, ‘_regular_price’, $opt_price);
    update_post_meta($variation_id, ‘_price’, $opt_price);
    update_post_meta($variation_id, ‘_thumbnail_id’, 0);
    update_post_meta($variation_id, ‘_stock’, $product[‘products_quantity’]);
    if ($special) {
    update_post_meta($variation_id, ‘_sale_price’, $special_price);
    if ($special[‘expires_date’] > time()) {
    update_post_meta($variation_id, ‘_sale_price_dates_to’, date(“Y-m-d”, $special[‘expires_date’]));
    update_post_meta($variation_id, ‘_sale_price_dates_from’, date(“Y-m-d”));
    }
    }
    if ($opt_price > $max_price) {
    $max_price = $opt_price;
    }
    if ($opt_price < $min_price) {
    $min_price = $opt_price;
    }
    }

    Thread Starter waheed146

    (@waheed146)

    Yes I am talkig about this code. can you analyze that part of the code and makes it to perform well as i have question.

    Plugin Author Alejandro Aranda

    (@alexwing)

    I currently have time to improve the plugin, I will try to do a test but I can not guarantee anything.

    Thread Starter waheed146

    (@waheed146)

    I hope to hear back from you soon

    Thread Starter waheed146

    (@waheed146)

    process breaks if a product of eCommerce have a lot of attribute. can you please help to not break the process.

    Thread Starter waheed146

    (@waheed146)

    can we separate out the attribute and variation process instead that whole process like we have separate the image and gallery process?

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Duplicate product images’ is closed to new replies.