Skip to content

Instantly share code, notes, and snippets.

@yuklia
Created May 31, 2016 16:05
Show Gist options
  • Save yuklia/c9be29a9d7796b4130ebf18a7d4f53c0 to your computer and use it in GitHub Desktop.
Save yuklia/c9be29a9d7796b4130ebf18a7d4f53c0 to your computer and use it in GitHub Desktop.
public function addOrderItem($orderItem, $qtyFlag = null)
{
/* @var $orderItem \Magento\Sales\Model\Order\Item */
if ($orderItem->getParentItem() === null) {
$storeId = $this->_storeManager->getStore()->getId();
try {
$product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId);
} catch (NoSuchEntityException $e) {
return $this;
}
$info = $orderItem->getProductOptionByCode('info_buyRequest');
$info = new \Magento\Framework\DataObject($info);
if ($qtyFlag === null) {
$info->setQty($orderItem->getQtyOrdered());
} else {
$info->setQty(1);
}
$this->addProduct($product, $info);
}
return $this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment