kkt_shoppe 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 597fb1562ba6b8a59114f039b0eb7d431a0e6817
4
- data.tar.gz: b79dfc7457411f2d2f96cdbeeaac37b93071c900
3
+ metadata.gz: bb53752d16704023abdca027c6e387744b60e4c9
4
+ data.tar.gz: 58f330c325c07e7e3e06d6cc4a3252a07889034d
5
5
  SHA512:
6
- metadata.gz: 88f3f089841dcc6fddc1809dd79353feae2352e9ae46e252b60f4c29bf173c1163cf42d4588c8533b90ef1d8149b3a2d19d793c5d27146d6064b0b50df5dade2
7
- data.tar.gz: 2b5d4c9862461b528c0414f7bc456fe2ed2565052d62d0b3998992917caff70beb0b89839822606e23a5b5abfb97e31ab7755ebe20ea39ae4192d637997cfac4
6
+ metadata.gz: 98dd5d416ce71c145558bb2188a9898cc97f513d232a9b75d9ed8edf9bb9c69733ec85f3df2e69e3f503db3f8b824421c6c301e816bf6e4f212190bb5666d8ff
7
+ data.tar.gz: b1d45698bf1f00c6b78eb29342751cb5d821d63f328995d0fb731737297c97b7646b90c1723d8df9a980ed527ee8c4a37d2236429bb3b628019af3f46b031597
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # KktShoppe
2
2
 
3
3
  KktShoppe is an Rails-based e-commerce platform which allows you to easily introduce a
4
- catalogue-based store into your Rails 4 applications.
4
+ catalogue-based store into your Rails 4 applications.
5
5
 
