Forums / Addon Order Total Modules / Better Together Contribution Support Thread

Better Together Contribution Support Thread

Views: 204,517

Results 521 to 540 of 696
11 Feb 2012, 11:27 AM
#521
cisi avatar

cisi

New Zenner

Join Date:
Dec 2011
Posts:
19
Plugin Contributions:
0

Better Together Contribution Support Thread

Hello, thanx for this great mod.
I'just installed, but i have a problem. I put the code

<?php
require($template->get_template_dir('/tpl_better_together_xsells.php',DIR_WS_TEMPLATE, 
   $current_page_base,'templates'). '/tpl_better_together_xsells.php');
?>

in tpl product info display, but it cause an error .. nothing display after that code . the require function call the tpl file in the right root ... i can't figure .. please help !!
Thanx in advance

11 Feb 2012, 12:08 PM
#522
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

Re: Better Together Contribution Support Thread

I suspect you stuck this inside a block of PHP code. Put it after a

?>

on the next line.

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.

11 Feb 2012, 12:32 PM
#523
cisi avatar

cisi

New Zenner

Join Date:
Dec 2011
Posts:
19
Plugin Contributions:
0

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 .. :shocking:

11 Feb 2012, 6:49 PM
#524
cisi avatar

cisi

New Zenner

Join Date:
Dec 2011
Posts:
19
Plugin Contributions:
0

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 ?? :no:

11 Feb 2012, 7:31 PM
#525
cisi avatar

cisi

New Zenner

Join Date:
Dec 2011
Posts:
19
Plugin Contributions:
0

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 ;))

17 Mar 2012, 11:50 PM
#526
ayoobg avatar

ayoobg

New Zenner

Join Date:
Nov 2011
Posts:
34
Plugin Contributions:
1

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:

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:

    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:

    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!

17 Mar 2012, 11:53 PM
#527
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

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.

2 Apr 2012, 6:16 AM
#528
kamion avatar

kamion

New Zenner

Join Date:
Mar 2011
Posts:
93
Plugin Contributions:
0

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.

2 Apr 2012, 6:24 AM
#529
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

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.

12 Apr 2012, 5:08 AM
#530
lpa17 avatar

lpa17

New Zenner

Join Date:
Apr 2012
Location:
China
Posts:
3
Plugin Contributions:
0

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!

12 Apr 2012, 10:10 AM
#531
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

Re: Better Together Contribution Support Thread

No, Better Together does not have a method to cap it at one discount.

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.

28 May 2012, 5:28 PM
#532
countrycharm avatar

countrycharm

Totally Zenned

Join Date:
Jul 2007
Posts:
2,179
Plugin Contributions:
2

Re: Better Together Contribution Support Thread

Hi Scott I'm getting half a info product page when I try to insert your code. Do I need to put each category I have between the 2 () or what. What I really like to have is buy any product in any category get the second one for 50% off. Thanks in advance.

If a straight two for one discount is what is desired, the calls are

  • add_twoforone_prod()
  • add_twoforone_cat()

Is your site Upgraded to the current version 1.5.4 Yet?
zencart-upgrades-website-installation

28 May 2012, 5:40 PM
#533
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

Re: Better Together Contribution Support Thread

countrycharm:

Hi Scott I'm getting half a info product page when I try to insert your code. Do I need to put each category I have between the 2 () or what.

Correct. But note that the function only supports one parameter, so you'll have to list each category. You can do this programmatically though.

     function setup() { 
        $list = array(3, 5, 7, 11, 13, 17, 19);
        foreach ($list as $i) {
            $this->add_twoforone_cat($i) 
        }
   }

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.

29 May 2012, 3:24 AM
#534
countrycharm avatar

countrycharm

Totally Zenned

Join Date:
Jul 2007
Posts:
2,179
Plugin Contributions:
2

Re: Better Together Contribution Support Thread

swguy:

Correct. But note that the function only supports one parameter, so you'll have to list each category. You can do this programmatically though.

 function setup() { 
    $list = array(3, 5, 7, 11, 13, 17, 19);
    foreach ($list as $i) {
        $this->add_twoforone_cat($i) 
    }

}


I'm not understanding this or something. Is the code above and example of what I need to put in the bottom of ot_better_together.php and just replace the number you provided with my category number? If this is correct what else do I add because when I go to admin/modules/ order total I get no module showing.

Is your site Upgraded to the current version 1.5.4 Yet?
zencart-upgrades-website-installation

29 May 2012, 11:16 AM
#535
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

Re: Better Together Contribution Support Thread

