shoppe 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf9a0256bc9ea841945749f08d51e47c307c574d
4
- data.tar.gz: 538c996c91a1a34081fbfe945b7afa450fed2443
3
+ metadata.gz: 0dcacefeadc890f3dc35dabd24f7287284cc479f
4
+ data.tar.gz: 7db5436aac835634aa2f6cd135f6035a7e219da6
5
5
  SHA512:
6
- metadata.gz: e75007e5bccf210a4954380863cadd7061396f758dd59ecfc7a28dd368068f56521c64ab2a501febf51eca1b5530122c7599f2590a740a5547903e78104056b6
7
- data.tar.gz: 7f896f5bf90086972c0119d604ad1390262d6ef7d21ee8c382da5a8c7025d3eb72c1745cf9aa69f0db73908bad0fa38b09ddc426e08eb8e570521c8e5623dab9
6
+ metadata.gz: 94959c589693f5a70d4fd2a838cee7ef2e3106ef4426775155b612f061ce4276df19de0c2d9ff7e8e823cdc06e357e1787e444930ee024a102260df32dff77c8
7
+ data.tar.gz: 9cd175fe855bcb9234dbd7c519c2fb86edf133ba76094d4fd12f6c993adcc5006f1eb6d9a6fd90eb047e5dc2af77b2fa85b06a5372ee955a1f49c15144ab8003
data/README.md CHANGED
@@ -39,7 +39,6 @@ instructions below and you'll be up and running in minutes.
39
39
  echo "gem 'shoppe', '~> 1.0'" >> Gemfile
40
40
  bundle
41
41
  rails generate shoppe:setup
42
- rails generate nifty:attachments:migration
43
42
  rails generate nifty:key_value_store:migration
44
43
  rake db:migrate shoppe:setup
45
44
  rails server
@@ -42,6 +42,11 @@ $ ->
42
42
  helper.children().each (index)->
43
43
  $(this).width(originals.eq(index).width())
44
44
  helper
45
+
46
+ $('a[data-behavior=addAttachmentToExtraAttachments]').on 'click', (event) ->
47
+ event.preventDefault();
48
+ $('div.extraAttachments').show();
49
+ $(this).hide();
45
50
 
46
51
  # Chosen
47
52
  $('select.chosen').chosen()
@@ -183,7 +183,7 @@ header.main {
183
183
  width:49%;
184
184
  margin:0;
185
185
  float:left;
186
- &:last-child { float:right;}
186
+ &:nth-child(2) { float:right;}
187
187
  }
188
188
 
189
189
  &.third {
@@ -299,6 +299,17 @@ header.main {
299
299
  }
300
300
  }
301
301
 
302
+ div.extraAttachments{
303
+ display: none;
304
+
305
+ dl.half { margin-top: 15px; }
306
+ }
307
+
308
+ p.addAttachments {
309
+ float: right;
310
+ margin: 15px 25px 0 0;
311
+ }
312
+
302
313
  //
303
314
  // attachment preview
304
315
  //
@@ -2,7 +2,7 @@ module Shoppe
2
2
  class AttachmentsController < Shoppe::ApplicationController
3
3
 
4
4
  def destroy
5
- @attachment = Nifty::Attachments::Attachment.find(params[:id])
5
+ @attachment = Shoppe::Attachment.find_by!(token: params[:id])
6
6
  @attachment.destroy
7
7
  respond_to do |wants|
8
8
  wants.html { redirect_to request.referer, :notice => t('shoppe.attachments.remove_notice')}
@@ -5,7 +5,7 @@ module Shoppe
5
5
  before_filter { params[:id] && @product = Shoppe::Product.root.find(params[:id]) }
6
6
 
7
7
  def index
8
- @products = Shoppe::Product.root.includes(:translations, :stock_level_adjustments, :default_image, :product_categories, :variants).order(:name).group_by(&:product_category).sort_by { |cat,pro| cat.name }
8
+ @products = Shoppe::Product.root.includes(:translations, :stock_level_adjustments, :product_categories, :variants).order(:name).group_by(&:product_category).sort_by { |cat,pro| cat.name }
9
9
  end
10
10
 
11
11
  def new
@@ -51,7 +51,8 @@ module Shoppe
51
51
  private
52
52
 
53
53
  def safe_params
54
- params[:product].permit(:name, :sku, :permalink, :description, :short_description, :weight, :price, :cost_price, :tax_rate_id, :stock_control, :default_image_file, :data_sheet_file, :active, :featured, :in_the_box, :product_attributes_array => [:key, :value, :searchable, :public], :product_category_ids => [])
54
+ file_params = [:file, :parent_id, :role, :parent_type, :file => []]
55
+ params[:product].permit(:name, :sku, :permalink, :description, :short_description, :weight, :price, :cost_price, :tax_rate_id, :stock_control, :active, :featured, :in_the_box, :attachments => [:default_image => file_params, :data_sheet => file_params, :extra => file_params], :product_attributes_array => [:key, :value, :searchable, :public], :product_category_ids => [])
55
56
  end
