Product.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { Collection, Model } from 'js-abstract-model'
  2. import { MediaList } from 'src/models/Media.js'
  3. class Product extends Model {
  4. constructor (data) {
  5. super(data, [
  6. { key: 'id' },
  7. { key: 'thumbnail' },
  8. { key: 'title' },
  9. { key: 'inventory' },
  10. { key: 'store_category' },
  11. { key: 'store_category_info' },
  12. { key: 'content_category' },
  13. { key: 'content_category_info' },
  14. {
  15. key: 'unit_price',
  16. default: 0
  17. },
  18. { key: 'sellable_price' },
  19. {
  20. key: 'discount_percent',
  21. default: 0
  22. },
  23. { key: 'description' },
  24. { key: 'maximum_order_count' },
  25. { key: 'is_physical' },
  26. { key: 'is_hidden' },
  27. { key: 'weight' },
  28. { key: 'physical_type' },
  29. { key: 'specification' },
  30. {
  31. key: 'is_add_to_basket_disabled',
  32. default: true
  33. },
  34. {
  35. key: 'is_purchased',
  36. default: false
  37. },
  38. {
  39. key: 'medias',
  40. default: []
  41. },
  42. {
  43. key: 'medias_info',
  44. relatedModel: MediaList
  45. }
  46. ], {
  47. is_physical: {
  48. infoKey: 'is_physical_info',
  49. enumListKey: 'is_physicalEnums',
  50. enums: [
  51. {
  52. label: 'فیزیکی',
  53. value: true
  54. },
  55. {
  56. label: 'مجازی',
  57. value: false
  58. }
  59. ]
  60. },
  61. is_hidden: {
  62. infoKey: 'is_hidden_info',
  63. enumListKey: 'is_hiddenEnums',
  64. enums: [
  65. {
  66. label: 'نمایان',
  67. value: true
  68. },
  69. {
  70. label: 'مخفی',
  71. value: false
  72. }
  73. ]
  74. },
  75. physical_type: {
  76. infoKey: 'physical_type_info',
  77. enumListKey: 'physical_typeEnums',
  78. enums: [
  79. {
  80. label: 'لوح فشرده',
  81. value: 'CD'
  82. },
  83. {
  84. label: 'کتاب',
  85. value: 'BOOK'
  86. },
  87. {
  88. label: 'جزوه',
  89. value: 'MANUSCRIPT'
  90. }
  91. ]
  92. }
  93. })
  94. if (!this.thumbnail) {
  95. this.thumbnail = '/img/sample-post-thumbnail.jpg'
  96. }
  97. }
  98. getFinalPrice () {
  99. return parseInt(this.unit_price * (100 - this.discount_percent)).toLocaleString('fa')
  100. }
  101. }
  102. class ProductList extends Collection {
  103. model () {
  104. return Product
  105. }
  106. }
  107. export { Product, ProductList }