Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
It's a common request having the ability to export a list of coupons to a CSV file to be handed over to partners or to be sent to customers via email.
For exporting, it's useful to give filter coupons by the batch where they were created. I've filed another issue for this:
Comment | File | Size | Author |
---|---|---|---|
#11 | 3146586-11.patch | 20.14 KB | jsacksick |
|
Issue fork commerce-3146586
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
flocondetoileNot sure that a CSV export should be in the scope of Drupal Commerce. Have you tried Entity Export CSV module ?
Comment #3
jsacksick CreditAttribution: jsacksick at Centarro commentedI'm not against adding this directly into Commerce, we probably can steal some code from Commerce pricelist (referring to the "Export prices" form.
Comment #4
jsacksick CreditAttribution: jsacksick at Centarro commentedI've been investigating this task today and it's probably not so straightforward to provide this from Commerce directly.
We basically have 2 options:
I'm personally in favor of option 2) but since Commerce doesn't depend on Views bulk operations, we can't easily provide this OOB ourselves. Perhaps Commerce could simply replace the coupons listing by a view, and people could then update that view to attach a display built using Views Data export.
Note that if we do with option 2), we need to write 2 custom formatters for the coupon usage. (One for the global usage limit and the other one for the customer usage limit). There's currently logic for that in the coupon list builder itself.
Perhaps it's also a good idea to resurrect https://www.drupal.org/project/commerce_backoffice? Commerce backoffice could then depend on Views bulk operations since Commerce doesn't?
Thoughts?
I'm wondering if we shouldn't write the custom formatters regardless of the solution we pick, so we could allow people to easily do this using custom views...
So perhaps Commerce could provide the formatters... And eventually, the Action plugin?
Comment #5
jsacksick CreditAttribution: jsacksick at Centarro commentedPerhaps, as suggested by the comment in #2, this isn't really a core concern as this can be easily done using a contrib module... This can either be done using Views data export... Or using the VBO Export module for example...
But note once again that this would still require Commerce to provide a better views integration by providing field formatters for the usage fields.
Comment #6
jsacksick CreditAttribution: jsacksick at Centarro commentedCreated #3216713: Create a field formatter for the usage_limit and usage_limit_customer fields.
Comment #7
rszrama CreditAttribution: rszrama at Centarro commentedRetitling the issue, because once this is accomplished, generating a CSV export is resolved via Views Data Export. The scope for core will just be the View conversion, which requires adding the related Views field integrations we're missing.
Comment #8
jsacksick CreditAttribution: jsacksick at Centarro commentedSome requirements about the view:
The view needs a contextual filter on the parent promotion, configured using the following configuration: "Provide default value: Raw value from url, using "2" as the path component).
Instead of displaying all coupons, let's add a pager to the view to output only 50 coupons at once.
The view needs to use the formatter introduced in #3216713: Create a field formatter for the usage_limit and usage_limit_customer fields.
We also need a sort criteria on the coupon ID (DESC).
The view needs to be provided on install, and we also need an update hook to import the view.
Also, the "entity.commerce_promotion_coupon.collection" route should be removed from the routing.yml.
Comment #11
jsacksick CreditAttribution: jsacksick at Centarro commentedI investigated/fixed some of the tests failures.
I also updated the view, changed the permission to "administer commerce_promotion", added a coupon code filter, and put the empty text in the table.
Comment #12
jsacksick CreditAttribution: jsacksick at Centarro commentedSo the coupons list is now a view, it doesn't provide any logic for the CSV export but this can easily be added as pointed out by @rszrama.