no way to delete orders

2,235 views
Skip to first unread message

Hameedullah Khan

unread,
Jan 5, 2012, 3:14:47 PM1/5/12
to Spree
Hello everyone,

I am wondering why is there no option to delete orders in spree admin?
I just can't seem to find the way to delete the orders. Can anyone
please point me to the right direction. I have tried searching google,
spree documentation everything.

Thanks.

Ryan Bigg

unread,
Jan 5, 2012, 3:25:51 PM1/5/12
to spree...@googlegroups.com
Orders can never be deleted as there needs to be a "log" that at this point in time a specific person bought these items.

You can cancel an order, which is like deleting it (as it will restock inventory) but there will still be a record in the DB.

Why do you need to actually delete orders?

> --
> You received this message because you are subscribed to the Google Groups "Spree" group.
> To post to this group, send email to spree...@googlegroups.com.
> To unsubscribe from this group, send email to spree-user+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/spree-user?hl=en.
>

Hameedullah Khan

unread,
Jan 6, 2012, 4:34:54 AM1/6/12
to spree...@googlegroups.com
On Fri, Jan 6, 2012 at 1:25 AM, Ryan Bigg <ry...@spreecommerce.com> wrote:
> Orders can never be deleted as there needs to be a "log" that at this point in time a specific person bought these items.
>
> You can cancel an order, which is like deleting it (as it will restock inventory) but there will still be a record in the DB.
>
> Why do you need to actually delete orders?
>

Okay, thanks. It was actually a client's requirement that they needed
to delete some orders.

Thanks for your help.

--
Hameedullah Khan

Brian Quinn

unread,
Jan 6, 2012, 4:43:19 AM1/6/12
to spree...@googlegroups.com
You can remove orders manually via the rails console.

Brian Quinn

-------------------------------------------
Spree Commerce Inc.
2 Wisconsin Circle, Suite 700
Chevy Chase, MD 20815
-------------------------------------------

Brian Phunk Gadoury

unread,
Jan 6, 2012, 9:03:00 PM1/6/12
to Spree
I've recently tried to delete test orders (to clean up report output,
etc) in a soon-to-be-production environment on a site running Spree
0.60.1 on Rails 3.0.9.

Using some_order.destroy in the rails console works for some orders,
but for others, I get the following backtrace:

