kkt_shoppe 1.2.1 → 1.3.0

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: 7fd6597e581c54983a21cd15705ca253fddba77c
4
- data.tar.gz: 56ff38e3fc9ea45f7e967c438f834604ea932346
3
+ metadata.gz: 1c5cfcba449d6f6034038dd1d0d1104fc0381a10
4
+ data.tar.gz: 28e3701135c64020af85a4bf2717f39c69ad5d04
5
5
  SHA512:
6
- metadata.gz: 53d16668a2ba4ef9a4347c1fc72ce2c103b11aef62a80b7d474ae58acae5b4412ade3e4f26091d8ac8f8eb3622c8ae4bf8a1f7802b2795c37ed6a51d6a28af78
7
- data.tar.gz: 95d480d02222dd842ea9ae9cf4c4408c1ba4fab5a32f6e5a55d3f9f411de7fb90b7a37193a24d5b6a28353996ce8b89578fef653a4908a73e5cf0b466cf35e13
6
+ metadata.gz: 80ac368443aac2d2c3477521c6d5a12883dbcc499aab321ed62e952e61b3d662aa22d0e6bac53f02988178140628d87ed1ce57afcc3881e2c43eb366aa58f69a
7
+ data.tar.gz: c417f1d156158991fd39dbcb380cddb3ad09cc4244e9a136c484a63178d281e7e987b17982e9687eaee0b414efcc4de99dbe110287752ec2e7e5bf8ead9d3fce
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 = KktShoppe::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>"
@@ -0,0 +1,48 @@
1
+ module KktShoppe
2
+ class Attachment < ActiveRecord::Base
3
+
4
+ # Set the table name
5
+ self.table_name = "kkt_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 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 => "KktShoppe::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 => "KktShoppe::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,29 @@
1
+ # encoding: utf-8
2
+
3
+ class KktShoppe::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
@@ -166,7 +166,7 @@ class CreateKktShoppeInitialSchema < ActiveRecord::Migration
166
166
  t.datetime "updated_at"
167
167
  end
168
168
  end
169
-
169
+
170
170
  def down
171
171
  [:users, :tax_rates, :stock_level_adjustments, :settings, :products, :product_categories, :product_attributes, :orders, :order_items, :delivery_services, :delivery_service_prices, :countries].each do |table|
172
172
  drop_table "kkt_shoppe_#{table}"
@@ -2,4 +2,4 @@ class AddAddressTypeToKktShoppeTaxRates < ActiveRecord::Migration
2
2
  def change
3
3
  add_column :kkt_shoppe_tax_rates, :address_type, :string
4
4
  end
5
- end
5
+ end
@@ -14,12 +14,12 @@ class CreateKktShoppePayments < ActiveRecord::Migration
14
14
  remove_column :kkt_shoppe_orders, :paid_at
15
15
  remove_column :kkt_shoppe_orders, :payment_reference
16
16
  remove_column :kkt_shoppe_orders, :payment_method
17
-
17
+
18
18
  add_column :kkt_shoppe_orders, :amount_paid, :decimal, :precision => 8, :scale => 2, :default => 0.0
19
19
  add_column :kkt_shoppe_orders, :exported, :boolean, :default => false
20
20
  add_column :kkt_shoppe_orders, :invoice_number, :string
21
21
  end
22
-
22
+
23
23
  def down
24
24
  drop_table :kkt_shoppe_payments
25
25
  add_column :kkt_shoppe_orders, :paid_at, :datetime
@@ -29,4 +29,4 @@ class CreateKktShoppePayments < ActiveRecord::Migration
29
29
  remove_column :kkt_shoppe_orders, :exported
30
30
  remove_column :kkt_shoppe_orders, :invoice_number
31
31
  end
32
- end
32
+ end
@@ -2,4 +2,4 @@ class AddCustomerToKktShoppeOrders < ActiveRecord::Migration
2
2
  def change
3
3
  add_column :kkt_shoppe_orders, :customer_id, :integer
4
4
  end
5
- end
5
+ end
@@ -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
@@ -41,6 +41,11 @@ module KktShoppe
41
41
  require 'kkt_shoppe/view_helpers'
42
42
  ActionView::Base.send :include, KktShoppe::ViewHelpers
43
43
  end
44
+
45
+ ActiveSupport.on_load(:active_record) do
46
+ require 'kkt_shoppe/model_extension'
47
+ ActiveRecord::Base.send :include, KktShoppe::ModelExtension
48
+ end
44
49
 
45
50
  # Load default navigation
46
51
  require 'kkt_shoppe/default_navigation'
@@ -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.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/kkt_shoppe.rb CHANGED
@@ -10,50 +10,50 @@ 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
18
-
18
+
19
19
  # The path to the root of the KktShoppe applicatinio
20
20
  #
21
21
  # @return [String]
22
22
  def root
23
23
  File.expand_path('../../', __FILE__)
24
24
  end
25
-
25
+
26
26
  # KktShoppe settings as configured in the database
27
27
  #
28
28
  # @return [KktShoppe::Settings]
29
29
  def settings
30
30
  Thread.current[:kkt_shoppe_settings] ||= KktShoppe::Settings.new(KktShoppe::Setting.to_hash)
31
31
  end