56
57
 
57
58
  end
@@ -10,19 +10,19 @@ module Shoppe
10
10
  end
11
11
 
12
12
  def attachment_preview(attachment, options = {})
13
- if attachment
13
+ if attachment.present? and attachment.token.present?
14
14
  String.new.tap do |s|
15
15
  if attachment.image?
16
- style = "style='background-image:url(#{attachment.path})'"
16
+ style = "style='background-image:url(#{attachment.file.thumb.url})'"
17
17
  else
18
18
  style = ''
19
19
  end
20
20
  s << "<div class='attachmentPreview #{attachment.image? ? 'image' : 'doc'}'>"
21
21
  s << "<div class='imgContainer'><div class='img' #{style}></div></div>"
22
22
  s << "<div class='desc'>"
23
- s << "<span class='filename'><a href='#{attachment_path(attachment)}'>#{attachment.file_name}</a></span>"
23
+ s << "<span class='filename'><a href='#{attachment.file.url}'>#{attachment.file_name}</a></span>"
24
24
  s << "<span class='delete'>"
25
- s << link_to(t('helpers.attachment_preview.delete', :default => 'Delete this file?'), attachment_path(attachment), :method => :delete, :data => {:confirm => t('helpers.attachment_preview.delete_confirm', :default => "Are you sure you wish to remove this attachment?")})
25
+ s << link_to(t('helpers.attachment_preview.delete', :default => 'Delete this file?'), attachment_path(attachment.token), :method => :delete, :data => {:confirm => t('helpers.attachment_preview.delete_confirm', :default => "Are you sure you wish to remove this attachment?")})
26
26
  s << "</span>"
27
27
  s << "</div>"
28
28
  s << "</div>"
@@ -0,0 +1,48 @@
1
+ module Shoppe
2
+ class Attachment < ActiveRecord::Base
3
+
4
+ # Set the table name
5
+ self.table_name = "shoppe_attachments"
6
+
7
+ # Mount the Carrierwave uploader
8
+ mount_uploader :file, AttachmentUploader
9
+
10
+ # Relationships
11
+ belongs_to :parent, :polymorphic => true
12
+
13
+ # Validations
14
+ validates :file_name, :presence => true
15
+ validates :file_type, :presence => true
16
+ validates :file_size, :presence => true
17
+ validates :file, :presence => true
18
+ validates :token, :presence => true, :uniqueness => true
19
+
20
+ # All attachments should have a token assigned to this
21
+ before_validation { self.token = SecureRandom.uuid if self.token.blank? }
22
+
23
+ # Set the appropriate values in the model
24
+ before_validation do
25
+ if self.file
26
+ self.file_name = self.file.filename if self.file_name.blank?
27
+ self.file_type = self.file.content_type if self.file_type.blank?
28
+ self.file_size = self.file.size if self.file_size.blank?
29
+ end
30
+ end
31
+
32
+ # Return the attachment for a given role
33
+ def self.for(role)
34
+ self.where(:role => role).first
35
+ end
36
+
37
+ # Return the path to the attachment
38
+ def path
39
+ file.url
40
+ end
41
+
42
+ # Is the attachment an image?
43
+ def image?
44
+ file_type.match(/\Aimage\//).present?
45
+ end
46
+
47
+ end
48
+ end
@@ -10,9 +10,8 @@ module Shoppe
10
10
  require_dependency 'shoppe/product/product_attributes'
11
11
  require_dependency 'shoppe/product/variants'
12
12
 
13
- # Products have a default_image and a data_sheet
14
- attachment :default_image
15
- attachment :data_sheet
13
+ # Attachments for this product
14
+ has_many :attachments, :as => :parent, :dependent => :destroy, :autosave => true, :class_name => "Shoppe::Attachment"
16
15
 
17
16
  # The product's categorizations
18
17
  #
@@ -63,6 +62,13 @@ module Shoppe
63
62
  translates :name, :permalink, :description, :short_description
64
63
  scope :ordered, -> { includes(:translations).order(:name) }
65
64
 
65
+ def attachments=(attrs)
66
+ if attrs["default_image"]["file"].present? then self.attachments.build(attrs["default_image"]) end
67
+ if attrs["data_sheet"]["file"].present? then self.attachments.build(attrs["data_sheet"]) end
68
+
69
+ if attrs["extra"]["file"].present? then attrs["extra"]["file"].each { |attr| self.attachments.build(file: attr, parent_id: attrs["extra"]["parent_id"], parent_type: attrs["extra"]["parent_type"]) } end
70
+ end
71
+
66
72
  # Return the name of the product
67
73
  #
68
74
  # @return [String]
@@ -108,6 +114,20 @@ module Shoppe
108
114
  self.product_categories.first rescue nil
109
115
  end
110
116
 
117
+ # Return attachment for the default_image role
118
+ #
119
+ # @return [String]
120
+ def default_image
121
+ self.attachments.for("default_image")
122
+ end
123
+
124
+ # Return attachment for the data_sheet role
125
+ #
126
+ # @return [String]
127
+ def data_sheet
128
+ self.attachments.for("data_sheet")
129
+ end
130
+
111
131
  # Search for products which include the given attributes and return an active record
112
132
  # scope of these products. Chainable with other scopes and with_attributes methods.
113
133
  # For example:
@@ -12,8 +12,8 @@ module Shoppe
12
12
 
13
13
  self.table_name = 'shoppe_product_categories'
14
14
 
15
- # Categories have an image attachment
16
- attachment :image
15
+ # Attachments for this product category
16
+ has_many :attachments, :as => :parent, :dependent => :destroy, :class_name => "Shoppe::Attachment"
17
17
 
18
18
  # All products within this category
19
19
  has_many :product_categorizations, dependent: :restrict_with_exception, class_name: 'Shoppe::ProductCategorization', inverse_of: :product_category
@@ -51,6 +51,13 @@ module Shoppe
51
51
  parent.hierarchy_array.concat [self]
52
52
  end
53
53
 
54
+ # Attachment with the role image
55
+ #
56
+ # @return [String]
57
+ def image
58
+ self.attachments.for("image")
59
+ end
60
+
54
61
  private
55
62
 
56
63
  def set_permalink
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ class Shoppe::AttachmentUploader < CarrierWave::Uploader::Base
4
+
5
+ include CarrierWave::MiniMagick
6
+
7
+ storage :file
8
+
9
+ # Where should files be stored?
10
+ def store_dir
11
+ "attachment/#{model.id}"
12
+ end
13
+
14
+ # Returns true if the file is an image
15
+ def image?(new_file)
16
+ self.file.content_type.include? 'image'
17
+ end
18
+
19
+ # Returns true if the file is not an image
20
+ def not_image?(new_file)
21
+ !self.file.content_type.include? 'image'
22
+ end
23
+
24
+ # Create different versions of your uploaded files:
25
+ version :thumb, :if => :image? do
26
+ process :resize_and_pad => [200, 200]
27
+ end
28
+
29
+ end
@@ -57,15 +57,35 @@
57
57
  = field_set_tag t('shoppe.products.attachments') do
58
58
  .splitContainer
59
59
  %dl.half
60
- %dt= f.label :default_image_file, t('shoppe.products.default_image')
60
+ %dt= f.label "attachments[default_image][file]", t('shoppe.products.default_image')
61
61
  %dd
62
62
  = attachment_preview @product.default_image
63
- %p= f.file_field :default_image_file
63
+ %p= f.file_field "attachments[default_image][file]"
64
+ = f.hidden_field "attachments[default_image][role]", value: "default_image"
65
+ = f.hidden_field "attachments[default_image][parent_id]", value: @product.id
64
66
  %dl.half
65
- %dt= f.label :data_sheet_file, t('shoppe.products.datasheet')
67
+ %dt= f.label "attachments[data_sheet][file]", t('shoppe.products.datasheet')
66
68
  %dd
67
69
  = attachment_preview @product.data_sheet
68
- %p= f.file_field :data_sheet_file
70
+ %p= f.file_field "attachments[data_sheet][file]"
71
+ = f.hidden_field "attachments[data_sheet][role]", value: "data_sheet"
72
+ = f.hidden_field "attachments[data_sheet][parent_id]", value: @product.id
73
+
74
+ .splitContainer.extraAttachments
75
+ %dl.half
76
+ %dd
77
+ = attachment_preview nil, hide_if_blank: false
78
+ %p= f.file_field "attachments[extra][file]", :multiple => true
79
+ = f.hidden_field "attachments[extra][parent_type]", value: "Shoppe::Product"
80
+ = f.hidden_field "attachments[extra][parent_id]", value: @product.id
81
+
82
+ - @product.attachments.each do |attachment|
83
+ - unless ["default_image", "data_sheet"].include?(attachment.role)
84
+ %dl.half
85
+ %dd
86
+ = attachment_preview attachment
87
+
88
+ %p.addAttachments= link_to t('shoppe.products.add_attachments') , '#', :data => {:behavior => 'addAttachmentToExtraAttachments'}, :class => 'button button-mini green'
69
89
 
70
90
  - unless @product.has_variants?
71
91
  = field_set_tag t('shoppe.products.pricing') do
@@ -387,6 +387,7 @@ de:
387
387
  attachments: Anhänge
388
388
  back_to_categories: Zurück zu den Kategorien
389
389
  category_details: Kategoriedetails
390
+ choose_product_category: Produktkategorie auswählen
390
391
  create_notice: Kategorie wurde erfolgreich erstellt
391
392
  delete_confirmation: Möchten Sie diese Kategorie wirklich löschen?
392
393
  description: Beschreibung
@@ -400,6 +401,7 @@ de:
400
401
  update_notice: Kategorie wurde erfolgreich aktualisiert
401
402
 
402
403
  products:
404
+ add_attachments: Anhänge betrachten/hinzufügen
403
405
  add_attribute: Attribut hinzufügen
404
406
  attachments: Anhänge
405
407
  attributes: Attribute
@@ -601,6 +603,7 @@ de:
601
603
  users: Benutzer
602
604
  countries: Länder
603
605
  settings: Einstellungen
606
+ customers: Kunden
604
607
 
605
608
  settings:
606
609
 
@@ -472,6 +472,7 @@ en:
472
472
  hierarchy: Hierarchy
473
473
 
474
474
  products:
475
+ add_attachments: View/add attachments
475
476
  add_attribute: Add attribute
476
477
  attachments: Attachments
477
478
  attributes: Attributes
@@ -400,6 +400,7 @@ es:
400
400
  update_notice: Categoría actualizada satisfactoriamente
401
401
 
402
402
  products:
403
+ add_attachments: Ver/agregar adjuntos
403
404
  add_attribute: Agregar atributo
404
405
  attachments: Adjuntos
405
406
  attributes: Atributos
@@ -415,6 +415,7 @@ pl:
415
415
  hierarchy: Hierarchy
416
416
 
417
417
  products:
418
+ add_attachments: Zobacz/dodaj załączniki
418
419
  add_attribute: Dodaj atrybut
419
420
  attachments: Załączniki
420
421
  attributes: Atrybuty
@@ -402,6 +402,7 @@ pt-BR:
402
402
  hierarchy: Hierarchy
403
403
 
404
404
  products:
405
+ add_attachments: Visualizar/adicionar anexos
405
406
  add_attribute: Adicionar atributo
406
407
  attachments: Anexos
407
408
  attributes: Atributos
@@ -0,0 +1,16 @@
1
+ class CreateShoppeAttachments < ActiveRecord::Migration
2
+ def change
3
+ create_table :shoppe_attachments do |t|
4
+ t.integer :parent_id, null: false
5
+ t.string :parent_type, null: false
6
+ t.string :token, unique: true
7
+ t.string :file, null: false
8
+ t.string :file_name
9
+ t.integer :file_size
10
+ t.string :file_type
11
+ t.string :role
12
+
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -11,20 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20150315223628) do
15
-
16
- create_table "nifty_attachments", force: true do |t|
17
- t.integer "parent_id"
18
- t.string "parent_type"
19
- t.string "token"
20
- t.string "digest"
21
- t.string "role"
22
- t.string "file_name"
23
- t.string "file_type"
24
- t.binary "data", limit: 16777215
25
- t.datetime "created_at"
26
- t.datetime "updated_at"
27
- end
14
+ ActiveRecord::Schema.define(version: 20150519173350) do
28
15
 
