Skip to content

Commit 472d911

Browse files
authored
GLUE-10972: API: Create Request for Quote (#8241)
GLUE-10972 API: Create Request for Quote
1 parent 7e79d7b commit 472d911

4 files changed

Lines changed: 96 additions & 0 deletions

File tree

src/Spryker/Glue/CustomersRestApi/CustomersRestApiFactory.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Spryker\Glue\CustomersRestApi\Processor\Relationship\AddressByCheckoutDataResourceRelationshipExpander;
3737
use Spryker\Glue\CustomersRestApi\Processor\Relationship\AddressResourceRelationshipExpanderInterface;
3838
use Spryker\Glue\CustomersRestApi\Processor\Relationship\CustomerByCompanyUserResourceRelationshipExpander;
39+
use Spryker\Glue\CustomersRestApi\Processor\Relationship\CustomerByQuoteRequestResourceRelationshipExpander;
3940
use Spryker\Glue\CustomersRestApi\Processor\Relationship\CustomerResourceRelationshipExpanderInterface;
4041
use Spryker\Glue\CustomersRestApi\Processor\RestResponseBuilder\AddressRestResponseBuilder;
4142
use Spryker\Glue\CustomersRestApi\Processor\RestResponseBuilder\AddressRestResponseBuilderInterface;
@@ -161,6 +162,17 @@ public function createCustomerByCompanyUserResourceRelationshipExpander(): Custo
161162
);
162163
}
163164

165+
/**
166+
* @return \Spryker\Glue\CustomersRestApi\Processor\Relationship\CustomerResourceRelationshipExpanderInterface
167+
*/
168+
public function createCustomerByQuoteRequestResourceRelationshipExpander(): CustomerResourceRelationshipExpanderInterface
169+
{
170+
return new CustomerByQuoteRequestResourceRelationshipExpander(
171+
$this->createCustomerRestResponseBuilder(),
172+
$this->createCustomerResourceMapper()
173+
);
174+
}
175+
164176
/**
165177
* @return \Spryker\Glue\CustomersRestApi\Processor\Relationship\AddressResourceRelationshipExpanderInterface
166178
*/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/**
4+
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5+
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6+
*/
7+
8+
namespace Spryker\Glue\CustomersRestApi\Plugin\GlueApplication;
9+
10+
use Spryker\Glue\CustomersRestApi\CustomersRestApiConfig;
11+
use Spryker\Glue\GlueApplication\Rest\Request\Data\RestRequestInterface;
12+
use Spryker\Glue\GlueApplicationExtension\Dependency\Plugin\ResourceRelationshipPluginInterface;
13+
use Spryker\Glue\Kernel\AbstractPlugin;
14+
15+
/**
16+
* @method \Spryker\Glue\CustomersRestApi\CustomersRestApiFactory getFactory()
17+
*/
18+
class CustomerByQuoteRequestResourceRelationshipPlugin extends AbstractPlugin implements ResourceRelationshipPluginInterface
19+
{
20+
/**
21+
* {@inheritDoc}
22+
* - Adds customer resource as a relationship.
23+
*
24+
* @api
25+
*
26+
* @param \Spryker\Glue\GlueApplication\Rest\JsonApi\RestResourceInterface[] $resources
27+
* @param \Spryker\Glue\GlueApplication\Rest\Request\Data\RestRequestInterface $restRequest
28+
*
29+
* @return void
30+
*/
31+
public function addResourceRelationships(array $resources, RestRequestInterface $restRequest): void
32+
{
33+
$this->getFactory()
34+
->createCustomerByQuoteRequestResourceRelationshipExpander()
35+
->addResourceRelationships($resources, $restRequest);
36+
}
37+
38+
/**
39+
* {@inheritDoc}
40+
*
41+
* @api
42+
*
43+
* @return string
44+
*/
45+
public function getRelationshipResourceType(): string
46+
{
47+
return CustomersRestApiConfig::RESOURCE_CUSTOMERS;
48+
}
49+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5+
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6+
*/
7+
8+
namespace Spryker\Glue\CustomersRestApi\Processor\Relationship;
9+
10+
use Generated\Shared\Transfer\CustomerTransfer;
11+
use Generated\Shared\Transfer\QuoteRequestTransfer;
12+
use Spryker\Glue\GlueApplication\Rest\JsonApi\RestResourceInterface;
13+
14+
class CustomerByQuoteRequestResourceRelationshipExpander extends AbstractCustomerResourceRelationshipExpander
15+
{
16+
/**
17+
* @param \Spryker\Glue\GlueApplication\Rest\JsonApi\RestResourceInterface $restResource
18+
*
19+
* @return \Generated\Shared\Transfer\CustomerTransfer|null
20+
*/
21+
protected function findCustomerTransferInPayload(RestResourceInterface $restResource): ?CustomerTransfer
22+
{
23+
/** @var \Generated\Shared\Transfer\QuoteRequestTransfer|null $payload */
24+
$payload = $restResource->getPayload();
25+
if (!$payload || !($payload instanceof QuoteRequestTransfer) || !$payload->getCompanyUser()->getCustomer()) {
26+
return null;
27+
}
28+
29+
return $payload->getCompanyUser()->getCustomer();
30+
}
31+
}

src/Spryker/Shared/CustomersRestApi/Transfer/customers_rest_api.transfer.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,8 @@
202202
<property name="shippingAddress" type="RestAddress" restRequestParameter="yes"/>
203203
</transfer>
204204

205+
<transfer name="QuoteRequest">
206+
<property name="companyUser" type="CompanyUser"/>
207+
</transfer>
208+
205209
</transfers>

0 commit comments

Comments
 (0)