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.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rubocop.yml +131 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +143 -0
  7. data/Rakefile +4 -0
  8. data/lib/shoperb_liquid/configuration.rb +169 -0
  9. data/lib/shoperb_liquid/drops/account_drop.rb +9 -0
  10. data/lib/shoperb_liquid/drops/address_drop.rb +121 -0
  11. data/lib/shoperb_liquid/drops/array_drop.rb +18 -0
  12. data/lib/shoperb_liquid/drops/attribute_drop.rb +21 -0
  13. data/lib/shoperb_liquid/drops/base.rb +65 -0
  14. data/lib/shoperb_liquid/drops/blog_category_drop.rb +56 -0
  15. data/lib/shoperb_liquid/drops/blog_post_drop.rb +46 -0
  16. data/lib/shoperb_liquid/drops/cart_drop.rb +42 -0
  17. data/lib/shoperb_liquid/drops/cart_item_drop.rb +111 -0
  18. data/lib/shoperb_liquid/drops/categories_drop.rb +13 -0
  19. data/lib/shoperb_liquid/drops/category_drop.rb +110 -0
  20. data/lib/shoperb_liquid/drops/collection_drop.rb +117 -0
  21. data/lib/shoperb_liquid/drops/country_drop.rb +37 -0
  22. data/lib/shoperb_liquid/drops/currency_drop.rb +17 -0
  23. data/lib/shoperb_liquid/drops/customer_credit_drop.rb +23 -0
  24. data/lib/shoperb_liquid/drops/customer_credits_drop.rb +18 -0
  25. data/lib/shoperb_liquid/drops/customer_drop.rb +108 -0
  26. data/lib/shoperb_liquid/drops/customer_group_drop.rb +17 -0
  27. data/lib/shoperb_liquid/drops/gift_card_drop.rb +34 -0
  28. data/lib/shoperb_liquid/drops/image_drop.rb +27 -0
  29. data/lib/shoperb_liquid/drops/integration_drop.rb +25 -0
  30. data/lib/shoperb_liquid/drops/integrations_drop.rb +17 -0
  31. data/lib/shoperb_liquid/drops/language_drop.rb +17 -0
  32. data/lib/shoperb_liquid/drops/link_drop.rb +53 -0
  33. data/lib/shoperb_liquid/drops/media_file_drop.rb +29 -0
  34. data/lib/shoperb_liquid/drops/menu_drop.rb +25 -0
  35. data/lib/shoperb_liquid/drops/menus_drop.rb +16 -0
  36. data/lib/shoperb_liquid/drops/meta_drop.rb +21 -0
  37. data/lib/shoperb_liquid/drops/order_drop.rb +148 -0
  38. data/lib/shoperb_liquid/drops/order_item_attribute_drop.rb +8 -0
  39. data/lib/shoperb_liquid/drops/order_item_attributes_drop.rb +19 -0
  40. data/lib/shoperb_liquid/drops/order_item_drop.rb +159 -0
  41. data/lib/shoperb_liquid/drops/order_return_drop.rb +43 -0
  42. data/lib/shoperb_liquid/drops/order_return_item_drop.rb +30 -0
  43. data/lib/shoperb_liquid/drops/order_return_item_entity_drop.rb +13 -0
  44. data/lib/shoperb_liquid/drops/order_return_parcel_drop.rb +29 -0
  45. data/lib/shoperb_liquid/drops/order_returns_drop.rb +13 -0
  46. data/lib/shoperb_liquid/drops/orders_drop.rb +14 -0
  47. data/lib/shoperb_liquid/drops/page_drop.rb +26 -0
  48. data/lib/shoperb_liquid/drops/pages_drop.rb +12 -0
  49. data/lib/shoperb_liquid/drops/payment_card_drop.rb +29 -0
  50. data/lib/shoperb_liquid/drops/payment_method_drop.rb +41 -0
  51. data/lib/shoperb_liquid/drops/payment_provider_drop.rb +23 -0
  52. data/lib/shoperb_liquid/drops/product_attribute_drop.rb +14 -0
  53. data/lib/shoperb_liquid/drops/product_collection_drop.rb +41 -0
  54. data/lib/shoperb_liquid/drops/product_collections_drop.rb +12 -0
  55. data/lib/shoperb_liquid/drops/product_drop.rb +195 -0
  56. data/lib/shoperb_liquid/drops/product_type_drop.rb +25 -0
  57. data/lib/shoperb_liquid/drops/product_types_drop.rb +15 -0
  58. data/lib/shoperb_liquid/drops/products_drop.rb +44 -0
  59. data/lib/shoperb_liquid/drops/refund_drop.rb +22 -0
  60. data/lib/shoperb_liquid/drops/refund_item_drop.rb +18 -0
  61. data/lib/shoperb_liquid/drops/review_drop.rb +37 -0
  62. data/lib/shoperb_liquid/drops/search_drop.rb +45 -0
  63. data/lib/shoperb_liquid/drops/shipping_item_drop.rb +29 -0
  64. data/lib/shoperb_liquid/drops/shipping_method_drop.rb +25 -0
  65. data/lib/shoperb_liquid/drops/shipping_parcel_drop.rb +25 -0
  66. data/lib/shoperb_liquid/drops/shop_drop.rb +81 -0
  67. data/lib/shoperb_liquid/drops/subscription_drop.rb +51 -0
  68. data/lib/shoperb_liquid/drops/subscription_plan_drop.rb +63 -0
  69. data/lib/shoperb_liquid/drops/theme_section_blocks_drop.rb +19 -0
  70. data/lib/shoperb_liquid/drops/theme_section_drop.rb +30 -0
  71. data/lib/shoperb_liquid/drops/theme_section_image_drop.rb +11 -0
  72. data/lib/shoperb_liquid/drops/theme_section_settings_drop.rb +40 -0
  73. data/lib/shoperb_liquid/drops/theme_settings_drop.rb +60 -0
  74. data/lib/shoperb_liquid/drops/url_drop.rb +218 -0
  75. data/lib/shoperb_liquid/drops/variant_attribute_drop.rb +8 -0
  76. data/lib/shoperb_liquid/drops/variant_drop.rb +206 -0
  77. data/lib/shoperb_liquid/drops/variants_drop.rb +13 -0
  78. data/lib/shoperb_liquid/drops/vendor_drop.rb +77 -0
  79. data/lib/shoperb_liquid/drops/vendors_drop.rb +13 -0
  80. data/lib/shoperb_liquid/errors.rb +6 -0
  81. data/lib/shoperb_liquid/ext/array.rb +7 -0
  82. data/lib/shoperb_liquid/ext/context.rb +12 -0
  83. data/lib/shoperb_liquid/ext/models.rb +55 -0
  84. data/lib/shoperb_liquid/ext/template.rb +13 -0
  85. data/lib/shoperb_liquid/filters/asset_filters.rb +57 -0
  86. data/lib/shoperb_liquid/filters/collection_filters.rb +26 -0
  87. data/lib/shoperb_liquid/filters/datum_filters.rb +150 -0
  88. data/lib/shoperb_liquid/filters/extension_filters.rb +35 -0
  89. data/lib/shoperb_liquid/filters/html_filters.rb +46 -0
  90. data/lib/shoperb_liquid/filters/theme_filters.rb +22 -0
  91. data/lib/shoperb_liquid/filters/translate_filters.rb +16 -0
  92. data/lib/shoperb_liquid/filters/url_filters.rb +60 -0
  93. data/lib/shoperb_liquid/registers.rb +76 -0
  94. data/lib/shoperb_liquid/tags/cache_tag.rb +45 -0
  95. data/lib/shoperb_liquid/tags/form_tag.rb +47 -0
  96. data/lib/shoperb_liquid/tags/layout_tag.rb +21 -0
  97. data/lib/shoperb_liquid/tags/paginate_tag.rb +134 -0
  98. data/lib/shoperb_liquid/tags/products_filter_tag.rb +106 -0
  99. data/lib/shoperb_liquid/tags/section_tag.rb +113 -0
  100. data/lib/shoperb_liquid.rb +46 -0
  101. data/shoperb_liquid.gemspec +24 -0
  102. metadata +223 -0
@@ -0,0 +1,159 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class OrderItemDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+
9
+ def name
10
+ record.name
11
+ end
12
+
13
+ def quantity
14
+ try_int(record.amount)
15
+ end
16
+
17
+ alias_method :qty, :quantity
18
+
19
+ def order
20
+ OrderDrop.new(record.order)
21
+ end
22
+
23
+ def amount_step
24
+ record.amount_step
25
+ end
26
+
27
+ def amount_step_unit
28
+ record.amount_step_unit
29
+ end
30
+
31
+ def sku
32
+ record.sku
33
+ end
34
+
35
+ def attributes
36
+ OrderItemAttributesDrop.new(record.item_attributes)
37
+ end
38
+
39
+ def weight
40
+ record.weight
41
+ end
42
+
43
+ def width
44
+ record.width
45
+ end
46
+
47
+ def height
48
+ record.height
49
+ end
50
+
51
+ def depth
52
+ record.depth
53
+ end
54
+
55
+ def price
56
+ record.price
57
+ end
58
+
59
+ def pkg_deposit
60
+ record.pkg_deposit
61
+ end
62
+
63
+ def subtotal
64
+ record.total_without_taxes
65
+ end
66
+
67
+ def total
68
+ record.total_wout_correlation
69
+ end
70
+
71
+ def total_weight
72
+ record.total_weight
73
+ end
74
+
75
+ def total_taxes
76
+ record.total_taxes
77
+ end
78
+
79
+ def requires_shipping?
80
+ !digital?
81
+ end
82
+
83
+ def digital?
84
+ record.digital?
85
+ end
86
+
87
+ def by_subscription?
88
+ record.by_subscription
89
+ end
90
+
91
+ def item_original_id
92
+ record.item_original_id
93
+ end
94
+
95
+ def money_was_repaid?
96
+ OrderItem.where(item_original_id: record.id).exists?
97
+ end
98
+
99
+ def url
100
+ record.url
101
+ end
102
+
103
+ def download_url
104
+ record.download_url
105
+ end
106
+
107
+ def requires_taxation?
108
+ record.charge_taxes?
109
+ end
110
+
111
+ def category
112
+ record.category&.name
113
+ end
114
+
115
+ def product_id
116
+ record.product_id
117
+ end
118
+
119
+ def product
120
+ ProductDrop.new(record.product)
121
+ end
122
+
123
+ def variant_id
124
+ record.variant_id
125
+ end
126
+
127
+ def brand
128
+ VendorDrop.new(record.brand)
129
+ end
130
+
131
+ def product_name
132
+ record.product&.name
133
+ end
134
+
135
+ def product_url
136
+ product.url
137
+ end
138
+
139
+ def product_url_full
140
+ product.url_full
141
+ end
142
+
143
+ def image
144
+ @image ||= variant_image || images.first
145
+ end
146
+
147
+ def variant_image
148
+ ImageDrop.new(record.variant.image) if record.variant && record.variant.image
149
+ end
150
+
151
+ def images
152
+ if pr = record.product
153
+ CollectionDrop.new(pr.images.sorted)
154
+ else
155
+ []
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class OrderReturnDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+
9
+ def labeled_number
10
+ record.labeled_number
11
+ end
12
+
13
+ def delivery_date
14
+ record.delivery_date
15
+ end
16
+ def comment
17
+ record.comment
18
+ end
19
+ def state
20
+ record.state
21
+ end
22
+
23
+ def items
24
+ CollectionDrop.new(record.items)
25
+ end
26
+
27
+ def parcel
28
+ record.return_parcel&.to_liquid
29
+ end
30
+
31
+ def created_at
32
+ record.created_at
33
+ end
34
+
35
+ def url
36
+ controller.store_order_return_path(id)
37
+ end
38
+
39
+ def generate_parcel_url
40
+ controller.store_order_return_generate_parcel_path(id)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class OrderReturnItemDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+ def order_item
9
+ OrderItemDrop.new(record.order_item)
10
+ end
11
+
12
+ def amount
13
+ try_int(record.amount)
14
+ end
15
+
16
+ def entities
17
+ CollectionDrop.new(record.entities)
18
+ end
19
+
20
+ def quantity_sent
21
+ try_int(record.quantity_sent)
22
+ end
23
+ def quantity_received
24
+ try_int(record.quantity_received)
25
+ end
26
+ def quantity_requested
27
+ try_int(record.quantity_requested)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class OrderReturnItemEntityDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+
9
+ def customer_comment
10
+ record.customer_comment
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class OrderReturnParcelDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+
9
+ def provider
10
+ record.provider
11
+ end
12
+
13
+ def barcode
14
+ record.barcode
15
+ end
16
+
17
+ def state
18
+ record.state
19
+ end
20
+
21
+ def filename
22
+ record.filename
23
+ end
24
+
25
+ def url
26
+ record.url
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class OrderReturnsDrop < CollectionDrop
5
+ def order_by_id_asc
6
+ collection.by_id("asc")
7
+ end
8
+
9
+ def order_by_id_desc
10
+ collection.by_id("desc")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class OrdersDrop < CollectionDrop
5
+ def initialize(collection=nil)
6
+ @collection = (collection || Order.all)
7
+ end
8
+
9
+ def had_subscription
10
+ @collection = @collection.had_subscription
11
+ self
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class PageDrop < 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 content
18
+ locals = @context.environments[0].symbolize_keys
19
+ record.content(@context.registers[:theme], controller, locals)
20
+ end
21
+
22
+ def url
23
+ controller.store_page_path(record)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class PagesDrop < CollectionDrop
5
+ private
6
+
7
+ def collection
8
+ @collection = Page.all if @collection.empty?
9
+ @collection
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class PaymentCardDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+
9
+ def url
10
+ controller.store_account_billing_payment_method_path(id)
11
+ end
12
+
13
+ def delete_url
14
+ controller.delete_store_account_billing_payment_method_path(id)
15
+ end
16
+
17
+ # stripe
18
+ def service
19
+ record.service
20
+ end
21
+
22
+ # {"name"=>nil, "brand"=>"Visa", "last4"=>"4242",
23
+ # "country"=>"US", "exp_year"=>2022, "exp_month"=>11, "type"=>"credit"}
24
+ def card
25
+ record.card
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class PaymentMethodDrop < Base
5
+ def name
6
+ record.name
7
+ end
8
+
9
+ def display_name
10
+ record.display_name
11
+ end
12
+
13
+ def provider
14
+ record.name
15
+ end
16
+
17
+ def state
18
+ record.state
19
+ end
20
+
21
+ def invoice_instructions
22
+ record.payment_method.invoice_instructions
23
+ end
24
+
25
+ def checkout_instructions
26
+ record.payment_method.instructions
27
+ end
28
+
29
+ def bank_account
30
+ record.payment_method.bank_account
31
+ end
32
+
33
+ def bank_name
34
+ record.payment_method.bank_name
35
+ end
36
+
37
+ def bic_swift_code
38
+ record.payment_method.bic_swift_code
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class PaymentProviderDrop < Base
5
+ def id
6
+ record.id
7
+ end
8
+
9
+ def name
10
+ record.name
11
+ end
12
+
13
+ # stripe
14
+ def type
15
+ record.service
16
+ end
17
+
18
+ # pk_test_JqbMzr2NvnK25D5QEEm0OlZg
19
+ def public_key
20
+ record.public_key
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'attribute_drop'
3
+
4
+ module ShoperbLiquid
5
+ class ProductAttributeDrop < AttributeDrop
6
+ def values
7
+ record.values
8
+ end
9
+
10
+ def value
11
+ record.values.join("; ")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ProductCollectionDrop < 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 permalink
18
+ record.permalink
19
+ end
20
+
21
+ def image
22
+ ImageDrop.new(record.image) if record.image
23
+ end
24
+
25
+ def url
26
+ controller.store_collection_path(record)
27
+ end
28
+
29
+ def description
30
+ record.description
31
+ end
32
+
33
+ def products
34
+ ProductsDrop.new(record.products.includes(:variants))
35
+ end
36
+
37
+ def vendors
38
+ VendorsDrop.new(record.vendors)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ProductCollectionsDrop < CollectionDrop
5
+ private
6
+
7
+ def collection
8
+ @collection = Collection.all if @collection.empty?
9
+ @collection
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,195 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShoperbLiquid
4
+ class ProductDrop < Base
5
+ def context=(context)
6
+ super(context)
7
+ record.customer = current_customer
8
+ end
9
+
10
+ def initialize(record)
11
+ @record = record || ::OpenStruct.new
12
+ end
13
+
14
+ def id
15
+ record.id
16
+ end
17
+
18
+ def name
19
+ record.name
20
+ end
21
+
22
+ def permalink
23
+ record.permalink
24
+ end
25
+
26
+ def handle
27
+ record.permalink
28
+ end
29
+
30
+ def stock
31
+ sum = 0
32
+ variants.each do |v|
33
+ return nil if v.stock.nil?
34
+ sum += v.stock
35
+ end
36
+ sum
37
+ end
38
+
39
+ def url
40
+ controller.store_product_path(record)
41
+ end
42
+
43
+ def url_full
44
+ controller.store_product_url(record, host: shop.domain)
45
+ end
46
+
47
+ def reviews_url
48
+ controller.reviews_store_product_path(record)
49
+ end
50
+
51
+ def dirty_variant_attributes
52
+ if record.dirty_variant_attributes.present?
53
+ record.dirty_variant_attributes
54
+ else
55
+ record.variants.each_with_object({}) do |v,h|
56
+ v.variant_attributes.each do |va|
57
+ h[va.name] ||= []
58
+ h[va.name] |= [va.value]
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def variant_attributes
65
+ locale = I18n.locale
66
+ dirty = dirty_variant_attributes
67
+ i18n = VariantAttribute.
68
+ where(attribute_key: dirty.keys).
69
+ each_with_object({}){|e,h|
70
+ h[e.name]||=e.translations
71
+ break if h.size.eql?(dirty.size)
72
+ }
73
+
74
+ dirty.each_with_object({}) do |(k,v), h|
75
+ h[k] = {
76
+ "title" => i18n[k].to_h["#{locale}.name"] || k,
77
+ "values" => v
78
+ }
79
+ end
80
+ end
81
+
82
+ def max_price
83
+ record.maximum_price
84
+ end
85
+
86
+ def min_price
87
+ record.minimum_price
88
+ end
89
+ alias_method :price, :min_price
90
+
91
+ def min_discount_price
92
+ record.minimum_discount_price
93
+ end
94
+
95
+ def max_discount_price
96
+ record.maximum_discount_price
97
+ end
98
+
99
+ def min_active_price
100
+ record.minimum_active_price
101
+ end
102
+
103
+ def max_active_price
104
+ record.maximum_active_price
105
+ end
106
+
107
+ def available?
108
+ _variants.available.exists?
109
+ end
110
+
111
+ def description
112
+ record.description
113
+ end
114
+
115
+ def options
116
+ record.product_attributes.map(&:value)
117
+ end
118
+
119
+ def tags
120
+ record.grouping_tags
121
+ end
122
+
123
+ def category
124
+ CategoryDrop.new(record.category)
125
+ end
126
+
127
+ def vendor
128
+ brand
129
+ end
130
+
131
+ def brand
132
+ VendorDrop.new(record.vendor)
133
+ end
134
+
135
+ def type
136
+ ProductTypeDrop.new(record.product_type)
137
+ end
138
+
139
+ def variants
140
+ VariantsDrop.new(_variants)
141
+ end
142
+
143
+ def available_variants
144
+ VariantsDrop.new(_variants.available)
145
+ end
146
+
147
+ def image
148
+ ImageDrop.new(record.image) if record.image
149
+ end
150
+
151
+ def images
152
+ CollectionDrop.new(record.images.sorted)
153
+ end
154
+
155
+ def attributes
156
+ CollectionDrop.new(record.product_attributes)
157
+ end
158
+
159
+ def variant_properties
160
+ CollectionDrop.new(record.variant_attributes)
161
+ end
162
+
163
+ def similar_products
164
+ ProductsDrop.new(record.similar)
165
+ end
166
+
167
+ def related_products
168
+ ProductsDrop.new(record.related_products)
169
+ end
170
+
171
+ def others_in_category
172
+ return ProductsDrop.new(Product.none) unless record.category
173
+
174
+ ProductsDrop.new(record.category.products_for_self_and_children.where.not(id: record.id))
175
+ end
176
+
177
+ def reviews
178
+ CollectionDrop.new(record.reviews.visible.with_content)
179
+ end
180
+
181
+ def reviewable?
182
+ record.reviewable?(current_customer)
183
+ end
184
+
185
+ def rating
186
+ record.rating
187
+ end
188
+
189
+ private
190
+
191
+ def _variants
192
+ record.variants
193
+ end
194
+ end
195
+ end