Example #1
0
 function insert_cabinet_to_drupal($cabinet_id)
 {
     // set HTTP_HOST or drupal will refuse to bootstrap
     $_SERVER['HTTP_HOST'] = 'zl-apps';
     $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
     include_once DRUPAL_ROOT . '/includes/bootstrap.inc';
     drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
     $cabinet = new Cabinet();
     $cabinet_detail = $cabinet->read(null, $cabinet_id);
     $cabinet_nid = null;
     $query = new EntityFieldQuery();
     $entities = $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'cabinet')->propertyCondition('status', 1)->fieldCondition('field_cabinet_id', 'value', $cabinet_detail['Cabinet']['id'], '=')->execute();
     if (!empty($entities)) {
         foreach ($entities['node'] as $nid => $value) {
             $cabinet_nid = $nid;
             break;
             // no need to loop more even if there is multiple (it is supposed to be unique
         }
     }
     $node = null;
     if (is_null($cabinet_nid)) {
         $node = new stdClass();
         $node->language = LANGUAGE_NONE;
     } else {
         $node = node_load($cabinet_nid);
     }
     $node->type = 'cabinet';
     node_object_prepare($node);
     $node->title = $cabinet_detail['Cabinet']['name'];
     $node->field_cabinet_id[$node->language][0]['value'] = $cabinet_detail['Cabinet']['id'];
     $node->field_product_type_id[$node->language][0]['value'] = $cabinet_detail['Cabinet']['product_type'];
     $node->sell_price = 0;
     $node->model = $cabinet_detail['Cabinet']['name'];
     $node->shippable = 1;
     $path = 'cabinet/' . $node->title;
     $node->path = array('alias' => $path);
     node_save($node);
 }