Skip to content

Commit

Permalink
Merge pull request #183 from vanilophp/feat-promotion
Browse files Browse the repository at this point in the history
Basic Promotion Module
  • Loading branch information
fulopattila122 authored Jul 26, 2024
2 parents 4ddbfd8 + f4a5cfb commit 1f8bae8
Show file tree
Hide file tree
Showing 51 changed files with 1,663 additions and 6 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3']
laravel: ['10.43', '10.48', '11.0', '11.17']
laravel: ['10.43', '10.48', '11.0', '11.14']
name: PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }}
steps:
- name: Checkout
Expand All @@ -27,22 +28,22 @@ jobs:
- name: Create SQLite Database
run: mkdir -p database && touch database/database.sqlite
- name: Run Tests [sqlite]
run: php vendor/bin/phpunit --testdox
run: php vendor/bin/phpunit --stop-on-defect --testdox
env:
TEST_DB_ENGINE: sqlite
- name: Run Tests [postgres]
run: php vendor/bin/phpunit --testdox
run: php vendor/bin/phpunit --stop-on-defect --testdox
env:
TEST_DB_ENGINE: pgsql
TEST_DB_PORT: ${{ job.services.postgres.ports[5432] }}
TEST_DB_PASSWORD: postgres
- name: Run Tests [mysql 5.7]
run: php vendor/bin/phpunit --testdox
run: php vendor/bin/phpunit --stop-on-defect --testdox
env:
TEST_DB_ENGINE: mysql
TEST_DB_PORT: ${{ job.services.mysql.ports[3306] }}
- name: Run Tests [mysql 8.0]
run: php vendor/bin/phpunit --testdox
run: php vendor/bin/phpunit --stop-on-defect --testdox
env:
TEST_DB_ENGINE: mysql
TEST_DB_PORT: ${{ job.services.mysql8.ports[3306] }}
Expand Down
2 changes: 1 addition & 1 deletion build-tools/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ git tag $VERSION
git push origin --tags

