Results 1 to 10 of 699

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Posts
    18
    Plugin Contributions
    0

    Default Re: Better Together Contribution Support Thread

    Thanx for the prompt response .. i checked, but .. no . I suspected that the require function call to an unexisting file, but .. no .. ive replaced require with echo and the call is right ... can't figure ..

  2. #2
    Join Date
    Dec 2011
    Posts
    18
    Plugin Contributions
    0

    Default Re: Better Together Contribution Support Thread

    oK, SOLVED THE FIRST PROBLEM, checked the debug file and error was ok 756 raw of ot_better_together.php , uncommented "better_together_admin.php" . Now i've got no error, but ... nothing happens, can't see any doscount, any suggestion ??

  3. #3
    Join Date
    Dec 2011
    Posts
    18
    Plugin Contributions
    0

    Default Re: Better Together Contribution Support Thread

    ok all .. it's ok !! Thanx for this great contribution .. going to study to better adapt to my site ;))

  4. #4
    Join Date
    Nov 2011
    Posts
    34
    Plugin Contributions
    1

    Default Re: Better Together Contribution Support Thread

    Here is a possible fix if like me you sell products that have different tax rates:

    Product A 10% tax
    Product B 0% tax.

    buy Product A and get B at discount. Or buy B and get A at discount.

    Will give you the right result depending on your tax setting in admin.

    i.e for items that have 0% TAX for discount you must set "Include Tax"=false and "Re-calculate Tax"=none

    i.e for items that have X% TAX for discount you must set "Include Tax"=true and "Re-calculate Tax"=Standard

    Possible Fix (test it first)

    open includes/modules/order_total/ot_better_together.php

    and add the following function:

    Code:
    function get_indvidual_tax(){
    	
    	require_once(DIR_WS_CLASSES . 'order.php');
    	$orderz = new order;
    
    	$getid = array();
    	$globTAX = array();
    	
    	for ($i=0, $m=sizeof($orderz->products); $i<$m; $i++) {
    		
    		//gather up all the different types of tax rates used in our cart
    		$getTAX_group = array();
    		foreach ($orderz->products[$i]['tax_groups'] as $j => $value) {
    			$getTAX_group[$j] = $value;
    			if (isset($globTAX[$j]) == false){
    				$globTAX[$j] = 0;
    			}
    		}
    		unset($value);
    		
    		//collect tax rates for each items in our cart
    		$getid[(int)$orderz->products[$i]['id']] = $getTAX_group;
    		
    	}
    	$combinLocalGlob = array();
    	array_push($combinLocalGlob,$getid);
    	array_push($combinLocalGlob,$globTAX);
    	
    	return $combinLocalGlob;
    	
    }
    This function captures the tax rates for each individual products in our basket.

    Now go to the calculate_deductions() function and assign these tax rates to our products.

    replace in the calculate_deductions() function with:

    Code:
        function calculate_deductions() {
           global $db, $order, $currencies;
    
           $od_amount = array();
           $od_amount['tax'] = 0;
    
           $products = $_SESSION['cart']->get_products();
           reset($products);
           $rc = usort($products, "bt_cmp");
           $discountable_products = array();
           // Build discount list 
    	    $getindTAX = $this->get_indvidual_tax(); //collects tax rates from function
    		$getindTAXglobal = $getindTAX[1];// collects all the tax rates used in our cart (will be used to calculate final tax amount)
    		$getindTAXlocal = $getindTAX[0];// collects tax rates for eaxh individual products in cart
    		
           for ($i=0, $n=sizeof($products); $i<$n; $i++) {
                $discountable_products[$i] = $products[$i]; 
    			$discountable_products[$i]['tax_value'] = $getindTAXlocal[(int)$discountable_products[$i]['id']]; // assign the tax rate for each individual item in cart
           }
    
           // Now compute discounts
           $discount = 0;
           for ($i=0, $n=sizeof($discountable_products); $i<$n; $i++) {
                // Is it a twofer? 
                if ($this->is_twofer($discountable_products[$i])) {
                    $npairs = (int)($discountable_products[$i]['quantity']/2);
                    $discountable_products[$i]['quantity'] -= ($npairs * 2);
                    $item_discountable = $npairs * $discountable_products[$i]['final_price'];
    				$discount += $item_discountable;
    				
                    if ($this->include_tax == 'true') {
    					$item_being_discounted = $discountable_products[$i];
    					foreach ($item_being_discounted['tax_value'] as $taxrate => $taxvalue) {
    						//calculate tax amount for discounted item
    						$item_tax_at = ($item_being_discounted['final_price']*$taxvalue)/100;
    						$remove_discount_from_tax = $item_tax_at*($item_discountable/$item_being_discounted['final_price']);
    						//add this amount to the global tax variable (ready to be used to calc tax)
    						$getindTAXglobal[$taxrate] += $remove_discount_from_tax;
    					}
    					unset($taxvalue);  
                    }
                }
    
                // Otherwise, do regular bt processing
                while ($discountable_products[$i]['quantity'] > 0) { 
                    $discountable_products[$i]['quantity'] -= 1;
                    $item_discountable = $this->get_discount(       
                        $discountable_products[$i], $discountable_products);
    					
    				$discount_amount = $item_discountable[0];
    				
    				if (isset($item_discountable[0]) == false){
    					$discount_amount = 0;
    				}
    				
                    if ($discount_amount == 0) { 
                        $discountable_products[$i]['quantity'] += 1;
                        break;
                    } else {
    					$discount += $discount_amount;
                       if ($this->include_tax == 'true') {
    					  $item_being_discounted = $item_discountable[1];
    					  foreach ($item_being_discounted['tax_value'] as $taxrate => $taxvalue) {
    						  //calculate tax amount for discounted item
    						  $item_tax_at = ($item_being_discounted['final_price']*$taxvalue)/100;
    						  $remove_discount_from_tax = $item_tax_at*($discount_amount/$item_being_discounted['final_price']);
    						  //add this amount to the global tax variable (ready to be used to calc tax)
    						  $getindTAXglobal[$taxrate] += $remove_discount_from_tax;
    					  }
    					  unset($taxvalue);
                       }
                    }
                }
           }
    
           $od_amount['total'] = round($discount, 2); 
           switch ($this->calculate_tax) {
           case 'Standard':
              reset($order->info['tax_groups']);
    		  
              while (list($key, $value) = each($order->info['tax_groups']))
              {
                 $tax_rate = zen_get_tax_rate_from_desc($key);
    			 
                 if ($tax_rate > 0) {
    				// this will deduct the correct tax amount for each individual items
                    $od_amount[$key] = $tod_amount = round($getindTAXglobal[$key], 2) ;
                    $od_amount['tax'] += $tod_amount;
                 }
              }
              break;
    
           case 'VAT': 
              reset($order->info['tax_groups']);
              while (list($key, $value) = each($order->info['tax_groups']))
              {
                 $tax_rate = zen_get_tax_rate_from_desc($key);
                 if ($tax_rate > 0) {
                    $od_amount[$key] = $tod_amount = $this->gross_down($od_amount['total']);
                    $od_amount['tax'] += $tod_amount;
                 }
              }
              break;
    
          }
          return $od_amount; 
        }
    you will also need to replace the get_discount function with:

    Code:
        function get_discount($discount_item, &$all_items) {
            $discount = 0; 
            for ($dis=0, $n=count($this->discountlist); $dis<$n; $dis++) {
               $li = $this->discountlist[$dis]; 
    
               // Based on type, check ident1
               if ( ($li->flavor == PROD_TO_PROD) || 
                    ($li->flavor == PROD_TO_CAT) ) {
                  if ($li->ident1 != $discount_item['id']) {
                     continue;
                  }
               } else { // CAT_TO_CAT, CAT_TO_PROD
                  if ($li->ident1 != $discount_item['category']) {
                     continue;
                  }
               }
    
               for ($i=sizeof($all_items) - 1; $i>= 0; $i--) {
                   if ($all_items[$i]['quantity'] == 0) 
                      continue;
                   $match = 0; 
                   if ( ($li->flavor == PROD_TO_PROD) || 
                        ($li->flavor == CAT_TO_PROD) ) {
                      if ($all_items[$i]['id'] == $li->ident2) {
                         $match = 1;
                      }
                   } else { // CAT_TO_CAT, PROD_TO_CAT 
                      if ($all_items[$i]['category'] == $li->ident2) {
                         $match = 1;
                      }
                   }
    
                   if ($match == 1) { 
                       $all_items[$i]['quantity'] -= 1;
                       if ($li->type == "$") {
                          $discount = $li->amt;
                       } else { // %
                          $discount = $all_items[$i]['final_price'] *  
                                      $li->amt / 100;
                       }
    				   
    				   $discount_and_product = array();
    				   array_push($discount_and_product,$discount);//discount amount
    				   array_push($discount_and_product,$all_items[$i]);//item being discounted need to be used to calculate tax
    				   
                       return $discount_and_product;
                   }
               }
            }
    
            return 0;
        }
    now you will have to set "Include Tax"=true and "Re-calculate Tax"=Standard

    and it should work with different tax rated items!

  5. #5
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,532
    Plugin Contributions
    127

    Default Re: Better Together Contribution Support Thread

    Interesting! Thanks for sharing your code.
    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  6. #6
    Join Date
    Mar 2011
    Posts
    93
    Plugin Contributions
    0

    Default Re: Better Together Contribution Support Thread

    Good work, swguy. This was what I was looking for, and saved me the hassle of having to code it all from scratch. :)

    Just a quick note, instead of using the define FILENAME_PRODUCT_INFO to construct the href link to the products, I suggest using the function zen_get_info_page($product_id) instead. This will cover custom product types.

  7. #7
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,532
    Plugin Contributions
    127

    Default Re: Better Together Contribution Support Thread

    Thanks - this is a good suggestion.
    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  8. #8
    Join Date
    Apr 2012
    Location
    China
    Posts
    3
    Plugin Contributions
    0

    Default Re: Better Together Contribution Support Thread

    Greetings from the other side of the world

    Thank you so much for your work swguy.

    I have been tring to customize the shipping cart and create a combined discount for 2 categories. Part of your work is exactly what I was tring to do. :-)

    One more question, I wonder if your module has got the function to allow customer to buy ONLY one item from the 2nd category at discounted price. (a single item added allowed)

    Once again, great work, Thank you!

 

 

Similar Threads

  1. Twitter Updates Sidebox Contribution Support Thread
    By delia in forum Addon Sideboxes
    Replies: 13
    Last Post: 29 Dec 2010, 12:44 AM
  2. Better Together Promotional Page Contribution
    By swguy in forum All Other Contributions/Addons
    Replies: 10
    Last Post: 27 Feb 2010, 05:52 PM
  3. Windows Live Product Search Contribution Support Thread
    By numinix in forum All Other Contributions/Addons
    Replies: 209
    Last Post: 3 Jul 2009, 08:23 PM
  4. Better together mod
    By coolman in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 16 Aug 2008, 09:48 PM
  5. LinkConnector Affiliate Contribution Support Thread
    By hyperdogmedia in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 28 Jun 2007, 06:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg