Exemple #1
0
function fn_mve_place_order(&$order_id, &$action, &$__order_status, &$cart)
{
    $order_info = fn_get_order_info($order_id);
    if ($order_info['is_parent_order'] != 'Y' && !empty($order_info['company_id'])) {
        // Check if the order already placed
        $payout_id = db_get_field('SELECT payout_id FROM ?:vendor_payouts WHERE order_id = ?i', $order_id);
        $company_data = fn_get_company_data($order_info['company_id']);
        $company_data['commission'] = $order_info['total'] > 0 ? $company_data['commission'] : 0;
        $company_data['commission_type'] = isset($company_data['commission_type']) ? $company_data['commission_type'] : '';
        $commission_amount = 0;
        if ($company_data['commission_type'] == 'P') {
            //Calculate commission amount and check if we need to include shipping cost
            $commission_amount = ($order_info['total'] - (Registry::get('settings.Vendors.include_shipping') == 'N' ? $order_info['shipping_cost'] : 0)) * $company_data['commission'] / 100;
        } else {
            $commission_amount = $company_data['commission'];
        }
        //Check if we need to take payment surcharge from vendor
        if (Registry::get('settings.Vendors.include_payment_surcharge') == 'Y') {
            $commission_amount += $order_info['payment_surcharge'];
        }
        $_data = array('company_id' => $order_info['company_id'], 'order_id' => $order_id, 'payout_date' => TIME, 'start_date' => TIME, 'end_date' => TIME, 'commission' => $company_data['commission'], 'commission_type' => $company_data['commission_type'], 'order_amount' => $order_info['total'], 'commission_amount' => $commission_amount);
        fn_set_hook('mve_place_order', $order_info, $company_data, $action, $__order_status, $cart, $_data);
        if ($commission_amount > $order_info['total']) {
            $commission_amount = $order_info['total'];
        }
        if (empty($payout_id)) {
            db_query('INSERT INTO ?:vendor_payouts ?e', $_data);
        } else {
            db_query('UPDATE ?:vendor_payouts SET ?u WHERE payout_id = ?i', $_data, $payout_id);
        }
    }
}
Exemple #2
0
 function updateBill($param)
 {
     if (!is_object($param)) {
         return false;
     }
     $order_info = fn_get_order_info($param->txn, false, true, true, true);
     $temp = '';
     if (!empty($order_info['payment_method']['processor_params']['passwd']) && !empty($order_info['payment_method']['processor_params']['login'])) {
         $txn = fn_convert_encoding('utf-8', 'windows-1251', $param->txn);
         $password = fn_convert_encoding('utf-8', 'windows-1251', $order_info['payment_method']['processor_params']['passwd']);
         $crc = strtoupper(md5($txn . strtoupper(md5($password))));
         if ($param->login == $order_info['payment_method']['processor_params']['login'] && $param->password == $crc) {
             $pp_response = array();
             $status = 'qiwi_order_status_' . $param->status;
             if ($param->status == 60) {
                 $pp_response['order_status'] = 'P';
             } elseif ($param->status >= 50 && $param->status < 60) {
                 $pp_response['order_status'] = 'O';
             } else {
                 $pp_response['order_status'] = 'F';
             }
             $pp_response['reason_text'] = __($status);
             fn_finish_payment($param->txn, $pp_response);
             $temp = new Response();
             $temp->updateBillResult = 0;
         }
     }
     return $temp;
 }
function modePayment()
{
    $rid = $_REQUEST['order_id'];
    $orderId = $_SESSION['pw_order_id'];
    $iframe = '';
    $matchOrder = $rid == $orderId;
    $orderInfo = fn_get_order_info($orderId);
    if ($matchOrder && $orderInfo) {
        // Prepare Widget
        $iframe = fn_paymentwall_generateWidget($orderInfo, fn_paymentwall_getPaymentConfigs($orderInfo['payment_id']));
    }
    fn_add_breadcrumb('Paymentwall Payment', '#', true);
    Tygh::$app['view']->assign('params', array('matchOrder' => $matchOrder, 'orderId' => $orderId, 'baseUrl' => fn_url(), 'iframe' => $iframe));
}
Exemple #4
0
 public function index($id = 0, $params = array())
 {
     if (!empty($id)) {
         $data = fn_get_order_info($id, false, false);
         if (empty($data)) {
             $status = Response::STATUS_NOT_FOUND;
         } else {
             $status = Response::STATUS_OK;
         }
     } else {
         $items_per_page = $this->safeGet($params, 'items_per_page', Registry::get('settings.Appearance.admin_orders_per_page'));
         list($data, $params) = fn_get_orders($params, $items_per_page);
         $data = array('orders' => $data, 'params' => $params);
         $status = Response::STATUS_OK;
     }
     return array('status' => $status, 'data' => $data);
 }
Exemple #5
0
 public function update($id, $params)
 {
     $data = array();
     $valid_params = true;
     $status = Response::STATUS_BAD_REQUEST;
     unset($params['shipment_id']);
     list($shipments, ) = fn_get_shipments_info(array('shipment_id' => $id));
     $shipment_data = reset($shipments);
     $order_info = fn_get_order_info($shipment_data['order_id'], false, true, true);
     if (Settings::instance()->getValue('use_shipments', '', $order_info['company_id']) == 'Y') {
         $data['message'] = __('api_shipments_not_allow_update');
         $valid_params = false;
     }
     if ($valid_params) {
         $shipment_id = fn_update_shipment($params, $id);
         if ($shipment_id) {
             $status = Response::STATUS_OK;
             $data = array('shipment_id' => $shipment_id);
         }
     }
     return array('status' => $status, 'data' => $data);
 }
Exemple #6
0
function fn_sms_notifications_place_order($order_id, $action, $fake1, $cart)
{
    if ($action !== 'save' && Registry::get('addons.sms_notifications.sms_new_order_placed') == 'Y') {
        Registry::get('view')->assign('order_id', $order_id);
        Registry::get('view')->assign('total', $cart['total']);
        $send_info = Registry::get('addons.sms_notifications.sms_send_payment_info');
        $send_email = Registry::get('addons.sms_notifications.sms_send_customer_email');
        $send_min_amount = Registry::get('addons.sms_notifications.sms_send_min_amout');
        $shippings = Registry::get('addons.sms_notifications.sms_send_shipping');
        if (!is_array($shippings)) {
            $shippings = array();
        }
        Registry::get('view')->assign('send_info', $send_info == 'Y' ? true : false);
        Registry::get('view')->assign('send_email', $send_email == 'Y' ? true : false);
        Registry::get('view')->assign('send_min_amount', $send_min_amount == 'Y' ? true : false);
        $order = fn_get_order_info($order_id);
        Registry::get('view')->assign('order_email', $order['email']);
        Registry::get('view')->assign('order_payment_info', $order['payment_method']['payment']);
        if (count($shippings)) {
            $in_shipping = false;
            if (!empty($order['shipping'])) {
                foreach ($order['shipping'] as $id => $data) {
                    if ($shippings[$id] == 'Y') {
                        $in_shipping = true;
                        break;
                    }
                }
            }
        } else {
            $in_shipping = true;
        }
        if ($in_shipping && $order['subtotal'] > doubleval($send_min_amount)) {
            $body = Registry::get('view')->display('addons/sms_notifications/views/sms/components/order_sms.tpl', false);
            fn_send_sms_notification($body);
        }
    }
}
Exemple #7
0
*                                                                          *
****************************************************************************
* PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/
use Tygh\Http;
use Tygh\Registry;
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
if (defined('PAYMENT_NOTIFICATION')) {
    if ($mode == 'frame' && !empty(Tygh::$app['session']['cmpi']['acs_url'])) {
        fn_create_payment_form(Tygh::$app['session']['cmpi']['acs_url'], Tygh::$app['session']['cmpi']['frame_data'], 'Card Issuer', false, 'post', false);
        exit;
    } elseif ($mode == 'bank' && !empty(Tygh::$app['session']['cmpi']['order_id'])) {
        $order_info = fn_get_order_info(Tygh::$app['session']['cmpi']['order_id']);
        $processor_data = fn_get_processor_data($order_info['payment_method']['payment_id']);
        $payment_name = str_replace('.php', '', $processor_data['processor_script']);
        Tygh::$app['session']['cmpi']['pares'] = !empty($_REQUEST['PaRes']) ? $_REQUEST['PaRes'] : '';
        $sess = Tygh::$app['session']->getName() . '=' . Tygh::$app['session']->getID();
        $src = fn_url("payment_notification.auth?payment={$payment_name}&{$sess}", AREA, 'current');
        $msg = __('text_cc_processor_connection', array('[processor]' => '3-D Secure server'));
        fn_create_payment_form($src, array(), '3-D Secure', false, 'get', false, 'parent');
        exit;
    } elseif ($mode == 'auth' && !empty(Tygh::$app['session']['cmpi']['order_id'])) {
        $view = Tygh::$app['view'];
        $view->assign('order_action', __('placing_order'));
        $view->display('views/orders/components/placing_order.tpl');
        fn_flush();
        fn_cmpi_authenticate();
        if (Tygh::$app['session']['cmpi']['signature'] == 'Y' && in_array(Tygh::$app['session']['cmpi']['pares'], array('Y', 'A', 'U'))) {
Exemple #8
0
/**
 * Calculate order discount for sub orders (used in MVE)
 *
 * @param string $type discount type
 * @param array $bonus Array with promotion data
 * @param int $bonus_id Bonus ID
 * @param array $cart Array with cart data
 * @return float calculated discount value
 */
function fn_promotions_calculate_order_discount($bonus, $bonus_id, $cart)
{
    $type = $bonus['discount_bonus'];
    $price = $cart['subtotal'];
    $value = $bonus['discount_value'];
    static $parent_orders = array();
    // this calculations are actual only for the fixed (absolute) amount
    if ($type == 'to_fixed' || $type == 'by_fixed') {
        // if it is parent or usual order
        if (empty($cart['parent_order_id'])) {
            // calculate usual discount
            $discount = fn_promotions_calculate_discount($type, $price, $value);
            // save order discount for future calculations of suborders
            $discount = fn_format_price($discount);
            $session_orders_discount =& $_SESSION['orders_discount'][$bonus['promotion_id'] . '_' . $bonus_id];
            $session_orders_discount['parent_order_discount'] = $discount;
            $session_orders_discount['suborders_discount'] = 0;
        } else {
            // this is sub order
            $parent_order_id = $cart['parent_order_id'];
            // get parent order subtotal info
            if (!isset($parent_orders[$parent_order_id]['subtotal'])) {
                $parent_order_info = fn_get_order_info($parent_order_id);
                $parent_orders[$parent_order_id]['subtotal'] = $parent_order_info['subtotal'];
            }
            if (!empty($parent_orders[$parent_order_id]['subtotal'])) {
                // calculate the share of the full discount
                $value = $value * $price / $parent_orders[$parent_order_id]['subtotal'];
            }
            $discount = fn_promotions_calculate_discount($type, $price, $value);
            $discount = fn_format_price($discount);
            $session_orders_discount =& $_SESSION['orders_discount'][$bonus['promotion_id'] . '_' . $bonus_id];
            $parent_order_discount = !empty($session_orders_discount['parent_order_discount']) ? $session_orders_discount['parent_order_discount'] : 0;
            $suborders_discount = !empty($session_orders_discount['suborders_discount']) ? $session_orders_discount['suborders_discount'] : 0;
            // check that total suborders discount is less than parent_order_discount
            // or this is last sub order, so we have to distract discount, to avoid the extra cents
            $new_suborders_discount = $suborders_discount + $discount;
            if ($new_suborders_discount > $parent_order_discount || !empty($cart['companies']) && end($cart['companies']) == $cart['company_id']) {
                $discount = $parent_order_discount - (!empty($session_orders_discount['suborders_discount']) ? $session_orders_discount['suborders_discount'] : 0);
                if ($discount < 0) {
                    $discount = 0;
                }
            }
            $session_orders_discount['suborders_discount'] = $suborders_discount + $discount;
        }
    } else {
        $discount = fn_promotions_calculate_discount($type, $price, $value);
    }
    return $discount;
}
Exemple #9
0
        190 - Payment success
        490 - Payment failure
        491 - Validation error
        492 - Technical error
        690 - Payment rejected
        790 - Waiting for user input
        791 - Waiting for processor
        792 - Waiting on consumer action (e.g.: initiate money transfer)
        793 - Payment on hold (e.g. waiting for sufficient balance)
        890 - Cancelled by consumer
        891 - Cancelled by merchant
*/
if (defined('PAYMENT_NOTIFICATION')) {
    if ($mode == 'notify') {
        $pp_response = array();
        $order_info = fn_get_order_info($_REQUEST['brq_invoicenumber']);
        $processor_data = fn_get_payment_method_data($order_info['payment_id']);
        $pp_response["transaction_id"] = $_REQUEST['brq_transactions'];
        $pp_response["reason_text"] = urldecode($_REQUEST['brq_statusmessage']);
        $_REQUEST['brq_websitekey'] = $processor_data['processor_params']['merchant_id'];
        $_signature = fn_buckaroo_calculate_signature($_REQUEST, $processor_data["processor_params"]["merchant_key"]);
        if (in_array($_REQUEST['brq_statuscode'], array('190')) && $_REQUEST['brq_signature'] == $_signature) {
            $pp_response['order_status'] = 'P';
        } elseif (in_array($_REQUEST['brq_statuscode'], array('791', '492'))) {
            $pp_response['order_status'] = 'O';
            // still waiting for the response
        } else {
            $pp_response['order_status'] = 'F';
        }
        fn_finish_payment($_REQUEST['brq_invoicenumber'], $pp_response, false);
        $route = $order_info['repaid'] ? 'repay' : 'route';
Exemple #10
0
****************************************************************************
* PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/
use Tygh\Http;
use Tygh\Registry;
use Tygh\Session;
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
if (defined('PAYMENT_NOTIFICATION')) {
    if ($mode == 'frame' && !empty($_SESSION['cmpi']['acs_url'])) {
        fn_create_payment_form($_SESSION['cmpi']['acs_url'], $_SESSION['cmpi']['frame_data'], 'Card Issuer', false, 'post', false);
        exit;
    } elseif ($mode == 'bank' && !empty($_SESSION['cmpi']['order_id'])) {
        $order_info = fn_get_order_info($_SESSION['cmpi']['order_id']);
        $processor_data = fn_get_processor_data($order_info['payment_method']['payment_id']);
        $payment_name = str_replace('.php', '', $processor_data['processor_script']);
        $_SESSION['cmpi']['pares'] = !empty($_REQUEST['PaRes']) ? $_REQUEST['PaRes'] : '';
        $sess = Session::getName() . '=' . Session::getId();
        $src = fn_url("payment_notification.auth?payment={$payment_name}&{$sess}", AREA, 'current');
        $msg = __('text_cc_processor_connection', array('[processor]' => '3-D Secure server'));
        fn_create_payment_form($src, array(), '3-D Secure', false, 'get', false, 'parent');
        exit;
    } elseif ($mode == 'auth' && !empty($_SESSION['cmpi']['order_id'])) {
        $view = Tygh::$app['view'];
        $view->assign('order_action', __('placing_order'));
        $view->display('views/orders/components/placing_order.tpl');
        fn_flush();
        fn_cmpi_authenticate();
        if ($_SESSION['cmpi']['signature'] == 'Y' && in_array($_SESSION['cmpi']['pares'], array('Y', 'A', 'U'))) {
Exemple #11
0
function fn_print_order_packing_slips($order_ids, $pdf = false, $lang_code = CART_LANGUAGE)
{
    $view = Registry::get('view');
    $html = array();
    if (!is_array($order_ids)) {
        $order_ids = array($order_ids);
    }
    foreach ($order_ids as $order_id) {
        $order_info = fn_get_order_info($order_id, false, true, false, true);
        if (empty($order_info)) {
            continue;
        }
        $view->assign('order_info', $order_info);
        if ($pdf == true) {
            fn_disable_live_editor_mode();
            $html[] = $view->displayMail('orders/print_packing_slip.tpl', false, 'A', $order_info['company_id'], $lang_code);
        } else {
            $view->displayMail('orders/print_packing_slip.tpl', true, 'A', $order_info['company_id'], $lang_code);
        }
        if ($order_id != end($order_ids)) {
            echo "<div style='page-break-before: always;'>&nbsp;</div>";
        }
    }
    if ($pdf == true) {
        Pdf::render($html, __('packing_slip') . '-' . implode('-', $order_ids));
    }
    return true;
}
Exemple #12
0
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if ($mode == 'export_profiles') {
        header('Content-type: text/csv');
        header('Content-disposition: attachment; filename=shop-customers' . date('Ymd') . '.txt');
        foreach ($_REQUEST['user_ids'] as $k => $v) {
            $users[$k] = fn_get_user_info($v);
        }
        $view->assign('users', $users);
        $view->display('addons/myob/views/users/components/export_to_myob.tpl');
        exit;
    }
    if ($mode == 'export_orders') {
        header('Content-type: text/csv');
        header('Content-disposition: attachment; filename=shop-orders' . date('Ymd') . '.txt');
        foreach ($_REQUEST['order_ids'] as $k => $v) {
            $orders[$k] = fn_get_order_info($v);
            $orders[$k]['order_date'] = date('j/n/Y', $orders[$k]['timestamp']);
            $orders[$k]['paid_amount'] = 0;
            //TODO: Update this!
            foreach ($orders[$k]['items'] as $ik => $iv) {
                $option_desc = "";
                $desc_count = 0;
                if (!empty($orders[$k]['items'][$ik]['product_options'])) {
                    foreach ($orders[$k]['items'][$ik]['product_options'] as $option_key => $option_value) {
                        if ($desc_count > 0) {
                            $option_desc .= ", ";
                        } else {
                            $option_desc = ' (';
                        }
                        $option_desc .= $option_value['option_name'] . ' = ' . $option_value['variant_name'];
                        $desc_count++;
Exemple #13
0
* license  and  accept  to the terms of the  License Agreement can install *
* and use this program.                                                    *
*                                                                          *
****************************************************************************
* PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/
use Tygh\Registry;
use Tygh\Http;
use Tygh\Shippings\RusSdek;
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $params = $_REQUEST;
    $order_info = fn_get_order_info($params['order_id'], false, true, true, true);
    if ($mode == 'sdek_order_delivery') {
        if (empty($params['add_sdek_info'])) {
            return false;
        }
        foreach ($params['add_sdek_info'] as $shipment_id => $sdek_info) {
            list($_shipments, $search) = fn_get_shipments_info(array('order_id' => $params['order_id'], 'advanced_info' => true, 'shipment_id' => $shipment_id));
            $shipment = reset($_shipments);
            $params_shipping = array('shipping_id' => $shipment['shipping_id'], 'Date' => date("Y-m-d", $shipment['shipment_timestamp']));
            $data_auth = RusSdek::dataAuth($params_shipping);
            if (empty($data_auth)) {
                continue;
            }
            $order_for_sdek = $sdek_info['Order'];
            $lastname = "";
            if (!empty($order_info['lastname'])) {
Exemple #14
0
function fn_exim_1c_export_orders($company_id, $lang_code)
{
    $cml = fn_get_cml_tag_names();
    $params = array('company_name' => true, 'place' => 'exim_1c', 'company_id' => $company_id);
    $statuses = Registry::get('addons.rus_exim_1c.exim_1c_order_statuses');
    if (!empty($statuses)) {
        foreach ($statuses as $key => $status) {
            if (!empty($status)) {
                $params['status'][] = $key;
            }
        }
    }
    list($orders, $search) = fn_get_orders($params);
    header("Content-type: text/xml; charset=utf-8");
    fn_echo("");
    $xml = new XMLWriter();
    $xml->openMemory();
    $xml->startDocument();
    $xml->startElement($cml['commerce_information']);
    foreach ($orders as $k => $data) {
        $order_data = fn_get_order_info($data['order_id']);
        $xml = fn_exim_1c_echo_order_xml($xml, $order_data, $lang_code);
    }
    $xml->endElement();
    fn_echo($xml->outputMemory());
}
Exemple #15
0
function fn_get_packing_info($shipment_id)
{
    $params['advanced_info'] = true;
    $params['shipment_id'] = $shipment_id;
    list($shipment, $search, $total) = fn_get_shipments_info($params);
    if (!empty($shipment)) {
        $shipment = array_pop($shipment);
        $order_info = fn_get_order_info($shipment['order_id'], false, true, true);
        $shippings = db_get_array("SELECT a.shipping_id, a.min_weight, a.max_weight, a.position, a.status, b.shipping, b.delivery_time, a.usergroup_ids FROM ?:shippings as a LEFT JOIN ?:shipping_descriptions as b ON a.shipping_id = b.shipping_id AND b.lang_code = ?s ORDER BY a.position", DESCR_SL);
        $_products = db_get_array("SELECT item_id, SUM(amount) AS amount FROM ?:shipment_items WHERE order_id = ?i GROUP BY item_id", $shipment['order_id']);
        $shipped_products = array();
        if (!empty($_products)) {
            foreach ($_products as $_product) {
                $shipped_products[$_product['item_id']] = $_product['amount'];
            }
        }
        foreach ($order_info['items'] as $k => $oi) {
            if (isset($shipped_products[$k])) {
                $order_info['items'][$k]['shipment_amount'] = $oi['amount'] - $shipped_products[$k];
            } else {
                $order_info['items'][$k]['shipment_amount'] = $order_info['items'][$k]['amount'];
            }
            if (isset($shipment['items'][$k])) {
                $order_info['items'][$k]['amount'] = $shipment['items'][$k];
            } else {
                $order_info['items'][$k]['amount'] = 0;
            }
        }
    } else {
        $shipment = $order_info = array();
    }
    return array($shipment, $order_info);
}
Exemple #16
0
function fn_update_order_customer_info($data, $order_id)
{
    $order_info = fn_get_order_info($order_id);
    $new_order_info = array();
    $need_update = false;
    if (empty($order_info)) {
        return false;
    }
    foreach ($data as $k => $v) {
        if ($data[$k] != $order_info[$k]) {
            $need_update = true;
            $new_order_info[$k] = $v;
        }
    }
    if ($need_update) {
        db_query("UPDATE ?:orders SET ?u WHERE order_id = ?i", $new_order_info, $order_id);
    }
    return true;
}
Exemple #17
0
function fn_reorder($order_id, &$cart, &$auth)
{
    $order_info = fn_get_order_info($order_id, false, false, false, true);
    unset($_SESSION['shipping_hash']);
    unset($_SESSION['edit_step']);
    fn_set_hook('reorder', $order_info, $cart, $auth);
    foreach ($order_info['products'] as $k => $item) {
        // refresh company id
        $company_id = db_get_field("SELECT company_id FROM ?:products WHERE product_id = ?i", $item['product_id']);
        $order_info['products'][$k]['company_id'] = $company_id;
        unset($order_info['products'][$k]['extra']['ekey_info']);
        $order_info['products'][$k]['product_options'] = empty($order_info['products'][$k]['extra']['product_options']) ? array() : $order_info['products'][$k]['extra']['product_options'];
        $order_info['products'][$k]['main_pair'] = fn_get_cart_product_icon($item['product_id'], $order_info['products'][$k]);
    }
    if (!empty($cart) && !empty($cart['products'])) {
        $cart['products'] = fn_array_merge($cart['products'], $order_info['products']);
    } else {
        $cart['products'] = $order_info['products'];
    }
    foreach ($cart['products'] as $k => $v) {
        $_is_edp = db_get_field("SELECT is_edp FROM ?:products WHERE product_id = ?i", $v['product_id']);
        if ($amount = fn_check_amount_in_stock($v['product_id'], $v['amount'], $v['product_options'], $k, $_is_edp, 0, $cart)) {
            $cart['products'][$k]['amount'] = $amount;
            // Change the path of custom files
            if (!empty($v['extra']['custom_files'])) {
                foreach ($v['extra']['custom_files'] as $option_id => $_data) {
                    if (!empty($_data)) {
                        foreach ($_data as $file_id => $file) {
                            $cart['products'][$k]['extra']['custom_files'][$option_id][$file_id]['path'] = 'sess_data/' . fn_basename($file['path']);
                        }
                    }
                }
            }
        } else {
            unset($cart['products'][$k]);
        }
    }
    // Restore custom files for editing
    $dir_path = 'order_data/' . $order_id;
    if (Storage::instance('custom_files')->isExist($dir_path)) {
        Storage::instance('custom_files')->copy($dir_path, 'sess_data');
    }
    // Redirect customer to step three after reordering
    $cart['payment_updated'] = true;
    fn_save_cart_content($cart, $auth['user_id']);
    unset($cart['product_groups']);
}
Exemple #18
0
/**
 * @author Albert Peschar <*****@*****.**>
 */
use Tygh\Http;
use Tygh\Registry;
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
$redirect_timeout = "\n    <script>\n    window.setTimeout(function() {\n        window.location = " . json_encode(fn_url('checkout.checkout')) . ";\n    }, 5000);\n    </script>\n    <p>You will be redirected in 5 seconds.</p>\n";
if (defined('PAYMENT_NOTIFICATION')) {
    if (!isset($_GET['order_id'])) {
        echo "<p>Order ID not specified.</p>", $redirect_timeout;
        exit;
    }
    $order_info = fn_get_order_info($_GET['order_id']);
    if (!$order_info) {
        echo "<p>Order not found.</p>", $redirect_timeout;
        exit;
    }
    $order_id = $order_info['order_id'];
    $processor_data = fn_get_payment_method_data($order_info['payment_id']);
    if (!$processor_data) {
        echo "<p>Payment method not found.</p>", $redirect_timeout;
        exit;
    }
    if (!isset($_GET['litepaid_id'])) {
        echo "<p>LitePaid ID not specified.</p>", $redirect_timeout;
        exit;
    }
    $litepaid_id = $_GET['litepaid_id'];
Exemple #19
0
function fn_create_return_gift_certificate($order_id, $amount)
{
    $min = Registry::get('addons.gift_certificates.min_amount') * 1;
    $max = Registry::get('addons.gift_certificates.max_amount') * 1;
    $order_info = fn_get_order_info($order_id);
    $templates = fn_get_gift_certificate_templates();
    $_data = array('send_via' => 'E', 'recipient' => "{$order_info['firstname']} {$order_info['lastname']}", 'sender' => Registry::get('settings.Company.company_name'), 'amount' => $amount, 'email' => $order_info['email'], 'address' => $order_info['s_address'], 'address_2' => $order_info['s_address_2'], 'city' => $order_info['s_city'], 'country' => $order_info['s_country'], 'state' => $order_info['s_state'], 'zipcode' => $order_info['s_zipcode'], 'phone' => $order_info['phone'], 'template' => key($templates));
    if (fn_allowed_for('ULTIMATE')) {
        $_data['company_id'] = Registry::ifGet('runtime.company_id', $order_info['company_id']);
    }
    do {
        $code = fn_generate_gift_certificate_code();
    } while (true == fn_check_gift_certificate_code($code));
    if ($amount < $min || $amount > $max) {
        fn_set_notification('E', __('error'), __('gift_cert_error_amount', array('[min]' => $min, '[max]' => $max)));
        $result = array();
    } else {
        $_data = fn_array_merge($_data, array('gift_cert_code' => $code, 'timestamp' => TIME));
        $gift_cert_id = db_query('INSERT INTO ?:gift_certificates ?e', $_data);
        $result = array($gift_cert_id => array('code' => $code, 'amount' => $amount));
    }
    return $result;
}
Exemple #20
0
    if ($mode == 'cancel') {
        $order_info = fn_get_order_info($_REQUEST['order_id']);
        fn_pp_save_mode($order_info);
        if ($order_info['status'] == 'O' || $order_info['status'] == 'I') {
            $pp_response['order_status'] = 'I';
            $pp_response["reason_text"] = __('text_transaction_cancelled');
            fn_finish_payment($order_info['order_id'], $pp_response);
        }
        fn_order_placement_routines('route', $_REQUEST['order_id'], false);
    } else {
        $order_id = !empty($_REQUEST['order_id']) ? $_REQUEST['order_id'] : 0;
        $token = !empty($_REQUEST['token']) ? $_REQUEST['token'] : 0;
        $payment_id = db_get_field("SELECT payment_id FROM ?:orders WHERE order_id = ?i", $order_id);
        $processor_data = fn_get_payment_method_data($payment_id);
        $processor_data['processor_script'] = 'paypal_express.php';
        $order_info = fn_get_order_info($order_id);
        fn_pp_save_mode($order_info);
        fn_paypal_complete_checkout($token, $processor_data, $order_info);
    }
}
$mode = !empty($mode) ? $mode : (!empty($_REQUEST['mode']) ? $_REQUEST['mode'] : '');
if ($mode == 'express_return') {
    $token = $_REQUEST['token'];
    $payment_id = $_REQUEST['payment_id'];
    $processor_data = fn_get_payment_method_data($payment_id);
    $paypal_checkout_details = fn_paypal_get_express_checkout_details($processor_data, $token);
    if (fn_paypal_ack_success($paypal_checkout_details)) {
        fn_paypal_user_login($paypal_checkout_details);
        $paypal_express_details = array('token' => $token, 'payment_id' => $payment_id);
        $_SESSION['pp_express_details'] = $paypal_express_details;
        $_SESSION['cart']['payment_id'] = $payment_id;
 /**
  * Get order data
  */
 public static function getOrderInfo($order_id)
 {
     $object = fn_get_order_info($order_id, false, true, true);
     $object['date'] = fn_twg_format_time($object['timestamp']);
     $status_data = fn_get_status_data($object['status'], STATUSES_ORDER);
     $object['status'] = empty($status_data['description']) ? '' : $status_data['description'];
     $object['items'] = !empty($object['items']) && is_array($object['items']) ? array_values($object['items']) : array();
     $object['shipping'] = array_values(isset($object['shipping']) ? $object['shipping'] : array());
     $object['taxes'] = array_values($object['taxes']);
     $object['items'] = array_values($object['products']);
     unset($object['products']);
     return $object;
 }
Exemple #22
0
 public static function orderPlacementRoutines($order_id, $force_notification = array(), $clear_cart = true, $action = '')
 {
     // don't show notifications
     // only clear cart
     $order_info = fn_get_order_info($order_id, true);
     $display_notification = true;
     fn_set_hook('placement_routines', $order_id, $order_info, $force_notification, $clear_cart, $action, $display_notification);
     if (!empty($_SESSION['cart']['placement_action'])) {
         if (empty($action)) {
             $action = $_SESSION['cart']['placement_action'];
         }
         unset($_SESSION['cart']['placement_action']);
     }
     if (AREA == 'C' && !empty($order_info['user_id'])) {
         $__fake = '';
         fn_save_cart_content($__fake, $order_info['user_id']);
     }
     $edp_data = fn_generate_ekeys_for_edp(array(), $order_info);
     fn_order_notification($order_info, $edp_data, $force_notification);
     // Empty cart
     if ($clear_cart == true && substr_count('OPT', $order_info['status']) > 0) {
         $_SESSION['cart'] = array('user_data' => !empty($_SESSION['cart']['user_data']) ? $_SESSION['cart']['user_data'] : array(), 'profile_id' => !empty($_SESSION['cart']['profile_id']) ? $_SESSION['cart']['profile_id'] : 0, 'user_id' => !empty($_SESSION['cart']['user_id']) ? $_SESSION['cart']['user_id'] : 0);
         db_query('DELETE FROM ?:user_session_products WHERE session_id = ?s AND type = ?s', Session::getId(), 'C');
     }
     $is_twg_hook = true;
     $_error = false;
     fn_set_hook('order_placement_routines', $order_id, $force_notification, $order_info, $_error, $is_twg_hook);
 }
Exemple #23
0
    if (!empty($_REQUEST['order_id'])) {
        if (empty($auth['user_id'])) {
            if (empty($auth['order_ids'])) {
                return array(CONTROLLER_STATUS_REDIRECT, 'auth.login_form?return_url=' . urlencode(Registry::get('config.current_url')));
            } else {
                $allowed_id = in_array($_REQUEST['order_id'], $auth['order_ids']);
            }
        } else {
            $allowed_id = db_get_field("SELECT user_id FROM ?:orders WHERE user_id = ?i AND order_id = ?i", $auth['user_id'], $_REQUEST['order_id']);
        }
        fn_set_hook('is_order_allowed', $_REQUEST['order_id'], $allowed_id);
        if (empty($allowed_id)) {
            // Access denied
            return array(CONTROLLER_STATUS_DENIED);
        }
        $order_info = fn_get_order_info($_REQUEST['order_id']);
        if (!empty($order_info['is_parent_order']) && $order_info['is_parent_order'] == 'Y') {
            $order_info['child_ids'] = implode(',', db_get_fields("SELECT order_id FROM ?:orders WHERE parent_order_id = ?i", $_REQUEST['order_id']));
        }
        if (!empty($order_info)) {
            Tygh::$app['view']->assign('order_info', $order_info);
        }
    }
    fn_add_breadcrumb(__('landing_header'));
} elseif ($mode == 'process_payment') {
    if (fn_allow_place_order($cart, $auth) == true) {
        $order_info = $cart;
        $order_info['products'] = $cart['products'];
        $order_info = fn_array_merge($order_info, $cart['user_data']);
        $order_info['order_id'] = $order_id = TIME . "_" . (!empty($auth['user_id']) ? $auth['user_id'] : 0);
        unset($order_info['user_data']);
Exemple #24
0
function fn_process_paypal_ipn($order_id, $data)
{
    $order_info = fn_get_order_info($order_id);
    if (!empty($order_info) && !empty($data['txn_id']) && (empty($order_info['payment_info']['txn_id']) || $data['payment_status'] != 'Completed' || $data['payment_status'] == 'Completed' && $order_info['payment_info']['txn_id'] !== $data['txn_id'])) {
        //Can't check refund transactions.
        if (isset($data['txn_type']) && !fn_validate_paypal_order_info($data, $order_info)) {
            return false;
        }
        $pp_settings = fn_get_paypal_settings();
        fn_clear_cart($cart, true);
        $customer_auth = fn_fill_auth(array(), array(), false, 'C');
        fn_form_cart($order_id, $cart, $customer_auth);
        if ($pp_settings['override_customer_info'] == 'Y') {
            $cart['user_data'] = fn_paypal_get_customer_info($data);
        }
        $cart['order_id'] = $order_id;
        $cart['payment_info'] = $order_info['payment_info'];
        $cart['payment_info']['protection_eligibility'] = !empty($data['protection_eligibility']) ? $data['protection_eligibility'] : '';
        $cart['payment_id'] = $order_info['payment_id'];
        if (!empty($data['memo'])) {
            //Save customer notes
            $cart['notes'] = $data['memo'];
        }
        if ($data['payment_status'] == 'Completed') {
            //save uniq ipn id to avoid double ipn processing
            $cart['payment_info']['txn_id'] = $data['txn_id'];
        }
        if (!empty($data['payer_email'])) {
            $cart['payment_info']['customer_email'] = $data['payer_email'];
        }
        if (!empty($data['payer_id'])) {
            $cart['payment_info']['client_id'] = $data['payer_id'];
        }
        //Sometimes, for some reasons cart_id in product products calculated incorrectle, so we need recalculate it.
        $cart['change_cart_products'] = true;
        fn_calculate_cart_content($cart, $customer_auth);
        $cart['payment_info']['order_status'] = $pp_settings['pp_statuses'][strtolower($data['payment_status'])];
        list($order_id, ) = fn_update_order($cart, $order_id);
        if ($order_id) {
            fn_change_order_status($order_id, $pp_settings['pp_statuses'][strtolower($data['payment_status'])]);
            if (fn_allowed_for('MULTIVENDOR')) {
                $child_order_ids = db_get_fields("SELECT order_id FROM ?:orders WHERE parent_order_id = ?i", $order_id);
                if (!empty($child_order_ids)) {
                    foreach ($child_order_ids as $child_order_id) {
                        fn_update_order_payment_info($child_order_id, $cart['payment_info']);
                    }
                }
            }
        }
        return true;
    }
}
             }
             return array(CONTROLLER_STATUS_OK, "orders_feedback.update?feedback_id=" . $_REQUEST['settings_data']['feedback_id']);
         }
     }
     return array(CONTROLLER_STATUS_OK, "orders_feedback.update?feedback_id=" . $_REQUEST['feedback_id']);
 }
 if ($mode == "test_send") {
     $test_email = $_REQUEST['test_email'];
     $remind = $_REQUEST['settings_data'];
     $remind['lang_code'] = DESCR_SL;
     if (fn_validate_email($test_email)) {
         $statuses = $remind['statuses'];
         $remind_orders = db_get_array("SELECT * FROM ?:orders WHERE status in (?a) AND lang_code=?s", $statuses, $remind['lang_code']);
         if (!empty($remind_orders)) {
             $remind_order = array_pop($remind_orders);
             $order_info = fn_get_order_info($remind_order['order_id']);
             $letter['body'] = $remind['body'];
             $letter['subject'] = $remind['subject'];
             $customer_name = $order_info['firstname'] . ' ' . $remind_order['lastname'];
             $company = db_get_field("SELECT company FROM ?:companies WHERE company_id=?i", $remind_order['company_id']);
             $products = array();
             foreach ($order_info['products'] as $key => $product) {
                 $product_data = fn_get_product_data($product['product_id'], $_SESSION['auth']);
                 if (!empty($product_data['discussion_type']) && $product_data['discussion_type'] != 'D') {
                     $products[$product['product_id']] = $product_data;
                 }
             }
             if (!empty($products)) {
                 Registry::get('view')->assign('products', $products);
                 $products_block = Registry::get('view')->fetch('addons/orders_feedback/components/products.tpl');
             } else {
Exemple #26
0
function fn_qwintry_update_shipment($shipment_data, $shipment_id = 0, $group_key = 0, $all_products = false, $force_notification = array())
{
    if (!empty($shipment_id)) {
        $arow = db_query("UPDATE ?:shipments SET tracking_number = ?s, carrier = ?s WHERE shipment_id = ?i", $shipment_data['tracking_number'], $shipment_data['carrier'], $shipment_id);
        if ($arow === false) {
            fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('shipment'))), '', '404');
            $shipment_id = false;
        }
    } else {
        if (empty($shipment_data['order_id']) || empty($shipment_data['shipping_id'])) {
            return false;
        }
        $order_info = fn_get_order_info($shipment_data['order_id'], false, true, true);
        $use_shipments = Settings::instance()->getValue('use_shipments', '', $order_info['company_id']) == 'Y' ? true : false;
        if (!$use_shipments && empty($shipment_data['tracking_number']) && empty($shipment_data['tracking_number'])) {
            return false;
        }
        if ($all_products) {
            foreach ($order_info['product_groups'] as $group) {
                foreach ($group['products'] as $item_key => $product) {
                    if (!empty($product['extra']['group_key'])) {
                        if ($group_key == $product['extra']['group_key']) {
                            $shipment_data['products'][$item_key] = $product['amount'];
                        }
                    } elseif ($group_key == 0) {
                        $shipment_data['products'][$item_key] = $product['amount'];
                    }
                }
            }
        }
        if (!empty($shipment_data['products']) && fn_check_shipped_products($shipment_data['products'])) {
            fn_set_hook('create_shipment', $shipment_data, $order_info, $group_key, $all_products);
            foreach ($shipment_data['products'] as $key => $amount) {
                if (isset($order_info['products'][$key])) {
                    $amount = intval($amount);
                    if ($amount > $order_info['products'][$key]['amount'] - $order_info['products'][$key]['shipped_amount']) {
                        $shipment_data['products'][$key] = $order_info['products'][$key]['amount'] - $order_info['products'][$key]['shipped_amount'];
                    }
                }
            }
            if (fn_check_shipped_products($shipment_data['products'])) {
                $shipment_data['timestamp'] = time();
                $shipment_id = db_query("INSERT INTO ?:shipments ?e", $shipment_data);
                foreach ($shipment_data['products'] as $key => $amount) {
                    if ($amount == 0) {
                        continue;
                    }
                    $_data = array('item_id' => $key, 'shipment_id' => $shipment_id, 'order_id' => $shipment_data['order_id'], 'product_id' => $order_info['products'][$key]['product_id'], 'amount' => $amount);
                    db_query("INSERT INTO ?:shipment_items ?e", $_data);
                }
                if (fn_check_permissions('orders', 'update_status', 'admin') && !empty($shipment_data['order_status'])) {
                    fn_change_order_status($shipment_data['order_id'], $shipment_data['order_status']);
                }
                /**
                 * Called after new shipment creation.
                 *
                 * @param array $shipment_data Array of shipment data.
                 * @param array $order_info Shipment order info
                 * @param int $group_key Group number
                 * @param bool $all_products
                 * @param int $shipment_id Created shipment identifier
                 */
                fn_set_hook('create_shipment_post', $shipment_data, $order_info, $group_key, $all_products, $shipment_id);
                if (!empty($force_notification['C'])) {
                    $shipment = array('shipment_id' => $shipment_id, 'timestamp' => $shipment_data['timestamp'], 'shipping' => db_get_field('SELECT shipping FROM ?:shipping_descriptions WHERE shipping_id = ?i AND lang_code = ?s', $shipment_data['shipping_id'], $order_info['lang_code']), 'tracking_number' => $shipment_data['tracking_number'], 'carrier' => $shipment_data['carrier'], 'comments' => $shipment_data['comments'], 'items' => $shipment_data['products']);
                    Mailer::sendMail(array('to' => $order_info['email'], 'from' => 'company_orders_department', 'data' => array('shipment' => $shipment, 'order_info' => $order_info), 'tpl' => 'shipments/shipment_products.tpl', 'company_id' => $order_info['company_id']), 'C', $order_info['lang_code']);
                }
                fn_set_notification('N', __('notice'), __('shipment_has_been_created'));
            }
        } else {
            fn_set_notification('E', __('error'), __('products_for_shipment_not_selected'));
        }
    }
    return $shipment_id;
}
Exemple #27
0
function fn_spsr_pre_check_invoice_create($order_id, $section, $spsr_shipments = array())
{
    $shipping = array();
    if (empty($order_id)) {
        return array(CONTROLLER_STATUS_REDIRECT, "orders.manage");
    }
    $order_info = fn_get_order_info($order_id, false, true, true, true);
    if (!empty($order_info)) {
        list($_shipments) = fn_get_shipments_info(array('order_id' => $order_id, 'advanced_info' => true));
        if (!empty($_shipments)) {
            $shipments = array();
            foreach ($_shipments as $shipment) {
                if ($shipment['carrier'] == 'spsr') {
                    if (empty($spsr_shipments) || !empty($spsr_shipments[$shipment['shipment_id']])) {
                        $shipments[$shipment['shipment_id']] = $shipment;
                    }
                }
            }
        }
        if (!empty($shipments)) {
            foreach ($shipments as $shipment_id => $shipment) {
                $shipping = fn_get_shipping_info($shipment['shipping_id'], DESCR_SL);
                $shipping['rate'] = $order_info['shipping_cost'];
                $invoices[$shipment_id] = RusSpsr::preInvoiceByShipments($shipment, $order_info, $shipping);
                $shipping_data[$shipment_id] = $shipping;
            }
        } else {
            return array(CONTROLLER_STATUS_REDIRECT, "orders.details?order_id={$order_id}&selected_section={$section}");
        }
    }
    return array($order_info, $invoices, $shipments, $shipping_data);
}
Exemple #28
0
function fn_anti_fraud_place_order(&$order_id, &$action, &$order_status)
{
    $checked = db_get_field('SELECT COUNT(*) FROM ?:order_data WHERE order_id = ?i AND type = ?s', $order_id, 'F');
    if ($action == 'save' || defined('ORDER_MANAGEMENT') || $checked) {
        return true;
    }
    $return = array();
    $af_settings = Registry::get('addons.anti_fraud');
    if (empty($af_settings['anti_fraud_key'])) {
        return false;
    }
    $order_info = fn_get_order_info($order_id);
    if (empty($order_info['ip_address'])) {
        $return['B'][] = 'af_ip_not_found';
    }
    $risk_factor = 1;
    $request = array('license_key' => $af_settings['anti_fraud_key'], 'i' => $order_info['ip_address'], 'city' => $order_info['b_city'], 'region' => $order_info['b_state'], 'postal' => $order_info['b_zipcode'], 'country' => $order_info['b_country'], 'domain' => substr($order_info['email'], strpos($order_info['email'], '@') + 1), 'emailMD5' => $order_info['email']);
    $_result = Http::get('http://www.maxmind.com/app/ccv2r', $request);
    $result = array();
    $_result = explode(';', $_result);
    if (is_array($_result)) {
        foreach ($_result as $v) {
            $tmp = explode('=', $v);
            $result[$tmp[0]] = $tmp[1];
        }
    }
    unset($_result);
    if (!empty($result['err'])) {
        $return['B'][] = 'af_' . fn_strtolower($result['err']);
        $risk_factor *= AF_ERROR_FACTOR;
    } else {
        // Check if order total greater than defined
        if (!empty($af_settings['anti_fraud_max_order_total']) && floatval($order_info['total']) > floatval($af_settings['anti_fraud_max_order_total'])) {
            $risk_factor *= AF_ORDER_TOTAL_FACTOR;
            $return['B'][] = 'af_big_order_total';
        }
        if (!empty($order_info['user_id'])) {
            // Check if this customer has processed orders
            $amount = db_get_field("SELECT COUNT(*) FROM ?:orders WHERE status IN ('P','C') AND user_id = ?i", $order_info['user_id']);
            if (!empty($amount)) {
                $risk_factor /= AF_COMPLETED_ORDERS_FACTOR;
                $return['G'][] = 'af_has_successfull_orders';
            }
            // Check if this customer has failed orders
            $amount = db_get_field("SELECT COUNT(*) FROM ?:orders WHERE status IN ('D','F') AND user_id = ?i", $order_info['user_id']);
            if (!empty($amount)) {
                $risk_factor *= AF_FAILED_ORDERS_FACTOR;
                $return['B'][] = 'af_has_failed_orders';
            }
        }
        if ($result['countryMatch'] == 'No') {
            $return['B'][] = 'af_country_doesnt_match';
        }
        if ($result['highRiskCountry'] == 'Yes') {
            $return['B'][] = 'af_high_risk_country';
        }
        if (!empty($af_settings['anti_fraud_safe_distance']) && intval($result['distance']) > intval($af_settings['anti_fraud_safe_distance'])) {
            $return['B'][] = 'af_long_distance';
        }
        if ($result['carderEmail'] == 'Yes') {
            $return['B'][] = 'af_carder_email';
        }
        $risk_factor += floatval($result['riskScore']);
        if ($risk_factor > 100) {
            $risk_factor = 100;
        }
    }
    $return['risk_factor'] = $risk_factor;
    if (floatval($risk_factor) >= floatval($af_settings['anti_fraud_risk_factor'])) {
        $action = 'save';
        $order_status = Registry::get('addons.anti_fraud.antifraud_order_status');
        $return['B'][] = 'af_high_risk_factor';
        $return['I'] = true;
        fn_set_notification('W', __('warning'), __('antifraud_failed_order'));
    } else {
        $return['G'][] = 'af_low_risk_factor';
    }
    $return = serialize($return);
    $data = array('order_id' => $order_id, 'type' => 'F', 'data' => $return);
    db_query("REPLACE INTO ?:order_data ?e", $data);
    return true;
}
Exemple #29
0
function fn_rma_print_packing_slips($return_ids, $auth, $area = AREA)
{
    $view = Registry::get('view');
    $passed = false;
    if (!is_array($return_ids)) {
        $return_ids = array($return_ids);
    }
    $view->assign('reasons', fn_get_rma_properties(RMA_REASON));
    $view->assign('actions', fn_get_rma_properties(RMA_ACTION));
    $view->assign('order_status_descr', fn_get_simple_statuses(STATUSES_RETURN));
    foreach ($return_ids as $return_id) {
        $return_info = fn_get_return_info($return_id);
        if (empty($return_info) || $area == 'C' && $return_info['user_id'] != $auth['user_id']) {
            continue;
        }
        $order_info = fn_get_order_info($return_info['order_id']);
        if (empty($order_info)) {
            continue;
        }
        $passed = true;
        $view->assign('return_info', $return_info);
        $view->assign('order_info', $order_info);
        $view->assign('company_data', fn_get_company_placement_info($order_info['company_id']));
        $view->displayMail('addons/rma/print_slip.tpl', true, $area, $order_info['company_id']);
        if ($return_id != end($return_ids)) {
            echo "<div style='page-break-before: always;'>&nbsp;</div>";
        }
    }
    return $passed;
}
Exemple #30
0
function fn_check_shipment_data($data)
{
    $shipments = array();
    foreach ($data as $k => $v) {
        if (!empty($v['shipment_id'])) {
            $shipment_info = db_get_row("SELECT ?:shipments.*, ?:shipment_items.order_id\n                 FROM ?:shipments\n                 LEFT JOIN ?:shipment_items\n                 ON ?:shipments.shipment_id = ?:shipment_items.shipment_id\n                 WHERE ?:shipments.shipment_id = ?i", $v['shipment_id']);
            if (!$shipment_info) {
                return false;
            }
            $shipment_items = db_get_hash_single_array("SELECT item_id, amount\n                 FROM ?:shipment_items\n                 WHERE shipment_id = ?i", array('item_id', 'amount'), $v['shipment_id']);
            $v = array_merge($shipment_info, $v);
        } elseif (empty($v['is_complete_data'])) {
            return false;
        }
        $order_info = fn_get_order_info($v['order_id'], false, true, true);
        if (!empty($v['shipment_id']) && !empty($shipment_items)) {
            foreach ($shipment_items as $item_id => $amount) {
                if (!isset($order_info['items'][$item_id])) {
                    return false;
                }
                $order_info['items'][$item_id]['shipped_amount'] -= $amount;
            }
        }
        if (empty($order_info)) {
            return false;
        }
        if (empty($v['shipping_id'])) {
            $v['shipping_id'] = $order_info['shipping_ids'];
        }
        if (empty($v['timestamp'])) {
            $v['timestamp'] = TIME;
        }
        $items = array();
        foreach ($v['products'] as $product) {
            if (!$product['is_complete_data']) {
                return false;
            }
            $item_id = $product['item_id'];
            if (!isset($order_info['items'][$item_id])) {
                return false;
            }
            $amount = intval($product['amount']);
            if ($amount > $order_info['items'][$item_id]['amount'] - $order_info['items'][$item_id]['shipped_amount']) {
                return false;
            }
            $items[] = array('item_id' => $item_id, 'order_id' => $v['order_id'], 'product_id' => $order_info['items'][$item_id]['product_id'], 'amount' => $amount);
        }
        unset($v['products']);
        $v['products'] = $items;
        $shipments[] = $v;
    }
    return $shipments;
}