Discussions

Populate line item field in code

I seem to be stuck on something that should be easy. I have added a new field to the base line item type of 'product' that is an entity reference to a user account. This is for registering a user for a conference. The user will have an online account. I use the code below to add the attendee to the cart but cannot figure out how to populate the entity reference field I added.

        $product = commerce_product_load_by_sku('myconference');
        $line_item = commerce_product_line_item_new($product, 1);
        commerce_cart_product_add($user->uid, $line_item, false);

Any help is greatly appreciated!

Posted: Jul 3, 2012
drupalcommerce Check out the #Drupal Commerce 2.x Roadmap to see where you can get involved: http://t.co/WAc3jmXY2a
drupalcommerce A new blog discussing the new showcase listing http://t.co/FHOzhAg3tl http://t.co/J5C87imjhb
drupalcommerce RT @drupalcon: Thanks @CommerceGuys and @CommerceJohn for your support, and for #CommerceKickstart! Take the tour http://t.co/ivKEYH7k0o
drupalcommerce Updating our extensions directory: 665 new or updated modules, distributions, sandboxes, & themes. http://t.co/6NMMofYo12 #weloveyouguys