7 replies [Last post]
BigMike's picture
Offline
Joined: 10/20/2008
Juice: 1057
Was this information Helpful?

Hello UC,

We are doing the "On Sale" trick mentioned in http://www.ubercart.org/forum/support/543/items_sale_how to display our products on sale whenever their sell price is less than their list price.

I have a view setup that I'd only like to return items that are on sale in this same manner.

Question: How can I filter this view to only show products whose sell price is less than their list price?

Yes I could use a nodequeue or similar term or whatnot to filter, but this requires an additional step. Ideally, what I'm looking for is the moment I save the product with a sell price lower than it's list price, it will 1) put the product on sale (how it's already configured for, as per the linked thread above), and 2) automatically add the product to this view through some filter (need help with this part!).

Any help would be greatly appreciated!

Thank you very much,
BigMike

To complete this form, please complete the word verification below.

BigMike's picture
Offline
Joined: 10/20/2008
Juice: 1057
Re: How to filter Views when sell price < list price

Anyone?

BigMike's picture
Offline
Joined: 10/20/2008
Juice: 1057
Re: How to filter Views when sell price < list price

Views are just too limited for this, so I made this work by using pure PHP.

Thanks
Mike

spessex's picture
Offline
Joined: 08/15/2011
Juice: 10
How? :-)

Hi Big Mike

Would you be able to tell me how you did this only I have exactly the same requirement and although I know my way around Drupal I have little PHP knowledge. Any help would be greatly appreciated Smiling

Stephen

BigMike's picture
Offline
Joined: 10/20/2008
Juice: 1057
spessex wrote:Hi Big
spessex wrote:

Hi Big Mike

Would you be able to tell me how you did this only I have exactly the same requirement and although I know my way around Drupal I have little PHP knowledge. Any help would be greatly appreciated Smiling

Stephen

Hello Stephen Smiling What I did was I ditched views altogether and simply created a block with the HTML and PHP I needed to get the job done. Here is a quick & dirty snippet that will display the SKU number, the product image, and the product title all three linked to the product itself. It also only outputs products that are published (where status = 1) and also truncates the length of the product title to 23 characters (these were specific needs that I had). I am a PHP n00b but this works for me. Go ahead and play with the sort order/HTML/theming/image path/whatnot and this should get you well on your way Smiling

<b>Products On Sale:</b><br /><br />
<?php
  $query
= "SELECT nid FROM {uc_products} WHERE list_price > sell_price ORDER BY model ASC";
 
$result = db_query($query, $user->uid);
  while (
$new_node = db_result($result)) {
   
$load_this = node_load($new_node, NULL, FALSE);
    if ((
$load_this->status) == 1) {
      print
"
  <div style=\"text-align: center; width: 210px; padding-bottom: 20px;\">
    <a href=\"/"
. $load_this->path . "\"><small>MODEL: " . $load_this->model . "</small><br />
      <img src=\"/sites/all/SITENAME/files/imagecache/product/"
. $load_this->field_image_cache['0']['filepath'] . "\" style=\"width: 200px; height: 150px; border: 3px solid #959595;\"><br />
      <b>"
. truncate_utf8($load_this->title,'23', FALSE, TRUE) . "</b>
    </a>
  </div>"
;
    }
  }
?>

Please let me know if you have any questions!
Regards,
BigMike

spessex's picture
Offline
Joined: 08/15/2011
Juice: 10
Thanks

Hi Big MIke

Thanks for this. Most helpful. I never thought of doing it that way. Smiling

Stephen

BigMike's picture
Offline
Joined: 10/20/2008
Juice: 1057
Re: How to filter Views when sell price < list price

Cool, happy to help!

lee-bergeron (not verified)
lee-bergeron's picture
Filter

Hi! I had that same problem for awhile and I did what you said and it work!!

Lee Bergeron