I have a site that I have product with similar names but of different brands. I store my product brand as one of the product field entity. Therefore, when I view my site order, my product titles tend to be identical but they are of different brands.
for e.g.
1. Brand A has title "LED light bulb"
2. Brand B also has title "LED light bulb"
And I cannot differentiate whether my customer buys Brand A or Brand B light bulb.
May I request for a feature for site admin to be able to add entities like product SKU or product field into site order list so that the site admin can tell which product is being purchased?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

shadeworm created an issue. See original summary.

sorabh.v6’s picture

Assigned: Unassigned » sorabh.v6
sorabh.v6’s picture

Product sku field is added to order item table. Please review.

@shadeworm If you want you can also add your product brand field into the order item table. It's a view with name order items. Just create a relationship of product variation and then add the fields you want to show on the table.

sorabh.v6’s picture

Assigned: sorabh.v6 » Unassigned
Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: 2928932-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

sorabh.v6’s picture

Status: Needs work » Needs review
FileSize
3.81 KB
5.52 KB

Code updated to pass the test.

Status: Needs review » Needs work

The last submitted patch, 6: 2928932-6.patch, failed testing. View results

MegaChriz’s picture

Title: Order Interface » Add SKU to view 'commerce_order_item_table'

Changed issue title to be more precise.

From an user point of view, I find it a good default to have the SKU displayed when viewing the details of an order. From a developer point of view I see how it would make thing less flexible: the view 'commerce_order_item_table' would get a hard dependency on commerce_product and likely would introduce issues with purchasable entities that are not a commerce_product. This is probably why the tests fail.

Maybe ProductVariation::getOrderItemTitle() should return both the title and the SKU?

sorabh.v6’s picture

Thanks, I will try.

sorabh.v6’s picture

@MegaChriz ProductVariation::getOrderItemTitle() returns title only and for sku there's a separate function ProductVariation::getSku(). It will not be good if we return both from a single method.

sorabh.v6’s picture

Uploading updated patch.

MegaChriz’s picture

@sorabh.v6
Yes, but there's also ProductVariation::getTitle() and ProductVariation::label(). From my understanding ProductVariation::getOrderItemTitle() is designed to show a label specific for display in the order item table. That is allowed to be different than in other places where a product variation is displayed.

You could let the method return something like this:
[Product title] ([SKU])
For example:
Lorem Ipsum (P001)

It would be good though to verify with the Commerce maintainers first if a feature request like this is desirable.

sorabh.v6’s picture

@MegaChriz Nice suggestion, I will confirm with bojanz first.

subhojit777’s picture

Status: Needs work » Needs review
FileSize
6.46 KB
400 bytes
subhojit777’s picture

The last submitted patch, 14: 2928932-14.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 15: 2928932-15.patch, failed testing. View results

bojanz’s picture

#12 is correct. What we need is a way to customize the title.

The attached patches are uncomittable, we can't add fields specific to 1 purchasable entity type.

sorabh.v6’s picture

Assigned: Unassigned » sorabh.v6
sorabh.v6’s picture

Assigned: sorabh.v6 » Unassigned
Status: Needs work » Needs review
FileSize
499 bytes

Hi All,

Removed all previous code and code added as suggested in #12. Thanks @MegaChriz.

I have not made any changes to .install file because I think changing the titles of the order items from previous orders might create some confusion and discrepancy. Please share your thoughts.

Thanks All

Status: Needs review » Needs work

The last submitted patch, 20: 2928932-20.patch, failed testing. View results

sorabh.v6’s picture

Updated code with changes in tests. Please review.

sorabh.v6’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 22: 2928932-22.patch, failed testing. View results

sorabh.v6’s picture

Status: Needs work » Needs review
FileSize
710 bytes
5.14 KB

Updated tests again. :D

sorabh.v6’s picture

At last, tt passed the tests. I am so happy :D

smccabe’s picture

Status: Needs review » Reviewed & tested by the community

Patch code looks proper to me on review and matches what is decided on in #12. Test updates also look correct.

Could probably use a review from MegaChris or Bojan as they are more familiar with the issue, but seems a pretty straightforward issue of appending the SKU by default.

_dcre_’s picture

I 've got a question which is not totally relevant, but pretty relevant..

Is it possible to use a different custom view in the place of commerce_order_item_table ?
Even further, how would one be able to have a different commerce_order_item_table view or view display for different order types?
Is that even possible?
Of course i mean in a programmatic way not via the UI, although the later would not be a bad idea.

Thanx in advance

agoradesign’s picture

Yes, you can exactly do that already. There are per order type settings to select both the shopping cart form view and the shopping cart block view. And you can set this via UI as well as in a programmatic way

_dcre_’s picture

@agoradesign i am actually referring to the backend order view (/admin/commerce/orders/ORDER-ID)

I don't see how/if i can set this up via the UI or programmatically. Am i missing something here?

AltaGrade’s picture

Status: Reviewed & tested by the community » Needs work

Long time. The patch does not apply anymore:

error: patch failed: modules/product/tests/src/Kernel/Entity/ProductVariationTest.php:85
error: modules/product/tests/src/Kernel/Entity/ProductVariationTest.php: patch does not apply

So maybe this kind of issues must be closed, especially when you can add relationship to product variation and get the SKU field.