Back to address' . '' . '' . yak_buy_end_tag(); } } if (!function_exists('yak_back_to_cc_tag')) { /** * [yak_back_to_cc] * * Button to jump back to credit card form in the case of an error */ function yak_back_to_cc_tag($attrs) { $checkout_param = $_SESSION['checkout_param']; $checkout_param_val = $_SESSION['checkout_param_val']; ob_start(); include 'yak-view-shipping-snippet.php'; $shipping_form = ob_get_contents(); ob_end_clean(); return yak_buy_begin_tag() . '' . '' . $shipping_form . '' . yak_buy_end_tag(); } } if (!function_exists('yak_buy_tag')) { /** * [yak_buy] * * Output the html for the buy button */ function yak_buy_tag($attrs) { $pp = yak_get_product(null, true); extract(shortcode_atts(array( 'id' => null ), $attrs)); // hack for NextGen Gallery plugin if ($id == null && count($attrs) > 0 && is_numeric($attrs[0])) { $id = $attrs[0]; } if ($id != $pp->ID) { $pp = yak_get_product($id); } $begin = yak_buy_begin_tag(); $content = yak_buy_content_tag(array('yak_post' => $pp)); $end = yak_buy_end_tag(); return $begin . "\n" . $content . "\n" . $end; } } if (!function_exists('yak_buy_begin_tag')) { /** * [yak_buy_begin] * Begin the output of the buy button html (output the form element) */ function yak_buy_begin_tag($attrs = null) { $url = apply_filters('the_permalink', yak_get_blogurl() . '/index.php'); return '
'; } } if (!function_exists('yak_cancelorder_tag')) { /** * [yak_cancelorder] * * Cancel an order */ function yak_cancelorder_tag($attrs) { if (isset($_SESSION['order_id'])) { yak_admin_cancel_order($_SESSION['order_id']); yak_cleanup_after_order(); } return ""; } } if (!function_exists('yak_checkout_tag')) { /** * Display the checkout page. */ function yak_checkout_tag($attrs) { global $post, $model, $credit_card_payments; $param_name = yak_get_post_param(); // get the payment type if set if (isset($_POST[PAYMENT_TYPE])) { $_SESSION[PAYMENT_TYPE] = $_POST[PAYMENT_TYPE]; } $payment_types = yak_get_option(PAYMENT_TYPES, null); $ptype = $_SESSION[PAYMENT_TYPE]; $ptypeval = $payment_types[$ptype]; $items = $_SESSION[ITEMS_NAME]; $_SESSION['checkout_param'] = $param_name; $_SESSION['checkout_param_val'] = $_REQUEST[$param_name]; $action = $_REQUEST['action']; // update button was hit, or address confirmation if ($action == 'update' || $action == 'address') { $order_value = 0.0; $order_items = 0; if (isset($items) && $items != null) { foreach ($items as $key => $item) { $itemkey = 'item_' . $key; $_POST[$itemkey] = round($_POST[$itemkey]); if (!isset($_POST[$itemkey]) || empty($_POST[$itemkey]) || $_POST[$itemkey] == 0) { $items[$key] = NULL; unset($items[$key]); } else { $qty = $_POST[$itemkey]; if (!is_numeric($qty) || $qty < 0) { $items[$key] = NULL; unset($items[$key]); continue; } $order_items += $qty; $items[$key]->quantity = $qty; $items[$key]->item_weight = yak_get_product_weight($items[$key]->id, $items[$key]->cat_id); $order_value += (yak_calc_price($items[$key]->id, $items[$key]->cat_id, $items[$key]->price) * $qty); } if ($order_items == 0) { unset($_SESSION['current_order_items']); unset($_SESSION['current_order_value']); } else { $_SESSION['current_order_items'] = $order_items; $_SESSION['current_order_value'] = $order_value; } } } } // reset the items in the session $_SESSION[ITEMS_NAME] = $items; // start building the 'model' (data used in the next screenflow) $model = array('items' => $items, 'param_name' => $param_name, 'post_id' => $post->ID); if (isset($GLOBALS['buynow_error_message'])) { return $GLOBALS['buynow_error_message']; } else if (!isset($_SESSION[ITEMS_NAME]) || sizeof($items) < 1) { // drop out if no items found in the session $msg = stripslashes(yak_get_option(EMPTY_BASKET_MESSAGE, '')); if (empty($msg)) { return __('You have no items in your shopping basket', 'yak'); } else { return $msg; } } if ($action == 'update' || $action == 'address') { require_once('yak-promo-utils.php'); if (!empty($_POST['promo_code'])) { $promo_code = $_POST['promo_code']; $promos = yak_get_promotions($promo_code, true); if (sizeof($promos) > 0) { if (!yak_allowed_promo($promos[0])) { if (!empty($_REQUEST['error_message'])) { $model['error_message'] = '' . $_REQUEST['error_message'] . '
'; } else { $model['error_message'] = '' . __("You don't have access to this promotion code", 'yak') . '
'; } $action = 'cart'; } else { $_SESSION['promo_code'] = $promo_code; } } else { $model['error_message'] = '' . __('Invalid promotion code', 'yak') . '
'; $action = 'cart'; } } else { unset($_SESSION['promo_code']); } } // default to displaying the first cart screen if ($action == 'update' || empty($action)) { $action = 'cart'; } // store the address data in the model if ($action == 'address' || $action == 'jump-to-address') { $model['shipping_address'] = yak_get_address('shipping'); $model['billing_address'] = yak_get_address('billing'); $model[SHIPPING_OPTIONS] = yak_get_shipping_options($ptype); $action = 'address'; } if ($action == 'jump-to-payment') { $action = null; $next_page = yak_get_next_payment_page($ptypeval); if (!empty($next_page)) { // special case for Credit Card payments if (yak_str_contains($next_page, '-cc')) { $action = 'cc'; } } } else if ($action == 'confirm') { $errors = yak_validate_address('shipping'); if (yak_checkout_error($model, __('Error(s) have occurred validating the shipping address information you provided', 'yak'), $errors)) { // drop back to display the address $action = 'address'; } else { $model['shipping_address'] = yak_get_address('shipping'); $model['billing_address'] = yak_get_address('billing'); $model[SHIPPING_OPTIONS] = yak_get_shipping_options($ptype); $model[SELECTED_SHIPPING_OPTION] = $_POST[SELECTED_SHIPPING_OPTION]; $next_page = yak_get_next_payment_page($ptypeval); if (!empty($next_page)) { // special case for Credit Card payments if (yak_str_contains($next_page, '-cc')) { $action = 'cc'; } } } } else if ($action == 'confirm_cc') { // we've come from credit card form, so process accordingly $errors = array(); if (!check_credit_card($_POST['cc_number'], $_POST['cc_type'], $errornumber, $errortext)) { $errors[] = $errortext; } if (mktime(0, 0, 0, $_POST['cc_expiry_month'], date('d'), $_POST['cc_expiry_year']) < mktime()) { $errors[] = __('Credit card has already expired', 'yak'); } if (empty($_POST['cc_name'])) { $errors[] = __('No cardholder name provided', 'yak'); } if (empty($_POST['cc_security_code'])) { $errors[] = __('No security code provided', 'yak'); } if (yak_checkout_error($model, __('Error(s) in your credit card details', 'yak'), $errors)) { $action = 'cc'; } else { $model['shipping_address'] = yak_get_address('shipping'); $model['billing_address'] = yak_get_address('billing'); $_SESSION['cc'] = array('number' => $_POST['cc_number'], 'security_code' => $_POST['cc_security_code'], 'type' => $_POST['cc_type'], 'name' => $_POST['cc_name'], 'expiry' => $_POST['cc_expiry_month'] . '/' . $_POST['cc_expiry_year']); $action = 'confirm'; } } else if ($action == 'confirm_accrecv') { // we've come from the accounts receivable form, so process accordingly $errors = array(); if (empty($_POST['accrecv_number'])) { $errors[] = __('No account number provided', 'yak'); } if (empty($_POST['accrecv_name'])) { $errors[] = __('No account name provided', 'yak'); } if (yak_checkout_error($model, __('Error(s) in your account details', 'yak'), $errors)) { $action = 'accrecv'; } else { $model['shipping_address'] = yak_get_address('shipping'); $model['billing_address'] = yak_get_address('billing'); $_SESSION['accrecv'] = array('number' => $_POST['accrecv_number'], 'name' => $_POST['accrecv_name']); $action = 'confirm'; } } else if ($action == 'confirm2') { // final confirmation caused an error, so redisplay confirmation screen // with the error message $model['error_message'] = '' . $_POST['error_message'] . '
'; $model['shipping_address'] = yak_get_address('shipping'); $model['billing_address'] = yak_get_address('billing'); $action = 'confirm'; } else if ($action == 'redirect_to_confirm') { $model['shipping_address'] = yak_get_address('shipping'); $model['billing_address'] = yak_get_address('billing'); $action = 'confirm'; } // if payment type is credit card, redirect to credit card input form if ($action == 'cc') { global $cards; $card_types = yak_get_option('yak_cc_types'); $model['cc_types'] = array(); foreach ($cards as $name=>$card) { if (in_array($name, $card_types)) { $model['cc_types'][$card['name']] = $card['name']; } } $model['cc_expiry_months'] = yak_get_expiry_months(); $model['cc_expiry_years'] = yak_get_expiry_years(); $action = 'cc'; } if (!empty($_SESSION['promo_code'])) { $model['promo_code'] = $_SESSION['promo_code']; } ob_start(); if (!empty($next_page)) { include $next_page; } else { include 'yak-view-' . $action . '.php'; } $rtn = ob_get_contents(); ob_end_clean(); return $rtn; } } if (!function_exists('yak_cleanup_tag')) { /** * [yak_cleanup] * * cleanup after successful order */ function yak_cleanup_tag($attrs) { yak_cleanup_after_order(); return ""; } } if (!function_exists('yak_customer_address_tag')) { function yak_customer_address_tag($attrs) { global $countries; $addr = yak_get_address('shipping'); if (isset($addr) && !empty($addr)) { $saddr = $addr->as_string('recipient', 'country', 'email', 'phone'); $saddr = str_replace("\n", "\nYou must login to view this page.
'; return; } $order_num = $_REQUEST['order_num']; echo '"; } } if (!function_exists('yak_price_tag')) { /** * [yak_price id="23" type="large" discount="true"] * * embed the product price (type, id, and discount are optional) -- discount defaults to true */ function yak_price_tag($attrs) { $pp = yak_get_product(null, true); extract(shortcode_atts(array( 'id' => null, 'type' => null, 'discount' => "true" ), $attrs)); if ($id == null) { $id = $pp->ID; } if ($discount == "true") { $discount = true; } else { $discount = false; } return '' . yak_price($id, $type, $discount, false) . ''; } } if (!function_exists('yak_product_page_tag')) { /** * [yak_product_page] * * Create a page of all products. */ function yak_product_page_tag($attrs) { global $product_page, $post; $id = $post->ID; $pagesize = yak_get_option(PRODUCT_PAGE_SIZE, 10); if (isset($_GET['offset'])) { $offset = $_GET['offset']; } else { $offset = 0; } $product_page = true; $products = yak_get_products('date', 'desc', null, $offset, $pagesize + 1); $s = ''; $count = 0; foreach ($products as $ppost) { $count += 1; if ($count > $pagesize) { break; } global $yak_post; $yak_post = $ppost; $s .= '