Sha256: 154a16b915cc5697dbec26ee4b48c029d1c57ffc7ab0ad6189d028a6fb0fdcf5
Contents?: true
Size: 959 Bytes
Versions: 132
Compression:
Stored size: 959 Bytes
Contents
module Spree class Promotion module Rules class FirstOrder < PromotionRule attr_reader :user, :email def applicable?(promotable) promotable.is_a?(Spree::Order) end def eligible?(order, options = {}) @user = order.try(:user) || options[:user] @email = order.email if user || email if !completed_orders.blank? && completed_orders.first != order eligibility_errors.add(:base, eligibility_error_message(:not_first_order)) end else eligibility_errors.add(:base, eligibility_error_message(:no_user_or_email_specified)) end eligibility_errors.empty? end private def completed_orders user ? user.orders.complete : orders_by_email end def orders_by_email Spree::Order.where(email: email).complete end end end end end
Version data entries
132 entries across 132 versions & 2 rubygems