Last Updated 3 months ago

Feeder — how to connect a custom data source (custom table / PHP method) to an export field?

The Feeder module supports a programmable mechanism that calls any PHP method for each product and uses the return value as the field value in the XML output. It requires no modifications to the module and is upgrade-safe.

Field configuration in Feeder:
- Source: Custom value
- Custom value: programmable.ClassName.methodName
- Path: target XML path, e.g. g:description

---

Class and method requirements:

The method can be static or non-static — Feeder detects this automatically via PHP Reflection. For a non-static method the class must have a no-argument constructor.

Signature:

public static function methodName(array $productData): string


The $productData argument contains:

[
    'product'          => $product,       // Product object; available: ->id, ->id_lang, ->id_shop
    'manufacturer'     => $manufacturer,  // Manufacturer object
    'default_category' => $category,      // Category object
    'combination'      => $combination,   // only for variants; id_product_attribute = $combination->id
]


The method should return a string (or an array of strings for multi-value fields). Feeder automatically applies htmlspecialchars() to the returned value — if the value contains HTML, enable the CDATA option in the export field configuration.

---

Where to place the class:

The classes/ directory of your own module — PrestaShop automatically registers classes from that directory in the autoloader after module installation:

modules/mymodule/classes/ClassName.php


The class should have a globally unique name. Namespaces are supported using backslashes: programmable.MyShop\ClassName.method.

---

Example — custom table with a Google Merchant Center description:

<?php
class GmcFeedSource
{
    public static function getDescription(array $productData): string
    {
        $product   = $productData['product'];
        $idProduct = (int) $product->id;
        $idLang    = (int) $product->id_lang;

        $row = Db::getInstance()->getRow('
            SELECT description
            FROM `' . _DB_PREFIX_ . 'gmc_product_lang`
            WHERE id_product = ' . $idProduct . '
              AND id_lang = '    . $idLang
        );

        if ($row && !empty($row['description'])) {
            return $row['description'];
        }

        // fallback to standard short description
        return strip_tags($product->description_short);
    }
}


In Feeder: Custom value = programmable.GmcFeedSource.getDescription

Please Wait!

Please wait... it will take a second!

Kliknij by skopiować