Skip to content

Commit

Permalink
Feat: add new route (#24)
Browse files Browse the repository at this point in the history
Add new PUT route for CustomerFamilyProductPrice

Co-authored-by: mdevaud <mdevaud@openstudio.fr>
  • Loading branch information
mdevaud and mdevaud authored May 14, 2024
1 parent e8ed25e commit 38ae801
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
47 changes: 47 additions & 0 deletions Api/Controller/CustomerFamilyProductPriceUpdateByRef.php
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() );
}
}
6 changes: 6 additions & 0 deletions Api/Resource/CustomerFamilyProductPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use CustomerFamily\Api\Controller\CustomerFamilyProductPriceUpdateByRef;
use CustomerFamily\Api\State\CustomerFamilyPricePersistProcessor;
use CustomerFamily\Model\Map\CustomerFamilyProductPriceTableMap;
use Propel\Runtime\Map\TableMap;
Expand All @@ -24,6 +25,11 @@
new Get(
uriTemplate: '/admin/customer_family_product_prices/{productSaleElementsId}/family/{customerFamilyCode}',
),
new Put(
uriTemplate: '/admin/customer_family_product_prices/reference/{productSaleElementsRef}/family/{customerFamilyCode}',
controller: CustomerFamilyProductPriceUpdateByRef::class,
read: false,
),
new Put(
uriTemplate: '/admin/customer_family_product_prices/{productSaleElementsId}/family/{customerFamilyCode}',
),
Expand Down
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<descriptive locale="fr_FR">
<title>Famille de clients et prix d'achat</title>
</descriptive>
<version>3.1.3</version>
<version>3.1.4</version>
<author>
<name>Guillaume Barral / Etienne Perriere</name>
<email>gbarral@openstudio.fr / eperriere@openstudio.fr</email>
Expand Down

0 comments on commit 38ae801

Please sign in to comment.