|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Thelia package. |
| 5 | + * http://www.thelia.net |
| 6 | + * |
| 7 | + * (c) OpenStudio <info@thelia.net> |
| 8 | + * |
| 9 | + * For the full copyright and license information, please view the LICENSE |
| 10 | + * file that was distributed with this source code. |
| 11 | + */ |
| 12 | + |
| 13 | +namespace CustomerFamily\Api\State; |
| 14 | + |
| 15 | +use ApiPlatform\Metadata\Delete; |
| 16 | +use ApiPlatform\Metadata\Operation; |
| 17 | +use ApiPlatform\Metadata\Post; |
| 18 | +use ApiPlatform\Metadata\Put; |
| 19 | +use ApiPlatform\State\ProcessorInterface; |
| 20 | +use ApiPlatform\State\ProviderInterface; |
| 21 | +use CustomerFamily\Api\Resource\CustomerFamilyProductPrice; |
| 22 | +use CustomerFamily\Model\CustomerFamilyProductPriceQuery; |
| 23 | +use CustomerFamily\Model\CustomerFamilyQuery; |
| 24 | +use Thelia\Api\Bridge\Propel\Service\ApiResourcePropelTransformerService; |
| 25 | +use Thelia\Model\ProductSaleElementsQuery; |
| 26 | +use TntSearch\Index\Customer; |
| 27 | + |
| 28 | +class CustomerFamilyPriceProvider implements ProviderInterface |
| 29 | +{ |
| 30 | + |
| 31 | + public function __construct( |
| 32 | + private readonly ApiResourcePropelTransformerService $apiResourcePropelTransformerService |
| 33 | + ) |
| 34 | + { |
| 35 | + } |
| 36 | + |
| 37 | + public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null |
| 38 | + { |
| 39 | + if(!isset($uriVariables['customerFamilyCode']) || !isset($uriVariables['productSaleElementsId'])) { |
| 40 | + return null; |
| 41 | + } |
| 42 | + $customerFamily = CustomerFamilyQuery::create()->findOneByCode($uriVariables['customerFamilyCode']); |
| 43 | + if (null === $customerFamily) { |
| 44 | + return null; |
| 45 | + } |
| 46 | + $customerFamilyPrice = CustomerFamilyProductPriceQuery::create() |
| 47 | + ->filterByCustomerFamilyId($customerFamily->getId()) |
| 48 | + ->filterByProductSaleElementsId($uriVariables['productSaleElementsId']) |
| 49 | + ->findOne(); |
| 50 | + if (null === $customerFamilyPrice) { |
| 51 | + return null; |
| 52 | + } |
| 53 | + return $this->apiResourcePropelTransformerService->modelToResource( |
| 54 | + CustomerFamilyProductPrice::class, |
| 55 | + $customerFamilyPrice, |
| 56 | + $context |
| 57 | + ); |
| 58 | + } |
| 59 | +} |
0 commit comments