We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10076
    • 1,024 Posts
    Had it working but this morning images disapeared, how strange. where do I donate the beers?

    Quote from: Bruno17 at Oct 15, 2014, 05:00 AM
    ok, here is tested code, which did work for me:

    $set = $modx->getOption('set', $scriptProperties, '');
    $input = $modx->fromJson($modx->resource->getTVValue('product'));
    $output = array();
     
    foreach ($input as $row) {
        if (isset($set) && !empty($set) && ($set != $row['set']))
            continue;
        $productname = $modx->getOption('productname', $row, '');
        $product_orders = '';
        for ($i = 1; $i <= 5;$i++) {
            $weight = $hook->getValue($productname.'_'.$i);
            $week = strftime('%W',strtotime('+'.$i.' week'));
            $product_orders .= $week . ' - ' . $weight . 'kg 
    ';
        }
     
        $output[] = $productname . ': 
    ' . $product_orders;
    }
    $products_output = implode("
    ", $output);
    $hook->setValue('products_output', $products_output);
    
    return true;
    
      • 4172
      • 5,888 Posts
      Are the images still there, in the backend?
      what do you get with
      [[*product]]

      at frontend.
      Is the image there, in the json-output?

      where do I donate the beers?
      The link in my sig should work.

        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 10076
        • 1,024 Posts
        Working outside, must be the image TV. Anyway would it be possible for you to leave some comments in the script so I understand and learn? Would be great and thanks loads.
          • 4172
          • 5,888 Posts
          <?php
           
          $set = $modx->getOption('set', $scriptProperties, '');//get the formit-scriptProperty &set for filtering specific sets
          $input = $modx->fromJson($modx->resource->getTVValue('product'));//get the product-TV of the current resource and convert the json to an array
          $output = array();
            
          foreach ($input as $row) {
              if (isset($set) && !empty($set) && ($set != $row['set']))
                  continue;//filter specific set, if specified
              $productname = $modx->getOption('productname', $row, '');//get the productname of the MIGX-item
              $product_orders = '';
              //loop thrue the weeks (1-5) now
              for ($i = 1; $i <= 5;$i++) {
                  $weight = $hook->getValue($productname.'_'.$i);//get the weight from input, for example: 'peccorino_1' to 'peccorino_5'
                  $week = strftime('%W',strtotime('+'.$i.' week'));//get the week-number
                  $product_orders .= $week . ' - ' . $weight . 'kg <br />';//prepare the output for a week, could also be done with getChunk
              }
            
              $output[] = $productname . ': <br />' . $product_orders;//fill the output-array with the product-output, could be done with getChunk
          }
          $products_output = implode("<br />", $output);//convert the output-array to a string
          $hook->setValue('products_output', $products_output);//put the output into a formit-value, so it can be used by other hooks and as placeholder
           
          return true;//return true, otherwise formit would stop processing here with an error-result
          


          may be it would be better not to use the productname but the MIGX_id as the name for your input-fields [ed. note: Bruno17 last edited this post 12 years ago.]
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 10076
            • 1,024 Posts
            There must be a backslash somewhere lost in that code, cause here s the output:
            [{"MIGX_id":"1","set":"bestel","productname":"Peccorino","productimage":"assets\/images\/produkten\/forbanner07.png"}]


            Quote from: Bruno17 at Oct 16, 2014, 12:40 AM
            Are the images still there, in the backend?
            what do you get with
            [[*product]]

            at frontend.
            Is the image there, in the json-output?

            where do I donate the beers?
            The link in my sig should work.

              • 10076
              • 1,024 Posts
              There must be a backslash somewhere lost in that code, cause here s the output:
              [{"MIGX_id":"1","set":"bestel","productname":"Peccorino","productimage":"assets\/images\/produkten\/forbanner07.png"}]


              Quote from: Bruno17 at Oct 16, 2014, 12:40 AM
              Are the images still there, in the backend?
              what do you get with
              [[*product]]

              at frontend.
              Is the image there, in the json-output?

              where do I donate the beers?
              The link in my sig should work.

                • 4172
                • 5,888 Posts
                I think, you should change the image-placeholder

                <div class="pur_col1 purlineitem"><img src="[[+image:add_before=`assets/images/`:phpthumbof=`w=100&h=100&zc=1]]" alt="Foto van [[+productname]] " ></div>


                to

                <div class="pur_col1 purlineitem"><img src="[[+productimage:phpthumbof=`w=100&h=100&zc=1]]" alt="Foto van [[+productname]] " ></div>
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!