public function vtwpr_woo_validate_order()
 {
     global $vtwpr_rules_set, $vtwpr_cart, $vtwpr_setup_options, $vtwpr_info, $woocommerce;
     vtwpr_debug_options();
     //v1.0.3
     //Open Session Variable, get rules_set and cart if not there...
     $data_chain = $this->vtwpr_get_data_chain();
     // switch from run-through at checkout time
     if (defined('VTWPR_PRO_DIRNAME') && $vtwpr_setup_options['use_lifetime_max_limits'] == 'yes') {
         /* 
         if ( $vtmam_cart->error_messages_processed == 'yes' ) {  
           $woocommerce->add_error(  __('Purchase error found.', 'vtmam') );  //supplies an error msg and prevents payment from completing 
           return;
         }
         */
         if ($vtwpr_cart->lifetime_limit_applies_to_cart == 'yes' && sizeof($vtwpr_cart->error_messages) == 0) {
             //error msg > 0 = 2nd time through HERE, customer has blessed the reduction
             //reapply rules to catch lifetime rule logic using email and address info...
             $total_discount_1st_runthrough = $vtwpr_cart->yousave_cart_total_amt;
             $vtwpr_info['checkout_validation_in_process'] = 'yes';
             $vtwpr_apply_rules = new VTWPR_Apply_Rules();
             //ERROR Message Path
             if (sizeof($vtwpr_cart->error_messages) > 0 && $vtwpr_cart->yousave_cart_total_amt < $total_discount_1st_runthrough) {
                 //2ND runthrough found additional lifetime limitations, need to alert customer
                 //insert error messages into checkout page
                 add_action('wp_head', array(&$this, 'vtwpr_display_rule_error_msg_at_checkout'));
                 //JS to insert error msgs
                 /*  turn on the messages processed switch
                         otherwise errors are processed and displayed multiple times when the
                         wpsc_checkout_form_validation filter finds an error (causes a loop around, 3x error result...) 
                     */
                 $vtwpr_cart->error_messages_processed = 'yes';
                 $woocommerce->add_error(__('Purchase error found.', 'vtwpr'));
                 //supplies an error msg and prevents payment from completing
                 /*  *********************************************************************
                       Mark checkout as having ++failed edits++, and can't progress to Payment Gateway. 
                       This works only with the filter 'wpsc_checkout_form_validation', which is activated on submit of
                       "payment" button. 
                     *************************************************************************  */
                 $is_valid = false;
             }
             /*  *************************************************
                  Load this info into session variables, to begin the 
                  DATA CHAIN - global to session back to global
                  global to session - in vtwpr_process_discount
                  session to global - in vtwpr_woo_validate_order
                  access global     - in vtwpr_post_purchase_maybe_save_log_info   
                 *************************************************   */
             $contents_total = $woocommerce->cart->cart_contents_total;
             $applied_coupons = $woocommerce->cart->applied_coupons;
             $data_chain = array();
             $data_chain[] = $vtwpr_rules_set;
             $data_chain[] = $vtwpr_cart;
             $data_chain[] = vtwpr_get_current_user_role();
             //v1.0.3
             $data_chain[] = $contents_total;
             $data_chain[] = $applied_coupons;
             $_SESSION['data_chain'] = serialize($data_chain);
         } else {
             //Get the screen data...
             vtwpr_get_purchaser_info_from_screen();
         }
     }
     return;
 }
