function eStore_calc_new_per_item_price($ret_coupon, $amount, $quantity)
{
    if ($ret_coupon->discount_type == 1) {
        global $total_cond_discount;
        $total_discount_amount = $ret_coupon->discount_value;
        $total_items_in_cart = eStore_get_total_cart_item_qty();
        $per_item_discount_amount = $total_discount_amount / $total_items_in_cart;
        $new_per_item_price = max($amount - $per_item_discount_amount, 0);
        $total_cond_discount = $total_cond_discount + $per_item_discount_amount * $quantity;
    } else {
        $new_per_item_price = eStore_calc_new_item_total($ret_coupon, $amount, $quantity) / $quantity;
    }
    return round($new_per_item_price, 2);
}
function eStore_manual_gateway_form_processing_code()
{
    if (isset($_POST['submit_shipping'])) {
        if (eStore_get_total_cart_item_qty() < 1) {
            //Cart does not have any item
            echo '<div class="eStore_error_message">Error! Your shopping cart is empty. Please add items to your cart before checking out.</div>';
            return;
        }
        $input_verified = false;
        global $wpdb;
        $wp_eStore_config = WP_eStore_Config::getInstance();
        $err_msg = eStore_check_address_details();
        if (!empty($err_msg)) {
            $msg = '<div id="error">';
            $msg .= ESTORE_REQUIRED_FIELDS_MISSING;
            $msg .= $err_msg;
            $msg .= '</div>';
            echo $msg;
        } else {
            //Fire the begin processing hook
            $clientip = $_SERVER['REMOTE_ADDR'];
            $clientemail = $_POST['email'];
            do_action('eStore_begin_manual_co_processing', $clientemail, $clientip);
            $last_records_id = $wp_eStore_config->getValue('eStore_custom_receipt_counter');
            //get_option('eStore_custom_receipt_counter');
            if (empty($last_records_id)) {
                $last_records_id = 0;
            }
            $receipt_counter = $last_records_id + 1;
            $wp_eStore_config->setValue('eStore_custom_receipt_counter', $receipt_counter);
            $wp_eStore_config->saveConfig();
            $address = $_POST['address'] . ", " . $_POST['city'] . ", " . $_POST['state'] . " " . $_POST['postcode'] . " " . $_POST['country'];
            $payment_data = extract_manaul_co_general_payment_data($_POST['firstname'], $_POST['lastname'], $_POST['email'], $address, $_POST['phone']);
            $cart_items = extract_manual_item_data();
            $cust_direction = get_option('eStore_manual_co_cust_direction');
            $curr_symbol = get_option('cart_currency_symbol');
            if (!empty($cust_direction)) {
                $cust_direction_mod = eStore_apply_post_payment_dynamic_tags($cust_direction, $payment_data, $cart_items);
                $body .= "\n-------------------------------\n";
                $body .= $cust_direction_mod;
                $body .= "\n-------------------------------\n";
            }
            $count = 1;
            $constructed_download_link .= "<br />";
            $product_key_data = "";
            $show_tax_inc_price = $wp_eStore_config->getValue('eStore_show_tax_inclusive_price');
            foreach ($_SESSION['eStore_cart'] as $item) {
                $products_table_name = $wpdb->prefix . "wp_eStore_tbl";
                $key = $item['item_number'];
                $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$key}'", OBJECT);
                $rounded_price = round($item['price'], 2);
                $body .= "\n" . WP_ESTORE_DETAILS_OF_ORDERED_PRODUCT . ": " . $count;
                $body .= "\n-------------------------";
                $body .= "\n" . ESTORE_PRODUCT_ID . ": " . $item['item_number'];
                $body .= "\n" . ESTORE_PRODUCT_NAME . ": " . $item['name'];
                if ($show_tax_inc_price == '1') {
                    $rounded_price = eStore_get_tax_include_price_by_prod_id($item['item_number'], $rounded_price);
                }
                $formatted_price = print_digi_cart_payment_currency($rounded_price, $curr_symbol);
                $body .= "\n" . ESTORE_PRICE . ": " . $formatted_price;
                $body .= "\n" . ESTORE_QUANTITY . ": " . $item['quantity'] . "\n";
                if (get_option('eStore_manual_co_give_download_links') != '') {
                    $download_link = generate_download_link_for_product($item['item_number'], $item['name'], $payment_data);
                    $constructed_download_link .= $download_link . "<br />";
                    $body .= $download_link . "\n";
                    $product_key = eStore_post_sale_retrieve_serial_key_and_update($retrieved_product, $item['name'], $item['quantity']);
                    $product_key_data .= $product_key;
                    $body .= $product_key;
                    $product_specific_instructions = eStore_get_product_specific_instructions($retrieved_product);
                    $product_specific_instructions = eStore_apply_post_payment_dynamic_tags($product_specific_instructions, $payment_data, $cart_items);
                    $body .= $product_specific_instructions;
                }
                $count++;
                //Check and signup WishList or WP eMember user if needed
                //if(get_option('eStore_manual_co_auto_update_db')=='1')
                if ($wp_eStore_config->getValue('eStore_manual_co_auto_create_membership') == '1') {
                    $member_ref = $retrieved_product->ref_text;
                    eStore_payment_debug('Checking if membership inegration is being used. Reference Text Value: ' . $member_ref, true);
                    if (!empty($member_ref)) {
                        if (get_option('eStore_enable_wishlist_int')) {
                            eStore_payment_debug('WishList integration is being used... doing member account creation/upgrade task... see the "subscription_handle_debug.log" file for details', true);
                            wl_handle_subsc_signup($payment_data, $member_ref, $payment_data['txn_id']);
                        } else {
                            if (function_exists('wp_eMember_install')) {
                                $eMember_id = $payment_data['eMember_userid'];
                                eStore_payment_debug('eMember integration is being used... doing member account creation/upgrade task... see the "subscription_handle_debug.log" file for details', true);
                                eMember_handle_subsc_signup($payment_data, $member_ref, $payment_data['txn_id'], $eMember_id);
                            }
                        }
                    }
                }
                //=== End of membership handling code ===
            }
            $body .= "\n-------------------------------\n";
            if ($show_tax_inc_price != '1') {
                $body .= ESTORE_SUB_TOTAL . ": " . print_digi_cart_payment_currency($_SESSION['eStore_cart_sub_total'], $curr_symbol);
            }
            if (!empty($_SESSION['eStore_cart_postage_cost'])) {
                $body .= "\n" . ESTORE_SHIPPING . ": " . print_digi_cart_payment_currency($_SESSION['eStore_cart_postage_cost'], $curr_symbol);
            }
            if (!empty($_SESSION['eStore_cart_total_tax'])) {
                $body .= "\n" . WP_ESTORE_TAX . ": " . print_digi_cart_payment_currency($_SESSION['eStore_cart_total_tax'], $curr_symbol);
            }
            $total = $_SESSION['eStore_cart_sub_total'] + $_SESSION['eStore_cart_postage_cost'] + $_SESSION['eStore_cart_total_tax'];
            $body .= "\n" . ESTORE_TOTAL . ": " . print_digi_cart_payment_currency($total, $curr_symbol);
            $conversion_rate = get_option('eStore_secondary_currency_conversion_rate');
            if (!empty($conversion_rate)) {
                $secondary_curr_symbol = get_option('eStore_secondary_currency_symbol');
                $body .= "\n" . ESTORE_TOTAL . ' (' . get_option('eStore_secondary_currency_code') . '): ' . print_digi_cart_payment_currency($total * $conversion_rate, $secondary_curr_symbol);
            }
            if (isset($_SESSION['eStore_store_pickup_checked']) && $_SESSION['eStore_store_pickup_checked'] == '1') {
                $body .= "\nStore Pickup: Yes";
            }
            $total_items = $count - 1;
            $body .= "\n" . WP_ESTORE_TOTAL_ITEMS_ORDERED . ": " . $total_items;
            $body .= "\n" . ESTORE_TRANSACTION_ID . ": " . $payment_data['txn_id'];
            $body .= "\n\n" . WP_ESTORE_CUSTOMER_DETAILS;
            $body .= "\n-------------------------";
            $body .= "\n" . WP_ESTORE_NAME . ": " . $_POST['firstname'] . " " . $_POST['lastname'];
            $body .= "\n" . ESTORE_EMAIL . ": " . $_POST['email'];
            $body .= "\n" . ESTORE_PHONE . ": " . $_POST['phone'];
            $body .= "\n" . ESTORE_ADDRESS . ": " . $_POST['address'];
            $body .= "\n" . ESTORE_CITY . ": " . $_POST['city'];
            $body .= "\n" . ESTORE_STATE . ": " . $_POST['state'];
            $body .= "\n" . ESTORE_POSTCODE . ": " . $_POST['postcode'];
            $body .= "\n" . ESTORE_COUNTRY . ": " . $_POST['country'];
            $body .= "\n" . WP_ESTORE_ADDITIONAL_COMMENT . ": " . $_POST['additional_comment'];
            $notify_email = get_option('eStore_manual_notify_email');
            $buyer_email = $_POST['email'];
            if (empty($notify_email)) {
                $notify_email = get_bloginfo('admin_email');
            }
            // Get referrer
            if (!empty($_SESSION['ap_id'])) {
                $referrer = $_SESSION['ap_id'];
            } else {
                if (isset($_COOKIE['ap_id'])) {
                    $referrer = $_COOKIE['ap_id'];
                }
            }
            //Call the filter for email notification body
            eStore_payment_debug('Applying filter - eStore_notification_email_body_filter', true);
            $body = apply_filters('eStore_notification_email_body_filter', $body, $payment_data, $cart_items);
            $seller_email_body = $body . "\n\n" . WP_ESTORE_REFERRER . ": " . $referrer;
            $from_email_address = get_option('eStore_download_email_address');
            $headers = 'From: ' . $from_email_address . "\r\n";
            // Notify Seller
            $n_subject = $wp_eStore_config->getValue('seller_email_subject_manual_co');
            if (empty($n_subject)) {
                $n_subject = get_option('eStore_seller_email_subj');
            }
            wp_mail($notify_email, $n_subject, $seller_email_body, $headers);
            // Notify Buyer
            $buyer_email_subj = $wp_eStore_config->getValue('buyer_email_subject_manual_co');
            if (empty($buyer_email_subj)) {
                $buyer_email_subj = get_option('eStore_buyer_email_subj');
            }
            wp_mail($buyer_email, $buyer_email_subj, $body, $headers);
            if (!empty($product_key_data)) {
                //Lets add any serial key info to the data
                $payment_data['product_key_data'] = $product_key_data;
            }
            //Fire the manual checkout hook
            do_action('eStore_manual_checkout_form_data', $payment_data, $cart_items);
            //Add to the customer database if the option is enabled
            if (get_option('eStore_manual_co_auto_update_db') == '1') {
                record_sales_data($payment_data, $cart_items);
            }
            //Perform autoresponder signup
            if (get_option('eStore_manual_co_do_autoresponder_signup') == '1') {
                eStore_item_specific_autoresponder_signup($cart_items, $_POST['firstname'], $_POST['lastname'], $_POST['email']);
                eStore_global_autoresponder_signup($_POST['firstname'], $_POST['lastname'], $_POST['email']);
            }
            //Award Affiliate Commission
            eStore_award_commission_manual_co($payment_data, $cart_items);
            // Revenue sharing
            eStore_award_author_commission_manual_co($payment_data, $cart_items);
            //Create affiliate account if needed
            eStore_handle_auto_affiliate_account_creation($payment_data);
            //Post IPN data to external site if needed
            eStore_POST_IPN_data_to_url($payment_data, '', $cart_items);
            //Save transaction result for thank you page display
            if (get_option('eStore_manual_co_give_download_links') != '') {
                $constructed_download_link = wp_eStore_replace_url_in_string_with_link($constructed_download_link);
                eStore_save_trans_result_for_thank_you_page_display($payment_data, $constructed_download_link, $cart_items);
            }
            $return_url = get_option('eStore_manual_return_url');
            if (empty($return_url)) {
                $return_url = get_bloginfo('wpurl');
            }
            //Google analytics tracking
            if (get_option('eStore_enable_analytics_tracking') && get_option('eStore_manual_co_give_download_links') != '') {
                eStore_track_ga_ecommerce($payment_data, $cart_items);
                $return_url = eStore_append_http_get_data_to_url($return_url, "eStore_manual_co_track_ga", "1");
            }
            //Reset cart and redirect to Thank you page
            reset_eStore_cart();
            eStore_redirect_to_url($return_url);
        }
    }
}
function eStore_cart_display_items_part($currency_symbol, $decimal, $fancy = '')
{
    $wp_eStore_config = WP_eStore_Config::getInstance();
    if (get_option('eStore_use_auto_discount')) {
        $total = eStore_get_cart_total();
        $total_items = eStore_get_total_cart_item_qty();
        // Auto discount for normal purchase
        $amt_threshold = get_option('eStore_amount_threshold_auto_coupon');
        if (!empty($amt_threshold) && $total > $amt_threshold) {
            if (isset($_SESSION['discount_applied_once']) && $_SESSION['discount_applied_once'] == 1) {
                eStore_load_price_from_backed_up_cart();
                unset($_SESSION['discount_applied_once']);
            }
            $coupon = get_option('eStore_amount_threshold_auto_coupon_code');
            eStore_apply_discount($coupon);
            $_SESSION['auto_discount_applied_once'] = 1;
        }
        $qty_threshold = get_option('eStore_qty_threshold_auto_coupon');
        if (!empty($qty_threshold) && $total_items > $qty_threshold) {
            if (isset($_SESSION['discount_applied_once']) && $_SESSION['discount_applied_once'] == 1) {
                eStore_load_price_from_backed_up_cart();
                unset($_SESSION['discount_applied_once']);
            }
            $coupon = get_option('eStore_qty_threshold_auto_coupon_code');
            eStore_apply_discount($coupon);
            $_SESSION['auto_discount_applied_once'] = 1;
        }
    }
    $output = "";
    $total_items = 0;
    $total = 0;
    $item_total_shipping = 0;
    if ($_SESSION['eStore_cart'] && is_array($_SESSION['eStore_cart'])) {
        $output .= '<tr>
        <th class="eStore_cart_item_name">' . ESTORE_ITEM_NAME . '</th>';
        if ($wp_eStore_config->getValue('eStore_do_not_show_qty_in_cart')) {
            $output .= '<th></th>';
        } else {
            $output .= '<th class="eStore_cart_item_qty">' . ESTORE_QUANTITY . '</th>';
        }
        $output .= '<th class="eStore_cart_item_price">' . ESTORE_PRICE . '</th><th></th>
        </tr>';
        foreach ($_SESSION['eStore_cart'] as $item) {
            //Draw the line item
            if (!empty($fancy)) {
                if ($fancy == "2") {
                    $output .= eStore_cart_display_line_item_fancy2($item, $currency_symbol, $decimal);
                }
            } else {
                $output .= eStore_cart_display_line_item($item, $currency_symbol, $decimal);
            }
            //End drawing line item
            $total += $item['price'] * $item['quantity'];
            $item_total_shipping += $item['shipping'] * $item['quantity'];
            $total_items += $item['quantity'];
        }
        $_SESSION['eStore_cart_sub_total'] = $total;
        //Check the shipping variation price
        if (!isset($_SESSION['eStore_selected_shipping_option_cost'])) {
            $_SESSION['eStore_selected_shipping_option_cost'] = 0;
        }
        if (isset($_POST['eStore_shipping_variation'])) {
            $_POST['eStore_shipping_variation'] = strip_tags($_POST['eStore_shipping_variation']);
            $pieces = explode('|', $_POST['eStore_shipping_variation']);
            $_SESSION['eStore_selected_shipping_option'] = $pieces[0];
            if (!empty($pieces[1])) {
                $_SESSION['eStore_selected_shipping_option_cost'] = $pieces[1];
            } else {
                $_SESSION['eStore_selected_shipping_option_cost'] = 0;
            }
        }
        // Base shipping can only be used in conjunction with individual item shipping
        if ($item_total_shipping != 0) {
            $baseShipping = get_option('eStore_base_shipping');
            $postage_cost = $item_total_shipping + $baseShipping;
            $_SESSION['eStore_cart_postage_cost'] = $postage_cost + $_SESSION['eStore_selected_shipping_option_cost'];
        } else {
            $postage_cost = 0;
            $_SESSION['eStore_cart_postage_cost'] = $postage_cost + $_SESSION['eStore_selected_shipping_option_cost'];
        }
        if (get_option('eStore_use_auto_discount')) {
            // Auto shipping discount
            $amt_threshold_free_shipping = get_option('eStore_amount_free_shipping_threshold');
            if (!empty($amt_threshold_free_shipping) && $total > $amt_threshold_free_shipping) {
                $postage_cost = 0;
                $_SESSION['eStore_cart_postage_cost'] = $postage_cost;
                $_SESSION['eStore_last_action_msg_3'] = '<p style="color: green;">' . ESTORE_TOTAL_DISCOUNT . ESTORE_DISCOUNT_FREE_SHIPPING;
            }
            $qty_threshold_free_shipping = get_option('eStore_qty_free_shipping_threshold');
            if (!empty($qty_threshold_free_shipping) && $total_items > $qty_threshold_free_shipping) {
                $postage_cost = 0;
                $_SESSION['eStore_cart_postage_cost'] = $postage_cost;
                $_SESSION['eStore_last_action_msg_3'] = '<p style="color: green;">' . ESTORE_TOTAL_DISCOUNT . ESTORE_DISCOUNT_FREE_SHIPPING;
            }
        }
    }
    $below_item_details_section = "";
    $below_item_details_section = apply_filters('eStore_below_item_details_filter', $below_item_details_section);
    if (!empty($below_item_details_section)) {
        $output .= '<div class="eStore_below_item_details">' . $below_item_details_section . '</div>';
    }
    do_action('eStore_action_after_cart_items_details');
    return $output;
}
Beispiel #4
0
function is_quantity_availabe($id, $requested_quantity, $prod_name = "")
{
    if (!is_numeric($requested_quantity)) {
        $_SESSION['eStore_last_action_msg'] = '<p style="color: red;">' . ESTORE_ENTER_A_NUMBER_FOR_QTY . '</p>';
        return false;
    }
    global $wpdb;
    $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
    $ret_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$id}'", OBJECT);
    if (!$ret_product) {
        //Invalid item ID
        echo "<br />Error! Invalid item ID passed to the is_quantity_availabe() function";
        return false;
    }
    $args = array('id' => $id, 'requested_quantity' => $requested_quantity, 'prod_name' => $prod_name);
    $qty_available_chk_result = "";
    $qty_available_chk_result = apply_filters('eStore_qty_available_filter', $qty_available_chk_result, $args);
    if (!empty($qty_available_chk_result)) {
        $_SESSION['eStore_last_action_msg_2'] = '<p style="color: red;">' . $qty_available_chk_result . '</p>';
        return false;
    }
    //Check per customer quantity limit
    if (is_numeric($ret_product->per_customer_qty_limit)) {
        $client_ip = $_SERVER['REMOTE_ADDR'];
        $purchased_qty = 0;
        $customer_table_name = WP_ESTORE_CUSTOMER_TABLE_NAME;
        $resultset = $wpdb->get_results("SELECT * FROM {$customer_table_name} WHERE ipaddress = '{$client_ip}' and purchased_product_id = '{$id}'", OBJECT);
        foreach ($resultset as $row) {
            $purchased_qty += $row->purchase_qty;
        }
        if (isset($_REQUEST['eStore_cquantity'])) {
            //This is a change quantity request in the cart
            $total_qty_for_this_item = $purchased_qty + $requested_quantity;
        } else {
            //Add to cart request
            $total_qty_for_this_item = $purchased_qty + $requested_quantity;
            //Alt logic below
            //$new_qty_to_add = strip_tags($_POST['add_qty']);
            //$current_item_qty_in_cart = eStore_get_current_cart_item_qty_for_product($id);
            //$total_qty_for_this_item = $current_item_qty_in_cart + $purchased_qty + $new_qty_to_add;
        }
        if ($total_qty_for_this_item > $ret_product->per_customer_qty_limit) {
            $_SESSION['eStore_last_action_msg_2'] = '<p style="color: red;">' . ESTORE_ITEM_LIMIT_EXCEEDED . '</p>';
            return false;
        }
    }
    //Check cart item limit
    if (is_numeric(WP_ESTORE_CART_CHECKOUT_ITEM_LIMIT) && WP_ESTORE_CART_CHECKOUT_ITEM_LIMIT > 0) {
        $current_item_qty_in_cart = eStore_get_total_cart_item_qty();
        if ($current_item_qty_in_cart >= WP_ESTORE_CART_CHECKOUT_ITEM_LIMIT) {
            $_SESSION['eStore_last_action_msg_2'] = '<p style="color: red;">' . ESTORE_CART_QTY_LIMIT_EXCEEDED . WP_ESTORE_CART_CHECKOUT_ITEM_LIMIT . '</p>';
            return false;
        }
    }
    if (is_numeric($ret_product->available_copies)) {
        if ($ret_product->available_copies >= $requested_quantity) {
            //$_SESSION['eStore_last_action_msg'] = '<p style="color: green;">'.ESTORE_QTY_UPDATED.'</p>';
            return true;
        } else {
            $_SESSION['eStore_last_action_msg'] = '<p style="color: red;">' . ESTORE_QUANTITY_LIMIT_EXCEEDED . ' ' . ESTORE_AVAILABLE_QTY . ': ' . $ret_product->available_copies . '</p>';
            $_SESSION['action_msg_set_time'] = time();
            return false;
        }
    } else {
        //$_SESSION['eStore_last_action_msg'] = '<p style="color: green;">'.ESTORE_QTY_UPDATED.'</p>';
        return true;
    }
}