Created
November 29, 2022 10:13
-
-
Save magevision/718e439b6d78188cadc6995b45f8dc79 to your computer and use it in GitHub Desktop.
QuoteBackendValidationRule
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
<?php | |
declare(strict_types=1); | |
namespace MageVision\Blog80\Model\Quote\ValidationRule; | |
use Magento\Framework\Validation\ValidationResultFactory; | |
use Magento\Quote\Model\Quote; | |
use Magento\Quote\Model\ValidationRules\QuoteValidationRuleInterface; | |
class CustomValidationRule implements QuoteValidationRuleInterface | |
{ | |
/** | |
* @var ValidationResultFactory | |
*/ | |
private $validationResultFactory; | |
/** | |
* @param ValidationResultFactory $validationResultFactory | |
*/ | |
public function __construct( | |
ValidationResultFactory $validationResultFactory, | |
) { | |
$this->validationResultFactory = $validationResultFactory; | |
} | |
/** | |
* @inheritdoc | |
* | |
* @param Quote $quote | |
* @return array | |
*/ | |
public function validate(Quote $quote): array | |
{ | |
$validationErrors = []; | |
if ($quote->isVirtual()) { | |
$validationErrors[] = __( | |
'Quote is Virtual!' | |
); | |
} | |
return [$this->validationResultFactory->create(['errors' => $validationErrors])]; | |
} | |
} |
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
<?xml version="1.0"?> | |
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | |
<type name="Magento\Quote\Model\ValidationRules\QuoteValidationComposite"> | |
<arguments> | |
<argument name="validationRules" xsi:type="array"> | |
<item name="CustomValidationRule" xsi:type="object">MageVision\Blog80\Model\Quote\ValidationRule\CustomValidationRule</item> | |
</argument> | |
</arguments> | |
</type> | |
</config> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment