Skip to content

Instantly share code, notes, and snippets.

@dubrod
Last active January 23, 2019 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubrod/6451d4cc0029ec56242aa27d0f5b368a to your computer and use it in GitHub Desktop.
Save dubrod/6451d4cc0029ec56242aa27d0f5b368a to your computer and use it in GitHub Desktop.
MODX ID to JSON
<?php
header("Content-Type:application/json");
$id = $_GET["id"];
if(empty($id)){ die(); }
$obj = $modx->getObject('modResource', $id);
$output = [];
$output = array(
"name" => $obj->get('longtitle'),
"sku" => $obj->getTVValue('sku'),
"img" => $obj->getTVValue('product_img'),
"barrel_length" => $obj->getTVValue('barrel-length')
);
return $modx->toJson($output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment