public function create($params) { $data = array(); $valid_params = true; $status = Response::STATUS_BAD_REQUEST; if (isset($params['shipping_ids']) && !isset($params['shipping_id'])) { $params['shipping_id'] = $params['shipping_ids']; } fn_clear_cart($cart, true); if (!empty($params['user_id'])) { $cart['user_data'] = fn_get_user_info($params['user_id']); } elseif (!empty($params['user_data'])) { $cart['user_data'] = $params['user_data']; } $cart['user_data'] = array_merge($cart['user_data'], $params); if (empty($params['user_id']) && empty($params['user_data'])) { $data['message'] = __('api_required_field', array('[field]' => 'user_id/user_data')); $valid_params = false; } elseif (empty($params['payment_id'])) { $data['message'] = __('api_required_field', array('[field]' => 'payment_id')); $valid_params = false; } if (empty($params['shipping_id'])) { $data['message'] = __('api_required_field', array('[field]' => 'shipping_id')); $valid_params = false; } if ($valid_params) { $cart['payment_id'] = $params['payment_id']; $customer_auth = fn_fill_auth($cart['user_data']); fn_add_product_to_cart($params['products'], $cart, $customer_auth); fn_calculate_cart_content($cart, $customer_auth); if (!empty($cart['product_groups']) && !empty($params['shipping_id'])) { foreach ($cart['product_groups'] as $key => $group) { foreach ($group['shippings'] as $shipping_id => $shipping) { if ($params['shipping_id'] == $shipping['shipping_id']) { $cart['chosen_shipping'][$key] = $shipping_id; break; } } } } $cart['calculate_shipping'] = true; fn_calculate_cart_content($cart, $customer_auth); if (empty($cart['shipping_failed']) || empty($params['shipping_id'])) { fn_update_payment_surcharge($cart, $customer_auth); list($order_id, ) = fn_place_order($cart, $customer_auth, 'save', $this->auth['user_id']); if (!empty($order_id)) { $status = Response::STATUS_CREATED; $data = array('order_id' => $order_id); } } } return array('status' => $status, 'data' => $data); }
function fn_mb_place_order($data) { define('SKIP_SESSION_VALIDATION', true); $order_id = 0; $mb_sess_id = base64_decode($data['mb_sess_id']); if (!empty($mb_sess_id)) { Session::resetId($mb_sess_id); $cart =& $_SESSION['cart']; $auth =& $_SESSION['auth']; list($order_id, $process_payment) = fn_place_order($cart, $auth); if (!empty($_REQUEST['order_id'])) { $data = array('order_id' => $order_id, 'type' => 'S', 'data' => TIME); db_query('REPLACE INTO ?:order_data ?e', $data); $data = array('order_id' => $order_id, 'type' => 'E', 'data' => $_REQUEST['inner_order_id']); db_query('REPLACE INTO ?:order_data ?e', $data); } } return $order_id; }
function fn_mb_place_order($data) { define('FORCE_SESSION_START', true); $order_id = 0; $mb_sess_id = base64_decode($data['mb_sess_id']); if (!empty($mb_sess_id)) { Tygh::$app['session']->resetID($mb_sess_id); $cart =& Tygh::$app['session']['cart']; $auth =& Tygh::$app['session']['auth']; list($order_id, $process_payment) = fn_place_order($cart, $auth); if (!empty($_REQUEST['order_id'])) { $data = array('order_id' => $order_id, 'type' => 'S', 'data' => TIME); db_query('REPLACE INTO ?:order_data ?e', $data); $data = array('order_id' => $order_id, 'type' => 'E', 'data' => $_REQUEST['inner_order_id']); db_query('REPLACE INTO ?:order_data ?e', $data); } } return $order_id; }
return array(CONTROLLER_STATUS_REDIRECT, "checkout.cart"); } if (!fn_allowed_for('ULTIMATE:FREE')) { $exceptions = fn_get_product_exceptions($v['product_id'], true); if (!isset($v['options_type']) || !isset($v['exceptions_type'])) { $v = array_merge($v, db_get_row('SELECT options_type, exceptions_type FROM ?:products WHERE product_id = ?i', $v['product_id'])); } if (!fn_is_allowed_options_exceptions($exceptions, $v['product_options'], $v['options_type'], $v['exceptions_type'])) { fn_set_notification('E', __('notice'), __('product_options_forbidden_combination', array('[product]' => $v['product']))); fn_delete_cart_product($cart, $k); return array(CONTROLLER_STATUS_REDIRECT, "checkout.cart"); } } } } list($order_id, $process_payment) = fn_place_order($cart, $auth); // Clean up saved shipping rates unset($_SESSION['product_groups']); if (!empty($order_id)) { if (empty($_REQUEST['skip_payment']) && $process_payment == true || !empty($_REQUEST['skip_payment']) && empty($auth['act_as_user'])) { // administrator, logged in as customer can skip payment $payment_info = !empty($cart['payment_info']) ? $cart['payment_info'] : array(); fn_start_payment($order_id, array(), $payment_info); } fn_order_placement_routines('route', $order_id); } else { return array(CONTROLLER_STATUS_REDIRECT, "checkout.cart"); } } if ($mode == 'update_steps') { $user_data = !empty($_REQUEST['user_data']) ? $_REQUEST['user_data'] : array();
function fn_call_requests_placing_order($params, $product_data, &$cart, &$auth) { // Save cart $buffer_cart = $cart; $buffer_auth = $auth; $cart = array('products' => array(), 'recalculate' => false, 'payment_id' => 0, 'is_call_request' => true); $firstname = $params['name']; $lastname = ''; $cart['user_data']['email'] = $params['email']; if (!empty($firstname) && strpos($firstname, ' ')) { list($firstname, $lastname) = explode(' ', $firstname); } $cart['user_data']['firstname'] = $firstname; $cart['user_data']['b_firstname'] = $firstname; $cart['user_data']['s_firstname'] = $firstname; $cart['user_data']['lastname'] = $lastname; $cart['user_data']['b_lastname'] = $lastname; $cart['user_data']['s_lastname'] = $lastname; $cart['user_data']['phone'] = $params['phone']; $cart['user_data']['b_phone'] = $params['phone']; $cart['user_data']['s_phone'] = $params['phone']; foreach (array('b_address', 's_address', 'b_city', 's_city', 'b_country', 's_country', 'b_state', 's_state') as $key) { if (!isset($cart['user_data'][$key])) { $cart['user_data'][$key] = ' '; } } if (empty($product_data[$params['product_id']])) { $product_data[$params['product_id']] = array('product_id' => $params['product_id'], 'amount' => 1); } fn_add_product_to_cart($product_data, $cart, $auth); fn_calculate_cart_content($cart, $auth, 'A', true, 'F', true); $order_id = 0; if ($res = fn_place_order($cart, $auth)) { list($order_id) = $res; } // Restore cart $cart = $buffer_cart; $auth = $buffer_auth; return $order_id; }
function heartlandplace_order($original_order_id) { $cart =& $_SESSION['cart']; $auth =& $_SESSION['auth']; list($order_id, $process_payment) = fn_place_order($cart, $auth); $data = array('order_id' => $order_id, 'type' => 'S', 'data' => TIME); db_query('REPLACE INTO ?:order_data ?e', $data); $data = array('order_id' => $order_id, 'type' => 'E', 'data' => $original_order_id); db_query('REPLACE INTO ?:order_data ?e', $data); return $order_id; }
/** * Place order handler * * @param array $cart Cart * @param array $auth Auth * @param array $params Params * @return str */ function fn_checkout_place_order(&$cart, &$auth, $params) { // Prevent unauthorized access if (empty($cart['user_data']['email'])) { return PLACE_ORDER_STATUS_DENIED; } // Prevent using disabled payment method by challenging HTTP data if (!empty($params['payment_id'])) { $cart['payment_id'] = $params['payment_id']; } if (isset($cart['payment_id'])) { $payment_method_data = fn_get_payment_method_data($cart['payment_id']); if (!empty($payment_method_data['status']) && $payment_method_data['status'] != 'A') { return PLACE_ORDER_STATUS_DENIED; } } // Remove previous failed order if (!empty($cart['failed_order_id']) || !empty($cart['processed_order_id'])) { $_order_ids = !empty($cart['failed_order_id']) ? $cart['failed_order_id'] : $cart['processed_order_id']; foreach ($_order_ids as $_order_id) { fn_delete_order($_order_id); } $cart['rewrite_order_id'] = $_order_ids; unset($cart['failed_order_id'], $cart['processed_order_id']); } if (!empty($params['payment_info'])) { $cart['payment_info'] = $params['payment_info']; } else { $cart['payment_info'] = array(); } if (empty($params['payment_info']) && !empty($cart['extra_payment_info'])) { $cart['payment_info'] = empty($cart['payment_info']) ? array() : $cart['payment_info']; $cart['payment_info'] = array_merge($cart['extra_payment_info'], $cart['payment_info']); } unset($cart['payment_info']['secure_card_number']); if (!empty($cart['products'])) { foreach ($cart['products'] as $cart_id => $product) { $_is_edp = db_get_field("SELECT is_edp FROM ?:products WHERE product_id = ?i", $product['product_id']); if (fn_check_amount_in_stock($product['product_id'], $product['amount'], empty($product['product_options']) ? array() : $product['product_options'], $cart_id, $_is_edp, 0, $cart) == false) { fn_delete_cart_product($cart, $cart_id); return PLACE_ORDER_STATUS_TO_CART; } if (!fn_allowed_for('ULTIMATE:FREE')) { $exceptions = fn_get_product_exceptions($product['product_id'], true); if (!isset($product['options_type']) || !isset($product['exceptions_type'])) { $product = array_merge($product, db_get_row('SELECT options_type, exceptions_type FROM ?:products WHERE product_id = ?i', $product['product_id'])); } if (!fn_is_allowed_options_exceptions($exceptions, $product['product_options'], $product['options_type'], $product['exceptions_type'])) { fn_set_notification('E', __('notice'), __('product_options_forbidden_combination', array('[product]' => $product['product']))); fn_delete_cart_product($cart, $cart_id); return PLACE_ORDER_STATUS_TO_CART; } if (!fn_is_allowed_options($product)) { fn_set_notification('E', __('notice'), __('product_disabled_options', array('[product]' => $product['product']))); fn_delete_cart_product($cart, $cart_id); return PLACE_ORDER_STATUS_TO_CART; } } } } list($order_id, $process_payment) = fn_place_order($cart, $auth); // Clean up saved shipping rates unset($_SESSION['product_groups']); if (!empty($order_id)) { if (empty($params['skip_payment']) && $process_payment == true || !empty($params['skip_payment']) && empty($auth['act_as_user'])) { // administrator, logged in as customer can skip payment $payment_info = !empty($cart['payment_info']) ? $cart['payment_info'] : array(); fn_start_payment($order_id, array(), $payment_info); } fn_order_placement_routines('route', $order_id); return PLACE_ORDER_STATUS_OK; } else { return PLACE_ORDER_STATUS_TO_CART; } }
* * **************************************************************************** * PLEASE READ THE FULL TEXT OF THE SOFTWARE LICENSE AGREEMENT IN THE * * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE. * ****************************************************************************/ if (!defined('BOOTSTRAP')) { require './../../../../payments/init_payment.php'; } if ($mode == 'in_context_order') { $token = $_REQUEST['token']; $payment_id = $_REQUEST['payment_id']; $payment_method_data = fn_get_payment_method_data($payment_id); $paypal_checkout_details = fn_paypal_get_express_checkout_details($payment_method_data, $token); if (fn_paypal_ack_success($paypal_checkout_details)) { fn_paypal_user_login($paypal_checkout_details); list($order_id, $status) = fn_place_order(Tygh::$app['session']['cart'], Tygh::$app['session']['auth']); fn_paypal_mark_in_context_payment_started($order_id); $order_info = fn_get_order_info($order_id); $processor_data = fn_get_processor_data($payment_id); fn_pp_save_mode($order_info); fn_paypal_complete_checkout($token, $processor_data, $order_info); } else { fn_paypal_get_error($paypal_checkout_details); fn_order_placement_routines('checkout_redirect'); } } elseif ($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)) {
function fn_get_ebay_orders($cart, $customer_auth) { $success_orders = $failed_orders = array(); setlocale(LC_TIME, 'en_US'); $params = array('OrderStatus' => 'All'); $last_transaction = db_get_field('SELECT timestamp FROM ?:ebay_cached_transactions WHERE type = ?s AND status = ?s ORDER BY timestamp DESC', 'orders', 'C'); // Need user_id if (!empty($last_transaction)) { $params['CreateTimeFrom'] = gmstrftime("%Y-%m-%dT%H:%M:%S", $last_transaction); $params['CreateTimeTo'] = gmstrftime("%Y-%m-%dT%H:%M:%S", TIME); } $data = array('timestamp' => TIME, 'user_id' => $_SESSION['auth']['user_id'], 'session_id' => Session::getId(), 'status' => 'A', 'type' => 'orders', 'result' => '', 'site_id' => 0); $transaction_id = db_query('INSERT INTO ?:ebay_cached_transactions ?e', $data); list(, $ebay_orders) = Ebay::instance()->GetOrders($params); $data = array('status' => 'C', 'result' => count($ebay_orders)); db_query('UPDATE ?:ebay_cached_transactions SET ?u WHERE transaction_id = ?i', $data, $transaction_id); if (!empty($ebay_orders)) { foreach ($ebay_orders as $k => $v) { $order_status = $v['OrderStatus'] == 'Completed' ? 'P' : 'O'; $cart = array(); fn_clear_cart($cart, true); $item_transactions = $v['TransactionArray']; $_cart = $products = array(); if (!is_array($item_transactions)) { $item_transactions = $item_transactions->Transaction; } $i = 1; foreach ($item_transactions as $item) { $email = (string) $item->Buyer->Email; break; } $shipping_address = $v['ShippingAddress']; $customer_name = explode(' ', (string) $shipping_address->Name); $firstname = array_shift($customer_name); $lastname = implode(' ', $customer_name); $_cart = array('user_id' => 0, 'company_id' => Registry::get('runtime.company_id'), 'email' => $email, 'ebay_order_id' => $v['OrderID'], 'timestamp' => strtotime($v['CreatedTime']), 'payment_id' => 0, 'user_data' => array('firstname' => $firstname, 'lastname' => $lastname, 'phone' => (string) $shipping_address->Phone, 'country' => (string) $shipping_address->Country, 's_firstname' => $firstname, 's_lastname' => $lastname, 's_address' => (string) $shipping_address->Street1, 's_city' => (string) $shipping_address->CityName, 's_state' => (string) $shipping_address->StateOrProvince, 's_country' => (string) $shipping_address->Country, 's_phone' => (string) $shipping_address->Phone, 's_zipcode' => (string) $shipping_address->PostalCode, 'b_firstname' => $firstname, 'b_lastname' => $lastname, 'b_address' => (string) $shipping_address->Street1, 'b_city' => (string) $shipping_address->CityName, 'b_state' => (string) $shipping_address->StateOrProvince, 'b_country' => (string) $shipping_address->Country, 'b_phone' => (string) $shipping_address->Phone, 'b_zipcode' => (string) $shipping_address->PostalCode), 'notes' => '', 'payment_info' => array(), 'calculate_shipping' => false, 'shipping_required' => false); $cart = fn_array_merge($cart, $_cart); foreach ($item_transactions as $item) { $_item = (array) $item->Item; $product_id = db_get_field('SELECT product_id FROM ?:ebay_template_products WHERE ebay_item_id = ?i', $_item['ItemID']); // Need check company_id if (!$product_id) { continue; } $product = fn_get_product_data($product_id, $cart['user_data']); $extra = array('product_options' => array()); $options = db_get_array('SELECT ?:product_options.option_id, ?:product_options_descriptions.option_name, ?:product_option_variants_descriptions.variant_id, ?:product_option_variants_descriptions.variant_name FROM ?:product_options JOIN ?:product_option_variants ON ?:product_option_variants.option_id = ?:product_options.option_id JOIN ?:product_options_descriptions ON ?:product_options_descriptions.option_id = ?:product_options.option_id JOIN ?:product_option_variants_descriptions ON ?:product_option_variants_descriptions.variant_id = ?:product_option_variants.variant_id WHERE product_id =?i', $product_id); if (isset($item->Variation)) { $variations_xml = (array) $item->Variation->VariationSpecifics; if (isset($variations_xml['NameValueList']->Name)) { $variations = (array) $variations_xml['NameValueList']; } else { foreach ($variations_xml['NameValueList'] as $variation) { $variations[] = (array) $variation; } } if (isset($variations)) { if (isset($variations['Name'])) { foreach ($options as $option) { if ($variations['Name'] == $option['option_name'] && $variations['Value'] == $option['variant_name']) { $extra['product_options'][$option['option_id']] = $option['variant_id']; } } } else { foreach ($variations as $variation) { foreach ($options as $option) { if ($variation['Name'] == $option['option_name'] && $variation['Value'] == $option['variant_name']) { $extra['product_options'][$option['option_id']] = $option['variant_id']; } } } } $variations = array(); } } $products[$i] = array('product_id' => $product_id, 'amount' => (int) $item->QuantityPurchased, 'price' => (double) $item->TransactionPrice, 'base_price' => (double) $item->TransactionPrice, 'is_edp' => $product['is_edp'], 'edp_shipping' => $product['edp_shipping'], 'free_shipping' => $product['free_shipping'], 'stored_price' => 'Y', 'company_id' => Registry::get('runtime.company_id'), 'extra' => $extra); unset($product); $i += 1; } if (empty($products)) { continue; } $cart['products'] = $products; unset($products); fn_calculate_cart_content($cart, $customer_auth, 'S', false, 'F', false); $cart['shipping_failed'] = false; $cart['company_shipping_failed'] = false; $cart['shipping_cost'] = $cart['display_shipping_cost'] = (double) $v['ShippingServiceSelected']->ShippingServiceCost; $cart['total'] = $v['Total']; $cart['subtotal'] = $v['Subtotal']; list($order_id, $process_payment) = fn_place_order($cart, $customer_auth); if (!empty($order_id)) { fn_change_order_status($order_id, $order_status, false); $success_orders[] = $order_id; } else { $failed_orders[] = $cart['ebay_order_id']; } } } return array($success_orders, $failed_orders); }
function fn_prepare_to_place_order(&$xml_data, &$cart, &$auth) { // Update user info $bill = $ship = $xml_data->ProcessedOrder->ShippingAddress; $b_customer_name = $s_customer_name = (string) $bill->Name; $cart['user_data'] = array_merge($cart['user_data'], array('firstname' => substr($s_customer_name, 0, strpos($s_customer_name, ' ')), 'lastname' => substr($s_customer_name, strpos($s_customer_name, ' ')), 'email' => (string) $xml_data->ProcessedOrder->BuyerInfo->BuyerEmailAddress, 'b_firstname' => substr($b_customer_name, 0, strpos($b_customer_name, ' ')), 'b_lastname' => substr($b_customer_name, strpos($b_customer_name, ' ')), 'b_address' => (string) $bill->AddressFieldOne, 'b_address_2' => (string) $bill->AddressFieldTwo, 'b_city' => (string) $bill->City, 'b_country' => (string) $bill->CountryCode, 'b_zipcode' => (string) $bill->PostalCode, 's_firstname' => substr($s_customer_name, 0, strpos($s_customer_name, ' ')), 's_lastname' => substr($s_customer_name, strpos($s_customer_name, ' ')), 's_address' => (string) $ship->AddressFieldOne, 's_address_2' => (string) $ship->AddressFieldTwo, 's_city' => (string) $ship->City, 's_country' => (string) $ship->CountryCode, 's_zipcode' => (string) $ship->PostalCode)); // Update shipping info $selected_shipping = (string) $xml_data->ProcessedOrder->DisplayableShippingLabel; $selected_shipping = preg_replace('/\\(' . __('price_includes_tax') . '.*/i', '', $selected_shipping); $shipping_id = db_get_field('SELECT shipping_id FROM ?:shipping_descriptions WHERE shipping = ?s AND lang_code = ?s', trim($selected_shipping), CART_LANGUAGE); $order_items = array(); $_order_items = $xml_data->ProcessedOrder->ProcessedOrderItems; foreach ($_order_items->ProcessedOrderItem as $item) { $order_items[] = $item; } // Calculate total shipping cost $total = sizeof($order_items); $shipping_total = 0; for ($i = 0; $i < $total; $i++) { $elm = $order_items[$i]; $attrs = $elm->ItemCharges; $components = array(); if (!empty($attrs)) { foreach ($attrs->Component as $attr) { $components[] = $attr; } } $attrs_total = sizeof($components); for ($j = 0; $j < $attrs_total; $j++) { $attr = $components[$j]; if (trim((string) $attr->Type) == 'Shipping') { $shipping_total += (string) $attr->Charge->Amount; } } } $cart['recalculate'] = true; list($cart_products, $product_groups) = fn_calculate_cart_content($cart, $auth, 'A', true, 'F', true); foreach ($product_groups as $group_key => $group) { foreach ($group['shippings'] as $sh_id => $shipping) { if ($shipping['shipping_id'] == $shipping_id) { $cart['chosen_shipping'][$group_key] = $sh_id; } } } $cart['payment_id'] = db_get_field("SELECT a.payment_id FROM ?:payments as a LEFT JOIN ?:payment_processors as b ON a.processor_id = b.processor_id WHERE b.processor_script = ?s", 'amazon_checkout.php'); list($order_id) = fn_place_order($cart, $auth, 'save'); // This string is here because payment_cc.php file wasn't executed db_query("REPLACE INTO ?:order_data (order_id, type, data) VALUES (?i, 'S', ?i)", $order_id, TIME); return $order_id; }
function fn_place_suborders($order_id, $cart, &$auth, $action, $issuer_id) { $order_ids = array(); $rewrite_order_id = empty($cart['rewrite_order_id']) ? array() : $cart['rewrite_order_id']; foreach ($cart['product_groups'] as $key_group => $group) { $_cart = $cart; $total_products_price = 0; $total_shipping_cost = 0; $total_company_part = 0; foreach ($group['products'] as $product) { $total_products_price += $product['price']; } foreach ($_cart['products'] as $cart_id => $product) { if (!in_array($cart_id, array_keys($group['products']))) { unset($_cart['products'][$cart_id]); } } if (!empty($_cart['chosen_shipping'][$key_group])) { $chosen_shipping_id = $_cart['chosen_shipping'][$key_group]; if (empty($group['chosen_shippings'])) { $total_shipping_cost += $group['shippings'][$chosen_shipping_id]['rate']; } else { foreach ($group['chosen_shippings'] as $shipping) { $total_shipping_cost += $shipping['rate']; } } $_cart['chosen_shipping'] = array($chosen_shipping_id); } else { $_cart['chosen_shipping'] = array(); } $cost = $cart['subtotal'] + $cart['shipping_cost']; if (!$cost) { $cost = 1; } $total_company_part = ($total_products_price + $total_shipping_cost) * 100 / $cost; $_cart['payment_surcharge'] = $total_company_part * $cart['payment_surcharge'] / 100; $_cart['recalculate'] = true; if (empty($_cart['stored_shipping'])) { $_cart['calculate_shipping'] = true; } $_cart['rewrite_order_id'] = array(); if ($next_id = array_shift($rewrite_order_id)) { $_cart['rewrite_order_id'][] = $next_id; } $_cart['company_id'] = $group['company_id']; $_cart['parent_order_id'] = $order_id; fn_calculate_cart_content($_cart, $auth); fn_calculate_payment_taxes($_cart, $auth); $_cart['product_groups'] = array($group); fn_set_hook('place_suborders', $cart, $_cart); list($order_ids[], ) = fn_place_order($_cart, $auth, $action, $issuer_id, $order_id); } return $order_ids; }
function importOrders() { ini_set('max_execution_time', 0); $this->useDatabase($this->sourceDB); //main link used for selecting orders $query = "SELECT * FROM shop_orders ORDER BY id DESC"; $result = mysqli_query($this->link, $query) or die('Failed to select items: ' . mysqli_error($this->link)); //lineLink for selecting order lines (ordered products) $lineLink = mysqli_connect($this->config['db_host'], $this->config['db_user'], $this->config['db_password']) or die('Database connection error. ' . mysqli_error($this->link)); $this->useDatabase($this->sourceDB, $lineLink); //destLink used to update timestamp for migrated orders $destLink = mysqli_connect($this->config['db_host'], $this->config['db_user'], $this->config['db_password']) or die('Database connection error. ' . mysqli_error($this->link)); $this->useDatabase($this->destinationDB, $destLink); while ($order = mysqli_fetch_array($result, MYSQL_ASSOC)) { $products = array(); $lineResult = mysqli_query($lineLink, "SELECT * FROM shop_cart WHERE order_id = {$order['id']}"); var_dump(mysqli_error($lineLink)); while ($line = mysqli_fetch_array($lineResult, MYSQL_ASSOC)) { echo $line['item_id'] . "<br>"; $products[$line['id']] = array('product_id' => $line['item_id'], 'amount' => $line['quantity'], 'price' => $line['price_in_order']); } $timestamp = strtotime($order['date']); $cart = array('products' => $products, 'recalculate' => false, 'user_data' => array('user_id' => $order['member_id'], 'firstname' => $order['name'], 'lastname' => $order['surname'], 'b_country' => $order['country'] == 'Россия' ? 'RU' : '', 's_country' => $order['country'] == 'Россия' ? 'RU' : '', 's_address' => $order['adress'], 'b_address' => $order['adress'], 's_zipcode' => $order['index'], 'b_zipcode' => $order['index'], 's_city' => $order['city'], 'b_city' => $order['city'], 's_phone' => $order['phone'], 'b_phone' => $order['phone'], 'email' => $order['email'], 'fields' => array(35 => $order['phone'], 39 => $order['usercomment'], 64 => $order['comment'])), 'subtotal' => $order['total'], 'original_subtotal' => $order['total'], 'display_subtotal' => $order['total'], 'total' => $order['total'] + $order['delivery_cost'], 'shipping_cost' => $order['delivery_cost'], 'display_shipping_cost' => $order['delivery_cost'], 'timestamp' => $timestamp, 'order_id' => $order['id'], 'status' => 'C'); $auth = array('user_id' => $order['member_id']); if (fn_place_order($cart, $auth)) { $lineResult = mysqli_query($destLink, "UPDATE cscart_orders SET timestamp={$timestamp}, status = 'C' WHERE order_id = {$order['id']}"); } } }
function fn_prepare_to_place_order(&$xml_data, &$cart, &$auth) { // Update user info $bill = $xml_data->getElementByName("buyer-billing-address"); $ship = $xml_data->getElementByName("buyer-shipping-address"); $b_customer_name = $bill->getValueByPath("/contact-name"); $s_customer_name = $ship->getValueByPath("/contact-name"); $phone = $ship->getValueByPath('/phone') != '' ? $ship->getValueByPath('/phone') : $bill->getValueByPath('/phone'); $cart['user_data'] = array('firstname' => substr($s_customer_name, 0, strpos($s_customer_name, ' ')), 'lastname' => substr($s_customer_name, strpos($s_customer_name, ' ')), 'email' => $ship->getValueByPath('/email'), 'phone' => $phone, 'b_firstname' => substr($b_customer_name, 0, strpos($b_customer_name, ' ')), 'b_lastname' => substr($b_customer_name, strpos($b_customer_name, ' ')), 'b_address' => $bill->getValueByPath('/address1'), 'b_address_2' => $bill->getValueByPath('/address2'), 'b_city' => $bill->getValueByPath('/city'), 'b_state' => $bill->getValueByPath('/region'), 'b_country' => $bill->getValueByPath('/country-code'), 'b_zipcode' => $bill->getValueByPath('/postal-code'), 's_firstname' => substr($s_customer_name, 0, strpos($s_customer_name, ' ')), 's_lastname' => substr($s_customer_name, strpos($s_customer_name, ' ')), 's_address' => $ship->getValueByPath('/address1'), 's_address_2' => $ship->getValueByPath('/address2'), 's_city' => $ship->getValueByPath('/city'), 's_state' => $ship->getValueByPath('/region'), 's_country' => $ship->getValueByPath('/country-code'), 's_zipcode' => $ship->getValueByPath('/postal-code')); // Find whether coupons or gift certificates are used. fn_get_google_codes($cart, $xml_data); // Find whether surcharge is used $itm = $xml_data->getElementByPath('/shopping-cart/items'); $items = $itm->getElementsByName('item'); $total = sizeof($items); for ($i = 0; $i < $total; $i++) { if ($items[$i]->getValueByPath('/item-name') == fn_get_lang_var('surcharge')) { $cart['payment_surcharge'] = $items[$i]->getValueByPath('/unit-price'); } } // Update shipping info $order_adj = $xml_data->getElementByName("order-adjustment"); if ($order_adj->getElementByPath('/shipping/merchant-calculated-shipping-adjustment')) { $order_shipping = $order_adj->getValueByPath('/shipping/merchant-calculated-shipping-adjustment/shipping-name'); $gc_shippings = $xml_data->getElementByPath('shopping-cart/merchant-private-data/additional_data/shippings'); if ($gc_shippings) { $gc_methods = $gc_shippings->getElementsByName('method'); $gc_methods_total = sizeof($gc_methods); for ($k = 0; $k < $gc_methods_total; $k++) { if ($gc_methods[$k]->getAttribute('name') == $order_shipping) { $id = $gc_methods[$k]->getAttribute('id'); fn_fill_google_shipping_info($id, $cart, $order_adj, $order_shipping); break; } } } } $cart['recalculate'] = true; fn_calculate_cart_content($cart, $auth, 'A', true, 'I', true); $cart['payment_id'] = db_get_field("SELECT a.payment_id FROM ?:payments as a LEFT JOIN ?:payment_processors as b ON a.processor_id = b.processor_id WHERE b.processor_script = 'google_checkout.php'"); list($order_id) = fn_place_order($cart, $auth, 'save'); // This string is here because payment_cc.php file wasn't executed db_query("REPLACE INTO ?:order_data (order_id, type, data) VALUES (?i, 'S', ?i)", $order_id, TIME); return $order_id; }
protected function placeOrder($ym_order_id, $payment_data, $address, $notes) { $this->cart['yandex_market'] = array('order_id' => $ym_order_id, 'payment_type' => $payment_data['type'], 'payment_method' => $payment_data['method'], 'address' => $address); $this->cart['yml_order_id'] = $ym_order_id; // need for search $this->cart['notes'] = $notes; $this->cart['payment_id'] = 0; // skip payment if ($res = fn_place_order($this->cart, $this->auth)) { list($order_id) = $res; return $order_id; } return false; }
if ($mode == 'place_order') { // Clean up saved shipping rates unset($_SESSION['shipping_rates']); // update totals and etc. fn_update_cart_by_data($cart, $_REQUEST, $customer_auth); if (!empty($_REQUEST['shipping_ids'])) { fn_checkout_update_shipping($cart, $_REQUEST['shipping_ids']); } if (empty($cart['stored_shipping'])) { $cart['calculate_shipping'] = true; } // recalculate cart content after update list($cart_products, $product_groups) = fn_calculate_cart_content($cart, $customer_auth); $cart['notes'] = !empty($_REQUEST['customer_notes']) ? $_REQUEST['customer_notes'] : ''; $cart['payment_info'] = !empty($_REQUEST['payment_info']) ? $_REQUEST['payment_info'] : array(); list($order_id, $process_payment) = fn_place_order($cart, $customer_auth, $action, $auth['user_id']); if (!empty($order_id)) { if ($action != 'save') { $action = 'route'; } if ($process_payment == true) { $payment_info = !empty($cart['payment_info']) ? $cart['payment_info'] : array(); fn_start_payment($order_id, fn_get_notification_rules($_REQUEST), $payment_info); } if (!empty($_REQUEST['update_order']['details'])) { db_query('UPDATE ?:orders SET details = ?s WHERE order_id = ?i', $_REQUEST['update_order']['details'], $order_id); } $notification_rules = fn_get_notification_rules($_REQUEST); // change status if it posted if (!empty($_REQUEST['order_status'])) { $order_info = fn_get_order_short_info($order_id);
public static function apiPlaceOrder($data, &$response, $lang_code = CART_LANGUAGE) { $cart =& $_SESSION['cart']; $auth =& $_SESSION['auth']; if (empty($cart)) { $response->addError('ERROR_ACCESS_DENIED', __('access_denied', $lang_code)); $response->returnResponse(); } if (!empty($data['user'])) { fn_twg_api_set_cart_user_data($data['user'], $response, $lang_code); } if (empty($auth['user_id']) && empty($cart['user_data'])) { $response->addError('ERROR_ACCESS_DENIED', __('access_denied', $lang_code)); $response->returnResponse(); } if (empty($data['payment_info']) && !empty($cart['extra_payment_info'])) { $data['payment_info'] = $cart['extra_payment_info']; } if (!empty($data['payment_info'])) { $cart['payment_id'] = (int) $data['payment_info']['payment_id']; unset($data['payment_info']['payment_id']); if (!empty($data['payment_info'])) { $cart['payment_info'] = $data['payment_info']; } unset($cart['payment_updated']); fn_update_payment_surcharge($cart, $auth); fn_save_cart_content($cart, $auth['user_id']); } unset($cart['payment_info']['secure_card_number']); // Remove previous failed order if (!empty($cart['failed_order_id']) || !empty($cart['processed_order_id'])) { $_order_ids = !empty($cart['failed_order_id']) ? $cart['failed_order_id'] : $cart['processed_order_id']; foreach ($_order_ids as $_order_id) { fn_delete_order($_order_id); } $cart['rewrite_order_id'] = $_order_ids; unset($cart['failed_order_id'], $cart['processed_order_id']); } if (!empty($data['shippings'])) { if (!fn_checkout_update_shipping($cart, $data['shippings'])) { unset($cart['shipping']); } } Registry::set('runtime.controller', 'checkout', true); list(, $_SESSION['shipping_rates']) = fn_calculate_cart_content($cart, $auth, 'E'); Registry::set('runtime.controller', 'twigmo'); if (empty($cart['shipping']) && $cart['shipping_failed']) { $response->addError('ERROR_WRONG_CHECKOUT_DATA', __('wrong_shipping_info', $lang_code)); $response->returnResponse(); } if (empty($cart['payment_info']) && !isset($cart['payment_id'])) { $response->addError('ERROR_WRONG_CHECKOUT_DATA', __('wrong_payment_info', $lang_code)); $response->returnResponse(); } if (!empty($data['notes'])) { $cart['notes'] = $data['notes']; } $cart['details'] = fn_twg_get_twigmo_order_note(); Registry::set('runtime.controller', 'checkout', true); list($order_id, $process_payment) = fn_place_order($cart, $auth); Registry::set('runtime.controller', 'twigmo'); if (empty($order_id)) { return false; } if ($process_payment == true) { $payment_info = !empty($cart['payment_info']) ? $cart['payment_info'] : array(); Registry::set('runtime.mode', 'place_order'); fn_start_payment($order_id, array(), $payment_info); } self::orderPlacementRoutines($order_id); return $order_id; }
function fn_charge_subscription($subscription_id) { $_SESSION['cart'] = isset($_SESSION['cart']) ? $_SESSION['cart'] : array(); $cart =& $_SESSION['cart']; $_SESSION['customer_auth'] = isset($_SESSION['customer_auth']) ? $_SESSION['customer_auth'] : array(); $customer_auth =& $_SESSION['customer_auth']; fn_clear_cart($cart, true); $customer_auth = fn_fill_auth(); $subscription = fn_get_recurring_subscription_info($subscription_id); if ($subscription['status'] != 'A') { fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('rb_subscription_inactive')); } else { $product_data = array(); foreach ($subscription['order_info']['items'] as $k => $item) { if (!empty($subscription['order_info']['items'][$k]['extra']['recurring_plan_id']) && $subscription['order_info']['items'][$k]['extra']['recurring_plan_id'] == $subscription['plan_id'] && $subscription['order_info']['items'][$k]['extra']['recurring_duration'] == $subscription['orig_duration']) { $product_data[$subscription['order_info']['items'][$k]['product_id']] = array('amount' => $subscription['order_info']['items'][$k]['amount'], 'extra' => array('recurring_plan_id' => $subscription['plan_id'], 'recurring_force_calculate' => true, 'recurring_subscription_id' => $subscription['subscription_id'], 'recurring_plan' => $subscription['order_info']['items'][$k]['extra']['recurring_plan'], 'recurring_duration' => $subscription['order_info']['items'][$k]['extra']['recurring_duration'])); if (!empty($subscription['order_info']['items'][$k]['extra']['product_options'])) { $product_data[$subscription['order_info']['items'][$k]['product_id']]['product_options'] = $subscription['order_info']['items'][$k]['extra']['product_options']; } } } $cart['user_id'] = $subscription['user_id']; $u_data = db_get_row("SELECT user_id, user_type, tax_exempt FROM ?:users WHERE user_id = ?i", $cart['user_id']); $customer_auth = fn_fill_auth($u_data); $cart['user_data'] = array(); fn_add_product_to_cart($product_data, $cart, $customer_auth); $cart['profile_id'] = 0; $cart['user_data'] = fn_get_user_info($customer_auth['user_id'], true, $cart['profile_id']); if (!empty($cart['user_data'])) { $profile_fields = fn_get_profile_fields('O', $customer_auth); $cart['ship_to_another'] = fn_check_shipping_billing($cart['user_data'], $profile_fields); } fn_calculate_cart_content($cart, $customer_auth, 'A', true, 'I'); $cart['payment_id'] = $subscription['order_info']['payment_id']; $cart['payment_info'] = $subscription['order_info']['payment_info']; $cart['recurring_subscription_id'] = $subscription_id; list($order_id, $process_payment) = fn_place_order($cart, $customer_auth); if (!empty($order_id)) { $order_info = fn_get_order_info($order_id, true); $evt_data = array('subscription_id' => $subscription_id, 'timestamp' => $order_info['timestamp'], 'event_type' => 'C'); db_query("INSERT INTO ?:recurring_events ?e", $evt_data); if ($process_payment == true) { fn_start_payment($order_id); } $edp_data = fn_generate_ekeys_for_edp(array(), $order_info); fn_order_notification($order_info, $edp_data); } } }