CartInput.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. namespace Webkul\BagistoApi\Dto;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use Symfony\Component\Serializer\Annotation\Groups;
  5. /**
  6. * Input DTO for cart operations with token-based authentication
  7. *
  8. * Supports both authenticated users (via bearer token) and guest users (via cart token).
  9. * Operations: add product, update item quantity, remove item, get cart, get all carts
  10. *
  11. * Authentication token is passed via Authorization: Bearer header, not as input parameter.
  12. */
  13. class CartInput
  14. {
  15. /**
  16. * ID field (optional, for GraphQL API Platform compatibility)
  17. */
  18. #[ApiProperty(required: false)]
  19. #[Groups(['mutation', 'query'])]
  20. public ?string $id = null;
  21. /**
  22. * Cart ID (optional, for specific cart operations)
  23. */
  24. #[ApiProperty(required: false)]
  25. #[Groups(['mutation', 'query'])]
  26. public ?int $cartId = null;
  27. /**
  28. * Product ID (required for addProduct operation)
  29. */
  30. #[ApiProperty(required: false)]
  31. #[Groups(['mutation'])]
  32. public ?int $productId = null;
  33. /**
  34. * Cart item ID (required for update/remove operations)
  35. */
  36. #[ApiProperty(required: false)]
  37. #[Groups(['mutation'])]
  38. public ?int $cartItemId = null;
  39. /**
  40. * Quantity of items to add/update
  41. */
  42. #[ApiProperty(required: false)]
  43. #[Groups(['mutation'])]
  44. public ?int $quantity = null;
  45. /**
  46. * Product options/attributes (JSON)
  47. */
  48. #[ApiProperty(required: false)]
  49. #[Groups(['mutation'])]
  50. public ?array $options = null;
  51. /**
  52. * Coupon code for discount
  53. */
  54. #[ApiProperty(required: false)]
  55. #[Groups(['mutation'])]
  56. public ?string $couponCode = null;
  57. /**
  58. * Shipping address ID
  59. */
  60. #[ApiProperty(required: false)]
  61. #[Groups(['mutation'])]
  62. public ?int $shippingAddressId = null;
  63. /**
  64. * Billing address ID
  65. */
  66. #[ApiProperty(required: false)]
  67. #[Groups(['mutation'])]
  68. public ?int $billingAddressId = null;
  69. /**
  70. * Shipping method code
  71. */
  72. #[ApiProperty(required: false)]
  73. #[Groups(['mutation'])]
  74. public ?string $shippingMethod = null;
  75. #[Groups(['query', 'mutation'])]
  76. #[ApiProperty(description: 'Selected shipping rate object')]
  77. public $selectedShippingRate = null;
  78. /**
  79. * Payment method code
  80. */
  81. #[ApiProperty(required: false)]
  82. #[Groups(['mutation'])]
  83. public ?string $paymentMethod = null;
  84. /**
  85. * Session ID for creating new guest cart (createOrGetCart operation)
  86. * Used to identify guest session and generate unique token
  87. */
  88. #[ApiProperty(required: false, description: 'Session ID for cart creation')]
  89. #[Groups(['mutation', 'query'])]
  90. public ?string $sessionId = null;
  91. /**
  92. * Flag to create new cart instead of using existing one
  93. * Used in createOrGetCart mutation
  94. */
  95. #[ApiProperty(required: false, description: 'Generate new cart with unique token')]
  96. #[Groups(['mutation'])]
  97. public ?bool $createNew = false;
  98. /**
  99. * Array of cart item IDs for bulk operations (remove multiple, move to wishlist)
  100. */
  101. #[ApiProperty(required: false)]
  102. #[Groups(['mutation'])]
  103. public ?array $itemIds = null;
  104. /**
  105. * Array of quantities for bulk operations
  106. */
  107. #[ApiProperty(required: false)]
  108. #[Groups(['mutation'])]
  109. public ?array $quantities = null;
  110. /**
  111. * Country code for shipping estimation
  112. */
  113. #[ApiProperty(required: false)]
  114. #[Groups(['mutation'])]
  115. public ?string $country = null;
  116. /**
  117. * State/Province code for shipping estimation
  118. */
  119. #[ApiProperty(required: false)]
  120. #[Groups(['mutation'])]
  121. public ?string $state = null;
  122. /**
  123. * Postal code for shipping estimation
  124. */
  125. #[ApiProperty(required: false)]
  126. #[Groups(['mutation'])]
  127. public ?string $postcode = null;
  128. /**
  129. * Device token for push notifications (optional)
  130. */
  131. #[ApiProperty(required: false, description: 'Device token for push notifications')]
  132. #[Groups(['mutation'])]
  133. public ?string $deviceToken = null;
  134. /**
  135. * Is buy now flag (0 = add to cart, 1 = buy now)
  136. * Used for direct checkout
  137. */
  138. #[ApiProperty(required: false, description: 'Is buy now (0 = cart, 1 = buy now)')]
  139. #[Groups(['mutation'])]
  140. public ?int $isBuyNow = 0;
  141. /**
  142. * Bundle product options
  143. * Format: [option_id => [product_id1, product_id2, ...]]
  144. * Example: [1 => [2, 3], 2 => [5]]
  145. * Used for Bundle products
  146. */
  147. #[ApiProperty(required: false, description: 'Bundle options JSON string. Example: {"1":[1],"2":[2]}')]
  148. #[Groups(['mutation'])]
  149. public ?string $bundleOptions = null;
  150. /**
  151. * Bundle product option quantities
  152. * Format: [option_id => quantity]
  153. * Example: [1 => 2, 2 => 1]
  154. * Used for Bundle products
  155. */
  156. #[ApiProperty(required: false, description: 'Bundle option quantities JSON string. Example: {"1":1,"2":2}')]
  157. #[Groups(['mutation'])]
  158. public ?string $bundleOptionQty = null;
  159. /**
  160. * Selected configurable product option (child product ID)
  161. * Used for Configurable products
  162. */
  163. #[ApiProperty(required: false, description: 'Selected configurable option (child product ID)')]
  164. #[Groups(['mutation'])]
  165. public ?int $selectedConfigurableOption = null;
  166. /**
  167. * Super attribute values for configurable products
  168. * Format: [attribute_id => option_value]
  169. * Example: [123 => 56, 124 => 57]
  170. * Used for Configurable products
  171. */
  172. #[ApiProperty(required: false, description: 'Super attributes for configurable products')]
  173. #[Groups(['mutation'])]
  174. public ?array $superAttribute = null;
  175. /**
  176. * Quantities for grouped product associated products
  177. * Format: [associated_product_id => quantity]
  178. * Example: [101 => 2, 102 => 1]
  179. * Used for Grouped products
  180. */
  181. #[ApiProperty(required: false, description: 'Quantities for grouped product associated products')]
  182. #[Groups(['mutation'])]
  183. public ?array $qty = null;
  184. /**
  185. * Quantities for grouped product associated products (GraphQL-friendly).
  186. *
  187. * GraphQL input objects cannot have numeric keys (e.g. {101: 2}), so this accepts a JSON string
  188. * that can represent a map: {"101":2,"102":1}.
  189. *
  190. * Used for Grouped products.
  191. */
  192. #[ApiProperty(required: false, description: 'Grouped product quantities as JSON string. Example: {"101":2,"102":1}')]
  193. #[Groups(['mutation'])]
  194. public ?string $groupedQty = null;
  195. /**
  196. * Downloadable product links to purchase
  197. * Format: [link_id1, link_id2, ...]
  198. * Used for Downloadable products
  199. */
  200. #[ApiProperty(
  201. required: false,
  202. description: 'Downloadable product link IDs'
  203. )]
  204. #[Groups(['mutation'])]
  205. public ?array $links = null;
  206. /**
  207. * Customizable options for products
  208. * Format: [option_id => value]
  209. * Used for Virtual products with customizable options
  210. */
  211. #[ApiProperty(required: false, description: 'Customizable options')]
  212. #[Groups(['mutation'])]
  213. public ?array $customizableOptions = null;
  214. /**
  215. * Additional data for products
  216. * Used for any extra product-specific data
  217. */
  218. #[ApiProperty(required: false, description: 'Additional product data')]
  219. #[Groups(['mutation'])]
  220. public ?array $additional = null;
  221. /**
  222. * Booking product options (GraphQL-friendly).
  223. *
  224. * Bagisto expects booking options under the `booking` key when adding a booking product to cart.
  225. * GraphQL input objects cannot represent arbitrary/nested maps reliably in all clients, so this
  226. * accepts a JSON string (decoded server-side) that will be forwarded as `booking`.
  227. *
  228. * Examples:
  229. * - Appointment/Default/Table: {"type":"appointment","date":"2026-03-12","slot":"10:00 AM - 11:00 AM"}
  230. * - Rental (hourly): {"type":"rental","date":"2026-03-12","slot":{"from":1710208800,"to":1710212400}}
  231. * - Rental (daily): {"type":"rental","date_from":"2026-03-12","date_to":"2026-03-14","renting_type":"daily"}
  232. * - Event: {"type":"event","qty":{"12":1,"13":2}} (at least one ticket qty > 0 required)
  233. */
  234. #[ApiProperty(required: false, description: 'Booking options as JSON string')]
  235. #[Groups(['mutation'])]
  236. public ?string $booking = null;
  237. /**
  238. * Optional booking note (mainly for table booking).
  239. *
  240. * If provided, it will be merged into the decoded `booking` payload as `booking.note`.
  241. * This avoids clients having to embed/escape the note inside the booking JSON string.
  242. */
  243. #[ApiProperty(required: false, description: 'Booking note / special request')]
  244. #[Groups(['mutation'])]
  245. public ?string $specialNote = null;
  246. /**
  247. * Backward compatibility: previous name for `specialNote`.
  248. */
  249. #[ApiProperty(required: false, description: 'Deprecated: use specialNote')]
  250. #[Groups(['mutation'])]
  251. public ?string $bookingNote = null;
  252. }