New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export in different rows OneToMany, mTm or localized fields #133
Comments
First you need to extract the data in the different languages. There are 2 ways do do that:
To achieve a CSV output like you want it
$separator = {{ CSV separator }} ?: ';';
if({{ CSV ENCODING }}) {
$separator = iconv('UTF-8', {{ CSV ENCODING }}, $separator);
}
if(!$params['response']->hasContent()) {
$params['response']->headers->set('Content-Type', 'text/csv');
$result = '';
if(!{{ CSV ENCODING }} || strtolower({{ CSV ENCODING }}) === 'utf-8') {
$result .= "\xEF\xBB\xBF";
}
$result .= '"productId", "language", "name"'."\n";
} else {
$result = '';
}
$decodeValue = function($value) use ($params) {
if(!is_scalar($value)) {
if(is_array($value) && is_scalar(reset($value))) {
$value = implode(', ', $value);
} else {
$value = json_encode($value, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
}
}
if({{ CSV ENCODING }}) {
$value = iconv('UTF-8', {{ CSV ENCODING }}, $value);
}
return '"'.str_replace('"', '""', $value).'"';
};
if($params['rawItemData']) {
foreach({{ name#all }} as $language => $name) {
$line = [];
$line[] = $decodeValue({{ id }});
$line[] = $decodeValue($language);
$line[] = $decodeValue($name);
$result .= implode($separator, $line)."\n";
}
}
$params['response']->addContent($result);
productId, categoryId, productName, categoryName This works the same as above for the languages but this time you have to select Next time, please be so fair and write such project-specific questions to help@blackbit.com |
Hello, I'm attempting to export data using the Data Director bundle, but I'm unsure of how to proceed. Specifically, I aim to export my product names in all available languages, following this structure:
productId, language, name
1, en, hello
1, es, hola
1, de, hallo
...
Additionally, I'm interested in exporting the relationships of my products, such as:
productId, categoryId, productName, categoryName
1, 1, pencil, cat1
1, 2, pencil, cat2
1, 3, pencil, cat3
...
I am aware that I can include this information in the same row and cell, but I am not interested in using this approach. Could you please guide me on how to accomplish this? Or is it not feasible with the Data Director bundle?
The text was updated successfully, but these errors were encountered: