<?php
// Prints all active shop products as JSON for CMS select fields
$path = '../../../../';
require_once $path . 'core/includes/header.inc.php';

$result = [0 => '-- Select product --'];

$products = \Mtc\Shop\Item::query()
    ->active()
    ->orderBy('name', 'ASC')
    ->get(['id', 'name']);

foreach ($products as $product) {
    $result[$product->id] = $product->name;
}

die(json_encode($result));
