Advertisement:

Author Topic: Add item by php code (photo link and custom field)  (Read 53009 times)

tobaccowebdesign

  • Newbie
  • *
  • Posts: 8
Add item by php code (photo link and custom field)
« on: July 19, 2012, 08:14:38 pm »
Hi developers,

I have a problem with insert item by php function, i already made this at the bottom, but i don't know how can i add the photos (i have link to image external or local) and a custom field (string)...

please help me i am a new user of this forum and osclass  ;D

many thanks

Davide

tobaccowebdesign

  • Newbie
  • *
  • Posts: 8
Re: Add item by php code (photo link and custom field)
« Reply #1 on: July 22, 2012, 05:03:26 pm »
HI i work on a plugin that insert post automatically, i made this:

   $mItems = new ItemActions(false);       
      $your_item = array();
      
      $tit = array();
      $tit['it_IT'] = $title;
      $your_item['title'] = $tit;
      
      $desc = array();
      $desc['it_IT'] = $description;
      $your_item['description'] = $desc;
      
      $your_item['contactName'] = $autor;
      $your_item['contactEmail'] = $post_autor;
      $your_item['active'] = 'ACTIVE';
      $your_item['catId'] = $category;
      $your_item['countryId'] = 'IT';
      $your_item['regionId'] = getRegionIDbyName($region, $your_item['countryId']);
      $your_item['cityId'] = getCityIDbyName($complete_province, $your_item['regionId']); 
      $your_item['cityArea'] = $city;
      $your_item['address'] = null;
      $your_item['showEmail'] = 0;
      $your_item['countryName'] = $nation;
      $your_item['regionName'] = $region;
      $your_item['cityName'] = $complete_province;
      $your_item['price'] = $price;
      $your_item['meta_ext-link'] = $link;
      
      $photoData = checkAndDownloadImg($image);

      if ( !empty($photoData) && !empty($photoData['folder']) && !empty($photoData['name']) && !empty($photoData['ext']) ){
         //se l immagine esiste
         $name = array();
         $name['name'] = array($photoData['name']);   
         $type = array();
         $type['type'] = array('image/'.$photoData['ext']);   
         $tmp_name = array();
         $tmp_name['tmp_name'] = array($photoData['folder']);
         $error = array();
         $error['error'] = array(0);
         $size = array();
         $size['size'] = array(30397);
         $your_item['photos'] = array($name, $type, $tmp_name, $error, $size);
      }

      $mItems->data = $your_item;
      $mItems->add();