Home
NexoPOS

Prefill Products

The product prefill is a feature added in NexoPOS 5.3.3. This allows creating a list of products that will be populated while creating a procurement. This feature might be used to suggest procurement to the end user.

How Does It Work?

To make it work, you need to use the class "ProcurementService" which now provides new methods: "storePreload" and "preload". The "storePreload" method accepts 4 parameters:

  • hash: it's a unique string generated to identify the products. You might use Str::uuid().
  • items: it's either an array of a collection with the following entries (product_id, unit_id, quantity)
  • multiplier: used to multiply how many times the items are added to the procurement list. The default value is 1.
  • expiration: define after how many times (in seconds) the prefill will expire and be cleared.

<?php
use App\Services\ProcurementService;
use Illuminate\Support\Str;

$uniqueId = Str::uuid();

$service = app()->make( ProcurementService::class );
$service->storePreload(
  hash: $uniqueId,
  items: [
      [ 
        'product_id' => 1,
        'unit_id' =>  1,
        'quantity' => 2
      ]
  ],
  multiplier: 3, // we want the product to be provided 3 times so we'll have 2*3 = 6 of the requested items
  expiration: 3600, // expires in one hour
);

Load The Prefilled Products

You need to redirect to the procurement page with an extra query argument (preload). When the query argument "preload" has as value the $uniqueId we created, the product will be fetched and added to the table.

Here is what the URL must look like.

yourwebsite.com/dashboard/procurement/create?preload=48927940-f2af-4d0e-83e1-d43b493989ef

Note that you can use the helper "ns()->route( 'ns.procurement-create' )" to get the procurement URL.