32
-
32
+
33
33
  # Clears the settings from the thread cache so they will be taken
34
34
  # from the database on next access
35
- #
35
+ #
36
36
  # @return [NilClass]
37
37
  def reset_settings
38
38
  Thread.current[:kkt_shoppe_settings] = nil
39
39
  end
40
-
41
- # Defines a new set of settings which should be configrable from the settings page
40
+
41
+ # Defines a new set of settings which should be configrable from the settings page
42
42
  # in the KktShoppe UI.
43
43
  def add_settings_group(group, fields = [])
44
44
  settings_groups[group] ||= []
45
45
  settings_groups[group] = settings_groups[group] | fields
46
46
  end
47
-
47
+
48
48
  # All settings groups which are available for configuration on the settings page.
49
49
  #
50
50
  # @return [Hash]
51
51
  def settings_groups
52
52
  @settings_groups ||= {}
53
53
  end
54
-
54
+
55
55
  end
56
-
56
+
57
57
  end
58
58
 
59
59
  # Start your engines.
@@ -1,9 +1,10 @@
1
1
  namespace :kkt_shoppe do
2
+
2
3
  desc "Load seed data for the KktShoppe"
3
4
  task :seed => :environment do
4
5
  require File.join(KktShoppe.root, 'db', 'seeds')
5
6
  end
6
-
7
+
7
8
  desc "Create a default admin user"
8
9
  task :create_default_user => :environment do
9
10
  KktShoppe::User.create(:email_address => 'admin@example.com', :password => 'password', :password_confirmation => 'password', :first_name => 'Default', :last_name => 'Admin')
@@ -14,16 +15,39 @@ namespace :kkt_shoppe do
14
15
  puts " Password........: password"
15
16
  puts
16
17
  end
17
-
18
+
18
19
  desc "Import default set of countries"
19
20
  task :import_countries => :environment do
20
21
  KktShoppe::CountryImporter.import
21
22
  end
22
-
23
+
23
24
  desc "Run the key setup tasks for a new application"
24
25
  task :setup => :environment do
25
26
  Rake::Task["kkt_shoppe:import_countries"].invoke if KktShoppe::Country.all.empty?
26
27
  Rake::Task["kkt_shoppe:create_default_user"].invoke if KktShoppe::User.all.empty?
27
28
  end
28
-
29
- end
29
+
30
+ desc "Converts nifty-attachment attachments to KktShoppe 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
52
+
53
+ end
metadata CHANGED
@@ -1,10 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kkt_shoppe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Kyle Thompson, Adam Cooke
7
+ - Kyle Thompson
8
+ - Adam Cooke
9
+ - Dean Perry
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
@@ -416,6 +418,8 @@ description: A full Rails engine providing e-commerce functionality for any Rail
416
418
  4 application.
417
419
  email:
418
420
  - kyle@kylekthompson.com
421
+ - adam@atechmedia.com
422
+ - dean@voupe.com
419
423
  executables: []
420
424
  extensions: []
421
425
  extra_rdoc_files: []
@@ -500,6 +504,7 @@ files:
500
504
  - app/mailers/kkt_shoppe/order_mailer.rb
501
505
  - app/mailers/kkt_shoppe/user_mailer.rb
502
506
  - app/models/kkt_shoppe/address.rb
507
+ - app/models/kkt_shoppe/attachment.rb
503
508
  - app/models/kkt_shoppe/country.rb
504
509
  - app/models/kkt_shoppe/customer.rb
505
510
  - app/models/kkt_shoppe/delivery_service.rb
@@ -521,6 +526,7 @@ files:
521
526
  - app/models/kkt_shoppe/stock_level_adjustment.rb
522
527
  - app/models/kkt_shoppe/tax_rate.rb
523
528
  - app/models/kkt_shoppe/user.rb
529
+ - app/uploaders/kkt_shoppe/attachment_uploader.rb
524
530
  - app/validators/permalink_validator.rb
525
531
  - app/views/kkt_shoppe/addresses/_form.html.haml
526
532
  - app/views/kkt_shoppe/addresses/edit.html.haml
@@ -619,6 +625,7 @@ files:
619
625
  - db/migrate/20141026181718_add_nested_to_product_categories.rb
620
626
  - db/migrate/20141027215005_create_kkt_shoppe_addresses.rb
621
627
  - db/migrate/20150315215633_add_customer_to_kkt_shoppe_orders.rb
628
+ - db/migrate/20150315223628_create_kkt_shoppe_attachments.rb
622
629
  - db/migrate/20150513171350_create_kkt_shoppe_product_category_translation_table.rb
623
630
  - db/migrate/20150519173350_create_kkt_shoppe_product_translation_table.rb
624
631
  - db/schema.rb
@@ -649,6 +656,7 @@ files:
649
656
  - lib/kkt_shoppe/errors/payment_declined.rb
650
657
  - lib/kkt_shoppe/errors/refund_failed.rb
651
658
  - lib/kkt_shoppe/errors/unorderable_item.rb
659
+ - lib/kkt_shoppe/model_extension.rb
652
660
  - lib/kkt_shoppe/navigation_manager.rb
653
661
  - lib/kkt_shoppe/orderable_item.rb
654
662
  - lib/kkt_shoppe/settings.rb