| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <?php
- namespace Webkul\BagistoApi\Models;
- use ApiPlatform\Metadata\ApiProperty;
- use ApiPlatform\Metadata\ApiResource;
- use ApiPlatform\Metadata\Get;
- use ApiPlatform\Metadata\GetCollection;
- use ApiPlatform\Metadata\Post;
- use ApiPlatform\Metadata\GraphQl\Mutation;
- use Symfony\Component\Serializer\Annotation\Groups;
- use Webkul\BagistoApi\Dto\CartInput;
- use Webkul\BagistoApi\State\CartTokenMutationProvider;
- use Webkul\BagistoApi\State\CartTokenProcessor;
- /**
- * CartToken - GraphQL API Resource for Cart Operations
- *
- * Provides mutations and queries for shopping cart management with token-based authentication.
- * Supports both authenticated users and guest users via cart tokens.
- *
- * Operations:
- * - createCartToken: Create new guest cart with unique UUID token
- * - updateCartItem: Update cart item quantity
- * - removeCartItem: Remove item from cart
- * - readCart: Get single cart details
- * - cartCollection: Get all customer carts
- * - mergeGuestCart: Merge guest cart to customer cart on login
- * - applyCouponCode: Apply discount coupon
- */
- #[ApiResource(
- routePrefix: '/api/shop',
- shortName: 'CartToken',
- paginationEnabled: false,
- uriTemplate: '/cart-tokens/{id}',
- operations: [
- // new Post(
- // name: 'create',
- // uriTemplate: '/cart-tokens',
- // input: CartInput::class,
- // output: CartToken::class,
- // processor: CartTokenProcessor::class,
- // denormalizationContext: [
- // 'allow_extra_attributes' => true,
- // 'groups' => ['mutation'],
- // ],
- // normalizationContext: [
- // 'groups' => ['mutation'],
- // ],
- // description: 'Create new guest cart with unique UUID token or get authenticated customer cart.',
- // ),
- new GetCollection(uriTemplate: '/cart-tokens',
- provider: CartTokenMutationProvider::class,
- normalizationContext: [
- 'groups' => ['query'],
- ],
- description: 'Get all customer carts',
- ),
- new Get(uriTemplate: '/cart-tokens/{id}',
- provider: CartTokenMutationProvider::class,
- normalizationContext: [
- 'groups' => ['query'],
- ],
- description: 'Get single cart by ID',
- ),
- ],
- graphQlOperations: [
- new Mutation(
- name: 'create',
- input: CartInput::class,
- output: CartToken::class,
- provider: CartTokenMutationProvider::class,
- processor: CartTokenProcessor::class,
- denormalizationContext: [
- 'allow_extra_attributes' => true,
- 'groups' => ['mutation'],
- ],
- normalizationContext: [
- 'groups' => ['mutation'],
- ],
- description: 'Create new guest cart with unique UUID token or get authenticated customer cart. Returns sessionToken for guests.',
- ),
- ]
- )]
- class CartToken
- {
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?int $id = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?string $cartToken = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?int $customerId = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?int $channelId = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?int $itemsCount = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?array $items = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?float $subtotal = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?float $baseSubtotal = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?float $discountAmount = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?float $baseDiscountAmount = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?float $taxAmount = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?float $baseTaxAmount = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?float $shippingAmount = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?float $baseShippingAmount = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?float $grandTotal = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?float $baseGrandTotal = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?string $formattedSubtotal = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?string $formattedDiscountAmount = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?string $formattedTaxAmount = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?string $formattedShippingAmount = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?string $formattedGrandTotal = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?string $couponCode = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?bool $success = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?string $message = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?array $carts = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?string $sessionToken = null;
- #[ApiProperty(readable: true, writable: false)]
- #[Groups(['query', 'mutation'])]
- public ?bool $isGuest = null;
- }
|