Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends on the purpose of your customization. Order Item has custom options stored as serialized array and at any time it is possible for your to modify it.</p> <p>Unlike quote item, in order item it has different name for retrieving them. The method is called <code>getProductOptions()</code></p> <p>Also there is another method that allows you to set them <code>setProductOptions(array $options)</code>.</p> <p>Here is some examples of this method usage in different test cases:</p> <ol> <li><p>If you need to store it only for internal code usage, you can just add option into array array and set it back:</p> <pre><code>$existentOptions = $orderItem-&gt;getProductOptions(); $existentOptions['your_custom_option'] = $yourCustomValue; $orderItem-&gt;setProductOptions($existentOptions); </code></pre></li> <li><p>If you need to show your custom option in the printed document, you need to add your custom option into special option of options, that have structure for showing up its value on the frontend, pdf documents, items list</p> <pre><code>$existentOptions = $orderItem-&gt;getProductOptions(); if (!isset($existentOptions['additional_options'])) { // If special options of options array is set before, create it. $existentOptions['additional_options'] = array(); } // Adding visible options value $existentOptions['additional_options'][] = array( 'label' =&gt; 'Your Option Label', 'value' =&gt; 'Your Option Value', // The last one that is optional (if not set, value is used) 'print_value' =&gt; 'Your Option Value shown in printed documents' ); $orderItem-&gt;setProductOptions($existentOptions); </code></pre></li> </ol> <p>Both of these methods even can be combined, if you need one option that is visible to customer and another option that is required for your code.</p> <p>Also don't forget to save your order/order item after you deed your modifications. </p> <p><strong>Advice</strong></p> <p>If you save order and haven't modified the order model itself, you need at least change some data in it, to force order model save all sub entities. For making this possible, you even can just set some non existent attribute.</p> <p>Case when save operation will not be invoked:</p> <pre><code>$order-&gt;load($id); $orderItem-&gt;getItemById($itemId); $orderItem-&gt;setSomething(111); $order-&gt;save(); // Order Item will not be saved!! </code></pre> <p>Case when save operation will be invoked:</p> <pre><code>$order-&gt;load($id); $orderItem-&gt;getItemById($itemId); $orderItem-&gt;setSomething(111); $order-&gt;setSomeNonExistentProperty(true); $order-&gt;save(); // Now it will be saved </code></pre> <p><strong>Have fun with Magento development</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload