-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[shopsys] added product inquiries (#3465)
- Loading branch information
Showing
9 changed files
with
231 additions
and
4 deletions.
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,84 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrontendApiBundle\Model\Mutation\Inquiry; | ||
|
||
use Overblog\GraphQLBundle\Definition\Argument; | ||
use Psr\Log\LoggerInterface; | ||
use Shopsys\FrameworkBundle\Component\Domain\Domain; | ||
use Shopsys\FrameworkBundle\Model\Customer\User\CurrentCustomerUser; | ||
use Shopsys\FrameworkBundle\Model\Inquiry\InquiryData; | ||
use Shopsys\FrameworkBundle\Model\Inquiry\InquiryDataFactory; | ||
use Shopsys\FrameworkBundle\Model\Inquiry\InquiryFacade; | ||
use Shopsys\FrameworkBundle\Model\Inquiry\Mail\InquiryMailFacade; | ||
use Shopsys\FrameworkBundle\Model\Product\Exception\ProductNotFoundException; | ||
use Shopsys\FrameworkBundle\Model\Product\ProductFacade; | ||
use Shopsys\FrontendApiBundle\Model\Mutation\AbstractMutation; | ||
use Shopsys\FrontendApiBundle\Model\Resolver\Products\Exception\ProductNotFoundUserError; | ||
|
||
class CreateInquiryMutation extends AbstractMutation | ||
{ | ||
/** | ||
* @param \Psr\Log\LoggerInterface $logger | ||
* @param \Shopsys\FrameworkBundle\Model\Inquiry\InquiryDataFactory $inquiryDataFactory | ||
* @param \Shopsys\FrameworkBundle\Model\Inquiry\InquiryFacade $inquiryFacade | ||
* @param \Shopsys\FrameworkBundle\Model\Product\ProductFacade $productFacade | ||
* @param \Shopsys\FrameworkBundle\Model\Inquiry\Mail\InquiryMailFacade $inquiryMailFacade | ||
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain | ||
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CurrentCustomerUser $currentCustomerUser | ||
*/ | ||
public function __construct( | ||
protected readonly LoggerInterface $logger, | ||
protected readonly InquiryDataFactory $inquiryDataFactory, | ||
protected readonly InquiryFacade $inquiryFacade, | ||
protected readonly ProductFacade $productFacade, | ||
protected readonly InquiryMailFacade $inquiryMailFacade, | ||
protected readonly Domain $domain, | ||
protected readonly CurrentCustomerUser $currentCustomerUser, | ||
) { | ||
} | ||
|
||
/** | ||
* @param \Overblog\GraphQLBundle\Definition\Argument $argument | ||
* @return bool | ||
*/ | ||
public function createInquiryMutation(Argument $argument): bool | ||
{ | ||
try { | ||
$inquiryData = $this->createInquiryDataFromArgument($argument); | ||
$inquiry = $this->inquiryFacade->create($inquiryData); | ||
|
||
$this->inquiryMailFacade->sendMail($inquiry); | ||
|
||
return true; | ||
} catch (ProductNotFoundException) { | ||
throw new ProductNotFoundUserError(sprintf('Product with UUID "%s" not found', $argument['input']['productUuid'])); | ||
} | ||
} | ||
|
||
/** | ||
* @param \Overblog\GraphQLBundle\Definition\Argument $argument | ||
* @return \Shopsys\FrameworkBundle\Model\Inquiry\InquiryData | ||
*/ | ||
protected function createInquiryDataFromArgument(Argument $argument): InquiryData | ||
{ | ||
$input = $argument['input']; | ||
|
||
$inquiryData = $this->inquiryDataFactory->create($this->domain->getId()); | ||
$product = $this->productFacade->getByUuid($input['productUuid']); | ||
|
||
$inquiryData->firstName = $input['firstName']; | ||
$inquiryData->lastName = $input['lastName']; | ||
$inquiryData->email = $input['email']; | ||
$inquiryData->telephone = $input['telephone']; | ||
$inquiryData->companyName = $input['companyName'] ?? null; | ||
$inquiryData->companyNumber = $input['companyNumber'] ?? null; | ||
$inquiryData->companyTaxNumber = $input['companyTaxNumber'] ?? null; | ||
$inquiryData->note = $input['note'] ?? null; | ||
$inquiryData->customerUser = $this->currentCustomerUser->findCurrentCustomerUser(); | ||
$inquiryData->product = $product; | ||
|
||
return $inquiryData; | ||
} | ||
} |
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
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
12 changes: 12 additions & 0 deletions
12
src/Resources/config/graphql-types/EnumType/ProductTypeEnumDecorator.types.yaml
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,12 @@ | ||
ProductTypeEnumDecorator: | ||
type: enum | ||
decorator: true | ||
config: | ||
description: "One of possible product types" | ||
values: | ||
BASIC: | ||
value: '@=constant("Shopsys\\FrameworkBundle\\Model\\Product\\ProductTypeEnum::TYPE_BASIC")' | ||
description: "Basic product" | ||
INQUIRY: | ||
value: '@=constant("Shopsys\\FrameworkBundle\\Model\\Product\\ProductTypeEnum::TYPE_INQUIRY")' | ||
description: "Product with inquiry form instead of add to cart button" |
52 changes: 52 additions & 0 deletions
52
...urces/config/graphql-types/ModelType/Inquiry/Input/CreateInquiryInputDecorator.types.yaml
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,52 @@ | ||
CreateInquiryInputDecorator: | ||
type: input-object | ||
inherits: | ||
- 'NameInputObjectDecorator' | ||
- 'TelephoneInputObjectDecorator' | ||
decorator: true | ||
config: | ||
fields: | ||
productUuid: | ||
type: "Uuid!" | ||
description: "Product UUID" | ||
email: | ||
type: "String!" | ||
description: "The customer's email address" | ||
validation: | ||
- NotBlank: | ||
message: "Please enter email" | ||
- Email: | ||
message: "Please enter valid email" | ||
- Length: | ||
max: 255 | ||
maxMessage: "Email cannot be longer than {{ limit }} characters" | ||
companyName: | ||
type: "String" | ||
description: "The customer’s company name" | ||
validation: | ||
- Length: | ||
max: 100 | ||
maxMessage: "Company name cannot be longer than {{ limit }} characters" | ||
companyNumber: | ||
type: "String" | ||
description: "The customer’s company identification number" | ||
validation: | ||
- Length: | ||
max: 50 | ||
maxMessage: "Identification number cannot be longer than {{ limit }} characters" | ||
- Regex: | ||
pattern: '/^[0-9]+$/' | ||
message: "Please fill in numbers only" | ||
companyTaxNumber: | ||
type: "String" | ||
description: "The customer’s company tax number" | ||
validation: | ||
- Length: | ||
max: 50 | ||
maxMessage: "Tax number cannot be longer than {{ limit }} characters" | ||
- Regex: | ||
pattern: '/^[0-9A-Z]*([0-9]+[A-Z]+|[A-Z]+[0-9]+)[0-9A-Z]*$/' | ||
message: "Please check Tax number format" | ||
note: | ||
type: "String" | ||
description: "Customer's question or note to the inquiry product" |
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