0

I'm working on a small CartThrob site at the moment. The site uses 'points' rather than real currency.

Products are stored in the "products" channel which contains a custom field for the points value of each product. There is also an options field to handle sizes/colours etc.

I have elected to use the points field by default but if a product has options then the points field is left at 0 and the price for each option entered in the options field - I find this easier for the client to understand than have them entering price differences for options.

Now, I need to order the products by price from lowest to highest. This is simple enough where there are no options but is it possible to include those products with option pricing in this ordering?

I'm using the obvious entries tag;

{exp:channel:entries channel="products" dynamic="no" orderby="price" sort="asc"}
... product stuff ...
{/exp:channel:entries}

It would be lovely if I could do something like;

{exp:channel:entries channel="products" dynamic="no" orderby="price|options:price" sort="asc"}
... product stuff ...
{/exp:channel:entries}

I'm hoping I can weave the option products into this somehow without having to resort to setting a "base price" on each one and have the client enter price diffrences for each option.

Is there a way to do this?

  • For products that have options, why can't the price field be equal to the first option price with the client made aware that this is for ordering? – Tyssen Aug 13 '13 at 11:14
  • It could, but then that means that option prices would need to be entered as modifiers rather than the absolute price. CT will natively add the option price to the base price. I've found some clients have difficulty getting their head around this and it doesn't make for the most user friendly experience for the customer. – foamcow Aug 13 '13 at 11:23
  • Right, gotchya. Been a while since I've used CT and wasn't aware that default behaviour was to add modifier to base price. Without adding an extra field just for ordering (or maybe an add-on like Low Reorder) the only other thing I can think of is to enter base price in the price field and then maybe create an accessory or extension that uses js to detect the value of the base price and insert a base+modifier value into each option cell (purely for presentation purposes). – Tyssen Aug 13 '13 at 11:34
  • Yeah I think I'm going to have to bite the bullet and use it like it's meant to be used :) Maybe I can do some maths on the template to show the real prices rather than "(+250)". – foamcow Aug 13 '13 at 12:43
1

Here are some suggestions:

  1. Bite the bullet and use the pricing how CT intended. Have a base price field and use modifiers.

  2. Keep the base price at 0, and use modifiers to show the total prices, like you want. But add a 'sorting price' or 'minimum' price purely for the purposes of ordering by price in your templates.

If you decide to go with option 1, you can show the total prices rather than +20 by using the arithmetic tag.

{exp:channel:entries channel="products" orderby="base_price"}
  <h1>{title}</h1>
  <h2>Options</h2>
  {product_options}
    <h3>{option_name}</h3>
    <p><b>Price:</b> {exp:cartthrob:arithmetic operator="+" num1="{base_price}" num2="{price}"}</p>
  {/product_options}
{/exp:channel:entries}
| improve this answer | |
1

If you only have a small amount of products, and you're not relying on the channel:entries pagination, you might be able to do it with stash. This is intended as psuedo-code and just a starting point (I forget the exact tags for getting item option prices in CT, for instance).

{exp:stash:set_list name="my_products" parse_tags="yes" parse_conditionals="yes"}
    {exp:channel:entries channel="products"}
        {stash:item_title}{title}{/stash:item_title}
        {stash:item_summary}{summary}{/stash:item_summary}
        {stash:item_price}{if price:numeric}{price}{if:else}{your_item_options_field}{price:numeric}{/your_item_options_field}{/if}{/stash:item_price}
    {/exp:channel:entries}
{/exp:stash:set_list}

You will probably need to fiddle around with parse order stuff to get that price stash working properly. Maybe add more parse_depth to the stash tag.

Then you'd do a list with stash:get_list

{exp:stash:get_list name="my_products" orderby="item_price"}
    <li>{item_title} - {item_price}</li>
{/exp:stash:get_list}

Check the stash wiki for more on set_list and get_list https://github.com/croxton/Stash/wiki

| improve this answer | |
  • Awesome, thanks Rob. I will give that a go. I do only have a few products and there is unlikely to be any pagination so this could be a goer. – foamcow Aug 14 '13 at 8:28

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.