Skip to content

Commit

Permalink
Merge branch '1.x' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson authored Aug 16, 2024
2 parents 38536e7 + 5d32f39 commit 4ebe4f1
Show file tree
Hide file tree
Showing 42 changed files with 513 additions and 72 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/check-pr-maintainer-access.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copied from https://raw.githubusercontent.com/filamentphp/filament/3.x/.github/workflows/check-pr-maintainer-access.yml
name: check-pr-maintainer-access

on:
pull_request_target:
types:
- opened

permissions:
pull-requests: write

jobs:
notify-when-maintainers-cannot-edit:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v3
with:
script: |
const query = `
query($number: Int!) {
repository(owner: "lunarphp", name: "lunar") {
pullRequest(number: $number) {
headRepositoryOwner {
login
}
maintainerCanModify
}
}
}
`
const pullNumber = context.issue.number
const variables = { number: pullNumber }
try {
console.log(`Check #${pullNumber} for maintainer edit access...`)
const result = await github.graphql(query, variables)
console.log(JSON.stringify(result, null, 2))
const pullRequest = result.repository.pullRequest
if (pullRequest.headRepositoryOwner.login === 'lunarphp') {
console.log('PR owned by lunarphp')
return
}
if (! pullRequest.maintainerCanModify) {
console.log('PR not owned by lunarphp and does not have maintainer edits enabled')
await github.issues.createComment({
issue_number: pullNumber,
owner: 'lunarphp',
repo: 'lunar',
body: 'Thanks for submitting a PR!\n\nIn order to review and merge PRs most efficiently, we require that all PRs grant maintainer edit access before we review them. If your fork belongs to a GitHub organization, please move the repository to your personal account and try again. If you\'re already using a personal fork, you can learn how to enable maintainer access [in the GitHub documentation](https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork).'
})
await github.issues.update({
issue_number: pullNumber,
owner: 'lunarphp',
repo: context.repo.repo,
state: 'closed'
})
}
} catch(error) {
console.log(error)
}
49 changes: 49 additions & 0 deletions docs/core/extending/discounts.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Discounts

## Overview
Expand Down Expand Up @@ -45,3 +46,51 @@ class MyCustomDiscountType extends AbstractDiscountType
}
}
```


## Adding form fields for your discount in the admin panel

If you require fields in the Lunar admin for your discount type, ensure your discount implements `Lunar\Admin\Base\LunarPanelDiscountInterface`. You will need to provide the `lunarPanelSchema`, `lunarPanelOnFill` and `lunarPanelOnSave` methods.

```php
<?php

namespace App\DiscountTypes;

use Lunar\Admin\Base\LunarPanelDiscountInterface;
use Lunar\DiscountTypes\AbstractDiscountType;
use Filament\Forms;

class MyCustomDiscountType extends AbstractDiscountType implements LunarPanelDiscountInterface
{
/**
* Return the schema to use in the Lunar admin panel
*/
public function lunarPanelSchema(): array
{
return [
Forms\Components\TextInput::make('data.my_field')
->label('My label')
->required(),
];
}

/**
* Mutate the model data before displaying it in the admin form.
*/
public function lunarPanelOnFill(array $data): array
{
// optionally do something with $data
return $data;
}

/**
* Mutate the form data before saving it to the discount model.
*/
public function lunarPanelOnSave(array $data): array
{
// optionally do something with $data
return $data;
}
}
```
5 changes: 3 additions & 2 deletions docs/core/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ You may need to update your app's `composer.json` to set `"minimum-stability": "

### Add the LunarUser Trait

Some parts of the core rely on the `User` model having certain relationships set up. We've bundled these into a trait which you must add to any models that represent users in your database.
Some parts of the core rely on the User model having certain relationships set up. We have bundled these into a trait and an interface, which you must add to any models that represent users in your database.

```php
use Lunar\Base\Traits\LunarUser;
use Lunar\Base\LunarUser as LunarUserInterface;
// ...

class User extends Authenticatable
class User extends Authenticatable implements LunarUserInterface
{
use LunarUser;
// ...
Expand Down
14 changes: 14 additions & 0 deletions docs/core/reference/carts.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ $cartLine = new \Lunar\Models\CartLine([
$cart->lines()->create([/* .. */]);
```

### Validation

When adding items to a cart there are a series of validation actions which are run, which are defined in the `config/lunar/cart.php` config file.

These actions will throw a `Lunar\Exceptions\Carts\CartException`.

```php
try {
$cart->add($purchasable, 500);
} catch (\Lunar\Exceptions\Carts\CartException $e) {
$error = $e->getMessage();
}
```

Now you have a basic Cart up and running, it's time to show you how you would
use the cart to get all the calculated totals and tax.

Expand Down
2 changes: 1 addition & 1 deletion docs/core/reference/products.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ You can associate attributes to a product type like so (it's just a straight
forward [Polymorphic relationship](https://laravel.com/docs/8.x/eloquent-relationships#many-to-many-polymorphic-relations)).

```php
$productType->mappedAttributes()->associate([ /* attribute ids ... */ ]);
$productType->mappedAttributes()->attach([ /* attribute ids ... */ ]);
```

You can associate both `Product` and `ProductVariant` attributes to a product type which will then display on either the
Expand Down
20 changes: 10 additions & 10 deletions docs/core/reference/taxation.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ These specify a geographic zone for tax rates to be applied. Tax Zones can be ba
Lunar\Models\TaxZone
```

|Field|Description|
|:-|:-|
|id||
|name|e.g. `UK`|
|zone_type|`country`, `state`, or `postcode`|
|price_display|`tax_inclusive` or `tax_exclusive`|
|active|true/false|
|default|true/false|
|created_at||
|updated_at||
|Field| Description |
|:-|:------------------------------------|
|id| |
|name| e.g. `UK` |
|zone_type| `country`, `states`, or `postcodes` |
|price_display| `tax_inclusive` or `tax_exclusive` |
|active| true/false |
|default| true/false |
|created_at| |
|updated_at| |

```php
$taxZone = TaxZone::create([
Expand Down
3 changes: 1 addition & 2 deletions docs/core/starter-kits.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ If you would prefer to install Lunar into your own Laravel application, please f
## Installation

::: tip
We assume you have a suitable local development environment in which to run Lunar. We would highly suggest Laravel Herd
for this purpose.
We assume you have a suitable local development environment in which to run Lunar. We would highly suggest [Laravel Herd](https://herd.laravel.com) for this purpose.
:::

### Create a New Project
Expand Down
15 changes: 15 additions & 0 deletions packages/admin/resources/lang/en/fieldtypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,20 @@
],
'file' => [
'label' => 'File',
'form' => [
'file_types' => [
'label' => 'Allowed File Types',
'placeholder' => 'New MIME',
],
'multiple' => [
'label' => 'Allow Multiple Files',
],
'min_files' => [
'label' => 'Min. Files',
],
'max_files' => [
'label' => 'Max. Files',
],
],
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
@endif
<x-filament-tables::cell>
<div class="fi-ta-text grid w-full gap-y-1 px-3 py-4">
<span class="fi-ta-text-item-label text-sm leading-6 text-gray-950 dark:text-white ">
<span class="fi-ta-text-item-label flex flex-col text-sm leading-6 text-gray-950 dark:text-white">
@foreach($permutation['values'] as $option => $value)
<small><strong>{{ $option }}:</strong> {{ $value }}</small>
@endforeach
Expand Down
21 changes: 21 additions & 0 deletions packages/admin/src/Base/LunarPanelDiscountInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Base;

interface LunarPanelDiscountInterface
{
/**
* Return the schema to use in the Lunar admin panel
*/
public function lunarPanelSchema(): array;

/**
* Mutate the model data before displaying it in the admin form.
*/
public function lunarPanelOnFill(array $data): array;

/**
* Mutate the form data before saving it to the discount model.
*/
public function lunarPanelOnSave(array $data): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function form(Form $form): Form
->helperText(
__('lunarpanel::attribute.form.description.helper')
)
->afterStateHydrated(fn ($state, $component) => $state ?: $component->state([Language::getDefault()->code => null]))
->maxLength(255),
Forms\Components\TextInput::make('handle')
->label(
Expand Down Expand Up @@ -133,6 +134,7 @@ public function table(Table $table): Table
])
->headerActions([
Tables\Actions\CreateAction::make()->mutateFormDataUsing(function (array $data, RelationManager $livewire) {
$data['configuration'] = $data['configuration'] ?? [];
$data['system'] = false;
$data['attribute_type'] = $livewire->ownerRecord->attributable_type;
$data['position'] = $livewire->ownerRecord->attributes()->count() + 1;
Expand Down
7 changes: 3 additions & 4 deletions packages/admin/src/Filament/Resources/CollectionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Filament\Forms;
use Filament\Forms\Components\Component;
use Filament\Pages\Page;
use Filament\Pages\SubNavigationPosition;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Builder;
Expand Down Expand Up @@ -89,16 +88,16 @@ protected static function getDefaultRelations(): array
return [];
}

public static function getRecordSubNavigation(Page $page): array
public static function getDefaultSubNavigation(): array
{
return $page->generateNavigationItems([
return [
Pages\EditCollection::class,
Pages\ManageCollectionChildren::class,
Pages\ManageCollectionProducts::class,
Pages\ManageCollectionAvailability::class,
Pages\ManageCollectionMedia::class,
Pages\ManageCollectionUrls::class,
]);
];
}

public static function getDefaultPages(): array
Expand Down
8 changes: 7 additions & 1 deletion packages/admin/src/Filament/Resources/CustomerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,13 @@ protected static function getCustomerGroupsFormComponent(): Component
{
return Forms\Components\CheckboxList::make('customerGroups')
->label(__('lunarpanel::customer.form.customer_groups.label'))
->relationship(name: 'customerGroups', titleAttribute: 'name');
->relationship(
name: 'customerGroups',
titleAttribute: 'name',
modifyQueryUsing: fn (Builder $query) => $query->distinct(
['id', 'name', 'handle', 'default']
)
);
}

protected static function getDefaultTable(Table $table): Table
Expand Down
14 changes: 14 additions & 0 deletions packages/admin/src/Filament/Resources/DiscountResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\Str;
use Lunar\Admin\Base\LunarPanelDiscountInterface;
use Lunar\Admin\Filament\Resources\DiscountResource\Pages;
use Lunar\Admin\Filament\Resources\DiscountResource\RelationManagers\BrandLimitationRelationManager;
use Lunar\Admin\Filament\Resources\DiscountResource\RelationManagers\CollectionLimitationRelationManager;
Expand Down Expand Up @@ -57,6 +58,18 @@ public static function getNavigationGroup(): ?string

public static function getDefaultForm(Form $form): Form
{
$discountSchemas = Discounts::getTypes()->map(function ($discount) {
if (! $discount instanceof LunarPanelDiscountInterface) {
return;
}

return Forms\Components\Section::make(Str::slug(get_class($discount)))
->heading($discount->getName())
->visible(
fn (Forms\Get $get) => $get('type') == get_class($discount)
)->schema($discount->lunarPanelSchema());
})->filter();

return $form->schema([
Forms\Components\Section::make('')->schema(
static::getMainFormComponents()
Expand Down Expand Up @@ -84,6 +97,7 @@ public static function getDefaultForm(Form $form): Form
)->schema(
static::getAmountOffFormComponents()
),
...$discountSchemas,
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Lunar\Admin\Filament\Resources\DiscountResource\Pages;

use Filament\Actions;
use Lunar\Admin\Base\LunarPanelDiscountInterface;
use Lunar\Admin\Filament\Resources\DiscountResource;
use Lunar\Admin\Support\Pages\BaseEditRecord;
use Lunar\DiscountTypes\BuyXGetY;
Expand All @@ -19,8 +20,29 @@ protected function getDefaultHeaderActions(): array
];
}

protected function mutateFormDataBeforeFill(array $data): array
{
if (class_exists($data['type'])) {
$type = new $data['type'];

if ($type instanceof LunarPanelDiscountInterface) {
return $type->lunarPanelOnFill($data);
}
}

return $data;
}

protected function mutateFormDataBeforeSave(array $data): array
{
if (class_exists($data['type'])) {
$type = new $data['type'];

if ($type instanceof LunarPanelDiscountInterface) {
return $type->lunarPanelOnSave($data);
}
}

$minPrices = $data['data']['min_prices'] ?? [];
$fixedPrices = $data['data']['fixed_values'] ?? [];
$currencies = Currency::enabled()->get();
Expand Down
Loading

0 comments on commit 4ebe4f1

Please sign in to comment.