How To Attach Extra Information To Order Item

Hello everyone,



I want to know how can I attach additional information to product order from an addon.

I tried using ‘pre_add_to_cart’, 'add_to_cart, and ‘post_add_to_cart’ hooks.

But whenever I add any information to the product or the cart array it gets deleted in the next step so how can I do this?

hi Elsherif,



you used correct hooks, but there is a trick:

if you print $_SESSION['cart'] array, product info is stored in $_SESSION['cart']['products'] and every cart product has unique hash - $_SESSION['cart']['products'][$cart_id] where $cart_id is the hash



every cart product has extra key (type - array) - $_SESSION['cart']['products'][$cart_id]['extra'], for example in extra product option info is stored and if you add subkey to extra it will be automatically saved into order details





the main idea of this feature is that when you add product to cart, you should add necessary info as subkey into extra



hope it helps.



best regards,

WSA team

[quote name=‘Damir (WSA-team)’ timestamp=‘1438107169’ post=‘224657’]

hi Elsherif,



you used correct hooks, but there is a trick:

if you print $_SESSION[‘cart’] array, product info is stored in $_SESSION[‘cart’][‘products’] and every cart product has unique hash - $_SESSION[‘cart’][‘products’][$cart_id] where $cart_id is the hash



every cart product has extra key (type - array) - $_SESSION[‘cart’][‘products’][$cart_id][‘extra’], for example in extra product option info is stored and if you add subkey to extra it will be automatically saved into order details





the main idea of this feature is that when you add product to cart, you should add necessary info as subkey into extra



hope it helps.



best regards,

WSA team

[/quote]

Thanks a lot … I’ve tried adding to the extra field but not in the $_SESSION array, instead I was adding to the hook’s $cart array so, I think that was the trick. It is working fine now. :)

Now I can attach data to the order item successfully while it is in the cart but how to retrieve it after checkout and placing the order?

Please try



{foreach from=$order_info.products item="product" key="key"}
{$product.extra|fn_print_r}
{/foreach}

[quote name=‘eComLabs’ timestamp=‘1438159362’ post=‘224710’]

Please try


<br />
{foreach from=$order_info.products item="product" key="key"}<br />
	{$product.extra|fn_print_r}<br />
{/foreach}<br />

```<br />
[/quote]<br />
Thank you ... it is working fine now <img src="upload://rA9Qa8gnUPZzRZRdI8kt3dpjkrs.png" class="bbc_emoticon" alt=":)">