Import CSV to Product Extensions (PX)

Import CSV to Product Extensions (PX)

Overview

This example demonstrates how to import product extension data from a CSV file into Pricefx Product Extensions (object type PX). Product extensions allow you to attach additional typed attribute sets to products. The extension table name is set as a <constant out="name"/> in the mapper.

Files

routes/import-product-extensions.xml

XML
<routes xmlns="http://camel.apache.org/schema/spring">
    <route id="import-csv-to-product-extensions">
        <from uri="file:{{import.px.directory}}?{{archive.file}}&amp;{{read.lock}}"/>
        <log message="Processing product extension file: ${header.CamelFileNameOnly}" loggingLevel="INFO"/>
        <split aggregationStrategy="recordsCountAggregation" streaming="true">
            <tokenize token="
" group="10000"/>
            <to uri="pfx-csv:unmarshal?skipHeaderRecord=true"/>
            <to uri="pfx-api:loaddata?objectType=PX&amp;mapper=import-product-extensions.mapper&amp;businessKeys=sku"/>
        </split>
        <log message="Product extension import complete. Total records: ${header.PfxTotalInputRecordsCount}" loggingLevel="INFO"/>
    </route>
</routes>

mappers/import-product-extensions.mapper.xml

XML
<mappers>
    <loadMapper id="import-product-extensions.mapper">
        <constant expression="Cars" out="name"/>
        <body in="sku" out="sku"/>
        <body in="make" out="attribute1"/>
        <body in="model" out="attribute2"/>
        <body in="year" out="attribute3"/>
        <body in="engineType" out="attribute4"/>
        <body in="horsepower" out="attribute5"/>
        <body in="fuelEfficiency" out="attribute6"/>
        <body in="bodyStyle" out="attribute7"/>
        <body in="driveType" out="attribute8"/>
        <body in="transmission" out="attribute9"/>
        <body in="msrp" out="attribute10"/>
    </loadMapper>
</mappers>

config/application.properties (snippet)

# Import directory for product extension CSV files
import.px.directory=/data/imports/product-extensions

How It Works

  1. File Pickup: The file: component monitors the configured directory for CSV files. {{archive.file}} moves processed files to a timestamped archive; {{read.lock}} waits until the file is fully written before reading.

  2. Splitting: The file is split into batches of 10,000 lines using tokenize token=" " group="10000" for memory-efficient streaming.

  3. CSV Unmarshalling: pfx-csv:unmarshal parses the CSV data. The skipHeaderRecord=true option uses the first row as column headers.

  4. Loading to Pricefx: pfx-api:loaddata sends data to Pricefx with objectType=PX targeting Product Extensions. The extension table name (Cars) is set as <constant expression="Cars" out="name"/> in the mapper. The mapper maps CSV columns to extension attributes (attribute1 through attribute10).

  5. Business Key: The businessKeys=sku parameter links each extension record to its parent product by SKU.

Common Pitfalls

  • Missing <constant out="name"/>: The mapper must include <constant expression="TableName" out="name"/> to set the extension table name. Without it, the import will fail with an IllegalStateException. There is no extensionName URI parameter for PX.

  • Extension table must exist: The Product Extension table (e.g., Cars) must be created in Pricefx Administration before importing data. The import will fail if the table does not exist.

  • SKU must exist in Products: The SKU values in the extension CSV must correspond to existing products. Extension records for non-existent SKUs will be rejected.

  • Attribute numbering: Product Extensions use attribute1 through attribute30. Make sure your mapper targets the correct attribute numbers matching your extension table configuration.

  • Case sensitivity in table name: The table name in the mapper constant is case-sensitive and must exactly match the extension table name in Pricefx.