Application->RecallVar('checkout_errors'); $ret = Array ( 'order' => Array ( 'CouponId' => (int)$object->GetDBField('CouponId'), 'CouponName' => (string)$object->GetDBField('CouponName'), 'GiftCertificateId' => (int)$object->GetDBField('GiftCertificateDiscount'), 'GiftCertificateDiscount' => $this->convertCurrency($object->GetDBField('GiftCertificateDiscount'), $currency), 'DiscountTotal' => $this->convertCurrency($object->GetDBField('DiscountTotal'), $currency), 'SubTotal' => $this->convertCurrency($object->GetDBField('SubTotal'), $currency), ), 'items' => Array (), 'errors' => $errors ? unserialize($errors) : Array (), ); $items =& $this->Application->recallObject('orditems', 'orditems_List', Array ('per_page' => -1)); /* @var $items kDBList */ $items->Query(); $items->GoFirst(); if ( $items->EOL() ) { return $ret; } $product =& $this->Application->recallObject('p', null, Array ('skip_autoload' => true)); /* @var $product kCatDBItem */ $sql = $product->GetSelectSQL() . ' WHERE ' . $product->TableName . '.' . $product->IDField . ' IN (' . implode(',', $items->GetCol('ProductId')) . ')'; $products = $this->Conn->Query($sql, $product->IDField); while ( !$items->EOL() ) { // prepare product from order item $product->LoadFromHash( $products[ $items->GetDBField('ProductId') ] ); $this->Application->SetVar('orditems_id', $items->GetID()); // for edit/delete links using GET // weird code from orditems:PrintList $this->Application->SetVar('p_id', $product->GetID()); $this->Application->SetVar('m_cat_id', $product->GetDBField('CategoryId')); // collect order item info $url_params = Array ( 'p_id' => $product->GetID(), 'm_cat_id' => $product->GetDBField('CategoryId'), 'pass' => 'm,p', ); $product_url = $this->Application->HREF('__default__', '', $url_params); $item_data = $items->GetDBField('ItemData'); $item_data = $item_data ? unserialize($item_data) : Array (); $row_index = $items->GetDBField('ProductId') . ':' . $items->GetDBField('OptionsSalt') . ':' . $items->GetDBField('BackOrderFlag'); $ret['items'][$row_index] = Array ( 'product_url' => $product_url, 'product_type' => $product->GetDBField('Type'), 'options' => isset($item_data['Options']) ? $item_data['Options'] : false, 'free_promo_shipping' => $this->eligibleForFreePromoShipping($items), 'fields' => Array ( 'OrderItemId' => $items->GetDBField('OrderItemId'), 'ProductName' => $items->GetDBField('ProductName'), 'BackOrderFlag' => (int)$items->GetDBField('BackOrderFlag'), 'FlatPrice' => $this->convertCurrency($items->GetDBField('FlatPrice'), $currency), 'Price' => $this->convertCurrency($items->GetDBField('Price'), $currency), 'Quantity' => (int)$items->GetDBField('Quantity'), 'Virtual' => (int)$items->GetDBField('Virtual'), 'Type' => (int)$product->GetDBField('Type'), 'cust_Availability' => $product->GetDBField('cust_Availability'), ), ); $items->GoNext(); } if ( $remove_errors ) { $this->Application->RemoveVar('checkout_errors'); } return $ret; } function convertCurrency($amount, $currency) { $converter =& $this->Application->recallObject('kCurrencyRates'); /* @var $converter kCurrencyRates */ // convert primary currency to selected (if they are the same, converter will just return) return (float)$converter->Convert($amount, 'PRIMARY', $this->getISO($currency)); } function getISO($currency) { if ($currency == 'selected') { $iso = $this->Application->RecallVar('curr_iso'); } elseif ($currency == 'primary' || $currency == '') { $iso = $this->Application->GetPrimaryCurrency(); } else { //explicit currency $iso = strtoupper($currency); } return $iso; } /** * Checks, that given order item is eligible for free promo shipping * * @param kDBItem|kDBList $order_item * @return bool */ function eligibleForFreePromoShipping(&$order_item) { if ( $order_item->GetDBField('Type') != PRODUCT_TYPE_TANGIBLE ) { return false; } $free_shipping = $order_item->GetDBField('MinQtyFreePromoShipping'); return $free_shipping > 0 && $free_shipping <= $order_item->GetDBField('Quantity'); } }