Jump to content

Welcome, Guest!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

  • 0
Theo

How to update or replace a Product's Feature Values using CSV Import?

Question

Hi

I've been battling with this one for a bit now. Maybe you guys know the answer?

I'm currently testing Product Update with CSV Import, but I'm stuck trying to update or replace the Product's Feature Values.

Instead of updating the feature values for this specific product, the system keeps on appending / adding the value to the feature.
This is great when you want to have multiple values for a feature (more on this one in another post). However, this is not great when I need to update or replace a product's feature values.
For example, I have a feature called "Rental price" and the initial value is "200". If I try to update this to "300", then the values allocated to this product is "200, 300".
Is there any way that I can reset all feature values for a specific product with a CSV import? Similar perhaps to "deleting existing images" when doing a product image update?

Also, I've tried to do "Custom position", but this does not show up in the filter / layered navigation - which is what I need.

Please let me know if there is a solution or some way to do this with CSV import or if there is a good module that allows you to update / replace a product's feature values?

 

Thanks in advance. 

 

 

 

Share this post


Link to post
Share on other sites

14 answers to this question

Recommended Posts

  • 0

You are probably not using the native CSV import feature. In your case with the native CSV import feature, it's not possible to assign both 200 and 300 to the "Rental price" feature, the old value 200 will be replaced by the new value 300.

Share this post


Link to post
Share on other sites
  • 0

Hi

Thanks for your reply Jonny.

I'm using the native CSV import feature. However, I am using a free module to enable "multiple values for a feature" for both the product screen and the layered navigation filter.
I suspect this is what's causing the issue... Kinda sucks that TB doesn't support multiple values for a feature yet - to avoid us using 3rd party modules to enable "basic" functionality...

I may now be forced to go the paid route for both "feature value update with CSV" as well as "multiple values for a feature for both layered navigation, product page, comparison, product list and csv import". Perhaps you can recommend any good ones?

This is the module I've been using to enable multiple values for a feature:
https://github.com/jdanthinne/advancedfeaturesvalues 

Edited by Theo

Share this post


Link to post
Share on other sites
  • 0

You can do a small customization to the CSV import feature to remove feature values first, and then import new values.

Share this post


Link to post
Share on other sites
  • 0

Hi Jonny

This is exactly what I'm looking for - so how do I do this?

 

 

Share this post


Link to post
Share on other sites
  • 0

Try adding this code to the \controllers\admin\AdminImportController.php file.

if ($forceIds || $matchRef)
    $product->deleteFeatures();

I didn't test it, because of I don't want to install the "advancedfeaturesvalues" module which overrides several files. Test it by yourself on a development site first.

Share this post


Link to post
Share on other sites
  • 0

Thanks for this...

We will be using Panda for our site (all this is part of testing our requirements) - as the "Advancedfeaturesvalues" module overrides several files, I'm a bit concerned if it will work with Panda...
As I know you haven't used this module before, do you maybe know of a module that does work with Panda - for "multiple feature values" -- for both layered navigation filter and product display (+ product list and comparison screens)?

I can only test this on Panda if TB meets our testing requirements, then we will go ahead with TB and a Panda purchase... which makes testing before then a bit challenging in this case...

Edited by Theo

Share this post


Link to post
Share on other sites
  • 0

Don't worry, the module can work fine with Panda theme, actually most 3rd modules can work with Panda theme, don't worry too much about compatibility. Panda theme didn't do any changes to the way of how TB works, so as long as a module is compatible with TB, then it can work fine Panda theme functionally.

Share this post


Link to post
Share on other sites
  • 0

Ok cool, that's great to hear.

By the way:
The code above, it looks like it will always delete features (unless I'm mistaken). Is there anyway it will only fire if there are features specified in the CSV?

 

Share this post


Link to post
Share on other sites
  • 0

Awesome! This helps 🙂 Thanks Jonny 🙂 

Will try this later and will let you know.

 

 

Edited by Theo

Share this post


Link to post
Share on other sites
  • 0

Hi Jonny

I've managed to test this today, and unfortunately it doesn't seem to be working... It gives me a 500 error on the CSV Import page when I try to add:


if ($forceIds || $matchRef) {
                       $product->deleteFeatures();
                    }

As per above.

In debug mode, it gives me the following error. Irrespective of whether I add curly brackets or not (notice your example did not have curly brackets for the if statement...)

features error.png

If I remove the curlies, it gives me an error on the foreach...

Edited by Theo

Share this post


Link to post
Share on other sites
  • 0

Which text editor you are using, I guess it's more about file format or something, That code is syntax correct with or without curly brackets.

Try using the cPanle's editor to apply the change, see attached pic, you can copy that code to change it, don't copy the code I sent you above.

Screenshot00929.jpg

Share this post


Link to post
Share on other sites
  • 0

Hi Jonny

This is so strange - probably one of those weird formatting issues... I copied the code directly from the file (and not from your example) and added  $product->deleteFeatures();
And now it works! (on initial tests anyway)

Weird...

I appreciate the reply back and solution, thank you. Will let you know if I encounter any issues with this during more thorough tests...
(oh and the text editor I'm using is Sublime Text)

Edited by Theo
  • Like 1

Share this post


Link to post
Share on other sites
  • 0

And also, for anyone reading this thread: 
The caveat or note with this solution is that it Nukes / deletes all Features pertaining to this product - and not just the ones that you're updating.
This means that you will need to 'replace' all the product's features when doing an update - you can't just do an update on one feature only.
So if you have 4 features on a product and only want to update 1, then you will need to remember to include all 4 features, and not just one in the CSV import when doing an update.
If you only have one feature, then it will delete the other 3, and only import 1.
This entire solution is geared to adding "updating feature values" with CSV Import to this free module (the module enables TB to have features with multiple values).
https://github.com/jdanthinne/advancedfeaturesvalues 

If you're not using this module or do not need to update features with multiple values using CSV Import, then this solution is not necessary, as TB updates feature values (one value per feature) on import without needing to change any code. It's just with "multiple values per feature" that there is a problem.

However, if you are using this module and need to update feature values when doing a CSV import,
in  \controllers\admin\AdminImportController.php file:
you need to add the following (the part in bold) just after "if (!$validateOnly && isset($features['features']) && !empty($features['features'])) {"

 // Features import
            $features = get_object_vars($product);

            if (!$validateOnly && isset($features['features']) && !empty($features['features'])) {
                if ($forceIds || $matchRef) {
                    $product->deleteFeatures();
                }


This deletes the target product's features and replaces it with what is specified in the CSV.

Full credit to @Jonny for the solution to this problem, obviously 🙂
 

Edited by Theo
  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×