workarea-global_e 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (232) hide show
  1. checksums.yaml +7 -0
  2. data/.eslintrc.json +37 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.github/workflows/ci.yml +77 -0
  7. data/.gitignore +20 -0
  8. data/.rubocop.yml +2 -0
  9. data/.ruby-version +1 -0
  10. data/CHANGELOG.md +261 -0
  11. data/Gemfile +16 -0
  12. data/README.md +39 -0
  13. data/Rakefile +59 -0
  14. data/app/assets/javascripts/workarea/storefront/global_e/modules/checkout_info_validator.js +122 -0
  15. data/app/assets/javascripts/workarea/storefront/global_e/modules/suppress_price_ranges.js +19 -0
  16. data/app/controllers/workarea/admin/country_exceptions_controller.rb +67 -0
  17. data/app/controllers/workarea/admin/fixed_prices_controller.rb +89 -0
  18. data/app/controllers/workarea/admin/orders_controller.decorator +6 -0
  19. data/app/controllers/workarea/storefront/application_controller.decorator +30 -0
  20. data/app/controllers/workarea/storefront/checkouts_controller.decorator +22 -0
  21. data/app/controllers/workarea/storefront/ge_checkouts_controller.rb +10 -0
  22. data/app/controllers/workarea/storefront/global_e_controller.rb +42 -0
  23. data/app/controllers/workarea/storefront/globale/api_controller.rb +108 -0
  24. data/app/controllers/workarea/storefront/globale/refund_controller.rb +65 -0
  25. data/app/controllers/workarea/storefront/users/logins_controller.decorator +13 -0
  26. data/app/helpers/workarea/admin/global_e_helpers.rb +28 -0
  27. data/app/models/workarea/address.decorator +11 -0
  28. data/app/models/workarea/catalog/product.decorator +14 -0
  29. data/app/models/workarea/fulfillment/status/partially_refunded.rb +13 -0
  30. data/app/models/workarea/fulfillment/status/refunded.rb +15 -0
  31. data/app/models/workarea/fulfillment.decorator +55 -0
  32. data/app/models/workarea/global_e/country_exception.rb +37 -0
  33. data/app/models/workarea/global_e/fixed_price.rb +93 -0
  34. data/app/models/workarea/global_e/order_api_events.rb +29 -0
  35. data/app/models/workarea/order/item.decorator +46 -0
  36. data/app/models/workarea/order/status/pending_global_e_fraud_check.rb +12 -0
  37. data/app/models/workarea/order.decorator +64 -0
  38. data/app/models/workarea/payment/status/global_e_appoved.rb +9 -0
  39. data/app/models/workarea/payment/status/pending_global_e_fraud_check.rb +9 -0
  40. data/app/models/workarea/payment/tender/global_e_payment.rb +16 -0
  41. data/app/models/workarea/payment.decorator +10 -0
  42. data/app/models/workarea/price_adjustment.decorator +13 -0
  43. data/app/models/workarea/price_adjustment_set.decorator +25 -0
  44. data/app/models/workarea/pricing/calculators/item_calculator.decorator +48 -0
  45. data/app/models/workarea/pricing/collection.decorator +90 -0
  46. data/app/models/workarea/pricing/discount/appliation_group.decorator +16 -0
  47. data/app/models/workarea/pricing/discount/international_item_proxy.rb +27 -0
  48. data/app/models/workarea/pricing/discount/international_order.rb +29 -0
  49. data/app/models/workarea/pricing/discount.decorator +65 -0
  50. data/app/models/workarea/pricing/price_distributor.decorator +37 -0
  51. data/app/models/workarea/pricing/request.decorator +17 -0
  52. data/app/models/workarea/pricing/sku.decorator +17 -0
  53. data/app/models/workarea/search/admin/order.decorator +11 -0
  54. data/app/models/workarea/shipping/sku.decorator +23 -0
  55. data/app/models/workarea/shipping.decorator +11 -0
  56. data/app/models/workarea/user.decorator +10 -0
  57. data/app/seeds/workarea/global_e_seeds.rb +66 -0
  58. data/app/services/workarea/create_fulfillment.decorator +12 -0
  59. data/app/services/workarea/global_e/address_details.rb +218 -0
  60. data/app/services/workarea/global_e/api/notify_order_refunded.rb +45 -0
  61. data/app/services/workarea/global_e/api/perform_order_payment.rb +46 -0
  62. data/app/services/workarea/global_e/api/remove_restricted_products.rb +28 -0
  63. data/app/services/workarea/global_e/api/send_order_to_merchant/item_pricer.rb +147 -0
  64. data/app/services/workarea/global_e/api/send_order_to_merchant/save_user.rb +59 -0
  65. data/app/services/workarea/global_e/api/send_order_to_merchant.rb +359 -0
  66. data/app/services/workarea/global_e/api/update_order_shipping_info.rb +38 -0
  67. data/app/services/workarea/global_e/api/update_order_status/canceled.rb +42 -0
  68. data/app/services/workarea/global_e/api/update_order_status.rb +28 -0
  69. data/app/services/workarea/global_e/attribute.rb +44 -0
  70. data/app/services/workarea/global_e/brand.rb +19 -0
  71. data/app/services/workarea/global_e/cart_user_details.rb +34 -0
  72. data/app/services/workarea/global_e/category.rb +19 -0
  73. data/app/services/workarea/global_e/checkout_cart_info.rb +358 -0
  74. data/app/services/workarea/global_e/custom_product_attribute.rb +19 -0
  75. data/app/services/workarea/global_e/discount.rb +215 -0
  76. data/app/services/workarea/global_e/merchant/brand.rb +21 -0
  77. data/app/services/workarea/global_e/merchant/category.rb +21 -0
  78. data/app/services/workarea/global_e/merchant/customer.rb +36 -0
  79. data/app/services/workarea/global_e/merchant/customer_details.rb +201 -0
  80. data/app/services/workarea/global_e/merchant/discount.rb +127 -0
  81. data/app/services/workarea/global_e/merchant/international_details.rb +296 -0
  82. data/app/services/workarea/global_e/merchant/order.rb +425 -0
  83. data/app/services/workarea/global_e/merchant/order_refund.rb +103 -0
  84. data/app/services/workarea/global_e/merchant/original_order.rb +28 -0
  85. data/app/services/workarea/global_e/merchant/parcel_tracking.rb +31 -0
  86. data/app/services/workarea/global_e/merchant/payment_details.rb +161 -0
  87. data/app/services/workarea/global_e/merchant/product.rb +222 -0
  88. data/app/services/workarea/global_e/merchant/refund_product.rb +69 -0
  89. data/app/services/workarea/global_e/merchant/response_info.rb +115 -0
  90. data/app/services/workarea/global_e/merchant_cart_product_attribute.rb +21 -0
  91. data/app/services/workarea/global_e/order_status.rb +20 -0
  92. data/app/services/workarea/global_e/order_status_details.rb +79 -0
  93. data/app/services/workarea/global_e/order_status_reason.rb +20 -0
  94. data/app/services/workarea/global_e/parcel.rb +53 -0
  95. data/app/services/workarea/global_e/product.rb +612 -0
  96. data/app/services/workarea/global_e/product_meta_data.rb +13 -0
  97. data/app/services/workarea/global_e/tracking_details.rb +23 -0
  98. data/app/services/workarea/global_e/update_order_dispatch_exception.rb +46 -0
  99. data/app/services/workarea/global_e/update_order_dispatch_request.rb +108 -0
  100. data/app/services/workarea/global_e/user_id_number_type.rb +21 -0
  101. data/app/services/workarea/global_e/users_details.rb +151 -0
  102. data/app/services/workarea/global_e/vat_category.rb +20 -0
  103. data/app/services/workarea/global_e/vat_rate_type.rb +27 -0
  104. data/app/services/workarea/save_order_analytics.decorator +18 -0
  105. data/app/view_models/workarea/admin/order_view_model.decorator +13 -0
  106. data/app/view_models/workarea/storefront/cart_view_model.decorator +7 -0
  107. data/app/view_models/workarea/storefront/order_item_view_model.decorator +16 -0
  108. data/app/view_models/workarea/storefront/order_view_model.decorator +45 -0
  109. data/app/view_models/workarea/storefront/product_view_model.decorator +35 -0
  110. data/app/views/workarea/admin/catalog_products/_country_exceptions_card.html.haml +31 -0
  111. data/app/views/workarea/admin/catalog_products/_global_e_attributes.html.haml +3 -0
  112. data/app/views/workarea/admin/catalog_products/_global_e_fields.html.haml +4 -0
  113. data/app/views/workarea/admin/country_exceptions/edit.html.haml +48 -0
  114. data/app/views/workarea/admin/country_exceptions/index.html.haml +47 -0
  115. data/app/views/workarea/admin/country_exceptions/new.html.haml +44 -0
  116. data/app/views/workarea/admin/fixed_prices/edit.html.haml +73 -0
  117. data/app/views/workarea/admin/fixed_prices/index.html.haml +55 -0
  118. data/app/views/workarea/admin/fixed_prices/new.html.haml +70 -0
  119. data/app/views/workarea/admin/orders/_global_e.html.haml +27 -0
  120. data/app/views/workarea/admin/orders/attributes.html.haml +131 -0
  121. data/app/views/workarea/admin/orders/global_e.html.haml +110 -0
  122. data/app/views/workarea/admin/orders/show.html.haml +27 -0
  123. data/app/views/workarea/admin/orders/tenders/_global_e_payment.html.haml +3 -0
  124. data/app/views/workarea/admin/pricing_skus/_cards.html.haml +98 -0
  125. data/app/views/workarea/storefront/cart_items/create.html.haml +71 -0
  126. data/app/views/workarea/storefront/carts/_pricing.html.haml +14 -0
  127. data/app/views/workarea/storefront/carts/show.html.haml +187 -0
  128. data/app/views/workarea/storefront/ge_checkouts/show.html.haml +1 -0
  129. data/app/views/workarea/storefront/global_e/_country_picker.html.haml +1 -0
  130. data/app/views/workarea/storefront/global_e/_head.html.haml +10 -0
  131. data/app/views/workarea/storefront/orders/_summary.html.haml +275 -0
  132. data/app/views/workarea/storefront/orders/tenders/_global_e_payment.html.haml +3 -0
  133. data/app/views/workarea/storefront/products/_pricing.html.haml +49 -0
  134. data/app/views/workarea/storefront/products/_restricted_item_text.html.haml +1 -0
  135. data/app/views/workarea/storefront/users/orders/_summary.html.haml +22 -0
  136. data/app/workers/workarea/global_e/update_order_dispatch.rb +28 -0
  137. data/app/workers/workarea/save_user_order_details.decorator +9 -0
  138. data/bin/rails +25 -0
  139. data/config/initializers/appends.rb +46 -0
  140. data/config/initializers/seeds.rb +1 -0
  141. data/config/initializers/workarea.rb +64 -0
  142. data/config/locales/en.yml +105 -0
  143. data/config/routes.rb +31 -0
  144. data/lib/workarea/global_e/engine.rb +10 -0
  145. data/lib/workarea/global_e/error.rb +8 -0
  146. data/lib/workarea/global_e/version.rb +5 -0
  147. data/lib/workarea/global_e.rb +58 -0
  148. data/script/admin_ci +5 -0
  149. data/script/ci +8 -0
  150. data/script/core_ci +5 -0
  151. data/script/plugins_ci +5 -0
  152. data/script/storefront_ci +5 -0
  153. data/test/dummy/.ruby-version +1 -0
  154. data/test/dummy/Rakefile +6 -0
  155. data/test/dummy/app/assets/config/manifest.js +3 -0
  156. data/test/dummy/app/assets/images/.keep +0 -0
  157. data/test/dummy/app/assets/javascripts/application.js +14 -0
  158. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  159. data/test/dummy/app/controllers/application_controller.rb +2 -0
  160. data/test/dummy/app/controllers/concerns/.keep +0 -0
  161. data/test/dummy/app/helpers/application_helper.rb +2 -0
  162. data/test/dummy/app/jobs/application_job.rb +2 -0
  163. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  164. data/test/dummy/app/models/concerns/.keep +0 -0
  165. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  166. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  167. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  168. data/test/dummy/bin/bundle +3 -0
  169. data/test/dummy/bin/rails +4 -0
  170. data/test/dummy/bin/rake +4 -0
  171. data/test/dummy/bin/setup +28 -0
  172. data/test/dummy/bin/update +28 -0
  173. data/test/dummy/bin/yarn +11 -0
  174. data/test/dummy/config/application.rb +23 -0
  175. data/test/dummy/config/boot.rb +5 -0
  176. data/test/dummy/config/environment.rb +5 -0
  177. data/test/dummy/config/environments/development.rb +52 -0
  178. data/test/dummy/config/environments/production.rb +83 -0
  179. data/test/dummy/config/environments/test.rb +45 -0
  180. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  181. data/test/dummy/config/initializers/assets.rb +14 -0
  182. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  183. data/test/dummy/config/initializers/content_security_policy.rb +25 -0
  184. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  185. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  186. data/test/dummy/config/initializers/inflections.rb +16 -0
  187. data/test/dummy/config/initializers/mime_types.rb +4 -0
  188. data/test/dummy/config/initializers/workarea.rb +5 -0
  189. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  190. data/test/dummy/config/locales/en.yml +33 -0
  191. data/test/dummy/config/puma.rb +34 -0
  192. data/test/dummy/config/routes.rb +5 -0
  193. data/test/dummy/config/secrets.yml +18 -0
  194. data/test/dummy/config/spring.rb +6 -0
  195. data/test/dummy/config.ru +5 -0
  196. data/test/dummy/db/seeds.rb +2 -0
  197. data/test/dummy/lib/assets/.keep +0 -0
  198. data/test/dummy/log/.keep +0 -0
  199. data/test/factories/workarea/global_e_factories.rb +836 -0
  200. data/test/integration/workarea/admin/catalog_product_country_exceptions_integration_test.rb +81 -0
  201. data/test/integration/workarea/admin/global_e_jump_to_integration_test.rb +20 -0
  202. data/test/integration/workarea/admin/pricing_sku_fixed_prices_integration_test.rb +83 -0
  203. data/test/integration/workarea/storefront/global_e_api/receive_order_integration_test.rb +278 -0
  204. data/test/integration/workarea/storefront/global_e_api/receive_order_refund_integration_test.rb +25 -0
  205. data/test/integration/workarea/storefront/global_e_api/receive_payment_integration_test.rb +34 -0
  206. data/test/integration/workarea/storefront/global_e_api/receive_shipping_info_integration_test.rb +29 -0
  207. data/test/integration/workarea/storefront/global_e_api/remove_restricted_products_integration_test.rb +27 -0
  208. data/test/integration/workarea/storefront/global_e_api/update_order_status_integration_test.rb +29 -0
  209. data/test/integration/workarea/storefront/global_e_checkout_cart_info/fixed_pricing_test.rb +438 -0
  210. data/test/integration/workarea/storefront/global_e_checkout_cart_info/gift_card_test.rb +63 -0
  211. data/test/integration/workarea/storefront/global_e_checkout_cart_info_integration_test.rb +660 -0
  212. data/test/integration/workarea/storefront/global_e_checkouts_integration_test.rb +71 -0
  213. data/test/integration/workarea/storefront/users/global_e_logins_integration_test.rb +20 -0
  214. data/test/models/workarea/catalog/product_global_e_test.rb +13 -0
  215. data/test/models/workarea/fixed_pricing_test.rb +117 -0
  216. data/test/models/workarea/global_e/country_exception_test.rb +36 -0
  217. data/test/models/workarea/payment_test.decorator +31 -0
  218. data/test/models/workarea/pricing/calculators/item_calculator_fixed_prices_test.rb +83 -0
  219. data/test/models/workarea/pricing/collection_fixed_prices_test.rb +83 -0
  220. data/test/models/workarea/pricing/price_distributor_test.decorator +21 -0
  221. data/test/models/workarea/pricing/sku_fixed_price_test.rb +133 -0
  222. data/test/support/workarea/global_e_support.rb +18 -0
  223. data/test/system/workarea/admin/global_e_system_test.rb +21 -0
  224. data/test/system/workarea/storefront/global_e_cart_system_test.rb +48 -0
  225. data/test/system/workarea/storefront/global_e_order_history_system_test.rb +43 -0
  226. data/test/teaspoon_env.rb +6 -0
  227. data/test/test_helper.rb +9 -0
  228. data/test/view_models/workarea/admin/global_e_order_view_model_test.rb +22 -0
  229. data/test/workers/workarea/global_e/update_order_dispatch_test.rb +64 -0
  230. data/test/workers/workarea/global_e_save_user_order_details_test.rb +41 -0
  231. data/workarea-global_e.gemspec +16 -0
  232. metadata +293 -0
