Re: Re: Re: Yes actually,

Posts: 50
Joined: 08/08/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik

CpILL your module worked great after I made some additions and one change to the module.

Had to add some form of "input control" on the data in the CSV file.
Changed this line:
$row[$form_values['column_'.$i]] = $csv_row[$i];
To this:
$row[$form_values['column_'.$i]] = str_replace('&', '&',$csv_row[$i]);

Added these functions (based heavily on your product attributes functions):

/**
* Implements hook_uc_import_csv_fields_list()
*
* returns an array of the fields available for the selected product class
*/
function content_uc_import_csv_fields_list($values) {
    if(!empty($values['class'])) {
        $fields = content_fields(null,$values['class']);
        if(count($fields)) {
            $fields = array_keys($fields);
            sort($fields);
            $field_names = array();
            foreach($fields as $field) {
                $field_name['cck_'.$field] = $field;
            }
            return array('CCK fields' => $field_name);
        }
    }
}


/**
* Implements hook_uc_import_csv_row()
*
* Adds the cck values to the xml object
*/
function content_uc_import_csv_row($product_xml, $data, $store_xml) {
    // Processing for each property individually
    $attribute_count = 0;
    foreach($data as $property => $value) {
        // Firstly: Is it one of ours? ...if it begins with 'cck_'
        if(!empty($value) && substr($property,0,4) == 'cck_') {
            $name = substr($property,4);
            if(!isset($product_xml->fields)) {
                $product_xml->addChild('fields');
            }
            $field = $product_xml->fields->addchild('field');
            $field->addchild('name',$name);
            $delta = $field->addchild('delta');
            $delta->addchild('value',$value);
        }
    }
}

Probably a lot of things which are not taken proper care of XML-wise, but it works (for us anyway) Smiling

We can now import csv-files (generated by NeoOffice) into custom product classes (with around 30 fields) in UberCart.

--

Erlend Strømsvik
Ny Media AS
erlend@nymedia.no

CSV Import 0.1 Alpha By: CpILL (52 replies) Mon, 09/24/2007 - 13:16