Skip to main content

WooCommerce PunchOut Integration

📋 Voraussetzungen

  • WordPress 5.8+ mit WooCommerce 5.0+
  • SSL-Zertifikat (HTTPS) aktiviert
  • Admin-Zugriff auf WordPress
  • PHP 7.4 oder höher
  • PunchFlow Account (Registrierung)

🚀 Schnellstart (2 Minuten)

Schritt 1: Plugin installieren

Option A: WordPress Plugin Store

  1. WordPress AdminPluginsInstallieren
  2. Suche nach "PunchFlow for WooCommerce"
  3. Installieren und Aktivieren

Option B: Manuelle Installation

# Plugin herunterladen
wget https://downloads.punchflow.de/woocommerce/latest.zip

# In WordPress hochladen
1. WordPress Admin → Plugins → Installieren → Plugin hochladen
2. ZIP-Datei auswählen
3. Installieren und aktivieren

Schritt 2: REST API aktivieren

  1. WooCommerceEinstellungenErweitertREST-API
  2. "Schlüssel hinzufügen" klicken
  3. Konfiguration:
    Beschreibung: PunchFlow Integration
    Benutzer: Admin-Benutzer auswählen
    Berechtigungen: Lesen/Schreiben
  4. Schlüssel generieren und kopieren

Schritt 3: PunchFlow verbinden

// Im PunchFlow Dashboard oder via API
{
"shop_type": "woocommerce",
"config": {
"shop_url": "https://ihr-shop.de",
"consumer_key": "ck_xxx",
"consumer_secret": "cs_xxx",
"version": "wc/v3"
}
}

⚙️ Plugin-Konfiguration

Basis-Einstellungen

In WordPress unter WooCommercePunchFlow:

// wp-content/plugins/punchflow/config.php
return [
'general' => [
'enabled' => true,
'api_key' => 'YOUR_PUNCHFLOW_API_KEY',
'environment' => 'production', // oder 'sandbox'
'debug_mode' => false,
],

'punchout' => [
'protocols' => ['cxml', 'oci'],
'session_timeout' => 60, // Minuten
'auto_login' => true,
'guest_checkout' => false,
],

'mapping' => [
'sku_field' => 'sku', // oder '_custom_sku'
'price_type' => 'regular', // oder 'sale'
'tax_display' => 'incl', // oder 'excl'
],

'customers' => [
'auto_register' => true,
'role' => 'b2b_customer',
'require_approval' => false,
]
];

B2B-Funktionen aktivieren

// functions.php oder Custom Plugin
add_action('init', function() {
// B2B-Kundengruppe erstellen
add_role('b2b_customer', 'B2B-Kunde', [
'read' => true,
'edit_posts' => false,
'delete_posts' => false,
]);

// Preise ohne MwSt. für B2B
add_filter('woocommerce_get_price_html', function($price, $product) {
if (current_user_can('b2b_customer')) {
$price = wc_price($product->get_price_excluding_tax());
}
return $price;
}, 10, 2);
});

🔄 Hook-Integration

Session-Hooks

// PunchOut Session Start
add_action('punchflow_session_start', function($session_data) {
// Benutzer automatisch anmelden
$user = get_user_by('email', $session_data['buyer_email']);
if (!$user) {
$user_id = wp_create_user(
$session_data['buyer_email'],
wp_generate_password(),
$session_data['buyer_email']
);
$user = get_user_by('id', $user_id);
}
wp_set_current_user($user->ID);
wp_set_auth_cookie($user->ID);

// Session-Daten speichern
update_user_meta($user->ID, 'punchout_session', $session_data);
});

// Cart Transfer
add_action('punchflow_before_transfer', function($cart_data) {
// Validierung vor Transfer
foreach ($cart_data['items'] as $item) {
$product = wc_get_product($item['product_id']);
if (!$product->is_in_stock()) {
throw new Exception('Produkt nicht auf Lager: ' . $product->get_name());
}
}
});

Checkout-Anpassungen

// Checkout für PunchOut anpassen
add_filter('woocommerce_checkout_fields', function($fields) {
if (punchflow_is_active_session()) {
// Zahlungsfelder entfernen
unset($fields['billing']['billing_payment']);

// Pflichtfelder anpassen
$fields['billing']['billing_company']['required'] = true;

// Felder vorausfüllen
$session = punchflow_get_session();
$fields['billing']['billing_email']['default'] = $session['buyer_email'];
}
return $fields;
});

// Transfer-Button hinzufügen
add_action('woocommerce_review_order_after_submit', function() {
if (punchflow_is_active_session()) {
?>
<button type="button" id="punchflow-transfer" class="button alt">
Zurück zum Einkaufssystem
</button>
<script>
jQuery('#punchflow-transfer').click(function() {
jQuery.post('<?php echo admin_url('admin-ajax.php'); ?>', {
action: 'punchflow_transfer_cart',
nonce: '<?php echo wp_create_nonce('punchflow_transfer'); ?>'
}, function(response) {
window.location.href = response.redirect_url;
});
});
</script>
<?php
}
});

📦 Produkt-Synchronisation

Meta-Felder für B2B

// Zusätzliche Produktfelder
add_action('woocommerce_product_options_general_product_data', function() {
// Herstellernummer
woocommerce_wp_text_input([
'id' => '_manufacturer_sku',
'label' => 'Herstellernummer',
'description' => 'Für PunchOut-Katalog'
]);

// UNSPSC-Code
woocommerce_wp_text_input([
'id' => '_unspsc_code',
'label' => 'UNSPSC-Code',
'description' => 'Klassifizierung für eProcurement'
]);

// Lieferzeit
woocommerce_wp_text_input([
'id' => '_delivery_time',
'label' => 'Lieferzeit (Tage)',
'type' => 'number'
]);
});

// Felder speichern
add_action('woocommerce_process_product_meta', function($post_id) {
update_post_meta($post_id, '_manufacturer_sku',
sanitize_text_field($_POST['_manufacturer_sku']));
update_post_meta($post_id, '_unspsc_code',
sanitize_text_field($_POST['_unspsc_code']));
update_post_meta($post_id, '_delivery_time',
intval($_POST['_delivery_time']));
});

Bulk-Export

// REST API Endpoint für Bulk-Export
add_action('rest_api_init', function() {
register_rest_route('punchflow/v1', '/products/export', [
'methods' => 'GET',
'callback' => 'punchflow_export_products',
'permission_callback' => 'punchflow_api_permission'
]);
});

function punchflow_export_products($request) {
$products = wc_get_products([
'limit' => -1,
'status' => 'publish'
]);

$export = [];
foreach ($products as $product) {
$export[] = [
'sku' => $product->get_sku(),
'name' => $product->get_name(),
'price' => $product->get_price(),
'stock' => $product->get_stock_quantity(),
'manufacturer_sku' => get_post_meta($product->get_id(), '_manufacturer_sku', true),
'unspsc_code' => get_post_meta($product->get_id(), '_unspsc_code', true),
'delivery_time' => get_post_meta($product->get_id(), '_delivery_time', true),
'categories' => wp_get_post_terms($product->get_id(), 'product_cat', ['fields' => 'names'])
];
}

return rest_ensure_response($export);
}

🎨 Template-Anpassungen

PunchOut-Modus Indikator

// header.php
<?php if (punchflow_is_active_session()): ?>
<div class="punchout-banner">
<p>PunchOut-Modus aktiv |
Session: <?php echo punchflow_get_session_id(); ?> |
<a href="#" id="punchout-cancel">Abbrechen</a>
</p>
</div>
<?php endif; ?>

Mini-Cart Anpassung

// mini-cart.php
<?php if (punchflow_is_active_session()): ?>
<button class="button punchout-transfer">
Warenkorb übertragen
</button>
<?php else: ?>
<a href="<?php echo wc_get_checkout_url(); ?>" class="button checkout">
Zur Kasse
</a>
<?php endif; ?>

