Price Bucket calculator

62 views
Skip to first unread message

Fernando

unread,
Jan 6, 2011, 3:29:16 PM1/6/11
to Spree
Hello,

I am trying to use the Price Bucket as a calculator for a shipping
method in Spree 0.40 / ruby 1.8.7. I am not sure how this should
exaclty works. I could not find current documentation in guides for
this (link for calculators guide not working), so I had a look at the
price_bucket.rb source file.

My understanding of the parameters (minimal, discount, normal) now is
if total_cost_of_order >= minimal
shipping_cost = discounts
else
shipping_cost = normal

For instance, with (minimal=120, discount=0, normal=5) if the order
price sums up to 140, it would be shipped without charge. Could
somebody confirm this?

Anyway, the problem is that, during checkout, after entering the
address I get the folllowing error:
undefined method `to_d' for #<Order:0xb56b7078>

Any ideas?

By the way, I am amazed about Spree, thanks guys for the awesome
software!

Fernando




peterz

unread,
Jan 7, 2011, 7:15:48 AM1/7/11
to spree...@googlegroups.com


On Thursday, January 6, 2011 9:29:16 PM UTC+1, Fernando wrote:
Hello,

I am trying to use the Price Bucket as a calculator for a shipping
method in Spree 0.40 / ruby 1.8.7. I am not sure how this should
exaclty works. I could not find current documentation in guides for
this (link for calculators guide not working), so I had a look at the
price_bucket.rb source file.

My understanding of the parameters (minimal, discount, normal) now is
if total_cost_of_order >= minimal
  shipping_cost = discounts
else
  shipping_cost = normal

For instance, with (minimal=120, discount=0, normal=5) if the order
price sums up to 140, it would be shipped without charge. Could
somebody confirm this?

Anyway, the problem is that, during checkout, after entering the
address I get the folllowing error:
undefined method `to_d' for #<Order:0xb56b7078>

Confirming the issue. Here is a trace:

activemodel (3.0.3) lib/active_model/attribute_methods.rb:364:in `method_missing'
activerecord (3.0.3) lib/active_record/attribute_methods.rb:46:in `method_missing'
spree_core (0.40.0) app/models/calculator/price_bucket.rb:21:in `compute'
activerecord (3.0.3) lib/active_record/associations/association_proxy.rb:218:in `send'
activerecord (3.0.3) lib/active_record/associations/association_proxy.rb:218:in `method_missing'
spree_core (0.40.0) app/models/order.rb:321:in `rate_hash'
spree_core (0.40.0) app/models/order.rb:317:in `collect'
spree_core (0.40.0) app/models/order.rb:317:in `rate_hash'

Denis (jumph4x)

unread,
Jan 7, 2011, 3:32:58 PM1/7/11
to Spree
I keep seeing this in my Mongrel tail:

Started GET "/some-path" for 127.0.0.1 at Fri Jan 07 15:31:56 -0500
2011
Error registering calculator Calculator::PriceBucket

Denis (jumph4x)

unread,
Jan 13, 2011, 5:20:01 PM1/13/11
to Spree

Torsten Rüger

unread,
Jan 13, 2011, 5:52:05 PM1/13/11
to spree...@googlegroups.com
Moi,

could you try switching class caching on (class reloading off) by
editing config/environments/development.rb to

config.cache_classes = true

and say if that resolves the issue.

Torsten

> --
> 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
> .
>

Denis (jumph4x)

unread,
Jan 13, 2011, 7:05:41 PM1/13/11
to Spree
It should be noted that this is not a fix, but a workaround.

Enabling caching of classes in development environment will prevent
any changes to the classes from being picking up for your running
server (Mongrel or Webrick), so to see your development progress, you
will be forced to restart the server each time you modify a file.

Fernando

unread,
Feb 3, 2011, 6:01:03 PM2/3/11
to Spree
Hello all,

I just tried switching class caching on. Unfortunately still get the
same error as in the first post. (exactly the same trace as peterz
reported)

I have also started a new spree app, with just one product, just this
one price bucket calculator, to make sure that this has nothing to do
with other code from extensions whatsoever. Still I get the same
error.

I am using spree 0.40.0 , rails 3.0.3. and ruby 1.8.7

Fernando

On 13 Jan., 23:52, Torsten Rüger <tors...@lightning.nu> wrote:
> Moi,
>
> could you try switching class caching on (class reloading off) by  
> editing config/environments/development.rb to
>
>    config.cache_classes = true
>
> and say if that resolves the issue.
>
> Torsten
>
> Fernando kirjoitti 6.1.2011 kello 22.29:
>
>
>
>
>
>
>
> > Hello,
>
> > I am trying to use thePriceBucketas a calculator for a shipping
> > method in Spree 0.40 / ruby 1.8.7. I am not sure how this should
> > exaclty works. I could not find current documentation in guides for
> > this (link for calculators guide not working), so I had a look at the
> > price_bucket.rb source file.
>
> > My understanding of the parameters (minimal, discount, normal) now is
> > if total_cost_of_order >= minimal
> >  shipping_cost = discounts
> > else
> >  shipping_cost = normal
>
> > For instance, with (minimal=120, discount=0, normal=5) if the order
> >pricesums up to 140, it would be shipped without charge. Could

Fernando

unread,
Feb 19, 2011, 6:08:02 PM2/19/11
to Spree
Hello all,

Problem solved, although I am not sure this was totally correct. I did
not fully understed the logic behind the price_bucket.rb calculator,
so just did an override of the compute method like this:

def compute(object)
base = object.line_items.inject(0) {|sum, li| sum += li.amount }
if base < self.preferred_minimal_amount
self.preferred_normal_amount
else
self.preferred_discount_amount
end
end

Cheers,
Fernando

On 4 Feb., 00:01, Fernando <fer.izquie...@gmail.com> wrote:
> Hello all,
>
> I just tried switching class caching on. Unfortunately still get the
> same error as in the first post. (exactly the same trace as peterz
> reported)
>
> I have also started a new spree app, with just one product, just this
> onepricebucketcalculator, to make sure that this has nothing to do
Reply all
Reply to author
Forward
0 new messages