It would be great if this module could also change the price in a view. Not sure if this is possible, though, due to Views' caching, etc.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Docc’s picture

Assigned: Unassigned » Docc
Status: Active » Needs review
FileSize
2.42 KB

Try this patch. It uses hook_views_data_alter to alter the price data.

Based on latest uc_views.
Remember to clear your cache after you applied the patch.

davemybes’s picture

Fantastic! Works like a charm, thanks.

Docc’s picture

Status: Needs review » Fixed

Commited to HEAD

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Bartezz’s picture

Hey Docc,

Question on this; I see that the inc file is still there. But the implementation of hook_views_data_alter is gone from the .module file. Now I also do see that things are still working when using row style fields in a view. So somehow views now calls hook_nodeapi:load, right?!

Now here's a popquiz question ;)
The following code (starting at #318) of course sets some variables which are used in hook_nodeapi:view (second code example)

          elseif (variable_get('uc_multiprice_currency_disable_unpriced_product', NULL)) {
              $currency = uc_multiprice_currency($cid);
              // and if the current users country currency doesn't match store default currency
              if ($currency != variable_get('uc_currency_code', 'USD')) {
                $pricehandlers = _uc_price_get_handlers(array(FALSE, FALSE));
                // and if multiprice currency price handler is enabled
                if ($pricehandlers['hook_data']['uc_multiprice']) {
                  $node->disabled_unpriced_product = TRUE;
                }
              }
            }
      case 'view':
        if ($node->disabled_unpriced_product) {
          $node->content['display_price']['#access'] = FALSE;
          $node->content['sell_price']['#value'] = theme('uc_multiprice_unavailable', 'This listing is currently not available.');
          $node->content['add_to_cart']['#access'] = FALSE;
        }
      break;

Ofcourse this doesn't work in views, or should it? Can you point me in a direction on how to achieve this for a row style fields kinda view. (It probably should work with a row style node view but I can't use this row style).

Cheers

Bartezz’s picture

Possible solution might be this module;
http://drupal.org/project/viewsnodefield

Cheers

Bartezz’s picture

Status: Closed (works as designed) » Needs review
FileSize
505 bytes

Hi Docc,

I added a line of code to set the sell price of a product to NULL when a product is disabled. This is a patch for 2.x-dev. With this sell_price set to NULL it helps creating and theming row style - fields displays as this is done in hook_nodeapi:load which Views uses.

Cheers

EDIT: please see http://drupal.org/node/1348096

Bartezz’s picture

Version: 6.x-1.0 » 6.x-2.x-dev
Status: Closed (fixed) » Needs review

I'm having problems with views when usinig row style fields in stead of node and with caching.

For now the solution would be to use row style node or with row style fields and using the viewsnodefield module. The latter will allow you to use views add on modules like views_hacks (Views Selective Exposed Filters) etc.

Caching is another problem I think. For now I'm not caching my views.

Docc can you tell me why the hook_views_data_alter is gone from the module?

I will do some testing over the next weeks on a clean install to see if I these issues are reproducable and if I can come up with patches.

Cheers

Docc’s picture

Because its using the price_alter function. Wich should work with views.
I used hook_views_data_alter before that.

I didnt try, but it should work with views if you select the altered state.

hixster’s picture

I am experiencing some issue with a view which is sorting products based on price (ascending). Everything works fine in the default currency (£), but when in my non default country, (US), sorting on price doesn't seem to work, my products are jumbled in order: ie:

$59.99
$29.99
$19.99
$54.99

Could it be related to this issue?

hixster’s picture

update - just tried printing the (numeric) price as a field in the view and it's just printing the unmodified default currency price.
My view was looking o.k because I was grabbing the themed price.

So how could i sort based on price? This is essential for me to fix. Could a CCK computed field be used a a hack?

Docc’s picture

Basicly the problems occurs when using the sort filter on a price field.
The price handler does not affect this data as the sort is based on the mysql query, ex: "ORDER BY uc_products_sell_price ASC"

So this is more a ubercart issue then multiprice?
I suggest using your own views alters to get the sorting right after the query. (just like the table style does)

Other options are replacing the (sort)handlers for the current uc_product views fields.
Or writing a custom views_data schema for multiprice.

Docc’s picture

Status: Needs review » Closed (works as designed)

Back to the original issue. Since the introduction of the price_handler this has been fixed.

If you want sort support either use the table row style or another style that allows sorting on a render level.

Bartezz’s picture

Status: Needs review » Closed (works as designed)

  • Docc committed 9d02b66 on 7.x-2.x
    #512160 Added support for uc_views