shoperb_liquid 0.0.1
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/.gitignore +23 -0
- data/.rubocop.yml +131 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +143 -0
- data/Rakefile +4 -0
- data/lib/shoperb_liquid/configuration.rb +169 -0
- data/lib/shoperb_liquid/drops/account_drop.rb +9 -0
- data/lib/shoperb_liquid/drops/address_drop.rb +121 -0
- data/lib/shoperb_liquid/drops/array_drop.rb +18 -0
- data/lib/shoperb_liquid/drops/attribute_drop.rb +21 -0
- data/lib/shoperb_liquid/drops/base.rb +65 -0
- data/lib/shoperb_liquid/drops/blog_category_drop.rb +56 -0
- data/lib/shoperb_liquid/drops/blog_post_drop.rb +46 -0
- data/lib/shoperb_liquid/drops/cart_drop.rb +42 -0
- data/lib/shoperb_liquid/drops/cart_item_drop.rb +111 -0
- data/lib/shoperb_liquid/drops/categories_drop.rb +13 -0
- data/lib/shoperb_liquid/drops/category_drop.rb +110 -0
- data/lib/shoperb_liquid/drops/collection_drop.rb +117 -0
- data/lib/shoperb_liquid/drops/country_drop.rb +37 -0
- data/lib/shoperb_liquid/drops/currency_drop.rb +17 -0
- data/lib/shoperb_liquid/drops/customer_credit_drop.rb +23 -0
- data/lib/shoperb_liquid/drops/customer_credits_drop.rb +18 -0
- data/lib/shoperb_liquid/drops/customer_drop.rb +108 -0
- data/lib/shoperb_liquid/drops/customer_group_drop.rb +17 -0
- data/lib/shoperb_liquid/drops/gift_card_drop.rb +34 -0
- data/lib/shoperb_liquid/drops/image_drop.rb +27 -0
- data/lib/shoperb_liquid/drops/integration_drop.rb +25 -0
- data/lib/shoperb_liquid/drops/integrations_drop.rb +17 -0
- data/lib/shoperb_liquid/drops/language_drop.rb +17 -0
- data/lib/shoperb_liquid/drops/link_drop.rb +53 -0
- data/lib/shoperb_liquid/drops/media_file_drop.rb +29 -0
- data/lib/shoperb_liquid/drops/menu_drop.rb +25 -0
- data/lib/shoperb_liquid/drops/menus_drop.rb +16 -0
- data/lib/shoperb_liquid/drops/meta_drop.rb +21 -0
- data/lib/shoperb_liquid/drops/order_drop.rb +148 -0
- data/lib/shoperb_liquid/drops/order_item_attribute_drop.rb +8 -0
- data/lib/shoperb_liquid/drops/order_item_attributes_drop.rb +19 -0
- data/lib/shoperb_liquid/drops/order_item_drop.rb +159 -0
- data/lib/shoperb_liquid/drops/order_return_drop.rb +43 -0
- data/lib/shoperb_liquid/drops/order_return_item_drop.rb +30 -0
- data/lib/shoperb_liquid/drops/order_return_item_entity_drop.rb +13 -0
- data/lib/shoperb_liquid/drops/order_return_parcel_drop.rb +29 -0
- data/lib/shoperb_liquid/drops/order_returns_drop.rb +13 -0
- data/lib/shoperb_liquid/drops/orders_drop.rb +14 -0
- data/lib/shoperb_liquid/drops/page_drop.rb +26 -0
- data/lib/shoperb_liquid/drops/pages_drop.rb +12 -0
- data/lib/shoperb_liquid/drops/payment_card_drop.rb +29 -0
- data/lib/shoperb_liquid/drops/payment_method_drop.rb +41 -0
- data/lib/shoperb_liquid/drops/payment_provider_drop.rb +23 -0
- data/lib/shoperb_liquid/drops/product_attribute_drop.rb +14 -0
- data/lib/shoperb_liquid/drops/product_collection_drop.rb +41 -0
- data/lib/shoperb_liquid/drops/product_collections_drop.rb +12 -0
- data/lib/shoperb_liquid/drops/product_drop.rb +195 -0
- data/lib/shoperb_liquid/drops/product_type_drop.rb +25 -0
- data/lib/shoperb_liquid/drops/product_types_drop.rb +15 -0
- data/lib/shoperb_liquid/drops/products_drop.rb +44 -0
- data/lib/shoperb_liquid/drops/refund_drop.rb +22 -0
- data/lib/shoperb_liquid/drops/refund_item_drop.rb +18 -0
- data/lib/shoperb_liquid/drops/review_drop.rb +37 -0
- data/lib/shoperb_liquid/drops/search_drop.rb +45 -0
- data/lib/shoperb_liquid/drops/shipping_item_drop.rb +29 -0
- data/lib/shoperb_liquid/drops/shipping_method_drop.rb +25 -0
- data/lib/shoperb_liquid/drops/shipping_parcel_drop.rb +25 -0
- data/lib/shoperb_liquid/drops/shop_drop.rb +81 -0
- data/lib/shoperb_liquid/drops/subscription_drop.rb +51 -0
- data/lib/shoperb_liquid/drops/subscription_plan_drop.rb +63 -0
- data/lib/shoperb_liquid/drops/theme_section_blocks_drop.rb +19 -0
- data/lib/shoperb_liquid/drops/theme_section_drop.rb +30 -0
- data/lib/shoperb_liquid/drops/theme_section_image_drop.rb +11 -0
- data/lib/shoperb_liquid/drops/theme_section_settings_drop.rb +40 -0
- data/lib/shoperb_liquid/drops/theme_settings_drop.rb +60 -0
- data/lib/shoperb_liquid/drops/url_drop.rb +218 -0
- data/lib/shoperb_liquid/drops/variant_attribute_drop.rb +8 -0
- data/lib/shoperb_liquid/drops/variant_drop.rb +206 -0
- data/lib/shoperb_liquid/drops/variants_drop.rb +13 -0
- data/lib/shoperb_liquid/drops/vendor_drop.rb +77 -0
- data/lib/shoperb_liquid/drops/vendors_drop.rb +13 -0
- data/lib/shoperb_liquid/errors.rb +6 -0
- data/lib/shoperb_liquid/ext/array.rb +7 -0
- data/lib/shoperb_liquid/ext/context.rb +12 -0
- data/lib/shoperb_liquid/ext/models.rb +55 -0
- data/lib/shoperb_liquid/ext/template.rb +13 -0
- data/lib/shoperb_liquid/filters/asset_filters.rb +57 -0
- data/lib/shoperb_liquid/filters/collection_filters.rb +26 -0
- data/lib/shoperb_liquid/filters/datum_filters.rb +150 -0
- data/lib/shoperb_liquid/filters/extension_filters.rb +35 -0
- data/lib/shoperb_liquid/filters/html_filters.rb +46 -0
- data/lib/shoperb_liquid/filters/theme_filters.rb +22 -0
- data/lib/shoperb_liquid/filters/translate_filters.rb +16 -0
- data/lib/shoperb_liquid/filters/url_filters.rb +60 -0
- data/lib/shoperb_liquid/registers.rb +76 -0
- data/lib/shoperb_liquid/tags/cache_tag.rb +45 -0
- data/lib/shoperb_liquid/tags/form_tag.rb +47 -0
- data/lib/shoperb_liquid/tags/layout_tag.rb +21 -0
- data/lib/shoperb_liquid/tags/paginate_tag.rb +134 -0
- data/lib/shoperb_liquid/tags/products_filter_tag.rb +106 -0
- data/lib/shoperb_liquid/tags/section_tag.rb +113 -0
- data/lib/shoperb_liquid.rb +46 -0
- data/shoperb_liquid.gemspec +24 -0
- metadata +223 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
class Base < ::Liquid::Drop
|
5
|
+
attr_reader :record
|
6
|
+
|
7
|
+
def initialize(record)
|
8
|
+
@record = record
|
9
|
+
end
|
10
|
+
|
11
|
+
def inspect
|
12
|
+
meths = self.class.invokable_methods - Set["to_liquid","record"]
|
13
|
+
meths.delete_if{|meth| meth.end_with?("_url")}
|
14
|
+
json = meths.each_with_object({}){|meth,h| h[meth] = (public_send(meth).to_s rescue "")}.to_json
|
15
|
+
"#{self.class}(#{record.respond_to?(:id) ? record.id : (id rescue '')})#{json}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def custom_fields
|
19
|
+
return {} unless record.respond_to?(:custom_field_values)
|
20
|
+
|
21
|
+
CustomField.where(klass: record.class.to_s.demodulize, customer_see: true).
|
22
|
+
each_with_object({}) do |cf,hash|
|
23
|
+
hash[cf.handle] = cf.as_json
|
24
|
+
hash[cf.handle]["set_values"] = record.custom_field_values.to_h[cf.handle.to_s]
|
25
|
+
hash[cf.handle]["set_values"] ||= cf.default_values if cf.default_values.select(&:present?).present?
|
26
|
+
hash[cf.handle]["set_values"] ||= []
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def try_int(num)
|
33
|
+
# the fastest way to compare, through float
|
34
|
+
int = num.to_i
|
35
|
+
int.to_f == num.to_f ? int : num
|
36
|
+
end
|
37
|
+
|
38
|
+
def routes
|
39
|
+
ShoperbLiquid.config.routes
|
40
|
+
end
|
41
|
+
|
42
|
+
# if email sets his own customer then use that one
|
43
|
+
def current_customer
|
44
|
+
if @context.key?("customer")
|
45
|
+
@context["customer"]
|
46
|
+
elsif @context.environments[0]&.has_key?("customer")
|
47
|
+
@context.environments[0]["customer"]
|
48
|
+
else
|
49
|
+
controller.current_customer
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def controller
|
54
|
+
@context.registers[:controller]
|
55
|
+
end
|
56
|
+
|
57
|
+
def shop
|
58
|
+
@context && @context["shop"]
|
59
|
+
end
|
60
|
+
|
61
|
+
def current_locale
|
62
|
+
ShoperbLiquid.config.translator.locale
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
class BlogCategoryDrop < Base
|
5
|
+
def initialize(record)
|
6
|
+
@record = record || Category.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def id
|
10
|
+
record.id
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
record.name
|
15
|
+
end
|
16
|
+
|
17
|
+
def handle
|
18
|
+
record.handle
|
19
|
+
end
|
20
|
+
|
21
|
+
def permalink
|
22
|
+
record.permalink
|
23
|
+
end
|
24
|
+
|
25
|
+
def description
|
26
|
+
record.description
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def level
|
31
|
+
record.level
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def image
|
36
|
+
ImageDrop.new(record.image) if record.image
|
37
|
+
end
|
38
|
+
|
39
|
+
def root
|
40
|
+
CategoryDrop.new(record.root)
|
41
|
+
end
|
42
|
+
|
43
|
+
def root?
|
44
|
+
record.root?
|
45
|
+
end
|
46
|
+
|
47
|
+
def blog_posts
|
48
|
+
CollectionDrop.new(record.blog_posts)
|
49
|
+
end
|
50
|
+
|
51
|
+
def posts
|
52
|
+
CollectionDrop.new(record.blog_posts)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
class BlogPostDrop < Base
|
5
|
+
def id
|
6
|
+
record.id
|
7
|
+
end
|
8
|
+
|
9
|
+
def name
|
10
|
+
record.name
|
11
|
+
end
|
12
|
+
|
13
|
+
def handle
|
14
|
+
record.handle
|
15
|
+
end
|
16
|
+
|
17
|
+
def category
|
18
|
+
record.category
|
19
|
+
end
|
20
|
+
|
21
|
+
def image
|
22
|
+
ImageDrop.new(record.image) if record.image
|
23
|
+
end
|
24
|
+
|
25
|
+
def content
|
26
|
+
locals = @context.environments[0].symbolize_keys
|
27
|
+
record.content(@context.registers[:theme], controller, locals)
|
28
|
+
end
|
29
|
+
|
30
|
+
def published_at
|
31
|
+
record.published_at
|
32
|
+
end
|
33
|
+
|
34
|
+
def next
|
35
|
+
self.class.new(nxt) if nxt = record.next
|
36
|
+
end
|
37
|
+
|
38
|
+
def prev
|
39
|
+
self.class.new(prev) if prev = record.prev
|
40
|
+
end
|
41
|
+
|
42
|
+
def url
|
43
|
+
controller.store_blog_post_path(record)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
class CartDrop < Base
|
5
|
+
def id
|
6
|
+
record.id
|
7
|
+
end
|
8
|
+
|
9
|
+
def total
|
10
|
+
record.customer = current_customer
|
11
|
+
record.total
|
12
|
+
end
|
13
|
+
|
14
|
+
def weight
|
15
|
+
record.weight
|
16
|
+
end
|
17
|
+
|
18
|
+
def discount_code
|
19
|
+
record.discount_code
|
20
|
+
end
|
21
|
+
|
22
|
+
def quantity
|
23
|
+
try_int(record.items.sum(:amount))
|
24
|
+
end
|
25
|
+
|
26
|
+
def requires_shipping?
|
27
|
+
record.require_shippable?
|
28
|
+
end
|
29
|
+
|
30
|
+
def notes
|
31
|
+
record.notes
|
32
|
+
end
|
33
|
+
|
34
|
+
def slug
|
35
|
+
record.slug
|
36
|
+
end
|
37
|
+
|
38
|
+
def items
|
39
|
+
CollectionDrop.new(record.items)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
class CartItemDrop < Base
|
5
|
+
def context=(context)
|
6
|
+
super(context)
|
7
|
+
|
8
|
+
@record.cart.customer = current_customer
|
9
|
+
@record.variant.customer = current_customer
|
10
|
+
rescue Exception => e
|
11
|
+
binding.irb
|
12
|
+
end
|
13
|
+
|
14
|
+
def id
|
15
|
+
record.id
|
16
|
+
end
|
17
|
+
|
18
|
+
def sku
|
19
|
+
record.sku
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
record.variant.name
|
24
|
+
end
|
25
|
+
|
26
|
+
def quantity
|
27
|
+
try_int(record.amount)
|
28
|
+
end
|
29
|
+
|
30
|
+
def stock
|
31
|
+
record.stock
|
32
|
+
end
|
33
|
+
|
34
|
+
def weight
|
35
|
+
record.variant.weight
|
36
|
+
end
|
37
|
+
|
38
|
+
def price
|
39
|
+
record.price
|
40
|
+
end
|
41
|
+
|
42
|
+
def pkg_deposit
|
43
|
+
record.variant.pkg_deposit if record.variant.pkg_deposit.present?
|
44
|
+
end
|
45
|
+
|
46
|
+
def discount_price
|
47
|
+
record.variant.active_price if record.variant.discount.present?
|
48
|
+
end
|
49
|
+
|
50
|
+
def active_price
|
51
|
+
record.variant.active_price
|
52
|
+
end
|
53
|
+
|
54
|
+
def discount?
|
55
|
+
record.variant.discount.present?
|
56
|
+
end
|
57
|
+
|
58
|
+
def discount_start
|
59
|
+
record.variant.formatted_discount_start
|
60
|
+
end
|
61
|
+
|
62
|
+
def discount_end
|
63
|
+
record.variant.formatted_discount_end
|
64
|
+
end
|
65
|
+
|
66
|
+
def total
|
67
|
+
record.total
|
68
|
+
end
|
69
|
+
|
70
|
+
def total_weight
|
71
|
+
record.weight
|
72
|
+
end
|
73
|
+
|
74
|
+
def requires_taxing?
|
75
|
+
record.variant.charge_taxes?
|
76
|
+
end
|
77
|
+
|
78
|
+
def requires_shipping?
|
79
|
+
!digital?
|
80
|
+
end
|
81
|
+
|
82
|
+
def digital?
|
83
|
+
record.variant.digital?
|
84
|
+
end
|
85
|
+
|
86
|
+
def by_subscription
|
87
|
+
record.by_subscription
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
def item_original_id
|
92
|
+
record.item_original_id
|
93
|
+
end
|
94
|
+
|
95
|
+
def vendor
|
96
|
+
VendorDrop.new(record.vendor)
|
97
|
+
end
|
98
|
+
|
99
|
+
def type
|
100
|
+
ProductTypeDrop.new(record.product.product_type)
|
101
|
+
end
|
102
|
+
|
103
|
+
def product
|
104
|
+
ProductDrop.new(record.product)
|
105
|
+
end
|
106
|
+
|
107
|
+
def variant
|
108
|
+
VariantDrop.new(record.variant)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
class CategoriesDrop < CollectionDrop
|
5
|
+
def initialize(collection=nil)
|
6
|
+
@collection = (collection || Category).active
|
7
|
+
end
|
8
|
+
|
9
|
+
def roots
|
10
|
+
CategoriesDrop.new(Category.roots.active)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
class CategoryDrop < Base
|
5
|
+
def initialize(record)
|
6
|
+
@record = record || Category.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def id
|
10
|
+
record.id
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
record.name
|
15
|
+
end
|
16
|
+
|
17
|
+
def handle
|
18
|
+
record.handle
|
19
|
+
end
|
20
|
+
|
21
|
+
def permalink
|
22
|
+
record.permalink
|
23
|
+
end
|
24
|
+
|
25
|
+
def description
|
26
|
+
record.description
|
27
|
+
end
|
28
|
+
|
29
|
+
def parent
|
30
|
+
record.parent
|
31
|
+
end
|
32
|
+
|
33
|
+
def level
|
34
|
+
record.level
|
35
|
+
end
|
36
|
+
|
37
|
+
def url
|
38
|
+
record.id ? controller.store_category_path(record) : ""
|
39
|
+
end
|
40
|
+
|
41
|
+
def image
|
42
|
+
ImageDrop.new(record.image) if record.image
|
43
|
+
end
|
44
|
+
|
45
|
+
def root
|
46
|
+
CategoryDrop.new(record.root)
|
47
|
+
end
|
48
|
+
|
49
|
+
def root?
|
50
|
+
record.root?
|
51
|
+
end
|
52
|
+
|
53
|
+
def current?
|
54
|
+
record == current_category
|
55
|
+
end
|
56
|
+
|
57
|
+
def open?
|
58
|
+
current_category && current_category.descends_from(record)
|
59
|
+
end
|
60
|
+
|
61
|
+
def descends_from(other)
|
62
|
+
record.descends_from(other)
|
63
|
+
end
|
64
|
+
|
65
|
+
def parents
|
66
|
+
CategoriesDrop.new(record.ancestors)
|
67
|
+
end
|
68
|
+
|
69
|
+
def children
|
70
|
+
CategoriesDrop.new(record.children)
|
71
|
+
end
|
72
|
+
|
73
|
+
def children?
|
74
|
+
record.children.any?
|
75
|
+
end
|
76
|
+
|
77
|
+
def products
|
78
|
+
ProductsDrop.new(record.products.includes(:variants))
|
79
|
+
end
|
80
|
+
|
81
|
+
def products_with_children
|
82
|
+
ProductsDrop.new(record.products_for_self_and_children)
|
83
|
+
end
|
84
|
+
|
85
|
+
def as_json(incl_children: false)
|
86
|
+
out={
|
87
|
+
id: id,
|
88
|
+
name: name,
|
89
|
+
permalink: permalink,
|
90
|
+
handle: handle,
|
91
|
+
description: description,
|
92
|
+
products_count: products_with_children.count,
|
93
|
+
has_children: children?,
|
94
|
+
url: url,
|
95
|
+
}
|
96
|
+
|
97
|
+
out[:children] = record.children.map do |e|
|
98
|
+
e.to_liquid(@context).as_json(incl_children: incl_children)
|
99
|
+
end if incl_children
|
100
|
+
|
101
|
+
out
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def current_category
|
107
|
+
controller.instance_variable_get("@category")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
class CollectionDrop < Liquid::Drop
|
5
|
+
include Pagy::Backend
|
6
|
+
|
7
|
+
attr_reader :collection
|
8
|
+
|
9
|
+
def initialize(collection=nil)
|
10
|
+
@collection = collection || []
|
11
|
+
end
|
12
|
+
|
13
|
+
def liquid_method_missing(method)
|
14
|
+
collection.detect { |o| o.try(handle_method.to_sym) == method.to_s }
|
15
|
+
end
|
16
|
+
|
17
|
+
def each
|
18
|
+
collection.each do |item|
|
19
|
+
yield item.to_liquid
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def count
|
24
|
+
collection.size
|
25
|
+
end
|
26
|
+
|
27
|
+
def size
|
28
|
+
collection.size
|
29
|
+
end
|
30
|
+
|
31
|
+
def any?
|
32
|
+
collection.any?
|
33
|
+
end
|
34
|
+
|
35
|
+
def many?
|
36
|
+
collection.many?
|
37
|
+
end
|
38
|
+
|
39
|
+
def one?
|
40
|
+
collection.one?
|
41
|
+
end
|
42
|
+
|
43
|
+
def empty?
|
44
|
+
collection.empty?
|
45
|
+
end
|
46
|
+
|
47
|
+
def none?
|
48
|
+
empty?
|
49
|
+
end
|
50
|
+
|
51
|
+
def first
|
52
|
+
collection.first.try(:to_liquid)
|
53
|
+
end
|
54
|
+
|
55
|
+
def last
|
56
|
+
collection.last.try(:to_liquid)
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_a
|
60
|
+
collection.map(&:to_liquid)
|
61
|
+
end
|
62
|
+
|
63
|
+
def to_json
|
64
|
+
collection.to_json
|
65
|
+
end
|
66
|
+
|
67
|
+
def inspect
|
68
|
+
to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
def pluck(key)
|
72
|
+
to_a.collect(&key.to_sym)
|
73
|
+
end
|
74
|
+
|
75
|
+
def sorted
|
76
|
+
@collection = collection.sorted
|
77
|
+
self
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_s
|
81
|
+
self.class.to_s
|
82
|
+
end
|
83
|
+
|
84
|
+
protected
|
85
|
+
|
86
|
+
def paginate(page, per_page)
|
87
|
+
pagy, items = if (collection.respond_to?(:paginate))
|
88
|
+
collection.paginate(page, per_page)
|
89
|
+
|
90
|
+
elsif collection.is_a?(Array)
|
91
|
+
# copy of pagy/extras/array
|
92
|
+
pagy = Pagy.new(count: collection.size, page: page, limit: per_page)
|
93
|
+
[pagy, collection[pagy.offset, pagy.limit]]
|
94
|
+
|
95
|
+
else
|
96
|
+
loc_coll = collection.dup
|
97
|
+
# support for shoperb website when it tries not to load all data at once
|
98
|
+
loc_coll = loc_coll.unscope(:limit,:offset) if loc_coll.respond_to?(:unscope)
|
99
|
+
pagy(loc_coll, limit: per_page, page: page)
|
100
|
+
end
|
101
|
+
|
102
|
+
return pagy, self.class.new(items)
|
103
|
+
end
|
104
|
+
|
105
|
+
def limit_value
|
106
|
+
(collection.respond_to?(:limit_value) && collection.limit_value) || 50
|
107
|
+
end
|
108
|
+
|
109
|
+
def limited
|
110
|
+
(collection.respond_to?(:limit) && collection.limit(limit_value)) || collection.slice(0..limit_value)
|
111
|
+
end
|
112
|
+
|
113
|
+
def handle_method
|
114
|
+
:handle
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
class CountryDrop < Base
|
5
|
+
def code
|
6
|
+
record.code
|
7
|
+
end
|
8
|
+
|
9
|
+
def name
|
10
|
+
record.name
|
11
|
+
end
|
12
|
+
|
13
|
+
def iso3
|
14
|
+
record.iso3
|
15
|
+
end
|
16
|
+
|
17
|
+
def numeric
|
18
|
+
record.numeric
|
19
|
+
end
|
20
|
+
|
21
|
+
def eu
|
22
|
+
record.eu
|
23
|
+
end
|
24
|
+
|
25
|
+
def na
|
26
|
+
record.na
|
27
|
+
end
|
28
|
+
|
29
|
+
def abstract
|
30
|
+
record.abstract
|
31
|
+
end
|
32
|
+
|
33
|
+
def states_json
|
34
|
+
record.states.as_json(only: [:name, :code])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
class CustomerCreditDrop < Base
|
5
|
+
|
6
|
+
def id
|
7
|
+
record.id
|
8
|
+
end
|
9
|
+
|
10
|
+
def amount
|
11
|
+
record.amount
|
12
|
+
end
|
13
|
+
|
14
|
+
def amount_left
|
15
|
+
record.amount_left
|
16
|
+
end
|
17
|
+
|
18
|
+
def expires_at
|
19
|
+
record.expires_at
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShoperbLiquid
|
4
|
+
class CustomerCreditsDrop < CollectionDrop
|
5
|
+
def initialize(collection=nil)
|
6
|
+
@collection = (collection || CustomerCredit.none)
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid
|
10
|
+
@collection = @collection.valid
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def total
|
15
|
+
@collection.sum(:amount_left)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|