Skip to content

Instantly share code, notes, and snippets.

@gregmoser
Last active August 29, 2015 13:55
Show Gist options
  • Save gregmoser/8742077 to your computer and use it in GitHub Desktop.
Save gregmoser/8742077 to your computer and use it in GitHub Desktop.
<!--- Define some values that should be passed in as part of the ajax call --->
<cfparam name="url.savedStateID" default="" /> <!--- This hold the savedStateID from the smartList that initiated the quickview --->
<cfparam name="url.currentRecordNumber" default="" /> <!--- This should also be passed up as the index value of the current record that was clicked on so that we know where in the list they came from --->
<!--- Now that we have all of our paramaters, we create a new Product Smart List --->
<cfset savedSmartList = $.slatwall.getSmartList("Product") />
<!--- Apply the savedStateID to the smart list which will setup all of the filters and sorting from the smartList that initiated this ajax page --->
<cfset savedSmartList.loadSavedState( url.savedStateID ) />
<!--- Only if the currentRecordNumber is bigger then 1 do we need a "Previous" button --->
<cfif url.currentRecordNumber gt 1>
<!--- Adjust the smartList to start 1 record before the currentRecord so that we can get a previous links productID --->
<cfset savedSmartList.setPageRecordsStart( url.currentRecordNumber - 1 ) />
<!--- Ask for a total of 3 so that we can get the previous, this & next --->
<cfset savedSmartList.setPageRecordsShow( 3 ) />
<a href="...&savedStateID=#savedSmartList.getSavedStateID()#&currentRecordNumber=#url.currentRecordNumber - 1#">Previous</a>
<!--- If when trying to retun 3 page records there aren't actually 3, then that means we are at the end of the list and don't need to display a "Next" button --->
<cfif arrayLen(savedSmartList.getPageRecords()) eq 3>
<a href="...&savedStateID=#savedSmartList.getSavedStateID()#&currentRecordNumber=#url.currentRecordNumber + 1#" />Next</a>
</cfif>
<!--- Set the product variable from the pageRecords --->
<cfset product = savedSmartList.getPageRecords()[1] />
<!--- In this case we don't need a "Previous" button because they clicked on the first one in the list --->
<cfelse>
<!--- Set the currentPageRecord so that smartList starts on that one --->
<cfset savedSmartList.setPageRecordsStart( url.currentRecordNumber )/>
<!--- Only Ask for a total of 2 page records so that we can get the this & next --->
<cfset savedSmartList.setPageRecordsShow( 2 ) />
<!--- Verify that in fact there is a "Next" record and we aren't at the end of the list --->
<cfif arrayLen(savedSmartList.getPageRecords()) eq 2>
<a href="...&savedStateID=#savedSmartList.getSavedStateID()#&currentRecordNumber=#url.currentRecordNumber + 1#" />Next</a>
</cfif>
<!--- Set the product variable from the pageRecords --->
<cfset product = savedSmartList.getPageRecords()[1] />
</cfif>
<h1>#product.getTitle()#</h1>
<div>#product.getDescription()#</div>
<div>#product.getLivePrice()#</div>
<form>
<input type="hidden" name="slatAction" value="public:cart.addItem" />
<input type="hidden" name="skuID" value="#product.getDefaultSku().getSkuID()#" />
<button>Add To Card</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment