If you want to migrate all not-yet-redeemed vouchers or vouchers with a remaining value from Shopware 5 to your Shopware 6 shop, you can use the following SQL query to export the corresponding voucher codes and remaining values from Shopware 5.
The query is adapted to the extension Gutscheine, Kaufgutscheine & Coupons - EasyCoupon Plugin von Net Inventors GmbH, but it can also be rewritten to be used with other voucher extensions. You can find more information about the mentioned extension in combination with Pickware POS here.
SELECT DISTINCT UUID() AS id, sev.description AS title, 0 AS deleted, NULL AS deleted_date, 1 AS active, 40020 AS voucher_type, sevc.code AS code, IF(sod.redeemed, ROUND(sev.value + sod.redeemed, 2), sev.value) AS value, 10010 AS value_type, 'Import von Pickware Shopware 5 Gutscheinen' AS comment, 0 AS discard_remaining, 1 AS mail_sent, 0 AS combine_vouchers, 1 AS currency_factor, sev.ordercode AS order_position_number, NULL AS max_redemption_value, 'EUR' AS currency_iso_code, -- dynamische Kundennummer aus direktem userID oder fallback über Bestellung IF( su.customernumber IS NOT NULL, CONCAT('{"customerNumber":"', su.customernumber, '"}'), IF( su_fallback.customernumber IS NOT NULL, CONCAT('{"customerNumber":"', su_fallback.customernumber, '"}'), '{}' ) ) AS virtual_import, vcv.validTo AS valid_until, 0 AS redemption_order, NULL AS pin, NULL AS initial_value, NULL AS tax_id, 'cart' AS discount_scopeFROM s_emarketing_voucher_codes sevcLEFT JOIN s_emarketing_vouchers sev ON sev.id = sevc.voucherIDLEFT JOIN s_emarketing_vouchers_attributes seva ON seva.voucherId = sev.id-- Redeemed value korrekt bestimmenLEFT JOIN ( SELECT sod.articleID AS voucherCodeId, SUM(sod.price) AS redeemed FROM s_order_details sod LEFT JOIN s_order so ON so.id = sod.orderID LEFT JOIN s_emarketing_voucher_codes vc ON vc.id = sod.articleID LEFT JOIN s_emarketing_vouchers v ON v.id = vc.voucherID WHERE sod.modus = 2 AND so.status NOT IN (-1, 1, 4) AND sod.articleordernumber = v.ordercode AND v.modus = 1 GROUP BY sod.articleID) AS sod ON sod.voucherCodeId = sevc.id-- Gutschein-MetadatenLEFT JOIN s_plugin_viison_coupon_voucher_code_gift_voucher vcv ON vcv.voucherCodeId = sevc.id-- Direkte Zuordnung via userIDLEFT JOIN s_user su ON su.id = sevc.userID-- Fallback: Kundennummer über eingelöste Bestellung (nur wenn userID NULL)LEFT JOIN s_order_details sod_fallback ON sod_fallback.id = vcv.orderDetailIdLEFT JOIN s_order so_fallback ON so_fallback.id = sod_fallback.orderIDLEFT JOIN s_user su_fallback ON su_fallback.id = so_fallback.userIDWHERE sevc.cashed = 0 AND sev.modus = 1;Afterwards, you can import the vouchers into Shopware 6. You can find all further information about this at Net Inventors.