29
16
  create_table "nifty_key_value_store", force: true do |t|
30
17
  t.integer "parent_id"
@@ -48,7 +35,7 @@ ActiveRecord::Schema.define(version: 20150315223628) do
48
35
  t.datetime "updated_at"
49
36
  end
50
37
 
51
- add_index "shoppe_addresses", ["customer_id"], name: "index_shoppe_addresses_on_customer_id", using: :btree
38
+ add_index "shoppe_addresses", ["customer_id"], name: "index_shoppe_addresses_on_customer_id"
52
39
 
53
40
  create_table "shoppe_attachments", force: true do |t|
54
41
  t.integer "parent_id", null: false
@@ -97,10 +84,10 @@ ActiveRecord::Schema.define(version: 20150315223628) do
97
84
  t.text "country_ids"
98
85
  end
99
86
 
100
- add_index "shoppe_delivery_service_prices", ["delivery_service_id"], name: "index_shoppe_delivery_service_prices_on_delivery_service_id", using: :btree
101
- add_index "shoppe_delivery_service_prices", ["max_weight"], name: "index_shoppe_delivery_service_prices_on_max_weight", using: :btree
102
- add_index "shoppe_delivery_service_prices", ["min_weight"], name: "index_shoppe_delivery_service_prices_on_min_weight", using: :btree
103
- add_index "shoppe_delivery_service_prices", ["price"], name: "index_shoppe_delivery_service_prices_on_price", using: :btree
87
+ add_index "shoppe_delivery_service_prices", ["delivery_service_id"], name: "index_shoppe_delivery_service_prices_on_delivery_service_id"
88
+ add_index "shoppe_delivery_service_prices", ["max_weight"], name: "index_shoppe_delivery_service_prices_on_max_weight"
89
+ add_index "shoppe_delivery_service_prices", ["min_weight"], name: "index_shoppe_delivery_service_prices_on_min_weight"
90
+ add_index "shoppe_delivery_service_prices", ["price"], name: "index_shoppe_delivery_service_prices_on_price"
104
91
 
105
92
  create_table "shoppe_delivery_services", force: true do |t|
106
93
  t.string "name"
@@ -113,7 +100,7 @@ ActiveRecord::Schema.define(version: 20150315223628) do
113
100
  t.string "tracking_url"
114
101
  end
