Magento 2.1 – Get ‘info_buyRequest’ in Pdf\Items\Invoice\DefaultInvoice

magento-2.1pdf

Trying to get data from 'info_buyRequest' the same way i have in other templates using:

$item->getBuyRequest()

This doesn't work in \Magento\Sales\Model\Order\Pdf\Items\Invoice\DefaultInvoice

When I var_dump($item) i see the string name of 'info_buyRequest':

var_dump($item);

//outputs
...
protected '_origData' => 
    array (size=80)
      'item_id' => string '12823' (length=5)
      'order_id' => string '4003' (length=4)
      'parent_item_id' => null
      'quote_item_id' => string '37733' (length=5)
      'store_id' => string '1' (length=1)
      'created_at' => string '2017-04-26 00:35:14' (length=19)
      'updated_at' => string '2017-04-26 00:52:01' (length=19)
      'product_id' => string '47' (length=2)
      'product_type' => string 'simple' (length=6)
      'product_options' => string 'a:2:{s:15:"info_buyRequest";...

but i haven't able to access the data with the different methods i have tried.

Best Answer

As per the $item var_dump,

$productOptions = unserialize($item->getProductOptions());
$infoByRequest = $productOptions['info_buyRequest'];

Or

$orderItem->getProductOptionByCode('info_buyRequest');
Related Topic