-
-
Notifications
You must be signed in to change notification settings - Fork 1
Add reviews #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add reviews #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| { | ||
| "permissions": { | ||
| "defaultMode": "acceptEdits", | ||
| "allow": [], | ||
| "deny": [] | ||
| } | ||
| "permissions": { | ||
| "defaultMode": "acceptEdits", | ||
| "allow": [], | ||
| "deny": [] | ||
| }, | ||
| "enabledMcpjsonServers": [ | ||
| "playwright" | ||
| ], | ||
| "enableAllProjectMcpServers": true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "mcpServers": { | ||
| "playwright": { | ||
| "type": "stdio", | ||
| "command": "npx", | ||
| "args": [ | ||
| "@playwright/mcp@latest" | ||
| ], | ||
| "env": {} | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Setono\SyliusReviewPlugin\Checker; | ||
|
|
||
| use Setono\SyliusReviewPlugin\Model\StoreReviewInterface; | ||
| use Sylius\Component\Review\Model\ReviewInterface; | ||
|
|
||
| final class ReviewAutoApprovalChecker implements ReviewAutoApprovalCheckerInterface | ||
| { | ||
| public function __construct( | ||
| private readonly int $minimumRatingForAutoApproval = 4, | ||
| ) { | ||
| } | ||
|
|
||
| public function shouldAutoApprove(StoreReviewInterface $review): bool | ||
| { | ||
| $rating = $review->getRating(); | ||
|
|
||
| return null !== $rating && $rating >= $this->minimumRatingForAutoApproval; | ||
| } | ||
|
|
||
| public function shouldAutoApproveProductReview(ReviewInterface $review): bool | ||
| { | ||
| $rating = $review->getRating(); | ||
|
|
||
| return null !== $rating && $rating >= $this->minimumRatingForAutoApproval; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Setono\SyliusReviewPlugin\Checker; | ||
|
|
||
| use Setono\SyliusReviewPlugin\Model\StoreReviewInterface; | ||
| use Sylius\Component\Review\Model\ReviewInterface; | ||
|
|
||
| interface ReviewAutoApprovalCheckerInterface | ||
| { | ||
| /** | ||
| * Returns true if the store review should be auto-approved | ||
| */ | ||
| public function shouldAutoApprove(StoreReviewInterface $review): bool; | ||
|
|
||
| /** | ||
| * Returns true if the product review should be auto-approved | ||
| */ | ||
| public function shouldAutoApproveProductReview(ReviewInterface $review): bool; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Setono\SyliusReviewPlugin\Checker\ReviewableOrder; | ||
|
|
||
| use Setono\CompositeCompilerPass\CompositeService; | ||
| use Sylius\Component\Core\Model\OrderInterface; | ||
|
|
||
| /** | ||
| * @extends CompositeService<ReviewableOrderCheckerInterface> | ||
| */ | ||
| final class CompositeReviewableOrderChecker extends CompositeService implements ReviewableOrderCheckerInterface | ||
| { | ||
| public function check(OrderInterface $order): ReviewableOrderCheck | ||
| { | ||
| foreach ($this->services as $service) { | ||
| $check = $service->check($order); | ||
| if (!$check->reviewable) { | ||
| return $check; | ||
| } | ||
| } | ||
|
|
||
| return ReviewableOrderCheck::reviewable(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Setono\SyliusReviewPlugin\Checker\ReviewableOrder; | ||
|
|
||
| use Sylius\Component\Core\Model\OrderInterface; | ||
|
|
||
| final class OrderFulfilledReviewableOrderChecker implements ReviewableOrderCheckerInterface | ||
| { | ||
| public function check(OrderInterface $order): ReviewableOrderCheck | ||
| { | ||
| if ($order->getState() === OrderInterface::STATE_FULFILLED) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add an array of 'reviewable states' in the contructor and make those configurable in the plugin configuration |
||
| return ReviewableOrderCheck::reviewable(); | ||
| } | ||
|
|
||
| return ReviewableOrderCheck::notReviewable('setono_sylius_review.ui.order_not_fulfilled'); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Setono\SyliusReviewPlugin\Checker\ReviewableOrder; | ||
|
|
||
| final class ReviewableOrderCheck | ||
| { | ||
| private function __construct( | ||
| public readonly bool $reviewable, | ||
| public readonly ?string $reason = null, | ||
| ) { | ||
| } | ||
|
|
||
| public static function reviewable(): self | ||
| { | ||
| return new self(true); | ||
| } | ||
|
|
||
| public static function notReviewable(string $reason): self | ||
| { | ||
| return new self(false, $reason); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Setono\SyliusReviewPlugin\Checker\ReviewableOrder; | ||
|
|
||
| use Sylius\Component\Core\Model\OrderInterface; | ||
|
|
||
| interface ReviewableOrderCheckerInterface | ||
| { | ||
| public function check(OrderInterface $order): ReviewableOrderCheck; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Setono\SyliusReviewPlugin\Checker\ReviewableOrder; | ||
|
|
||
| use Setono\SyliusReviewPlugin\Repository\StoreReviewRepositoryInterface; | ||
| use Sylius\Component\Core\Model\OrderInterface; | ||
|
|
||
| final class StoreReviewEditableReviewableOrderChecker implements ReviewableOrderCheckerInterface | ||
| { | ||
| public function __construct( | ||
| private readonly StoreReviewRepositoryInterface $storeReviewRepository, | ||
| private readonly string $editablePeriod = '+24 hours', | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this configurable in the plugin configuration. Also make it possible to disable this functionality because some store owners might want to allow users to be able to edit forever |
||
| ) { | ||
| } | ||
|
|
||
| public function check(OrderInterface $order): ReviewableOrderCheck | ||
| { | ||
| $existingReview = $this->storeReviewRepository->findOneByOrder($order); | ||
|
|
||
| if (null === $existingReview) { | ||
| return ReviewableOrderCheck::reviewable(); | ||
| } | ||
|
|
||
| $createdAt = $existingReview->getCreatedAt(); | ||
| if (null === $createdAt) { | ||
| return ReviewableOrderCheck::reviewable(); | ||
| } | ||
|
|
||
| $editableUntil = \DateTimeImmutable::createFromInterface($createdAt)->modify($this->editablePeriod); | ||
|
|
||
| if (new \DateTimeImmutable() < $editableUntil) { | ||
| return ReviewableOrderCheck::reviewable(); | ||
| } | ||
|
|
||
| return ReviewableOrderCheck::notReviewable('setono_sylius_review.ui.review_period_expired'); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to
AutoApprovalCheckerInterfaceand make it use the composite pattern used elsewhere in this plugin to allow plugin users to define their own 'auto approval checker' functionality