Skip to content

Product Export/Import fails with "Backend header doesn't contain fields" error #178

@wojtekdoman

Description

@wojtekdoman

Environment

  • OroCommerce Version: 6.1.x
  • PHP Version: 8.2
  • Database: PostgreSQL 15
  • Operating System: Linux/Docker
  • Installation Type: Community Edition

Summary

Product export functionality and import template generation fail with "Backend header doesn't contain fields" error due to missing field mappings in ProductDataConverter::getBackendHeader() method.

Current Behavior

Issue 1: Product Export Failure

When attempting to export products via admin panel or CLI:

  • Export process fails immediately
  • Error message: Backend header doesn't contain fields: featured, inventory_status:id, newArrival, sku, descriptions:default:wysiwyg, metaDescriptions:default:text, metaKeywords:default:text, names:default:string, shortDescriptions:default:text

Issue 2: Import Template Generation Failure

When generating import template:

  • Generated file is empty (0 bytes)
  • Error message: Backend header doesn't contain fields: descriptions:English (United States):fallback, descriptions:English (United States):wysiwyg, names:English (United States):fallback, names:English (United States):string, shortDescriptions:English (United States):fallback, shortDescriptions:English (United States):text

Expected Behavior

  • Product export should successfully generate CSV file with all product data
  • Import template should generate valid CSV file with proper headers and sample data
  • Both operations should handle all standard product fields including featured status, inventory status, and localized content

Steps to Reproduce

For Export Issue:

  1. Navigate to Products > Products in admin panel
  2. Click "Export" button
  3. Select CSV format
  4. Click "Export"
  5. Observe error message

For Import Template Issue:

  1. Navigate to Products > Products in admin panel
  2. Click "Import File" button
  3. Click "Download Data Template"
  4. Observe empty file download

Root Cause Analysis

The issue is located in:

/vendor/oro/commerce/src/Oro/Bundle/ProductBundle/ImportExport/DataConverter/ProductDataConverter.php

The getBackendHeader() method is missing mappings for several critical fields:

Missing Standard Fields:

  • featured - boolean field for featured products
  • newArrival - boolean field for new products
  • inventory_status:id - inventory status reference
  • sku - product SKU (critical field)

Missing Localized Fields:

Fields with default locale prefix:

  • descriptions:default:wysiwyg
  • names:default:string
  • shortDescriptions:default:text
  • metaDescriptions:default:text
  • metaKeywords:default:text

Fields with specific locale (e.g., "English (United States)"):

  • descriptions:English (United States):wysiwyg
  • names:English (United States):string
  • shortDescriptions:English (United States):text

Proposed Solution

Update ProductDataConverter::getBackendHeader() method to include all missing field mappings:

protected function getBackendHeader()
{
    $header = parent::getBackendHeader();
    
    // Add missing standard fields
    $header['featured'] = 'featured';
    $header['newArrival'] = 'newArrival';
    $header['inventory_status:id'] = 'inventory_status.id';
    $header['sku'] = 'sku';
    
    // Add missing localized fields with default locale
    $header['descriptions:default:wysiwyg'] = 'descriptions.default.wysiwyg';
    $header['names:default:string'] = 'names.default.string';
    $header['shortDescriptions:default:text'] = 'shortDescriptions.default.text';
    $header['metaDescriptions:default:text'] = 'metaDescriptions.default.text';
    $header['metaKeywords:default:text'] = 'metaKeywords.default.text';
    
    // Add support for specific locale pattern
    $locales = $this->getLocales(); // Method to get configured locales
    foreach ($locales as $locale) {
        $localeStr = $locale->getName(); // e.g., "English (United States)"
        $header["descriptions:{$localeStr}:wysiwyg"] = "descriptions.{$localeStr}.wysiwyg";
        $header["descriptions:{$localeStr}:fallback"] = "descriptions.{$localeStr}.fallback";
        $header["names:{$localeStr}:string"] = "names.{$localeStr}.string";
        $header["names:{$localeStr}:fallback"] = "names.{$localeStr}.fallback";
        $header["shortDescriptions:{$localeStr}:text"] = "shortDescriptions.{$localeStr}.text";
        $header["shortDescriptions:{$localeStr}:fallback"] = "shortDescriptions.{$localeStr}.fallback";
    }
    
    return $header;
}

Workaround

Until the fix is released, users can:

  1. For Export: Create custom export processor that extends ProductDataConverter and overrides getBackendHeader()
  2. For Import: Use manually created CSV templates with correct headers
  3. Alternative: Use API endpoints for product data extraction/import instead of CSV functionality

Impact

Severity: High

  • Complete inability to use built-in product export functionality
  • Blocks data migration and backup processes
  • Affects B2B commerce operations requiring bulk product management

Affected Components:

  • Product export functionality
  • Import template generation
  • Product DataFixtures (for development/testing)
  • Any custom integrations relying on CSV import/export

Additional Context

This issue appears to be a regression or incomplete implementation when new product fields (featured, newArrival) were added to the system without updating the corresponding data converter mappings.

The issue affects both:

  1. Direct product export operations
  2. Template generation for import operations

Related Information

  • Similar field mapping patterns exist in other DataConverter classes (e.g., CustomerDataConverter, OrderDataConverter) which handle their fields correctly
  • The issue may also affect other entities if they follow similar patterns

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions