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

Volume prices only working when Item Total is less than 0 #103

Open
eddxw opened this issue Dec 7, 2017 · 2 comments
Open

Volume prices only working when Item Total is less than 0 #103

eddxw opened this issue Dec 7, 2017 · 2 comments

Comments

@eddxw
Copy link

eddxw commented Dec 7, 2017

Volume prices only working when Item Total is less than 0.

In this example the item master price is $20.
screen shot 2017-12-07 at 1 25 12 pm
Here a discount of $2 should be applied to the order but it isn't.
screen shot 2017-12-07 at 1 26 58 pm
Now, when the discount is greater than the master price (item total is less than 0) everything works
screen shot 2017-12-07 at 1 33 16 pm

@eddxw
Copy link
Author

eddxw commented Dec 7, 2017

I replaced line_item_decorator.rb contents with:

Spree::LineItem.class_eval do
  define_method(:copy_price) do
    self.price = variant.volume_price(quantity, order.user);
  end
end

https://github.com/spree-contrib/spree_volume_pricing/blob/master/app/models/spree/line_item_decorator.rb

Now it's working
screen shot 2017-12-07 at 2 43 51 pm

But I don't really understand what are these of lines for:

  old_copy_price = instance_method(:copy_price)
  define_method(:copy_price) do
    old_copy_price.bind(self).call
    return unless variant

    if changed? && changes.keys.include?('quantity')
      vprice = variant.volume_price(quantity, order.user)
      if price.present? && vprice <= variant.price
        self.price = vprice and return
      end
    end

    self.price = variant.price if price.nil?
  end

@MatthewKennedy
Copy link

Works for me.

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