Sha256: 406815279b61f0ffb83bdff3d969592c5e400e95b14fc0cd98b8a1edcaf82f73

Contents?: true

Size: 1.22 KB

Versions: 69

Compression:

Stored size: 1.22 KB

Contents

module Spree::ZonePricing::ProductsHelper
  def self.included(base)
    base.class_eval do
      alias_method :spree_product_price, :product_price unless method_defined?(:spree_product_price)
      alias_method :product_price, :site_product_price
    end
  end

  # returns the price of the product to show for display purposes
  def site_product_price(product_or_variant, options={})
    options.assert_valid_keys(:format_as_currency, :show_vat_text)
    options.reverse_merge! :format_as_currency => true, :show_vat_text => Spree::Config[:show_price_inc_vat]

    # Check if this object is a product, if so then access the master variant
    # record for the product to get the zone pricing
    object = product_or_variant.is_a?(Product) ? product_or_variant.master : product_or_variant

    # Get the zone price for this variant/product if one is defined
    # otherwise use the normal price
    if object.respond_to?(:zone_price)
      amount = object.zone_price(get_user_country_id)
    else
      amount = object.price
    end

    amount += Calculator::Vat.calculate_tax_on(product_or_variant) if Spree::Config[:show_price_inc_vat]
    options.delete(:format_as_currency) ? format_price(amount, options) : ("%0.2f" % amount).to_f
  end

end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
spree_zone_pricing-0.1.69 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.68 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.66 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.65 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.64 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.63 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.62 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.61 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.60 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.59 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.58 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.57 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.56 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.55 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.54 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.53 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.52 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.51 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.50 lib/spree/zone_pricing/products_helper.rb
spree_zone_pricing-0.1.49 lib/spree/zone_pricing/products_helper.rb