115
102
 
116
- add_index "shoppe_delivery_services", ["active"], name: "index_shoppe_delivery_services_on_active", using: :btree
103
+ add_index "shoppe_delivery_services", ["active"], name: "index_shoppe_delivery_services_on_active"
117
104
 
118
105
  create_table "shoppe_order_items", force: true do |t|
119
106
  t.integer "order_id"
@@ -129,8 +116,8 @@ ActiveRecord::Schema.define(version: 20150315223628) do
129
116
  t.datetime "updated_at"
130
117
  end
131
118
 
132
- add_index "shoppe_order_items", ["order_id"], name: "index_shoppe_order_items_on_order_id", using: :btree
133
- add_index "shoppe_order_items", ["ordered_item_id", "ordered_item_type"], name: "index_shoppe_order_items_ordered_item", using: :btree
119
+ add_index "shoppe_order_items", ["order_id"], name: "index_shoppe_order_items_on_order_id"
120
+ add_index "shoppe_order_items", ["ordered_item_id", "ordered_item_type"], name: "index_shoppe_order_items_ordered_item"
134
121
 
135
122
  create_table "shoppe_orders", force: true do |t|
136
123
  t.string "token"
@@ -177,9 +164,9 @@ ActiveRecord::Schema.define(version: 20150315223628) do
177
164
  t.integer "customer_id"
178
165
  end
179
166
 
180
- add_index "shoppe_orders", ["delivery_service_id"], name: "index_shoppe_orders_on_delivery_service_id", using: :btree
181
- add_index "shoppe_orders", ["received_at"], name: "index_shoppe_orders_on_received_at", using: :btree
182
- add_index "shoppe_orders", ["token"], name: "index_shoppe_orders_on_token", using: :btree
167
+ add_index "shoppe_orders", ["delivery_service_id"], name: "index_shoppe_orders_on_delivery_service_id"
168
+ add_index "shoppe_orders", ["received_at"], name: "index_shoppe_orders_on_received_at"
169
+ add_index "shoppe_orders", ["token"], name: "index_shoppe_orders_on_token"
183
170
 
184
171
  create_table "shoppe_payments", force: true do |t|
185
172
  t.integer "order_id"
@@ -195,8 +182,8 @@ ActiveRecord::Schema.define(version: 20150315223628) do
195
182
  t.datetime "updated_at"
196
183
  end
197
184
 
198
- add_index "shoppe_payments", ["order_id"], name: "index_shoppe_payments_on_order_id", using: :btree
199
- add_index "shoppe_payments", ["parent_payment_id"], name: "index_shoppe_payments_on_parent_payment_id", using: :btree
185
+ add_index "shoppe_payments", ["order_id"], name: "index_shoppe_payments_on_order_id"
186
+ add_index "shoppe_payments", ["parent_payment_id"], name: "index_shoppe_payments_on_parent_payment_id"
200
187
 
201
188
  create_table "shoppe_product_attributes", force: true do |t|
202
189
  t.integer "product_id"
@@ -209,9 +196,9 @@ ActiveRecord::Schema.define(version: 20150315223628) do
209
196
  t.boolean "public", default: true
210
197
  end
211
198
 
212
- add_index "shoppe_product_attributes", ["key"], name: "index_shoppe_product_attributes_on_key", using: :btree
213
- add_index "shoppe_product_attributes", ["position"], name: "index_shoppe_product_attributes_on_position", using: :btree
214
- add_index "shoppe_product_attributes", ["product_id"], name: "index_shoppe_product_attributes_on_product_id", using: :btree
199
+ add_index "shoppe_product_attributes", ["key"], name: "index_shoppe_product_attributes_on_key"
200
+ add_index "shoppe_product_attributes", ["position"], name: "index_shoppe_product_attributes_on_position"
201
+ add_index "shoppe_product_attributes", ["product_id"], name: "index_shoppe_product_attributes_on_product_id"
215
202
 
216
203
  create_table "shoppe_product_categories", force: true do |t|
217
204
  t.string "name"
@@ -227,17 +214,44 @@ ActiveRecord::Schema.define(version: 20150315223628) do
227
214
  t.boolean "permalink_includes_ancestors", default: false
228
215
  end
229
216
 
230
- add_index "shoppe_product_categories", ["lft"], name: "index_shoppe_product_categories_on_lft", using: :btree
231
- add_index "shoppe_product_categories", ["permalink"], name: "index_shoppe_product_categories_on_permalink", using: :btree
232
- add_index "shoppe_product_categories", ["rgt"], name: "index_shoppe_product_categories_on_rgt", using: :btree
217
+ add_index "shoppe_product_categories", ["lft"], name: "index_shoppe_product_categories_on_lft"
218
+ add_index "shoppe_product_categories", ["permalink"], name: "index_shoppe_product_categories_on_permalink"
219
+ add_index "shoppe_product_categories", ["rgt"], name: "index_shoppe_product_categories_on_rgt"
233
220
 
