-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new PUT route for CustomerFamilyProductPrice Co-authored-by: mdevaud <mdevaud@openstudio.fr>
- Loading branch information
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace CustomerFamily\Api\Controller; | ||
|
||
use CustomerFamily\Api\Resource\CustomerFamilyProductPrice; | ||
use CustomerFamily\Model\CustomerFamilyProductPriceQuery; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Attribute\AsController; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Thelia\Api\Bridge\Propel\Service\ApiResourcePropelTransformerService; | ||
|
||
#[AsController] | ||
class CustomerFamilyProductPriceUpdateByRef | ||
{ | ||
public function __construct( | ||
private ApiResourcePropelTransformerService $apiResourcePropelTransformerService | ||
) | ||
{ | ||
} | ||
|
||
public function __invoke(string $productSaleElementsRef, string $customerFamilyCode, Request $request) | ||
{ | ||
$customerFamilyProductPrice = CustomerFamilyProductPriceQuery::create() | ||
->useProductSaleElementsQuery() | ||
->filterByRef($productSaleElementsRef) | ||
->endUse() | ||
->useCustomerFamilyQuery() | ||
->filterByCode($customerFamilyCode) | ||
->endUse() | ||
->findOne() | ||
; | ||
|
||
if(!$customerFamilyProductPrice){ | ||
throw new NotFoundHttpException('NotFound'); | ||
} | ||
/** @var CustomerFamilyProductPrice $customerFamilyProductPriceResource */ | ||
$customerFamilyProductPriceResource = $this->apiResourcePropelTransformerService->modelToResource(CustomerFamilyProductPrice::class,$customerFamilyProductPrice,[]); | ||
|
||
/** @var CustomerFamilyProductPrice $data */ | ||
$data = $request->get('data'); | ||
|
||
return $customerFamilyProductPriceResource | ||
->setPromo(isset($data->promo) ? $data->getPromo() : $customerFamilyProductPriceResource->getPromo() ) | ||
->setPrice( isset($data->price) ? $data->getPrice() : $customerFamilyProductPriceResource->getPrice()) | ||
->setPromoPrice( isset($data->promoPrice) ? $data->getPromoPrice() : $customerFamilyProductPriceResource->getPromoPrice() ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters