Warenwirtschaft: AP-34 — Varianten-Artikelnummer korrekt zuordnen

Bestellungen mit Produktvarianten (z. B. Deocreme MINI) wurden im Versand nicht
automatisch zugeordnet und mussten manuell nachgepflegt werden. Zwei
zusammenwirkende Fehler:

1. Connector (partnercenter-api v1.6.0): compose_cart_content() las per
   get_product_id() das Elternprodukt und sendete dessen SKU — nie die eigene
   Artikel-Nr. der Variation. Jetzt liest get_product() (variations-aware) die
   Variations-SKU, Fallback auf Eltern-SKU nur wenn leer. Plugin muss neu in den
   Shop ausgerollt werden.

2. Importer (ShoppingUserController::prepareOrder): matchte nur den Teil vor dem
   ersten „-" gegen wp_number. In der Live-DB ist jede Variante eine eigene
   products-Zeile mit eigener wp_number (kein main_product_id, keine „-"-Suffixe).
   Jetzt Zuordnung primär über die VOLLE SKU gegen wp_number; der „-"-Split bleibt
   nur Legacy-Fallback für alte Variations-SKUs „basisnr-suffix".

Tests: neue AP-34-Prüfung (MINI 100026 landet beim MINI-Produkt, nicht beim
50-ml-Basisprodukt 100006) + Legacy-Fallback-Test. Suite 327 grün.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-08-28 09:32:51 +00:00
parent 190713c21b
commit 8c938eed0a
4 changed files with 65 additions and 14 deletions

View file

@ -3,7 +3,7 @@
/**
* Plugin Name: PARTNERCENTER API Connector
* Description: Connect WooCommerce to PARTNERCENTER API
* Version: 1.5.0
* Version: 1.6.0
* Author: Cross Media Cloud
* Author URI: https://www.cross-media-cloud.de
* License: GNU General Public License v2 or later

View file

@ -237,11 +237,21 @@ trait PARTNERCENTER_API_Order
// Loop all order items
foreach ($this->order->get_items() as $order_item) {
// Get product ID of order item
$product_id = $order_item->get_product_id();
// AP-34: Bei Produktvarianten hat jede Variante ihre eigene Artikel-Nr.
// (SKU). get_product() liefert für variable Produkte das Variations-Objekt
// (nutzt get_variation_id(), sonst get_product_id()), also die richtige
// Variations-SKU. Nur wenn an der Variation keine eigene SKU gepflegt ist,
// fallen wir auf das Elternprodukt zurück.
$product = $order_item->get_product();
// Get product object
$product = wc_get_product($product_id);
// Get variation-aware SKU with fallback to the parent product SKU
$sku = $product ? $product->get_sku() : '';
if ($sku === '') {
$parent_product = wc_get_product($order_item->get_product_id());
if ($parent_product) {
$sku = $parent_product->get_sku();
}
}
// Get sum of total and taxes
$line_total = $order_item->get_total() + $order_item->get_total_tax();
@ -254,7 +264,7 @@ trait PARTNERCENTER_API_Order
// Build array item
$cart[] = [
'article' => $product->get_sku(),
'article' => $sku,
'qty' => intval($order_item->get_quantity()),
'price' => $item_price_converted,
];