234
221
  create_table "shoppe_product_categorizations", force: true do |t|
235
222
  t.integer "product_id", null: false
236
223
  t.integer "product_category_id", null: false
237
224
  end
238
225
 
239
- add_index "shoppe_product_categorizations", ["product_category_id"], name: "categorization_by_product_category_id", using: :btree
240
- add_index "shoppe_product_categorizations", ["product_id"], name: "categorization_by_product_id", using: :btree
226
+ add_index "shoppe_product_categorizations", ["product_category_id"], name: "categorization_by_product_category_id"
227
+ add_index "shoppe_product_categorizations", ["product_id"], name: "categorization_by_product_id"
228
+
229
+ create_table "shoppe_product_category_translations", force: true do |t|
230
+ t.integer "shoppe_product_category_id", null: false
231
+ t.string "locale", null: false
232
+ t.datetime "created_at"
233
+ t.datetime "updated_at"
234
+ t.string "name"
235
+ t.string "permalink"
236
+ t.text "description"
237
+ end
238
+
239
+ add_index "shoppe_product_category_translations", ["locale"], name: "index_shoppe_product_category_translations_on_locale"
240
+ add_index "shoppe_product_category_translations", ["shoppe_product_category_id"], name: "index_75826cc72f93d014e54dc08b8202892841c670b4"
241
+
242
+ create_table "shoppe_product_translations", force: true do |t|
243
+ t.integer "shoppe_product_id", null: false
244
+ t.string "locale", null: false
245
+ t.datetime "created_at"
246
+ t.datetime "updated_at"
247
+ t.string "name"
248
+ t.string "permalink"
249
+ t.text "description"
250
+ t.text "short_description"
251
+ end
252
+
253
+ add_index "shoppe_product_translations", ["locale"], name: "index_shoppe_product_translations_on_locale"
254
+ add_index "shoppe_product_translations", ["shoppe_product_id"], name: "index_shoppe_product_translations_on_shoppe_product_id"
241
255
 
242
256
  create_table "shoppe_products", force: true do |t|
243
257
  t.integer "parent_id"
@@ -259,9 +273,9 @@ ActiveRecord::Schema.define(version: 20150315223628) do
259
273
  t.boolean "default", default: false
260
274
  end
261
275
 
262
- add_index "shoppe_products", ["parent_id"], name: "index_shoppe_products_on_parent_id", using: :btree
263
- add_index "shoppe_products", ["permalink"], name: "index_shoppe_products_on_permalink", using: :btree
264
- add_index "shoppe_products", ["sku"], name: "index_shoppe_products_on_sku", using: :btree
276
+ add_index "shoppe_products", ["parent_id"], name: "index_shoppe_products_on_parent_id"
277
+ add_index "shoppe_products", ["permalink"], name: "index_shoppe_products_on_permalink"
278
+ add_index "shoppe_products", ["sku"], name: "index_shoppe_products_on_sku"
265
279
 
266
280
  create_table "shoppe_settings", force: true do |t|
267
281
  t.string "key"
@@ -269,7 +283,7 @@ ActiveRecord::Schema.define(version: 20150315223628) do
269
283
  t.string "value_type"
270
284
  end
271
285
 
272
- add_index "shoppe_settings", ["key"], name: "index_shoppe_settings_on_key", using: :btree
286
+ add_index "shoppe_settings", ["key"], name: "index_shoppe_settings_on_key"
273
287
 
274
288
  create_table "shoppe_stock_level_adjustments", force: true do |t|
275
289
  t.integer "item_id"
@@ -282,8 +296,8 @@ ActiveRecord::Schema.define(version: 20150315223628) do
282
296
  t.datetime "updated_at"
283
297
  end
284
298
 
285
- add_index "shoppe_stock_level_adjustments", ["item_id", "item_type"], name: "index_shoppe_stock_level_adjustments_items", using: :btree
286
- add_index "shoppe_stock_level_adjustments", ["parent_id", "parent_type"], name: "index_shoppe_stock_level_adjustments_parent", using: :btree
299
+ add_index "shoppe_stock_level_adjustments", ["item_id", "item_type"], name: "index_shoppe_stock_level_adjustments_items"
300
+ add_index "shoppe_stock_level_adjustments", ["parent_id", "parent_type"], name: "index_shoppe_stock_level_adjustments_parent"
287
301
 
288
302
  create_table "shoppe_tax_rates", force: true do |t|
289
303
  t.string "name"
@@ -303,6 +317,6 @@ ActiveRecord::Schema.define(version: 20150315223628) do
303
317
  t.datetime "updated_at"
304
318
  end
305
319
 
306
- add_index "shoppe_users", ["email_address"], name: "index_shoppe_users_on_email_address", using: :btree
320
+ add_index "shoppe_users", ["email_address"], name: "index_shoppe_users_on_email_address"
307
321
 
308
322
  end
@@ -10,8 +10,8 @@ require "globalize"
10
10
 
11
11
  require 'nifty/utils'
12
12
  require 'nifty/key_value_store'
13
- require 'nifty/attachments'
14
13
  require 'nifty/dialog'
14
+ require 'carrierwave'
15
15
 
16
16
  module Shoppe
17
17
  class << self
@@ -41,6 +41,11 @@ module Shoppe
41
41
  require 'shoppe/view_helpers'
42
42
  ActionView::Base.send :include, Shoppe::ViewHelpers
43
43
  end
44
+
45
+ ActiveSupport.on_load(:active_record) do
46
+ require 'shoppe/model_extension'
47
+ ActiveRecord::Base.send :include, Shoppe::ModelExtension
48
+ end
44
49
 
45
50
  # Load default navigation
46
51
  require 'shoppe/default_navigation'
@@ -0,0 +1,44 @@
1
+ module Shoppe
2
+ module ModelExtension
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ base.after_save do
7
+ if @pending_attachments
8
+ @pending_attachments.each do |pa|
9
+ old_attachments = self.attachments.where(:role => pa[:role]).pluck(:id)
10
+ self.attachments.create(:file => pa[:file], :role => pa[:role])
11
+ self.attachments.where(:id => old_attachments).destroy_all
12
+ end
13
+ @pending_attachments = nil
14
+ end
15
+ end
16
+ end
17
+
18
+ module ClassMethods
19
+
20
+ def attachment(name)
21
+ unless self.reflect_on_all_associations(:has_many).map(&:name).include?(:attachments)
22
+ has_many :attachments, :as => :parent, :dependent => :destroy, :class_name => 'Shoppe::Attachment'
23
+ end
24
+
25
+ has_one name, -> { select(:id, :token, :parent_id, :parent_type, :file_name, :file_type, :file_size).where(:role => name) }, :class_name => 'Shoppe::Attachment', :as => :parent
26
+
27
+ define_method "#{name}_file" do
28
+ instance_variable_get("@#{name}_file")
29
+ end
30
+
31
+ define_method "#{name}_file=" do |file|
32
+ instance_variable_set("@#{name}_file", file)
33
+ if file.is_a?(ActionDispatch::Http::UploadedFile)
34
+ @pending_attachments ||= []
35
+ @pending_attachments << {:role => name, :file => file}
36
+ else
37
+ nil
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Shoppe
2
- VERSION = "1.0.8"
2
+ VERSION = "1.0.9"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  namespace :shoppe do
2
+
2
3
  desc "Load seed data for the Shoppe"
3
4
  task :seed => :environment do
4
5
  require File.join(Shoppe.root, 'db', 'seeds')
@@ -25,5 +26,28 @@ namespace :shoppe do
25
26
  Rake::Task["shoppe:import_countries"].invoke if Shoppe::Country.all.empty?
26
27
  Rake::Task["shoppe:create_default_user"].invoke if Shoppe::User.all.empty?
27
28
  end
29
+
30
+ desc "Converts nifty-attachment attachments to Shoppe Attachments"
31
+ task :attachments => :environment do
32
+ require "nifty/attachments"
33
+
34
+ attachments = Nifty::Attachments::Attachment.all
35
+
36
+ attachments.each do |attachment|
37
+ object = attachment.parent_type.constantize.find(attachment.parent_id)
38
+
39
+ attach = object.attachments.build
40
+ attach.role = attachment.role
41
+ attach.file_name = attachment.file_name
42
+
43
+ tempfile = Tempfile.new("attach-#{attachment.token}")
44
+ tempfile.binmode
45
+ tempfile.write(attachment.data)
46
+ uploaded_file = ActionDispatch::Http::UploadedFile.new(tempfile: tempfile, filename: attachment.file_name, type: attachment.file_type)
47
+
48
+ attach.file = uploaded_file
49
+ attach.save!
50
+ end
51
+ end
28
52
 
29
53
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoppe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
+ - Dean Perry
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-06-27 00:00:00.000000000 Z
12
+ date: 2015-07-01 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rails
@@ -176,14 +177,14 @@ dependencies:
176
177
  requirements:
177
178
  - - "~>"
178
179
  - !ruby/object:Gem::Version
179
- version: 3.0.1
180
+ version: 3.0.2
180
181
  type: :runtime
181
182
  prerelease: false
182
183
  version_requirements: !ruby/object:Gem::Requirement
183
184
  requirements:
184
185
  - - "~>"
185
186
  - !ruby/object:Gem::Version
186
- version: 3.0.1
187
+ version: 3.0.2
187
188
  - !ruby/object:Gem::Dependency
188
189
  name: globalize
189
190
  requirement: !ruby/object:Gem::Requirement
@@ -239,45 +240,67 @@ dependencies:
239
240
  - !ruby/object:Gem::Version
240
241
  version: '1.1'
241
242
  - !ruby/object:Gem::Dependency
242
- name: nifty-attachments
243
+ name: nifty-dialog
243
244
  requirement: !ruby/object:Gem::Requirement
244
245
  requirements:
245
246
  - - ">="