6
6
  ![GemVersion](https://badge.fury.io/rb/kkt_shoppe.png)
7
7
  [![Code Climate](https://codeclimate.com/github/trykkt_shoppe/core/badges/gpa.svg)](https://codeclimate.com/github/trykkt_shoppe/core)
@@ -39,7 +39,6 @@ instructions below and you'll be up and running in minutes.
39
39
  echo "gem 'kkt_shoppe', '~> 1.0'" >> Gemfile
40
40
  bundle
41
41
  rails generate kkt_shoppe:setup
42
- rails generate nifty:attachments:migration
43
42
  rails generate nifty:key_value_store:migration
44
43
  rake db:migrate kkt_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 KktShoppe
2
2
  class AttachmentsController < KktShoppe::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('kkt_shoppe.attachments.remove_notice')}
@@ -5,7 +5,7 @@ module KktShoppe
5
5
  before_filter { params[:id] && @product = KktShoppe::Product.root.find(params[:id]) }
6
6
 
7
7
  def index
8
- @products = KktShoppe::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 = KktShoppe::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 KktShoppe
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 KktShoppe
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>"
@@ -10,9 +10,8 @@ module KktShoppe
10
10
  require_dependency 'kkt_shoppe/product/product_attributes'
11
11
  require_dependency 'kkt_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 KktShoppe
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 KktShoppe
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 KktShoppe
12
12
 
13
13
  self.table_name = 'kkt_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: 'KktShoppe::ProductCategorization', inverse_of: :product_category
@@ -51,6 +51,13 @@ module KktShoppe
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,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
@@ -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('kkt_shoppe.products.attachments') do
58
58
  .splitContainer
59
59
  %dl.half
60
- %dt= f.label :default_image_file, t('kkt_shoppe.products.default_image')
60
+ %dt= f.label "attachments[default_image][file]", t('kkt_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('kkt_shoppe.products.datasheet')
67
+ %dt= f.label "attachments[data_sheet][file]", t('kkt_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: "KktShoppe::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('kkt_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('kkt_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 CreateKktShoppeAttachments < ActiveRecord::Migration
2
+ def change
3
+ create_table :kkt_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
data/db/schema.rb CHANGED
@@ -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 "kkt_shoppe_addresses", ["customer_id"], name: "index_kkt_shoppe_addresses_on_customer_id", using: :btree
38
+ add_index "kkt_shoppe_addresses", ["customer_id"], name: "index_kkt_shoppe_addresses_on_customer_id"
52
39
 
53
40
  create_table "kkt_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 "kkt_shoppe_delivery_service_prices", ["delivery_service_id"], name: "index_kkt_shoppe_delivery_service_prices_on_delivery_service_id", using: :btree
101
- add_index "kkt_shoppe_delivery_service_prices", ["max_weight"], name: "index_kkt_shoppe_delivery_service_prices_on_max_weight", using: :btree
102
- add_index "kkt_shoppe_delivery_service_prices", ["min_weight"], name: "index_kkt_shoppe_delivery_service_prices_on_min_weight", using: :btree
103
- add_index "kkt_shoppe_delivery_service_prices", ["price"], name: "index_kkt_shoppe_delivery_service_prices_on_price", using: :btree
87
+ add_index "kkt_shoppe_delivery_service_prices", ["delivery_service_id"], name: "index_kkt_shoppe_delivery_service_prices_on_delivery_service_id"
88
+ add_index "kkt_shoppe_delivery_service_prices", ["max_weight"], name: "index_kkt_shoppe_delivery_service_prices_on_max_weight"
89
+ add_index "kkt_shoppe_delivery_service_prices", ["min_weight"], name: "index_kkt_shoppe_delivery_service_prices_on_min_weight"
90
+ add_index "kkt_shoppe_delivery_service_prices", ["price"], name: "index_kkt_shoppe_delivery_service_prices_on_price"
104
91
 
105
92
  create_table "kkt_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 "kkt_shoppe_delivery_services", ["active"], name: "index_kkt_shoppe_delivery_services_on_active", using: :btree
103
+ add_index "kkt_shoppe_delivery_services", ["active"], name: "index_kkt_shoppe_delivery_services_on_active"
117
104
 
118
105
  create_table "kkt_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 "kkt_shoppe_order_items", ["order_id"], name: "index_kkt_shoppe_order_items_on_order_id", using: :btree
133
- add_index "kkt_shoppe_order_items", ["ordered_item_id", "ordered_item_type"], name: "index_kkt_shoppe_order_items_ordered_item", using: :btree
119
+ add_index "kkt_shoppe_order_items", ["order_id"], name: "index_kkt_shoppe_order_items_on_order_id"
120
+ add_index "kkt_shoppe_order_items", ["ordered_item_id", "ordered_item_type"], name: "index_kkt_shoppe_order_items_ordered_item"
134
121
 
135
122
  create_table "kkt_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 "kkt_shoppe_orders", ["delivery_service_id"], name: "index_kkt_shoppe_orders_on_delivery_service_id", using: :btree
181
- add_index "kkt_shoppe_orders", ["received_at"], name: "index_kkt_shoppe_orders_on_received_at", using: :btree
182
- add_index "kkt_shoppe_orders", ["token"], name: "index_kkt_shoppe_orders_on_token", using: :btree
167
+ add_index "kkt_shoppe_orders", ["delivery_service_id"], name: "index_kkt_shoppe_orders_on_delivery_service_id"
168
+ add_index "kkt_shoppe_orders", ["received_at"], name: "index_kkt_shoppe_orders_on_received_at"
169
+ add_index "kkt_shoppe_orders", ["token"], name: "index_kkt_shoppe_orders_on_token"
183
170
 
184
171
  create_table "kkt_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 "kkt_shoppe_payments", ["order_id"], name: "index_kkt_shoppe_payments_on_order_id", using: :btree
199
- add_index "kkt_shoppe_payments", ["parent_payment_id"], name: "index_kkt_shoppe_payments_on_parent_payment_id", using: :btree
185
+ add_index "kkt_shoppe_payments", ["order_id"], name: "index_kkt_shoppe_payments_on_order_id"
186
+ add_index "kkt_shoppe_payments", ["parent_payment_id"], name: "index_kkt_shoppe_payments_on_parent_payment_id"
200
187
 
201
188
  create_table "kkt_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 "kkt_shoppe_product_attributes", ["key"], name: "index_kkt_shoppe_product_attributes_on_key", using: :btree
213
- add_index "kkt_shoppe_product_attributes", ["position"], name: "index_kkt_shoppe_product_attributes_on_position", using: :btree
214
- add_index "kkt_shoppe_product_attributes", ["product_id"], name: "index_kkt_shoppe_product_attributes_on_product_id", using: :btree
199
+ add_index "kkt_shoppe_product_attributes", ["key"], name: "index_kkt_shoppe_product_attributes_on_key"
200
+ add_index "kkt_shoppe_product_attributes", ["position"], name: "index_kkt_shoppe_product_attributes_on_position"
201
+ add_index "kkt_shoppe_product_attributes", ["product_id"], name: "index_kkt_shoppe_product_attributes_on_product_id"
215
202
 
216
203
  create_table "kkt_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 "kkt_shoppe_product_categories", ["lft"], name: "index_kkt_shoppe_product_categories_on_lft", using: :btree
231
- add_index "kkt_shoppe_product_categories", ["permalink"], name: "index_kkt_shoppe_product_categories_on_permalink", using: :btree
232
- add_index "kkt_shoppe_product_categories", ["rgt"], name: "index_kkt_shoppe_product_categories_on_rgt", using: :btree
217
+ add_index "kkt_shoppe_product_categories", ["lft"], name: "index_kkt_shoppe_product_categories_on_lft"
218
+ add_index "kkt_shoppe_product_categories", ["permalink"], name: "index_kkt_shoppe_product_categories_on_permalink"
219
+ add_index "kkt_shoppe_product_categories", ["rgt"], name: "index_kkt_shoppe_product_categories_on_rgt"
233
220
 
234
221
  create_table "kkt_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 "kkt_shoppe_product_categorizations", ["product_category_id"], name: "categorization_by_product_category_id", using: :btree
240
- add_index "kkt_shoppe_product_categorizations", ["product_id"], name: "categorization_by_product_id", using: :btree
226
+ add_index "kkt_shoppe_product_categorizations", ["product_category_id"], name: "categorization_by_product_category_id"
227
+ add_index "kkt_shoppe_product_categorizations", ["product_id"], name: "categorization_by_product_id"
228
+
229
+ create_table "kkt_shoppe_product_category_translations", force: true do |t|
230
+ t.integer "kkt_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 "kkt_shoppe_product_category_translations", ["locale"], name: "index_kkt_shoppe_product_category_translations_on_locale"
240
+ add_index "kkt_shoppe_product_category_translations", ["kkt_shoppe_product_category_id"], name: "index_75826cc72f93d014e54dc08b8202892841c670b4"
241
+
242
+ create_table "kkt_shoppe_product_translations", force: true do |t|
243
+ t.integer "kkt_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 "kkt_shoppe_product_translations", ["locale"], name: "index_kkt_shoppe_product_translations_on_locale"
254
+ add_index "kkt_shoppe_product_translations", ["kkt_shoppe_product_id"], name: "index_kkt_shoppe_product_translations_on_kkt_shoppe_product_id"
241
255
 
242
256
  create_table "kkt_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 "kkt_shoppe_products", ["parent_id"], name: "index_kkt_shoppe_products_on_parent_id", using: :btree
263
- add_index "kkt_shoppe_products", ["permalink"], name: "index_kkt_shoppe_products_on_permalink", using: :btree
264
- add_index "kkt_shoppe_products", ["sku"], name: "index_kkt_shoppe_products_on_sku", using: :btree
276
+ add_index "kkt_shoppe_products", ["parent_id"], name: "index_kkt_shoppe_products_on_parent_id"
277
+ add_index "kkt_shoppe_products", ["permalink"], name: "index_kkt_shoppe_products_on_permalink"
278
+ add_index "kkt_shoppe_products", ["sku"], name: "index_kkt_shoppe_products_on_sku"
265
279
 
266
280
  create_table "kkt_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 "kkt_shoppe_settings", ["key"], name: "index_kkt_shoppe_settings_on_key", using: :btree
286
+ add_index "kkt_shoppe_settings", ["key"], name: "index_kkt_shoppe_settings_on_key"
273
287
 
274
288
  create_table "kkt_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 "kkt_shoppe_stock_level_adjustments", ["item_id", "item_type"], name: "index_kkt_shoppe_stock_level_adjustments_items", using: :btree
286
- add_index "kkt_shoppe_stock_level_adjustments", ["parent_id", "parent_type"], name: "index_kkt_shoppe_stock_level_adjustments_parent", using: :btree
299
+ add_index "kkt_shoppe_stock_level_adjustments", ["item_id", "item_type"], name: "index_kkt_shoppe_stock_level_adjustments_items"
300
+ add_index "kkt_shoppe_stock_level_adjustments", ["parent_id", "parent_type"], name: "index_kkt_shoppe_stock_level_adjustments_parent"
287
301
 
288
302
  create_table "kkt_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 "kkt_shoppe_users", ["email_address"], name: "index_kkt_shoppe_users_on_email_address", using: :btree
320
+ add_index "kkt_shoppe_users", ["email_address"], name: "index_kkt_shoppe_users_on_email_address"
307
321
 
308
322
  end
@@ -1,12 +1,12 @@
1
1
  module KktShoppe
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace KktShoppe
4
-
4
+
5
5
  if KktShoppe.respond_to?(:root)
6
6
  config.autoload_paths << File.join(KktShoppe.root, 'lib')
7
7
  config.assets.precompile += ['kkt_shoppe/sub.css', 'kkt_shoppe/printable.css']
8
8
  end
9
-
9
+
10
10
  # We don't want any automatic generators in the engine.
11
11
  config.generators do |g|
12
12
  g.orm :active_record
@@ -21,35 +21,39 @@ module KktShoppe
21
21
  require_dependency(c)
22
22
  end
23
23
  end
24
-
24
+
25
25
  initializer 'kkt_shoppe.initialize' do |app|
26
26
  # Add the default settings
27
27
  KktShoppe.add_settings_group :system_settings, [:store_name, :email_address, :currency_unit, :tax_name, :demo_mode]
28
-
28
+
29
29
  # Add middleware
30
30
  app.config.middleware.use KktShoppe::SettingsLoader
31
-
31
+
32
32
  # Load our migrations into the application's db/migrate path
33
33
  unless app.root.to_s.match root.to_s
34
34
  config.paths["db/migrate"].expanded.each do |expanded_path|
35
35
  app.config.paths["db/migrate"] << expanded_path
36
36
  end
37
- end
38
-
37
+ end
38
+
39
39
  # Load view helpers for the base application
40
40
  ActiveSupport.on_load(:action_view) do
41
41
  require 'kkt_shoppe/view_helpers'
42
42
  ActionView::Base.send :include, KktShoppe::ViewHelpers
43
43
  end
44
-
44
+
45
+ ActiveSupport.on_load(:active_record) do
46
+ require 'kkt_shoppe/model_extension'
47
+ ActiveRecord::Base.send :include, KktShoppe::ModelExtension
48
+ end
49
+
45
50
  # Load default navigation
46
51
  require 'kkt_shoppe/default_navigation'
47
52
  end
48
-
53
+
49
54
  generators do
50
55
  require 'kkt_shoppe/setup_generator'
51
56
  end
52
-
57
+
53
58
  end
54
59
  end
55
-
@@ -0,0 +1,44 @@
1
+ module KktShoppe
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 => 'KktShoppe::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 => 'KktShoppe::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 KktShoppe
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
data/lib/kkt_shoppe.rb CHANGED
@@ -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 KktShoppe
17
17
  class << self
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kkt_shoppe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Thompson, Adam Cooke
@@ -176,14 +176,14 @@ dependencies:
176
176
  requirements:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
- version: 3.0.1
179
+ version: 3.0.2
180
180
  type: :runtime
181
181
  prerelease: false
182
182
  version_requirements: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - "~>"
185
185
  - !ruby/object:Gem::Version
186
- version: 3.0.1
186
+ version: 3.0.2
187
187
  - !ruby/object:Gem::Dependency
188
188
  name: globalize
189
189
  requirement: !ruby/object:Gem::Requirement
@@ -239,45 +239,67 @@ dependencies:
239
239
  - !ruby/object:Gem::Version
240
240
  version: '1.1'
241
241
  - !ruby/object:Gem::Dependency
242
- name: nifty-attachments
242
+ name: nifty-dialog
243
243
  requirement: !ruby/object:Gem::Requirement
244
244
  requirements:
245
245
  - - ">="
246
246
  - !ruby/object:Gem::Version
247
- version: 1.0.3
247
+ version: 1.0.7
248
248
  - - "<"
249
249
  - !ruby/object:Gem::Version
250
- version: 2.0.0
250
+ version: '1.1'
251
251
  type: :runtime
252
252
  prerelease: false
253
253
  version_requirements: !ruby/object:Gem::Requirement
254
254
  requirements:
255
255
  - - ">="
256
256
  - !ruby/object:Gem::Version
257
- version: 1.0.3
257
+ version: 1.0.7
258
258
  - - "<"
259
259
  - !ruby/object:Gem::Version
260
- version: 2.0.0
260
+ version: '1.1'
261
261
  - !ruby/object:Gem::Dependency
262
- name: nifty-dialog
262
+ name: carrierwave
263
263
  requirement: !ruby/object:Gem::Requirement
264
264
  requirements:
265
- - - ">="
265
+ - - "~>"
266
266
  - !ruby/object:Gem::Version
267
- version: 1.0.7
268
- - - "<"
267
+ version: 0.10.0
268
+ type: :runtime
269
+ prerelease: false
270
+ version_requirements: !ruby/object:Gem::Requirement
271
+ requirements:
272
+ - - "~>"
269
273
  - !ruby/object:Gem::Version
270
- version: '1.1'
274
+ version: 0.10.0
275
+ - !ruby/object:Gem::Dependency
276
+ name: fog
277
+ requirement: !ruby/object:Gem::Requirement
278
+ requirements:
279
+ - - "~>"
280
+ - !ruby/object:Gem::Version
281
+ version: 1.31.0
271
282
  type: :runtime
272
283
  prerelease: false
273
284
  version_requirements: !ruby/object:Gem::Requirement
274
285
  requirements:
275
- - - ">="
286
+ - - "~>"
276
287
  - !ruby/object:Gem::Version
277
- version: 1.0.7
278
- - - "<"
288
+ version: 1.31.0
289
+ - !ruby/object:Gem::Dependency
290
+ name: mini_magick
291
+ requirement: !ruby/object:Gem::Requirement
292
+ requirements:
293
+ - - "~>"
279
294
  - !ruby/object:Gem::Version
280
- version: '1.1'
295
+ version: 4.2.7
296
+ type: :runtime
297
+ prerelease: false
298
+ version_requirements: !ruby/object:Gem::Requirement
299
+ requirements:
300
+ - - "~>"
301
+ - !ruby/object:Gem::Version
302
+ version: 4.2.7
281
303
  - !ruby/object:Gem::Dependency
282
304
  name: coffee-rails
283
305
  requirement: !ruby/object:Gem::Requirement
@@ -499,6 +521,8 @@ files:
499
521
  - app/models/kkt_shoppe/stock_level_adjustment.rb
500
522
  - app/models/kkt_shoppe/tax_rate.rb
501
523
  - app/models/kkt_shoppe/user.rb
524
+ - app/models/shoppe/attachment.rb
525
+ - app/uploaders/shoppe/attachment_uploader.rb
502
526
  - app/validators/permalink_validator.rb
503
527
  - app/views/kkt_shoppe/addresses/_form.html.haml
504
528
  - app/views/kkt_shoppe/addresses/edit.html.haml
@@ -597,6 +621,7 @@ files:
597
621
  - db/migrate/20141026181718_add_nested_to_product_categories.rb
598
622
  - db/migrate/20141027215005_create_kkt_shoppe_addresses.rb
599
623
  - db/migrate/20150315215633_add_customer_to_kkt_shoppe_orders.rb
624
+ - db/migrate/20150315223628_create_kkt_shoppe_attachments.rb
600
625
  - db/migrate/20150513171350_create_kkt_shoppe_product_category_translation_table.rb
601
626
  - db/migrate/20150519173350_create_kkt_shoppe_product_translation_table.rb
602
627
  - db/schema.rb
@@ -627,6 +652,7 @@ files:
627
652
  - lib/kkt_shoppe/errors/payment_declined.rb
628
653
  - lib/kkt_shoppe/errors/refund_failed.rb
629
654
  - lib/kkt_shoppe/errors/unorderable_item.rb
655
+ - lib/kkt_shoppe/model_extension.rb
630
656
  - lib/kkt_shoppe/navigation_manager.rb
631
657
  - lib/kkt_shoppe/orderable_item.rb
632
658
  - lib/kkt_shoppe/settings.rb
@@ -634,6 +660,7 @@ files:
634
660
  - lib/kkt_shoppe/setup_generator.rb
635
661
  - lib/kkt_shoppe/version.rb
636
662
  - lib/kkt_shoppe/view_helpers.rb
663
+ - lib/shoppe/model_extension.rb
637
664
  - lib/tasks/kylekthompson_shoppe.rake
638
665
  homepage: http://tryshoppe.com
639
666
  licenses:
@@ -660,3 +687,4 @@ signing_key:
660
687
  specification_version: 4
661
688
  summary: Just an *edited* e-commerce platform.
662
689
  test_files: []
690
+ has_rdoc: