Sha256: 925ede933e6934fc4486f4cc4beb2e06e2e427c638ffbe2d0c4da5da38bea4d6

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

module Workarea
  decorate Pricing::Calculators::ItemCalculator, with: :global_e do
    def adjust
      order.fixed_pricing = is_fixed_price?

      return super unless is_fixed_price?

      order.items.each do |item|
        price = pricing.for_sku(item.sku, quantity: item.quantity)

        item.adjust_pricing(
          price: 'item',
          quantity: item.quantity,
          calculator: self.class.name,
          amount: price.sell * item.quantity,
          description: 'Item Subtotal',
          data: {
            'on_sale' => price.on_sale?,
            'original_price' => price.regular.to_f,
            'tax_code' => price.tax_code
          }
        )

        fixed_price = pricing.fixed_price_for_sku(item.sku, currency_code: order.currency, country: order.shipping_country)

        item.adjust_international_pricing(
          price: 'item',
          quantity: item.quantity,
          calculator: self.class.name,
          amount: fixed_price.sell * item.quantity,
          description: 'Item Subtotal',
          data: {
            'on_sale' => fixed_price.on_sale?,
            'original_price' => fixed_price.regular.to_f,
            'tax_code' => price.tax_code
          }
        )
      end
    end

    private

      def is_fixed_price?
        pricing.records.present? &&
          pricing.records.all? { |sku| sku.fixed_price_for(currency_code: order.currency, country: order.shipping_country) }
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-global_e-1.3.0 app/models/workarea/pricing/calculators/item_calculator.decorator
workarea-global_e-1.2.1 app/models/workarea/pricing/calculators/item_calculator.decorator