1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Migrations for WEM Commerce Product Nodes Translations. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
class DFSWEMCommerceNodesTranslations extends DemoFrameworkBaseCommerceNodes { |
9
|
|
|
|
10
|
|
|
public function __construct($arguments) { |
11
|
|
|
parent::__construct($arguments); |
12
|
|
|
$this->map = new MigrateSQLMap($this->machineName, |
13
|
|
|
array( |
14
|
|
|
'translated_title' => array( |
15
|
|
|
'type' => 'varchar', |
16
|
|
|
'length' => 255, |
17
|
|
|
'not null' => TRUE, |
18
|
|
|
), |
19
|
|
|
), |
20
|
|
|
MigrateDestinationNode::getKeySchema() |
21
|
|
|
); |
22
|
|
|
$this->description = t('Import translated WEM Commerce product nodes.'); |
23
|
|
|
$this->dependencies = array('DFSWEMProducts'); |
24
|
|
|
$import_path = drupal_get_path('module', 'dfs_wem') . '/import/'; |
25
|
|
|
$this->source = new MigrateSourceCSV($import_path . 'dfs_wem.nodes.wem_commerce.translations.csv', $this->csvcolumns(), array('header_rows' => 1)); |
26
|
|
|
$this->destination = new MigrateDestinationNode('wem_commerce'); |
27
|
|
|
// Commerce |
28
|
|
|
$this->addFieldMapping('field_wem_product_ref', 'skus'); |
29
|
|
|
$this->addFieldMapping('field_wem_com_rel_interests', 'interests'); |
30
|
|
|
// Workbench |
31
|
|
|
$this->addFieldMapping('workbench_moderation_state_new', 'workbench_moderation_state_new')->defaultValue('published'); |
32
|
|
|
// Translations |
33
|
|
|
$this->addFieldMapping('title', 'translated_title'); |
34
|
|
|
$this->addFieldMapping('tnid', 'title')->sourceMigration('DFSWEMCommerceNodes'); |
35
|
|
|
// UUID |
36
|
|
|
$this->addFieldMapping('uuid', 'uuid'); |
37
|
|
|
// Created |
38
|
|
|
$this->addFieldMapping('created', 'created')->defaultValue(strtotime("now")); |
39
|
|
|
// Persona |
40
|
|
|
$this->addFieldMapping('field_persona', 'persona'); |
41
|
|
|
// Site Section |
42
|
|
|
$this->addFieldMapping('field_site_section', 'site_section')->defaultValue("Commerce"); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
View Code Duplication |
function csvcolumns() { |
|
|
|
|
46
|
|
|
$columns[0] = array('title', 'Source Title'); |
|
|
|
|
47
|
|
|
$columns[1] = array('language', 'Language'); |
48
|
|
|
$columns[2] = array('translated_title', 'Title'); |
49
|
|
|
$columns[3] = array('description', 'Description'); |
50
|
|
|
$columns[4] = array('sku', 'SKU'); |
51
|
|
|
$columns[5] = array('interests', 'Interests'); |
52
|
|
|
$columns[6] = array('uuid', 'UUID'); |
53
|
|
|
$columns[7] = array('created', 'Created'); |
54
|
|
|
$columns[8] = array('persona', 'Persona'); |
55
|
|
|
return $columns; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
function prepareRow($row) { |
|
|
|
|
59
|
|
|
$products = array(); |
60
|
|
|
foreach (explode(', ', $row->sku) as $sku) { |
61
|
|
|
$product = commerce_product_load_by_sku($sku); |
62
|
|
|
$products[] = $product->product_id; |
63
|
|
|
} |
64
|
|
|
$row->skus = $products; |
65
|
|
|
$row->interests = explode(", ", $row->interests); |
66
|
|
|
return TRUE; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
function prepare(&$node, $row) { |
|
|
|
|
70
|
|
|
if (isset($node->tnid) && ($source = node_load($node->tnid))) { |
71
|
|
|
$node->translation_source = $source; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.