Possible configuration types
|
As configuration snippets
The import:products
command uses and executes
only the operations specified by the given shortcut,
e.g., add-update
.
The command-line options can specify the database configuration.
- It is necessary to provide a custom configuration snippet that enables the flags and containing the paths to the image files:
This custom snippet requires the JSON format and can be named with any name, e.g., images.json
, and must get
placed in the predefined custom location.
Example
<custom-configuration-dir>/params.json
, which contains values as follows:{
"params": {
"my-website-country-mapping": { (1)
"DE": [ "de_DE", "de_AT", "de_CH" ],
"EN": [ "en_US", "en_UK" ]
}
}
}
1 | Defining the custom option my-website-country-mapping |
observer
such as:<?php
namespace My\Project;
use TechDivision\Import\Observers\AbstractObserver;
/**
* A custom observer implementation.
*/
class MyObserver extends AbstractObserver
{
/**
* Return's the global param with the passed name.
*
* @param string $name The name of the param to return
* @param mixed $defaultValue The default value if the param doesn't exist
*
* @return string The requested param
* @throws \Exception Is thrown, if the requested param is not available
*/
public function getGlobalParam($name, $defaultValue = null)
{
return $this->getSubject()->getConfiguration()->getConfiguration()->getParam($name, $defaultValue);
}
/**
* Will be invoked by the action on the events the listener has been registered.
*
* @param \TechDivision\Import\Subjects\SubjectInterface $subject The subject instance
*
* @return array The modified row
*/
public function handle(SubjectInterface $subject)
{
// load the params from the configuration
$myWebsiteMapping = $this->getGlobalParam('my-website-country-mapping'); (1)
// do something with the configuration value
}
}
1 | The custom option my-website-country-mapping gets called in a observer method |
As command-line option
In addition to the parameters defined in the configuration file, it is possible to specify parameters via the command line as an option as well.
my-website-country-mapping
bin/import-cli-simple.phar import:products \ (1)
--params='{ "params": { "my-website-country-mapping": { "DE": [ "de_LI" ] } } }' (2)
1 | Add additional --params to the CLI command import:products |
2 | set the configuration option my-website-country-mapping with predefined values |
As file based defined option
It is possible to refer to a separate configuration file containing JSON encoded parameters by specifying a path.
|
- The file must follow the following format:
{
"params": {
"my-website-country-mapping": {
"DE": [ "de_LI" ]
}
}
}