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; }
$cart['edit_step'] = 'step_two'; } } } // Final step $final_step = 'step_four'; if (!$display_steps['step_four']) { $final_step = 'step_three'; if (!$display_steps['step_three']) { $final_step = 'step_two'; } } Tygh::$app['view']->assign('final_step', $final_step); $cart['user_data'] = !empty($cart['user_data']) ? $cart['user_data'] : array(); if (!empty($_REQUEST['shipping_ids'])) { fn_checkout_update_shipping($cart, $_REQUEST['shipping_ids']); } if (!empty($_REQUEST['payment_id'])) { $cart['payment_id'] = $_REQUEST['payment_id']; } elseif (empty($cart['payment_id'])) { $params = array('usergroup_ids' => $auth['usergroup_ids']); $payments = fn_get_payments($params); $first_method = reset($payments); $cart['payment_id'] = $first_method['payment_id']; } if (isset($cart['payment_id'])) { $cart['payment_method_data'] = fn_get_payment_method_data($cart['payment_id']); } if (!empty($auth['user_id'])) { //if the error occurred during registration, but despite this, the registration was performed, then the variable should be cleared. unset($_SESSION['failed_registration']);
Storage::instance('custom_files')->get($file['path'], $file['name']); } } elseif ($mode == 'delete_file' && isset($_REQUEST['cart_id'])) { if (isset($cart['products'][$_REQUEST['cart_id']]['extra']['custom_files'][$_REQUEST['option_id']][$_REQUEST['file']])) { // Delete saved custom file $file = $cart['products'][$_REQUEST['cart_id']]['extra']['custom_files'][$_REQUEST['option_id']][$_REQUEST['file']]; Storage::instance('custom_files')->delete($file['path']); Storage::instance('custom_files')->delete($file['path'] . '_thumb'); unset($cart['products'][$_REQUEST['cart_id']]['extra']['custom_files'][$_REQUEST['option_id']][$_REQUEST['file']]); } fn_save_cart_content($cart, $customer_auth['user_id']); return array(CONTROLLER_STATUS_REDIRECT, "order_management.{$_suffix}"); } elseif ($mode == 'update_payment') { // // Update payment method // $cart['payment_id'] = !empty($_REQUEST['payment_id']) ? $_REQUEST['payment_id'] : 0; return array(CONTROLLER_STATUS_REDIRECT, "order_management.{$_suffix}"); } elseif ($mode == 'update_shipping' && isset($_REQUEST['shipping_id'])) { // // Update shipping method // $supplier_id = !empty($_REQUEST['supplier_id']) ? $_REQUEST['supplier_id'] : 0; fn_checkout_update_shipping($cart, array($supplier_id => $_REQUEST['shipping_id'])); return array(CONTROLLER_STATUS_REDIRECT, "order_management.{$_suffix}"); } Registry::get('view')->assign('cart', $cart); if (!Registry::get('view')->getTemplateVars('user_data') && !empty($cart['user_data'])) { Registry::get('view')->assign('user_data', $cart['user_data']); } Registry::get('view')->assign('customer_auth', $customer_auth);
/** * Update steps data handler * * @param array $cart Cart * @param array $auth Auth * @param array $params Params * @return array */ function fn_checkout_update_steps(&$cart, &$auth, $params) { $redirect_params = array(); $user_data = !empty($params['user_data']) ? $params['user_data'] : array(); unset($user_data['user_type']); if (!empty($auth['user_id'])) { if (isset($user_data['profile_id'])) { if (empty($user_data['profile_id'])) { $user_data['profile_type'] = 'S'; } $profile_id = $user_data['profile_id']; } elseif (!empty($cart['profile_id'])) { $profile_id = $cart['profile_id']; } else { $profile_id = db_get_field("SELECT profile_id FROM ?:user_profiles WHERE user_id = ?i AND profile_type = 'P'", $auth['user_id']); } $user_data['user_id'] = $auth['user_id']; $current_user_data = fn_get_user_info($auth['user_id'], true, $profile_id); if ($profile_id != NULL) { $cart['profile_id'] = $profile_id; } $errors = false; // Update contact information if (($params['update_step'] == 'step_one' || $params['update_step'] == 'step_two') && !empty($user_data['email'])) { // Check email $email_exists = fn_is_user_exists($auth['user_id'], $user_data); if (!empty($email_exists)) { fn_set_notification('E', __('error'), __('error_user_exists')); $redirect_params['edit_step'] = $params['update_step']; $errors = true; $params['next_step'] = $params['update_step']; } } // Update billing/shipping information if ($params['update_step'] == 'step_two' || $params['update_step'] == 'step_one' && !$errors) { if (!empty($user_data)) { $user_data = fn_array_merge($current_user_data, $user_data); $user_data['user_type'] = !empty($current_user_data['user_type']) ? $current_user_data['user_type'] : AREA; $user_data = fn_fill_contact_info_from_address($user_data); } $user_data = fn_array_merge($current_user_data, $user_data); if (empty($params['ship_to_another'])) { $profile_fields = fn_get_profile_fields('O'); fn_fill_address($user_data, $profile_fields); } // Check if we need to send notification with new email to customer $email = db_get_field('SELECT email FROM ?:users WHERE user_id = ?i', $auth['user_id']); $send_notification = false; if (isset($user_data['email']) && $user_data['email'] != $email) { $send_notification = true; } list($user_id, $profile_id) = fn_update_user($auth['user_id'], $user_data, $auth, !empty($params['ship_to_another']), $send_notification, false); $cart['profile_id'] = $profile_id; } // Add/Update additional fields if (!empty($user_data['fields'])) { fn_store_profile_fields($user_data, array('U' => $auth['user_id'], 'P' => $profile_id), 'UP'); // FIXME } } elseif (Registry::get('settings.Checkout.disable_anonymous_checkout') != 'Y') { if (empty($auth['user_id']) && !empty($user_data['email'])) { $email_exists = fn_is_user_exists(0, $user_data); if (!empty($email_exists)) { fn_set_notification('E', __('error'), __('error_user_exists')); fn_save_post_data('user_data'); if (!empty($params['guest_checkout'])) { $redirect_params['edit_step'] = $params['step_two']; $redirect_params['guest_checkout'] = 1; } return $redirect_params; } } if (isset($user_data['fields'])) { $fields = fn_array_merge(isset($cart['user_data']['fields']) ? $cart['user_data']['fields'] : array(), $user_data['fields']); } if ($params['update_step'] == 'step_two' && !empty($user_data)) { $user_data = fn_fill_contact_info_from_address($user_data); } $cart['user_data'] = fn_array_merge($cart['user_data'], $user_data); // Fill shipping info with billing if needed if (empty($params['ship_to_another']) && $params['update_step'] == 'step_two') { $profile_fields = fn_get_profile_fields('O'); fn_fill_address($cart['user_data'], $profile_fields); } if (!empty($cart['user_data']['b_vat_id']) && !empty($cart['user_data']['b_country'])) { if (fn_check_vat_id($user_data['b_vat_id'], $cart['user_data']['b_country'])) { fn_set_notification('N', __('notice'), __('vat_id_number_is_valid')); } else { fn_set_notification('E', __('error'), __('vat_id_number_is_not_valid')); $cart['user_data']['b_vat_id'] = ''; return $redirect_params; } } elseif (isset($user_data['b_vat_id'])) { $user_data['b_vat_id'] = ''; } } if (!empty($params['next_step'])) { $redirect_params['edit_step'] = $params['next_step']; } if (!empty($params['shipping_ids'])) { fn_checkout_update_shipping($cart, $params['shipping_ids']); } if (!empty($params['payment_id'])) { $cart['payment_id'] = (int) $params['payment_id']; if (!empty($params['payment_info'])) { $cart['extra_payment_info'] = $params['payment_info']; if (!empty($cart['extra_payment_info']['card_number'])) { $cart['extra_payment_info']['secure_card_number'] = preg_replace('/^(.+?)([0-9]{4})$/i', '***-$2', $cart['extra_payment_info']['card_number']); } } else { unset($cart['extra_payment_info']); } fn_update_payment_surcharge($cart, $auth); fn_save_cart_content($cart, $auth['user_id']); } if (!empty($params['customer_notes'])) { $cart['notes'] = $params['customer_notes']; } // Recalculate the cart $cart['recalculate'] = true; if (!empty($params['next_step']) && ($params['next_step'] == 'step_three' || $params['next_step'] == 'step_four')) { $cart['calculate_shipping'] = true; } $shipping_calculation_type = Registry::get('settings.General.estimate_shipping_cost') == 'Y' || !empty($completed_steps['step_two']) ? 'A' : 'S'; list($cart_products, $product_groups) = fn_calculate_cart_content($cart, $auth, $shipping_calculation_type, true, 'F'); $shipping_hash = fn_get_shipping_hash($cart['product_groups']); if (!empty($_SESSION['shipping_hash']) && $_SESSION['shipping_hash'] != $shipping_hash && $params['next_step'] == 'step_four' && $cart['shipping_required']) { if (!empty($cart['chosen_shipping'])) { fn_set_notification('W', __('important'), __('text_shipping_rates_changed')); } $cart['chosen_shipping'] = array(); $redirect_params['edit_step'] = 'step_three'; return $redirect_params; } return $redirect_params; }
protected function addProductsToCart($items, $delivery) { $products = array(); foreach ($items as $item) { $products[$item['offerId']] = array('product_id' => $item['offerId'], 'amount' => $item['count']); } fn_add_product_to_cart($products, $this->cart, $this->auth); $addr = $this->parseDelivery($delivery); $this->cart['user_data'] = array('lastname' => self::FAKE_YM_NAME, 'b_firstname' => self::FAKE_YM_NAME, 's_firstname' => self::FAKE_YM_NAME, 'firstname' => self::FAKE_YM_NAME, 'b_lastname' => self::FAKE_YM_NAME, 's_lasttname' => self::FAKE_YM_NAME, 'b_address' => $addr['address'], 's_address' => $addr['address'], 'b_city' => $addr['city'], 's_city' => $addr['city'], 'b_country' => $addr['country_code'], 's_country' => $addr['country_code'], 'b_state' => $_state = !empty($addr['state_code']) ? $addr['state_code'] : $addr['subject_federation'], 's_state' => $_state, 's_zipcode' => $addr['postcode'], 'b_zipcode' => $addr['postcode']); if (!empty($delivery['type']) && !empty($delivery['id'])) { fn_checkout_update_shipping($this->cart, array(0 => $delivery['id'])); } $this->cart['calculate_shipping'] = true; list($cart_products, $product_groups) = fn_calculate_cart_content($this->cart, $this->auth, 'A', true, 'F', true); return array($cart_products, $product_groups, $addr); }