Problem/Motivation
Commerce provides coupons out-of-the-box, but a migrated site does not have coupon or coupon usage data provided by commerce_coupon module.
Commerce coupon provides:
- Commerce coupon entity
- Commerce coupon conditions:
- Usage limit is provided by its sub-module commerce_coupon_usage
- Usage data is also tracked on a commerce order entity reference field.
- Start/End date is provided by its sub-module commerce_coupon_date
- Product conditions, which do not exist on the coupon level in Commerce from 8.x and above
- Usage limit is provided by its sub-module commerce_coupon_usage
These all map to commerce promotion coupons fairly reasonably.
Proposed resolution
- Provide a separate, smaller test fixture with commerce_coupon data because commerce_kickstart does not use commerce_coupon.
- Add a Commerce promotion coupon migration that optionally sets start/end date and usage limits.
- Add a Commerce promotion coupon usage migration.
- Workaround any Commerce discount migration that stores duplicate data when coupons are used.
Remaining tasks
Blocked on #2905242: Migrate discount and discount_offer for tests, but an initial patch or merge request can be created.
Issue fork commerce_migrate-3292345
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
mradcliffeComment #3
danharper commentedHow do I get the diff to test?
Comment #5
jim_b commentedThe patch files from this issue's fork no longer work with commerce_migrate v3.2.1 or v3.2.x-dev after the update on 9 Jul 2023.
(The v3.2.x-dev before 9 Jul 2023 would allow these patches to apply.)
Comment #7
karlsheaJust to be helpful to others, as of today MR !13 is support for coupon migrations on 4.0.x on top of the patch at https://www.drupal.org/project/commerce_migrate/issues/2905242#comment-1...
Comment #8
makbeta commentedI'm attempting to use/test this solution. The coupon and discount migration seems to work just fine. However, I don't get the `upgrade_commerce1_coupon_usage` as an available migration. I see the YML file and it seems to be checking out, but for some reason the migration not being included into the list.
My D7 site was configured to use coupons and discounts. I'm wondering if I need to do something to enable this migration or if certain criteria needs to be met for this migration to register.
Any input on this will be greatly appreciated.
Comment #9
makbeta commentedLooks like the migration of coupon usage relies on Coupon Usage module (data in the database table
commerce_coupon_usage_transaction), which is not something I have in my case. Coupons can be associated with an order in D7 without the Coupon Usage module. The module can be enabled in D7, but the historical data is then not populated.During the migration to D9, the discount is migrated by the coupon information is not migrated into the coupon field. The order to coupon association can be read from another table
field_data_commerce_coupons, which is not handled by this specific solution, but can be extended.Comment #10
paulbeaney commentedJust managed to get all this up and running with a bit of tweaking for my specific scenario, but there does seem to be one basic problem: this migration re-uses the Promotion Usage destination plugin, but said plugin sets the coupon_id to zero in the import() function. I ended up just tweaking the function to this so that the Coupon Usage migration can supply the value for coupon_id: