Product.js 2.2 KB

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