Commit 36c5927d authored by Aleksey.Alekseev's avatar Aleksey.Alekseev
Browse files

products import part 2

parent df037cb3
......@@ -139,7 +139,7 @@ class SynhelperContentImport {
case 'field_type_service':
case 'field_object_type':
$n[$key] = $this->importAttach($value);
$n[$key] = $this->importTaxonomyField($value);
break;
case 'field_paragraph':
......@@ -228,16 +228,43 @@ class SynhelperContentImport {
* Creates product.
*/
private function createProduct(array $data, array $variations = NULL) {
$product = Product::create([
'uid' => 1,
'type' => $data['type'],
'title' => $data['title'],
'field_image' => $this->importImages($data['field_image']),
'field_gallery' => $this->importImages($data['field_gallery']),
'field_short' => $data['field_short'],
'body' => $data['body'],
'variations' => $variations,
]);
foreach ($data as $key => $value) {
switch ($key) {
case 'field_image':
case 'field_gallery':
$n[$key] = $this->importImages($value);
break;
case 'field_attach':
$n[$key] = $this->importAttach($value);
break;
case 'field_catalog':
$n[$key] = $this->importTaxonomyField($value);
break;
case 'field_tx_options':
foreach ($value as $termName) {
$terms[] = $this->importTaxonomyField($termName);
}
$n[$key] = $terms;
break;
case 'field_paragraph':
$n[$key] = $this->importParagraph($value);
break;
case 'variations':
$n[$key] = $variations;
break;
default:
$n[$key] = $value;
break;
}
}
$n['uid'] = 1;
$product = Product::create($n);
$product->save();
}
......@@ -361,7 +388,7 @@ class SynhelperContentImport {
* Import Paragraph(about && image_blocks).
* If needed more just copy one of them and set your fields.
*/
private function importParagraph($field_paragraph) {
private function importParagraph($field_paragraph) : array {
$storage = \Drupal::service('entity_type.manager')->getStorage('paragraph');
/* Importing About Us */
......@@ -419,6 +446,25 @@ class SynhelperContentImport {
'target_revision_id' => $paragraph->getRevisionId(),
];
}
/* Importing Параметры */
if (!empty($field_paragraph['product_param'])) {
foreach ($field_paragraph['product_param'] as $param) {
$t = [
'uid' => 1,
'type' => $param['type'],
'field_product_param_param' => $param['field_product_param_param'],
'field_product_param_value' => $param['field_product_param_value'],
];
$paragraph = $storage->create($t);
$paragraph->save();
$paragraphs[] = [
'type' => 'product_param',
'target_id' => $paragraph->id(),
'target_revision_id' => $paragraph->getRevisionId(),
];
}
}
return $paragraphs;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment