PHP code example of goldnead / statamic-products

1. Go to this page and download the library: Download goldnead/statamic-products library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

goldnead / statamic-products example snippets


use Goldnead\StatamicPayments\Support\Checkout;

// Sell one. The handle is all `statamic-payments` needs; the amount comes from
// the server and never from the request.
$checkout = app(Checkout::class)->start('stimmwerkstatt');

abort_if($checkout === null, 404);          // no such product, or it is inactive

return redirect()->away($checkout->checkoutUrl);

// Ask what something costs, without starting anything.
$product = app(\Goldnead\StatamicPayments\Support\Catalogue::class)->find('stimmwerkstatt');

// Or reach the row itself.
use Goldnead\StatamicProducts\Models\Product;

$product = Product::firstWhere('handle', 'stimmwerkstatt');
$product->grantSlugs();          // ['stimmwerkstatt-zugang']
$product->hasBeenSold();         // whether the handle is frozen
$product->isShadowedByConfig();  // whether a config line overrules this row

use Goldnead\StatamicOffers\Models\Offer;

Offer::create([
    'handle' => 'fruehling',
    'name' => 'Frühlingsaktion',
    'product' => 'stimmwerkstatt',
    'amount_cent' => 9900,
]);

use Goldnead\StatamicProducts\Support\ContentKinds;

ContentKinds::register('community', 'Community-Bereich', 'Space (Kennung)');

use Goldnead\StatamicProducts\Support\SessionTypes;

SessionTypes::register('8f0c…', 'Einzelsession');
SessionTypes::register('2b7d…', 'Gruppensession');

use Goldnead\StatamicProducts\Support\AccessContainers;

AccessContainers::allow(['assets', 'downloads']);

use Goldnead\StatamicProducts\Support\AccessContainers;
use Goldnead\StatamicProducts\Support\ContentKinds;
use Goldnead\StatamicProducts\Support\SessionTypes;

ContentKinds::register('community', 'Community-Bereich', 'Space (Kennung)');
SessionTypes::register('8f0c…', 'Einzelsession');
AccessContainers::allow(['assets', 'downloads']);

use Goldnead\StatamicProducts\Support\ContentKinds;
use Goldnead\StatamicProducts\Support\RefTarget;
use Statamic\Facades\Entry;

ContentKinds::register(
    'library',
    'Bibliothek',
    'Bibliothek',
    // [value => label], read when the form opens (not at boot).
    options: fn () => Entry::query()->where('collection', 'libraries')->get()
        ->mapWithKeys(fn ($e) => [$e->id() => $e->get('title')])->all(),
    // A string = found, that is its name. null = gone. RefTarget::unknowable() = cannot say.
    resolver: fn (string $ref) => Entry::find($ref)?->get('title'),
);

use Goldnead\StatamicProducts\Support\Accesses;

$access = Accesses::find('choiraccelerator');   // null when there is no record

$access->expand();                // every slug a grant covers, transitive, without its own
$access->creditLines();           // this access's credit lines for new grants
$access->creditLines(

Accesses::buyerLinksFor($user);           // with statamic-entitlements: active grants only
Accesses::buyerLinks(['webinar-oktober']); // without: pass the slugs the viewer holds, nothing else

// [['access' => 'webinar-oktober', 'ref' => '<event uuid>', 'label' => null, 'url' => 'https://…']]