Vanilo 6.1 has been released with the new Snapshot module, issued payment requests, product attachments, duplicate order protection, and MySQL 9.7 support.
Supported Versions
- PHP 8.4 & 8.5 are supported
- Laravel 12 is supported from v12.69 and upwards
- Laravel 13 is supported from v13.30 and upwards
- MySQL 9.7 has been added to the list of actively tested database engines, next to MySQL 8.4
Snapshot Module
Vanilo 6.1 introduces the Snapshot module, which captures the state of an object at a given moment, stores it in the database, and restores it later. Snapshots are versioned, and can optionally have an expiry date.
The module consists of the following main elements:
Snapshottable: the interface for objects that can be converted to, and restored from a snapshot payload;SnapshotPayload: the interface for the captured content, along with its version, date and validity;Snapshot: the interface (and the Eloquent model) of the stored snapshot;SnapshotPayloadTypes: the registry that maps the type ids to payload classes.
Using the Module
The Snapshot module is part of the framework package.
If you use the standalone modules instead of the framework, install it with composer require vanilo/snapshot.
Add it to your config/concord.php file and run the migrations:
// config/concord.php
return [
'modules' => [
//...
Vanilo\Snapshot\Providers\ModuleServiceProvider::class,
]
];
Defining a Payload
use Vanilo\Snapshot\Concerns\CalculatesSnapshotValidity;
use Vanilo\Snapshot\Concerns\HasSnapshotMetadata;
use Vanilo\Snapshot\Contracts\SnapshotPayload;
use Vanilo\Snapshot\SnapshotMetadata;
class QuotePayload implements SnapshotPayload
{
use CalculatesSnapshotValidity;
use HasSnapshotMetadata;
public function __construct(
public readonly string $customer,
public readonly float $total,
protected readonly SnapshotMetadata $meta,
) {
}
public static function fromArray(array $data, SnapshotMetadata $meta): static
{
return new static($data['customer'], $data['total'], $meta);
}
public function toArray(): array
{
return ['customer' => $this->customer, 'total' => $this->total];
}
}
Register the payload type in a service provider:
use Vanilo\Snapshot\SnapshotPayloadTypes;
SnapshotPayloadTypes::register('quote', QuotePayload::class);
Taking and Restoring Snapshots
The source object has to implement the Snapshottable interface:
use Illuminate\Database\Eloquent\Model;
use Vanilo\Snapshot\Contracts\SnapshotPayload;
use Vanilo\Snapshot\Contracts\Snapshottable;
use Vanilo\Snapshot\SnapshotMetadata;
class Quote extends Model implements Snapshottable
{
protected $fillable = ['customer', 'total'];
public function toSnapshotPayload(): SnapshotPayload
{
return new QuotePayload(
$this->customer,
(float) $this->total,
new SnapshotMetadata(
version: 1,
takenAt: now()->toImmutable(),
validUntil: now()->addDays(14)->toImmutable(), // `null` means it never expires
),
);
}
public static function fromSnapshotPayload(SnapshotPayload $payload): static
{
return new static(['customer' => $payload->customer, 'total' => $payload->total]);
}
}
The take() method returns an unsaved snapshot, so you decide when to persist it:
use Vanilo\Snapshot\Models\Snapshot;
$snapshot = Snapshot::take($quote);
$snapshot->save();
$snapshot->isValid(); // true
$snapshot->isValid(now()->addMonth()); // false
$restored = Quote::fromSnapshotPayload($snapshot->payload());
If the source is an Eloquent model, the snapshot also gets associated with it via the snapshottable polymorphic relation.
Issued Payment Requests
Until now, payment requests were only created on the fly, and Vanilo kept no record of them. The new
IssuedPaymentRequest model/table makes it possible to keep track of the requests that were issued for a payment.
A payment can have multiple issued requests, available via the issuedRequests relation. Each of them can optionally
refer to a snapshot:
use Vanilo\Snapshot\Contracts\Snapshottable;
use Vanilo\Snapshot\Models\Snapshot;
$gateway = $payment->getMethod()->getGateway();
$paymentRequest = $gateway->createPaymentRequest($payment);
$snapshot = null;
if ($paymentRequest instanceof Snapshottable) {
$snapshot = Snapshot::take($paymentRequest);
$snapshot->save();
}
$payment->issuedRequests()->create(['snapshot_id' => $snapshot?->id]);
Restoring Payment Requests
Payment gateways can implement the new, opt-in RestoresPaymentRequestFromSnapshot interface:
namespace Vanilo\Payment\Contracts;
use Vanilo\Snapshot\Contracts\Snapshot;
interface RestoresPaymentRequestFromSnapshot
{
public function restorePaymentRequestFromSnapshot(Snapshot $snapshot): PaymentRequest;
}
This way, when a customer returns to an unfinished payment, the application can reuse the still valid payment request instead of creating a new one at the payment provider:
use Vanilo\Payment\Contracts\RestoresPaymentRequestFromSnapshot;
use Vanilo\Snapshot\Models\Snapshot;
$issuedRequest = $payment->issuedRequests()->latest('id')->first();
$snapshot = $issuedRequest?->hasSnapshot() ? Snapshot::find($issuedRequest->getSnapshotId()) : null;
if ($gateway instanceof RestoresPaymentRequestFromSnapshot && $snapshot?->isValid()) {
$paymentRequest = $gateway->restorePaymentRequestFromSnapshot($snapshot);
}
Existing gateways continue to work without any change. The first gateway to implement the interface is Mollie for Vanilo, beginning with v4.1.
Product Attachments
Files like user manuals, data sheets or warranty documents can now be attached to products, master products, and master product variants.
Attachments are stored in the separate attachments collection of the Spatie Media Library, therefore they don't mix
with the product images, and no image conversions are generated for them.
// The name is optional
$product->addAttachment($request->file('manual'), 'User Guide');
$product->hasAttachments(); // true
$product->attachmentCount(); // 1
$product->getAttachments(); // the collection of attachments
$product->getAttachment($id); // a single attachment by its id or uuid
Displaying them on the storefront:
@if($product->hasAttachments())
<ul>
@foreach($product->getAttachments() as $attachment)
<li><a href="{{ $attachment->getUrl() }}">{{ $attachment->name }}</a></li>
@endforeach
</ul>
@endif
If your product class overrides the
registerMediaCollections()method, call$this->registerAttachmentsMediaCollection()in it. If it overridesregisterMediaConversions(), return early when$this->isAttachment($media)is true.
Duplicate Order Protection
Under rare circumstances, like a double-click on the submit button or parallel requests, a race condition could result in two orders being created from the same cart.
To prevent this, the orders table now has an optional cart_id field with a unique constraint, so the database
rejects the second order. The Order::findByCartId() method retrieves the order that has already been created from the cart:
use Illuminate\Database\UniqueConstraintViolationException;
use Vanilo\Foundation\Models\Order;
use Vanilo\Order\Contracts\OrderFactory;
try {
$order = app(OrderFactory::class)->createFromDataArray(['cart_id' => $cart->id], $items);
} catch (UniqueConstraintViolationException $e) {
$order = Order::findByCartId($cart->id) ?? throw $e;
}
The field isn't populated automatically, the protection takes effect when your application sets the cart_id of the order.
Since carts get deleted once the order has been placed, the field is intentionally not a foreign key.
Thousand Separator
The format_price() helper function now supports a configurable thousand separator:
// config/vanilo.php
return [
'foundation' => [
'currency' => [
'code' => 'EUR',
'sign' => '€',
'format' => '%1$.2f %2$s',
'decimal_separator' => ',',
'thousand_separator' => '.',
],
// ...
],
];
format_price(1234567.89); // 1.234.567,89 €
It isn't used by default, and only single-byte characters are accepted as separators.
Admin Improvements
The attachments of products, master products and master product variants can be managed in the Admin as well. The new Attachments card on the edit pages lets you upload multiple files at once, open, and delete them. The product and master product pages also list the attached files along with their sizes.
Uploading and deleting attachments requires the existing create media and delete media permissions, respectively.
The most common document, spreadsheet, presentation, image, archive and CAD file types are accepted by default.
To allow further ones, extend the list in a service provider's boot() method:
use Vanilo\Admin\Http\Requests\CreateAttachment;
CreateAttachment::$allowedExtensions[] = 'epub';
Additionally:
- The "Products" menu item is now properly activated on the master product pages;
- The minimum Spatie Media Library version is now v11.23.
Bug Fixes
Fixed a rare cart bug, where merging the carts on login picked the current session cart instead of the previous one.
It affected applications that have both the preserve_for_user and merge_duplicates cart settings enabled.
For the full list of changes, see the Vanilo 6.1 Changelog,
Admin 6.1 Changelog.