Skip to content

Instantly share code, notes, and snippets.

@jasonvarga
Created January 24, 2013 03:03
Show Gist options
  • Save jasonvarga/4617311 to your computer and use it in GitHub Desktop.
Save jasonvarga/4617311 to your computer and use it in GitHub Desktop.
Product Page Model
{!-- Wrapper template --}
{stash:embed:layouts:product}
{!-- Custom field prefix --}
{preload_replace:cf="cf_product_"}
{exp:channel:entries
channel="products"
url_title="{segment_2}"
limit="1"
dynamic="no"
disable="pagination|member_data"}
{!-- If segment_2 isn't a valid URL title, it's a 404. --}
{if no_results}
{redirect="404"}
{/if}
{!--
Set variables to be used inside wrapper
--}
{!-- Single vars --}
{exp:stash:set}
{stash:entry_id}{entry_id}{/stash:entry_id}
{stash:title}{title}{/stash:title}
{stash:price}{{cf}price}{/stash:price}
{stash:description}{{cf}description}{/stash:description}
{stash:image}{{cf}images:url}{/stash:image}
{if '{{cf}images:total_files}' > 1} {stash:has_additional_images}true{/stash:has_additional_images} {/if}
{/exp:stash:set}
{!-- Var pairs --}
{exp:stash:set_list name="images"}
{{cf}images}
{stash:url}{url}{/stash:url}
{/{cf}images}
{/exp:stash:set_list}
{exp:stash:set_list name="product_options"}
{{cf}options}
{option_name}
{stash:name}{option_name}{/stash:name}
{stash:price}
{exp:cartthrob:arithmetic
expression="{{cf}price:numeric}+{exp:cartthrob:view_formatted_number number='{price}' prefix=''}"
parse="inward"}
{/stash:price}
{stash:inventory}{if inventory == 0}Out of stock{if:else}{inventory} left{/if}{/stash:inventory}
{/{cf}options}
{/exp:stash:set_list}
{/exp:channel:entries}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment