-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from vanilophp/feat-promotion
Basic Promotion Module
- Loading branch information
Showing
51 changed files
with
1,663 additions
and
6 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
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,6 @@ | ||
* text=auto | ||
|
||
/.github export-ignore | ||
/Tests export-ignore | ||
.gitattributes export-ignore | ||
phpunit.xml export-ignore |
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,13 @@ | ||
name: Close Pull Request | ||
|
||
on: | ||
pull_request_target: | ||
types: [opened] | ||
|
||
jobs: | ||
run: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: superbrothers/close-pull-request@v3 | ||
with: | ||
comment: "Thank you for your pull request. However, you have submitted this PR on a Vanilo sub-module which is a read-only split of `vanilo/framework`. Please submit your PR on the https://github.com/vanilophp/framework repository.<br><br>Thanks!" |
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,28 @@ | ||
name: tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
strategy: | ||
matrix: | ||
php: ['8.2', '8.3'] | ||
laravel: ['10.43', '10.48', '11.0', '11.14'] | ||
name: PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@master | ||
- name: Installing PHP | ||
uses: shivammathur/setup-php@master | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: mbstring, json, sqlite3 | ||
tools: composer:v2 | ||
- name: Lock Laravel Version | ||
run: composer require "illuminate/support:${{ matrix.laravel }}.*" --no-update -v && composer require "illuminate/console:${{ matrix.laravel }}.*" --no-update -v | ||
- name: Composer Install | ||
run: composer install --prefer-dist --no-progress --no-interaction | ||
- name: Run Tests | ||
run: php vendor/bin/phpunit --testdox |
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Promotion\Actions; | ||
|
||
use Nette\Schema\Expect; | ||
use Nette\Schema\Schema; | ||
use Vanilo\Adjustments\Adjusters\SimpleDiscount; | ||
use Vanilo\Adjustments\Contracts\Adjuster; | ||
use Vanilo\Promotion\Contracts\PromotionActionType; | ||
|
||
class CartFixedDiscount implements PromotionActionType | ||
{ | ||
public const DEFAULT_ID = 'cart_fixed_discount'; | ||
|
||
public static function getName(): string | ||
{ | ||
return __('Cart Fixed Discount'); | ||
} | ||
|
||
public function getAdjuster(array $configuration): Adjuster | ||
{ | ||
return new SimpleDiscount($configuration['amount']); | ||
} | ||
|
||
public function getSchema(): Schema | ||
{ | ||
return Expect::structure(['amount' => Expect::float(0)->required()])->castTo('array'); | ||
} | ||
|
||
public function getSchemaSample(array $mergeWith = null): array | ||
{ | ||
return ['amount' => 19.99]; | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Contains the Coupon interface. | ||
* | ||
* @copyright Copyright (c) 2024 Attila Fulop | ||
* @author Attila Fulop | ||
* @license MIT | ||
* @since 2024-07-09 | ||
* | ||
*/ | ||
|
||
namespace Vanilo\Promotion\Contracts; | ||
|
||
interface Coupon | ||
{ | ||
public static function findByCode(string $code): ?Coupon; | ||
|
||
public function getPromotion(): Promotion; | ||
|
||
public function canBeUsed(): bool; | ||
|
||
public function isExpired(): bool; | ||
|
||
public function isDepleted(): bool; | ||
} |
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Contains the Promotion interface. | ||
* | ||
* @copyright Copyright (c) 2024 Attila Fulop | ||
* @author Attila Fulop | ||
* @license MIT | ||
* @since 2024-07-09 | ||
* | ||
*/ | ||
|
||
namespace Vanilo\Promotion\Contracts; | ||
|
||
interface Promotion | ||
{ | ||
public function isValid(?\DateTimeInterface $at = null): bool; | ||
|
||
public function addRule(PromotionRuleType|string $type, array $configuration): self; | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Promotion\Contracts; | ||
|
||
use Vanilo\Adjustments\Contracts\Adjustable; | ||
use Vanilo\Contracts\Configurable; | ||
|
||
interface PromotionAction extends Configurable | ||
{ | ||
public function getActionType(): PromotionActionType; | ||
|
||
public function execute(object $subject): Adjustable; | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Promotion\Contracts; | ||
|
||
use Konekt\Extend\Contracts\Registerable; | ||
use Vanilo\Adjustments\Contracts\Adjuster; | ||
use Vanilo\Contracts\Schematized; | ||
|
||
interface PromotionActionType extends Schematized, Registerable | ||
{ | ||
public static function getName(): string; | ||
|
||
public function getAdjuster(array $configuration): Adjuster; | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Promotion\Contracts; | ||
|
||
use Vanilo\Contracts\Configurable; | ||
|
||
interface PromotionRule extends Configurable | ||
{ | ||
public function getRuleType(): PromotionRuleType; | ||
|
||
public function isPassing(object $subject): bool; | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Promotion\Contracts; | ||
|
||
use Konekt\Extend\Contracts\Registerable; | ||
use Vanilo\Contracts\Schematized; | ||
|
||
interface PromotionRuleType extends Schematized, Registerable | ||
{ | ||
public static function getName(): string; | ||
|
||
public function isPassing(object $subject, array $configuration): bool; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Promotion/Exceptions/InexistentPromotionActionException.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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Promotion\Exceptions; | ||
|
||
use RuntimeException; | ||
|
||
class InexistentPromotionActionException extends RuntimeException | ||
{ | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Promotion/Exceptions/InexistentPromotionRuleException.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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanilo\Promotion\Exceptions; | ||
|
||
use RuntimeException; | ||
|
||
class InexistentPromotionRuleException extends RuntimeException | ||
{ | ||
} |
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,21 @@ | ||
# The MIT License (MIT) | ||
|
||
Copyright (c) 2024 Vanilo UG | ||
|
||
> Permission is hereby granted, free of charge, to any person obtaining a copy | ||
> of this software and associated documentation files (the "Software"), to deal | ||
> in the Software without restriction, including without limitation the rights | ||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
> copies of the Software, and to permit persons to whom the Software is | ||
> furnished to do so, subject to the following conditions: | ||
> | ||
> The above copyright notice and this permission notice shall be included in | ||
> all copies or substantial portions of the Software. | ||
> | ||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
> THE SOFTWARE. |
Oops, something went wrong.