Answers.Body: <p>I got a solution. 
  You can't overwrite array elements at this point, but the whole array. I also found it better to use the event "commerce_cart.onBeforeAddToCart".
  My working code is now:</p>
  
  <pre><code>craft()-&gt;on('commerce_cart.onBeforeAddToCart', function($event) {
      $imageId = craft()-&gt;ultraschall-&gt;uploadCustomerImage(); // add image to asset folder
      if(isset($imageId) &amp;&amp; is_numeric($imageId)){
          $lineItem = $event-&gt;params['lineItem'];
          $options = $lineItem-&gt;options;
          $options['image'] = $imageId;
          $lineItem-&gt;options = $options;
      }
  });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-12T08:08:50.993Z
Answers.LastActivityDate: 2017-04-12T08:08:50.993Z
Answers.UserDisplayName: phaetons
Body: <p>Our Shop-Customers should upload an image per Item they add to the basket. I managed to upload the image and insert it to an asset folder.</p>
  
  <p>How can i assign the image to the lineItem (maybe as an option)?</p>
  
  <p>This didn't work, as options is not writable:</p>
  
  <pre><code>craft()-&gt;on('commerce_lineItems.onBeforeSaveLineItem', function($event){
      $imageId = craft()-&gt;ultraschall-&gt;uploadCustomerImage(); // add image to asset folder
      if(isset($imageId) &amp;&amp; is_numeric($imageId)){
          $lineItem = $event-&gt;params['lineItem'];
          $lineItem-&gt;options['imageId'] = $imageId;
      } 
  });
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-06T00:30:54.683Z
Comments.Text: To be honest I'd have expected that to work, but you could perhaps instead save the asset id to the note field if you're not using that for something else.  Hacky though.  What error do you actually get?
Comments.UserDisplayName: Jeremy Daalder
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-06T08:01:20.057Z
Comments.Text: I get following error: "Indirect modification of overloaded property Craft\Commerce_LineItemModel::$options has no effect", regardless if the option field exists in the form or not.
Comments.UserDisplayName: phaetons
Tags: <plugin-development><plugin-craftcommerce>
Title: Assigning Image to lineItem?
ThreadText: # Assigning Image to lineItem?
  
  (Asked by: username_0 on 2017-04-05)
  
  Our Shop-Customers should upload an image per Item they add to the basket. I managed to upload the image and insert it to an asset folder.
  
  How can i assign the image to the lineItem (maybe as an option)?
  
  This didn't work, as options is not writable:
  
  ```
  craft()->on('commerce_lineItems.onBeforeSaveLineItem', function($event){
      $imageId = craft()->ultraschall->uploadCustomerImage(); // add image to asset folder
      if(isset($imageId) && is_numeric($imageId)){
          $lineItem = $event->params['lineItem'];
          $lineItem->options['imageId'] = $imageId;
      } 
  });
  
  ```
  
  **Tags:** plugin-development, plugin-craftcommerce
  
  > **Comments:**
  > **username_1**: To be honest I'd have expected that to work, but you could perhaps instead save the asset id to the note field if you're not using that for something else.  Hacky though.  What error do you actually get?  
  > **username_0**: I get following error: "Indirect modification of overloaded property Craft\Commerce_LineItemModel::$options has no effect", regardless if the option field exists in the form or not.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-04-12. Score: 1 | Accepted answer
  
  I got a solution.
  You can't overwrite array elements at this point, but the whole array. I also found it better to use the event "commerce\_cart.onBeforeAddToCart".
  My working code is now:
  
  ```
  craft()->on('commerce_cart.onBeforeAddToCart', function($event) {
      $imageId = craft()->ultraschall->uploadCustomerImage(); // add image to asset folder
      if(isset($imageId) && is_numeric($imageId)){
          $lineItem = $event->params['lineItem'];
          $options = $lineItem->options;
          $options['image'] = $imageId;
          $lineItem->options = $options;
      }
  });
  
  ```
  
  
  ---
  
  