Discussions

Import script & taxonomy terms to product (product_display)

Hi!

Is possible to add the taxonomy terms to product (product_display) with API function?

G.

Posted: May 8, 2012

Comments

makgab on May 8, 2012

It works, for example:

     if ( ... ) {
          echo "\nUpdate...\n";
           $product = new StdClass();
           $product->product_id = $product_q->product_id; // for the modify product
           $product->title = $xml_title;
           $product->sku = $xml_id;
           $product->status = '1';
           $product->revision_timestamp = time();
           $product->type = 'product';
           $product->uid = $user->uid;
           $product->created = time();
           $product->changed = time();
           $product->field_symbol_code[LANGUAGE_NONE][0]['value'] = $xml_code;
           $product->field_productgroups[LANGUAGE_NONE] = array(
                 array('tid' => 5),
                 array('tid' => 12),
                 );
           commerce_product_save($product);
      } else {
           // save new (insert) product
           echo "\nInsert...\n";
           $product = commerce_product_new('product');
           $product->title = $xml_title;
           $product->sku = $xml_id;
           $product->status = '1';
           $product->revision_timestamp = time();
           $product->uid = $user->uid;
           $product->created = time();
           $product->changed = time();
           $product->field_symbol_code[LANGUAGE_NONE][0]['value'] = $xml_code;
           $product->field_productgroups[LANGUAGE_NONE] = array(
                 array('tid' => 5),
                 array('tid' => 12),
                 );
           commerce_product_save($product);
        } // if