246
247
  - !ruby/object:Gem::Version
247
- version: 1.0.3
248
+ version: 1.0.7
248
249
  - - "<"
249
250
  - !ruby/object:Gem::Version
250
- version: 2.0.0
251
+ version: '1.1'
251
252
  type: :runtime
252
253
  prerelease: false
253
254
  version_requirements: !ruby/object:Gem::Requirement
254
255
  requirements:
255
256
  - - ">="
256
257
  - !ruby/object:Gem::Version
257
- version: 1.0.3
258
+ version: 1.0.7
258
259
  - - "<"
259
260
  - !ruby/object:Gem::Version
260
- version: 2.0.0
261
+ version: '1.1'
261
262
  - !ruby/object:Gem::Dependency
262
- name: nifty-dialog
263
+ name: carrierwave
263
264
  requirement: !ruby/object:Gem::Requirement
264
265
  requirements:
265
- - - ">="
266
+ - - "~>"
266
267
  - !ruby/object:Gem::Version
267
- version: 1.0.7
268
- - - "<"
268
+ version: 0.10.0
269
+ type: :runtime
270
+ prerelease: false
271
+ version_requirements: !ruby/object:Gem::Requirement
272
+ requirements:
273
+ - - "~>"
269
274
  - !ruby/object:Gem::Version
270
- version: '1.1'
275
+ version: 0.10.0
276
+ - !ruby/object:Gem::Dependency
277
+ name: fog
278
+ requirement: !ruby/object:Gem::Requirement
279
+ requirements:
280
+ - - "~>"
281
+ - !ruby/object:Gem::Version
282
+ version: 1.31.0
271
283
  type: :runtime
272
284
  prerelease: false
273
285
  version_requirements: !ruby/object:Gem::Requirement
274
286
  requirements:
275
- - - ">="
287
+ - - "~>"
276
288
  - !ruby/object:Gem::Version
277
- version: 1.0.7
278
- - - "<"
289
+ version: 1.31.0
290
+ - !ruby/object:Gem::Dependency
291
+ name: mini_magick
292
+ requirement: !ruby/object:Gem::Requirement
293
+ requirements:
294
+ - - "~>"
279
295
  - !ruby/object:Gem::Version
280
- version: '1.1'
296
+ version: 4.2.7
297
+ type: :runtime
298
+ prerelease: false
299
+ version_requirements: !ruby/object:Gem::Requirement
300
+ requirements:
301
+ - - "~>"
302
+ - !ruby/object:Gem::Version
303
+ version: 4.2.7
281
304
  - !ruby/object:Gem::Dependency
282
305
  name: coffee-rails
283
306
  requirement: !ruby/object:Gem::Requirement
@@ -394,6 +417,7 @@ description: A full Rails engine providing e-commerce functionality for any Rail
394
417
  4 application.
395
418
  email:
396
419
  - adam@atechmedia.com
420
+ - dean@voupe.com
397
421
  executables: []
398
422
  extensions: []
399
423
  extra_rdoc_files: []
@@ -478,6 +502,7 @@ files:
478
502
  - app/mailers/shoppe/order_mailer.rb
479
503
  - app/mailers/shoppe/user_mailer.rb
480
504
  - app/models/shoppe/address.rb
505
+ - app/models/shoppe/attachment.rb
481
506
  - app/models/shoppe/country.rb
482
507
  - app/models/shoppe/customer.rb
483
508
  - app/models/shoppe/delivery_service.rb
@@ -499,6 +524,7 @@ files:
499
524
  - app/models/shoppe/stock_level_adjustment.rb
500
525
  - app/models/shoppe/tax_rate.rb
501
526
  - app/models/shoppe/user.rb
527
+ - app/uploaders/shoppe/attachment_uploader.rb
502
528
  - app/validators/permalink_validator.rb
503
529
  - app/views/layouts/shoppe/application.html.haml
504
530
  - app/views/layouts/shoppe/printable.html.haml
@@ -597,6 +623,7 @@ files:
597
623
  - db/migrate/20141026181718_add_nested_to_product_categories.rb
598
624
  - db/migrate/20141027215005_create_shoppe_addresses.rb
599
625
  - db/migrate/20150315215633_add_customer_to_shoppe_orders.rb
626
+ - db/migrate/20150315223628_create_shoppe_attachments.rb
600
627
  - db/migrate/20150513171350_create_shoppe_product_category_translation_table.rb
601
628
  - db/migrate/20150519173350_create_shoppe_product_translation_table.rb
602
629
  - db/schema.rb
@@ -627,6 +654,7 @@ files:
627
654
  - lib/shoppe/errors/payment_declined.rb
628
655
  - lib/shoppe/errors/refund_failed.rb
629
656
  - lib/shoppe/errors/unorderable_item.rb
657
+ - lib/shoppe/model_extension.rb
630
658
  - lib/shoppe/navigation_manager.rb
631
659
  - lib/shoppe/orderable_item.rb
632
660
  - lib/shoppe/settings.rb