Advertisement
Guest User

Untitled

a guest
May 25th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. 'use strict'
  2. class DiscountAllocations {
  3. constructor(){
  4. this.type = 'discount_code';
  5. this.title = 'custom discount';
  6. this.description = 'Reshipment';
  7. this.value = '10.0';
  8. this.value_type = 'fixed_amount';
  9. this.allocation_method = 'across';
  10. this.target_selection = 'all';
  11. this.target_type = 'line_item';
  12. this.discount_allocations = [{
  13. type: this.type,
  14. title: this.title,
  15. description: this.description,
  16. value: this.value,
  17. value_type: this.value_type,
  18. allocation_method: this.allocation_method,
  19. target_selection: this.target_selection,
  20. target_type: this.target_type
  21. }];
  22. }
  23. get(){
  24. return this.discount_allocations;
  25. }
  26. }
  27.  
  28. class DiscountCode {
  29. constructor(subtotal_price){
  30. this.code = 'reshipment_discount';
  31. this.amount = subtotal_price;
  32. this.type = 'fixed_amount';
  33. this.discount_codes = [{
  34. code: this.code,
  35. amount: this.amount,
  36. type: this.type
  37. }];
  38. }
  39.  
  40. get() {
  41. return this.discount_codes;
  42. }
  43. }
  44.  
  45. class ShippingLines {
  46. constructor(line){
  47. this.shipping_lines = [{
  48. code: line[0].code,
  49. price: 0,
  50. price_set: {
  51. shop_money: {
  52. amount: line[0].price_set.shop_money.amount,
  53. currency_code: line[0].price_set.shop_money.currency_code
  54. },
  55. presentment_money: {
  56. amount: line[0].price_set.presentment_money.amount,
  57. currency_code: line[0].price_set.presentment_money.currency_code
  58. }
  59. },
  60. discounted_price: line[0].price_set.shop_money.amount,
  61. discount_price_set: {
  62. shop_money: {
  63. amount: line[0].price_set.shop_money.amount,
  64. currency_code: line[0].price_set.presentment_money.currency_code
  65. },
  66. presentment_money: {
  67. amount: line[0].price_set.shop_money.amount,
  68. currency_code: line[0].price_set.presentment_money.currency_code
  69. }
  70. },
  71. source: line[0].source,
  72. title: line[0].title,
  73. tax_lines: line[0].tax_lines,
  74. carrier_identifier: line[0].carrier_identifier,
  75. }];
  76. }
  77. get() {
  78. return this.shipping_lines;
  79. }
  80. }
  81.  
  82. class Order {
  83. constructor(billing_address, buyer_accepts_marketing, currency, customer, email,
  84. fulfillments, fulfillment_status, line_items, note, order_id, original_order_number,
  85. payment_gateway_names, phone, presentment_currency, processing_method,
  86. refunds, reship, shipping_address, shipping_lines, subtotal_price,
  87. subtotal_price_set, taxes_included, total_line_items_price,
  88. total_line_items_price_set, total_price, total_price_set,
  89. total_shipping_price_set, total_weight){
  90. this.billing_address = billing_address;
  91. this.buyer_accepts_marketing = buyer_accepts_marketing;
  92. this.currency = currency;
  93. this.customer = customer;
  94. this.subtotal_price = subtotal_price;
  95. this.discount_allocations = new DiscountAllocations().get();
  96. this.discount_codes = new DiscountCode(subtotal_price).get();
  97. this.email = email;
  98. this.financial_status = 'paid';
  99. this.fulfillments = fulfillments;
  100. this.fulfillment_status = fulfillment_status || null;
  101. this.inventory_behaviour = 'decrement_obeying_policy';
  102. this.line_items = line_items;
  103. this.note = 'Reshipment issued for ' + original_order_number + ' Reason: ' + reship.reason;
  104. this.order_id = order_id;
  105. this.original_order_number = original_order_number;
  106. this.payment_gateway_names = payment_gateway_names;
  107. this.phone = phone || null;
  108. this.presentment_currency = presentment_currency;
  109. this.processing_method = processing_method;
  110. this.refunds = refunds;
  111. this.reship = {
  112. type: reship.type,
  113. reason: reship.reason
  114. };
  115. this.shipping_address = shipping_address;
  116. this.shipping_lines = new ShippingLines(shipping_lines).get();
  117. this.subtotal_price_set = subtotal_price_set;
  118. this.tags = 'ccapp';
  119. this.taxes_included = taxes_included;
  120. this.total_line_items_price = total_line_items_price;
  121. this.total_line_items_price_set = total_line_items_price_set;
  122. this.total_price = total_price;
  123. this.total_price_set = total_price_set;
  124. this.total_shipping_price_set = total_shipping_price_set;
  125. this.total_tax = 0;
  126. this.total_weight = total_weight;
  127. }
  128. }
  129.  
  130. module.exports = Order;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement