We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7455
    • 2,204 Posts
    I was struggeling with treasurechest that there was no option to use ditto to create a list of items.

    I made a snippet that helps populate the ditto template:

    <?php
    $result = $modx->db->select("*", $modx->getFullTableName('treasure_chest'), "id = '".$productid."'" ); 	
    		$tcinfo = $modx->db->getRow($result);
    		
    		 if($label=="amount") return $tcinfo['amount'];
    		 if($label=="image") return $tcinfo['image'];
    		 if($label=="item") return  $tcinfo['item_name'];
    ?>
    


    as you can see its a simple script
    you can expand the if($label== part with all the rest of the items that are in the db I only needed these 3

    create a tv called productid to set the product id or use the another script I made ( http://modxcms.com/forums/index.php/topic,20173.msg217011.html#msg217011 )

    then create a ditto template like this:
    <div class="shop_item">
    
    <div class="links">
    <span class="titel">[+pagetitle+]</span>
    <span class="prijs">$ [[tcgetvalue? &label=`amount` &productid=`[+productid+]`]]</span>
    <span class="toevoegen"><a href="#" onclick="return false;" class="treasureChest" title="[+pagetitle+]" name="[+productid+]" rel="id"><span>add to cart</span></a></span>
    </div>
    
    <div class="rechts">
    <span class="plaatje"><a href="[~[+id+]~]" title="[+pagetitle+]"><img src="/assets/snippets/treasure_chest/images/phpthumb/phpThumb.php?src=../../../../../[[tcgetvalue? &label=`image` &productid=`[+productid+]`]]&w=125&f=png" alt="[+pagetitle+]"></a></span>
    </div>
    
    </div>
    


    the call ditto using that template.
    make sure all the pages that you call have shop items that have images else phpthumb will trow an error.
    you can use filters in ditto to ignore pages that have no id set or is not the right template etc.

    se here the results (and get yourself a gage):
    http://www.cisterngauges.com/shop.html

    Greets Dimmy
      follow me on twitter: @dimmy01
      • 22199
      • 4 Posts
      Hy,
      I’m actually working on TC on modx version 9.6.3.

      I just modified a bit your code to mix 2 tips you already made before.

      - a small tv for easy creating a shop item page(dropdown list)
      - a Ditto call to create a list of items

      I personnally didn’t like to insert for each document a tv called productid.
      (but i kept nearly all your code to make the upagrade easy)

      So in this way, i just need to associate my new document with the dropdown TV
      Ditto + tcgetvalue will do the rest.

      Here is a ditto call in the Ditto template(an image for example)
      <img src="[[tcgetvalue? &label=`image` &idDoc=`[+id+]` &productid=`[+productid+]`]]" alt="[+pagetitle+]" />

      I have just added idDoc

      Here is the snippet modified
      <?php
      //search for TV's id by "name" and "ItemId"(name of your TV)
      $result = $modx->db->select("id", "modx_site_tmplvars", "name = 'itemId'","", "1");   
      $id_item = $modx->db->getValue($result);  
      
      //search TV value by this $id_tem
      $result = $modx->db->select("value,tmplvarid", "modx_site_tmplvar_contentvalues", "tmplvarid = '".$id_item."' AND contentid = '".$idDoc."' ","", "1");  
      $value_item = $modx->db->getValue($result);  
      
      //keep the original code to simlify upgrades
      $productid=$value_item;
      $result = $modx->db->select("*", $modx->getFullTableName('treasure_chest'), "id = '".$productid."'" ); 	
      		$tcinfo = $modx->db->getRow($result);
      
      		 if($label=="amount") return $tcinfo['amount'];
      		 if($label=="image") return $tcinfo['image'];
      		 if($label=="item") return  $tcinfo['item_name'];
                       if($label=="id") return  $tcinfo['id'];
      ?>
      


      Again, this is just a kind of mix with your 2 codes on TC.
      I’m sure there is a way to simplify the code and make it more simple

      I hope this can be handy for somebody.
      Thanks again for your help.










        • 7455
        • 2,204 Posts
        Nice work only the &productid=`[+productid+]`]]" parameter is not used any more so can be left out in the ditto call

        and instead of entering the tvname you could use the id directly (its in () behind the name in the manager), that makes one less db query.

        Dimmy
          follow me on twitter: @dimmy01
          • 12924
          • 2 Posts
          Hi guys, i have been trying to follow you with this, but its just going no-where! The Ditto call is successfully calling the right link to the item,, but thats it!

          The image is grayed box with the ’not a file’ red text and the ’add to cart’ doesnt do anything. Also, the price is not being called in.

          Please help with this!

          Thanks

          Alex
            • 7455
            • 2,204 Posts
            did you call treasurechest in the head of the page also? like this:

            [!TreasureChest? &service=`global`!]

            that makes the add to card work
              follow me on twitter: @dimmy01
              • 12924
              • 2 Posts
              I did manage to figure that bit yeah! (took a while though!) So the Add to cart works fine, but the other parameters dont. The price wont show and nor will the image... bit of a pain in the arse TC!

              The concept is good, but it just doesnt seem to do basic tasks very easily. I ahve admitidly moved onto FoxyCart!
                • 22574
                • 181 Posts
                Hey Guys,

                I have taken some of the info here and decided to see if I could pull all of my products directly out of the DB without having to have a page for each. huh

                What I have so far is a basic snippet that pulls out the info from the DB then calls the treasureChest snippet then calls a chunk. grin

                The problem is that what ever product that is called last seams to over-rights the older products, so they all end up begin the same.

                Is there a way to clear the treasureChest call?

                Cheers
                  • 22574
                  • 181 Posts
                  Ahh worked it out! I needed to use the parseChunk insteed of the getChunk.