Hey,

Just wondering what it would take to expose UC's shipping costs to views, from the shipping tables, so one can get a report going of actual shipping costs? I'm currently thinking of manual shipping, but I imagine it could be the same for other types as well (the actual costs are usually different from quoted costs for freight)

Comments

jpstrikesback’s picture

Title: Actual Shipping Costs » add Actual Shipping Costs
Category: feature » task
Status: Active » Needs review

ok that was rather easy:

 // Add shipping costs to uc_views
  $data['uc_shipments']['table']['group'] = t('Ubercart shipment');
  $data['uc_shipments']['table']['join']['uc_orders'] = array(
    'left_field' => 'order_id',
    'field' => 'order_id',
  );
  $data['uc_shipments']['carrier'] = array(
    'title' => t('Shipping Carrier Title'),
    'help' => t('The shipping carrier used.'),
    'field' => array(
      'handler' => 'views_handler_field',
      'click sortable' => TRUE,
    ),
  );
  $data['uc_shipments']['cost'] = array(
    'title' => t('Shipping Cost Amount'),
    'help' => t('The shipping actual cost.'),
    'field' => array(
      'handler' => 'uc_views_handler_field_money_amount',
      'click sortable' => TRUE,
    ),
  );
xacobe’s picture

Im tried this code in diferent places and I couldnt make work.
Could you explain where did you paste that piece of code? It´s not so easy for me.

Thanks

jpstrikesback’s picture

I just added it to uc.views.views.inc, inside hook_views_data()

function uc_views_views_data(){

//all the other data

//my data

return $data;
}
madsph’s picture

Thank you for the input.

I will see if I can include this in the module.

Since shipping is a new dependency, I will have to make some adjustments to avoid problems for people with out shipping.

xacobe’s picture

Thanks jpstrikesback,

I just added and I still couldnt get that numbers, Im using dev version with some modifications, so it is not properly tested. I could see a new field on views but not numbers on it :(

Ill keep trying

jpstrikesback’s picture

StatusFileSize
new11.85 KB

Here is something a little more complete then...but my date_api stuff doesn't seem to work i dunno why...

jpstrikesback’s picture

@madsph Any idea why the date_api stuff I've done doesn't work?

madsph’s picture

Sorry for taking so long to get back to you. Unfortunately the time I can spend on this project is very limited at the moment :-(

How ever - I have installed your module, and I can't see that there is anything wrong with it - what is about the date_api stuff you can't get to work?

jpstrikesback’s picture

Hey, no worries : )

the date_api handler doesn't seem to work with the shipment date field, it uses it, but when it comes to selecting the actual field to filter on in the handler UI it's not there...does anyone see the same or am I in a alternate universe?

madsph’s picture

StatusFileSize
new57.9 KB

Strange - I can't reproduce any errors.

I have made a very simple view with only one field (shipping date), and an exposed filter using an exact date to match shipping date (see attached picture)

The environment I am testing on is slightly out dated:
Drupal: 6.15
Views 6.x-2.6

jpstrikesback’s picture

oops, I just downloaded what I uploaded and noticed that I've commented out the simple date_api call, it's on the last lines of uc_views_shipments.views.inc...my bad, if you want to uncomment it and test again I'd be very grateful!

madsph’s picture

Okay - I now get what you mean. I can't get the field to show up in the list either.

I will see if I can dig anything up and let you know.

Anonymous’s picture

What does the patch in #6 create? I've installed & enabled it, but am so far not seeing any additional fields.

Anonymous’s picture

Hm, I think I found my problem. This submodule is for shipping costs on orders completed, rather than shipping costs associated with products themselves (ie: flat rate shipping cost per product). Any idea where I could find that to be put into views? Thanks.

longwave’s picture

I don't think per-product shipping costs are actually recorded anywhere, as not all shipping methods can provide this information - often a store will use a flat rate per order, or calculate based on total weight of items.

Anonymous’s picture

I've got flat rate shipping set up, and it provides a field for each product to enter a non-default rate. Wish I knew enough php to write sometime for this myself.

longwave’s picture

Category: task » feature

That could be exposed to Views against product nodes, but if you change or delete that flatrate in the future it won't be correct for previous orders as the history isn't available. Then again if you only want to show shipping prices on node views or something, this doesn't matter.