This is a followup to #1911278: Expose shipping data to views.

Add a field to the package view that lists the content of the package in a simple way. There should be options for listing by SKU or product title, and for using a comma-separated list or a bullet list. Each item can optionally be a link to the product node. It should be themable, of course.

It might be a good idea to add a token that does the same thing.

Comments

Jordan_Fei’s picture

Hi DanZ,

Where is the default view for package view? I didn't find the uc_shipping.views_default.inc.

Thanks,
Jordan

DanZ’s picture

There is no default view yet. This is all new functionality from #1911278: Expose shipping data to views. You can create your own custom view, though.

See also #1937764: Master Issue: Overhaul shipping. The UI for shipping needs to be overhauled. This will surely involve a new default view of packages.

Note that I'll get to this eventually, but I do have other projects, so it would be fine if you did this first.

Jordan_Fei’s picture

Hi Danz,

I would like to do this task if you can guide me. Now I can think out two points need your comments:
1. The relationship between package and package content: uc_packages, uc_packaged_products, uc_order_products and uc_products?

2. Do you have any example for this kind of views field handler extending? (Use a comma-separated list, and each item optionally be a link to the product node.) Or give me some comments to help me do this from technical perspective.

Thanks,
Jordan

DanZ’s picture

The relationship between package and package content: uc_packages, uc_packaged_products, uc_order_products and uc_products?

{uc_products} contains fields that are added to product nodes. This describes the individual products that are for sale. So, that means the price, weight, etc.

{uc_order_products} contains information about the items actually added to an order. This includes the options values and the quantity ordered. Once the order product entities are fully loaded, they also contain all the product and node information. These also include the price paid for products.

{uc_packages} contains information about individual packages. This includes the ID of the shipment and order, the size of the package, a tracking number, a link to a shipping label image.

{uc_packaged_products} cross-references which order products belong in which packages. It does this by listing IDs of the packages and order products.

See uc_shipping_views_data() for the relationships between the tables.

Do you have any example for this kind of views field handler extending? (Use a comma-separated list, and each item optionally be a link to the product node.) Or give me some comments to help me do this from technical perspective.

I don't know a lot about this yet, as I haven't researched it yet, and I don't have an example, but the steps are something like this:

Add the new field to uc_shipping_views_data().

Add a new handler for the new field. This should extract data directly from the package object. The fully-loaded package object has a field containing a list of products.

The render() method of the handler should be overridden to output the themed list.

Add options for the field (commas/bullets, SKUs/descriptions).

Add a theme preprocess function that prepares the data for theming.

Add a theme function that takes the data and the output options and generates HTML.

longwave’s picture

Is it not possible to do this already using the grouping options available in Views, now we have added relationships that allow you to pull product information into a package view? Or if that's not workable, maybe http://drupal.org/project/views_field_view would help? I'd like to avoid adding specific fields to Views if other more flexible solutions are available.

longwave’s picture

Category: task » feature
DanZ’s picture

Is it not possible to do this already using the grouping options available in Views

As far as I know, the grouping options are only what SQL gets you, which are "group by" and mathematical aggregation. I don't know any way to do concatenation, which is what you'd want here. If there is a way, that would be ideal.

Or if that's not workable, maybe http://drupal.org/project/views_field_view would help?

That probably would do it. However, I'm thinking in terms of overhauling the shipping UI. You'd want a view of packages in the default UI, and that view should show what's in each package. So, that's part of the core. I think it would be better to avoid installing another separate module in order to turn on shipping.

If there's a clean way to have a subview without requiring an additional module, that would be great. It would really allow users to customize what shows up in the field.

I'd like to avoid adding specific fields to Views if other more flexible solutions are available.

I agree: When available, it's generally better to rely on general-purpose code instead of doing it with custom code. At least, by using the theming mechanism, the output can be kept fairly flexible.

It's worth doing some research on this, but I don't see any clean way to do this short of adding an additional Views field. Besides, most people setting up a custom view of packages are going to want that field because they'll want to know what's in there.

I'm hoping that it's possible to re-use some of the code already used to display packages, but I haven't looked into that yet.

longwave’s picture

Yeah, doesn't seem the grouping options in Views allow this just yet. #1362524: add GROUP_CONCAT aggregate function; and move aggregate function helpers to a query extender? looks like the most relevant feature request.

I am not sure there's a clean and simple way to allow a subview; that's why that module exists, after all.

Jordan_Fei’s picture

Hi DanZ and longwave,

Thanks for both of your comments! Your discussion about the solutions choosing are wonderful.
A good solution selection is important.

For DanZ's normal solution I can understand basically.

For longwave's first solution, I am not quite being understand yet, maybe I need to spend more time on research this solution.

For longwave's second solution I am not sure that dependence on other module is good or not on this feature, just follow your decision.

I would like to do some coding for this feature to implement your idea on this feature. :)

Thanks&Regards
Jordan

Jordan_Fei’s picture

It seems the GROUP_CONCAT aggregate function is still on discussion, not commit to views 7 yet. Maybe we can wait until that feature is moved into views module.

But I am worried that if we want to use the GROUP_CONCAT aggregate function, the granularity of package views should be on {uc_packaged_products} level, not {uc_packages} level.

DanZ’s picture

But I am worried that if we want to use the GROUP_CONCAT aggregate function, the granularity of package views should be on {uc_packaged_products} level, not {uc_packages} level.

This should not be a problem. The only thing that {uc_packaged_products} adds is a quantity field for the number of that product in the package. Other than that, it only has links to the order products and the package.

So, it's perfectly possible to make a parameterized view of the packaged products. Get the quantity {uc_packaged_products}, make a relationship to {uc_order_products}, and get the other information from there.

TR’s picture

Version: 7.x-3.x-dev » 8.x-4.x-dev
Component: Shipping » Fulfillment
Issue summary: View changes