Shopware Product Export via CLI

Using the product-export:generate command, you can generate single or multiple product exports in Shopware, for example, for Google Shopping.



Command Syntax

The following syntax is available in Shopware:

bin/console product-export:generate <storefront-sales-channel-id> (<export-id>) (--force) (--include-inactive)


Parameter Required Description
storefront-sales-channel-id Yes The Storefront Sales Channel ID of the respective sales channel
export-id No The exact ID of the export
—force No Forces regeneration
—include-inactive No Also performs the generation for inactive product exports



Execution Types

Exports can be generated either via the Shopware Message Queue or synchronously via the CLI command.


Execution via the Message Queue (Asynchronous)

To use the Shopware Message Queue, the generate via scheduler option must be enabled. Otherwise, the export is generated synchronously via the CLI command.


Execution via the CLI Command (Synchronous)

To execute the process synchronously via the CLI command, the generate via scheduler option must be disabled. Otherwise, the export is generated asynchronously via the message queue.




Determining the Correct Parameters

Unfortunately, Shopware does not provide the storefront-sales-channel-id or the id of the export in the Shopware administration interface. For this reason, the parameters must be determined via the database.


The Shopware database can be accessed in the following ways, among others:

  • phpMyAdmin
  • Adminer
  • Direct MySQL connection


To do this, open the product_export table and determine the desired parameters based on the database columns:

  • id
  • storefront_sales_channel_id


Use the parameters you’ve determined to construct the CLI command. You’ll find the correct syntax at the beginning of this article.



Sample Script

You can use the following sample script to generate all exports for a specific sales channel. To do this, create a new file in your store’s document root directory.

Example:

touch /var/www/creoline-demo.com/product-exports.sh
#!/bin/bash

echo "[$(date '+%d/%m/%Y %H:%M:%S')] Generating Exports for Sales Channel #1"
/usr/bin/php -d memory_limit=-1 /var/www/creoline-demo.com/bin/console product-export:generate 082...5c00 --force
echo "[$(date '+%d/%m/%Y %H:%M:%S')] [DONE] Sales Channel #1"

echo "[$(date '+%d/%m/%Y %H:%M:%S')] Generating Exports for Sales Channel #2"
/usr/bin/php -d memory_limit=-1 /var/www/creoline-demo.com/bin/console product-export:generate 082...5c00 --force
echo "[$(date '+%d/%m/%Y %H:%M:%S')] [DONE] Sales Channel #2"


The script then requires execute permissions:

chmod +x /var/www/creoline-demo.com/product-exports.sh


The script can then be run using the following command:

/var/www/creoline-demo.com/product-exports.sh


If you want to run the script automatically, you can either create a cron job via our Customer Center or schedule it using crontab.


crontab -e

# Generate product exports every day at 00:00 
0 0 * * * /var/www/creoline-demo.com/product-exports.sh