shoperb-theme-editor 0.8.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 +7 -0
- data/CONTRIBUTING.md +40 -0
- data/LICENSE.md +21 -0
- data/README.md +124 -0
- data/bin/shoperb +313 -0
- data/lib/shoperb_theme_editor/api/server.rb +10 -0
- data/lib/shoperb_theme_editor/api/views/callback.erb +53 -0
- data/lib/shoperb_theme_editor/api.rb +264 -0
- data/lib/shoperb_theme_editor/build/json.rb +167 -0
- data/lib/shoperb_theme_editor/build/liquid.rb +38 -0
- data/lib/shoperb_theme_editor/build/section.rb +51 -0
- data/lib/shoperb_theme_editor/build/settings.rb +224 -0
- data/lib/shoperb_theme_editor/build.rb +68 -0
- data/lib/shoperb_theme_editor/configuration.rb +98 -0
- data/lib/shoperb_theme_editor/error.rb +35 -0
- data/lib/shoperb_theme_editor/ext/array.rb +17 -0
- data/lib/shoperb_theme_editor/ext/nil_class.rb +7 -0
- data/lib/shoperb_theme_editor/ext/sequel.rb +82 -0
- data/lib/shoperb_theme_editor/ext.rb +2 -0
- data/lib/shoperb_theme_editor/init.rb +87 -0
- data/lib/shoperb_theme_editor/logger.rb +58 -0
- data/lib/shoperb_theme_editor/mounter/models/address.rb +65 -0
- data/lib/shoperb_theme_editor/mounter/models/attribute.rb +11 -0
- data/lib/shoperb_theme_editor/mounter/models/attribute_key.rb +17 -0
- data/lib/shoperb_theme_editor/mounter/models/base.rb +196 -0
- data/lib/shoperb_theme_editor/mounter/models/blog_category.rb +47 -0
- data/lib/shoperb_theme_editor/mounter/models/blog_post.rb +45 -0
- data/lib/shoperb_theme_editor/mounter/models/brand.rb +11 -0
- data/lib/shoperb_theme_editor/mounter/models/cart.rb +35 -0
- data/lib/shoperb_theme_editor/mounter/models/cart_item.rb +71 -0
- data/lib/shoperb_theme_editor/mounter/models/category.rb +99 -0
- data/lib/shoperb_theme_editor/mounter/models/collection.rb +40 -0
- data/lib/shoperb_theme_editor/mounter/models/country.rb +18 -0
- data/lib/shoperb_theme_editor/mounter/models/currency.rb +17 -0
- data/lib/shoperb_theme_editor/mounter/models/custom_field.rb +22 -0
- data/lib/shoperb_theme_editor/mounter/models/customer.rb +77 -0
- data/lib/shoperb_theme_editor/mounter/models/customer_customer_group.rb +12 -0
- data/lib/shoperb_theme_editor/mounter/models/customer_group.rb +13 -0
- data/lib/shoperb_theme_editor/mounter/models/customer_subscription.rb +40 -0
- data/lib/shoperb_theme_editor/mounter/models/customer_subscription_plan.rb +32 -0
- data/lib/shoperb_theme_editor/mounter/models/discount.rb +40 -0
- data/lib/shoperb_theme_editor/mounter/models/discount_variant.rb +15 -0
- data/lib/shoperb_theme_editor/mounter/models/image.rb +51 -0
- data/lib/shoperb_theme_editor/mounter/models/language.rb +17 -0
- data/lib/shoperb_theme_editor/mounter/models/link.rb +61 -0
- data/lib/shoperb_theme_editor/mounter/models/media_file.rb +19 -0
- data/lib/shoperb_theme_editor/mounter/models/menu.rb +21 -0
- data/lib/shoperb_theme_editor/mounter/models/meta.rb +10 -0
- data/lib/shoperb_theme_editor/mounter/models/news_item.rb +11 -0
- data/lib/shoperb_theme_editor/mounter/models/order.rb +133 -0
- data/lib/shoperb_theme_editor/mounter/models/order_item.rb +137 -0
- data/lib/shoperb_theme_editor/mounter/models/order_item_attribute.rb +17 -0
- data/lib/shoperb_theme_editor/mounter/models/order_return.rb +42 -0
- data/lib/shoperb_theme_editor/mounter/models/order_return_item.rb +29 -0
- data/lib/shoperb_theme_editor/mounter/models/order_return_item_entity.rb +25 -0
- data/lib/shoperb_theme_editor/mounter/models/order_return_parcel.rb +20 -0
- data/lib/shoperb_theme_editor/mounter/models/page.rb +26 -0
- data/lib/shoperb_theme_editor/mounter/models/payment_card.rb +21 -0
- data/lib/shoperb_theme_editor/mounter/models/payment_method.rb +67 -0
- data/lib/shoperb_theme_editor/mounter/models/payment_provider.rb +23 -0
- data/lib/shoperb_theme_editor/mounter/models/product.rb +144 -0
- data/lib/shoperb_theme_editor/mounter/models/product_attribute.rb +32 -0
- data/lib/shoperb_theme_editor/mounter/models/product_search.rb +53 -0
- data/lib/shoperb_theme_editor/mounter/models/product_type.rb +21 -0
- data/lib/shoperb_theme_editor/mounter/models/review.rb +38 -0
- data/lib/shoperb_theme_editor/mounter/models/search.rb +11 -0
- data/lib/shoperb_theme_editor/mounter/models/shipping_method.rb +39 -0
- data/lib/shoperb_theme_editor/mounter/models/shop.rb +58 -0
- data/lib/shoperb_theme_editor/mounter/models/state.rb +17 -0
- data/lib/shoperb_theme_editor/mounter/models/theme.rb +89 -0
- data/lib/shoperb_theme_editor/mounter/models/variant.rb +96 -0
- data/lib/shoperb_theme_editor/mounter/models/variant_attribute.rb +46 -0
- data/lib/shoperb_theme_editor/mounter/models/vendor.rb +38 -0
- data/lib/shoperb_theme_editor/mounter/server/assets.rb +35 -0
- data/lib/shoperb_theme_editor/mounter/server/defaults.rb +44 -0
- data/lib/shoperb_theme_editor/mounter/server/exception_handler.rb +22 -0
- data/lib/shoperb_theme_editor/mounter/server/partials/_shoperb_footer.liquid +0 -0
- data/lib/shoperb_theme_editor/mounter/server/partials/_shoperb_header.liquid +0 -0
- data/lib/shoperb_theme_editor/mounter/server/partials/_shoperb_stylesheets.liquid +3 -0
- data/lib/shoperb_theme_editor/mounter/server/renderer.rb +166 -0
- data/lib/shoperb_theme_editor/mounter/server/routes/cart.rb +127 -0
- data/lib/shoperb_theme_editor/mounter/server/routes/dummy.rb +34 -0
- data/lib/shoperb_theme_editor/mounter/server/routes/locale.rb +31 -0
- data/lib/shoperb_theme_editor/mounter/server/routes/pages.rb +33 -0
- data/lib/shoperb_theme_editor/mounter/server/routes/search.rb +18 -0
- data/lib/shoperb_theme_editor/mounter/server/routes.rb +366 -0
- data/lib/shoperb_theme_editor/mounter/server/routes_helper.rb +278 -0
- data/lib/shoperb_theme_editor/mounter/server.rb +66 -0
- data/lib/shoperb_theme_editor/mounter.rb +30 -0
- data/lib/shoperb_theme_editor/os.rb +13 -0
- data/lib/shoperb_theme_editor/package.rb +81 -0
- data/lib/shoperb_theme_editor/sync/images.rb +69 -0
- data/lib/shoperb_theme_editor/sync/pagination.rb +52 -0
- data/lib/shoperb_theme_editor/sync.rb +229 -0
- data/lib/shoperb_theme_editor/translations.rb +22 -0
- data/lib/shoperb_theme_editor/utils.rb +50 -0
- data/lib/shoperb_theme_editor.rb +159 -0
- data/shoperb_theme_editor.gemspec +60 -0
- metadata +510 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class Customer < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :last_bill_address_id, :last_ship_address_id,
|
9
|
+
:first_name, :last_name, :email, :newsletter, :active,
|
10
|
+
:discount_pct, :recommended_products_ids
|
11
|
+
c_fields :company, cast: TrueClass
|
12
|
+
|
13
|
+
|
14
|
+
def name
|
15
|
+
"#{first_name} #{last_name}".strip
|
16
|
+
end
|
17
|
+
|
18
|
+
def last_bill_address
|
19
|
+
Address.all.detect { |address| attributes[:last_bill_address_id] == address.attributes[:id] }
|
20
|
+
end
|
21
|
+
|
22
|
+
def last_ship_address
|
23
|
+
Address.all.detect { |address| attributes[:last_ship_address_id] == address.attributes[:id] }
|
24
|
+
end
|
25
|
+
|
26
|
+
def addresses
|
27
|
+
check = { owner_type: "Customer", owner_id: attributes[:id] }.with_indifferent_access
|
28
|
+
Address.all.select { |address|
|
29
|
+
address.attributes.slice(:owner_type, :owner_id).with_indifferent_access == check
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def customer_groups
|
34
|
+
CustomerGroup.where(customer_ids: /[\[,]#{id}[,\]]/)
|
35
|
+
end
|
36
|
+
|
37
|
+
def orders
|
38
|
+
Order.dataset
|
39
|
+
end
|
40
|
+
|
41
|
+
def credits
|
42
|
+
[]
|
43
|
+
end
|
44
|
+
|
45
|
+
def recommended_products
|
46
|
+
possible = attributes.fetch(:recommended_products_ids, []).map(&:to_s)
|
47
|
+
Product.active.select { |product| possible.include?(product.attributes[:id].to_s) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def purchased_variant?(variant)
|
51
|
+
[true, false].sample
|
52
|
+
end
|
53
|
+
|
54
|
+
def existing_order_returns
|
55
|
+
OrderReturn.dataset
|
56
|
+
end
|
57
|
+
|
58
|
+
def order_returns
|
59
|
+
new_order_returns
|
60
|
+
end
|
61
|
+
|
62
|
+
def new_order_returns
|
63
|
+
order = Order.last
|
64
|
+
{order.id => order}
|
65
|
+
end
|
66
|
+
|
67
|
+
def not_returned_items
|
68
|
+
0
|
69
|
+
end
|
70
|
+
|
71
|
+
def subscriptions
|
72
|
+
CustomerSubscription.dataset
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end end end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class CustomerGroup < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id,:name,:handle, :customer_customer_group_ids, :customer_ids
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end end end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Shoperb module Theme module Editor
|
3
|
+
module Mounter
|
4
|
+
module Model
|
5
|
+
class CustomerSubscription < Sequel::Model
|
6
|
+
extend Base::SequelClass
|
7
|
+
include Base::Sequel
|
8
|
+
|
9
|
+
fields :id, :plan_id, :customer_id, :auto_collection, :state, :qty,
|
10
|
+
:starts_at, :ends_at, :trial_starts_at, :trial_ends_at,
|
11
|
+
:gift_card_code
|
12
|
+
|
13
|
+
def self.primary_key
|
14
|
+
:id
|
15
|
+
end
|
16
|
+
|
17
|
+
belongs_to :plan, class_name: CustomerSubscriptionPlan.to_s, foreign_key: :plan_id
|
18
|
+
belongs_to :customer
|
19
|
+
|
20
|
+
|
21
|
+
def active?
|
22
|
+
state == "active"
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.active
|
26
|
+
all
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_liquid context=nil
|
30
|
+
if klass = (ShoperbLiquid.const_get("SubscriptionDrop"))
|
31
|
+
klass.new(self).tap do |drop|
|
32
|
+
drop.context = context if context
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end end end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class CustomerSubscriptionPlan < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :name, :invoice_name, :description, :handle, :interval,
|
9
|
+
:interval_count, :item_price, :setup_cost, :trial_interval, :trial_interval_count
|
10
|
+
|
11
|
+
translates :name, :invoice_name, :description
|
12
|
+
|
13
|
+
def self.primary_key
|
14
|
+
:id
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.active
|
18
|
+
all
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_liquid context=nil
|
22
|
+
if klass = (ShoperbLiquid.const_get("SubscriptionPlanDrop"))
|
23
|
+
klass.new(self).tap do |drop|
|
24
|
+
drop.context = context if context
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end end end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class Discount < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :name, :code, :type, :status, :minimum_order_amount, :target_type,
|
9
|
+
:start_date, :end_date, :amount, :region_specific, :shipping_region_ids
|
10
|
+
|
11
|
+
def self.primary_key
|
12
|
+
:id
|
13
|
+
end
|
14
|
+
|
15
|
+
has_many :discount_variants
|
16
|
+
|
17
|
+
def variants
|
18
|
+
discount_variants.map(&:variant)
|
19
|
+
end
|
20
|
+
class << self
|
21
|
+
def assign records
|
22
|
+
super
|
23
|
+
|
24
|
+
count = 1
|
25
|
+
discs_variants=records.each_with_object([]){|r,a|
|
26
|
+
next if r["target_type"]!="variants"
|
27
|
+
r["target_ids"].each do |variant_id|
|
28
|
+
a << {"id"=> count, "discount_id"=> r["id"], "variant_id"=> variant_id}
|
29
|
+
count+=1
|
30
|
+
end
|
31
|
+
}
|
32
|
+
Mounter::Model::DiscountVariant.assign(discs_variants)
|
33
|
+
|
34
|
+
records
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end end end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class DiscountVariant < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :discount_id, :variant_id
|
9
|
+
|
10
|
+
belongs_to :discount
|
11
|
+
belongs_to :variant
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end end end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class Image < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :entity_id, :entity_type, :name,
|
9
|
+
:url, :original_width, :original_height
|
10
|
+
c_fields :sizes, cast: JSON
|
11
|
+
|
12
|
+
def self.sorted
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
dataset_module do
|
17
|
+
def for(obj)
|
18
|
+
where(entity_type: obj.class.name.split("::")[-1], entity_id: obj.id)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# todo: TODOREF2
|
23
|
+
# nothing to use as primary_key besides id right now
|
24
|
+
# def self.primary_key
|
25
|
+
# :name
|
26
|
+
# end
|
27
|
+
# todo: TODOREF2 end
|
28
|
+
|
29
|
+
def self.image_size instance, name, url
|
30
|
+
Struct.new(:name, :url) do |klass|
|
31
|
+
def klass.method_missing name, *args, &block
|
32
|
+
instance.send(name, *args, &block)
|
33
|
+
end
|
34
|
+
end.new(name, url)
|
35
|
+
end
|
36
|
+
|
37
|
+
def entity
|
38
|
+
@entity ||= (Model.const_get(entity_type, false) rescue nil).try { |klass|
|
39
|
+
klass.all.detect { |obj| obj.attributes[:id] == entity_id }
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def image_sizes
|
44
|
+
@image_sizes ||= sizes.map do |name, url|
|
45
|
+
self.class.image_size(self, name, "/#{Editor["oauth-site"]}/images/#{id}/#{url}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end end end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class Language < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :code, :name, :native, :active
|
9
|
+
|
10
|
+
def self.primary_key
|
11
|
+
:code
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end end end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class Link < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :entity_id, :parent_id, :entity_type, :style, :name, :menu_id,
|
9
|
+
:value, :handle, :position, :translations
|
10
|
+
|
11
|
+
translates :name, :description
|
12
|
+
|
13
|
+
def self.primary_key
|
14
|
+
:handle
|
15
|
+
end
|
16
|
+
belongs_to :menu
|
17
|
+
|
18
|
+
def parent
|
19
|
+
@parent ||= Link.all.detect { |parent| parent.attributes[:id] == self.parent_id }
|
20
|
+
end
|
21
|
+
|
22
|
+
def children
|
23
|
+
@children ||= Link.all.select { |child| child.parent_id == attributes[:id] }
|
24
|
+
end
|
25
|
+
|
26
|
+
def entity
|
27
|
+
return unless entity_type && entity_id
|
28
|
+
klass = Model.const_get(entity_type)
|
29
|
+
scope = if klass.respond_to?(:active)
|
30
|
+
klass.active
|
31
|
+
else
|
32
|
+
klass.all
|
33
|
+
end
|
34
|
+
scope.detect { |object| object.attributes[:id] == entity_id }
|
35
|
+
end
|
36
|
+
|
37
|
+
def index_action?
|
38
|
+
style.downcase == style.downcase.pluralize
|
39
|
+
end
|
40
|
+
|
41
|
+
def path(*args)
|
42
|
+
return '' unless style
|
43
|
+
|
44
|
+
responder = args[0][:responder]
|
45
|
+
path = "store_#{style.underscore}_path"
|
46
|
+
|
47
|
+
case style
|
48
|
+
when "CUSTOM"
|
49
|
+
value
|
50
|
+
when "HOME"
|
51
|
+
responder.store_root_path
|
52
|
+
when "SEARCH"
|
53
|
+
responder.store_search_path
|
54
|
+
else
|
55
|
+
index_action? ? responder.send(path) : (responder.send(path, entity) if entity)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end end end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class MediaFile < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
fields :id, :filename, :extension, :mime, :url, :image
|
8
|
+
|
9
|
+
def filename
|
10
|
+
attributes[:filename]
|
11
|
+
end
|
12
|
+
|
13
|
+
def handle
|
14
|
+
filename
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end end end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class Menu < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :name, :handle, :editable, :translations
|
9
|
+
|
10
|
+
translates :name
|
11
|
+
|
12
|
+
def self.primary_key
|
13
|
+
:id
|
14
|
+
end
|
15
|
+
|
16
|
+
has_many :links
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end end end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class Order < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :number, :token, :email, :total, :subtotal,
|
9
|
+
:total_shipping, :total_taxes,
|
10
|
+
:created_at, :state, :notes, :ship_address_id,
|
11
|
+
:bill_address_id; :taxation_percentage
|
12
|
+
c_fields :require_shipping, :require_taxation, cast: TrueClass
|
13
|
+
c_fields :neto_discount, :bruto_discount, cast: BigDecimal
|
14
|
+
|
15
|
+
def self.primary_key
|
16
|
+
:number
|
17
|
+
end
|
18
|
+
|
19
|
+
# has_one :shipping_method
|
20
|
+
def shipping_method
|
21
|
+
@shipping_method ||= ShippingMethod.sample
|
22
|
+
end
|
23
|
+
|
24
|
+
def ship_address
|
25
|
+
#Address.all.detect { |address| address.attributes[:id] == self.ship_address_id }
|
26
|
+
@ship_address ||= Address.sample # as we use custom data
|
27
|
+
end
|
28
|
+
|
29
|
+
def bill_address
|
30
|
+
# Address.all.detect { |address| address.attributes[:id] == self.bill_address_id }
|
31
|
+
@bill_address ||= Address.sample # as we use custom data
|
32
|
+
end
|
33
|
+
|
34
|
+
def items
|
35
|
+
# OrderItem.all.select { |item| item.attributes[:order_number] == self.id }
|
36
|
+
OrderItem.all.map{|oi| oi.order=self;oi}
|
37
|
+
end
|
38
|
+
|
39
|
+
def shipping_items
|
40
|
+
items.map{|i| ShoperbLiquid::ShippingItemDrop.new(i)}
|
41
|
+
end
|
42
|
+
|
43
|
+
def refunds
|
44
|
+
[
|
45
|
+
ShoperbLiquid::RefundDrop.new(OpenStruct.new(
|
46
|
+
state: "initial", amount: 30.to_d, reason: "Other",
|
47
|
+
refund_items: items.map{|i| ShoperbLiquid::RefundItemDrop.new(OpenStruct.new(count: i.amount, order_item_id: i.id, order_item: i, id: i.id))}
|
48
|
+
))
|
49
|
+
]
|
50
|
+
end
|
51
|
+
|
52
|
+
# belongs_to :payment_method
|
53
|
+
def payment_method
|
54
|
+
@payment_method ||= PaymentMethod.sample
|
55
|
+
end
|
56
|
+
|
57
|
+
# belongs_to :customer
|
58
|
+
def customer
|
59
|
+
@customer ||= Customer.sample
|
60
|
+
end
|
61
|
+
|
62
|
+
# belongs_to :currency
|
63
|
+
def currency
|
64
|
+
@currency ||= Currency.sample
|
65
|
+
end
|
66
|
+
|
67
|
+
def subtotal_wo_discount
|
68
|
+
subtotal
|
69
|
+
end
|
70
|
+
|
71
|
+
def total_wo_discount
|
72
|
+
total
|
73
|
+
end
|
74
|
+
|
75
|
+
def checkout
|
76
|
+
self
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.sorted
|
80
|
+
all
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.had_subscription
|
84
|
+
all
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.raw_data
|
88
|
+
500.times.map do |i|
|
89
|
+
{
|
90
|
+
id: 1000 + i,
|
91
|
+
number: "00#{i+1}",
|
92
|
+
token: "a0f4add16292d40806ffccb6452a168a17768",
|
93
|
+
email: "mail@shoperb.com",
|
94
|
+
total: 0.2001e4,
|
95
|
+
subtotal: 0.165372e4,
|
96
|
+
total_shipping: 0.0,
|
97
|
+
total_taxes: 0.347281e3,
|
98
|
+
require_shipping: true,
|
99
|
+
require_taxation: true,
|
100
|
+
created_at: Time.parse("2019-05-23 11:59:50 UTC"),
|
101
|
+
state: "new",
|
102
|
+
notes: "", # possible nil
|
103
|
+
ship_address_id: 104184, # possible nil
|
104
|
+
bill_address_id: 104183, # possible nil
|
105
|
+
taxation_percentage: "42",
|
106
|
+
neto_discount: 1,
|
107
|
+
bruto_discount: 2,
|
108
|
+
}
|
109
|
+
end.unshift({
|
110
|
+
id: 100,
|
111
|
+
number: "v01",
|
112
|
+
token: "varianted-92d40806ffccb6452a168a17768",
|
113
|
+
email: "mail@shoperb.com",
|
114
|
+
total: 0.2001e4,
|
115
|
+
subtotal: 0.165372e4,
|
116
|
+
total_shipping: 0.0,
|
117
|
+
total_taxes: 0.347281e3,
|
118
|
+
require_shipping: true,
|
119
|
+
require_taxation: true,
|
120
|
+
created_at: Time.parse("2019-05-23 11:59:50 UTC"),
|
121
|
+
state: "new",
|
122
|
+
notes: "", # possible nil
|
123
|
+
ship_address_id: 104184, # possible nil
|
124
|
+
bill_address_id: 104183, # possible nil
|
125
|
+
taxation_percentage: "42",
|
126
|
+
neto_discount: 1,
|
127
|
+
bruto_discount: 2,
|
128
|
+
})
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end end end
|