예제 #1
0
 public function vtprd_maybe_before_mini_cart()
 {
     //error_log( print_r(  'Function begin - vtprd_maybe_before_mini_cart', true ) );
     //v1.1.1 begin -
     // "do_no_actions" set/unset in function  vtprd_build_product_price_array
     if (!isset($_SESSION)) {
         session_start();
         header("Cache-Control: no-cache");
         header("Pragma: no-cache");
     }
     if (isset($_SESSION['do_no_actions']) && $_SESSION['do_no_actions']) {
         //error_log( print_r(  'before_mini_cart - do_no_actions EXIT ', true ) );
         return;
     }
     //v1.1.1 end
     global $woocommerce, $vtprd_info, $vtprd_setup_options, $vtprd_cart, $vtprd_cart_item, $vtprd_rules_set;
     vtprd_debug_options();
     //v1.1
     if ($vtprd_cart == null || !isset($vtprd_cart->cart_items)) {
         //v1.1.1 was losing addressability to cart_items array...
         $data_chain = $this->vtprd_get_data_chain();
         if ($vtprd_cart == null) {
             //haven't had the cart call yet...
             //error_log( print_r(  'before_mini_cart - $vtprd_cart == null EXIT ', true ) );
             return;
         }
     }
     $mini_cart_updated = false;
     $cart_object = $woocommerce->cart->get_cart();
     foreach ($cart_object as $cart_item_key => $cart_item_value) {
         /* v1.1.0.6  REMOVED
            //  If formerly free item is purchased, mini-cart update may be needed
            //price already at zero, no update needed
            if ($cart_item_value['data']->price == 0) {
              continue;
            }
            */
         if ($cart_item_value['variation_id'] > ' ') {
             $woo_product_id = $cart_item_value['variation_id'];
         } else {
             $woo_product_id = $cart_item_value['product_id'];
         }
         if ($vtprd_setup_options['discount_taken_where'] == 'discountUnitPrice') {
             foreach ($vtprd_cart->cart_items as $vtprd_key => $vtprd_cart_item) {
                 //******************************
                 //v1.1.1
                 // GLOBAL CHANGE ==>> $key to $cart_item_key, $value to $cart_item_value
                 //  CHANGE to compare WOO item key rather than product ID WHICH IS NOT UNIQUE for the measurements plugin
                 //******************************
                 if ($vtprd_cart_item->cart_item_key == $cart_item_key) {
                     //v1.1.1
                     vtprd_get_product_session_info($vtprd_cart_item->product_id);
                     //this will now pick up BOTH inline discounts, and solo CATLOG discounts...
                     switch (true) {
                         case $vtprd_cart_item->product_inline_discount_price_woo > 0 || $vtprd_cart_item->product_inline_discount_price_woo == 0 && $vtprd_cart_item->product_discount_price_woo == 0 && $vtprd_cart_item->yousave_total_amt > 0:
                             //there is a discount...
                             //v1.0.9.3 spec begin
                             $cart_item_value['data']->price = $this->vtprd_choose_mini_cart_price($vtprd_cart_item);
                             //$vtprd_cart_item->product_inline_discount_price_woo;   //$vtprd_cart_item->discount_price;    //
                             //v1.0.9.3 spec end
                             $mini_cart_updated = true;
                             break;
                         case $vtprd_cart_item->product_discount_price_woo > 0:
                             $cart_item_value['data']->price = $this->vtprd_choose_mini_cart_price($vtprd_cart_item);
                             //$vtprd_cart_item->discount_price;    //
                             $mini_cart_updated = true;
                             break;
                         case $vtprd_cart_item->unit_price < $cart_item_value['data']->price:
                             //Pick up a **solo CATALOG price reduction**
                             $cart_item_value['data']->price = $vtprd_cart_item->unit_price;
                             /*$this->vtprd_choose_unit_price($vtprd_cart_item);*/
                             $mini_cart_updated = true;
                             break;
                     }
                 }
             }
             //end foreach
         } else {
             // **discountCoupon path**
             /*
                       foreach($vtprd_cart->cart_items as $vtprd_key => $vtprd_cart_item) {      
                         if ($vtprd_cart_item->cart_item_key == $cart_item_key ) {
                             //if ADDon, move the cart value in all cases => this is the CATALOG price
                             $cart_item_value['data']->price = $vtprd_cart_item->unit_price;  
                             $mini_cart_updated = true;
                             break; //FOund it - get out of  $vtprd_cart->cart_items foreach            
                         }      
                       
                       }
             */
             //check to be sure any **Catalog** deal prices are reflected here - *** 2nd-nth time, these numbers are not reflected in the mini-cart ***
             vtprd_maybe_get_product_session_info($woo_product_id);
             //v1.1.1 begin
             //***************************************************************************
             //for ADDONS product, unit price getting lost for discountCOUPON - go find it!
             // Unit Price will already reflect any Catalog discount, if available
             //***************************************************************************
             if (class_exists('WC_Product_Addons') && $vtprd_info['product_session_info']['product_has_addons']) {
                 foreach ($vtprd_cart->cart_items as $vtprd_key => $vtprd_cart_item) {
                     if ($vtprd_cart_item->cart_item_key == $cart_item_key) {
                         //if ADDon, move the cart value in all cases => this is the CATALOG price
                         $cart_item_value['data']->price = $vtprd_cart_item->unit_price;
                         $mini_cart_updated = true;
                         break;
                         //FOund it - get out of  $vtprd_cart->cart_items foreach
                     }
                 }
             } else {
                 //v1.1.1 end
                 if (isset($vtprd_info['product_session_info']['product_discount_price'])) {
                     //v1.1.0.6 added isset test
                     if (($vtprd_info['product_session_info']['product_discount_price'] > 0 || $vtprd_info['product_session_info']['product_discount_price'] == 0 && $vtprd_info['product_session_info']['product_yousave_total_amt'] > 0) && $vtprd_info['product_session_info']['product_discount_price'] < $cart_item_value['data']->price) {
                         $cart_item_value['data']->price = $vtprd_info['product_session_info']['product_discount_price'];
                         $mini_cart_updated = true;
                     }
                 }
             }
         }
         //end if
     }
     //end foreach
     if ($mini_cart_updated) {
         $_SESSION['internal_call_for_calculate_totals'] = true;
         $woocommerce->cart->calculate_totals();
         //error_log( print_r(  'before_mini_cart - calculate_totals ', true ) );
     } else {
         //v1.1.1.2 begin -  totals are messed up session 1st time through  (very weird)
         if ($vtprd_setup_options['discount_taken_where'] == 'discountCoupon' && $vtprd_info['ruleset_contains_auto_add_free_product'] == 'yes') {
             $_SESSION['internal_call_for_calculate_totals'] = true;
             $woocommerce->cart->calculate_totals();
         }
     }
     //v1.1.1.2 end
     //error_log( print_r(  'before_mini_cart - $woocommerce->cart at END', true ) );
     //error_log( var_export($woocommerce->cart, true ) );
     //error_log( print_r(  'before_mini_cart - $vtprd_cart at END', true ) );
     //error_log( var_export($vtprd_cart, true ) );
     return;
 }
 public function vtprd_maybe_before_mini_cart()
 {
     global $woocommerce, $vtprd_info, $vtprd_setup_options, $vtprd_cart, $vtprd_cart_item, $vtprd_rules_set;
     //error_log( print_r(  'IN vtprd_maybe_before_mini_cart ' , true ) );
     vtprd_debug_options();
     //v1.1
     if ($vtprd_cart == null) {
         $data_chain = $this->vtprd_get_data_chain();
         if ($vtprd_cart == null) {
             //haven't had the cart call yet...
             return;
         }
     }
     $mini_cart_updated = false;
     $cart_object = $woocommerce->cart->get_cart();
     //error_log( print_r(  '$cart_object= ' , true ) );
     //error_log( var_export($cart_object , true ) );
     foreach ($cart_object as $key => $value) {
         //error_log( print_r(  'IN vtprd_maybe_before_mini_cart FOReach1', true ) );
         //error_log( print_r(  '$woo_cart_item ' , true ) );
         //error_log( var_export($value , true ) );
         /* v1.1.0.6  REMOVED
            //  If formerly free item is purchased, mini-cart update may be needed
            //price already at zero, no update needed
            if ($value['data']->price == 0) {
              continue;
            }
            */
         if ($value['variation_id'] > ' ') {
             $woo_product_id = $value['variation_id'];
         } else {
             $woo_product_id = $value['product_id'];
         }
         if ($vtprd_setup_options['discount_taken_where'] == 'discountUnitPrice') {
             foreach ($vtprd_cart->cart_items as $vtprd_key => $vtprd_cart_item) {
                 //error_log( print_r(  'IN vtprd_maybe_before_mini_cart FOReach2', true ) );
                 //error_log( print_r(  'discount_price= ' .$vtprd_cart_item->discount_price . ' for PRODUCT= ' .$vtprd_cart_item->product_id , true ) );
                 //error_log( print_r(  'product_inline_discount_price_woo= ' .$vtprd_cart_item->product_inline_discount_price_woo, true ) );
                 //error_log( print_r(  '$vtprd_cart_item ' , true ) );
                 //error_log( var_export($vtprd_cart_item , true ) );
                 if ($vtprd_cart_item->product_id == $woo_product_id) {
                     //error_log( print_r(  '$woo_product_id FOUND= ' .$woo_product_id  , true ) );
                     //this will now pick up BOTH inline discounts, and solo CATLOG discounts...
                     switch (true) {
                         case $vtprd_cart_item->product_inline_discount_price_woo > 0 || $vtprd_cart_item->product_inline_discount_price_woo == 0 && $vtprd_cart_item->product_discount_price_woo == 0 && $vtprd_cart_item->yousave_total_amt > 0:
                             //there is a discount...
                             //v1.0.9.3 spec begin
                             $value['data']->price = $this->vtprd_choose_mini_cart_price($vtprd_cart_item);
                             //$vtprd_cart_item->product_inline_discount_price_woo;   //$vtprd_cart_item->discount_price;    //
                             //v1.0.9.3 spec end
                             $mini_cart_updated = true;
                             //error_log( print_r(  'case 1' , true ) );
                             break;
                         case $vtprd_cart_item->product_discount_price_woo > 0:
                             $value['data']->price = $this->vtprd_choose_mini_cart_price($vtprd_cart_item);
                             //$vtprd_cart_item->discount_price;    //
                             $mini_cart_updated = true;
                             //error_log( print_r(  'case 2' , true ) );
                             break;
                         case $vtprd_cart_item->unit_price < $value['data']->price:
                             //Pick up a **solo CATALOG price reduction**
                             $value['data']->price = $vtprd_cart_item->unit_price;
                             $mini_cart_updated = true;
                             //error_log( print_r(  'case 3' , true ) );
                             break;
                             /*efault:
                             error_log( print_r(  'NO CASE Action' , true ) ); 
                             break;  
                             */
                     }
                 }
             }
             //end foreach
         } else {
             //discountCoupon path
             //check to be sure any Catalog deal prices are reflected here - *** 2nd-nth time, these numbers are not reflected in the mini-cart ***
             vtprd_maybe_get_product_session_info($woo_product_id);
             if (isset($vtprd_info['product_session_info']['product_discount_price'])) {
                 //v1.1.0.6 added isset test
                 if (($vtprd_info['product_session_info']['product_discount_price'] > 0 || $vtprd_info['product_session_info']['product_discount_price'] == 0 && $vtprd_info['product_session_info']['product_yousave_total_amt'] > 0) && $vtprd_info['product_session_info']['product_discount_price'] < $value['data']->price) {
                     $value['data']->price = $vtprd_info['product_session_info']['product_discount_price'];
                     $mini_cart_updated = true;
                 }
             }
         }
     }
     if ($mini_cart_updated) {
         $_SESSION['internal_call_for_calculate_totals'] = true;
         $woocommerce->cart->calculate_totals();
     }
     return;
 }
예제 #3
0
function vtprd_load_vtprd_cart_for_processing()
{
    global $post, $wpdb, $woocommerce, $vtprd_cart, $vtprd_cart_item, $vtprd_setup_options, $vtprd_info;
    // from Woocommerce/templates/cart/mini-cart.php  and  Woocommerce/templates/checkout/review-order.php
    $woocommerce_cart_contents = $woocommerce->cart->get_cart();
    $calculator_product_in_cart = false;
    //v1.1.1
    $addons_product_in_cart = false;
    //v1.1.1
    if (sizeof($woocommerce_cart_contents) > 0) {
        //v1.0.8.0  save previous cart before creating new cart image, for lifetime confirmation processing only
        $vtprd_previous_cart = $vtprd_cart;
        //v1.0.8.0
        $vtprd_cart = new vtprd_Cart();
        $cart_has_catalog_discounts = 'no';
        //v1.1.1
        foreach ($woocommerce_cart_contents as $cart_item_key => $cart_item) {
            $_product = $cart_item['data'];
            if ($_product->exists() && $cart_item['quantity'] > 0) {
                $vtprd_cart_item = new vtprd_Cart_Item();
                //v1.1.1 begin
                //unique identifier in place of prod id, as some products DO NOT have an unique one
                $vtprd_cart_item->cart_item_key = $cart_item_key;
                //v1.1.1 end
                //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;';
                    }
                    $vtprd_cart_item->product_id = $cart_item['variation_id'];
                    $vtprd_cart_item->variation_array = $cart_item['variation'];
                    $vtprd_cart_item->product_name = $parent_post->post_title . '&nbsp;' . $varLabels;
                    $vtprd_cart_item->parent_product_name = $parent_post->post_title;
                    $vtprd_cart_item->variation_name_html = $woocommerce->cart->get_item_data($cart_item);
                    //v1.0.7.9
                    // added for v1.0.9.0 but unused, so commented ...
                    //  $variation_product = get_product( $vtprd_cart_item->product_id );  //v1.0.9.0
                } else {
                    $vtprd_cart_item->product_id = $cart_item['product_id'];
                    $vtprd_cart_item->product_name = $_product->get_title() . $woocommerce->cart->get_item_data($cart_item);
                }
                //v1.0.8.6  begin
                //for Variation Products with Attributes only, **there is NO product_ID difference** - the only difference is in the variation array.
                //   this info is used later to uniquely identify the product to which a discount should be added.
                $vtprd_cart_item->product_variation_key = array('product_id' => $cart_item['product_id'], 'variation_id' => $cart_item['variation_id'], 'variation' => $cart_item['variation']);
                //v1.0.8.6  end
                $product = get_product($vtprd_cart_item->product_id);
                //v1.0.7.4
                //v1.0.8.5 begin
                $varID = $cart_item['variation_id'];
                $prodID = $cart_item['product_id'];
                //v1.0.8.5 end
                $vtprd_cart_item->quantity = $cart_item['quantity'];
                $product_id = $vtprd_cart_item->product_id;
                //***always*** will be a session found
                //$session_found = vtprd_maybe_get_product_session_info($product_id);
                vtprd_maybe_get_product_session_info($product_id);
                //************************************************************************
                /*
                              v1.0.9.0 begin     this part of the routine reworked.
                               WITH V1.0.9.0 WE IGNORE THE UNIT PRICE IN THE CART,
                                as that could reflect both a CATALOG discount AND an **in-line** CART discount 
                                not a problem with coupone-based discount)
                                rather, we either go back to the ORIGINAL unit price for processing
                                OR we use the CATALOG discounted unit price.
                                (1) Original price, as taken from the DB
                                (2) Catalog pricing, taken from session variable
                                (3) Cart pricing, from running cart discount
                */
                //************************************************************************
                //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 discounted current price AND the original price for comparison
                if (isset($vtprd_info['product_session_info']['product_yousave_total_amt']) && $vtprd_info['product_session_info']['product_yousave_total_amt'] > 0) {
                    //v1.0.9.0 changed to pick up FREE items...
                    //  $vtprd_cart_item->unit_price             =  vtprd_compute_current_unit_price($product_id, $cart_item, $vtprd_cart_item, $product, $vtprd_previous_cart);     //v1.0.8.0
                    $vtprd_cart_item->unit_price = $vtprd_info['product_session_info']['product_discount_price'];
                    $vtprd_cart_item->save_orig_unit_price = $vtprd_info['product_session_info']['product_unit_price'];
                    //v1.0.7.4  save for later comparison
                    $vtprd_cart_item->db_unit_price = $vtprd_info['product_session_info']['product_unit_price'];
                    $vtprd_cart_item->db_unit_price_special = $vtprd_info['product_session_info']['product_special_price'];
                    $vtprd_cart_item->db_unit_price_list = $vtprd_info['product_session_info']['product_list_price'];
                    $vtprd_cart_item->product_list_price_catalog_correctly_taxed = $vtprd_info['product_session_info']['product_list_price_catalog_correctly_taxed'];
                    //v1.1.1
                    $cart_has_catalog_discounts = 'yes';
                    //v1.1.1
                } else {
                    $price = vtprd_get_current_active_price($product_id, $product);
                    //v1.1.1 added $product to call
                    $vtprd_previous_cart = '';
                    $price = vtprd_compute_current_unit_price($product_id, $cart_item, $vtprd_cart_item, $product, $vtprd_previous_cart, $price);
                    $vtprd_cart_item->unit_price = $price;
                    $vtprd_cart_item->save_orig_unit_price = $vtprd_cart_item->db_unit_price_list;
                    /*  now loaded in vtprd_get_current_active_price
                        $vtprd_cart_item->db_unit_price         = $price;
                        $vtprd_cart_item->db_unit_price_list    = $regular_price;
                        $vtprd_cart_item->db_unit_price_special = $sale_price;                  
                        */
                }
                //v1.0.9.0 end
                //v1.1.1 begin
                //*****************************************************
                // PLUGIN:: woocommerce-product-addons
                //*****************************************************
                /*
                With addons plugin, Catalog rules *do not affect the pricing of addons* - only the primary product.
                If there is a CART rule discount, both the Primary product and the addons will be discounted together.
                */
                if (class_exists('WC_Product_Addons') && isset($cart_item['addons'])) {
                    //if this is an ADDONS product
                    $vtprd_cart_item->other_plugins_info_array = $cart_item['addons'];
                    if ($vtprd_info['product_session_info']['product_has_addons']) {
                        $addons_total_price = 0;
                        foreach ($cart_item['addons'] as $key => $addon) {
                            $addons_total_price += $addon['price'];
                        }
                        $vtprd_cart_item->unit_price += $addons_total_price;
                        $vtprd_cart_item->save_orig_unit_price += $addons_total_price;
                        $vtprd_cart_item->db_unit_price += $addons_total_price;
                        $vtprd_cart_item->db_unit_price_special += $addons_total_price;
                        $vtprd_cart_item->db_unit_price_list += $addons_total_price;
                        $_SESSION['vtprd_addons_added_' . $product_id] = $addons_total_price;
                        //used in vtprd_maybe_get_price
                        $addons_product_in_cart = true;
                    }
                }
                //v1.1.1 end
                //v1.1.1 begin
                //*****************************************************
                // PLUGIN:: woocommerce-measurement-price-calculator
                //*****************************************************
                /* Overrides any other pricing from upstream pricing plugins, if there.
                   woocommerce-measurement-price-calculator provides the ability to price by weights, measures etc
                   sort of like fake variations.  However, it is all under the **original** product, with no actual
                   variation product ids.  So the data that is unique to the added product is in the
                   'pricing_item_meta_data' array, which is appended to the cart item.  It contains the 
                   current price of the item, undisturbed.  So it can always act as the original source of the pricing.
                   CATALOG rules are processed using the "woocommerce_get_price" hook, also using a calculator-specific
                   array to process successfully.                               
                   */
                if (class_exists('WC_Measurement_Price_Calculator') && $vtprd_info['product_session_info']['product_has_calculator'] && isset($cart_item['pricing_item_meta_data']) && isset($cart_item['pricing_item_meta_data']['_price'])) {
                    //if this is a calculator product
                    $vtprd_cart_item->unit_price = $cart_item['pricing_item_meta_data']['_price'];
                    $vtprd_cart_item->save_orig_unit_price = $cart_item['pricing_item_meta_data']['_price'];
                    $vtprd_cart_item->db_unit_price = $cart_item['pricing_item_meta_data']['_price'];
                    $vtprd_cart_item->db_unit_price_special = $cart_item['pricing_item_meta_data']['_price'];
                    $vtprd_cart_item->db_unit_price_list = $cart_item['pricing_item_meta_data']['_price'];
                    $_SESSION['vtprd_calculator_added_' . $product_id] = $cart_item['pricing_item_meta_data']['_price'];
                    //used in vtprd_maybe_get_price
                    $calculator_product_in_cart = true;
                }
                //v1.1.1 end
                //v1.1.1 begin
                //update old_price for later crossout use ==>> need ***cart_item_key***, can't use product_id for calculator/addons items!
                $_SESSION['vtprd_orig_cart_price_' . $vtprd_cart_item->cart_item_key] = $vtprd_cart_item->unit_price;
                //v1.1.1 end
                // db_unit_price_special CAN be zero if item is FREE!!
                //if ($vtprd_cart_item->unit_price < $vtprd_cart_item->db_unit_price_list )  {
                //v1.1.0.4 begin  added >= 0 and != null test
                if ($vtprd_cart_item->db_unit_price_special != null && $vtprd_cart_item->db_unit_price_special >= 0 && $vtprd_cart_item->db_unit_price_special < $vtprd_cart_item->db_unit_price_list) {
                    //v1.1.0.4 end
                    $vtprd_cart_item->product_is_on_special = 'yes';
                }
                /*
                if  ($vtprd_cart_item->db_unit_price_special == null) {
                $vtprd_cart_item->product_is_on_special = 'It"s null, dummy!!!';
                } else 
                if  ($vtprd_cart_item->db_unit_price_special <= 0 ) {
                $vtprd_cart_item->product_is_on_special = 'It"s not numeric, dummy!!!';
                } 
                */
                $vtprd_cart_item->total_price = $vtprd_cart_item->quantity * $vtprd_cart_item->unit_price;
                /*  *********************************
                 ***  JUST the cat *ids* please...
                 ************************************ */
                $vtprd_cart_item->prod_cat_list = wp_get_object_terms($cart_item['product_id'], $vtprd_info['parent_plugin_taxonomy'], $args = array('fields' => 'ids'));
                $vtprd_cart_item->rule_cat_list = wp_get_object_terms($cart_item['product_id'], $vtprd_info['rulecat_taxonomy'], $args = array('fields' => 'ids'));
                //initialize the arrays
                $vtprd_cart_item->prod_rule_include_only_list = array();
                $vtprd_cart_item->prod_rule_exclusion_list = array();
                /*  *********************************
                 ***  fill in include/exclude arrays if selected on the PRODUCT Screen (parent plugin)
                 ************************************ */
                $vtprd_includeOrExclude_meta = get_post_meta($cart_item['product_id'], $vtprd_info['product_meta_key_includeOrExclude'], true);
                //v1.0.7.8  use the parent ID at all times!
                if ($vtprd_includeOrExclude_meta) {
                    switch ($vtprd_includeOrExclude_meta['includeOrExclude_option']) {
                        case 'includeAll':
                            break;
                        case 'includeList':
                            $vtprd_cart_item->prod_rule_include_only_list = $vtprd_includeOrExclude_meta['includeOrExclude_checked_list'];
                            break;
                        case 'excludeList':
                            $vtprd_cart_item->prod_rule_exclusion_list = $vtprd_includeOrExclude_meta['includeOrExclude_checked_list'];
                            break;
                        case 'excludeAll':
                            $vtprd_cart_item->prod_rule_exclusion_list[0] = 'all';
                            //set the exclusion list to exclude all
                            break;
                    }
                }
                //v1.0.9.3 added if isset
                if (isset($cart_item['line_subtotal'])) {
                    $vtprd_cart_item->lifetime_line_subtotal = $cart_item['line_subtotal'];
                    //v1.0.8.0  for future lifetime processing only...
                }
                //add cart_item to cart array
                $vtprd_cart->cart_items[] = $vtprd_cart_item;
            }
        }
        //	endforeach;
    }
    //end  if (sizeof($woocommerce->cart->get_cart())>0)
    //v1.1.1 begin
    if ($calculator_product_in_cart) {
        $_SESSION['calculator_product_in_cart'] = 'yes';
    } else {
        $_SESSION['calculator_product_in_cart'] = 'no';
    }
    if ($addons_product_in_cart) {
        $_SESSION['addons_product_in_cart'] = 'yes';
    } else {
        $_SESSION['addons_product_in_cart'] = 'no';
    }
    //v1.1.1 end
    if (defined('VTPRD_PRO_DIRNAME') && $vtprd_setup_options['use_lifetime_max_limits'] == 'yes') {
        vtprd_get_purchaser_info_from_screen();
    }
    $vtprd_cart->purchaser_ip_address = $vtprd_info['purchaser_ip_address'];
    $vtprd_cart->cart_contents_count = $woocommerce->cart->cart_contents_count;
    //v1.0.9.3  used to check if cart contents have changed...
    $vtprd_info['cart_has_catalog_discounts'] = $cart_has_catalog_discounts;
    //v1.1.1
}
function vtprd_load_vtprd_cart_for_processing()
{
    global $post, $wpdb, $woocommerce, $vtprd_cart, $vtprd_cart_item, $vtprd_setup_options, $vtprd_info;
    // from Woocommerce/templates/cart/mini-cart.php  and  Woocommerce/templates/checkout/review-order.php
    $woocommerce_cart_contents = $woocommerce->cart->get_cart();
    //error_log( print_r(  'Woo Cart', true ) );
    //error_log( var_export($woocommerce_cart_contents, true ) );
    if (sizeof($woocommerce_cart_contents) > 0) {
        //error_log( print_r(  'Begin LOAD CART CONTENTS ', true ) );
        //v1.0.8.0  save previous cart before creating new cart image, for lifetime confirmation processing only
        $vtprd_previous_cart = $vtprd_cart;
        //v1.0.8.0
        $vtprd_cart = new vtprd_Cart();
        foreach ($woocommerce_cart_contents as $cart_item_key => $cart_item) {
            $_product = $cart_item['data'];
            if ($_product->exists() && $cart_item['quantity'] > 0) {
                $vtprd_cart_item = new vtprd_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;';
                    }
                    $vtprd_cart_item->product_id = $cart_item['variation_id'];
                    $vtprd_cart_item->variation_array = $cart_item['variation'];
                    $vtprd_cart_item->product_name = $parent_post->post_title . '&nbsp;' . $varLabels;
                    $vtprd_cart_item->parent_product_name = $parent_post->post_title;
                    $vtprd_cart_item->variation_name_html = $woocommerce->cart->get_item_data($cart_item);
                    //v1.0.7.9
                    // added for v1.0.9.0 but unused, so commented ...
                    //  $variation_product = get_product( $vtprd_cart_item->product_id );  //v1.0.9.0
                } else {
                    $vtprd_cart_item->product_id = $cart_item['product_id'];
                    $vtprd_cart_item->product_name = $_product->get_title() . $woocommerce->cart->get_item_data($cart_item);
                }
                //v1.0.8.6  begin
                //for Variation Products with Attributes only, **there is NO product_ID difference** - the only difference is in the variation array.
                //   this info is used later to uniquely identify the product to which a discount should be added.
                $vtprd_cart_item->product_variation_key = array('product_id' => $cart_item['product_id'], 'variation_id' => $cart_item['variation_id'], 'variation' => $cart_item['variation']);
                //v1.0.8.6  end
                $product = get_product($vtprd_cart_item->product_id);
                //v1.0.7.4
                //v1.0.8.5 begin
                $varID = $cart_item['variation_id'];
                $prodID = $cart_item['product_id'];
                //v1.0.8.5 end
                $vtprd_cart_item->quantity = $cart_item['quantity'];
                $product_id = $vtprd_cart_item->product_id;
                //***always*** will be a session found
                //$session_found = vtprd_maybe_get_product_session_info($product_id);
                vtprd_maybe_get_product_session_info($product_id);
                //************************************************************************
                /*
                              v1.0.9.0 begin     this part of the routine reworked.
                               WITH V1.0.9.0 WE IGNORE THE UNIT PRICE IN THE CART,
                                as that could reflect both a CATALOG discount AND an **in-line** CART discount 
                                not a problem with coupone-based discount)
                                rather, we either go back to the ORIGINAL unit price for processing
                                OR we use the CATALOG discounted unit price.
                                (1) Original price, as taken from the DB
                                (2) Catalog pricing, taken from session variable
                                (3) Cart pricing, from running cart discount
                */
                //************************************************************************
                //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 discounted current price AND the original price for comparison
                if (isset($vtprd_info['product_session_info']['product_yousave_total_amt']) && $vtprd_info['product_session_info']['product_yousave_total_amt'] > 0) {
                    //v1.0.9.0 changed to pick up FREE items...
                    //  $vtprd_cart_item->unit_price             =  vtprd_compute_current_unit_price($product_id, $cart_item, $vtprd_cart_item, $product, $vtprd_previous_cart);     //v1.0.8.0
                    $vtprd_cart_item->unit_price = $vtprd_info['product_session_info']['product_discount_price'];
                    $vtprd_cart_item->save_orig_unit_price = $vtprd_info['product_session_info']['product_unit_price'];
                    //v1.0.7.4  save for later comparison
                    $vtprd_cart_item->db_unit_price = $vtprd_info['product_session_info']['product_unit_price'];
                    $vtprd_cart_item->db_unit_price_special = $vtprd_info['product_session_info']['product_special_price'];
                    $vtprd_cart_item->db_unit_price_list = $vtprd_info['product_session_info']['product_list_price'];
                    //error_log( print_r(  'Pricing in Cart, from session_info, product = ' .$product_id. ' unit price= ' .$vtprd_cart_item->db_unit_price_list .' qty= ' .$vtprd_cart_item->quantity, true ) );
                } else {
                    //error_log( print_r(  'no session_info', true ) );
                    //echo '<pre> CALL to vtprd_get_current_active_price 001 - product= '.print_r($product_id), true).'</pre>' ;
                    //echo '<pre> before call 001 $product_id = '.print_r($product_id, true).'</pre>' ;
                    $price = vtprd_get_current_active_price($product_id);
                    //error_log( print_r(  'price 001= ' .$price, true ) );
                    $vtprd_previous_cart = '';
                    $price = vtprd_compute_current_unit_price($product_id, $cart_item, $vtprd_cart_item, $product, $vtprd_previous_cart, $price);
                    //error_log( print_r(  'price 002= ' .$price, true ) );
                    $vtprd_cart_item->unit_price = $price;
                    $vtprd_cart_item->save_orig_unit_price = $vtprd_cart_item->db_unit_price_list;
                    /*  now loaded in vtprd_get_current_active_price
                        $vtprd_cart_item->db_unit_price         = $price;
                        $vtprd_cart_item->db_unit_price_list    = $regular_price;
                        $vtprd_cart_item->db_unit_price_special = $sale_price;                  
                        */
                }
                //v1.0.9.0 end
                // db_unit_price_special CAN be zero if item is FREE!!
                //if ($vtprd_cart_item->unit_price < $vtprd_cart_item->db_unit_price_list )  {
                //v1.1.0.4 begin  added >= 0 and != null test
                if ($vtprd_cart_item->db_unit_price_special != null && $vtprd_cart_item->db_unit_price_special >= 0 && $vtprd_cart_item->db_unit_price_special < $vtprd_cart_item->db_unit_price_list) {
                    //v1.1.0.4 end
                    $vtprd_cart_item->product_is_on_special = 'yes';
                }
                /*
                if  ($vtprd_cart_item->db_unit_price_special == null) {
                $vtprd_cart_item->product_is_on_special = 'It"s null, dummy!!!';
                } else 
                if  ($vtprd_cart_item->db_unit_price_special <= 0 ) {
                $vtprd_cart_item->product_is_on_special = 'It"s not numeric, dummy!!!';
                } 
                */
                $vtprd_cart_item->total_price = $vtprd_cart_item->quantity * $vtprd_cart_item->unit_price;
                /*  *********************************
                 ***  JUST the cat *ids* please...
                 ************************************ */
                $vtprd_cart_item->prod_cat_list = wp_get_object_terms($cart_item['product_id'], $vtprd_info['parent_plugin_taxonomy'], $args = array('fields' => 'ids'));
                $vtprd_cart_item->rule_cat_list = wp_get_object_terms($cart_item['product_id'], $vtprd_info['rulecat_taxonomy'], $args = array('fields' => 'ids'));
                //initialize the arrays
                $vtprd_cart_item->prod_rule_include_only_list = array();
                $vtprd_cart_item->prod_rule_exclusion_list = array();
                /*  *********************************
                 ***  fill in include/exclude arrays if selected on the PRODUCT Screen (parent plugin)
                 ************************************ */
                $vtprd_includeOrExclude_meta = get_post_meta($cart_item['product_id'], $vtprd_info['product_meta_key_includeOrExclude'], true);
                //v1.0.7.8  use the parent ID at all times!
                if ($vtprd_includeOrExclude_meta) {
                    switch ($vtprd_includeOrExclude_meta['includeOrExclude_option']) {
                        case 'includeAll':
                            break;
                        case 'includeList':
                            $vtprd_cart_item->prod_rule_include_only_list = $vtprd_includeOrExclude_meta['includeOrExclude_checked_list'];
                            break;
                        case 'excludeList':
                            $vtprd_cart_item->prod_rule_exclusion_list = $vtprd_includeOrExclude_meta['includeOrExclude_checked_list'];
                            break;
                        case 'excludeAll':
                            $vtprd_cart_item->prod_rule_exclusion_list[0] = 'all';
                            //set the exclusion list to exclude all
                            break;
                    }
                }
                //v1.0.9.3 added if isset
                if (isset($cart_item['line_subtotal'])) {
                    $vtprd_cart_item->lifetime_line_subtotal = $cart_item['line_subtotal'];
                    //v1.0.8.0  for future lifetime processing only...
                }
                //add cart_item to cart array
                $vtprd_cart->cart_items[] = $vtprd_cart_item;
            }
        }
        //	endforeach;
    }
    //end  if (sizeof($woocommerce->cart->get_cart())>0)
    if (defined('VTPRD_PRO_DIRNAME') && $vtprd_setup_options['use_lifetime_max_limits'] == 'yes') {
        vtprd_get_purchaser_info_from_screen();
    }
    $vtprd_cart->purchaser_ip_address = $vtprd_info['purchaser_ip_address'];
    $vtprd_cart->cart_contents_count = $woocommerce->cart->cart_contents_count;
    //v1.0.9.3  used to check if cart contents have changed...
    //error_log( print_r(  'product_session_info', true ) );
    //$product_session_info = $vtprd_info['product_session_info'];
    //error_log( var_export($product_session_info, true ) );
    // error_log( print_r(  'END LOAD CART CONTENTS ', true ) );
    // error_log( var_export($vtprd_cart, true ) );
}