How to emulate:
If you have a product with multiple revisions, add a view that use aggregation for ordered products, use relation Order required and add two fields order_product.nid and uc_product cost field, you will get multiple records for the same products instead of last revision cost.

The problem is present for all fields that describes "additional fields" nid like sell_price or list_price.

If I add e required relation to the node with with products relationship is still not working.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

longwave’s picture

I think this is basically a duplicate of #944238: Order Products: node revision ID from time of sale required, but can you export a sample view that demonstrates the issue so we can reproduce the problem more easily?

longwave’s picture

Status: Active » Postponed (maintainer needs more info)

If you add a node relationship and then get the cost field through the node relationship, does that work better? We have a default join on nid between uc_product and uc_order_product, but this will not select the correct data when using node revisions.

SilviuChingaru’s picture

It doesn't connect right because uc_order_products should connect to node based on nid and then to uc_products data, not directly.

Something like "access uc_products when uc_order_products is base with left table node on field nid and left field nid, and the node connects to uc_products via vid by default so the right version is picked". Right?

This is where is wrong: We shoudn't connect from uc_order_product to uc_products based on nid but on node directly and then to uc_products via left table.

I'll try it a little bit latter and I'll post also my view and maybe a patch...

longwave’s picture

That's why I asked "if you add a node relationship...", because node is linked to uc_products through vid if you use a relationship and this should work, however we also have an automatic join of uc_order_products to uc_products on nid alone which is wrong. However, changing or removing the implicit joins now may cause existing Views to break, so we have to be careful.

SilviuChingaru’s picture

It won't break because the hook_view_info() will be something like:
$data['uc_product']['table']['join']['uc_order_product'] = array(
...
'left_table' => 'node',
'left_field' => 'nid',
'field' => 'nid',
...
);
and the uc_product is linked to node via vid field. So no relation is needed and only the query is changed so nothing is breaked in existing view.

By the way is not working with node relation because they are linked both via relationship and directly in the query. I thin this is because we "expose uc_product fields directly".

SilviuChingaru’s picture

It doesn't work if we link uc_order_products directly to uc_products because products uses vid's like node but uc_order_products stores only product nid not the vid. So if we join on nid we'll get one record for each revision not just last updated product's fields like it should (we don't have multiple products but the same so it should not be multiple records displayed for the same product).

The #5 is working only if the uc_order_products is the base table but if the base is uc_order, with a relationship to the ordered products tha above definition is ignored by the view so is not the right way.

The corect working way here is to use a relationship to the nid to pull all product's updated fields and not the products fields.

Patch attached and is working fine this way.

SilviuChingaru’s picture

Status: Postponed (maintainer needs more info) » Needs review
longwave’s picture

Status: Needs review » Fixed

Makes sense, I hope this doesn't break any existing Views out there but really I have no way of telling. Committed.

SilviuChingaru’s picture

For user with issues:
If something is breaked just add a relationship to ordered product and add same fields (the one that aren't shown anymore) from that relation.

Status: Fixed » Closed (fixed)

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