ProductCustomizableOptionPrice.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Webkul\BagistoApi\Models;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. use Webkul\Product\Models\ProductCustomizableOptionPrice as BaseProductCustomizableOptionPrice;
  8. #[ApiResource(
  9. operations: [],
  10. graphQlOperations: [],
  11. )]
  12. class ProductCustomizableOptionPrice extends BaseProductCustomizableOptionPrice
  13. {
  14. /**
  15. * Get the customizable option that owns the price.
  16. */
  17. public function customizable_option(): BelongsTo
  18. {
  19. return $this->belongsTo(ProductCustomizableOption::class, 'product_customizable_option_id');
  20. }
  21. /**
  22. * Get id
  23. */
  24. #[ApiProperty(
  25. identifier: true,
  26. writable: false,
  27. readable: true
  28. )]
  29. #[Groups(['read'])]
  30. public function getId(): ?int
  31. {
  32. return $this->id;
  33. }
  34. /**
  35. * Get label
  36. */
  37. #[ApiProperty(
  38. writable: false,
  39. readable: true
  40. )]
  41. #[Groups(['read'])]
  42. public function getLabel(): ?string
  43. {
  44. return $this->label;
  45. }
  46. public function getPriceAttribute($value)
  47. {
  48. return $value !== null ? (float) core()->convertPrice((float) $value) : null;
  49. }
  50. /**
  51. * Get price
  52. */
  53. #[ApiProperty(
  54. writable: false,
  55. readable: true
  56. )]
  57. #[Groups(['read'])]
  58. public function getPrice(): ?float
  59. {
  60. return $this->price ? (float) $this->price : null;
  61. }
  62. public function getFormattedPriceAttribute(): ?string
  63. {
  64. return $this->price !== null ? core()->formatPrice($this->price) : null;
  65. }
  66. #[ApiProperty(writable: false, readable: true)]
  67. public function getFormatted_price(): ?string
  68. {
  69. return $this->getFormattedPriceAttribute();
  70. }
  71. /**
  72. * Get sort_order
  73. */
  74. #[ApiProperty(
  75. writable: false,
  76. readable: true
  77. )]
  78. #[Groups(['read'])]
  79. public function getSort_order(): ?int
  80. {
  81. return $this->sort_order;
  82. }
  83. }