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

OrderPopulator is deprecated. 404 when trying to add items to cart (Spree - 2.4.5) #6195

Closed
APohio opened this issue Mar 17, 2015 · 5 comments

Comments

@APohio
Copy link

APohio commented Mar 17, 2015

I am getting a 404 error when trying to add items to the cart.

Started POST "/orders/populate" for 127.0.0.1 at 2015-03-18 12:19:41 +1300
Processing by Spree::OrdersController#populate as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"X7X/Y/2QtRSflHG3PWSU+tXU9nEoP7posRsQYkXltHQ=", "quantity"=>"1", "button"=>""}
Spree::Preference Load (1.0ms) SELECT spree_preferences.* FROM spree_preferences WHERE spree_preferences.key = 'spree/frontend_configuration/locale' LIMIT 1
Spree::User Load (1.0ms) SELECT spree_users.* FROM spree_users WHERE spree_users.deleted_at IS NULL AND spree_users.id = 1 ORDER BY spree_users.id ASC LIMIT 1
Spree::Store Load (0.0ms) SELECT spree_stores.* FROM spree_stores WHERE (url like '%localhost%') ORDER BY spree_stores.id ASC LIMIT 1
Spree::Store Load (0.0ms) SELECT spree_stores.* FROM spree_stores WHERE spree_stores.default = 1 ORDER BY spree_stores.id ASC LIMIT 1
Spree::Order Load (0.0ms) SELECT spree_orders.* FROM spree_orders WHERE spree_orders.completed_at IS NULL AND spree_orders.currency = 'NZD' AND spree_orders.guest_token = 'TNsLJs_p59-PuKjawl31Yg' AND spree_orders.store_id = 1 AND spree_orders.user_id = 1 LIMIT 1
Spree::Order Load (1.0ms) SELECT spree_orders.* FROM spree_orders WHERE spree_orders.user_id = 1 AND spree_orders.completed_at IS NULL ORDER BY created_at DESC LIMIT 1
Spree::Order Load (1.0ms) SELECT spree_orders.* FROM spree_orders WHERE spree_orders.user_id = 1 AND spree_orders.completed_at IS NULL AND (id != 2)
Spree::Product Load (1.0ms) SELECT spree_products.* FROM spree_products WHERE spree_products.deleted_at IS NULL AND (deleted_at is NULL) ORDER BY spree_products.id DESC LIMIT 3
CACHE (0.0ms) SELECT spree_products.* FROM spree_products WHERE spree_products.deleted_at IS NULL AND (deleted_at is NULL) ORDER BY spree_products.id DESC LIMIT 3
Spree::Order Load (0.0ms) SELECT spree_orders.* FROM spree_orders WHERE spree_orders.number IS NULL LIMIT 1
(1.0ms) SELECT COUNT(*) FROM spree_roles INNER JOIN spree_roles_users ON spree_roles.id = spree_roles_users.role_id WHERE spree_roles_users.user_id = 1 AND spree_roles.name = 'admin'
DEPRECATION WARNING: OrderPopulator is deprecated and will be removed from Spree 3, use OrderContents with order.contents.add instead. (called from populate at C:/ruby/hitechplastics/app/controllers/spree/orders_controller.rb:45)
Rendered public/404.html (0.0ms)
Completed 404 Not Found in 454ms (Views: 405.0ms | ActiveRecord: 6.0ms)

Here is my populate method from orders_controller (standard from spree 2.4.5)

 def populate
    populator = Spree::OrderPopulator.new(current_order(create_order_if_necessary: true),    current_currency)
  if populator.populate(params[:variant_id], params[:quantity], params[:options])
    respond_with(@order) do |format|
      format.html { redirect_to cart_path }
    end
  else
    flash[:error] = populator.errors.full_messages.join(" ")
    redirect_back_or_default(spree.root_path)
  end
end

And my gemfile

source 'https://rubygems.org'
gem 'rails', '4.1.8'
gem 'mysql2'
gem 'sass-rails', '> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '
> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '> 2.0'
gem 'sdoc', '
> 0.4.0', group: :doc

gem 'tzinfo-data', platforms: [:mingw, :mswin]

gem 'spree', '2.4.5'
gem 'spree_gateway', git: 'https://github.com/spree/spree_gateway', branch: '2-4-stable'
gem 'spree_auth_devise', git: 'https://github.com/spree/spree_auth_devise', branch: '2-4-stable'
gem 'spree_bootstrap_frontend', git: 'https://github.com/200Creative/spree_bootstrap_frontend', branch: '2-4-stable'
gem 'spree_static_content', git: 'https://github.com/spree/spree_static_content', branch: '2-4-stable'
gem 'spree_editor', git: 'https://github.com/spree-contrib/spree_editor', branch: '2-4-stable'
gem 'spree_mail_settings', git: 'https://github.com/spree-contrib/spree_mail_settings', branch: '2-4-stable'
gem 'coffee-script-source', '1.8.0'
gem 'therubyracer', :platforms => :ruby
gem 'multi_json', '~> 1.10.1'

Please let me know if there is anything else you need to help me with this issue.

Thanks in advance.

@JDutil
Copy link
Member

JDutil commented Mar 18, 2015

I'm pretty sure this is a duplicate of #2210 not sure if you're trying to use a respond_override though. If not I believe you're customizing something that causes a ActiveRecord find that fails to find a record causing the 404 error.

@JDutil
Copy link
Member

JDutil commented Mar 18, 2015

Parameters: {"utf8"=>"✓", "authenticity_token"=>"X7X/Y/2QtRSflHG3PWSU+tXU9nEoP7posRsQYkXltHQ=", "quantity"=>"1", "button"=>""}

Actually just noticed you're not submitting a variant_id parameter. So you're probably hitting 404 trying to look up the variant to add: https://github.com/spree/spree/blob/2-4-stable/core/app/models/spree/order_populator.rb#L35

@JDutil JDutil closed this as completed Mar 18, 2015
@APohio
Copy link
Author

APohio commented Mar 18, 2015

Thank you for your reply. I noticed it with the missing variant id but not sure how to add one in because my populate method and add to cart are all standard spree ones. I haven't played around with the methods. My order_populator is unedited too (exactly the same as the one you linked). I am not using a respond_override either. What do you recommend I should do? I could always pass in the variant_id through a hidden field as a quick fix?

@JDutil
Copy link
Member

JDutil commented Mar 18, 2015

Yea your cart form should include the variant id so if your customizing it you need to make sure to pass the variant id. By default if there are variants we render radio tags, and if there are no variants we just put the master id in a hidden field:
https://github.com/spree/spree/blob/master/frontend/app/views/spree/products/_cart_form.html.erb#L3-L27

@APohio
Copy link
Author

APohio commented Mar 18, 2015

Fantastic! Thank you for your help. My _cart_form partial was missing the part you linked. All working now. Cheers.

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

3 participants