Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spree 2.4.3: Count on hand not being loaded with products (.xls) #35

Open
redglory opened this issue Feb 16, 2015 · 9 comments
Open

Spree 2.4.3: Count on hand not being loaded with products (.xls) #35

redglory opened this issue Feb 16, 2015 · 9 comments

Comments

@redglory
Copy link
Contributor

I'm trying to load some products and everything goes as expected except for the count_on_hand stock items. It remains 0. My column looks liem this:

Variants | StockItem
newborn-clothes-size:0M;color:branco | count_on_hand:1

Spree v2.4.3

What am I missing here?!

@redglory redglory changed the title Count on hand not being loaded Spree 2.4.3: Count on hand not being loaded with products (.xls) Feb 16, 2015
@autotelik
Copy link
Owner

Spree added a whole new stock keeping layer to Spree 2

The old count_on_hand is no longer on Variant. Have you tried using the master branch ... I have been working to get full 2 support in master ..

If you still have issues, see from line 138 of https://github.com/autotelik/datashift_spree/blob/master/lib/loaders/spree/product_loader.rb - v.stock_items.first.count_on_hand

@redglory
Copy link
Contributor Author

I'm running from master (git assignment).

This is a row form my .xls:

sku | name |    description | avaliable_on  | cost_price |  price   | shipping_category | tax_category |    taxons |    taxons |    taxons |    taxons |    product_properties |    variants    | stock_location_name | stock_items
3218 |  Conjunto Gorro e Luvas |    Conjunto Gorro e Luvas  | 2015-02-12    | 6,28 |    13,82   | CTT - Correio Normal < 2kg    | IVA   | Secções>Bebé Menino    | Marcas>Tuc Tuc |  Categorias>Gorros e Bonés |        Composição:100% Algodão  | newborn-clothes-size:0M;color:branco  | casa_susana   | count_on_hand:1

My log states:

#<ActiveRecord::RecordInvalid: Validation failed: Stock location can't be blank, Variant can't be blank>
Cannot assign [#<Spree::StockItem id: nil, stock_location_id: nil, variant_id: nil, count_on_hand: 0, created_at: nil, updated_at: nil, backorderable: false, deleted_at: nil>] (Array) to has_many association [stock_items] 

I'm trying to pass a column as "stock_location_name" before sotck_items one...

Will look into this code and thank you for your support :)

@autotelik
Copy link
Owner

To manage stock you need at least one Stock Location defined in your store. IF yuo cleared out the defautl seeds etc you may not have the default ... you can add one via the admin GUI ... .. see https://guides.spreecommerce.com/user/configuring_inventory.html

I did come across another potential call you might try..adjust_count_on_hand :

variant.stock_items.first.adjust_count_on_hand(quantity)

@redglory
Copy link
Contributor Author

I have 2 stock locations defined on my DB. I tried to select one in my .xls with column "stock_location" and value "name:casa_susana" to no avail.

I would have to replace product_loader.rb to accomplish that right? (variant.stock_items.first.adjust_count_on_hand(quantity))

@autotelik
Copy link
Owner

yes something like ... inherit from product_loader

implement ... your own def process(method_detail, value)
which just fixes for count on hand otherwise call super

if(current_value && (current_method_detail.operator?('count_on_hand') || current_method_detail.operator?('on_hand')) )

 # NEW IMPLEMENTATION THAT WORKS FOR STOCK

else
super( file_name, opts )
end

@redglory
Copy link
Contributor Author

Forking your project and gonna try this.

Thanks for the pointers :)

@redglory
Copy link
Contributor Author

I've forked datashift_spree and made some changes so that we can load stock with Spree version >= 2.2.

already tested. sure it needs some code cleanup but it works, at least for me

https://github.com/redglory/datashift_spree/blob/master/lib/loaders/spree/product_loader.rb

Please check :)

@autotelik
Copy link
Owner

Hi .. thanks so much for contributing .. please submit a pull request, will be easier to visualize diffs and I will merge into main gem

cheers
tom

@redglory
Copy link
Contributor Author

redglory commented Mar 1, 2015

Hey sure thing.

Not at home right nos but will pull request lateral at night.

Cheers

EDIT: #36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants