Forum

Thread tagged as: Problem, Shop

Formatting shop price

Hello,

what am i doing wrong, when formatting numbers in templates?

<perch:shop id="price" type="hidden" format="#:2|,| " />

"price" is 5490 and formats to 1.00

Thanks!

Jiri Zavadil

Jiri Zavadil 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Price needs to be type="shop_currency_value" not type="hidden"

I have that one - for the admin purposes - before, this tag was for the output. However, I wanted to get rid of the currency symbol just on this one page. Can't be done?

<p class="price">
<perch:shop id="price" type="shop_currency_value" label="Price" divider-before="Pricing" size="m" min="0" step="any" order="4" suppress="true" />
<perch:shop id="price" type="hidden" />
</p>
Drew McLellan

Drew McLellan 2638 points
Perch Support

In which template is this, and which page function are you using to display it?

product.php

<?php   
    // Header
    perch_layout('global/header', [
        'body-class' => 'product',
    ]);

    // Menu
    perch_categories(array(
            'set' => 'produkty'
        ));

    // Product detail
    perch_shop_product(perch_get('product'), [
        'template' => 'products/product.html'
    ]);

    // Footer
    perch_layout('global/footer');

product.html -> here's the price tag

<div class="productDetail">
<div class="productImage">

    <!--* Main image *-->
    <img src="<perch:shop id="image" type="image" label="Main image" order="11" divider-before="Images" width="2000" height="2000" crop="false" quality="85" density="1" sharpen="4" />">

    <!--* resized images *-->
    <perch:shop id="image" type="image" crop="false" quality="85" density="2" sharpen="4" suppress="true" width="1000" height="1000" />
    <perch:shop id="image" type="image" crop="false" quality="85" density="2" sharpen="4" suppress="true" width="500" height="500" />
    <perch:shop id="image" type="image" crop="false" quality="85" density="2" sharpen="4" suppress="true" width="250" height="250" />
</div>

<div class="productImages">
    <perch:repeater id="otherimages" label="Other images" order="12">
        <img src="<perch:shop id="otherimages" type="image"  label="Image" width="2000" height="2000" crop="false" quality="85" density="1" sharpen="4" />" />

        <!--* resized images *-->
        <perch:shop id="otherimages" type="image" crop="false" quality="85" density="2" sharpen="4" suppress="true" width="1000" height="1000" />
        <perch:shop id="otherimages" type="image" crop="false" quality="85" density="2" sharpen="4" suppress="true" width="500" height="500" />
        <perch:shop id="otherimages" type="image" crop="false" quality="85" density="2" sharpen="4" suppress="true" width="250" height="250" />
    </perch:repeater>
</div>


<div class="productInfo">
    <h2>#<perch:shop id="sku" type="text" label="SKU" required="true" order="1" /></h2>


    <!--* <h2>#<perch:shop id="title" type="text" label="Title" required="true" order="2" /></h2> *-->

    <p class="price"><perch:shop id="price" type="shop_currency_value" label="Price" divider-before="Pricing" size="m" min="0" step="any" order="4" suppress="true" /><perch:shop id="price" type="hidden" /></p>

    <perch:shop id="slug" type="slug" editable="true" indelible="false" label="Slug" for="sku title" order="2" suppress="true" />

    <perch:shop id="status" type="shop_status" label="Status" suppress="true" order="6" />

    <perch:categories id="category" set="produkty" label="Category" suppress="true" order="7">
        <perch:category id="catTitle" />
    </perch:categories>

    <perch:form id="add_to_cart" class="cartForm" app="perch_shop" action="/cart">

      <perch:if exists="has_variants">
        <perch:productopts>
          <!--*<legend><perch:productopt id="title" /></legend>*-->
          <perch:productvalues>
            <perch:before><ul class="productVariants clearfix"></perch:before>
              <li>
                <label>
                    <perch:input id="options" name="opt-<perch:productvalue id="optionID" />[]" value="<perch:productvalue id="valueID" />" type="radio" required="required" />
                    <div class="variant"><perch:productvalue id="valueTitle" /></div>
                </label>
              </li>
            <perch:after></ul></perch:after>
          </perch:productvalues>
        </perch:productopts>

      <perch:else />
      <!--* produkt bez variant *-->
      <div class="productHasNoVariants">
        <span>one-size</span>
      </div>
      </perch:if>
      <perch:input id="product" type="hidden" env-autofill="false" value="<perch:shop id="productID" type="hidden" env-autofill="false" />" />
      <perch:input type="submit" class="cart-submit" value="Koupit" />
    </perch:form>   


    <p class="productDesc"><perch:shop id="description" type="textarea" label="Description" order="3" markdown="false" size="s" /></p>



    <!--* hidden fields *-->
    <perch:shop id="stock_level" type="number" label="Stock level" size="s" divider-before="Stock" suppress="true" order="8" />
    <perch:shop id="stock_location" type="shop_stock_location" label="Count stock" order="9" suppress="true" />
    <perch:shop id="stock_status" type="shop_stock_status" label="Stock status" required="true" suppress="true" order="10" />
    <perch:shop id="tax_group" type="shop_tax_group" label="Tax group" required="true" suppress="true" order="5" />


    <!--* required fields *-->

    <!--*<perch:shop id="on_sale" type="checkbox" value="0" label="Use sale price" />*-->


    <!--* <perch:shop id="title" type="text" label="Title" required="true"/>
    <perch:shop id="brand" type="shop_brand" label="Brand" allowempty="true" />
    <perch:shop id="catalog_only" type="shop_catalog_only" label="Catalog only" />
    <perch:shop id="sale_price" type="shop_currency_value" label="Sale price" size="m" min="0" step="any" />
    <perch:shop id="trade_price" type="shop_currency_value" label="Trade price" size="m" min="0" step="any" runway="true" />
    <perch:shop id="max_in_cart" type="number" label="Max quantity in cart" size="s" />
    <perch:shop id="requires_shipping" type="shop_requires_shipping" label="Requires shipping" divider-before="Shipping" />
    <perch:shop id="weight" type="number" label="Shipping weight" size="s" />
    <perch:shop id="width" type="number" label="Width" size="s" />
    <perch:shop id="height" type="number" label="Height" size="s" />
    <perch:shop id="depth" type="number" label="Depth" size="s" /> *-->




</div>



<!--* <perch:showall /> *-->

thanks!

Drew McLellan

Drew McLellan 2638 points
Perch Support

You should be able to add output="raw" to the tag to get it unformatted, which will then let you format it.

Hello Drew, no change :(

<perch:shop id="price" type="hidden" output="raw" format="`#:2|,| " />

outputs

1.00
Drew McLellan

Drew McLellan 2638 points
Perch Support

You still have type="hidden". You need to use type="shop_currency_value" for the price.

sweet! this is it:

<perch:shop id="price" type="shop_currency_value" output="raw" format="#:0|,| "/>

Thank you! :)