Hi, I've been struggling with this stuff (I'm new to entities) for like 6 hours now. A little help would go a long way.

Since there's some issue where I can't specify the fields from an eck entity in rules when I make a new entity, I resorted to creaking the entity via php. I finally figured out how to properly create an entity:

$values = array('uid' => 1, 'field_receipt_prod_ref' => 1, 'type' => 'receipt');
$new_ent = entity_create('receipt', $values)->save();

as you can see I have field_receipt_prod_ref, that part isn't saving and is what I'm trying to figure out, it's a product reference field from commerce. How can I save the value of that field into the entity as if I created it through the form? Thanks so so much in advance.

Comments

antoniotorres’s picture

Found the answer, here it is

$new_ent = entity_create('receipt', array(
  'uid' => $uid,
  'type' => 'receipt', //bundle
  'field_receipt_prod_ref' => array(      
    LANGUAGE_NONE => array(
      0 => array(
        'product_id' => $product_id,
      ),
    ),
  ),
))->save();
antoniotorres’s picture

Status: Active » Closed (works as designed)