MIGX - get individual data into snippet

I have a MIGX TV which fills table rows that generate a pricing table with currently 50+ prices. I would need to get each individual price from that table and insert it into a snippet, so I can generate a PDF with them. Is it possible to retrieve the individual values from that?

More details

I’m basically building a contract pdf generator, so I have a form in which people can choose up to three licenses. Each license contains several services, with each individual pricepoints and all of them are listed within the one TV at the moment.

Therefore I need to get the individual price values for each license (depending on the selection) to be able to print the prices of each service within that license! out in a PDF.

If there’s a better solution or other method, please let me know as well! These two criteria should be met:

  1. client has to easily add/change/delete the price values
  2. each price value has to be retrieved by a snippet (on a different resource than the pricing table is on) to be put into a pdf generator

Appreciate any help or thoughts!

I’m not exactly sure I understand what you’re asking, but in case I do:

I’d tell your MIGX snippet to output as something like JSON or an array, that way you can parse the data however you like and retrieve the cell’s data that you’re specifically looking for, which you can then pass to your snippet call.

Hoi,

Why not use pdfResource, to make you’re pdf.
In pdfResource will make a pdf of the resource you save … the chunk you use for pdfResource, could contain a getimagelist snippet to call the migx tv. Almost the same chunk you use to show the table in the front end of the site.

Maybe this could be a solution for you.

Greetings,
Appeltje

@wallacio I think this might be what I need. Could you elaborate more on how I can fetch my MIGX TV as JSON or an array?

@appeltje Thanks fo the idea! I think this might not be possible though, because I need additional data from a form and also I need to display each selected value on a specific X and Y position on the generated PDF as it’s using a contract template.

Oké wish you luck with finding a solution and hope someone else can help. I use pdfResource to gather data which is filled in several tv’s and migx tv’s and save them to the server so the user can download it.

1 Like

Actually, now I think about it - MIGX stores as JSON in the TV anyway so you don’t even have to use getImageList.

I’m making the wild assumption that you have a very basic MIGX structure but you should get enough of an idea to tweak this for your own needs. This is mostly debug output so that you can see what’s going on but the logic should be correct:

$debug = true; // just for messing around
$valuetofind = null; // variable to hold the value (price) you're looking for

$jsonPrices = $modx->resource->getTVValue('pricingTable'); // the name of the template variable containing the MIGX data
$arrPrices = $modx->fromJSON($jsonPrices);

$debugoutput = ""; // just for debug purposes
$debugoutput .= "<pre>";
foreach($arrPrices as $arrPrice) {
    // $arrPrice is a MIGX row
  foreach($arrPrice as $key => $value) {
      // each column in the row

      // dump some debug so you can see the structure
      $debugoutput .= '<strong>' . $key . '</strong> : ' . $value;
      $debugoutput .= '<br>';

      // debug aside, this is where you'd probably want to extract the value you're looking for:
      // if $key == something, $valuetofind = something else.
      // if you're done here, break out of each loop? See Note A below!
  }
  $debugoutput .= '<hr>';
}
$debugoutput .= "</pre>";

if ($debug) {
    return $output;
} else {
    return $valuetofind; // You probably won't want this here, if you're doing stuff in the foreach above. 
}

Note A: If you’re planning to generate a single PDF from every value in the table, you would probably do that here. I don’t know how efficient that’s going to be though!

1 Like

@wallacio Thank you so much for your help and sorry for my extremely late reply! That’s great help and will definitely get me going in the right direction. Thank you so much!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.