# Products

## Usage

To convert a `POST_PRODUCT_DATA` feed to the newer `JSON_LISTINGS_FEED` format:

```php
use SellingPartnerApi\FeedTransformer\Transformer;
use SellingPartnerApi\FeedTransformer\FeedTypes\Product;

$feedPath = 'path/to/feed.xml';
$json = Transformer::fromFile(
    Product::$feedType,
    $feedPath,
    'ATVPDKIKX0DER',  // -> US Selling Partner API marketplace ID
    [ /* options */ ]
);

$jsonFeedPath = 'path/to/new/feed.json';
file_put_contents($jsonFeedPath, json_encode($json));
```

***The first time using this feed transformer with a particular product type, we strongly recommend running the converted data through*** [***our validators***](https://docs.highsidelabs.co/feed-transformer/validation) ***before putting it into production.*** That way, you can ensure you know if certain elements of your XML feed aren't able to be mapped to the new format.

## Product variants

If you send variation data via the `POST_PRODUCT_DATA` feed and then use a `POST_PRODUCT_RELATIONSHIP_DATA` feed to set parent/child SKUs, please note that it's currently not possible to set any variation data other than the variation theme via the `JSON_LISTINGS_FEED`. If you have the `<Parentage>` tag in your product feeds, they will be skipped, so please use the `POST_PRODUCT_RELATIONSHIP_DATA` feed type/converter to specify parent/child product relationships.

## Parameters

### `productType`

{% hint style="danger" %}
**Required**
{% endhint %}

This must be a valid Amazon product type, corresponding to the product type that you're defining relationships between in the feed. It cannot be the base product type, `PRODUCT`.

### `shippingGroupMap`

{% hint style="warning" %}
Required if the `MerchantShippingGroupName` tag is present in the feed file being converted.
{% endhint %}

This is a mapping of your account's shipping group names to their internal Amazon identifiers. Instructions on how to generate this mapping are here: [#shippinggroupmap](https://docs.highsidelabs.co/feed-transformer/tab/invloader#shippinggroupmap "mention")

### `onUnsupportedField`

{% hint style="info" %}
Optional. Default `fail`.
{% endhint %}

This option controls what happens when the feed transformer encounters an XML tag that has no direct equivalent in the new JSON format. There are two accepted values:

* `ignore`: Silently move past un-mappable XML tags.
* `callback`: Pass un-mappable XML fields (by [xpath](https://developer.mozilla.org/en-US/docs/Web/XPath)) to a user-defined callback. See [#callback](#callback "mention")
* `fail`: The first time an un-mappable XML tag is encountered, throw an `InvalidFeedException` . This is the default.

### `callback`

{% hint style="info" %}
Conditionally required if `onSupportedField` is set to `callback` .
{% endhint %}

This option is the callback to be called if `onSupportedField` is set to `callback` and an un-mappable XML field is encountered while processing the input data. The callback's signature is `fn (string): void`. For example:

```php
$options = [
    'onUnsupportedField' => 'callback',
    'callback' => function ($field) {
        echo "Unsupported field: $field";
        // -> Unsupported field: Message/Product/DescriptionData/UnsupportedField
    },
    // ...
];
```
