Sha256: 0b70f5db80b9b3aa533416f926e7db864ad9ad67d94084ea8d86d34772e9ab6f

Contents?: true

Size: 930 Bytes

Versions: 2

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

module Spree
  module PromotionHandler
    Coupon.class_eval do
      def apply
        if order.coupon_code.present?
          if promotion&.actions.exists?
            experience_key  = order.flow_order&.dig('experience', 'key')
            forbiden_keys   = promotion.flow_data&.dig('filter', 'experience') || []

            if experience_key.present? && !forbiden_keys.include?(experience_key)
              self.error = 'Promotion is not available in current country'
            else
              handle_present_promotion(promotion)
            end
          else
            self.error = if Promotion.with_coupon_code(order.coupon_code)&.expired?
                           Spree.t(:coupon_code_expired)
                         else
                           Spree.t(:coupon_code_not_found)
                         end
          end
        end

        self
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flowcommerce_spree-0.0.2 app/models/spree/promotion_handler/coupon_decorator.rb
flowcommerce_spree-0.0.1 app/models/spree/promotion_handler/coupon_decorator.rb