🧪 Testing

Test-Modus aktivieren

// wp-config.php
define('PUNCHFLOW_TEST_MODE', true);
define('PUNCHFLOW_TEST_URL', 'https://sandbox.punchflow.de');

Test-Session erstellen

# WP-CLI Befehl
wp punchflow test-session \
--protocol=cxml \
--buyer=test@example.com \
--return-url=https://test.erp.com

Unit-Tests

// tests/test-punchflow.php
class PunchFlowTest extends WP_UnitTestCase {

public function test_session_creation() {
$session = punchflow_create_session([
'protocol' => 'cxml',
'buyer_email' => 'test@example.com'
]);

$this->assertNotEmpty($session['session_id']);
$this->assertEquals('active', $session['status']);
}

public function test_cart_transfer() {
// Cart erstellen
WC()->cart->add_to_cart(123, 2);

// Transfer testen
$result = punchflow_transfer_cart();

$this->assertTrue($result['success']);
$this->assertNotEmpty($result['redirect_url']);
}
}

📊 Analytics & Reporting

Dashboard-Widget

// Dashboard Widget für PunchOut-Statistiken
add_action('wp_dashboard_setup', function() {
wp_add_dashboard_widget(
'punchflow_stats',
'PunchOut Analytics',
'punchflow_dashboard_widget'
);
});

function punchflow_dashboard_widget() {
$stats = punchflow_get_stats();
?>
<div class="punchflow-stats">
<p>Sessions heute: <strong><?php echo $stats['today']; ?></strong></p>
<p>Sessions diese Woche: <strong><?php echo $stats['week']; ?></strong></p>
<p>Conversion Rate: <strong><?php echo $stats['conversion']; ?>%</strong></p>
<p>Durchschnittlicher Warenwert: <strong><?php echo wc_price($stats['avg_value']); ?></strong></p>
</div>
<?php
}

Custom Reports

// WooCommerce Admin Report erweitern
add_filter('woocommerce_admin_reports', function($reports) {
$reports['punchout'] = [
'title' => 'PunchOut',
'reports' => [
'sessions' => [
'title' => 'Sessions',
'description' => 'PunchOut Session-Übersicht',
'hide_title' => false,
'callback' => 'punchflow_render_sessions_report'
]
]
];
return $reports;
});

🔧 Troubleshooting

Häufige Probleme

REST API funktioniert nicht

# .htaccess prüfen
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# Permalinks neu generieren
WordPress Admin → Einstellungen → Permalinks → Speichern

Session wird nicht erkannt

// Debug-Logging aktivieren
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('PUNCHFLOW_DEBUG', true);

// Logs prüfen
tail -f wp-content/debug.log

Performance-Probleme

// Object Cache aktivieren
define('WP_CACHE', true);

// Transients für PunchFlow nutzen
set_transient('punchflow_products', $products, HOUR_IN_SECONDS);

🚀 Performance-Optimierung

Caching-Strategie

// Redis Object Cache
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);
define('WP_REDIS_PREFIX', 'punchflow');
define('WP_REDIS_DATABASE', 0);

Lazy Loading

// Produkte asynchron laden
jQuery(document).ready(function($) {
if (window.punchflowSession) {
$('.product-grid').on('scroll', function() {
if ($(this).scrollTop() + $(this).height() >=
$(this)[0].scrollHeight - 100) {
loadMoreProducts();
}
});
}
});

📚 Weitere Ressourcen

💡 Best Practices

  1. Regelmäßige Backups vor Updates
  2. Staging-Umgebung für Tests nutzen
  3. Caching für bessere Performance
  4. Monitoring mit Tools wie New Relic
  5. Security-Plugins wie Wordfence
  6. API-Keys in wp-config.php speichern

🆘 Support

Bei Fragen oder Problemen: