/** * Returns the current store link. * @param bool url Optional, whether to return a link or url. Defaults to show link. * @param string link_text Optional, text to show in link. */ function mp_store_link_sc($atts) { extract(shortcode_atts(array('url' => false, 'link_text' => ''), $atts)); return mp_store_link(false, $url, $link_text); }
function filter_nav_menu($list, $args = array()) { $store_object = false; if ($args->depth == 1) { return $list; } //find store page $store_url = mp_store_link(false, true); $store_page = get_option('mp_store_page'); foreach ($list as $menu_item) { if ($menu_item->object_id == $store_page || $menu_item->url == $store_url) { $store_object = $menu_item; break; } } if ($store_object) { $obj_products = clone $store_object; $obj_products->title = __('Products', 'mp'); $obj_products->menu_item_parent = $store_object->ID; $obj_products->ID = '99999999999'; $obj_products->db_id = '99999999999'; $obj_products->post_name = '99999999999'; $obj_products->url = mp_products_link(false, true); $obj_products->current = get_query_var('pagename') == 'product_list' ? true : false; $obj_products->current_item_ancestor = get_query_var('pagename') == 'product_list' ? true : false; $list[] = $obj_products; //if cart disabled return only the products menu item if ($this->get_setting('disable_cart')) { return $list; } $obj_cart = clone $store_object; $obj_cart->title = __('Shopping Cart', 'mp'); $obj_cart->menu_item_parent = $store_object->ID; $obj_cart->ID = '99999999999'; $obj_cart->db_id = '99999999999'; $obj_cart->post_name = '99999999999'; $obj_cart->url = mp_cart_link(false, true); $obj_cart->current = get_query_var('pagename') == 'cart' ? true : false; $obj_cart->current_item_ancestor = get_query_var('pagename') == 'cart' ? true : false; $list[] = $obj_cart; $obj_order = clone $store_object; $obj_order->title = __('Order Status', 'mp'); $obj_order->menu_item_parent = $store_object->ID; $obj_order->ID = '99999999999'; $obj_order->db_id = '99999999999'; $obj_order->post_name = '99999999999'; $obj_order->url = mp_orderstatus_link(false, true); $obj_order->current = get_query_var('pagename') == 'orderstatus' ? true : false; $obj_order->current_item_ancestor = get_query_var('pagename') == 'orderstatus' ? true : false; $list[] = $obj_order; } return $list; }
/** * Use this to do the final payment. Create the order then process the payment. If * you know the payment is successful right away go ahead and change the order status * as well. * Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors * it will redirect to the next step. * * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true * @param array $shipping_info. Contains shipping info and email in case you need it */ function process_payment($cart, $shipping_info) { global $mp, $current_user; $timestamp = time(); $settings = get_option('mp_settings'); $url = $this->API_URL . "api/checkout/v2/merchantCheckoutForm/Merchant/" . $this->API_Merchant_id; $order_id = $mp->generate_order_id(); $params = array(); $params['_type'] = 'checkout-shopping-cart'; $params['shopping-cart.merchant-private-data'] = $order_id; $params['checkout-flow-support.merchant-checkout-flow-support.edit-cart-url'] = mp_cart_link(false, true); $params["checkout-flow-support.merchant-checkout-flow-support.continue-shopping-url"] = mp_store_link(false, true); $params["checkout-flow-support.merchant-checkout-flow-support.tax-tables.default-tax-table.tax-rules.default-tax-rule-1.shipping-taxed"] = $settings['tax']['tax_shipping'] ? 'true' : 'false'; $params["checkout-flow-support.merchant-checkout-flow-support.tax-tables.default-tax-table.tax-rules.default-tax-rule-1.tax-areas.world-area-1"] = ''; $totals = array(); $item_params = array(); $i = 1; $items = 0; $coupon_code = $mp->get_coupon_code(); foreach ($cart as $product_id => $variations) { foreach ($variations as $data) { $price = $mp->coupon_value_product($coupon_code, $data['price'] * $data['quantity'], $product_id); $totals[] = $price; $item_params["shopping-cart.items.item-{$i}.item-name"] = $data['name']; $item_params["shopping-cart.items.item-{$i}.item-description"] = $data['url']; $item_params["shopping-cart.items.item-{$i}.unit-price"] = $price; $item_params["shopping-cart.items.item-{$i}.unit-price.currency"] = $this->currencyCode; $item_params["shopping-cart.items.item-{$i}.quantity"] = $data['quantity']; $item_params["shopping-cart.items.item-{$i}.merchant-item-id"] = $data['SKU']; $i++; $items++; } } $total = array_sum($totals); $params = array_merge($params, $item_params); //shipping line $shipping_tax = 0; if (($shipping_price = $mp->shipping_price(false)) !== false) { $total += $shipping_price; $shipping_tax = $mp->shipping_tax_price($shipping_price) - $shipping_price; $params["checkout-flow-support.merchant-checkout-flow-support.shipping-methods.flat-rate-shipping-1.price"] = $shipping_price; $params["checkout-flow-support.merchant-checkout-flow-support.shipping-methods.flat-rate-shipping-1.price.currency"] = $this->currencyCode; $params["checkout-flow-support.merchant-checkout-flow-support.shipping-methods.flat-rate-shipping-1.name"] = __('Standard Shipping', 'mp'); } //tax line if tax inclusive pricing is off. It it's on it would screw up the totals if (!$mp->get_setting('tax->tax_inclusive')) { $tax_price = $mp->tax_price(false) + $shipping_tax; $total += $tax_price; $params["checkout-flow-support.merchant-checkout-flow-support.tax-tables.default-tax-table.tax-rules.default-tax-rule-1.rate"] = $tax_price; } else { $params["checkout-flow-support.merchant-checkout-flow-support.tax-tables.default-tax-table.tax-rules.default-tax-rule-1.rate"] = '0.00'; } $param_list = array(); foreach ($params as $k => $v) { $param_list[] = "{$k}=" . rawurlencode($v); } $param_str = implode('&', $param_list); //setup transients for ipn in case checkout doesn't redirect (ipn should come within 12 hrs!) set_transient('mp_order_' . $order_id . '_cart', $cart, 60 * 60 * 12); set_transient('mp_order_' . $order_id . '_shipping', $shipping_info, 60 * 60 * 12); set_transient('mp_order_' . $order_id . '_userid', $current_user->ID, 60 * 60 * 12); $response = $this->google_api_request($param_str, $url); if ($response['_type'] == 'checkout-redirect') { wp_redirect($response['redirect-url']); exit; } else { $mp->cart_checkout_error(sprintf(__('There was a problem setting up your purchase with Google Checkout. Please try again or <a href="%s">select a different payment method</a>.<br/>%s', 'mp'), mp_checkout_step_url('checkout'), @$response['error-message'])); } }
function filter_list_pages($list, $args) { if ($args['depth'] == 1) { return $list; } $temp_break = strpos($list, mp_store_link(false, true) . '"'); //if we can't find the page for some reason skip if ($temp_break === false) { return $list; } $break = strpos($list, '</a>', $temp_break) + 4; $nav = substr($list, 0, $break); if (!$this->get_setting('disable_cart')) { $nav .= '<ul class="children"><li class="page_item' . (get_query_var('pagename') == 'product_list' ? ' current_page_item' : '') . '"><a href="' . mp_products_link(false, true) . '" title="' . __('Products', 'mp') . '">' . __('Products', 'mp') . '</a></li>'; $nav .= '<li class="page_item' . (get_query_var('pagename') == 'cart' ? ' current_page_item' : '') . '"><a href="' . mp_cart_link(false, true) . '" title="' . __('Shopping Cart', 'mp') . '">' . __('Shopping Cart', 'mp') . '</a></li>'; $nav .= '<li class="page_item' . (get_query_var('pagename') == 'orderstatus' ? ' current_page_item' : '') . '"><a href="' . mp_orderstatus_link(false, true) . '" title="' . __('Order Status', 'mp') . '">' . __('Order Status', 'mp') . '</a></li> </ul> '; } else { $nav .= ' <ul> <li class="page_item' . (get_query_var('pagename') == 'product_list' ? ' current_page_item' : '') . '"><a href="' . mp_products_link(false, true) . '" title="' . __('Products', 'mp') . '">' . __('Products', 'mp') . '</a></li> </ul> '; } $nav .= substr($list, $break); return $nav; }