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
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="import-csv-to-product-extensions">
<from uri="file:{{import.px.directory}}?{{archive.file}}&{{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&mapper=import-product-extensions.mapper&businessKeys=sku"/>
</split>
<log message="Product extension import complete. Total records: ${header.PfxTotalInputRecordsCount}" loggingLevel="INFO"/>
</route>
</routes>
mappers/import-product-extensions.mapper.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
-
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. -
Splitting: The file is split into batches of 10,000 lines using
tokenize token=" " group="10000"for memory-efficient streaming. -
CSV Unmarshalling:
pfx-csv:unmarshalparses the CSV data. TheskipHeaderRecord=trueoption uses the first row as column headers. -
Loading to Pricefx:
pfx-api:loaddatasends data to Pricefx withobjectType=PXtargeting 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 (attribute1throughattribute10). -
Business Key: The
businessKeys=skuparameter 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 anIllegalStateException. There is noextensionNameURI 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
attribute1throughattribute30. 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.