@@ -0,0 +1,660 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class GlobalEcheckoutCartInfoIntegrationTest < Workarea::IntegrationTest
6
+ def test_get_checkout_cart_info
7
+ order_discount = create_order_total_discount(promo_codes: %w(TESTCODE))
8
+ product_1 = create_complete_product(
9
+ variants: [{ sku: 'SKU', details: { material: 'Cotton' }, regular: 5.00, sale: 4.00 }]
10
+ )
11
+ product_2 = create_complete_product(
12
+ variants: [{ sku: 'SKU2', details: { material: 'Cotton' }, regular: 5.00, sale: 4.00, on_sale: true }]
13
+ )
14
+ cart = create_cart(
15
+ order: create_order(promo_codes: ['TESTCODE']),
16
+ items: [
17
+ { product: product_1, sku: product_1.skus.first, quantity: 1 },
18
+ { product: product_2, sku: product_2.skus.first, quantity: 1 }
19
+ ]
20
+ )
21
+
22
+ get storefront.global_e_checkout_cart_info_path(cartToken: cart.global_e_token, format: :json)
23
+
24
+ assert response.ok?
25
+ expected_response = {
26
+ "productsList" => [
27
+ {
28
+ "ProductCode" => product_1.skus.first,
29
+ "ProductGroupCode" => product_1.id,
30
+ "CartItemId" => cart.items.first.id.to_s,
31
+ "Name" => product_1.name,
32
+ "Description" => product_1.description,
33
+ "URL" => "http://www.example.com/products/test-product",
34
+ "Weight" => 5.0,
35
+ "Height" => 5,
36
+ "Width" => 5,
37
+ "Length" => 5,
38
+ "ImageURL" => "/product_images/test-product/Cotton/#{product_1.images.first.id}/detail.jpg?c=0",
39
+ "ImageHeight" => 780,
40
+ "ImageWidth" => 780,
41
+ "ListPrice" => 0,
42
+ "OriginalListPrice" => 5.0,
43
+ "SalePrice" => 0,
44
+ "OriginalSalePrice" => 5.0,
45
+ "IsFixedPrice" => false,
46
+ "OrderedQuantity" => 1,
47
+ "IsVirtual" => false,
48
+ "IsBlockedForGlobalE" => false,
49
+ "Attributes" => [
50
+ {
51
+ "AttributeCode" => "material",
52
+ "AttributeTypeCode" => "material",
53
+ "Name" => "Cotton"
54
+ }
55
+ ]
56
+ },
57
+ {
58
+ "ProductCode" => product_2.skus.first,
59
+ "ProductGroupCode" => product_2.id,
60
+ "CartItemId" => cart.items.second.id.to_s,
61
+ "Name" => product_2.name,
62
+ "Description" => product_2.description,
63
+ "URL" => "http://www.example.com/products/test-product-1",
64
+ "Weight" => 5.0,
65
+ "Height" => 5,
66
+ "Width" => 5,
67
+ "Length" => 5,
68
+ "ImageURL" => "/product_images/test-product-1/Cotton/#{product_2.images.first.id}/detail.jpg?c=0",
69
+ "ImageHeight" => 780,
70
+ "ImageWidth" => 780,
71
+ "ListPrice" => 0,
72
+ "OriginalListPrice" => 5.0,
73
+ "SalePrice" => 0,
74
+ "OriginalSalePrice" => 4.0,
75
+ "IsFixedPrice" => false,
76
+ "OrderedQuantity" => 1,
77
+ "IsVirtual" => false,
78
+ "IsBlockedForGlobalE" => false,
79
+ "Attributes" => [
80
+ {
81
+ "AttributeCode" => "material",
82
+ "AttributeTypeCode" => "material",
83
+ "Name" => "Cotton"
84
+ }
85
+ ]
86
+ }
87
+ ],
88
+ "discountsList" => [
89
+ {
90
+ "OriginalDiscountValue" => 0.9,
91
+ "DiscountType" => 1,
92
+ "DiscountValue" => 0,
93
+ "Name" => "Order Total Discount",
94
+ "Description" => "Order Total - Order Total Discount",
95
+ "CalculationMode" => 1,
96
+ "CouponCode" => "testcode",
97
+ "DiscountCode" => order_discount.id.to_s
98
+ }
99
+ ]
100
+ }
101
+ assert_equal(expected_response, JSON.parse(response.body))
102
+ end
103
+
104
+ def test_get_checkout_cart_info_stock_validation_mode
105
+ product_1 = create_complete_product(
106
+ variants: [{ sku: 'SKU', details: { material: 'Cotton' }, regular: 5.00, sale: 4.00, policy: 'standard' }]
107
+ )
108
+ product_2 = create_complete_product(
109
+ variants: [{ sku: 'SKU2', details: { material: 'Cotton' }, regular: 5.00, sale: 4.00, on_sale: true, policy: 'standard' }]
110
+ )
111
+ cart = create_cart(
112
+ order: create_order(promo_codes: ['TESTCODE']),
113
+ items: [
114
+ { product: product_1, sku: product_1.skus.first, quantity: 1 },
115
+ { product: product_2, sku: product_2.skus.first, quantity: 1 }
116
+ ]
117
+ )
118
+
119
+ get storefront.global_e_checkout_cart_info_path(cartToken: cart.global_e_token, format: :json)
120
+
121
+ assert response.ok?
122
+ expected_response = {
123
+ "productsList" => [
124
+ {
125
+ "ProductCode" => product_1.skus.first,
126
+ "ProductGroupCode" => product_1.id,
127
+ "CartItemId" => cart.items.first.id.to_s,
128
+ "Name" => product_1.name,
129
+ "Description" => product_1.description,
130
+ "URL" => "http://www.example.com/products/test-product",
131
+ "Weight" => 5.0,
132
+ "Height" => 5,
133
+ "Width" => 5,
134
+ "Length" => 5,
135
+ "ImageURL" => "/product_images/test-product/Cotton/#{product_1.images.first.id}/detail.jpg?c=0",
136
+ "ImageHeight" => 780,
137
+ "ImageWidth" => 780,
138
+ "ListPrice" => 0,
139
+ "OriginalListPrice" => 5.0,
140
+ "SalePrice" => 0,
141
+ "OriginalSalePrice" => 5.0,
142
+ "IsFixedPrice" => false,
143
+ "OrderedQuantity" => 1,
144
+ "IsVirtual" => false,
145
+ "IsBlockedForGlobalE" => false,
146
+ "Attributes" => [
147
+ {
148
+ "AttributeCode" => "material",
149
+ "AttributeTypeCode" => "material",
150
+ "Name" => "Cotton"
151
+ }
152
+ ]
153
+ },
154
+ {
155
+ "ProductCode" => product_2.skus.first,
156
+ "ProductGroupCode" => product_2.id,
157
+ "CartItemId" => cart.items.second.id.to_s,
158
+ "Name" => product_2.name,
159
+ "Description" => product_2.description,
160
+ "URL" => "http://www.example.com/products/test-product-1",
161
+ "Weight" => 5.0,
162
+ "Height" => 5,
163
+ "Width" => 5,
164
+ "Length" => 5,
165
+ "ImageURL" => "/product_images/test-product-1/Cotton/#{product_2.images.first.id}/detail.jpg?c=0",
166
+ "ImageHeight" => 780,
167
+ "ImageWidth" => 780,
168
+ "ListPrice" => 0,
169
+ "OriginalListPrice" => 5.0,
170
+ "SalePrice" => 0,
171
+ "OriginalSalePrice" => 4.0,
172
+ "IsFixedPrice" => false,
173
+ "OrderedQuantity" => 1,
174
+ "IsVirtual" => false,
175
+ "IsBlockedForGlobalE" => false,
176
+ "Attributes" => [
177
+ {
178
+ "AttributeCode" => "material",
179
+ "AttributeTypeCode" => "material",
180
+ "Name" => "Cotton"
181
+ }
182
+ ]
183
+ }
184
+ ],
185
+ "discountsList" => []
186
+ }
187
+ assert_equal(expected_response, JSON.parse(response.body))
188
+
189
+ Inventory::Sku.find('SKU2').update_attributes(available: 0)
190
+ get storefront.global_e_checkout_cart_info_path(cartToken: cart.global_e_token, IsStockValidation: '1', format: :json)
191
+
192
+ assert response.ok?
193
+ expected_response = {
194
+ "productsList" => [
195
+ {
196
+ "ProductCode" => product_1.skus.first,
197
+ "ProductGroupCode" => product_1.id,
198
+ "CartItemId" => cart.items.first.id.to_s,
199
+ "Name" => product_1.name,
200
+ "Description" => product_1.description,
201
+ "URL" => "http://www.example.com/products/test-product",
202
+ "Weight" => 5.0,
203
+ "Height" => 5,
204
+ "Width" => 5,
205
+ "Length" => 5,
206
+ "ImageURL" => "/product_images/test-product/Cotton/#{product_1.images.first.id}/detail.jpg?c=0",
207
+ "ImageHeight" => 780,
208
+ "ImageWidth" => 780,
209
+ "ListPrice" => 0,
210
+ "OriginalListPrice" => 5.0,
211
+ "SalePrice" => 0,
212
+ "OriginalSalePrice" => 5.0,
213
+ "IsFixedPrice" => false,
214
+ "OrderedQuantity" => 1,
215
+ "IsVirtual" => false,
216
+ "IsBlockedForGlobalE" => false,
217
+ "Attributes" => [
218
+ {
219
+ "AttributeCode" => "material",
220
+ "AttributeTypeCode" => "material",
221
+ "Name" => "Cotton"
222
+ }
223
+ ]
224
+ }
225
+ ],
226
+ "discountsList" => []
227
+ }
228
+ assert_equal(expected_response, JSON.parse(response.body))
229
+ end
230
+
231
+ def test_get_checkout_cart_info_with_user_addresses
232
+ user = create_user(
233
+ addresses: [
234
+ {
235
+ first_name: 'Ben',
236
+ last_name: 'Crouse',
237
+ street: '22 S. 3rd St.',
238
+ city: 'Philadelphia',
239
+ postal_code: '19106',
240
+ region: 'PA',
241
+ country: 'US',
242
+ phone_number: '2159251800',
243
+ last_billed_at: Time.current
244
+ },
245
+ {
246
+ first_name: 'Ben',
247
+ last_name: 'Crouse',
248
+ street: '22 S. 3rd St.',
249
+ city: 'Philadelphia',
250
+ postal_code: '19106',
251
+ region: 'PA',
252
+ country: 'US',
253
+ phone_number: '2159251800',
254
+ last_shipped_at: Time.current
255
+ },
256
+ {
257
+ first_name: 'Ben',
258
+ last_name: 'Crouse',
259
+ street: "211 Yonge St",
260
+ city: "Toronto",
261
+ postal_code: "ON M5B 1M4",
262
+ region: "ON",
263
+ country: "CA",
264
+ phone_number: '2159251800',
265
+ last_billed_at: Time.current,
266
+ last_shipped_at: Time.current
267
+ }
268
+ ]
269
+ )
270
+ product_1 = create_complete_product
271
+ cart = create_cart(
272
+ user: user,
273
+ items: [
274
+ { product: product_1, sku: product_1.skus.first, quantity: 1 }
275
+ ]
276
+ )
277
+
278
+ get storefront.global_e_checkout_cart_info_path(cartToken: cart.global_e_token, format: :json)
279
+
280
+ assert response.ok?
281
+ expected_response = {
282
+ "productsList" => [
283
+ {
284
+ "ProductCode" => product_1.skus.first,
285
+ "ProductGroupCode" => product_1.id,
286
+ "CartItemId" => cart.items.first.id.to_s,
287
+ "Name" => product_1.name,
288
+ "Description" => product_1.description,
289
+ "URL" => "http://www.example.com/products/test-product",
290
+ "Weight" => 5.0,
291
+ "Height" => 5,
292
+ "Width" => 5,
293
+ "Length" => 5,
294
+ "ImageURL" => "/product_images/test-product/Cotton/#{product_1.images.first.id}/detail.jpg?c=0",
295
+ "ImageHeight" => 780,
296
+ "ImageWidth" => 780,
297
+ "ListPrice" => 0,
298
+ "OriginalListPrice" => 5.0,
299
+ "SalePrice" => 0,
300
+ "OriginalSalePrice" => 5.0,
301
+ "IsFixedPrice" => false,
302
+ "OrderedQuantity" => 1,
303
+ "IsVirtual" => false,
304
+ "IsBlockedForGlobalE" => false,
305
+ "Attributes" => [
306
+ {
307
+ "AttributeCode" => "material",
308
+ "AttributeTypeCode" => "material",
309
+ "Name" => "Cotton"
310
+ }
311
+ ]
312
+ }
313
+ ],
314
+ 'discountsList' => [],
315
+ 'userDetails' => {
316
+ "UserId" => user.id.to_s,
317
+ "AddressDetails" => [
318
+ {
319
+ "AddressBookId" => user.addresses[0].id.to_s,
320
+ "FirstName" => "Ben",
321
+ "LastName" => "Crouse",
322
+ "Phone1" => "2159251800",
323
+ "Address1" => "22 S. 3rd St.",
324
+ "City" => "Philadelphia",
325
+ "StateCode" => "PA",
326
+ "StateOrProvice" => "Pennsylvania",
327
+ "Zip" => "19106",
328
+ "CountryCode" => "US",
329
+ "IsBilling" => true,
330
+ "IsShipping" => false,
331
+ "IsDefaultBilling" => false,
332
+ "IsDefaultShipping" => false,
333
+ "Email" => user.email
334
+ },
335
+ {
336
+ "AddressBookId" => user.addresses[1].id.to_s,
337
+ "FirstName" => "Ben",
338
+ "LastName" => "Crouse",
339
+ "Phone1" => "2159251800",
340
+ "Address1" => "22 S. 3rd St.",
341
+ "City" => "Philadelphia",
342
+ "StateCode" => "PA",
343
+ "StateOrProvice" => "Pennsylvania",
344
+ "Zip" => "19106",
345
+ "CountryCode" => "US",
346
+ "IsBilling" => false,
347
+ "IsShipping" => true,
348
+ "IsDefaultBilling" => false,
349
+ "IsDefaultShipping" => false,
350
+ "Email" => user.email
351
+ },
352
+ {
353
+ "AddressBookId" => user.addresses[2].id.to_s,
354
+ "FirstName" => "Ben",
355
+ "LastName" => "Crouse",
356
+ "Phone1" => "2159251800",
357
+ "Email" => user.email,
358
+ "Address1" => "211 Yonge St",
359
+ "City" => "Toronto",
360
+ "StateOrProvice" => "Ontario",
361
+ "StateCode" => "ON",
362
+ "Zip" => "ON M5B 1M4",
363
+ "CountryCode" => "CA",
364
+ "IsShipping" => true,
365
+ "IsBilling" => true,
366
+ "IsDefaultShipping" => true,
367
+ "IsDefaultBilling" => true
368
+ }
369
+ ]
370
+ }
371
+ }
372
+ assert_equal(expected_response, JSON.parse(response.body))
373
+ end
374
+
375
+ def test_product_discount_with_multiple_line_items
376
+ product_1 = create_complete_product
377
+ product_2 = create_complete_product(
378
+ variants: [{ sku: 'SKU2', details: { material: 'Cotton' }, regular: 5.00, sale: 4.00, on_sale: true }]
379
+ )
380
+
381
+ product_discount = create_product_discount(
382
+ product_ids: [product_1.id.to_s, product_2.id.to_s]
383
+ )
384
+
385
+ order_discount = create_order_total_discount(
386
+ compatible_discount_ids: [product_discount.id.to_s]
387
+ )
388
+
389
+ cart = create_cart(
390
+ items: [
391
+ { product: product_1, sku: product_1.skus.first, quantity: 1 },
392
+ { product: product_2, sku: product_2.skus.first, quantity: 1 }
393
+ ]
394
+ )
395
+
396
+ get storefront.global_e_checkout_cart_info_path(cartToken: cart.global_e_token, format: :json)
397
+
398
+ assert response.ok?
399
+ expected_response = {
400
+ "productsList" => [
401
+ {
402
+ "ProductCode" => product_1.skus.first,
403
+ "ProductGroupCode" => product_1.id,
404
+ "CartItemId" => cart.items.first.id.to_s,
405
+ "Name" => product_1.name,
406
+ "Description" => product_1.description,
407
+ "URL" => "http://www.example.com/products/test-product",
408
+ "Weight" => 5.0,
409
+ "Height" => 5,
410
+ "Width" => 5,
411
+ "Length" => 5,
412
+ "ImageURL" => "/product_images/test-product/Cotton/#{product_1.images.first.id}/detail.jpg?c=0",
413
+ "ImageHeight" => 780,
414
+ "ImageWidth" => 780,
415
+ "ListPrice" => 0,
416
+ "OriginalListPrice" => 5.0,
417
+ "SalePrice" => 0,
418
+ "OriginalSalePrice" => 5.0,
419
+ "IsFixedPrice" => false,
420
+ "OrderedQuantity" => 1,
421
+ "IsVirtual" => false,
422
+ "IsBlockedForGlobalE" => false,
423
+ "Attributes" => [
424
+ {
425
+ "AttributeCode" => "material",
426
+ "AttributeTypeCode" => "material",
427
+ "Name" => "Cotton"
428
+ }
429
+ ]
430
+ },
431
+ {
432
+ "ProductCode" => product_2.skus.first,
433
+ "ProductGroupCode" => product_2.id,
434
+ "CartItemId" => cart.items.second.id.to_s,
435
+ "Name" => product_2.name,
436
+ "Description" => product_2.description,
437
+ "URL" => "http://www.example.com/products/test-product-1",
438
+ "Weight" => 5.0,
439
+ "Height" => 5,
440
+ "Width" => 5,
441
+ "Length" => 5,
442
+ "ImageURL" => "/product_images/test-product-1/Cotton/#{product_2.images.first.id}/detail.jpg?c=0",
443
+ "ImageHeight" => 780,
444
+ "ImageWidth" => 780,
445
+ "ListPrice" => 0,
446
+ "OriginalListPrice" => 5.0,
447
+ "SalePrice" => 0,
448
+ "OriginalSalePrice" => 4.0,
449
+ "IsFixedPrice" => false,
450
+ "OrderedQuantity" => 1,
451
+ "IsVirtual" => false,
452
+ "IsBlockedForGlobalE" => false,
453
+ "Attributes" => [
454
+ {
455
+ "AttributeCode" => "material",
456
+ "AttributeTypeCode" => "material",
457
+ "Name" => "Cotton"
458
+ }
459
+ ]
460
+ }
461
+ ],
462
+ "discountsList" => [
463
+ {
464
+ "OriginalDiscountValue" => 2.50,
465
+ "DiscountType" => 1,
466
+ "DiscountValue" => 0,
467
+ "Name" => "Test Discount",
468
+ "Description" => "Product - Test Discount",
469
+ "ProductCartItemId" => cart.items.first.id.to_s,
470
+ "DiscountCode" => "#{product_discount.id}-#{cart.items.first.id}",
471
+ "CalculationMode" => 1
472
+ },
473
+ {
474
+ "OriginalDiscountValue" => 2.00,
475
+ "DiscountType" => 1,
476
+ "DiscountValue" => 0,
477
+ "Name" => "Test Discount",
478
+ "Description" => "Product - Test Discount",
479
+ "ProductCartItemId" => cart.items.second.id.to_s,
480
+ "DiscountCode" => "#{product_discount.id}-#{cart.items.second.id}",
481
+ "CalculationMode" => 1
482
+ },
483
+ {
484
+ "OriginalDiscountValue" => 0.45,
485
+ "Name" => "Order Total Discount",
486
+ "Description" => "Order Total - Order Total Discount",
487
+ "DiscountCode" => order_discount.id.to_s,
488
+ "DiscountType" => 1,
489
+ "DiscountValue" => 0,
490
+ "CalculationMode" => 1
491
+ }
492
+ ]
493
+ }
494
+ assert_equal(expected_response, JSON.parse(response.body))
495
+ end
496
+
497
+ def test_multiple_discounts_with_same_name
498
+ product_1 = create_complete_product
499
+
500
+ product_discount_1 = create_product_discount(
501
+ product_ids: [product_1.id.to_s]
502
+ )
503
+
504
+ product_discount_2 = create_product_discount(
505
+ product_ids: [product_1.id.to_s],
506
+ compatible_discount_ids: [product_discount_1.id.to_s]
507
+ )
508
+
509
+ cart = create_cart(
510
+ items: [
511
+ { product: product_1, sku: product_1.skus.first, quantity: 1 }
512
+ ]
513
+ )
514
+
515
+ get storefront.global_e_checkout_cart_info_path(cartToken: cart.global_e_token, format: :json)
516
+
517
+ assert response.ok?
518
+ expected_response = {
519
+ "productsList" => [
520
+ {
521
+
522
+ "ProductCode" => product_1.skus.first,
523
+ "ProductGroupCode" => product_1.id,
524
+ "CartItemId" => cart.items.first.id.to_s,
525
+ "Name" => product_1.name,
526
+ "Description" => product_1.description,
527
+ "URL" => "http://www.example.com/products/test-product",
528
+ "Weight" => 5.0,
529
+ "Height" => 5,
530
+ "Width" => 5,
531
+ "Length" => 5,
532
+ "ImageURL" => "/product_images/test-product/Cotton/#{product_1.images.first.id}/detail.jpg?c=0",
533
+ "ImageHeight" => 780,
534
+ "ImageWidth" => 780,
535
+ "ListPrice" => 0,
536
+ "OriginalListPrice" => 5.0,
537
+ "IsFixedPrice" => false,
538
+ "OrderedQuantity" => 1,
539
+ "IsVirtual" => false,
540
+ "IsBlockedForGlobalE" => false,
541
+ "Attributes" => [{ "AttributeCode" => "material", "AttributeTypeCode" => "material", "Name" => "Cotton" }],
542
+ "SalePrice" => 0,
543
+ "OriginalSalePrice" => 5.0
544
+ }
545
+ ],
546
+ "discountsList" => [
547
+ {
548
+ "OriginalDiscountValue" => 2.5,
549
+ "Name" => "Test Discount",
550
+ "Description" => "Product - Test Discount",
551
+ "ProductCartItemId" => cart.items.first.id.to_s,
552
+ "DiscountCode" => "#{product_discount_1.id}-#{cart.items.first.id.to_s}",
553
+ "DiscountType" => 1,
554
+ "DiscountValue" => 0,
555
+ "CalculationMode" => 1
556
+ },
557
+ {
558
+ "OriginalDiscountValue" => 1.25,
559
+ "Name" => "Test Discount",
560
+ "Description" => "Product - Test Discount",
561
+ "ProductCartItemId" => cart.items.first.id.to_s,
562
+ "DiscountCode" => "#{product_discount_2.id}-#{cart.items.first.id.to_s}",
563
+ "DiscountType" => 1,
564
+ "DiscountValue" => 0,
565
+ "CalculationMode" => 1
566
+ }
567
+ ]
568
+ }
569
+ assert_equal(expected_response, JSON.parse(response.body))
570
+ end
571
+
572
+ def test_free_gifts
573
+ product_1 = create_complete_product
574
+
575
+ free_gift = create_product(
576
+ name: 'Free Item',
577
+ variants: [{ sku: 'FREE_SKU', regular: 5.to_m }]
578
+ )
579
+
580
+ free_gift_discount = create_free_gift_discount(
581
+ name: 'Test',
582
+ sku: 'FREE_SKU',
583
+ order_total_operator: :greater_than,
584
+ order_total: 1
585
+ )
586
+
587
+ cart = create_cart(
588
+ items: [{ product: product_1, sku: product_1.skus.first, quantity: 1 }]
589
+ )
590
+
591
+ get storefront.global_e_checkout_cart_info_path(cartToken: cart.global_e_token, format: :json)
592
+
593
+ assert response.ok?
594
+ expected_response = {
595
+ "productsList" => [
596
+ {
597
+ "ProductCode" => product_1.skus.first,
598
+ "ProductGroupCode" => product_1.id,
599
+ "CartItemId" => cart.items.first.id.to_s,
600
+ "Name" => product_1.name,
601
+ "Description" => product_1.description,
602
+ "URL" => "http://www.example.com/products/test-product",
603
+ "Weight" => 5.0,
604
+ "Height" => 5,
605
+ "Width" => 5,
606
+ "Length" => 5,
607
+ "ImageURL" => "/product_images/test-product/Cotton/#{product_1.images.first.id}/detail.jpg?c=0",
608
+ "ImageHeight" => 780,
609
+ "ImageWidth" => 780,
610
+ "ListPrice" => 0,
611
+ "OriginalListPrice" => 5.0,
612
+ "SalePrice" => 0,
613
+ "OriginalSalePrice" => 5.0,
614
+ "IsFixedPrice" => false,
615
+ "OrderedQuantity" => 1,
616
+ "IsVirtual" => false,
617
+ "IsBlockedForGlobalE" => false,
618
+ "Attributes" => [
619
+ {
620
+ "AttributeCode" => "material",
621
+ "AttributeTypeCode" => "material",
622
+ "Name" => "Cotton"
623
+ }
624
+ ]
625
+ },
626
+ {
627
+ "ProductCode" => "FREE_SKU",
628
+ "ProductGroupCode" => free_gift.id,
629
+ "CartItemId" => cart.items.detect(&:free_gift?).id.to_s,
630
+ "Name" => "Free Item",
631
+ "URL" => "http://www.example.com/products/free-item",
632
+ "ListPrice" => 0,
633
+ "OriginalListPrice" => 5.0,
634
+ "IsFixedPrice" => false,
635
+ "OrderedQuantity" => 1,
636
+ "IsVirtual" => false,
637
+ "IsBlockedForGlobalE" => false,
638
+ "Attributes" => [],
639
+ "SalePrice" => 0,
640
+ "OriginalSalePrice" => 0.0
641
+ }
642
+ ],
643
+ "discountsList" => [
644
+ {
645
+ "OriginalDiscountValue" => 5.0,
646
+ "CalculationMode" => 1,
647
+ "Name" => "Test",
648
+ "Description" => "Free Gift - Test",
649
+ "ProductCartItemId" => cart.items.detect(&:free_gift?).id.to_s,
650
+ "DiscountCode" => "#{free_gift_discount.id}-#{cart.items.detect(&:free_gift?).id}",
651
+ "DiscountType" => 1,
652
+ "DiscountValue" => 0
653
+ }
654
+ ]
655
+ }
656
+ assert_equal(expected_response, JSON.parse(response.body))
657
+ end
658
+ end
659
+ end
660
+ end