3 replies [Last post]
harrisben's picture
Offline
Joined: 04/17/2009
Juice: 192
Was this information Helpful?

Howdy all,

I would like to use views to display my product catalog and have installed the uc_views module, but I was wondering if anyone has had any success exposing attributes/options to views? I really need to display the available attribute options of products at the node summary level (not as a form, just listed) and would like to avoid having to code the entire catalog myself just because of this one tiny thing.

Please let me know if you have any ideas.

manatwo's picture
Offline
Joined: 02/19/2008
Juice: 235
Re: Using Views for product catalog

Really have no idea if this will work, but you could try the Views Customfield-PHP module and print them with PHP as you would in a theme.

harrisben's picture
Offline
Joined: 04/17/2009
Juice: 192
manatwo wrote: Really have
manatwo wrote:

Really have no idea if this will work, but you could try the Views Customfield-PHP module and print them with PHP as you would in a theme.

I've been experiencing a series of mental break-throughs recently and can report that it is indeed possible to use the views customfield-php module to display attributes and options. Fortunately in my case there is just a single attribute so it's quite easy to layout.

I have two customfields, the UOM (option name) and price (option price).

For the UOM I used the following code, which works perfectly:

<?php
$attributes
= uc_product_get_attributes($data->nid);
foreach (
$attributes as $attribute) { ?>

  <table><tbody>
  <?php foreach ($attribute->options as $option) { ?>
    <tr><td>
    <?php print $option->name; ?>
    </td></tr>
  <?php } ?>
  </tbody></table>
<?php }
?>

For the price I use the following:

<?php
$attributes
= uc_product_get_attributes($data->nid);
foreach (
$attributes as $attribute) { ?>

  <table><tbody>
  <?php foreach ($attribute->options as $option) { ?>
    <tr><td>
    <?php print uc_price($option->price, $context); ?>
    </td></tr>
  <?php } ?>
  </tbody></table>
<?php }
?>

Unfortunately using uc_price() here seems to return an error and I'm not sure why (I've tested without formatting the price and it works). Any ideas on how I can get it working correctly?

If anyone knows why using

LoveGolf's picture
Offline
Joined: 10/16/2008
Juice: 106
Re: Using Views for product catalog

Right. Attributes and options are not currently exposed to views for use out of the box.

I'm sure you could hire someone who knows what they are doing for a custom solution though.