# Tag Components
for REMOTE in adjustments cart category channel checkout contracts links master-product order payment product properties shipment support taxes
for REMOTE in adjustments cart category channel checkout contracts links master-product order payment product promotion properties shipment support taxes
do
echo ""
echo ""
Expand Down
2 changes: 2 additions & 0 deletions build-tools/split.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ remote master-product
remote order
remote payment
remote product
remote promotion
remote properties
remote shipment
remote support
Expand All @@ -51,6 +52,7 @@ split 'src/MasterProduct' master-product
split 'src/Order' order
split 'src/Payment' payment
split 'src/Product' product
split 'src/Promotion' promotion
split 'src/Properties' properties
split 'src/Shipment' shipment
split 'src/Support' support 8683e47dd2dbd15ac2ceac4dcfae405c4b271aff
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"laravel/framework": "^10.43|^11.0",
"konekt/enum": "^4.2",
"konekt/concord": "^1.13",
"konekt/xtend": "^1.2",
"spatie/laravel-medialibrary": "^11.0",
"cviebrock/eloquent-sluggable": "^10.0|^11.0",
"konekt/laravel-migration-compatibility": "^1.6",
Expand All @@ -42,6 +43,7 @@
"vanilo/order": "self.version",
"vanilo/payment": "self.version",
"vanilo/product": "self.version",
"vanilo/promotion": "self.version",
"vanilo/properties": "self.version",
"vanilo/shipment": "self.version",
"vanilo/support": "self.version",
Expand Down
1 change: 1 addition & 0 deletions module-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
| Order | [![Tests](https://img.shields.io/github/actions/workflow/status/vanilophp/order/tests.yml?branch=master&style=flat-square)](https://github.com/vanilophp/order/actions?query=workflow%3Atests) | [![Packagist version](https://img.shields.io/packagist/v/vanilo/order.svg?style=flat-square&include_prereleases)](https://packagist.org/packages/vanilo/order) |
| Payment | [![Tests](https://img.shields.io/github/actions/workflow/status/vanilophp/payment/tests.yml?branch=master&style=flat-square)](https://github.com/vanilophp/payment/actions?query=workflow%3Atests) | [![Packagist version](https://img.shields.io/packagist/v/vanilo/payment.svg?style=flat-square&include_prereleases)](https://packagist.org/packages/vanilo/payment) |
| Product | [![Tests](https://img.shields.io/github/actions/workflow/status/vanilophp/product/tests.yml?branch=master&style=flat-square)](https://github.com/vanilophp/product/actions?query=workflow%3Atests) | [![Packagist version](https://img.shields.io/packagist/v/vanilo/product.svg?style=flat-square&include_prereleases)](https://packagist.org/packages/vanilo/product) |
| Promotion | [![Tests](https://img.shields.io/github/actions/workflow/status/vanilophp/promotion/tests.yml?branch=master&style=flat-square)](https://github.com/vanilophp/promotion/actions?query=workflow%3Atests) | [![Packagist version](https://img.shields.io/packagist/v/vanilo/promotion.svg?style=flat-square&include_prereleases)](https://packagist.org/packages/vanilo/promotion) |
| Properties | [![Tests](https://img.shields.io/github/actions/workflow/status/vanilophp/properties/tests.yml?branch=master&style=flat-square)](https://github.com/vanilophp/properties/actions?query=workflow%3Atests) | [![Packagist version](https://img.shields.io/packagist/v/vanilo/properties.svg?style=flat-square&include_prereleases)](https://packagist.org/packages/vanilo/properties) |
| Shipment | [![Tests](https://img.shields.io/github/actions/workflow/status/vanilophp/shipment/tests.yml?branch=master&style=flat-square)](https://github.com/vanilophp/shipment/actions?query=workflow%3Atests) | [![Packagist version](https://img.shields.io/packagist/v/vanilo/shipment.svg?style=flat-square&include_prereleases)](https://packagist.org/packages/vanilo/shipment) |
| Support | [![Tests](https://img.shields.io/github/actions/workflow/status/vanilophp/support/tests.yml?branch=master&style=flat-square)](https://github.com/vanilophp/support/actions?query=workflow%3Atests) | [![Packagist version](https://img.shields.io/packagist/v/vanilo/support.svg?style=flat-square&include_prereleases)](https://packagist.org/packages/vanilo/support) |
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<testsuite name="Properties Tests">
<directory>src/Properties/Tests</directory>
</testsuite>
<testsuite name="Promotion Tests">
<directory>src/Promotion/Tests</directory>
</testsuite>
<testsuite name="Category Tests">
<directory>src/Category/Tests</directory>
</testsuite>
Expand Down
6 changes: 6 additions & 0 deletions src/Promotion/.gitattributes
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
13 changes: 13 additions & 0 deletions src/Promotion/.github/workflows/close-pull-request.yml
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!"
28 changes: 28 additions & 0 deletions src/Promotion/.github/workflows/tests.yml
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
36 changes: 36 additions & 0 deletions src/Promotion/Actions/CartFixedDiscount.php
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];
}
}
28 changes: 28 additions & 0 deletions src/Promotion/Contracts/Coupon.php
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;
}
22 changes: 22 additions & 0 deletions src/Promotion/Contracts/Promotion.php
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;
}
15 changes: 15 additions & 0 deletions src/Promotion/Contracts/PromotionAction.php
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;
}
16 changes: 16 additions & 0 deletions src/Promotion/Contracts/PromotionActionType.php
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;
}
14 changes: 14 additions & 0 deletions src/Promotion/Contracts/PromotionRule.php
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;
}
15 changes: 15 additions & 0 deletions src/Promotion/Contracts/PromotionRuleType.php
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 src/Promotion/Exceptions/InexistentPromotionActionException.php
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 src/Promotion/Exceptions/InexistentPromotionRuleException.php
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
{
}
21 changes: 21 additions & 0 deletions src/Promotion/LICENSE.md
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.
Loading

0 comments on commit 1f8bae8

Please sign in to comment.