<commit_before>class AftershipController < Spree::BaseController

	def track_shipment
		respond_to do |format|
			format.html {
				redirect_to root_path
			}
			format.json {
				# for testing purposes enter order number and email as 'test'
				if params[:order_number].match(/^test/) && params[:email] = "test"
					numbers = []
					num = params[:order_number][-1].to_i
					if num > 0
						num.times do |i|
							numbers << "testtracking#{i+1}"
						end
						render json: {success: true, tracking_numbers: numbers, shipped_at: DateTime.now.to_date} and return
					else
						render json: {success: true} and return
					end
				else
					order = Spree::Order.where("number = ? AND email = ?", params[:order_number], params[:email])
				end

				if order.any?
					tracked_shipments = order.first.shipments.select{|s| s.tracking.present? }
					if tracked_shipments.any?
						numbers = tracked_shipments.collect{|t| t.tracking}
						render json: {success: true, tracking_numbers: numbers, shipped_at: tracked_shipments.last.shipped_at.to_date}
					else
						render json: {success: true}
					end
				else<commit_msg>fix on shipment tracking for when no shipped_at date is available<commit_after>class AftershipController < Spree::BaseController

	def track_shipment
		respond_to do |format|
			format.html {
				redirect_to root_path
			}
			format.json {
				render json: {success: false} if params[:order_number].blank? || params[:email].blank?
				# for testing purposes enter order number and email as 'test'
				if params[:order_number].match(/^test/) && params[:email] = "test"
					numbers = []
					num = params[:order_number][-1].to_i
					if num > 0
						num.times do |i|
							numbers << "testtracking#{i+1}"
						end
						render json: {success: true, tracking_numbers: numbers, shipped_at: DateTime.now.to_date} and return
					else
						render json: {success: true} and return
					end
				else
					order = Spree::Order.where("number = ? AND email = ?", params[:order_number], params[:email])
				end

				if order.any?
					tracked_shipments = order.first.shipments.select{|s| s.tracking.present? }
					if tracked_shipments.any?
						numbers = tracked_shipments.collect{|t| t.tracking}
						render json: {success: true, tracking_numbers: numbers, shipped_at: tracked_shipments.last.shipped_at.try(:to_date)}
					else
						render json: {success: true}
					end
				else
{'fraction_non_alphanumeric': 0.11351351351351352, 'fraction_numerical': 0.002494802494802495, 'mean_word_length': 3.228471001757469, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1996268', 'n_tokens_mistral': 983, 'n_tokens_neox': 730, 'n_words': 194}