Create a custom purchased_entity views field plugin

Bojan info/suggestions:

There are some Views that render the purchased_entity:
order summary, cart form, cart block

However, an order item type might specify a NULL purchased entity type, meaning that order items of that type won’t have a purchased entity, in which case there’s nothing to render

If there’s nothing to render, the view should show the order item title

there’s no logic for that

We need to create a custom views field plugin for the purchased_entity field
that has a settings form for selecting the view mode
and in the main function renders the purchased entity if it exists, otherwise it falls back to the order item title

Comments

vasike created an issue. See original summary.

vasike’s picture

Status: Active » Needs review

PR available
https://github.com/drupalcommerce/commerce/pull/650

Is there's something else needed?

jasonsafro’s picture

Works for me.

kingdutch’s picture

Assigned: vasike » Unassigned
StatusFileSize
new3.92 KB

Adding patch file (based on PR linked in #2 on the date of this comment) so I can reference it from composer files without the possibility of it changing due to new commits on the PR.

Also unassigning because it needs a Review :)

BD3’s picture

Thanks, the patch in #4 is working for me using some donations with a custom form.

Marko B’s picture

Not sure how this is suppose to work. I have order summary view where I would expect to have an extra item that is added in table, but I keep getting 2 rows as result and this item is ignored, although it should be 3 of them. So the patch doesn't seem to help here, maybe it does in some other scenario, seems that we should have more robust solution.

Marko B’s picture

Further inspecting I see the problem comes from production variation relationship, If I just list order items, this item will be shown without a problem, but as other products have product variations I want to show their image in cart summary, with that this "donation" item is gone out of results.

cameron prince’s picture

StatusFileSize
new1.56 KB

Re-roll for commerce v2.16.0.

spokje’s picture

StatusFileSize
new2.36 KB

Let's see if this reroll against the latest 8.x-2.x branch gives some more green in TestBot-land.

msti’s picture

StatusFileSize
new2.37 KB
robcarr’s picture

This seems to work for me. Rolled against Commerce 2.27

+1 for RTBC

msti’s picture

StatusFileSize
new2.39 KB

I am updating the patch because it was giving an error for commerce 2.30
before:

return [['rendered' => $order_item->getTitle()]];

after:

return [['rendered' => ['#plain_text' => $order_item->getTitle()]]];
cameron prince’s picture

Re-roll for 3.x.