ree-1.8.7-2011.03 :001 > Order.complete.last.destroy
NoMethodError: undefined method `line_items' for nil:NilClass
from /home/deployuser/.bundler/ruby/1.8/gems/spree_core-0.60.1/app/
models/calculator/flexi_rate.rb:24:in `compute'
from /home/deployuser/.bundler/ruby/1.8/gems/activerecord-3.0.9/
lib/active_record/associations/association_proxy.rb:222:in `send'
from /home/deployuser/.bundler/ruby/1.8/gems/activerecord-3.0.9/
lib/active_record/associations/association_proxy.rb:222:in
`method_missing'
from /home/deployuser/.bundler/ruby/1.8/gems/spree_core-0.60.1/lib/
spree/calculated_adjustments.rb:62:in `update_adjustment'
from /home/deployuser/.bundler/ruby/1.8/gems/activerecord-3.0.9/
lib/active_record/associations/association_proxy.rb:222:in `send'
from /home/deployuser/.bundler/ruby/1.8/gems/activerecord-3.0.9/
lib/active_record/associations/association_proxy.rb:222:in
`method_missing'
from /home/deployuser/.bundler/ruby/1.8/gems/spree_core-0.60.1/app/
models/adjustment.rb:45:in `update!'
from /home/deployuser/.bundler/ruby/1.8/gems/activesupport-3.0.9/
lib/active_support/core_ext/class/attribute.rb:73:in `to_proc'
[SNIP]

I haven't had time to look into the differences between delete-able
orders and non-delete-able orders, but I figured I'd mention it while
this topic was warm. :)

Thanks,
Phunk

Brian Quinn

unread,
Jan 7, 2012, 4:11:48 PM1/7/12
to spree...@googlegroups.com
Calling .destroy will fire all callbacks which could cause problems for test data,  plus a lot of Spree models aren't designed to be destroyed.

Calling delete or delete_all is a better option, no callbacks will be fired. For example:

Order.delete_all 


-- 
Brian Quinn
Spree Commerce

Brian Phunk Gadoury

unread,
Jan 9, 2012, 1:20:24 PM1/9/12
to Spree
Thanks for the reply, Brian.

I figured destroy was the best bet, as it would fire all callbacks and
avoid orphaning order-specific data in other tables. (We don't have
any test data.)

I'll use delete on a few orders and see how things look.

-Phunk
> > On Jan 6, 2:43 am, Brian Quinn <br...@spreecommerce.com (http://spreecommerce.com)> wrote:
> > > You can remove orders manually via the rails console.
>
> > > Brian Quinn
>
> > --
> > You received this message because you are subscribed to the Google Groups "Spree" group.
> > To post to this group, send email to spree...@googlegroups.com (mailto:spree...@googlegroups.com).
> > To unsubscribe from this group, send email to spree-user+...@googlegroups.com (mailto:spree-user+...@googlegroups.com).

Brian Quinn

unread,
Jan 9, 2012, 2:15:02 PM1/9/12
to spree...@googlegroups.com
You'll need to be pretty precise about what you are deleting, be sure to run .delete_all on

Payment, LineItem, Adjustment, Shipment, InventoryUnit, Address and possibly User

Brian Quinn

-------------------------------------------
Spree Commerce Inc.
2 Wisconsin Circle, Suite 700
Chevy Chase, MD 20815
-------------------------------------------

To post to this group, send email to spree...@googlegroups.com.
To unsubscribe from this group, send email to spree-user+...@googlegroups.com.

kx

unread,
May 23, 2012, 2:42:18 AM5/23/12
to spree...@googlegroups.com
Hi Brian,

How do you actually call the .delete_all or destroy_all command? I tried to start the rails console in my /script folder using the command: "rails console production" and entered the Order.destroy_all / Order.delete_all and receive the following error:

Loading production environment (Rails 3.2.3)
1.9.3p194 :001 > Order.destroy_all
NameError: uninitialized constant Order
from (irb):1
from /home/mfadmin/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
from /home/mfadmin/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /home/mfadmin/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

I am using spree 1.1.0 with ruby 1.9.3p194, rails 3.2.3 and running on passenger with apache on my production server. Spree is working fine but I will like to remove the sample orders. When I run ActiveRecord::Base.connection, it shows that it is connected to the SQLite database:

#<SQLite3::Database:0x9e438d4>, @max=1000, @cache={}>, @config={:adapter=>"sqlite3", :database=>"/pathtoapp/db/production.sqlite3", :pool=>5, :timeout=>5000}>  

What can be causing the error?

Cheers,
Kai Xin
For more options, visit this group athttp://groups.google.com/group/spree-user?hl=en.

--
You received this message because you are subscribed to the Google Groups "Spree" group.
To post to this group, send email to spree...@googlegroups.com.
To unsubscribe from this group, send email to spree-user+unsubscribe@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/spree-user?hl=en.

--
You received this message because you are subscribed to the Google Groups "Spree" group.
To post to this group, send email to spree...@googlegroups.com.
To unsubscribe from this group, send email to spree-user+unsubscribe@googlegroups.com.

Bounmy Stéphane

unread,
May 23, 2012, 5:57:43 AM5/23/12
to spree...@googlegroups.com, spree...@googlegroups.com
Hi kx,

you need to put the namespace Spree:

Spree::Order.destroy_all

Best,
Stephane
To view this discussion on the web visit https://groups.google.com/d/msg/spree-user/-/KetO2F-5hz4J.

To post to this group, send email to spree...@googlegroups.com.
To unsubscribe from this group, send email to spree-user+...@googlegroups.com.

kx

unread,
May 23, 2012, 6:16:28 AM5/23/12
to spree...@googlegroups.com
Works like a charm. Thank you so much Stephane =)
Reply all
Reply to author
Forward
0 new messages