public function testSaveCustomFieldsArray() { $my_product_id = 21; $vals = array('Red', 'Blue', 'Green'); $custom_field = array('field_name' => 'Color', 'field_value' => $vals, 'field_type' => 'dropdown', 'content_id' => $my_product_id); //adding a custom field "Color" to product $new_id = save_custom_field($custom_field); $field = get_custom_field_by_id($new_id); $to_delete = array('id' => $new_id); $delete = delete_custom_field($to_delete); $this->assertEquals($field['name'], 'Color'); $this->assertEquals($field['type'], 'dropdown'); $this->assertEquals($field['value'], $vals); $this->assertEquals(intval($delete) > 0, true); }
public function copy($data) { $new_cont_id = false; if (defined('MW_API_CALL')) { $to_trash = true; $adm = $this->app->user_manager->is_admin(); if ($adm == false) { return array('error' => 'You must be admin to copy content!'); } } if (isset($data['id'])) { $this->app->event_manager->trigger('content.before.copy', $data); $cont = get_content_by_id($data['id']); if ($cont != false and isset($cont['id'])) { $new_cont = $cont; if (isset($new_cont['title'])) { $new_cont['title'] = $new_cont['title'] . ' copy'; } $new_cont['id'] = 0; $content_cats = array(); $cats = content_categories($cont['id']); if (!empty($cats)) { foreach ($cats as $cat) { if (isset($cat['id'])) { $content_cats[] = $cat['id']; } } } if (!empty($content_cats)) { $new_cont['categories'] = $content_cats; } $new_cont_id = $this->save($new_cont); $cust_fields = get_custom_fields('content', $data['id'], true); if (!empty($cust_fields)) { foreach ($cust_fields as $cust_field) { $new = $cust_field; $new['id'] = 0; $new['rel_id'] = $new_cont_id; $new_item = save_custom_field($new); } } $images = get_pictures($data['id']); if (!empty($images)) { foreach ($images as $image) { $new = $image; $new['id'] = 0; $new['rel_id'] = $new_cont_id; $new['rel_type'] = 'content'; $new_item = save_media($new); } } } } return $new_cont_id; }