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,366 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
class Server
|
4
|
+
module Routes
|
5
|
+
Editor.autoload_all self, "mounter/server/routes"
|
6
|
+
|
7
|
+
mattr_accessor :app
|
8
|
+
|
9
|
+
class << self
|
10
|
+
delegate :register, to: :app
|
11
|
+
delegate :get, to: :app
|
12
|
+
delegate :post, to: :app
|
13
|
+
delegate :patch, to: :app
|
14
|
+
delegate :put, to: :app
|
15
|
+
delegate :delete, to: :app
|
16
|
+
delegate :not_found, to: :app
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.registered(app)
|
20
|
+
self.app = app
|
21
|
+
register_modules
|
22
|
+
|
23
|
+
get "/?:locale?/categories" do
|
24
|
+
scope = Model::Category.where
|
25
|
+
if params[:parent_id].present?
|
26
|
+
params[:parent_id] = Model::Category.find_by(handle: params[:parent_id]).id if params[:parent_id].to_i.eql?(0)
|
27
|
+
scope = scope.where(parent_id: params[:parent_id].to_i)
|
28
|
+
end
|
29
|
+
respond_to do |f|
|
30
|
+
f.json{
|
31
|
+
locals, registers = registers_and_locals
|
32
|
+
context = Liquid::Context.build(registers: registers)
|
33
|
+
children = params[:include].to_s.split("|").include?("children")
|
34
|
+
json scope.map{|el| el.to_liquid(context).as_json(incl_children: children) }
|
35
|
+
}
|
36
|
+
f.html{
|
37
|
+
respond :categories, categories: scope.map(&:to_liquid)
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
get "/?:locale?/categories/*" do
|
43
|
+
params[:id] = params[:splat][0]
|
44
|
+
drop = ShoperbLiquid::CategoryDrop.new(request.env[:current_category] = Model::Category.find_by(permalink: params[:id]))
|
45
|
+
@category = drop.record
|
46
|
+
respond :category, category: drop, meta: drop
|
47
|
+
end
|
48
|
+
|
49
|
+
get "/?:locale?/products/:id" do
|
50
|
+
product = ShoperbLiquid::ProductDrop.new(record = Model::Product.find_by(permalink: params[:id])||Model::Product.new(name: "Product not found!", id: -1))
|
51
|
+
category = product.category
|
52
|
+
template = record.template.presence || :product
|
53
|
+
respond template.to_sym, product: product, category: category, meta: product
|
54
|
+
end
|
55
|
+
|
56
|
+
# params:
|
57
|
+
# * ids - to filter by variant ids
|
58
|
+
# * product_id - to filter by product_id
|
59
|
+
# * attrributes - hash to filter by attributes {not_translated_key: not_translated_value,..}
|
60
|
+
post "/?:locale?/variants" do
|
61
|
+
pars = JSON.parse(request.body.string,symbolize_names: true)
|
62
|
+
scope = Model::Variant
|
63
|
+
scope = scope.where(id: pars[:ids].map(&:to_i)) if pars[:ids].present?
|
64
|
+
scope = scope.where(product_id: pars[:product_id].to_i) if pars[:product_id].present?
|
65
|
+
|
66
|
+
if pars[:attributes].present?
|
67
|
+
# for now lets just return some variants
|
68
|
+
end
|
69
|
+
pagy, scope = scope.paginate(pars[:page]||1, 10)
|
70
|
+
arr = scope.to_a || []
|
71
|
+
arr = arr.map{|i| i.to_liquid.as_json }.shuffle
|
72
|
+
resp = {
|
73
|
+
variants: arr,
|
74
|
+
page: {
|
75
|
+
page: pagy.page,
|
76
|
+
total: pagy.items,
|
77
|
+
pages: pagy.pages
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
if pars[:product_id].present? && pars.has_key?(:left_options)
|
82
|
+
# resp[:left_options] = left_options(params[:product_id])
|
83
|
+
v_ids = Model::Variant.
|
84
|
+
where(product_id: pars[:product_id].to_i).
|
85
|
+
available.
|
86
|
+
map(&:id)
|
87
|
+
resp[:left_options] = {}
|
88
|
+
|
89
|
+
Model::VariantAttribute.
|
90
|
+
where(variant_id: v_ids).
|
91
|
+
each do |attr|
|
92
|
+
# doing = true
|
93
|
+
# pars[:attributes].to_h.each{|k,v|
|
94
|
+
# doing=false if attr.name == k.to_s && attr.value == v
|
95
|
+
# }
|
96
|
+
# if doing
|
97
|
+
resp[:left_options][attr.name] ||= []
|
98
|
+
resp[:left_options][attr.name] |= [attr.value]
|
99
|
+
# end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
json resp
|
104
|
+
end
|
105
|
+
|
106
|
+
get "/?:locale?/product-filters" do
|
107
|
+
products = Model::Product.where
|
108
|
+
if params[:category].present?
|
109
|
+
obj = Model::Category.find_by(handle: params[:category])
|
110
|
+
products = products.where(category_id: obj.self_and_descendants.map(&:id))
|
111
|
+
end
|
112
|
+
if params[:collection].present?
|
113
|
+
obj = Model::Collection.find_by(handle: params[:collection])
|
114
|
+
products = products.where(id: obj.product_ids)
|
115
|
+
end
|
116
|
+
|
117
|
+
context = OpenStruct.new(products: products.map(&:to_liquid))
|
118
|
+
tag = ShoperbLiquid::ProductsFilterTag.send(:new,"","",OpenStruct.new)
|
119
|
+
json tag.facets(context)[params[:attribute]].to_h["values"].to_h
|
120
|
+
end
|
121
|
+
|
122
|
+
get "/?:locale?/products/:id/reviews" do
|
123
|
+
product = ShoperbLiquid::ProductDrop.new(record = Model::Product.find_by(permalink: params[:id]))
|
124
|
+
category = product.category
|
125
|
+
reviews = product.reviews
|
126
|
+
respond :reviews, product: product, category: category, meta: product, reviews: reviews
|
127
|
+
end
|
128
|
+
|
129
|
+
get "/?:locale?/cart" do
|
130
|
+
respond :cart
|
131
|
+
end
|
132
|
+
|
133
|
+
get "/?:locale?/" do
|
134
|
+
respond [:home, :index, :frontpage]
|
135
|
+
end
|
136
|
+
|
137
|
+
get "/?:locale?/login" do
|
138
|
+
respond :login
|
139
|
+
end
|
140
|
+
|
141
|
+
post "/?:locale?/login" do
|
142
|
+
respond :login
|
143
|
+
end
|
144
|
+
|
145
|
+
get "/?:locale?/signup" do
|
146
|
+
respond :signup
|
147
|
+
end
|
148
|
+
|
149
|
+
get "/?:locale?/recover" do
|
150
|
+
respond :password_request
|
151
|
+
end
|
152
|
+
|
153
|
+
get "/?:locale?/reset" do
|
154
|
+
respond :password_change
|
155
|
+
end
|
156
|
+
|
157
|
+
get "/?:locale?/account" do
|
158
|
+
respond :account
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
get "/?:locale?/account/billing/payment-methods" do
|
163
|
+
respond :billing_payment_methods, payment_methods: [Model::PaymentCard.first.to_liquid]
|
164
|
+
end
|
165
|
+
get "/?:locale?/account/billing/payment-methods/add" do
|
166
|
+
meth = Model::PaymentCard.new.to_liquid
|
167
|
+
provider = Model::PaymentProvider.first.to_liquid
|
168
|
+
respond :billing_payment_method, payment_method: meth, providers: [provider]
|
169
|
+
end
|
170
|
+
post "/?:locale?/account/billing/payment-methods" do # create action
|
171
|
+
redirect "/account/billing/payment-methods"
|
172
|
+
end
|
173
|
+
get "/?:locale?/account/billing/payment-methods/:id" do
|
174
|
+
respond :billing_payment_method, payment_method: Model::PaymentCard.first.to_liquid
|
175
|
+
end
|
176
|
+
get "/?:locale?/account/billing/payment-methods/:id/delete" do
|
177
|
+
redirect "/account/billing/payment-methods"
|
178
|
+
end
|
179
|
+
|
180
|
+
get "/?:locale?/account/subscriptions" do
|
181
|
+
respond :billing_subscriptions, subscriptions: ShoperbLiquid::CollectionDrop.new(Model::CustomerSubscription.all.map{|e| ShoperbLiquid::SubscriptionDrop.new(e)})
|
182
|
+
end
|
183
|
+
get "/?:locale?/account/subscriptions/plans" do
|
184
|
+
respond :billing_subscription_plans, subscription: ShoperbLiquid::Subscription.new(Model::CustomerSubscription.all.detect(&:active?))
|
185
|
+
end
|
186
|
+
get "/?:locale?/account/subscriptions/create/?:plan_id?" do
|
187
|
+
subscription = Model::CustomerSubscription.new
|
188
|
+
subscription.plan_id = params[:plan_id]
|
189
|
+
subscription.instance_variable_set(:@attributes,
|
190
|
+
subscription.attributes.merge(params.fetch(:subscription,{}).slice(:qty))
|
191
|
+
)
|
192
|
+
subscription.customer = current_customer
|
193
|
+
|
194
|
+
flash[:notice] = "subscription.error_occured"
|
195
|
+
respond :billing_subscription, subscription: subscription, payment_methods: [Model::PaymentCard.first], providers: [Model::PaymentProvider.first.to_liquid]
|
196
|
+
end
|
197
|
+
get "/?:locale?/account/subscriptions/:id/delete" do
|
198
|
+
flash[:notice] = "subscription.deleted"
|
199
|
+
redirect_to "/account/subscriptions/plans"
|
200
|
+
end
|
201
|
+
|
202
|
+
get "/?:locale?/reset/:token" do
|
203
|
+
respond :password_change
|
204
|
+
end
|
205
|
+
|
206
|
+
not_found do
|
207
|
+
respond :not_found
|
208
|
+
end
|
209
|
+
|
210
|
+
get "/?:locale?/brands" do
|
211
|
+
respond :brands
|
212
|
+
end
|
213
|
+
|
214
|
+
get "/?:locale?/brands/:id" do
|
215
|
+
drop = ShoperbLiquid::VendorDrop.new(Model::Vendor.find(id: params[:id]))
|
216
|
+
respond :brand, vendor: drop, brand: drop, meta: drop
|
217
|
+
end
|
218
|
+
|
219
|
+
get "/?:locale?/blog" do
|
220
|
+
respond :blog_posts, posts: ShoperbLiquid::CollectionDrop.new(Model::BlogPost.active)
|
221
|
+
end
|
222
|
+
|
223
|
+
get "/?:locale?/blog/:id" do
|
224
|
+
post = Model::BlogPost.find_by(permalink: params[:id])
|
225
|
+
template = post.template.presence || :blog_post
|
226
|
+
respond template, post: post, meta: post
|
227
|
+
end
|
228
|
+
|
229
|
+
get "/?:locale?/order-returns" do
|
230
|
+
respond :order_returns, order_returns: ShoperbLiquid::OrderReturnsDrop.new(Model::OrderReturn.dataset)
|
231
|
+
end
|
232
|
+
post "/?:locale?/order-returns" do
|
233
|
+
redirect "/order-returns"
|
234
|
+
end
|
235
|
+
get "/?:locale?/order-returns/new" do
|
236
|
+
respond :order_return, order_return: Model::OrderReturn.new.to_liquid, orders: ShoperbLiquid::OrdersDrop.new(Model::Order.all.to_a[0..10])
|
237
|
+
end
|
238
|
+
get "/?:locale?/order-returns/:id" do
|
239
|
+
respond :order_return, order_return: Model::OrderReturn.find(id: params[:id])&.to_liquid
|
240
|
+
end
|
241
|
+
post "/?:locale?/order-returns/:id/generate-parcel" do
|
242
|
+
respond :order_return, order_return: Model::OrderReturn.find(id: params[:id])&.to_liquid
|
243
|
+
end
|
244
|
+
|
245
|
+
get "/?:locale?/addresses/new" do
|
246
|
+
respond :address, address: ShoperbLiquid::AddressDrop.new(Model::Address.new)
|
247
|
+
end
|
248
|
+
|
249
|
+
post "/?:locale?/addresses" do
|
250
|
+
respond :address, address: ShoperbLiquid::AddressDrop.new(Model::Address.new(params[:address]))
|
251
|
+
end
|
252
|
+
|
253
|
+
patch "/?:locale?/addresses/:id" do
|
254
|
+
respond :address, address: ShoperbLiquid::AddressDrop.new(current_customer.addresses.detect { |address| address.id.to_s == params[:id].to_s })
|
255
|
+
end
|
256
|
+
|
257
|
+
put "/?:locale?/addresses/:id" do
|
258
|
+
respond :address, address: ShoperbLiquid::AddressDrop.new(current_customer.addresses.detect { |address| address.id.to_s == params[:id].to_s })
|
259
|
+
end
|
260
|
+
|
261
|
+
get "/?:locale?/addresses/:id/delete" do
|
262
|
+
redirect_to "/addresses"
|
263
|
+
end
|
264
|
+
|
265
|
+
get "/?:locale?/emails" do
|
266
|
+
out = "<p>You have next templates:</p>"
|
267
|
+
out += "<ul>"
|
268
|
+
Dir["emails/*"].each do |file|
|
269
|
+
url = file.sub(".liquid","")
|
270
|
+
out += %Q{<li><a href="#{url}">#{url}</a></li>}
|
271
|
+
end
|
272
|
+
out + "</ul>"
|
273
|
+
end
|
274
|
+
|
275
|
+
get "/?:locale?/emails/:template" do
|
276
|
+
entities = {}
|
277
|
+
order = if params[:order_id]
|
278
|
+
Model::Order.find(id: params[:order_id])
|
279
|
+
else
|
280
|
+
Model::Order.first
|
281
|
+
end
|
282
|
+
entities.merge!(order: ShoperbLiquid::OrderDrop.new(order))
|
283
|
+
customer = if order
|
284
|
+
order.customer
|
285
|
+
elsif params[:customer_id]
|
286
|
+
Model::Customer.find(id: params[:order_id])
|
287
|
+
else
|
288
|
+
Model::Customer.last
|
289
|
+
end
|
290
|
+
entities.merge!(customer: ShoperbLiquid::CustomerDrop.new(customer))
|
291
|
+
tpl = params[:template]
|
292
|
+
|
293
|
+
content_type "text/plain" if tpl.end_with?(".text")
|
294
|
+
respond_email tpl, entities
|
295
|
+
end
|
296
|
+
|
297
|
+
post "/?:locale?/reviews" do
|
298
|
+
redirect "/products/#{params['review']['product_id']}"
|
299
|
+
end
|
300
|
+
|
301
|
+
append_paths
|
302
|
+
end
|
303
|
+
|
304
|
+
private
|
305
|
+
|
306
|
+
def self.register_modules
|
307
|
+
register Assets
|
308
|
+
register Defaults
|
309
|
+
register Locale
|
310
|
+
register Pages
|
311
|
+
register Cart
|
312
|
+
register Search
|
313
|
+
register Server::Renderer
|
314
|
+
end
|
315
|
+
|
316
|
+
def self.append_paths
|
317
|
+
resource Model::Collection do
|
318
|
+
ShoperbLiquid::ProductCollectionDrop.new(Model::Collection.find_by(permalink: params[:id]))
|
319
|
+
end
|
320
|
+
|
321
|
+
resources Model::Collection do
|
322
|
+
ShoperbLiquid::CollectionDrop.new(Model::Collection.all)
|
323
|
+
end
|
324
|
+
|
325
|
+
resource Model::Order do
|
326
|
+
ShoperbLiquid::OrderDrop.new(Model::Order.find(id: params[:id]) || Model::Order.find(number: params[:id]))
|
327
|
+
end
|
328
|
+
|
329
|
+
resources Model::Order do
|
330
|
+
ShoperbLiquid::CollectionDrop.new(Model::Order.all)
|
331
|
+
end
|
332
|
+
|
333
|
+
resources Model::Product do
|
334
|
+
ShoperbLiquid::ProductsDrop.new(Model::Product.active)
|
335
|
+
end
|
336
|
+
|
337
|
+
resources Model::Address do
|
338
|
+
ShoperbLiquid::CollectionDrop.new(current_customer.addresses)
|
339
|
+
end
|
340
|
+
|
341
|
+
resource Model::Address do
|
342
|
+
ShoperbLiquid::AddressDrop.new(current_customer.addresses.detect { |address| address.id.to_s == params[:id].to_s })
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
def self.resource collection, &block
|
347
|
+
name = collection.to_s.demodulize.underscore
|
348
|
+
get "/?:locale?/#{name.pluralize}/:id" do
|
349
|
+
drop = instance_exec(&block)
|
350
|
+
instance_variable_set("@#{name}", drop.record)
|
351
|
+
|
352
|
+
respond name, name => drop, :meta => drop
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
def self.resources collection, &block
|
357
|
+
name = collection.to_s.demodulize.underscore.pluralize
|
358
|
+
get "/?:locale?/#{name}" do
|
359
|
+
respond name, name => instance_exec(&block)
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end end end
|
@@ -0,0 +1,278 @@
|
|
1
|
+
module Shoperb module Theme module Editor
|
2
|
+
module Mounter
|
3
|
+
class Server
|
4
|
+
module RoutesHelper
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def store_root_path(**_)
|
8
|
+
"/"
|
9
|
+
end
|
10
|
+
|
11
|
+
def store_signup_path(**_)
|
12
|
+
"/signup"
|
13
|
+
end
|
14
|
+
|
15
|
+
def store_login_path(**_)
|
16
|
+
"/login"
|
17
|
+
end
|
18
|
+
|
19
|
+
def store_new_login_path(**_)
|
20
|
+
"/login"
|
21
|
+
end
|
22
|
+
|
23
|
+
def store_logout_path(**_)
|
24
|
+
"/logout"
|
25
|
+
end
|
26
|
+
|
27
|
+
def store_recover_password_path(**_)
|
28
|
+
"/recover"
|
29
|
+
end
|
30
|
+
|
31
|
+
def store_new_recover_password_path(**_)
|
32
|
+
"/recover"
|
33
|
+
end
|
34
|
+
|
35
|
+
def store_reset_password_path(**_)
|
36
|
+
"/reset"
|
37
|
+
end
|
38
|
+
|
39
|
+
def store_upd_reset_password_path(**_)
|
40
|
+
"/reset"
|
41
|
+
end
|
42
|
+
|
43
|
+
def store_account_path(**_)
|
44
|
+
"/account"
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_store_account_billing_payment_methods_path(**_)
|
48
|
+
"/account/billing/payment-methods/add"
|
49
|
+
end
|
50
|
+
|
51
|
+
def store_account_billing_payment_methods_path(**_)
|
52
|
+
"/account/billing/payment-methods"
|
53
|
+
end
|
54
|
+
|
55
|
+
def store_account_billing_payment_method_path(id, **_)
|
56
|
+
"/account/billing/payment-methods/#{id}"
|
57
|
+
end
|
58
|
+
|
59
|
+
def delete_store_account_billing_payment_method_path(id, **_)
|
60
|
+
"/account/billing/payment-methods/#{id}/delete"
|
61
|
+
end
|
62
|
+
|
63
|
+
def store_account_subscriptions_path(**_)
|
64
|
+
"/account/subscriptions"
|
65
|
+
end
|
66
|
+
|
67
|
+
def store_account_subscription_plans_path(**_)
|
68
|
+
"/account/subscriptions/plans"
|
69
|
+
end
|
70
|
+
|
71
|
+
def store_account_create_subscription_path(plan_id = nil,**_)
|
72
|
+
str = "/account/subscriptions/create"
|
73
|
+
str += "/#{plan_id}" if plan_id
|
74
|
+
str
|
75
|
+
end
|
76
|
+
|
77
|
+
def store_account_delete_subscription_path(id,**_)
|
78
|
+
"/account/subscriptions/#{id}/delete"
|
79
|
+
end
|
80
|
+
|
81
|
+
def store_address_path(obj, **_)
|
82
|
+
id = get_id(obj)
|
83
|
+
"/addresses/#{id}"
|
84
|
+
end
|
85
|
+
|
86
|
+
def new_store_address_path(**_)
|
87
|
+
"/addresses/new"
|
88
|
+
end
|
89
|
+
|
90
|
+
def store_addresses_path(**_)
|
91
|
+
"/addresses"
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def delete_store_address_path(id,**_)
|
96
|
+
"/addresses/#{id}/delete"
|
97
|
+
end
|
98
|
+
|
99
|
+
def store_brand_path(obj, **_)
|
100
|
+
id = get_id(obj)
|
101
|
+
"/brands/#{id}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def store_brands_path(**_)
|
105
|
+
"/brands"
|
106
|
+
end
|
107
|
+
|
108
|
+
def store_category_path(obj, **_)
|
109
|
+
id = get_id(obj)
|
110
|
+
"/categories/#{id}"
|
111
|
+
end
|
112
|
+
|
113
|
+
def store_categories_path(**_)
|
114
|
+
"/categories"
|
115
|
+
end
|
116
|
+
|
117
|
+
def store_checkout_order_url(obj, **_)
|
118
|
+
id = get_id(obj)
|
119
|
+
"/checkout/#{id}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def store_collection_path(obj, **_)
|
123
|
+
id = get_id(obj)
|
124
|
+
"/collections/#{id}"
|
125
|
+
end
|
126
|
+
|
127
|
+
def store_collections_path(**_)
|
128
|
+
"/collections"
|
129
|
+
end
|
130
|
+
|
131
|
+
def store_order_path(obj, **_)
|
132
|
+
id = get_id(obj)
|
133
|
+
"/orders/#{id}"
|
134
|
+
end
|
135
|
+
|
136
|
+
def store_orders_path(**_)
|
137
|
+
"/orders"
|
138
|
+
end
|
139
|
+
|
140
|
+
def store_page_path(obj, **_)
|
141
|
+
id = get_id(obj)
|
142
|
+
"/pages/#{id}"
|
143
|
+
end
|
144
|
+
|
145
|
+
def store_pages_path(**_)
|
146
|
+
"/pages"
|
147
|
+
end
|
148
|
+
|
149
|
+
def store_product_path(obj, **_)
|
150
|
+
id = get_id(obj)
|
151
|
+
"/products/#{id}"
|
152
|
+
end
|
153
|
+
|
154
|
+
def store_product_url(obj, **_)
|
155
|
+
"https://#{shop.domain}/#{Translations.locale}/products/#{get_id(obj)}"
|
156
|
+
end
|
157
|
+
|
158
|
+
def reviews_store_product_path(obj, **_)
|
159
|
+
"/products/#{get_id(obj)}/reviews"
|
160
|
+
end
|
161
|
+
|
162
|
+
def store_products_path(**_)
|
163
|
+
"/products"
|
164
|
+
end
|
165
|
+
|
166
|
+
def store_variants_path(**_)
|
167
|
+
"/variants"
|
168
|
+
end
|
169
|
+
|
170
|
+
def store_reviews_path(**_)
|
171
|
+
"/reviews"
|
172
|
+
end
|
173
|
+
|
174
|
+
def store_subscribers_add_path(**_)
|
175
|
+
"/subscribers/add"
|
176
|
+
end
|
177
|
+
|
178
|
+
def store_search_path(**_)
|
179
|
+
"/search"
|
180
|
+
end
|
181
|
+
|
182
|
+
def store_blog_post_path(obj, **_)
|
183
|
+
id = get_id(obj)
|
184
|
+
"/blog/#{id}"
|
185
|
+
end
|
186
|
+
|
187
|
+
def store_blog_posts_path(**_)
|
188
|
+
"/blog"
|
189
|
+
end
|
190
|
+
|
191
|
+
def store_cart_path(**_)
|
192
|
+
"/cart"
|
193
|
+
end
|
194
|
+
def store_carts_path(**_)
|
195
|
+
"/carts"
|
196
|
+
end
|
197
|
+
|
198
|
+
def add_store_cart_path(**_)
|
199
|
+
"/cart/add"
|
200
|
+
end
|
201
|
+
|
202
|
+
def update_store_cart_path(**_)
|
203
|
+
"/cart/update"
|
204
|
+
end
|
205
|
+
|
206
|
+
def checkout_store_cart_path(**_)
|
207
|
+
"/cart/checkout"
|
208
|
+
end
|
209
|
+
|
210
|
+
def add_store_multi_cart_path(obj,**_)
|
211
|
+
"/cart/#{get_id(obj)}/add"
|
212
|
+
end
|
213
|
+
|
214
|
+
def update_store_multi_cart_path(obj,**_)
|
215
|
+
"/cart/#{get_id(obj)}/update"
|
216
|
+
end
|
217
|
+
|
218
|
+
def checkout_store_multi_cart_path(obj,**_)
|
219
|
+
"/cart/#{get_id(obj)}/checkout"
|
220
|
+
end
|
221
|
+
|
222
|
+
def store_order_returns_path(**_)
|
223
|
+
"/order-returns"
|
224
|
+
end
|
225
|
+
|
226
|
+
def new_store_order_return_path(**_)
|
227
|
+
"/order-returns/new"
|
228
|
+
end
|
229
|
+
|
230
|
+
def store_order_return_path(id, **_)
|
231
|
+
"/order-returns/#{id}"
|
232
|
+
end
|
233
|
+
|
234
|
+
def store_order_return_generate_parcel_path(id, **_)
|
235
|
+
"/order-returns/#{id}/generate-parcel"
|
236
|
+
end
|
237
|
+
|
238
|
+
def recognize_path(**args)
|
239
|
+
url_for(**args)
|
240
|
+
end
|
241
|
+
|
242
|
+
def url_for(**args)
|
243
|
+
end
|
244
|
+
|
245
|
+
private
|
246
|
+
|
247
|
+
def get_id(obj)
|
248
|
+
case obj
|
249
|
+
when Numeric then obj
|
250
|
+
when String then obj
|
251
|
+
when NilClass then raise StandardError.new("missing argument for building path")
|
252
|
+
else
|
253
|
+
obj.try(:permalink) || obj.try(:to_param) || obj.try(:id)
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
def self.after(*names)
|
258
|
+
names.each do |name|
|
259
|
+
m = instance_method(name)
|
260
|
+
define_method(name) do |*args, &block|
|
261
|
+
res = m.bind(self).(*args, &block)
|
262
|
+
yield(res, *args)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
after(*instance_methods) do |res, **args|
|
268
|
+
if res.try(:start_with?, "http")
|
269
|
+
res
|
270
|
+
else
|
271
|
+
locale = args.symbolize_keys[:locale] || Translations.locale
|
272
|
+
"/#{locale}#{res}"
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end end end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
Sinatra.autoload :Flash, "sinatra/flash"
|
2
|
+
Sinatra.autoload :RespondWith,"sinatra/respond_with"
|
3
|
+
|
4
|
+
Tilt::Template.class_eval do
|
5
|
+
def require_template_library(name)
|
6
|
+
# Silence the warning
|
7
|
+
require name
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Shoperb module Theme module Editor
|
12
|
+
module Mounter
|
13
|
+
class Server < Sinatra::Base
|
14
|
+
Editor.autoload_all self, "mounter/server"
|
15
|
+
|
16
|
+
include Server::RoutesHelper
|
17
|
+
|
18
|
+
set :root, Dir.pwd
|
19
|
+
set :environment, :development
|
20
|
+
|
21
|
+
use ExceptionHandler
|
22
|
+
register Renderer
|
23
|
+
register Routes
|
24
|
+
|
25
|
+
helpers do
|
26
|
+
def current_cart
|
27
|
+
Model::Cart.first || Model::Cart.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def current_carts
|
31
|
+
current_cart.id ? Model::Cart.all : []
|
32
|
+
end
|
33
|
+
|
34
|
+
def shop
|
35
|
+
Model::Shop.first || raise(Error.new("No data has been synced."))
|
36
|
+
end
|
37
|
+
|
38
|
+
def current_customer
|
39
|
+
if (id = params[:customer_id].to_i) > 0
|
40
|
+
Model::Customer.find(id: id)
|
41
|
+
else
|
42
|
+
Model::Customer.first || Model::Customer.new(first_name: "No customer", last_name: "in customers.yml")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def current_settings
|
47
|
+
Editor.theme_settings
|
48
|
+
end
|
49
|
+
|
50
|
+
# so far in liquid it's used to replace locale only
|
51
|
+
# theme setting link, but we will skip it for now.
|
52
|
+
# just minimum required implementation.
|
53
|
+
def url_for(*args_main, **args)
|
54
|
+
args_main.each do |arg|
|
55
|
+
arg.each{|k,v| args[k] = v}
|
56
|
+
end
|
57
|
+
request.fullpath.gsub(/\A(?=#{shop.all_languages.map{|s|"/#{s}"}.join("|")}|)\/(.*)/, "/#{args[:locale]}/\\1") if args[:locale]
|
58
|
+
end
|
59
|
+
|
60
|
+
def form_authenticity_token
|
61
|
+
"token"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end end end
|