Module: Auth::Concerns::Shopping::ProductConcern

Extended by:
ActiveSupport::Concern
Includes:
ChiefModelConcern, EsConcern, OwnerConcern, BarCodeConcern, Mongoid::Autoinc
Included in:
CartItemConcern, Shopping::Product
Defined in:
app/models/auth/concerns/shopping/product_concern.rb

Overview

need a seperate model that implements it

Instance Method Summary collapse

Instance Method Details

#add_to_previous_rolling_n_minutes(minutes, origin_epoch, cycle_to_add) ⇒ Object

so we have completed the rolling n minutes.



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'app/models/auth/concerns/shopping/product_concern.rb', line 154

def add_to_previous_rolling_n_minutes(minutes,origin_epoch,cycle_to_add)

	## get all the minutes less than that.
	rolling_n_minutes_less_than_that = minutes.keys.select{|c| c < origin_epoch}			

	end_min = rolling_n_minutes_less_than_that.size < Auth.configuration.rolling_minutes ? rolling_n_minutes_less_than_that.size : Auth.configuration.rolling_minutes

	end_min = end_min - 1

	end_min = end_min > 0 ? end_min : 0
	rolling_n_minutes_less_than_that[0..end_min].each do |epoch|
		minutes[epoch].cycles << cycle_to_add
	end

end

#attrs_to_copy_from_prod_to_prodObject



140
141
142
# File 'app/models/auth/concerns/shopping/product_concern.rb', line 140

def attrs_to_copy_from_prod_to_prod
	["product_code","name","description","price"]
end

#schedule_cycles(minutes, location_id, conditions = {}) ⇒ Object

adds the relevant cycles to the minutes, and returns the hash that came in. does not save the minutes, after adding the cycles to them. @return => minute object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'app/models/auth/concerns/shopping/product_concern.rb', line 173

def schedule_cycles(minutes,location_id,conditions = {})

	products = Auth.configuration.product_class.constantize.all if conditions.blank?

	products = Auth.configuration.product_class.constantize.where(conditions) if !conditions.blank?

	minutes.keys.each do |epoch|
		
		products.each do |product|
		
			all_cycles_valid = true
			product.cycles.each do |cycle|

				all_cycles_valid = cycle.requirements_satisfied(epoch + cycle.time_since_prev_cycle.minutes*60,location_id)
						
			end


			if all_cycles_valid == true
				cycle_chain = []
				product.cycles.each do |cycle|
					epoch_at_which_to_add = epoch + cycle.time_since_prev_cycle.minutes*60
					cycle_to_add = cycle.dup
					cycle_to_add.start_time = epoch_at_which_to_add
					cycle_to_add.end_time = cycle_to_add.start_time + cycle_to_add.duration
					cycle_to_add.cycle_chain = cycle_chain
					if minutes[epoch_at_which_to_add]
						
						#add_to_previous_rolling_n_minutes(minutes,epoch_at_which_to_add,cycle_to_add)


						minutes[epoch_at_which_to_add].cycles << cycle_to_add



						cycle_chain << cycle_to_add.id.to_s
					else
						#raise "necessary minute not in range."
					end
				end
			end
		end
	end
	minutes
end

#set_autocomplete_descriptionObject



272
273
274
# File 'app/models/auth/concerns/shopping/product_concern.rb', line 272

def set_autocomplete_description
	self.autocomplete_description = self.name + " - " + self.description
end

#set_autocomplete_tagsObject



267
268
269
270
# File 'app/models/auth/concerns/shopping/product_concern.rb', line 267

def set_autocomplete_tags
	self.tags = []
	self.tags << "product"
end


276
277
278
# File 'app/models/auth/concerns/shopping/product_concern.rb', line 276

def set_primary_link
	self.primary_link = Rails.application.routes.url_helpers.send(Auth::OmniAuth::Path.show_or_update_or_delete_path(Auth.configuration.product_class),self.id.to_s)
end

here need to add this action links to the products. it is basically a form to add a cart item that should be added hereitself.



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'app/models/auth/concerns/shopping/product_concern.rb', line 223

def set_secondary_links
	## this can be done both as a user and as an admin.
	## what if the admin assigns it for himself.
	## these checks have to be established for everyone.
	unless self.secondary_links["Order Now"]
		self.secondary_links["Order Now"] = {
			:partial => "auth/shopping/products/show/action_links.html.erb",
			:instance_name_in_locals => "product", 
			:other_locals => {}
		}
	end

	unless self.secondary_links["Edit Product"]
		self.secondary_links["Edit Product"] = {
			:url => Rails.application.routes.url_helpers.send(Auth::OmniAuth::Path.edit_path(Auth.configuration.product_class),self.id.to_s)
		}
	end

	unless self.secondary_links["See All Products"]
		## for this the url is ===> index path.
		self.secondary_links["See All Products"] = {
			:url => Rails.application.routes.url_helpers.send(Auth::OmniAuth::Path.create_or_index_path(Auth.configuration.product_class),{})
		}

	end

	unless self.secondary_links["See Related Products"]
		self.secondary_links["See All Products"] = {
			:url => Rails.application.routes.url_helpers.send(Auth::OmniAuth::Path.create_or_index_path(Auth.configuration.product_class),{})
		}

	end
	
	unless self.secondary_links["Add New Product"]
		self.secondary_links["Add New Product"] = {
			:partial => "auth/shopping/products/search_results/add_product.html.erb",
			:instance_name_in_locals => "product", 
			:other_locals => {}	
		}
	end

end

#write_attribute(field, value) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/models/auth/concerns/shopping/product_concern.rb', line 121

def write_attribute(field,value)
	super(field,value)
	if field.to_s == "auto_incrementing_number"
		if self.auto_incrementing_number_changed?
			unless self.unique_hash_id
				hashids = Hashids.new(Auth.configuration.hashids_salt,0,Auth.configuration.hashids_alphabet)
				self.unique_hash_id = hashids.encode(self.auto_incrementing_number)
				## check if the option that create from product id is ticked, then assign that otherwise give it its own new product code
				if self.create_from_product_id
					
				else
					self.product_code = self.unique_hash_id if (self.product_code.blank?)
				end
			end
		end
	end
end