GithubHelp home page GithubHelp logo

Comments (15)

autotelik avatar autotelik commented on August 10, 2024

Ok this is a bug in datashift_spree products loader

See method add _ options _ variants

It sets the sku automatically on the variant regardless, need to add a check and only auto generate the sku if not present in the spreadsheet

Sent from Yahoo Mail on Android

from datashift_spree.

autotelik avatar autotelik commented on August 10, 2024

Hmmm maybe im talking nonsense... seems actually as long as variant_sku column appear AFTER variants column this should not matter as the auto sku should be over written

from datashift_spree.

autotelik avatar autotelik commented on August 10, 2024

I cannot change at moment but I believe bug in line 136 - 138 of product loader

else
super
end

The call to super will not work in this case as the column name is actually 'sku' not 'variant_sku' so specific code needs adding here to assign the sku to the Variant

from datashift_spree.

autotelik avatar autotelik commented on August 10, 2024

something like .....

if(@load_object.variants.size > 1)
@load_object.variants.each_with_index {|v, i| v.sku = "#{current_value}_#{i}" }
else
@load_object.variants.first.sku = current_value.to_s
end

@load_object.save

from datashift_spree.

fredericboivin avatar fredericboivin commented on August 10, 2024

This is still an issue.

I don't completely understand all the code so I'm not sure where to stand but from what I gather, the variant_sku are correctly assigned but not saved.

When the loop is done, @load_object.save is called, which attemps to save the master product only, so it seems like the Variant SKUs are getting replaced locally but the @load_object affects only the master and the changes are not being persisted.

Since they use the same code, I guess it affects variant_price and count_on_hand equally.

Any suggestions?

from datashift_spree.

autotelik avatar autotelik commented on August 10, 2024

Some changes to fix count_on_hand for Spree 2 have literally just been checked in.

Sorry bit hard to follow the trail ..can you specify exactly which fields are not being persisted as you expect .. On Variants ?

sku, price and count_on_hand ? For what version of Spree ? And using master branch from github (not gem) ?

thanks
tom

from datashift_spree.

fredericboivin avatar fredericboivin commented on August 10, 2024

I'm using the latest version of everything :

Datashift v0.16.0@d561aa (from github)
Datashift_spree v.0.6.0@d6e271 (from github)

Spree 2.4.3

And I'm trying to assign specific SKUs to variant by using variant_sku, "sku1|sku2|sku3"

I've found the issue though :

SKU are not updated because the children (Spree::Variant) are updated locally through the parent (Spree::Product) and Spree::Product does not accepts_nested_attributes for Spree::Variant so the changes on the children are not persisted when saving the parent (@load_object.save)

So it's possible to replace @load_object.save by

@load_object.variants.each do |i|
i.save
end

Or we could use v.update_attributes( sku: values[i].to_s") instead.

I don't know the project well enough to know the best way to fix it, what are your thoughts?

(English is not my mother tongue so sorry if it's not exactly clear)

I'm referring to this part of the code

elsif(current_method_detail.operator?('variant_sku') && current_value)
      if(@load_object.variants.size > 0)

        if(current_value.to_s.include?(Delimiters::multi_assoc_delim))

          # Check if we processed Option Types and assign  per option
          values = current_value.to_s.split(Delimiters::multi_assoc_delim)

          if(@load_object.variants.size == values.size)
            @load_object.variants.each_with_index {|v, i| v.sku = values[i].to_s}
            @load_object.variants.each do |i|
              i.save
            end
            @load_object.save
          else
            puts "WARNING: SKU entries did not match number of Variants - None Set"
          end

        end
      else
        super
      end

from datashift_spree.

redglory avatar redglory commented on August 10, 2024

Hum... I've not changed any code regarding 'variant_sku' method and I got my custom variant sku's saved...

from datashift_spree.

fredericboivin avatar fredericboivin commented on August 10, 2024

I will post a more detailed use case later today with a CSV sample, dependencies version, log entries from Datashift and resulting SQL.

from datashift_spree.

fredericboivin avatar fredericboivin commented on August 10, 2024

Sample CSV

SKU Name ShippingCategory Price Option Types Option Types Option Types variant_sku
ILJR0247 TSHIRT PROMO DEFAUT 100 color:Q; size:M color:Q; size:G color:A; size:TP 10583856

Resultings SKU :

| ILJR0247_1
| ILJR0247_2
| ILJR0247_3

Variant_SKU is processed without problem but values aren't overwritten. From the logs, it's clear that after looping over @load_object. variants, the SKUs are replaced locally but the changes aren't persisted when the Product is saved.

If you look at a relevant part of the log, you see that no UPDATE is being called on any variant.

http://pastebin.com/uLLc8NTC

Could you post a sample of your working CSV ? Also, which version of Rails/Spree are you running?

I might be doing something wrong but still, if I save the Product.variants explicitly in the 'variant_sku' block, it works

I'm curious about your thoughts on this

from datashift_spree.

autotelik avatar autotelik commented on August 10, 2024

redglory kindly commited some fixes all around this yesterday (936b96e)

Have you tried pulling this latest from master ? if this does not fix your problem just let me know and I'll try and go through your examples/logs.

from datashift_spree.

autotelik avatar autotelik commented on August 10, 2024

@load_object.variants.each_with_index {|v, i| v.sku = values[i].to_s }
@load_object.save

I assume save on Parent product peculates down to associations but given what you see perhaps not

I don't have time to dev/test this right now, so if you're desperate ..try changing

Line 154 .... @load_object.variants.each_with_index {|v, i| v.sku = values[i].to_s }

To save the Variant itself, something like :

@load_object.variants.each_with_index do |v, i|
v.sku = values[i].to_s
begin
v.save!
rescue => x
logger.error "Warning SKU not set on Variant #{v.inspect} #{e.message}"
end

cheers
tom

from datashift_spree.

fredericboivin avatar fredericboivin commented on August 10, 2024

I will try again with the master branch and get back to you

Cheers

from datashift_spree.

joeswann avatar joeswann commented on August 10, 2024

Just ran into pretty much this issue with spree 3.0.0 and variant_price

Changing line 112 to this seemed to do the trick
@load_object.variants.each_with_index {|v, i| v.update_attributes(price: values[i].to_f) }

from datashift_spree.

ping0xFF avatar ping0xFF commented on August 10, 2024

@joeswann Thanks, that fixed it per your suggestion.

@load_object.variants.each_with_index {|v, i| v.update_attributes(sku: values[i].to_f) }

from datashift_spree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.