CartProductFeed API: Feed Generation Part 1 – PAttributeDefault

Get ExportFeed Now

Data leaves the Content Management System and enters a feed in a controlled process. There are four points where your custom modifier can hook the feed generation process. This post discusses the first of those four points and the differences.

FeedGenPartOne

PAttributeDefault is the first hook. It occurs when the product streams out from the database but before any attributes are applied. At this time, only two properties are known for certain: id and title. Some attributes exist already, such as valid.

Attributes set here will be overwritten by any content found in the database. This is the ideal place to set a default brand: the chosen value will be replaced by the brand of the product if a brand has been set. If no brand has been set, the default value will be retained.

A simple example:

FeedGenE1

Mapped via Advanced Commands:

setAttributeDefault my_color as none PRandomColor

mapAttribute my_color as g:color

 

Note: Attribute names are case-sensitive. The name of the attribute, if you want it to appear in the feed, will be automatically translated by the attribute mapping engine later on. So the name of the attribute is irrelevant to the final result.

Note: It is possible to set other attributes at the same time

eg: $this->attribute[‘title’] = ‘test’;

Note: setting a default attribute does NOT mean it it mapped into the feed automatically (hence the two-step process). The reason for this is most default attributes will influence other attributes (for example has_sale_price or valid). Other custom modifiers change attributes that are already mapped.