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,137 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class OrderItem < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
fields :id, :name, :sku
|
8
|
+
c_fields :order_id, :item_original_id, cast: Integer
|
9
|
+
c_fields :require_shipping, :charge_taxes, :brand_id, cast: TrueClass
|
10
|
+
c_fields :by_subscription, :digital, cast: TrueClass
|
11
|
+
c_fields :amount, :amount_step,:amount_step_unit, cast: BigDecimal
|
12
|
+
c_fields :weight, :width, :depth, cast: BigDecimal
|
13
|
+
c_fields :total_weight, :total_taxes, cast: BigDecimal
|
14
|
+
c_fields :price, :total_without_taxes, :total_wout_correlation, cast: BigDecimal
|
15
|
+
|
16
|
+
belongs_to :order
|
17
|
+
has_many :item_attributes, class_name: OrderItemAttribute.to_s
|
18
|
+
|
19
|
+
def order
|
20
|
+
Order.first
|
21
|
+
end
|
22
|
+
|
23
|
+
def digital?
|
24
|
+
digital
|
25
|
+
end
|
26
|
+
|
27
|
+
def category
|
28
|
+
@category ||= [Category.first, nil].sample
|
29
|
+
end
|
30
|
+
|
31
|
+
def product
|
32
|
+
@product ||= [Product.first, nil].sample
|
33
|
+
end
|
34
|
+
|
35
|
+
def variant
|
36
|
+
return @variant if defined?(@variant)
|
37
|
+
|
38
|
+
@variant = if order&.token.start_with?("varianted")
|
39
|
+
Variant.all.sample
|
40
|
+
else
|
41
|
+
[Variant.first, nil].sample
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def brand
|
46
|
+
Vendor.find(id: brand_id) if brand_id
|
47
|
+
end
|
48
|
+
|
49
|
+
def order_item
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
def item_attributes
|
54
|
+
variant&.variant_attributes || []
|
55
|
+
end
|
56
|
+
|
57
|
+
def url
|
58
|
+
variant&.url
|
59
|
+
end
|
60
|
+
|
61
|
+
def product_id
|
62
|
+
product&.id || 3
|
63
|
+
end
|
64
|
+
|
65
|
+
def variant_id
|
66
|
+
variant&.id || 4
|
67
|
+
end
|
68
|
+
|
69
|
+
def created_at
|
70
|
+
Time.now - 3600
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.raw_data
|
74
|
+
[
|
75
|
+
{
|
76
|
+
id: 1,
|
77
|
+
name: "Subscriptional product",
|
78
|
+
amount: 1,
|
79
|
+
sku: nil,
|
80
|
+
weight: nil,
|
81
|
+
width: nil,
|
82
|
+
height: nil,
|
83
|
+
depth: nil,
|
84
|
+
price: 0.11e3,
|
85
|
+
total_without_taxes: 0.11e3,
|
86
|
+
total_wout_correlation: 0.132e3,
|
87
|
+
total_weight: 0,
|
88
|
+
total_taxes: 0.22e2,
|
89
|
+
digital: true,
|
90
|
+
download_url: "http://shoperb.com/store_checkout_download_url",
|
91
|
+
charge_taxes: true,
|
92
|
+
by_subscription: true,
|
93
|
+
},
|
94
|
+
{
|
95
|
+
id: 2,
|
96
|
+
name: "ProductForGA",
|
97
|
+
amount: 1,
|
98
|
+
sku: nil,
|
99
|
+
weight: nil,
|
100
|
+
width: nil,
|
101
|
+
height: nil,
|
102
|
+
depth: nil,
|
103
|
+
price: 0.11e3,
|
104
|
+
total_without_taxes: 0.11e3,
|
105
|
+
total_wout_correlation: 0.132e3,
|
106
|
+
total_weight: 0,
|
107
|
+
total_taxes: 0.22e2,
|
108
|
+
digital: true,
|
109
|
+
download_url: "http://shoperb.com/store_checkout_download_url",
|
110
|
+
charge_taxes: true,
|
111
|
+
by_subscription: false,
|
112
|
+
},
|
113
|
+
{
|
114
|
+
id: 3,
|
115
|
+
name: "ProductForGA 2",
|
116
|
+
amount: 2,
|
117
|
+
sku: "3213-1111",
|
118
|
+
weight: 1,
|
119
|
+
width: 2,
|
120
|
+
height: 3,
|
121
|
+
depth: 4,
|
122
|
+
price: 0.22e3,
|
123
|
+
total_without_taxes: 0.22e3,
|
124
|
+
total_wout_correlation: 0.232e3,
|
125
|
+
total_weight: 2,
|
126
|
+
total_taxes: 0.22e2,
|
127
|
+
digital: false,
|
128
|
+
download_url: nil,
|
129
|
+
charge_taxes: true,
|
130
|
+
by_subscription: false
|
131
|
+
}
|
132
|
+
]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end end end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class OrderItemAttribute < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
# todo: TODOREF2
|
8
|
+
def self.from_variant
|
9
|
+
all
|
10
|
+
end
|
11
|
+
def self.from_product
|
12
|
+
all
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end end end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Shoperb module Theme module Editor
|
3
|
+
module Mounter
|
4
|
+
module Model
|
5
|
+
class OrderReturn < Sequel::Model
|
6
|
+
extend Base::SequelClass
|
7
|
+
include Base::Sequel
|
8
|
+
fields :id, :delivery_date, :comment, :state, :subtotal, :created_at
|
9
|
+
|
10
|
+
dataset_module do
|
11
|
+
def by_id(dir)
|
12
|
+
list = sort_by(&:id)
|
13
|
+
dir == "desc" ? list.reverse : list
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def items
|
18
|
+
OrderReturnItem.all
|
19
|
+
end
|
20
|
+
|
21
|
+
def return_parcel
|
22
|
+
[OrderReturnParcel.first, nil].sample
|
23
|
+
end
|
24
|
+
|
25
|
+
def labeled_number
|
26
|
+
"R-#{id}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.raw_data
|
30
|
+
[
|
31
|
+
{id: 1, delivery_date: "", comment: "", state: "pending", created_at: Time.now},
|
32
|
+
{id: 2, delivery_date: nil, comment: nil, state: "pending", created_at: Time.now - 3600},
|
33
|
+
{id: 3, delivery_date: Time.now+3.days, comment: "Sending back via Omniva", state: "sending", created_at: Time.now},
|
34
|
+
{id: 4, delivery_date: Time.now+5.days, comment: "Sending back via Posti", state: "in_transit", created_at: Time.now},
|
35
|
+
{id: 5, delivery_date: Time.now+1.days, comment: "Sending back via Posti", state: "receiving", created_at: Time.now},
|
36
|
+
{id: 6, delivery_date: Time.now-1.days, comment: "Sending back via Omniva", state: "received", created_at: Time.now},
|
37
|
+
]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end end end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Shoperb module Theme module Editor
|
3
|
+
module Mounter
|
4
|
+
module Model
|
5
|
+
class OrderReturnItem < Sequel::Model
|
6
|
+
extend Base::SequelClass
|
7
|
+
include Base::Sequel
|
8
|
+
fields :id, :amount
|
9
|
+
|
10
|
+
def order_item
|
11
|
+
OrderItem.first
|
12
|
+
end
|
13
|
+
|
14
|
+
def entities
|
15
|
+
OrderReturnItemEntity.all
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.raw_data
|
19
|
+
[
|
20
|
+
{id:1, amount: 0 },
|
21
|
+
{id:2, amount: 0 },
|
22
|
+
{id:3, amount: 0 },
|
23
|
+
{id:4, amount: 3 },
|
24
|
+
]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end end end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Shoperb module Theme module Editor
|
3
|
+
module Mounter
|
4
|
+
module Model
|
5
|
+
class OrderReturnItemEntity < Sequel::Model
|
6
|
+
extend Base::SequelClass
|
7
|
+
include Base::Sequel
|
8
|
+
fields :id, :customer_comment
|
9
|
+
|
10
|
+
def order_item
|
11
|
+
OrderItem.first
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.raw_data
|
15
|
+
[
|
16
|
+
{id:1, customer_comment: "Lorem impsum" },
|
17
|
+
{id:2, customer_comment: "Came broken" },
|
18
|
+
{id:3, customer_comment: "Lost shiny surface" },
|
19
|
+
{id:4, customer_comment: "Didn't like it" },
|
20
|
+
]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end end end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Shoperb module Theme module Editor
|
3
|
+
module Mounter
|
4
|
+
module Model
|
5
|
+
class OrderReturnParcel < Sequel::Model
|
6
|
+
extend Base::SequelClass
|
7
|
+
include Base::Sequel
|
8
|
+
fields :id, :provider, :barcode, :state, :filename, :url
|
9
|
+
|
10
|
+
|
11
|
+
def self.raw_data
|
12
|
+
[
|
13
|
+
{id: 1, provider: "royalmail_uk", barcode: "qqqqaaaa", state: "uploaded", filename: '628x800.png', url: "https://via.placeholder.com/628x800.png?text=Here+will+be+shipping+label"},
|
14
|
+
{id: 2, provider: "custom", barcode: nil, state: "local", filename: nil, url: "/system/stock/return_parcels/20190606/2/"},
|
15
|
+
]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end end end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class Page < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :state, :name, :content, :permalink, :handle, :translations, :template
|
9
|
+
|
10
|
+
translates :name, :content
|
11
|
+
|
12
|
+
def self.primary_key
|
13
|
+
:permalink
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.active
|
17
|
+
all.select(&:active?)
|
18
|
+
end
|
19
|
+
|
20
|
+
def active?
|
21
|
+
state == "active"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end end end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class PaymentCard < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :service, :card
|
9
|
+
|
10
|
+
def self.raw_data
|
11
|
+
[{
|
12
|
+
id: 2,
|
13
|
+
service:"stripe",
|
14
|
+
card: {"name"=>nil, "brand"=>"Visa", "last4"=>"4242","country"=>"US", "exp_year"=>2022, "exp_month"=>11, "type"=>"credit"}
|
15
|
+
}]
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end end end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class PaymentMethod < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :name, :state, :invoice_instructions, :instructions
|
9
|
+
|
10
|
+
def payment_method
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def display_name
|
15
|
+
name
|
16
|
+
end
|
17
|
+
|
18
|
+
def succeed?
|
19
|
+
state == "captured"
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.raw_data
|
23
|
+
[{
|
24
|
+
id: 1,
|
25
|
+
name: "Credit card payment",
|
26
|
+
provider: "Braintree",
|
27
|
+
state: "failed",
|
28
|
+
invoice_instructions: nil,
|
29
|
+
checkout_instructions: nil,
|
30
|
+
bank_account: nil,
|
31
|
+
bank_name: nil,
|
32
|
+
bic_swift_code: nil,
|
33
|
+
},
|
34
|
+
{
|
35
|
+
id: 2,
|
36
|
+
name: "Invoice payment",
|
37
|
+
provider: "Credit Card",
|
38
|
+
state: "captured",
|
39
|
+
invoice_instructions: nil,
|
40
|
+
checkout_instructions: nil,
|
41
|
+
bank_account: nil,
|
42
|
+
bank_name: nil,
|
43
|
+
bic_swift_code: nil,
|
44
|
+
},
|
45
|
+
{
|
46
|
+
id: 3,
|
47
|
+
name: "Invoice payment",
|
48
|
+
provider: "Credit Card",
|
49
|
+
state: "captured",
|
50
|
+
invoice_instructions: "После оформления заказа в интернете на Ваш адрес электронной почты автоматически будет выслан счет для оплаты.\n
|
51
|
+
ПРЕЖДЕ ЧЕМ ОПЛАТИТЬ СЧЕТ, ДОЖДИТЕСЬ ЗВОНКА НАШЕГО АДМИНИСТРАТОРА ПО ПРОДАЖАМ.\n\n
|
52
|
+
Мы свяжемся с Вами, исползуя контактную информацию, которую указали во время оформления заказа, чтобы информаровать
|
53
|
+
Вас о времени, когда сможете получить свои заказ. Получение заказа может длится от 1-7 дней, в зависимости от того,
|
54
|
+
являэтся лы товар на складе.\n\nВ ПОЛЕ ПРИЧИНА (КОММЕНТАРИЙ) К ПЛАТЕЖУ УКАЖИТЕ НОМЕР СЧЕТА ИЛИ ЗАКАЗА (№) ! ! !\n\n
|
55
|
+
Вы можете оплатить счет в:\n\nвашем интернет-банке;\nфилиале банка",
|
56
|
+
checkout_instructions: nil,
|
57
|
+
bank_account: "Mike Billman\nLV05HAB00551000009999",
|
58
|
+
bank_name: "A/S Swedbank",
|
59
|
+
bic_swift_code: "LV05HAB0",
|
60
|
+
}
|
61
|
+
]
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end end end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class PaymentProvider < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :name, :type, :service, :public_key
|
9
|
+
|
10
|
+
def self.raw_data
|
11
|
+
[{
|
12
|
+
id: 1,
|
13
|
+
name: "Stripe",
|
14
|
+
type: "stripe",
|
15
|
+
service: "stripe",
|
16
|
+
public_key: "pk_test_JqbMzr2NvnK25D5QEEm0OlZg"
|
17
|
+
}]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end end end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class Product < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :name, :description, :has_options, :permalink,
|
9
|
+
:handle, :state, :translations, :template, :collection_ids,
|
10
|
+
:minimum_discount_price,
|
11
|
+
:maximum_discount_price, :minimum_active_price
|
12
|
+
c_fields :category_id, :vendor_id, :product_type_id, cast: Integer
|
13
|
+
c_fields :dirty_variant_attributes, cast: JSON
|
14
|
+
c_fields :grouping_tags, :related_ids, cast: JSON
|
15
|
+
|
16
|
+
translates :name, :description
|
17
|
+
|
18
|
+
attr_accessor :customer
|
19
|
+
|
20
|
+
|
21
|
+
belongs_to :product_type
|
22
|
+
alias_method :type, :product_type
|
23
|
+
|
24
|
+
belongs_to :category
|
25
|
+
|
26
|
+
belongs_to :vendor
|
27
|
+
|
28
|
+
has_many :variants
|
29
|
+
|
30
|
+
has_many :product_attributes
|
31
|
+
|
32
|
+
has_many :reviews
|
33
|
+
|
34
|
+
def self.primary_key
|
35
|
+
:id
|
36
|
+
end
|
37
|
+
|
38
|
+
dataset_module do
|
39
|
+
def active
|
40
|
+
where(state: 'active')
|
41
|
+
end
|
42
|
+
|
43
|
+
def by_name(dir)
|
44
|
+
as_dataset(sort_by(&:name))
|
45
|
+
end
|
46
|
+
|
47
|
+
def by_price(dir)
|
48
|
+
sort_by(&:minimum_price)
|
49
|
+
end
|
50
|
+
|
51
|
+
def by_created(dir)
|
52
|
+
sort_by(&:id)
|
53
|
+
end
|
54
|
+
|
55
|
+
def by_updated(dir)
|
56
|
+
sort_by(&:id)
|
57
|
+
end
|
58
|
+
|
59
|
+
def by_product_type(dir)
|
60
|
+
sort_by{|pr| pr.product_type&.name.to_s }
|
61
|
+
end
|
62
|
+
|
63
|
+
def by_tags(dir)
|
64
|
+
sort_by{|pr| pr.grouping_tags.to_s }
|
65
|
+
end
|
66
|
+
|
67
|
+
def by_sku(dir)
|
68
|
+
sort_by{|pr| pr.variants[0]&.sku.to_s }
|
69
|
+
end
|
70
|
+
|
71
|
+
def by_handle(dir)
|
72
|
+
sort_by{|pr| pr.handle.to_s }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
def self.random
|
79
|
+
all.sample
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def active?
|
84
|
+
state == "active"
|
85
|
+
end
|
86
|
+
|
87
|
+
def reviewable?(customer)
|
88
|
+
true
|
89
|
+
end
|
90
|
+
|
91
|
+
def collections
|
92
|
+
Collection.as_dataset(Collection.to_a.select { |collection| collection_ids.to_a.include?(collection.attributes[:id]) })
|
93
|
+
end
|
94
|
+
|
95
|
+
def images
|
96
|
+
Image.for(self)
|
97
|
+
end
|
98
|
+
|
99
|
+
def image
|
100
|
+
images.first
|
101
|
+
end
|
102
|
+
|
103
|
+
def available?
|
104
|
+
variants.to_a.any? { |o| o.available? }
|
105
|
+
end
|
106
|
+
|
107
|
+
def minimum_active_price
|
108
|
+
variants.to_a.min { |a, b| a.active_price <=> b.active_price }.try(:active_price)
|
109
|
+
end
|
110
|
+
def maximum_active_price
|
111
|
+
variants.to_a.max { |a, b| a.active_price <=> b.active_price }.try(:active_price)
|
112
|
+
end
|
113
|
+
def minimum_price
|
114
|
+
variants.to_a.min { |a, b| a.price <=> b.price }.try(:price)
|
115
|
+
end
|
116
|
+
def maximum_price
|
117
|
+
variants.to_a.max { |a, b| a.price <=> b.price }.try(:price)
|
118
|
+
end
|
119
|
+
|
120
|
+
def similar
|
121
|
+
category.products if category
|
122
|
+
end
|
123
|
+
def related_products
|
124
|
+
as_dataset(Product.to_a.select{|pr| related_ids.to_a.include?(pr.id)})
|
125
|
+
end
|
126
|
+
|
127
|
+
def rating
|
128
|
+
count = reviews.visible.count
|
129
|
+
sum = reviews.visible.reduce(0) do |memo, item|
|
130
|
+
memo += item.rating
|
131
|
+
memo
|
132
|
+
end
|
133
|
+
|
134
|
+
if count == 0
|
135
|
+
return 0
|
136
|
+
end
|
137
|
+
|
138
|
+
return sum / count
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end end end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class ProductAttribute < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
fields :id, :product_id, :attribute_key_id
|
8
|
+
c_fields :values, cast: JSON
|
9
|
+
|
10
|
+
translates :values
|
11
|
+
belongs_to :attribute_key
|
12
|
+
|
13
|
+
def self.primary_key
|
14
|
+
:id
|
15
|
+
end
|
16
|
+
|
17
|
+
def name
|
18
|
+
attribute_key.name
|
19
|
+
end
|
20
|
+
|
21
|
+
def handle
|
22
|
+
attribute_key.handle
|
23
|
+
end
|
24
|
+
|
25
|
+
def value
|
26
|
+
values.join("; ")
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end end end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class ProductSearch
|
5
|
+
include Pagy::Backend
|
6
|
+
|
7
|
+
attr_reader :word, :options
|
8
|
+
|
9
|
+
def initialize(word:, **options)
|
10
|
+
@word = word
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def paginate(page: 1, per: 12)
|
15
|
+
page = 1 if !page || page == 0
|
16
|
+
|
17
|
+
pagy(results, items: per, page: page, count: results.count)
|
18
|
+
end
|
19
|
+
|
20
|
+
def performed
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
def terms
|
25
|
+
word ? word.to_s.split(/[ \+]+/) : ""
|
26
|
+
end
|
27
|
+
|
28
|
+
def results
|
29
|
+
return Product.none if word.blank?
|
30
|
+
return @results if defined?(@results)
|
31
|
+
|
32
|
+
rel = Product
|
33
|
+
terms.each do |term|
|
34
|
+
rel = rel.where(Sequel.ilike(:name, "%#{term}%")) if term.presence
|
35
|
+
end
|
36
|
+
@results = rel
|
37
|
+
end
|
38
|
+
|
39
|
+
def results_size
|
40
|
+
results.size
|
41
|
+
end
|
42
|
+
|
43
|
+
def searching?
|
44
|
+
word.present?
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_curl
|
48
|
+
"No request"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end end end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
module Model
|
4
|
+
class ProductType < Sequel::Model
|
5
|
+
extend Base::SequelClass
|
6
|
+
include Base::Sequel
|
7
|
+
|
8
|
+
fields :id, :name, :handle, :translations
|
9
|
+
|
10
|
+
translates :name
|
11
|
+
|
12
|
+
def self.primary_key
|
13
|
+
:handle
|
14
|
+
end
|
15
|
+
|
16
|
+
has_many :products
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end end end
|