On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • For the cart I’m trying to set up, I need two Add to Cart links for different products on the same page.

    Ie. The product in question can either be bought individually or in packs of 10. I want to set it up so that the "individual" product is an item within TreasureChest, and the "10 Pack" is another item (with a different price etc) within TreasureChest, but still have a single product page for both items.

    So far I have:

    [[treasureChest? &item=`2`]]
    Individual: $[+treasure.amount+] [+treasure.add+]

    That works fine, I had the thought of adding:

    [[treasureChest? &item=`3`]]
    10 Pack: $[+treasure.amount+] [+treasure.add+]

    directly below the code for Item 2, however it just resulted in both prices coming out as Item 3’s price.

    Is there any way I can achieve this? I would prefer no dirty hacks, but I have to make this happen, so am willing to look at all my options.

    Thanks very much! And thanks Scotty for such an awesome snippit!
    • More probably than not, you’d need to call the snippet uncached ( [! ..... !] ) for multiple calls to work... just a guess, I have never gotten past a quick test of TreasureChest yet but that’s often true of multiple snippet calls it should work.
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l'outil id
      • Keep the products in a central location and you can also use Ditto/TVs/PHx to aggregate and template results.

        You can easily make the add to cart link yourself, rather than using the one that TreasureChest creates, as long as the TreasureChest JavaScript code is loaded on that page (service=`global`) e.g:
        <p class="productAdd"><a href="#" onclick="return false;" class="addToCart" title="Yoga VII" name="40" rel="id"><span>Add To Cart</span></a></p>
        

        You can maybe also use TVs (e.g. create them to contain an array of relevant item row IDs) and Ditto extenders to automatically pull up Treasure chest item info from the DB and populate placeholders.

        For instance an extender to get price & tax info from the TreasureChest table via Ditto into custom placeholders:

        tcPriceGetter.extender.inc.php
        <?php
        
        if (!function_exists("tcPriceGetter")) {
        	function tcPriceGetter($resource) {
        		global $modx;
        		
        		$productID = $resource["tcProductID"];
        		$table = $modx->getFullTableName('treasure_chest');
        		$query = "SELECT amount + tax FROM $table WHERE id=$productID";
        		$result = $modx->db->query($query);
        		$tcPrice = $modx->db->getValue($result);
        		
        		return ($tcPrice < 1) ? 'No price found' : $tcPrice;
        	}
        }
        
        $placeholders['tcPrice'] = array(array("tcProductID","*"),"tcPriceGetter");
        ?>
        


        And Ditto template:
        <li>
        	<a class="imgPreviewLink" href="[~[+id+]~]" title="[+longtitle+]">
        		<img src="/assets/snippets/treasure_chest/images/phpthumb/phpThumb.php?src=../products/[+alias+].jpg&w=125&f=png" alt="[+pagetitle+]">
        	</a>
        	<h3>
        		<a href="[~[+id+]~]" title="[+longtitle+]">[+pagetitle+]</a>
        	</h3>
        	<p class="productPrice">£[+tcPrice+]</p>
        	<p class="viewItemLink"><a href="[~[+id+]~]" title="[+longtitle+]">View item</a></p>
        	<p class="productAdd"><a href="#" onclick="return false;" class="addToCart" title="[+pagetitle+]" name="[+tcProductID+]" rel="id"><span>Add To Cart</span></a></p>
        </li>
        
        • Quote from: ram at May 30, 2008, 09:25 AM

          You can easily make the add to cart link yourself, rather than using the one that TreasureChest creates, as long as the TreasureChest JavaScript code is loaded on that page (service=`global`) e.g:
          <p class="productAdd"><a href="#" onclick="return false;" class="addToCart" title="Yoga VII" name="40" rel="id"><span>Add To Cart</span></a></p>
          


          <?php
          
          if (!function_exists("tcPriceGetter")) {
          	function tcPriceGetter($resource) {
          		global $modx;
          		
          		$productID = $resource["tcProductID"];
          		$table = $modx->getFullTableName('treasure_chest');
          		$query = "SELECT amount + tax FROM $table WHERE id=$productID";
          		$result = $modx->db->query($query);
          		$tcPrice = $modx->db->getValue($result);
          		
          		return ($tcPrice < 1) ? 'No price found' : $tcPrice;
          	}
          }
          
          $placeholders['tcPrice'] = array(array("tcProductID","*"),"tcPriceGetter");
          ?>
          


          Thankyou for that; I’ve managed to use parts of that to come up with the solution that I needed.

          cheers!