modified product form to split attribute.

This commit is contained in:
Julien Chanséaume
2014-07-24 17:14:26 +02:00
committed by Julien Chanseaume
parent b4d0d085fe
commit 4e1e082a7c
5 changed files with 305 additions and 56 deletions

View File

@@ -30,6 +30,11 @@
{* Content *}
{block name="main-content"}
{$product_id={product attr="id"}}
{$pse_count={count type="product_sale_elements" product="$product_id"}}
{$check_availability={config key="check-available-stock" default="1"}}
<div class="main">
{loop name="product.details" type="product" id="{product attr="id"}" limit="1" with_prev_next_info="1"}
<article id="product" class="col-main" role="main" itemscope itemtype="http://schema.org/Product">
@@ -73,7 +78,6 @@
{ifloop rel="image.carouselsup"}
<div class="item">
<ul>
{loop name="image.carouselsup" type="image" product="{$ID}" width="560" height="445" resize_mode="borders" offset="5"}
<li>
<a href="{$IMAGE_URL}" class="thumbnail">
@@ -97,8 +101,8 @@
<section id="product-details">
<div class="product-info">
<h1 class="name"><span itemprop="name">{$TITLE}</span></h1>
{if $REF}<span itemprop="sku" class="sku">{intl l='Ref.'}: {$REF}</span>{/if}
<h1 class="name"><span itemprop="name">{$TITLE}</span><span id="pse-name" class="pse-name"></span></h1>
{if $REF}<span itemprop="sku" class="sku">{intl l='Ref.'}: <span id="pse-ref">{$REF}</span></span>{/if}
{loop name="brand_info" type="brand" product="{$ID}"}
<p><a href="{$URL}" title="{intl l="More information about this brand"}"><span itemprop="brand">{$TITLE}</span></a></p>
@@ -109,26 +113,12 @@
</div>{/if}
</div>
{* Default value *}
{assign var="current_stock_class" value = "in-stock"}
{assign var="current_stock_href" value = "http://schema.org/InStock"}
{loop name="stock_meta" type="product_sale_elements" product="$ID"}
{loop name="combi_meta" type="attribute_combination" product_sale_elements="$ID"}
{if $LOOP_COUNT == 0}
{if $QUANTITY == 0}
{assign var="current_stock_class" value = "out-of-stock"}
{assign var="current_stock_href" value = "http://schema.org/OutOfStock"}
{/if}
{/if}
{/loop}
{/loop}
<div class="product-price" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<div class="availability">
<span class="availibity-label">{intl l="Availability"}: </span>
<span itemprop="availability" href="{$current_stock_href}" class="{$current_stock_class}" id="stock-information">
<span class="in">{intl l='In Stock'}</span><span class="out">{intl l='Out of Stock'}</span>
<span itemprop="availability" href="{$current_stock_href}" class="" id="pse-availability">
<span class="in">{intl l='In Stock'}</span>
<span class="out">{intl l='Out of Stock'}</span>
</span>
</div>
@@ -136,17 +126,15 @@
{loop type="category" name="category_tag" id=$DEFAULT_CATEGORY}
<meta itemprop="category" content="{$TITLE}">
{/loop}
<meta itemprop="itemCondition" itemscope itemtype="http://schema.org/NewCondition"> <!-- List of condition : NewCondition, DamagedCondition, UsedCondition, RefurbishedCondition -->
<meta itemprop="priceCurrency" content="{currency attr="symbol"}"> <!-- List of currency : The currency used to describe the product price, in three-letter ISO format. -->
{if $IS_PROMO }
{loop name="productSaleElements_promo" type="product_sale_elements" product="{$ID}" limit="1" order="min_price"}
{assign var="default_product_sale_elements" value="$ID"}
<span class="special-price"><span itemprop="price" class="price-label">{intl l="Special Price:"} </span><span class="price">{format_number number="{$TAXED_PROMO_PRICE}"} {currency attr="symbol"}</span></span>
<span class="old-price"><span class="price-label">{intl l="Regular Price:"} </span><span class="price">{format_number number="{$TAXED_PRICE}"} {currency attr="symbol"}</span></span>
{/loop}
{else}
<span class="regular-price"><span itemprop="price" class="price">{format_number number="{$BEST_TAXED_PRICE}"} {currency attr="symbol"}</span></span>
{/if}
{* List of condition : NewCondition, DamagedCondition, UsedCondition, RefurbishedCondition *}
<meta itemprop="itemCondition" itemscope itemtype="http://schema.org/NewCondition">
{* List of currency : The currency used to describe the product price, in three-letter ISO format. *}
<meta itemprop="priceCurrency" content="{currency attr="symbol"}">
<span id="pse-promo">
<span id="pse-price" class="special-price"><span itemprop="price" class="price-label">{intl l="Special Price:"} </span><span class="price">{format_number number="{$TAXED_PROMO_PRICE}"} {currency attr="symbol"}</span></span>
<span id="pse-price-old" class="old-price"><span class="price-label">{intl l="Regular Price:"} </span><span class="price">{format_number number="{$TAXED_PRICE}"} {currency attr="symbol"}</span></span>
</span>
</div>
</div>
@@ -165,32 +153,25 @@
<input id="{$label_attr.for}" type="hidden" name="{$name}" value="{$ID}" {$attr} >
{/form_field}
<fieldset class="product-options">
{ifloop rel="stock"}
{* pse *}
{form_field form=$form field='product_sale_elements_id'}
<input id="pse-id" type="hidden" name="{$name}" value="{$PRODUCT_SALE_ELEMENT}" {$attr} >
{/form_field}
{if $pse_count > 1}
{* We have more than 1 combination: custom form *}
<fieldset id="pse-options" class="product-options">
{loop name="attributes" type="attribute" product="$product_id" order="manual"}
<div class="option">
<label for="options" class="option-heading">Options</label>
<label for="option-{$ID}" class="option-heading">{$TITLE}</label>
<div class="option-content">
{form_field form=$form field='product_sale_elements_id'}
<select name="{$name}" class="form-control">
{loop name="stock" type="product_sale_elements" product="$ID" order="min_price"}
{if $IS_PROMO }
<option value="{$ID}" data-quantity="{$QUANTITY}" data-price="{format_number number="{$TAXED_PROMO_PRICE}"} {currency attr="symbol"}" data-old-price="{format_number number="{$TAXED_PRICE}"} {currency attr="symbol"}">{$ATTRIBUTE_AVAILABILITY_TITLE}
{else}
<option value="{$ID}" data-quantity="{$QUANTITY}" data-price="{format_number number="{$TAXED_PRICE}"} {currency attr="symbol"}" data-old-price="{format_number number="{$TAXED_PRICE}"} {currency attr="symbol"}">{$ATTRIBUTE_AVAILABILITY_TITLE}
{/if}
{$REF}
({loop name="combi" type="attribute_combination" product_sale_elements="$ID" order="alpha"}
{if $LOOP_COUNT > 1}-{/if}
{$ATTRIBUTE_AVAILABILITY_TITLE}
{/loop})
</option>
{/loop}
</select>
{/form_field}
<select id="option-{$ID}" name="option-{$ID}" class="form-control pse-option" data-attribute="{$ID}"></select>
</div>
</div>
{/ifloop}
{/loop}
</fieldset>
{/if}
<fieldset class="product-cart form-inline">
{form_field form=$form field='quantity'}
<div class="form-group group-qty {if $error}has-error{elseif $value != "" && !$error}has-success{/if}">
@@ -208,6 +189,7 @@
<button type="submit" class="btn btn_add_to_cart">{intl l="Add to cart"}</button>
</div>
</fieldset>
</form>
{/form}
</section>
@@ -303,3 +285,34 @@
</div><!-- /.main -->
{/block}
{block name="javascript-initialization"}
{if $pse_count > 1}
{$pse=[]}
{$combination_label=[]}
{$combination_values=[]}
{loop name="pse" type="product_sale_elements" product="{product attr="id"}"}
{$pse[$ID]=["id" => $ID, "default" => $IS_DEFAULT, "promo" => $IS_PROMO, "new" => $IS_NEW, "ref" => "{$REF}", "ean" => "{$EAN}", "quantity" => {$QUANTITY}, "price" => "{format_number number="{$TAXED_PRICE}"} {currency attr="symbol"}", "promo" => "{format_number number="{$TAXED_PROMO_PRICE}"} {currency attr="symbol"}" ]}
{$pse_combination=[]}
{loop name="combi" type="attribute_combination" product_sale_elements="$ID"}
{if ! $combination_label[$ATTRIBUTE_ID]}
{$combination_label[$ATTRIBUTE_ID]=["name" => "{$ATTRIBUTE_TITLE}", "values" => []]}
{/if}
{if ! $combination_values[$ATTRIBUTE_AVAILABILITY_ID]}
{$combination_label[$ATTRIBUTE_ID]["values"][]=$ATTRIBUTE_AVAILABILITY_ID}
{$combination_values[$ATTRIBUTE_AVAILABILITY_ID]=["{$ATTRIBUTE_AVAILABILITY_TITLE}", $ATTRIBUTE_ID]}
{/if}
{$pse_combination[]=$ATTRIBUTE_AVAILABILITY_ID}
{/loop}
{$pse[$ID]["combinations"]=$pse_combination}
{/loop}
<script type="text/javascript">
// Product sale elements
var PSE_FORM = true;
var PSE_CHECK_AVAILABILITY = {if $check_availability}true{else}false{/if};
var PSE = {$pse|json_encode nofilter};
var PSE_COMBINATIONS = {$combination_label|json_encode nofilter};
var PSE_COMBINATIONS_VALUE = {$combination_values|json_encode nofilter};
</script>
{/if}
{/block}