Jump to content
Sign in to follow this  

Importer script can't integrate MapMarker field input

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;


    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>';

Here is a sample row output:


array(17) { ["title"]=> string(7) "Zylkene" ["boat_manufacturer"]=> string(6) "Lagoon" ["boat_model"]=> string(13) "Lagoon 560 S2" ["boat_condition"]=> string(8) "Preowned" ["boat_date_list"]=> string(0) "" ["boat_status"]=> string(8) "For Sale" ["boat_date_sale"]=> string(0) "" ["boat_yr_build"]=> string(0) "" ["boat_yr_model"]=> string(0) "" ["boat_layout"]=> string(0) "" ["boat_price_list"]=> string(6) "950000" ["boat_currency"]=> string(3) "EUR" ["boat_price_onapp"]=> string(0) "" ["boat_location"]=> string(20) "Le Marin, Martinique" ["boat_images"]=> string(0) "" ["boat_video"]=> string(0) "" ["boat_panorama"]=> string(0) "" } FieldtypePageTitleLanguage FieldtypePage FieldtypePage FieldtypePage FieldtypeDatetime FieldtypePage FieldtypeDatetime FieldtypeText FieldtypeText FieldtypePage FieldtypeInteger FieldtypePage FieldtypeCheckbox FieldtypeMapMarker mapmarkerFieldtypeImage FieldtypeURL 

So it reads the field as being a MapMarker but does not input the address data as it's set to. Any clue as to why?

Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Vineet Sawant
      I'm trying to import some heavy data into Processwire, but I'm not sure what would be the best way to do it.
      Usually I use CSV to Pages plugin, but this time the data is too heavy(~40k rows with 10+ columns of excel sheet), thus this plugin can't help.
      I also tried Tasker plugin but I can't seem to go through the setup itself, it requires some template setup but I'm totally clueless about how to do it, so that plugin is not of any use either.
      I wanted to know from you guys how you do it and in future what would be the best way to migrate thousands of rows of data in to PW.
    • By Rodd
      Hi everyone!
      I have a website in a production environment and I want to duplicate it in a local environment. I exported the content of the website (with the 'Site Profile Exporter' module) but I cannot use it actually. I've got an issue with the database. I imported this one in MAMP then.

      I also exported the pages (with the 'ProcessPagesExportImport' module), but I cannot import it to my local website because the fields don't exist. So I created this fields, but I have this error :
      How can I use the elements that already exist and are presents in my database? How can I duplicate correctly the templates, fields and pages?
      Thanks by advance
      PS: Sorry if my english is bad
    • By hellerdruck
      Hi all
      I need help with something. Situation: We have let's say 2'000 Files (Excel) that should be displayed (list with links) on a page. We'd need to filter these files by given Keywords or a tree structure or both. Now, I'm looking for a solution whereas our customer can synchronise the files from his local computer with the folder on the webserver. They will update and upload files on a daily basis. Therefore, it would need to synchronise rather than load the files manually in pages or repeaters. Maybe indexing would be an idea, too.
      Are there any modules for Processwire that would help achieving this? Could anyone point me in the right direction?
      Thanks in advance.
    • By iNoize
      Hello, need some help for an RealEstate project. It have to use the OnOffice to import the objects. 
  • Create New...