} else { return array(CONTROLLER_STATUS_OK, "gift_certificates.add"); } } // Gift certificates is empty, create it if (empty($_SESSION['cart']['gift_certificates'])) { $_SESSION['cart']['gift_certificates'] = array(); } $previous_cart_total = isset($_SESSION['cart']['total']) ? floatval($_SESSION['cart']['total']) : 0; list($gift_cert_id, $gift_cert) = fn_add_gift_certificate_to_cart($gift_cert_data, $auth); if (!empty($gift_cert_id)) { $_SESSION['cart']['gift_certificates'][$gift_cert_id] = $gift_cert; } fn_save_cart_content($_SESSION['cart'], $auth['user_id']); if (defined('AJAX_REQUEST')) { fn_calculate_cart_content($_SESSION['cart'], $auth, false, false, 'F', false); if ($previous_cart_total == floatval($_SESSION['cart']['total'])) { fn_delete_cart_gift_certificate($gift_cert_id); fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var('text_failed_gift_certificate_addition')); exit; } $view->assign('cart_amount', $_SESSION['cart']['amount']); $view->assign('cart_subtotal', $_SESSION['cart']['subtotal']); fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var('text_gift_cert_added_to_cart')); $view->display('views/checkout/components/cart_status.tpl'); exit; } } } if ($mode == 'update') { if (!empty($_REQUEST['gift_cert_data']) && !empty($_REQUEST['gift_cert_id']) && $_REQUEST['type'] == 'C') {
/** * Validate rule * * @param int $promotion_id promotion ID * @param array $promotion rule data * @param array $data data array * @param array $auth auth array (for cart rules) * @param array $cart_products cart products array (for cart rules) * @return bool true if rule can be applied, false - otherwise */ function fn_promotion_validate($promotion_id, $promotion, &$data, &$auth, &$cart_products) { $schema = fn_promotion_get_schema('conditions'); $stop_validating = false; $result = true; static $parent_orders = array(); fn_set_hook('pre_promotion_validate', $promotion_id, $promotion, $data, $stop_validating, $result, $auth, $cart_products); if ($stop_validating) { return $result; } if (empty($promotion['condition'])) { // if promotion is unconditional, apply it return true; } $promotion['value'] = !isset($promotion['value']) ? '' : $promotion['value']; if (!empty($schema[$promotion['condition']])) { $value = ''; $parent_order_value = ''; if (!empty($data['parent_order_id']) && empty($parent_orders[$data['parent_order_id']])) { $parent_orders[$data['parent_order_id']] = array('cart' => array(), 'cart_products' => array(), 'product_groups' => array()); fn_form_cart($data['parent_order_id'], $parent_orders[$data['parent_order_id']]['cart'], $auth); list($parent_orders[$data['parent_order_id']]['cart_products'], $parent_orders[$data['parent_order_id']]['product_groups']) = fn_calculate_cart_content($parent_orders[$data['parent_order_id']]['cart'], $auth); } // Ordinary field if (!empty($schema[$promotion['condition']]['field'])) { // Array definition, parse it if (strpos($schema[$promotion['condition']]['field'], '@') === 0) { $value = fn_promotion_get_object_value($schema[$promotion['condition']]['field'], $data, $auth, $cart_products); } else { // If field can be used in both zones, it means that we're using products if (in_array('catalog', $schema[$promotion['condition']]['zones']) && in_array('cart', $schema[$promotion['condition']]['zones']) && !empty($cart_products)) { // this is the "cart" zone. FIXME!!! foreach ($cart_products as $v) { if ($promotion['operator'] == 'nin') { if (fn_promotion_validate_attribute($v[$schema[$promotion['condition']]['field']], $promotion['value'], 'in')) { return false; } } else { if (fn_promotion_validate_attribute($v[$schema[$promotion['condition']]['field']], $promotion['value'], $promotion['operator'])) { return true; } } } return $promotion['operator'] == 'nin' ? true : false; } if (!isset($data[$schema[$promotion['condition']]['field']])) { return false; } $value = $data[$schema[$promotion['condition']]['field']]; if (!empty($data['parent_order_id']) && !empty($parent_orders[$data['parent_order_id']]['cart'][$schema[$promotion['condition']]['field']])) { $parent_order_value = $parent_orders[$data['parent_order_id']]['cart'][$schema[$promotion['condition']]['field']]; } } // Field is the result of function } elseif (!empty($schema[$promotion['condition']]['field_function'])) { $function_args = $schema[$promotion['condition']]['field_function']; $function_name = array_shift($function_args); $function_args_definitions = $function_args; // If field can be used in both zones, it means that we're using products if (in_array('catalog', $schema[$promotion['condition']]['zones']) && in_array('cart', $schema[$promotion['condition']]['zones']) && !empty($cart_products)) { // this is the "cart" zone. FIXME!!! foreach ($cart_products as $product) { $function_args = $function_args_definitions; foreach ($function_args as $k => $v) { if (strpos($v, '@') !== false) { $function_args[$k] =& fn_promotion_get_object_value($v, $product, $auth, $cart_products); } elseif ($v == '#this') { $function_args[$k] =& $promotion; } elseif ($v == '#id') { $function_args[$k] =& $promotion_id; } } $value = call_user_func_array($function_name, $function_args); if ($promotion['operator'] == 'nin') { if (fn_promotion_validate_attribute($value, $promotion['value'], 'in')) { return false; } } else { if (fn_promotion_validate_attribute($value, $promotion['value'], $promotion['operator'])) { return true; } } } return $promotion['operator'] == 'nin' ? true : false; } foreach ($function_args as $k => $v) { if (strpos($v, '@') !== false) { $function_args[$k] =& fn_promotion_get_object_value($v, $data, $auth, $cart_products); } elseif ($v == '#this') { $function_args[$k] =& $promotion; } elseif ($v == '#id') { $function_args[$k] =& $promotion_id; } } $value = call_user_func_array($function_name, $function_args); if (!empty($data['parent_order_id']) && !empty($parent_orders[$data['parent_order_id']])) { $parent_p = $function_args_definitions; foreach ($parent_p as $k => $v) { if (strpos($v, '@') !== false) { $parent_p[$k] =& fn_promotion_get_object_value($v, $parent_orders[$data['parent_order_id']]['cart'], $auth, $parent_orders[$data['parent_order_id']]['cart_products']); } elseif ($v == '#this') { $parent_p[$k] =& $promotion; } elseif ($v == '#id') { $parent_p[$k] =& $promotion_id; } } $parent_order_value = call_user_func_array($function_name, $parent_p); } } // Value is validated $result = fn_promotion_validate_attribute($value, $promotion['value'], $promotion['operator']); if ($parent_order_value) { $result = $result || fn_promotion_validate_attribute($parent_order_value, $promotion['value'], $promotion['operator']); } return $result; } return false; }
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; }
* This is commercial software, only users who have purchased a valid * * 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; if (!defined('BOOTSTRAP')) { die('Access denied'); } if (in_array($mode, array('cart', 'checkout', 'place_order')) && isset(Tygh::$app['session']['cart']['use_gift_certificates'])) { $company_id = Registry::get('runtime.company_id'); $codes = fn_check_gift_certificate_code(array_keys(Tygh::$app['session']['cart']['use_gift_certificates']), true, $company_id); $remove_codes = array_diff_key(Tygh::$app['session']['cart']['use_gift_certificates'], !empty($codes) ? $codes : array()); $removed_codes = false; if (!empty($remove_codes)) { foreach ($remove_codes as $code => $value) { unset(Tygh::$app['session']['cart']['use_gift_certificates'][$code]); } $removed_codes = true; } if ($removed_codes) { fn_set_notification('W', __('warning'), __('warning_gift_cert_deny', array('[codes]' => implode(', ', array_keys($remove_codes)))), 'K'); } if ($mode == 'place_order') { fn_calculate_cart_content(Tygh::$app['session']['cart'], $auth, 'A', true, 'F'); } return; }
function fn_twg_api_get_shippings(&$params) { list(, $product_groups) = fn_calculate_cart_content($params['cart'], $params['auth']); $result = array(); $product_groups = $product_groups ? $product_groups : array(); foreach ($product_groups as $group_key => &$product_group) { $product_group['group_key'] = $group_key; $is_free_shippings = $product_group['all_edp_free_shipping'] || $product_group['all_free_shipping'] || $product_group['free_shipping'] || $product_group['shipping_no_required']; if (!$is_free_shippings) { $result[] = $product_groups[$group_key]; } } return $result; }
/** * 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; }
public function update($id, $params) { fn_define('ORDER_MANAGEMENT', true); $data = array(); $valid_params = true; $status = Response::STATUS_BAD_REQUEST; if ($valid_params) { fn_clear_cart($cart, true); $customer_auth = fn_fill_auth(array(), array(), false, 'C'); $cart_status = md5(serialize($cart)); // Order info was not found or customer does not have enought permissions if (fn_form_cart($id, $cart, $customer_auth) && $cart_status != md5(serialize($cart))) { unset($params['product_groups']); if (empty($params['shipping_id'])) { $shipping = reset($cart['shipping']); if (!empty($shipping['shipping_id'])) { $params['shipping_id'] = $shipping['shipping_id']; } } $cart['order_id'] = $id; fn_calculate_cart_content($cart, $customer_auth); if (!empty($params['user_id'])) { $cart['user_data'] = fn_get_user_info($params['user_id']); } elseif (!empty($params)) { $cart['user_data'] = array_merge($cart['user_data'], $params); } 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; } } } } if (!empty($params['payment_id'])) { if (!empty($params['payment_info'])) { $cart['payment_info'] = $params['payment_info']; } elseif ($params['payment_id'] != $cart['payment_id']) { $cart['payment_info'] = array(); } $cart['payment_id'] = $params['payment_id']; } if (!empty($params['products'])) { $cart['products'] = $params['products']; } fn_calculate_cart_content($cart, $customer_auth); if (!empty($cart) && empty($cart['shipping_failed'])) { $cart['parent_order_id'] = 0; fn_update_payment_surcharge($cart, $customer_auth); list($order_id, $order_status) = fn_update_order($cart, $id); if ($order_id) { if (!empty($params['status']) && fn_check_permissions('orders', 'update_status', 'admin')) { fn_change_order_status($order_id, $params['status'], '', fn_get_notification_rules($params, false)); } elseif (!empty($order_status)) { fn_change_order_status($order_id, $order_status, '', fn_get_notification_rules($params, false)); } $status = Response::STATUS_OK; $data = array('order_id' => $order_id); } } } } return array('status' => $status, 'data' => $data); }
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); }
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; }
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); }
$shipping_calculation_type = 'A'; list($cart_products, $product_groups) = fn_calculate_cart_content($cart, $auth, $shipping_calculation_type, true, 'F'); $payment_methods = fn_prepare_checkout_payment_methods($cart, $auth); if (!empty($payment_methods)) { $first_method = reset($payment_methods); $first_method = reset($first_method); $checkout_buttons = fn_get_checkout_payment_buttons($cart, $cart_products, $auth); if (!empty($checkout_buttons)) { Registry::get('view')->assign('checkout_buttons', $checkout_buttons, false); } } else { $first_method = false; } if ($first_method != false && empty($cart['payment_id']) && floatval($cart['total']) != 0) { $cart['payment_id'] = $first_method['payment_id']; list($cart_products, $product_groups) = fn_calculate_cart_content($cart, $auth, $shipping_calculation_type, true, 'F'); } if (!empty($cart['shipping_failed']) || !empty($cart['company_shipping_failed'])) { $checkout_style = Registry::get('settings.General.checkout_style'); if (defined('AJAX_REQUEST') && $checkout_style != 'multi_page' || $checkout_style == 'multi_page' && !defined('AJAX_REQUEST')) { fn_set_notification('W', __('warning'), __('text_no_shipping_methods')); } } $shipping_hash = fn_get_shipping_hash($cart['product_groups']); if (!empty($_SESSION['shipping_hash']) && $_SESSION['shipping_hash'] != $shipping_hash && $cart['shipping_required']) { $_SESSION['chosen_shipping'] = array(); } $_SESSION['shipping_hash'] = $shipping_hash; fn_gather_additional_products_data($cart_products, array('get_icon' => true, 'get_detailed' => true, 'get_options' => true, 'get_discounts' => false)); if (floatval($cart['total']) == 0) { $cart['payment_id'] = 0;
$cart =& $_SESSION['cart']; $auth =& $_SESSION['auth']; // Update shipping info if (!empty($_REQUEST['shipping_ids'])) { fn_checkout_update_shipping($cart, $_REQUEST['shipping_ids']); } $payment_methods = fn_twg_get_payment_methods(); if (!empty($payment_methods['payment'])) { foreach ($payment_methods['payment'] as $k => $v) { if ($options = fn_twg_get_payment_options($v['payment_id'])) { $payment_methods['payment'][$k]['options'] = $options; } } $cart['recalculate'] = true; $cart['calculate_shipping'] = true; fn_calculate_cart_content($cart, $auth, 'A'); $response->setData(array('payments' => $payment_methods['payment'], 'cart' => fn_twg_api_get_session_cart($cart, $lang_code))); } } elseif ($meta['object'] == 'shipping_methods') { $_SESSION['cart']['calculate_shipping'] = true; $params = array('cart' => &$_SESSION['cart'], 'auth' => &$_SESSION['auth']); $product_groups = fn_twg_api_get_shippings($params); $shipping_methods = Api::getAsList('companies_rates', $product_groups); $shipping_methods['shipping_failed'] = !empty($_SESSION['cart']['shipping_failed']) ? $_SESSION['cart']['shipping_failed'] : false; $response->setData($shipping_methods); } elseif ($meta['object'] == 'product_files') { $file_url = array('fileUrl' => fn_url("orders.get_file&ekey=" . $_REQUEST['ekey'] . "&file_id=" . $_REQUEST['file_id'] . "&product_id=" . $_REQUEST['product_id'], AREA, 'rel')); $response->setData($file_url); } elseif ($meta['object'] == 'errors') { $response->returnResponse(); } else {
} elseif ($mode == 'get_custom_file' && isset($_REQUEST['cart_id']) && isset($_REQUEST['option_id']) && isset($_REQUEST['file'])) { if (isset($cart['products'][$_REQUEST['cart_id']]['extra']['custom_files'][$_REQUEST['option_id']][$_REQUEST['file']])) { $file = $cart['products'][$_REQUEST['cart_id']]['extra']['custom_files'][$_REQUEST['option_id']][$_REQUEST['file']]; fn_get_file($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']]; @unlink($file['path']); @unlink($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']); $cart['recalculate'] = true; if (defined('AJAX_REQUEST')) { fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var('text_product_file_has_been_deleted')); if ($action == 'from_status') { fn_calculate_cart_content($cart, $customer_auth, 'S', true, 'F', true); $view->assign('force_items_deletion', true); $view->display('views/checkout/components/cart_status.tpl'); exit; } } return array(CONTROLLER_STATUS_REDIRECT, "order_management.products"); } if (!empty($profile_fields)) { $view->assign('profile_fields', $profile_fields); } $view->assign('cart', $cart); $view->assign('customer_auth', $customer_auth);
$callback_response['Response']['CallbackOrders']['CallbackOrder'] = array(); $calculate_taxes = (string) $xml->OrderCalculationCallbacks->CalculateTaxRates == 'true' ? true : false; $calculate_promotions = (string) $xml->OrderCalculationCallbacks->CalculatePromotions == 'true' ? true : false; $calculate_shippings = (string) $xml->OrderCalculationCallbacks->CalculateShippingRates == 'true' ? true : false; $address_id = (string) $xml->CallbackOrders->CallbackOrder->Address->AddressId; $callback_response['Response']['CallbackOrders']['CallbackOrder']['Address']['AddressId'] = $address_id; // Fill the cart address information from the Amazon request $address_xml = $xml->CallbackOrders->CallbackOrder->Address; $user_data = array('b_address' => (string) $address_xml->AddressFieldOne, 's_address' => (string) $address_xml->AddressFieldOne, 'b_address2' => (string) $address_xml->AddressFieldTwo, 's_address2' => (string) $address_xml->AddressFieldTwo, 'b_city' => (string) $address_xml->City, 's_city' => (string) $address_xml->City, 'b_state' => (string) $address_xml->State, 's_state' => (string) $address_xml->State, 'b_zipcode' => (string) $address_xml->PostalCode, 's_zipcode' => (string) $address_xml->PostalCode, 'b_country' => (string) $address_xml->CountryCode, 's_country' => (string) $address_xml->CountryCode); if (strpos($user_data['b_zipcode'], '-') !== false) { $zip = explode('-', $user_data['b_zipcode']); $user_data['b_zipcode'] = $user_data['s_zipcode'] = $zip[0]; } $cart['user_data'] = $user_data; $cart['calculate_shipping'] = true; list($cart_products, $_SESSION['shipping_product_groups']) = fn_calculate_cart_content($cart, $auth, 'A', true, 'F', true); $cart_shippings = array(); foreach ($_SESSION['shipping_product_groups'] as $key_group => $group) { if (!empty($group['shippings'])) { foreach ($group['shippings'] as $shipping) { $shipping_id = $shipping['shipping_id']; if (empty($cart_shippings[$shipping_id])) { $cart_shippings[$shipping_id] = $shipping; $cart_shippings[$shipping_id]['rates'] = array(); } $cart_shippings[$shipping_id]['rates'][$key_group] = $shipping['rate']; } } } fn_gather_additional_products_data($cart_products, array('get_icon' => false, 'get_detailed' => false, 'get_options' => true, 'get_discounts' => false)); // Determine the tax calculation type
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; } }
function fn_process_epayph_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_epayph_order_info($data, $order_info)) { return false; } $pp_settings = fn_get_epayph_settings(); $data['payment_status'] = strtolower($data['payment_status']); 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_epayph_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']; } fn_calculate_cart_content($cart, $customer_auth); list($order_id, ) = fn_update_order($cart, $order_id); if ($order_id) { $send_notification = $order_info['status'] == $pp_settings['pp_statuses'][$data['payment_status']] ? false : array(); $short_order_data = fn_get_order_short_info($order_id); fn_change_order_status($order_id, $pp_settings['pp_statuses'][$data['payment_status']], $short_order_data['status'], $send_notification); } return true; } }
function fn_qwintry_fn_form_cart($order_info) { fn_clear_cart($cart, true); $customer_auth = fn_fill_auth(); fn_form_cart($order_info['order_id'], $cart, $customer_auth, array()); list($cart_products, ) = fn_calculate_cart_content($cart, $customer_auth, 'E', false, 'F', false); if (!empty($cart_products)) { foreach ($cart_products as $k => $v) { fn_gather_additional_product_data($cart_products[$k], false, false, true, false); } } $cart['products'] = $cart_products; return $cart; }
$response[] = '<merchant-calculation-results xmlns="http://checkout.google.com/schema/2">'; $response[] = ' <results>'; for ($i = 0; $i < $total; $i++) { $address_id = $addresses[$i]->getAttribute('id'); $cart['user_data'] = array('s_address' => '', 's_city' => $addresses[$i]->getValueByPath('/city'), 's_state' => $addresses[$i]->getValueByPath('/region'), 's_country' => $addresses[$i]->getValueByPath('/country-code'), 's_zipcode' => $addresses[$i]->getValueByPath('/postal-code'), 'b_address' => '', 'b_city' => $addresses[$i]->getValueByPath('/city'), 'b_state' => $addresses[$i]->getValueByPath('/region'), 'b_country' => $addresses[$i]->getValueByPath('/country-code'), 'b_zipcode' => $addresses[$i]->getValueByPath('/postal-code'), 'phone' => '', 'country' => '', 'firstname' => '', 'lastname' => ''); $country_fields = array('s_country' => 's_state', 'b_country' => 'b_state'); foreach ($country_fields as $_c => $_s) { // For UK google returns region description, instead of the code, so we need to get the state code manually if ($_c == 'UK') { $cart['user_data'][$_s] = db_get_field("SELECT a.code FROM ?:states as a LEFT JOIN ?:state_descriptions as b ON b.state_id = a.state_id AND lang_code = ?s WHERE a.country_code = ?s AND b.state = ?s", CART_LANGUAGE, $cart['user_data'][$_c], $cart['user_data'][$_s]); } } // Apply the codes entered on the Google side to the cart $_codes = fn_apply_google_codes($cart, $codes); // Find the shipping rates for each customer location list($cart_products, $shipping_rates) = fn_calculate_cart_content($cart, $_SESSION['auth'], 'A', true, 'I', true); $use_taxes = false; $_taxes_list = fn_get_taxes(); foreach ($_taxes_list as $v) { if ($v['price_includes_tax'] != 'Y') { $use_taxes = true; break; } } // Go throught all shipping methods, passes to google checkout and get rates (if calculated) for ($k = 0; $k < $gc_methods_total; $k++) { $_id = $gc_methods[$k]->getAttribute('id'); $response[] = ' <result shipping-name="' . trim($gc_methods[$k]->getAttribute('name')) . '" address-id="' . $address_id . '">'; if ($this_shipping = fn_get_google_shipping_rate($_id, $shipping_rates)) { fn_recalculate_taxes($cart, $shipping_rates, $this_shipping); $response[] = ' <shipping-rate currency="' . $currency_code . '">' . $this_shipping['rate'] . '</shipping-rate>';
use Tygh\BlockManager\SchemesManager; if (!defined('BOOTSTRAP')) { die('Access denied'); } /** * Act on behalf functionality */ if (!empty($_REQUEST['skey'])) { $session_data = fn_get_storage_data('session_' . $_REQUEST['skey'] . '_data'); fn_set_storage_data('session_' . $_REQUEST['skey'] . '_data', ''); if (!empty($session_data)) { Tygh::$app['session']->start(); Tygh::$app['session']->fromArray(unserialize($session_data)); Tygh::$app['session']->save(Tygh::$app['session']->getID(), Tygh::$app['session']->toArray()); if (!fn_cart_is_empty(Tygh::$app['session']['cart'])) { fn_calculate_cart_content(Tygh::$app['session']['cart'], Tygh::$app['session']['auth'], 'S', true, 'F', true); fn_save_cart_content(Tygh::$app['session']['cart'], Tygh::$app['session']['auth']['user_id']); } } return array(CONTROLLER_STATUS_REDIRECT, fn_query_remove(REAL_URL, 'skey')); } // UK Cookies Law if (Registry::get('settings.Security.uk_cookies_law') == 'Y') { if (!empty($_REQUEST['cookies_accepted']) && $_REQUEST['cookies_accepted'] == 'Y') { Tygh::$app['session']['cookies_accepted'] = true; } if (!defined('AJAX_REQUEST') && empty(Tygh::$app['session']['cookies_accepted'])) { $url = fn_link_attach(Registry::get('config.current_url'), 'cookies_accepted=Y'); $url = str_replace('&', '&', $url); $text = __('uk_cookies_law', array('[url]' => $url)); fn_delete_notification('uk_cookies_law');
****************************************************************************/ use Tygh\Development; use Tygh\Registry; use Tygh\Session; use Tygh\BlockManager\Location; use Tygh\BlockManager\Layout; if (!defined('BOOTSTRAP')) { die('Access denied'); } if (!empty($_REQUEST['skey'])) { $session_data = fn_get_storage_data('session_' . $_REQUEST['skey'] . '_data'); fn_set_storage_data('session_' . $_REQUEST['skey'] . '_data', ''); if (!empty($session_data)) { $_SESSION = unserialize($session_data); Session::save(Session::getId(), $_SESSION); fn_calculate_cart_content($_SESSION['cart'], $_SESSION['auth'], 'S', true, 'F', true); fn_save_cart_content($_SESSION['cart'], $_SESSION['auth']['user_id']); } return array(CONTROLLER_STATUS_REDIRECT, fn_query_remove(REAL_URL, 'skey')); } // UK Cookies Law if (Registry::get('settings.Security.uk_cookies_law') == 'Y') { if (!empty($_REQUEST['cookies_accepted']) && $_REQUEST['cookies_accepted'] == 'Y') { $_SESSION['cookies_accepted'] = true; } if (!defined('AJAX_REQUEST') && empty($_SESSION['cookies_accepted'])) { $url = fn_link_attach(Registry::get('config.current_url'), 'cookies_accepted=Y'); $text = __('uk_cookies_law', array('[url]' => $url)); fn_delete_notification('uk_cookies_law'); fn_set_notification('W', __('warning'), $text, 'K', 'uk_cookies_law'); } else {
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; }
/** * Extract cart content from the customer's profile. * $type : C - cart, W - wishlist * * @param array $cart * @param integer $user_id * @param string $type * * @return void */ function fn_extract_cart_content(&$cart, $user_id, $type = 'C', $user_type = 'R') { $auth =& $_SESSION['auth']; $old_session_id = ''; // Restore cart content if (!empty($user_id)) { $item_types = fn_get_cart_content_item_types('X'); $condition = db_quote("user_id = ?i AND type = ?s AND user_type = ?s AND item_type IN (?a)", $user_id, $type, $user_type, $item_types); fn_set_hook('pre_extract_cart', $cart, $condition, $item_types); $_prods = db_get_hash_array("SELECT * FROM ?:user_session_products WHERE " . $condition, 'item_id'); if (!empty($_prods) && is_array($_prods)) { $cart['products'] = empty($cart['products']) ? array() : $cart['products']; foreach ($_prods as $_item_id => $_prod) { $old_session_id = $_prod['session_id']; $_prod_extra = unserialize($_prod['extra']); unset($_prod['extra']); $cart['products'][$_item_id] = empty($cart['products'][$_item_id]) ? fn_array_merge($_prod, $_prod_extra, true) : $cart['products'][$_item_id]; } } } fn_set_hook('extract_cart', $cart, $user_id, $type, $user_type); if ($type == 'C') { $cart['change_cart_products'] = true; fn_calculate_cart_content($cart, $auth, 'S', false, 'I', false); } }
} //copy the product id $ls_current_page_product[$combination_hash]['product_id'] = $product_id; //assign the db hash $ls_current_page_product[$combination_hash]['ls_db_hash'] = $combination_hash; //assign the product options foreach ($_REQUEST['product_data'][$product_id] as $option_id => $variant_id) { $ls_current_page_product[$combination_hash]['product_options'][$option_id]['value'] = $variant_id; } //tests $ls_msg['product_id'] = $product_id; $ls_msg['combination_hash'] = $combination_hash; //get product trackig and available since $ls_current_page_product[$combination_hash]['tracking'] = db_get_field('SELECT tracking FROM ?:products WHERE product_id = ?i', $product_id); //get cart products details list($ls_total_products, $ls_product_groups) = fn_calculate_cart_content($_SESSION['cart'], $auth, Registry::get('settings.General.estimate_shipping_cost') == 'Y' ? 'A' : 'S', true, 'F', true); //check to see if this product is already in cart if (!fn_is_product_in_cart($ls_current_page_product, $ls_total_products, $product)) { //set the product page order amount $ls_current_page_product[$combination_hash]['order_amount'] = 1; //product not in cart, add it in the total products array $ls_total_products[$combination_hash] = $ls_current_page_product[$combination_hash]; //get product and linked products details fn_ls_get_linked_products($ls_total_products); //get total linked products for the order fn_ls_linked_products_order_total($ls_total_products); //correct the inventory and order amounts if there are linked products in cart $ls_final_order_amount = fn_linked_products_in_cart_amount($ls_total_products, $ls_total_products[$combination_hash]['product_id']); if ($ls_final_order_amount > 1) { //linked variants(not products present in cart) and product tracking!=O //decrement the inventory
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; }
} if ($changed_options) { list($cart_products) = fn_calculate_cart_content($_cart, $_auth, 'S', true, 'F', true); fn_gather_additional_products_data($cart_products, array('get_icon' => true, 'get_detailed' => true, 'get_options' => true, 'get_discounts' => false)); } if (count($_SESSION['cart']['products']) != count($_cart['products'])) { $_recalculate = false; foreach ($_SESSION['cart']['products'] as $cart_id => $product) { if (!isset($_cart['products'][$cart_id]) && !isset($exclude_products[$cart_id])) { $_recalculate = true; break; } } if ($_recalculate) { $_cart = $_SESSION['cart']; list($cart_products) = fn_calculate_cart_content($_cart, $_auth, 'S', true, 'F', true); } } // Restore the cart_id if (!empty($cart_products)) { foreach ($cart_products as $k => $product) { if (!empty($product['object_id'])) { $c_product = !empty($_cart['products'][$k]) ? $_cart['products'][$k] : array(); unset($cart_products[$k], $_cart['products'][$k]); $_cart['products'][$product['object_id']] = $c_product; $cart_products[$product['object_id']] = $product; $k = $product['object_id']; } $cart_products[$k]['changed_option'] = isset($product['object_id']) ? isset($_REQUEST['changed_option'][$product['object_id']]) ? $_REQUEST['changed_option'][$product['object_id']] : '' : isset($_REQUEST['changed_option'][$k]) ? $_REQUEST['changed_option'][$k] : ''; } }
* This is commercial software, only users who have purchased a valid * * 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; if (!defined('BOOTSTRAP')) { die('Access denied'); } if (in_array($mode, array('cart', 'checkout', 'place_order')) && isset($_SESSION['cart']['use_gift_certificates'])) { $company_id = Registry::get('runtime.company_id'); $codes = fn_check_gift_certificate_code(array_keys($_SESSION['cart']['use_gift_certificates']), true, $company_id); $remove_codes = array_diff_key($_SESSION['cart']['use_gift_certificates'], !empty($codes) ? $codes : array()); $removed_codes = false; if (!empty($remove_codes)) { foreach ($remove_codes as $code => $value) { unset($_SESSION['cart']['use_gift_certificates'][$code]); } $removed_codes = true; } if ($removed_codes) { fn_set_notification('W', __('warning'), __('warning_gift_cert_deny', array('[codes]' => implode(', ', array_keys($remove_codes)))), 'K'); } if ($mode == 'place_order') { fn_calculate_cart_content($_SESSION['cart'], $auth, 'A', true, 'F'); } return; }
Storage::instance('custom_files')->delete($file['path'] . '_thumb'); unset($product['extra']['custom_files'][$option_id][$file_id]); if (!empty($product['extra']['custom_files'][$option_id])) { $product['product_options'][$option_id] = md5(serialize($product['extra']['custom_files'][$option_id])); } else { unset($product['product_options'][$option_id]); } $product['extra']['product_options'] = empty($product['product_options']) ? array() : $product['product_options']; $cart['products'][$_REQUEST['cart_id']] = $product; } fn_save_cart_content($cart, $auth['user_id']); $cart['recalculate'] = true; if (defined('AJAX_REQUEST')) { fn_set_notification('N', __('notice'), __('text_product_file_has_been_deleted')); if (Registry::get('runtime.action') == 'from_status') { fn_calculate_cart_content($cart, $auth, 'S', true, 'F', true); } } return array(CONTROLLER_STATUS_REDIRECT, 'checkout.' . $_REQUEST['redirect_mode']); //Clear cart } elseif ($mode == 'clear') { fn_clear_cart($cart); fn_save_cart_content($cart, $auth['user_id']); return array(CONTROLLER_STATUS_REDIRECT, 'checkout.cart'); //Purge undeliverable products } elseif ($mode == 'purge_undeliverable') { fn_purge_undeliverable_products($cart); fn_set_notification('N', __('notice'), __('notice_undeliverable_products_removed')); return array(CONTROLLER_STATUS_REDIRECT, 'checkout.checkout'); } elseif ($mode == 'complete') { if (!empty($_REQUEST['order_id'])) {
} if (!empty($cart['user_data'])) { $cart['ship_to_another'] = fn_check_shipping_billing($cart['user_data'], $profile_fields); } // // Get products info // and shipping rates // // Clean up saved shipping rates // unset($_SESSION['shipping_rates']); if (!empty($shipping_rates)) { define('CACHED_SHIPPING_RATES', true); } $cart['calculate_shipping'] = true; // calculate cart - get products with options, full shipping rates info and promotions list($cart_products, $product_groups) = fn_calculate_cart_content($cart, $customer_auth); Registry::get('view')->assign('product_groups', $product_groups); if (fn_allowed_for('MULTIVENDOR') && !empty($cart['order_id'])) { $order_info = fn_get_order_info($cart['order_id']); if (isset($order_info['company_id'])) { Registry::get('view')->assign('order_company_id', $order_info['company_id']); } } fn_gather_additional_products_data($cart_products, array('get_icon' => false, 'get_detailed' => false, 'get_options' => true, 'get_discounts' => false)); Registry::get('view')->assign('cart_products', $cart_products); // //Get payment methods // $payment_methods = fn_get_payment_methods($customer_auth); // Check if payment method has surcharge rates foreach ($payment_methods as $k => $v) {
$callback_response['Response']['CallbackOrders']['CallbackOrder'] = array(); $calculate_taxes = (string) $xml->OrderCalculationCallbacks->CalculateTaxRates == 'true' ? true : false; $calculate_promotions = (string) $xml->OrderCalculationCallbacks->CalculatePromotions == 'true' ? true : false; $calculate_shippings = (string) $xml->OrderCalculationCallbacks->CalculateShippingRates == 'true' ? true : false; $address_id = (string) $xml->CallbackOrders->CallbackOrder->Address->AddressId; $callback_response['Response']['CallbackOrders']['CallbackOrder']['Address']['AddressId'] = $address_id; // Fill the cart address information from the Amazon request $address_xml = $xml->CallbackOrders->CallbackOrder->Address; $user_data = array('b_address' => (string) $address_xml->AddressFieldOne, 's_address' => (string) $address_xml->AddressFieldOne, 'b_address2' => (string) $address_xml->AddressFieldTwo, 's_address2' => (string) $address_xml->AddressFieldTwo, 'b_city' => (string) $address_xml->City, 's_city' => (string) $address_xml->City, 'b_state' => (string) $address_xml->State, 's_state' => (string) $address_xml->State, 'b_zipcode' => (string) $address_xml->PostalCode, 's_zipcode' => (string) $address_xml->PostalCode, 'b_country' => (string) $address_xml->CountryCode, 's_country' => (string) $address_xml->CountryCode); if (strpos($user_data['b_zipcode'], '-') !== false) { $zip = explode('-', $user_data['b_zipcode']); $user_data['b_zipcode'] = $user_data['s_zipcode'] = $zip[0]; } $cart['user_data'] = $user_data; $cart['calculate_shipping'] = true; list($cart_products, Tygh::$app['session']['shipping_product_groups']) = fn_calculate_cart_content($cart, $auth, 'A', true, 'F', true); $cart_shippings = array(); foreach (Tygh::$app['session']['shipping_product_groups'] as $key_group => $group) { if (!empty($group['shippings'])) { foreach ($group['shippings'] as $shipping) { $shipping_id = $shipping['shipping_id']; if (empty($cart_shippings[$shipping_id])) { $cart_shippings[$shipping_id] = $shipping; $cart_shippings[$shipping_id]['rates'] = array(); } $cart_shippings[$shipping_id]['rates'][$key_group] = $shipping['rate']; } } } fn_gather_additional_products_data($cart_products, array('get_icon' => false, 'get_detailed' => false, 'get_options' => true, 'get_discounts' => false)); // Determine the tax calculation type
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); } } }