Example #1
0
/**
 * 2016-05-03
 * Заметил, что у order item, которым соответствуют простые варианты настраиваемого товара,
 * цена почему-то равна нулю и содержится в родительском order item.
 * 2016-08-17
 * Цена возвращается в валюте заказа (не в учётной валюте системы).
 * @param OI|IOI $item
 * @return float
 */
function df_oi_price(IOI $item)
{
    return $item->getPrice() ?: ($item->getParentItem() ? df_oi_price($item->getParentItem()) : 0);
}
 /**
  * Check if order item can be invoiced. Dummy item can be invoiced or with his children or
  * with parent item which is included to invoice
  *
  * @param \Magento\Sales\Api\Data\OrderItemInterface $item
  * @return bool
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _canInvoiceItem(\Magento\Sales\Api\Data\OrderItemInterface $item)
 {
     $qtys = [];
     if ($item->getLockedDoInvoice()) {
         return false;
     }
     if ($item->isDummy()) {
         if ($item->getHasChildren()) {
             foreach ($item->getChildrenItems() as $child) {
                 if (empty($qtys)) {
                     if ($child->getQtyToInvoice() > 0) {
                         return true;
                     }
                 } else {
                     if (isset($qtys[$child->getId()]) && $qtys[$child->getId()] > 0) {
                         return true;
                     }
                 }
             }
             return false;
         } elseif ($item->getParentItem()) {
             $parent = $item->getParentItem();
             if (empty($qtys)) {
                 return $parent->getQtyToInvoice() > 0;
             } else {
                 return isset($qtys[$parent->getId()]) && $qtys[$parent->getId()] > 0;
             }
         }
     } else {
         return $item->getQtyToInvoice() > 0;
     }
 }