-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62ad80d
commit 2a19a82
Showing
9 changed files
with
347 additions
and
13 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
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
31 changes: 31 additions & 0 deletions
31
src/Sylius/Bundle/PromotionBundle/Validator/Constraints/PromotionNotCouponBased.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,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\PromotionBundle\Validator\Constraints; | ||
|
||
use Symfony\Component\Validator\Constraint; | ||
|
||
final class PromotionNotCouponBased extends Constraint | ||
{ | ||
public string $message = 'sylius.promotion_coupon.promotion.not_coupon_based'; | ||
|
||
public function getTargets(): string | ||
{ | ||
return self::CLASS_CONSTRAINT; | ||
} | ||
|
||
public function validatedBy(): string | ||
{ | ||
return 'sylius_promotion_not_coupon_based_validator'; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Sylius/Bundle/PromotionBundle/Validator/PromotionNotCouponBasedValidator.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,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\PromotionBundle\Validator; | ||
|
||
use Sylius\Bundle\PromotionBundle\Validator\Constraints\PromotionNotCouponBased; | ||
use Sylius\Component\Promotion\Model\PromotionCouponInterface; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class PromotionNotCouponBasedValidator extends ConstraintValidator | ||
{ | ||
public function validate(mixed $value, Constraint $constraint): void | ||
{ | ||
if (null === $value) { | ||
return; | ||
} | ||
|
||
/** @var PromotionNotCouponBased $constraint */ | ||
Assert::isInstanceOf($constraint, PromotionNotCouponBased::class); | ||
|
||
/** @var PromotionCouponInterface $value */ | ||
Assert::isInstanceOf($value, PromotionCouponInterface::class); | ||
|
||
$promotion = $value->getPromotion(); | ||
if (null === $promotion) { | ||
return; | ||
} | ||
|
||
if (!$promotion->isCouponBased()) { | ||
$this->context | ||
->buildViolation($constraint->message) | ||
->atPath('promotion') | ||
->addViolation() | ||
; | ||
} | ||
} | ||
} |
Oops, something went wrong.