<![CDATA[ TreasureChest: Is it possible to have two products on the one page? - My Forums]]> https://forums.modx.com/thread/?thread=48466 <![CDATA[Re: TreasureChest: Is it possible to have two products on the one page?]]> https://forums.modx.com/thread/48466/treasurechest-is-it-possible-to-have-two-products-on-the-one-page#dis-post-281180 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!]]> brpcs Jun 02, 2008, 07:55 PM https://forums.modx.com/thread/48466/treasurechest-is-it-possible-to-have-two-products-on-the-one-page#dis-post-281180 <![CDATA[Re: TreasureChest: Is it possible to have two products on the one page?]]> https://forums.modx.com/thread/48466/treasurechest-is-it-possible-to-have-two-products-on-the-one-page#dis-post-281179
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>
]]>
ram May 30, 2008, 04:25 AM https://forums.modx.com/thread/48466/treasurechest-is-it-possible-to-have-two-products-on-the-one-page#dis-post-281179
<![CDATA[Re: TreasureChest: Is it possible to have two products on the one page?]]> https://forums.modx.com/thread/48466/treasurechest-is-it-possible-to-have-two-products-on-the-one-page#dis-post-281178 davidm May 30, 2008, 02:21 AM https://forums.modx.com/thread/48466/treasurechest-is-it-possible-to-have-two-products-on-the-one-page#dis-post-281178 <![CDATA[TreasureChest: Is it possible to have two products on the one page?]]> https://forums.modx.com/thread/48466/treasurechest-is-it-possible-to-have-two-products-on-the-one-page#dis-post-281177
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!]]>
brpcs May 29, 2008, 11:09 PM https://forums.modx.com/thread/48466/treasurechest-is-it-possible-to-have-two-products-on-the-one-page#dis-post-281177