-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
graphQl-512: added street lines validation
- Loading branch information
Vitaliy Boyko
committed
Apr 3, 2019
1 parent
4a28abb
commit 2d0eecc
Showing
7 changed files
with
300 additions
and
1 deletion.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
app/code/Magento/QuoteGraphQl/Model/Cart/QuoteAddress/Validator.php
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,45 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Cart\QuoteAddress; | ||
|
||
use Magento\Customer\Helper\Address as AddressHelper; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Quote\Model\Quote\Address as QuoteAddress; | ||
|
||
/** | ||
* Validate Quote Address | ||
*/ | ||
class Validator | ||
{ | ||
/** | ||
* @var AddressHelper | ||
*/ | ||
private $addressHelper; | ||
|
||
/** | ||
* @param AddressHelper $addressHelper | ||
*/ | ||
public function __construct(AddressHelper $addressHelper) | ||
{ | ||
$this->addressHelper = $addressHelper; | ||
} | ||
|
||
/** | ||
* Additional Quote Address validation for the GraphQl endpoint | ||
* | ||
* @param QuoteAddress $quoteAddress | ||
* @throws GraphQlInputException | ||
*/ | ||
public function validate(QuoteAddress $quoteAddress) | ||
{ | ||
$maxAllowedLineCount = $this->addressHelper->getStreetLines(); | ||
if (is_array($quoteAddress->getStreet()) && count($quoteAddress->getStreet()) > $maxAllowedLineCount) { | ||
throw new GraphQlInputException(__('"Street Address" cannot contain more than %1 lines.', $maxAllowedLineCount)); | ||
} | ||
} | ||
} |
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
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