| @@ 10-57 (lines=48) @@ | ||
| 7 | use Sylius\SyliusShopApiPlugin\Command\PutOptionBasedConfigurableItemToCart; |
|
| 8 | use Symfony\Component\HttpFoundation\Request; |
|
| 9 | ||
| 10 | final class PutOptionBasedConfigurableItemToCartRequest |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var string |
|
| 14 | */ |
|
| 15 | private $token; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @var string |
|
| 19 | */ |
|
| 20 | private $productCode; |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @var array|null |
|
| 24 | */ |
|
| 25 | private $options; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * @var int |
|
| 29 | */ |
|
| 30 | private $quantity; |
|
| 31 | ||
| 32 | private function __construct($token, $productCode, $options, $quantity) |
|
| 33 | { |
|
| 34 | $this->token = $token; |
|
| 35 | $this->productCode = $productCode; |
|
| 36 | $this->options = $options; |
|
| 37 | $this->quantity = $quantity; |
|
| 38 | } |
|
| 39 | ||
| 40 | public static function fromArray(array $item) |
|
| 41 | { |
|
| 42 | return new self($item['token'] ?? null, $item['productCode'] ?? null, $item['options'] ?? null, $item['quantity'] ?? null); |
|
| 43 | } |
|
| 44 | ||
| 45 | public static function fromRequest(Request $request) |
|
| 46 | { |
|
| 47 | return new self($request->attributes->get('token'), $request->request->get('productCode'), $request->request->get('options'), $request->request->getInt('quantity', 1)); |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * @return PutOptionBasedConfigurableItemToCart |
|
| 52 | */ |
|
| 53 | public function getCommand() |
|
| 54 | { |
|
| 55 | return new PutOptionBasedConfigurableItemToCart($this->token, $this->productCode, $this->options, $this->quantity); |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||
| @@ 10-57 (lines=48) @@ | ||
| 7 | use Sylius\SyliusShopApiPlugin\Command\PutVariantBasedConfigurableItemToCart; |
|
| 8 | use Symfony\Component\HttpFoundation\Request; |
|
| 9 | ||
| 10 | final class PutVariantBasedConfigurableItemToCartRequest |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var string |
|
| 14 | */ |
|
| 15 | private $token; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @var string |
|
| 19 | */ |
|
| 20 | private $productCode; |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @var string |
|
| 24 | */ |
|
| 25 | private $variantCode; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * @var int |
|
| 29 | */ |
|
| 30 | private $quantity; |
|
| 31 | ||
| 32 | private function __construct($token, $productCode, $variantCode, $quantity) |
|
| 33 | { |
|
| 34 | $this->token = $token; |
|
| 35 | $this->productCode = $productCode; |
|
| 36 | $this->variantCode = $variantCode; |
|
| 37 | $this->quantity = $quantity; |
|
| 38 | } |
|
| 39 | ||
| 40 | public static function fromArray(array $item) |
|
| 41 | { |
|
| 42 | return new self($item['token'] ?? null, $item['productCode'] ?? null, $item['variantCode'] ?? null, $item['quantity'] ?? null); |
|
| 43 | } |
|
| 44 | ||
| 45 | public static function fromRequest(Request $request) |
|
| 46 | { |
|
| 47 | return new self($request->attributes->get('token'), $request->request->get('productCode'), $request->request->get('variantCode'), $request->request->getInt('quantity', 1)); |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * @return PutVariantBasedConfigurableItemToCart |
|
| 52 | */ |
|
| 53 | public function getCommand() |
|
| 54 | { |
|
| 55 | return new PutVariantBasedConfigurableItemToCart($this->token, $this->productCode, $this->variantCode, $this->quantity); |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||