Jump to content

Importer script can't integrate MapMarker field input


hellomoto
 Share

Recommended Posts

I have an importer function that goes like this so far

function importCSV($filepath, $template, $parent_id = null, $grandparent_id = null) {
  $csv = array_map('str_getcsv', file($filepath));
  array_walk($csv, function(&$a) use ($csv) {
    $a = array_combine($csv[0], $a); # set header keys
  });
  array_shift($csv); # remove column header
  //echo '<pre>'; print_r($csv); echo '</pre>';
  foreach($csv as $r) {
    $p = new Page();
    $p->name = wire('sanitizer')->pageName($r['title']);
    $p->template = $template;
    if($parent_id !== 0||null) {
      $p->parent_id = $parent_id;
    } elseif($parent_id == 0||null) {
      //echo $r['parent'].' ';
      $parent = wire('sanitizer')->pageName($r['parent']);
      $parent = str_replace('---','-',$parent);
      //echo $parent.' ';//echo $grandparent_id.'gp ';
      $parent = wire('pages')->get('title=' . $r['parent'] . ', parent_id=' . $grandparent_id)->id;
      //echo $parent.'p ';
      $p->parent_id = $parent;
      unset($r['parent']);
    }
    $p->save();

	var_dump($r);

    foreach($r as $k=>$v) {
      $fieldtype = wire('fields')->get('name='.$k)->type;
      echo $fieldtype.' ';
      if($fieldtype->name == 'FieldtypeImage') {
        $imgs = explode('|', $v);
        foreach($imgs as $i) {
          $p->$k = $i;
        }
      }
      elseif($fieldtype->name == 'FieldtypeMapMarker') {
        echo 'mapmarker';
        $p->set($k->address, $v);
      }
      else $p->$k = $v;
    }
    $p->save(); echo '<br><br>';
  }
}

It reads the field as being a MapMarker but does not input the address data?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...