Skip to content

Commit

Permalink
Merge branch '0.8' into feature/hub_translation_NL
Browse files Browse the repository at this point in the history
  • Loading branch information
glennjacobs authored Dec 18, 2023
2 parents 8ab5e34 + 55b4529 commit 7f03b91
Show file tree
Hide file tree
Showing 82 changed files with 2,060 additions and 424 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default defineConfig({
]
},
{
text: '0.5',
text: '0.7',
items: [
{text: 'Changelog', link: '/core/upgrading'},
{text: 'Contributing', link: '/core/contributing'},
Expand Down
2 changes: 1 addition & 1 deletion docs/core/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Lunar uses a monorepo [lunarphp/lunar](https://github.com/lunarphp/lunar) approa

## Repository Branching

**Bug Fixes** should target the latest compatible branch version i.e `0.3`. The `main` branch should never have bug fix PR's unless they fix features that are in an upcoming release.
**Bug Fixes** should target the latest compatible branch version i.e `0.7`. The `main` branch should never have bug fix PR's unless they fix features that are in an upcoming release.

**Features** that bring new (or enhance current) functionality to Lunar should always target the `main` branch.

Expand Down
2 changes: 1 addition & 1 deletion docs/core/extending/discounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MyCustomDiscountType extends AbstractDiscountType
/**
* Called just before cart totals are calculated.
*
* @return CartLine
* @return Cart
*/
public function apply(Cart $cart): Cart
{
Expand Down
12 changes: 12 additions & 0 deletions docs/core/extending/shipping.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ class CustomShippingModifier extends ShippingModifier
)
);

ShippingManifest::addOption(
new ShippingOption(
name: 'Pick up in store',
description: 'Pick your order up in store',
identifier: 'PICKUP',
price: new Price(0, $cart->currency, 1),
taxClass: $taxClass,
// This is for your reference, so you can check if a collection option has been selected.
collect: true
)
);

// Or add multiple options, it's your responsibility to ensure the identifiers are unique
ShippingManifest::addOptions(collect([
new ShippingOption(
Expand Down
52 changes: 51 additions & 1 deletion docs/core/reference/carts.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ CartSession::setCustomer($customer);
```


### Adding shipping/billing address
## Adding shipping/billing address

As outlined above, you can add shipping / billing addresses to the cart using
the following methods:
Expand Down Expand Up @@ -376,6 +376,56 @@ $cart->shippingAddress;
$cart->billingAddress;
```

### ShippingOption override

In some cases you might want to present an estimated shipping cost without users having to fill out a full shipping address, this is where the `ShippingOptionOverride` comes in, if set on the cart it can be used to calculate shipping for a single request.

```php
$shippingOption = $cart->getEstimatedShipping([
'postcode' => '123456',
'state' => 'Essex',
'country' => Country::first(),
]);
````

This will return an estimated (cheapest) shipping option for the cart, based on it's current totals. By default this will not be taken into account when calculating shipping in the cart pipelines, in order to enable that we need to pass an extra parameter.

```php
$shippingOption = $cart->getEstimatedShipping([
'postcode' => '123456',
'state' => 'Essex',
'country' => Country::first(),
], setOverride: true);
````

Now when the pipelines are run, the option which was returned by `getEstimatedShipping` will be used when calculating shipping totals, bypassing any other logic, note this will only happen for that one request.

If you are using the `CartSession` manager, you can easily set the parameters you want to estimate shipping so you don't need to pass them each time:

```php
CartSession::estimateShippingUsing([
'postcode' => '123456',
'state' => 'Essex',
'country' => Country::first(),
]);
```

You can also manually set the shipping method override directly on the cart.

```php
$cart->shippingOptionOverride = new \Lunar\DataTypes\ShippingOption(/* .. */);
```

Calling `CartSession::current()` by itself won't trigger the shipping override, but you can pass the `estimateShipping` parameter to enable it:

```php
// Will not use the shipping override, default behaviour.
CartSession::current();

// Will use the shipping override, based on what is set using `estimateShippingUsing`
CartSession::current(estimateShipping: true);
```

## Handling User Login

When a user logs in, you will likely want to check if they have a cart
Expand Down
67 changes: 15 additions & 52 deletions docs/core/reference/discounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Lunar\Models\Discount
| `id` | | |
| `name` | The given name for the discount | |
| `handle` | The unique handle for the discount | |
| `type` | The type of discount | `Lunar\DiscountTypes\Coupon` |
| `type` | The type of discount | `Lunar\DiscountTypes\BuyXGetY` |
| `data` | JSON | Any data to be used by the type class
| `starts_at` | The datetime the discount starts (required) |
| `ends_at` | The datetime the discount expires, if `NULL` it won't expire |
Expand Down Expand Up @@ -94,78 +94,41 @@ Lunar\Models\DiscountPurchasable
### Adding your own Discount type

```php
namespace App\Discounts;
<?php

use Lunar\Base\DataTransferObjects\CartDiscount;
use Lunar\DataTypes\Price;
use Lunar\Facades\Discounts;
use Lunar\Models\CartLine;
use Lunar\Models\Discount;

class CustomDiscount
{
protected Discount $discount;
namespace App\DiscountTypes;

/**
* Set the data for the discount to user.
*
* @param array $data
* @return self
*/
public function with(Discount $discount): self
{
$this->discount = $discount;

return $this;
}
use Lunar\Models\Cart;
use Lunar\DiscountTypes\AbstractDiscountType;

class MyCustomDiscountType extends AbstractDiscountType
{
/**
* Return the name of the discount.
*
* @return string
*/
public function getName(): string
{
return 'Custom Discount';
return 'Custom Discount Type';
}

/**
* Called just before cart totals are calculated.
*
* @return CartLine
* @return Cart
*/
public function execute(CartLine $cartLine): CartLine
public function apply(Cart $cart): Cart
{
$data = $this->discount->data;

// Return the unaltered cart line back
if (! $conditionIsMet) {
return $cartLine;
}

$cartLine->discount = $this->discount;

$discountTotal = $cartLine->unitPrice->value * $discountQuantity;

$cartLine->discountTotal = new Price(
$discountTotal,
$cartLine->cart->currency,
1
);

$cartLine->subTotalDiscounted = new Price(
$line->subTotal->value - $discountTotal,
$cart->currency,
1
);
// ...
return $cart;
}
}

```

```php
Discounts::addType(
CustomDiscount::class
);
use Lunar\Facades\Discounts;

Discounts::addType(MyCustomDiscountType::class);
```

13 changes: 6 additions & 7 deletions docs/core/reference/orders.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Lunar\Models\Order
| discount_breakdown | A json field for the discount breakdown e.g. `[{"discount_id": 1, "lines": [{"id": 1, "qty": 1}]], "total": 200}]`
| discount_total | Any discount amount excl. tax
| shipping_total | The shipping total excl. tax
| tax_breakdown | A json field for the tax breakdown e.g. `[{"name": "VAT", "total": 123, "percentage": 20}]`
| tax_breakdown | A json field for the tax breakdown e.g. `[{"description": "VAT", "identifier" : "vat", "value": 123, "percentage": 20, "currency_code": "GBP"}]`
| tax_total | The total amount of tax applied
| total | The grand total with tax
| notes | Any additional order notes
Expand All @@ -44,15 +44,14 @@ $order = \Lunar\Models\Order::create([/** .. */]);

// Recommended way
$order = Cart::first()->createOrder(
allowMultiple: false,
draftOrderId: null,
allowMultipleOrders: false,
orderIdToUpdate: null,
);
```

- `allowMultiple` - Generally carts will only have one draft order associated, however if you want to allow carts to
- `allowMultipleOrders` - Generally carts will only have one draft order associated, however if you want to allow carts to
have multiple, you can pass `true` here.
- `draftOrderId` - If you want to be sure you're going to get the existing/correct order back, you can pass an ID of a
draft order here to use, note it does have to relate to this cart already.
- `orderIdToUpdate` - You can optionally pass the ID of an order to update instead of attempting to create a new order, this must be a draft order i.e. a null `placed_at` and related to the cart.

The underlying class for creating an order is `Lunar\Actions\Carts\CreateOrder`, you are free to override this in the
config file `config/cart.php`
Expand Down Expand Up @@ -211,7 +210,7 @@ Lunar\Models\OrderLine
| quantity | The amount of this item purchased
| sub_total | The sub total minus any discounts, excl. tax
| discount_total | Any discount amount excl. tax
| tax_breakdown | A json field for the tax breakdown e.g. `[{"name": "VAT", "total": 123, "percentage": 20}]`
| tax_breakdown | A json field for the tax breakdown e.g. `[{"description": "VAT", "identifier" : "vat", "value": 123, "percentage": 20, "currency_code": "GBP"}]`
| shipping_breakdown| A json field for the shipping breakdown e.g. `[{"name": "Standard Delivery", "identifier": "STD", "price": 123}]`
| tax_total | The total amount of tax applied
| total | The grand total with tax
Expand Down
56 changes: 55 additions & 1 deletion docs/core/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,61 @@ php artisan lunar:hub:install

## Support Policy

Lunar currently provides bug fixes and security updates for only the latest minor release, e.g. `0.6`.
Lunar currently provides bug fixes and security updates for only the latest minor release, e.g. `0.7`.

## 0.7

### High Impact

#### TaxBreakdown casting has been refactored

Database columns which have `tax_breakdown` casting will now actually cast back into the `TaxBreakdown` object. This means you will need to update any storefront views or API transformers to accommodate this.

Before:

```php
@foreach ($order->tax_breakdown as $tax)
{{ $tax->total->formatted }}
@endforeach
```

```php
@foreach ($order->tax_breakdown->amounts as $tax)
{{ $tax->price->formatted }}
@endforeach
```

When migrations are run, a state update routine will trigger to convert all existing `tax_breakdown` column. Please ensure you take a backup of your database beforehand and avoid running in production until you are satisfied the data is correct.

### Medium Impact

#### Discount updates

Limitations and exclusions on discounts have had a revamp, please double-check all discounts you have in Lunar to ensure they are all correct. Generally speaking the integrity should be unaffected, but it's better to be sure.

#### Calculate lines pipeline update

If you are using unit quantities greater than `1`, there was an issue in the calculate lines pipeline which resulted in the unit quantity being applied twice, so if the price was `10` with a unit quantity of `100` it would show the unit price as `0.001` instead of `0.01`. This should be resolved going forward to show correctly.

### Low Impact

#### Click & Collect parameter added to `ShippingOption`

The `Lunar\DataTypes\ShippingOption` class now has an additional `collect` parameter. This can be used to determine whether the shipping option is considered "collect in store". This defaults to `false` so there are no additional steps if your store doesn't offer click and collect.

```php
ShippingManifest::addOption(
new ShippingOption(
name: 'Pick up in store',
description: 'Pick your order up in store',
identifier: 'PICKUP',
price: new Price(/** .. */),
taxClass: $taxClass,
collect: true
)
);
```


## 0.6

Expand Down
7 changes: 4 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"devDependencies": {
"vitepress": "^1.0.0-beta.7"
"vitepress": "^1.0.0-rc.31"
},
"scripts": {
"docs:dev": "vitepress dev",
"docs:build": "vitepress build",
"docs:preview": "vitepress preview"
}
}
},
"type": "module"
}
3 changes: 3 additions & 0 deletions packages/admin/config/customers.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Searchable meta fields.
Expand All @@ -13,5 +14,7 @@
|
*/
'searchable_meta' => [],

'impersonate' => null,

];
2 changes: 2 additions & 0 deletions packages/admin/config/database.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Disable migrations
Expand All @@ -11,4 +12,5 @@
|
*/
'disable_migrations' => false,

];
5 changes: 5 additions & 0 deletions packages/admin/config/products.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Disable product variants
Expand Down Expand Up @@ -38,16 +39,20 @@
'required' => true,
'unique' => true,
],

'gtin' => [
'required' => false,
'unique' => false,
],

'mpn' => [
'required' => false,
'unique' => false,
],

'ean' => [
'required' => false,
'unique' => false,
],

];
Loading

0 comments on commit 7f03b91

Please sign in to comment.