Skip to content
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

Basic Promotion Module #183

Merged
merged 37 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
72b5f70
Added Promotion and Coupon models
kedves Jul 9, 2024
3f8c56b
Apply fixes from StyleCI
StyleCIBot Jul 9, 2024
cc18de6
Class fix
kedves Jul 9, 2024
622d4a7
Apply fixes from StyleCI
StyleCIBot Jul 9, 2024
5f5978d
Added the Promotion module to the build scripts + test suites
fulopattila122 Jul 9, 2024
8a0e8ee
Added the missing Concord-orchestration to the Promotion + Coupon mod…
fulopattila122 Jul 9, 2024
27bca59
Removed the `code` field from the Promotion table/model
fulopattila122 Jul 9, 2024
b2f4a8d
Removed the `code` field from the Promotion model #2
fulopattila122 Jul 9, 2024
06db9d0
Renamed promo/coupon fields to match existing patterns
fulopattila122 Jul 9, 2024
94c7da7
Apply fixes from StyleCI
StyleCIBot Jul 9, 2024
676dea3
Using proxies in relations
fulopattila122 Jul 9, 2024
00eb1aa
Added Promo/Coupo interface candidates
fulopattila122 Jul 9, 2024
0c41da4
Implemented Interface methods and added test for Promotion and Coupon
kedves Jul 9, 2024
3bb84ec
Apply fixes from StyleCI
StyleCIBot Jul 9, 2024
9f5edd6
- Added PromotionRule and PromotionRuleTypes with registry
kedves Jul 11, 2024
f402f15
Apply fixes from StyleCI
StyleCIBot Jul 11, 2024
d222bbd
Merge branch 'refs/heads/master' into feat-promotion
kedves Jul 11, 2024
99bb8ac
Added PromotionAction and CartFixedDiscount action type
kedves Jul 12, 2024
c5cc1b8
Apply fixes from StyleCI
StyleCIBot Jul 12, 2024
c73290f
Using Laravel 11.14 for CI
fulopattila122 Jul 15, 2024
be00351
License name fix
fulopattila122 Jul 15, 2024
87c8fe3
Using Xtend's Registry for promotion action types
fulopattila122 Jul 15, 2024
546eadc
Merge branch 'refs/heads/master' into feat-promotion
fulopattila122 Jul 15, 2024
9d2f4a6
Using Xtend's Registry for promotion rule types
fulopattila122 Jul 15, 2024
69e6682
Added `--stop-on-defect` explicitly to CI phpunit command
fulopattila122 Jul 15, 2024
aff7240
Made `PromotionRuleType` `Schematized` instead of `Configurable`
fulopattila122 Jul 15, 2024
90f1d68
Apply fixes from StyleCI
StyleCIBot Jul 15, 2024
1765953
Refactoring Promotion Action Types from Configurable -> Schematized -…
fulopattila122 Jul 15, 2024
68b8383
Merge remote-tracking branch 'origin/feat-promotion' into feat-promotion
fulopattila122 Jul 15, 2024
f50e131
Apply fixes from StyleCI
StyleCIBot Jul 15, 2024
6ae0517
Modified the promotion action adjuster logic
fulopattila122 Jul 16, 2024
bac0fcc
Merge remote-tracking branch 'origin/feat-promotion' into feat-promotion
fulopattila122 Jul 16, 2024
b417512
Apply fixes from StyleCI
StyleCIBot Jul 16, 2024
0ad46ff
Merge branch 'refs/heads/master' into feat-promotion
fulopattila122 Jul 25, 2024
fc3ba33
Temporary switch back to Laravel 11.16 in CI
fulopattila122 Jul 25, 2024
0d20554
Temporary switch back to Laravel 11.15 in CI
fulopattila122 Jul 25, 2024
f4a5cfb
Temporary switch back to Laravel 11.14 in CI
fulopattila122 Jul 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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