…ds to be installed
When automatically creating a related record via delegated attributes prefer the `build_*` method instead of doing a straight assignment from an instance of the class of the related object. This ensures relationship constraints are followed. Without the meta-programming mess this is basically the difference between: product.master = Spree::Variant.new and product.build_master This is important because `Spree::Product.new(price: 0).master.is_master` will return `false` as the assignment of `price` (a delegated attribute) will cause a new variant to be assigned to master but that variant won't have the `is_master` flag automatically set. I believe this is sort of fixed up by `set_master_variants_default` in the case of products but this is a more general fix. It might be worth investigating if the callback can be removed. Not causing any real performance issue but had having unnecessary code hanging around. 1. https://github.com/spree/spree/blob/master/core/app/models/spree/product.rb#L322
Just adding something to the Hash won't do the trick. You'll also have to patch the price generation, copying prices to line items, the price generation for shipments, and you'll have to subclass the DefaultTax calculator.
Our client needs to display different prices to different customers. The MOSS refactoring has enabled different prices for different tax zones, which is great, but they also need to display prices excluding VAT for *some* business customers. The logic for that is (while in accordance with EU tax law) rather custom. This PR is supposed only to enable passing more than just the tax zone as options for price calculation. In order to accomplish this, the `current_tax_zone` helper is replaced with a `current_price_options` helper which returns a Hash. All the values of that Hash are used to calculate product cache keys. I took care to order those so that we don't end up with different caches for the same content. * Remove current_tax_zone helper and replace with current_price_options * Adapt product cache key to price options hash * Adapt base helper to call #price_including_vat_for with price_options hash * Adapt price model for price_options hash * Adapt VAT price calculation module * Use new #included_tax_amount signature * Adapt tax_rate.rb * Adapt line_item.rb * Add tests for edge case price options * Adapt StockEstimator