by
KK » Wed Apr 23, 2014 1:03 am
Hi,
As promised, here is a working example (I'll be using the sample site that comes with our Cart tutorial -
http://www.couchcms.com/docs/concepts/s ... art-1.html).
Add the following editable region to the products template (i.e. index.php) -
- Code: Select all
<cms:editable name='out_of_stock' label='Out of stock' type='checkbox' opt_values='Yes=1' />
This checkbox can be ticked if a product goes out of stock.
Next, we use the value within the checkbox to either display the 'Add to cart' button or show a 'Out of stock' message while displaying each product.
The original portion of the 'index.php' template that displays the products is this (excerpted for clarity) -
- Code: Select all
<div class="product-details">
<cms:pp_product_form class="cart-form">
..
..
<div class="purchase-box">
<label class="quantity-label">Qty:</label>
<input class="product-quantity" type="number" name="qty" min="1" step="1" value="1" title="Quantity">
<input class="button product-add" type="submit" value="Add to Cart">
</div>
..
..
</cms:pp_product_form>
</div>
We amend the code above to incorporate the checkbox's value like this -
- Code: Select all
<div class="product-details">
<cms:pp_product_form class="cart-form">
..
..
<div class="purchase-box">
<cms:if out_of_stock>
<label class="quantity-label">Out of stock</label>
<cms:else />
<label class="quantity-label">Qty:</label>
<input class="product-quantity" type="number" name="qty" min="1" step="1" value="1" title="Quantity">
<input class="button product-add" type="submit" value="Add to Cart">
</cms:if>
</div>
..
..
</cms:pp_product_form>
</div>
Hope this helps.