Look at "Common Installation Problems" in the help file for Better Together on my site. (There's a link in the readme.) It looks like you might have problem #3.

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.

29 May 2012, 5:20 PM
#536
countrycharm avatar

countrycharm

Totally Zenned

Join Date:
Jul 2007
Posts:
2,179
Plugin Contributions:
2

Re: Better Together Contribution Support Thread

swguy:

Look at "Common Installation Problems" in the help file for Better Together on my site. (There's a link in the readme.) It looks like you might have problem #3.

Hi Scott I know it's problem #3 but I seem not to be able to get it to work. Here' are the codes I tried at the bottom. It still get no modules showing in admin.

function setup() { 
        $list =  array(4,6,7,10,11,13,18,21,36,37,46,58,73,76,77,81,82,89,98,109,111,113,116,118,120,121,124,133,134,142,148,154,163,166,168,170,177,179,180,181,182,183,184);
        foreach ($list as $i) {
            $this->add_twoforone_cat($i)
        }
function setup() { 
        $list =   array(4,6,7,10,11,13,18,21,36,37,46,58,73,76,77,81,82,89,98,109,111,113,116,118,120,121,124,133,134,142,148,154,163,166,168,170,177,179,180,181,182,183,184);
        foreach ($list as $i) {
            $this->add_twoforone_cat($i)
        }
}

Lets work on this one here instead.

I want to be able to offer, buy any item from any category and get 50% off any other item from any other category. What code would I use to get this to work. Here are my category numbers. Thanks in advance

4,6,7,10,11,13,18,21,36,37,46,58,73,76,77,81,82,89,98,109,111,113,116,118,120,121,124,133,134,142,148,154,163,166,168,170,177,179,180,181,182,183,184

Is your site Upgraded to the current version 1.5.4 Yet?
zencart-upgrades-website-installation

30 May 2012, 8:17 PM
#537
countrycharm avatar

countrycharm

Totally Zenned

Join Date:
Jul 2007
Posts:
2,179
Plugin Contributions:
2

Re: Better Together Contribution Support Thread

countrycharm:

Hi Scott I know it's problem #3 but I seem not to be able to get it to work. Here' are the codes I tried at the bottom. It still get no modules showing in admin.

function setup() {
$list = array(4,6,7,10,11,13,18,21,36,37,46,58,73,76,77,81,82,89,98,109,111,113,116,118,120,121,124,133,134,142,148,154,163,166,168,170,177,179,180,181,182,183,184);
foreach ($list as $i) {
$this->add_twoforone_cat($i)
}

> ```php
function setup() { 
        $list =   array(4,6,7,10,11,13,18,21,36,37,46,58,73,76,77,81,82,89,98,109,111,113,116,118,120,121,124,133,134,142,148,154,163,166,168,170,177,179,180,181,182,183,184);
        foreach ($list as $i) {
            $this->add_twoforone_cat($i)
        }
}

Lets work on this one here instead.

I want to be able to offer, buy any item from any category and get 50% off any other item from any other category. What code would I use to get this to work. Here are my category numbers. Thanks in advance

I guess this is not and option either or do I have to purchase one of your paid modules to get it to work? Scott you are not ignoring me are you? I feel like this should work some how.

buy any item from any category and get 50% off any other item from any other category

Is your site Upgraded to the current version 1.5.4 Yet?
zencart-upgrades-website-installation

30 May 2012, 11:34 PM
#538
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

Re: Better Together Contribution Support Thread

You may or may not need something more complex than Better Together. But you definitely need to hire someone to do this installation for you. There's a limit to how much time I can spend debugging a failed install on the forum.

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.

31 May 2012, 1:05 AM
#539
countrycharm avatar

countrycharm

Totally Zenned

Join Date:
Jul 2007
Posts:
2,179
Plugin Contributions:
2

Re: Better Together Contribution Support Thread

swguy:

You may or may not need something more complex than Better Together. But you definitely need to hire someone to do this installation for you. There's a limit to how much time I can spend debugging a failed install on the forum.

I have it installed Scott It's not a failed install I just want to know is there a way to make this work. Yes or no, and if it will how do I get it to work. When I help or answer someone question in other threads I try to help all I can. I don't come back with There's a limit to how much time I can spend debugging a failed install on the forum. If we all did that nothing would get accomplish. No disrespect to you but I'm pretty good at sorting things when pointed in the right direction. I know you’re in the business of making money who isn’t. Like I said no disrespect to you. Thanks anyway for your time.

buy any item from any category and get 50% off any other item from any other category

Is your site Upgraded to the current version 1.5.4 Yet?
zencart-upgrades-website-installation

31 May 2012, 10:48 AM
#540
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

Re: Better Together Contribution Support Thread

You have stated multiple times that you can't see the module in admin. This is the definition of a failed install.

Can you do the two things you've asked about with Better Together? Yes, but you have to write some code (which I gave you an outline for). But this level of modification is beyond the abilities of many people - perhaps including you. This is why I suggested that you stop banging your head against the wall and just hire someone.

You have been working on this for days and still haven't completed it. Perhaps this isn't the best use of your time?

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.