Restrict which fields are imported when updating existing records

Closed

Import WP Pro Updated 1 year ago 8 Replies

Ángel asked 2 years ago on July 18, 2023 at 10:00 am

Hello,

I have imported several products, with thousands of images, and now I have added 3 new attributes:

 

1. Attribute1 Field {21}

2. Attribute2 Field {22}

3. Attribute3 Field {23}

 

I would like to know what name I should put on this attached field.

I would not like to import everything again, just the value of those attributes I have added.

I am waiting for your clarification. Thank you.

PS: When will there be a new update of your great add-on?

J

James replied Support Agent

2 years ago on July 18, 2023 at 6:50 pm

Hi,

I have included the latest version of the importwp-woocommerce addon, this has some small tweaks to the product attribute importer.

To restrict attributes being updated, the permissions field key for each is:

product_attributes.{row_number minus 1}

Using the attached screenshot as an example, the Colour product attribute on row 1 would have the permission key:

product_attributes.0

And the Tags attribute permission key on row 2 would be:

product_attributes.1

As with any import i would recommend backing up your files and database, before running any import. Then running the import on a small dataset to make sure it is working as expected before running the full import.

James

ĂL

Ángel replied

2 years ago on July 19, 2023 at 10:06 am

Hello, 

 

I have tried to follow the steps carefully, but when I import the attributes, the attributes with variations that I had created, are deleted and all their images and price combinations...

 

1. Create and import an import file type "Variable Products" for the unique SKUs of the products.

2. Create and import a "Product Variation" import file type for the variable attributes (size and colour).

 

So far so good, but when I try to add more attributes to the file point 1 and import (indicating that I only want to import the attributes that I mark) the import completes, but deletes the variations of point 2. I lose all the size and colour variations of point 2, and gain all the variations that I added.

 

I have added in the permissions step, that it only updates the new attributes:

 

Attribute Filta 6 --> product_attributes.7

Attribute Row 7 --> product_attributes.8

Attribute Row 8 --> product_attributes.9

Attribute Row 9 --> product_attributes.10

Attribute Row 10 --> product_attributes.11

Attribute Row 11 --> product_attributes.12

Attribute Row 12 --> product_attributes.13

 

The new attributes are added correctly, but it deletes the previously imported product variations. Why? I don't understand. Can you help me? Thank you.

 

Regards

 
J

James replied Support Agent

2 years ago on July 19, 2023 at 8:32 pm

thank you for explaining the steps to follow, i have been able to replicate the issue.

To resolve this i have added a new wordpress filter:

add_filter('iwp/woocommerce/product_attributes/keep_existing', '__return_true');

This overrides the default behaviour when importing attributes, allowing you to append / update them instead of clearing the products attributes each time.

I have attached an updated version of the importwp-woocommerce plugin, along with a custom plugin that adds the previously mentioned code.

ĂL

Ángel replied

2 years ago on July 21, 2023 at 7:07 am

Hi James,

 

This modification seems to work well. Thank you.

 

I hope an official update will be released soon, with these patches included. Your extension has a huge potential, don't leave it. ;)

 

Can you tell me where to find the keys for each parameter? In products attributes is product_attributes.[number -1}

 

But what is the key of other parameters? For example, if I just want to update the stock of the variation.

 

I look forward to hearing from you. Thank you.

J

James replied Support Agent

2 years ago on July 21, 2023 at 10:12 am

The changes made to the plugin will be available in its next release.

A full list of product permission keys:

post_title
post_name
post_content
post_excerpt
post_status
product_type
_virtual
_downloadable
_visibility
_product_url
_button_text
tax_status
tax_class
post_author
_regular_price
_sale_price
_sale_price_dates_to
_sale_price_dates_from
_sku
_stock_status
_manage_stock
_stock
_backorders
_low_stock_amount
_sold_individually
_weight
_length
_width
_height
shipping_class
_purchase_note
_download_limit
_download_expiry
post_date
product_gallery.*
product_downloads.*
product_upsell
product_crosssell
product_grouped

The main ones to note in stock is the:

_stock_status
_manage_stock
_stock
_low_stock_amount
ĂL

Ángel replied

2 years ago on July 21, 2023 at 11:26 am

Hello James,

Thanks, it seems to be working correctly, although the import of 25,000 rows is very slow...

I will do some tests.

Yours sincerely,

Angel.

J

James replied Support Agent

2 years ago on July 21, 2023 at 12:27 pm

The importer does not directly change the value of the stock or any product database value, instead it uses the woocommerce methods to alter them, it does this for compatability reasons with other plugins and themes, this can however slow the importer down based on the amount of other installed plugins.

I will run some tests with the same records size to see if anything can be optimised.

ĂL

Ángel replied

1 year ago on July 24, 2023 at 8:36 am

Hello,

 

Maybe a direct import to the wp_wc_product_meta_meta_lookup table and its corresponding transient update, would be a good way. Importing line by line is very slow.

 

I look forward to hearing from you. Thank you.