Example #2
0
function vtwpr_load_vtwpr_cart_for_processing()
{
    global $post, $wpdb, $woocommerce, $vtwpr_cart, $vtwpr_cart_item, $vtwpr_setup_options, $vtwpr_info;
    // from Woocommerce/templates/cart/mini-cart.php  and  Woocommerce/templates/checkout/review-order.php
    $woocommerce_cart_contents = $woocommerce->cart->get_cart();
    if (sizeof($woocommerce_cart_contents) > 0) {
        $vtwpr_cart = new vtwpr_Cart();
        foreach ($woocommerce_cart_contents as $cart_item_key => $cart_item) {
            $_product = $cart_item['data'];
            if ($_product->exists() && $cart_item['quantity'] > 0) {
                $vtwpr_cart_item = new vtwpr_Cart_Item();
                //the product id does not change in woo if variation purchased.
                //  Load expected variation id, if there, along with constructed product title.
                $varLabels = ' ';
                if ($cart_item['variation_id'] > ' ') {
                    // get parent title
                    $parent_post = get_post($cart_item['product_id']);
                    // get variation names to string onto parent title
                    foreach ($cart_item['variation'] as $key => $value) {
                        $varLabels .= $value . '&nbsp;';
                    }
                    $vtwpr_cart_item->product_id = $cart_item['variation_id'];
                    $vtwpr_cart_item->variation_array = $cart_item['variation'];
                    $vtwpr_cart_item->product_name = $parent_post->post_title . '&nbsp;' . $varLabels;
                    $vtwpr_cart_item->parent_product_name = $parent_post->post_title;
                } else {
                    $vtwpr_cart_item->product_id = $cart_item['product_id'];
                    $vtwpr_cart_item->product_name = $_product->get_title() . $woocommerce->cart->get_item_data($cart_item);
                }
                $vtwpr_cart_item->quantity = $cart_item['quantity'];
                $product_id = $vtwpr_cart_item->product_id;
                //***always*** will be a session found
                //$session_found = vtwpr_maybe_get_product_session_info($product_id);
                vtwpr_maybe_get_product_session_info($product_id);
                //By this time, there may  be a 'display' session variable for this product, if a discount was displayed in the catalog
                //  so 2nd - nth iteration picks up the original unit price, not any discount shown currently
                //  The discount is applied in apply-rules for disambiguation, then rolled out before it gets processed (again)     product_discount_price
                if ($vtwpr_info['product_session_info']['product_discount_price'] > 0) {
                    $vtwpr_cart_item->unit_price = $vtwpr_info['product_session_info']['product_unit_price'];
                    $vtwpr_cart_item->db_unit_price = $vtwpr_info['product_session_info']['product_unit_price'];
                    $vtwpr_cart_item->db_unit_price_special = $vtwpr_info['product_session_info']['product_special_price'];
                    $vtwpr_cart_item->db_unit_price_list = $vtwpr_info['product_session_info']['product_list_price'];
                } else {
                    //vat_exempt seems to be the same as tax exempt, using the same field???
                    //  how does this work with taxes included in price?
                    //  how about shipping includes taxes, then roll out taxes (vat_exempt) ???
                    //FROM my original plugins:  $vtwpr_cart_item->unit_price     =  get_option( 'woocommerce_display_cart_prices_excluding_tax' ) == 'yes' || $woocommerce->customer->is_vat_exempt() ? $_product->get_price_excluding_tax() : $_product->get_price();
                    //FROM woo cart		$product_price = get_option( 'woocommerce_tax_display_cart' ) == 'excl' ? $_product->get_price_excluding_tax() : $_product->get_price_including_tax();
                    //  combining the two:::
                    //DON'T USE THIS ANYMORE, BECOMES SELF-REFERENTIAL, AS GET_PRICE() NOW HOOKS THE SINGLE PRODUCT DISCOUNT ...
                    //    $vtwpr_cart_item->unit_price     =  get_option( 'woocommerce_tax_display_cart' ) == 'excl' || $woocommerce->customer->is_vat_exempt() ? $_product->get_price_excluding_tax() : $_product->get_price();
                    //v1.0.3 begin - redo for VAT processing...
                    $regular_price = get_post_meta($product_id, '_regular_price', true);
                    if ($regular_price > 0) {
                        $vtwpr_cart_item->db_unit_price_list = $regular_price;
                    } else {
                        $vtwpr_cart_item->db_unit_price_list = get_post_meta($product_id, '_price', true);
                    }
                    $vtwpr_cart_item->db_unit_price_special = get_post_meta($product_id, '_sale_price', true);
                    if (get_option('woocommerce_prices_include_tax') == 'no' || $woocommerce->customer->is_vat_exempt()) {
                        //NO VAT included in price
                        $vtwpr_cart_item->unit_price = $cart_item['line_subtotal'] / $cart_item['quantity'];
                    } else {
                        //VAT included in price, and $cart_item pricing has already subtracted out the VAT, so use DB prices (otherwise if other functions called, recursive processing will ensue...)
                        switch (true) {
                            case $vtwpr_cart_item->db_unit_price_special > 0:
                                if ($vtwpr_cart_item->db_unit_price_list < 0 || $vtwpr_cart_item->db_unit_price_special < $vtwpr_cart_item->db_unit_price_list) {
                                    //item is on sale, use sale price
                                    $vtwpr_cart_item->unit_price = $vtwpr_cart_item->db_unit_price_special;
                                } else {
                                    //use regular price
                                    $vtwpr_cart_item->unit_price = $vtwpr_cart_item->db_unit_price_list;
                                }
                                break;
                            default:
                                $vtwpr_cart_item->unit_price = $vtwpr_cart_item->db_unit_price_list;
                                break;
                        }
                        /*
                        if ( ($vtwpr_cart_item->db_unit_price_special > 0) &&
                             ($vtwpr_cart_item->db_unit_price_special < $vtwpr_cart_item->db_unit_price_list) ) {
                          $vtwpr_cart_item->unit_price = $vtwpr_cart_item->db_unit_price_special;
                        } else {
                          $vtwpr_cart_item->unit_price = $vtwpr_cart_item->db_unit_price_list;
                        }
                        */
                    }
                    $vtwpr_cart_item->db_unit_price = $vtwpr_cart_item->unit_price;
                    //v1.0.3 end
                }
                // db_unit_price_special CAN be zero if item is FREE!!
                if ($vtwpr_cart_item->unit_price < $vtwpr_cart_item->db_unit_price_list) {
                    $vtwpr_cart_item->product_is_on_special = 'yes';
                }
                $vtwpr_cart_item->total_price = $vtwpr_cart_item->quantity * $vtwpr_cart_item->unit_price;
                /*  *********************************
                 ***  JUST the cat *ids* please...
                 ************************************ */
                $vtwpr_cart_item->prod_cat_list = wp_get_object_terms($cart_item['product_id'], $vtwpr_info['parent_plugin_taxonomy'], $args = array('fields' => 'ids'));
                $vtwpr_cart_item->rule_cat_list = wp_get_object_terms($cart_item['product_id'], $vtwpr_info['rulecat_taxonomy'], $args = array('fields' => 'ids'));
                //initialize the arrays
                $vtwpr_cart_item->prod_rule_include_only_list = array();
                $vtwpr_cart_item->prod_rule_exclusion_list = array();
                /*  *********************************
                 ***  fill in include/exclude arrays if selected on the PRODUCT Screen (parent plugin)
                 ************************************ */
                $vtwpr_includeOrExclude_meta = get_post_meta($cart_item['product_id'], $vtwpr_info['product_meta_key_includeOrExclude'], true);
                //v1.0.4  use the parent ID at all times!
                if ($vtwpr_includeOrExclude_meta) {
                    switch ($vtwpr_includeOrExclude_meta['includeOrExclude_option']) {
                        case 'includeAll':
                            break;
                        case 'includeList':
                            $vtwpr_cart_item->prod_rule_include_only_list = $vtwpr_includeOrExclude_meta['includeOrExclude_checked_list'];
                            break;
                        case 'excludeList':
                            $vtwpr_cart_item->prod_rule_exclusion_list = $vtwpr_includeOrExclude_meta['includeOrExclude_checked_list'];
                            break;
                        case 'excludeAll':
                            $vtwpr_cart_item->prod_rule_exclusion_list[0] = 'all';
                            //set the exclusion list to exclude all
                            break;
                    }
                }
                //add cart_item to cart array
                $vtwpr_cart->cart_items[] = $vtwpr_cart_item;
            }
        }
        //	endforeach;
    }
    //end  if (sizeof($woocommerce->cart->get_cart())>0)
    if (defined('VTWPR_PRO_DIRNAME') && $vtwpr_setup_options['use_lifetime_max_limits'] == 'yes') {
        vtwpr_get_purchaser_info_from_screen();
    }
    $vtwpr_cart->purchaser_ip_address = $vtwpr_info['purchaser_ip_address'];
}