0

I have a channel for my products (items) and I want some of the entries there to not specify a price (meaning, leave the price field blank). When I loop through my items entries, it doesn't display those items where the price field is left blank:

{exp:channel:entries
    channel="items"
}
    {exp:store:product
        entry_id="{entry_id}"
    }
        {if '{price}' == ''}
            nothing
        {if:else}
            {price}
        {/if}

        <h1>{price}: {length}x{width}x{height}</h1>
    {/exp:store:product}

{/exp:channel:entries}

The reason I want to leave the price field blank is because I want to set the price of some items in the template. A lot of the items for sale won't have a set selling price. Rather, there will be a set profit margin added on top of the item's cost based on the item's category (and these profit margins per category will change from time to time).

So, the questions:

  1. How do I display items that have a NULL price? If this is not possible, I guess I can just set it to any number less than 0 and consider that the case when I should set the selling price on the fly.
  2. How do I set the price of an item on the fly?
2

Yes, Store does support dynamic prices. However, you have to enable it when you create the field in the field group. You will see an option called "Enable Dynamic Prices", you will need to set this to Yes. Please note this is a security risk and could allow malicious users to specify any price they want to products.

After this setting you don't have to add a price to products when saving entries.

Now, when you add the product tag you can use this form field:

<input type="text" name="price" value="9.99">

The price of the product in the cart will be 9.99.

Brad

| improve this answer | |
  • I had to edit your comment as the code snippet wasn't showing. – ExpressionEngineNewbie Sep 4 '14 at 22:56
  • This doesn't seem to be a viable option at all. It's too simple to modify the DOM to change the price. Is there a way to specify the price as a parameter of some tag? – ExpressionEngineNewbie Sep 4 '14 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.