[PP-1] Migrate Commerce coupon as promotion coupons

Created on 23 June 2022, about 2 years ago
Updated 29 April 2024, 2 months ago

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

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 πŸ“Œ Migrate discount and discount_offer Needs review for tests, but an initial patch or merge request can be created.

✨ Feature request
Status

Postponed

Version

3.2

Component

Drupal Commerce 1.x

Created by

πŸ‡ΊπŸ‡ΈUnited States mradcliffe USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • @j_ten_man opened merge request.
  • πŸ‡ΊπŸ‡ΈUnited States jim_b

    The 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.)

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 11 months ago
    Composer require failure
  • @mradcliffe opened merge request.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.2 & MySQL 8
    last update 11 months ago
    350 pass, 3 fail
  • πŸ‡ΊπŸ‡ΈUnited States KarlShea Minneapolis, πŸ‡ΊπŸ‡Έ

    Just 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... πŸ“Œ Migrate discount and discount_offer Needs review

  • πŸ‡ΊπŸ‡ΈUnited States makbeta

    I'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.

  • πŸ‡ΊπŸ‡ΈUnited States makbeta

    Looks 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.

  • πŸ‡«πŸ‡·France paulbeaney

    Just 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:

    public function import(Row $row, array $old_destination_id_values = []) {
        $success = FALSE;
        $values = ['usage_id' => 0] + $row->getDestination();
         ...
Production build 0.69.0 2024