-
-
Save rsanchez/054aa0970de0410a3e43 to your computer and use it in GitHub Desktop.
convert CT1 price modifiers to CT2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fieldtypes = array( | |
'ct_price_mod' => 'cartthrob_price_modifiers', | |
'ct_coupon' => 'cartthrob_discount', | |
'ct_items' => 'cartthrob_order_items', | |
'ct_matrix_pq' => 'cartthrob_price_quantity_thresholds', | |
); | |
foreach ($fieldtypes as $field_type => $new_field_type) | |
{ | |
//get fields that match this old field type | |
$fields = get_instance()->db->select('field_id') | |
->where('field_type', $field_type) | |
->get('channel_fields') | |
->result(); | |
foreach ($fields as $field) | |
{ | |
$field_data = NULL; | |
//get the entries with field data for this field id | |
$entries = get_instance()->db->select('entry_id, field_id_'.$field->field_id) | |
->where('field_id_'.$field->field_id.' !=', '') | |
->get('channel_data') | |
->result(); | |
foreach ($entries as $entry) | |
{ | |
if ($field_type === 'ct_items') | |
{ | |
$data = @unserialize($entry->{'field_id_'.$field->field_id}); | |
if (is_array($data)) | |
{ | |
foreach ($data as $row_id => $row) | |
{ | |
$insert = array( | |
'order_id' => $entry->entry_id, | |
'row_order' => $row_id, | |
); | |
foreach (array('entry_id', 'title', 'quantity', 'price') as $key) | |
{ | |
$insert[$key] = (isset($row[$key])) ? $row[$key] : ''; | |
unset($row[$key]); | |
} | |
$insert['extra'] = (count($row) > 0) ? base64_encode(serialize($row)) : ''; | |
get_instance()->db->insert('cartthrob_order_items', $insert); | |
} | |
$field_data = 1; | |
} | |
} | |
else if ($field_type === 'ct_price_mod') | |
{ | |
$data = @unserialize($entry->{'field_id_'.$field->field_id}); | |
if (is_array($data)) | |
{ | |
foreach ($data as &$row) | |
{ | |
if (isset($row['option'])) | |
{ | |
$row = array_merge(array('option_value' => $row['option']), $row); | |
unset($row['option']); | |
} | |
} | |
$field_data = base64_encode(serialize($data)); | |
} | |
} | |
else | |
{ | |
$field_data = base64_encode($entry->{'field_id_'.$field->field_id}); | |
} | |
if ( ! is_null($field_data)) | |
{ | |
get_instance()->db->update( | |
'channel_data', | |
array('field_id_'.$field->field_id => $field_data), | |
array('entry_id' => $entry->entry_id) | |
); | |
} | |
} | |
} | |
get_instance()->db->update('channel_fields', array('field_type' => $new_field_type), array('field_type' => $field_type)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment