Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

2gether Discount


boxtel

Recommended Posts

I know. Any idea where and how this could be implemented? Basically, there is a moment in the calculation of the price where the discount amount is taken as before tax, and one where it is *after* the tax...

I have no idea, there are a lot of moments in time, figuring out the right moment is very difficult.

Treasurer MFC

Link to comment
Share on other sites

I have no idea, there are a lot of moments in time, figuring out the right moment is very difficult.

 

Oh well. Thank you. I'll still try and fix this, as with this problem, anybody using this contribution and taxes is going to have wrong total prices.

 

So, another things: the discount is always considered as without tax when calculating the tax, but not when calculating the total to which to add the tax (I believe)

Link to comment
Share on other sites

Oh well. Thank you. I'll still try and fix this, as with this problem, anybody using this contribution and taxes is going to have wrong total prices.

 

So, another things: the discount is always considered as without tax when calculating the tax, but not when calculating the total to which to add the tax (I believe)

 

Niviche,

 

let me try to explain the concept of irony here as you obviously are not aware of the concept.

 

Once you call a contribution "useless" (because it obviously does not satisfy your needs), doesn't it enter your mind for a second that from that moment in time, any consideration for assistance from my part with regard to your needs ceases to exist?

That no cooperation will ever materialize after that, that such a thought simply becomes an impossibility?

Has that concept ever taken hold up there?

Treasurer MFC

Link to comment
Share on other sites

All right, sorry for having used the word "useless". I should just have written that, with this bug, the contribution is broken for people using taxes in their shop.

 

I'm really sorry if I offended you. I am deeply thankful for your work on this contribution, obviously, and would just like to help to fix it. After all, it *is* broken in this case.

Link to comment
Share on other sites

All right, sorry for having used the word "useless". I should just have written that, with this bug, the contribution is broken for people using taxes in their shop.

 

I'm really sorry if I offended you. I am deeply thankful for your work on this contribution, obviously, and would just like to help to fix it. After all, it *is* broken in this case.

 

Not even close to a nice try.

Treasurer MFC

Link to comment
Share on other sites

Not even close to a nice try.

 

Nice... All right, I try to see where the problem is, explain where I believe it comes from, what it breaks, and it's not enough. Well, sorry. I guess I should have written "bug report: total amount incorrect if display_price_with_tax is set to true". I just tried to do a little more than that.

Link to comment
Share on other sites

Nice... All right, I try to see where the problem is, explain where I believe it comes from, what it breaks, and it's not enough. Well, sorry. I guess I should have written "bug report: total amount incorrect if display_price_with_tax is set to true". I just tried to do a little more than that.

You did do more than that, you chose to be a smart-ass and that is where you messed up.

Treasurer MFC

Link to comment
Share on other sites

You did do more than that, you chose to be a smart-ass and that is where you messed up.

 

All right. Sorry, sorry, sorry. I shouldn't have written "useless", I was just trying to help, I didn't want to offend anybody. Had I, I wouldn't have posted all this info.

Link to comment
Share on other sites

All right. Sorry, sorry, sorry. I shouldn't have written "useless", I was just trying to help, I didn't want to offend anybody. Had I, I wouldn't have posted all this info.

 

See, now that feels much better, there are no "useless" contributions here only contributions worthy of improvement.

 

Now, basically osc calculates taxes based on the individual items. So in checkout confirmation it uses the tax classes assigned to the individual products to come up with the total tax amount. It is not that it uses a tax amount over the subtotal or anything like that.

 

Because of that, virtually any discount scheme has to adjust the taxes after the fact.

 

which means that it has to determine what taxes should have been taken and then take it off to be accurate.

Both for the subtotal as well as the individual product taxes as they can differ.

 

In short, the original order total module does not take any taxes into account.

But, at checkout it does look at the taxes whether it has to adjust them in order to include the discounts or not.

 

it does this via the routine :

 

// tax adjustment calculation to include discount

if ($order->info['tax'] > 0) {

// discount percentage as in discount divided by subtotal

$discount_percentage = $od_amount/$order->info['subtotal'];

// current tax * discount percentage

$tod_amount = $order->info['tax']*$discount_percentage;

// substract from current tax value

$order->info['tax'] = $order->info['tax'] - $tod_amount;

reset($order->info['tax_groups']);

while (list($key, $value) = each($order->info['tax_groups'])) {

// current tax group value * discount percentage

$god_amount = $value*$discount_percentage;

// substract from current tax group value

$order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;

}

}

// end tax calc

 

now, if you have any idea as to how to implement a right tax scheme for your "prices including tax" policy, I am happy to implement it. I do not use taxes at all so please explain as simple as you can.

Treasurer MFC

Link to comment
Share on other sites

  • 3 weeks later...

Hi Amanda,

 

First of all, thank you for a great contribution, and all the support you've provided which has enabled me to get it working well.

 

There is one part which I haven't been able to get to work though, and I wonder if you can help me? If one of the products in the 2gether offer has a stock level of 0, then I don't want the 2gether offer to show for that product. I added the code below as suggested, but the offer still shows on product_info.php:

 

if you wish to automatically disable the 2gether entry if 1 of the products is sold (together or not) you add this code to checkout_process.php:

 

// disable 2gether products entry

$together_query = tep_db_query("select status from " . TABLE_2GETHER . " where status = 1 and (product_1_id = '" . tep_get_prid($order->products[$i]['id']) . "' or product_2_id = '" . tep_get_prid($order->products[$i]['id']) . "')");

if (tep_db_num_rows($together_query) > 0) {

tep_db_query("update " . TABLE_2GETHER . " set status = 0 where status = 1 and (product_1_id = '" . tep_get_prid($order->products[$i]['id']) . "' or product_2_id = '" . tep_get_prid($order->products[$i]['id']) . "')");

}

 

I have osC set up so that products are still visible even if the stock is 0, so they're not marked as out of stock, if that's of any help.

 

Thanks!

Link to comment
Share on other sites

Hi Amanda,

 

First of all, thank you for a great contribution, and all the support you've provided which has enabled me to get it working well.

 

There is one part which I haven't been able to get to work though, and I wonder if you can help me? If one of the products in the 2gether offer has a stock level of 0, then I don't want the 2gether offer to show for that product. I added the code below as suggested, but the offer still shows on product_info.php:

I have osC set up so that products are still visible even if the stock is 0, so they're not marked as out of stock, if that's of any help.

 

Thanks!

 

what this code does is when a product is ordered and the resulting stock becomes zero and that product is part of an active 2gether combination, that 2gether combination is disabled.

 

The 2gether module itself does not check if the products in it have sufficient stock, it checks if the combination is still active. That namely saves additional database joins with the product table for all those products which do not feature in 2gether discount.

 

So I assume that you now have products in 2gether discount which already have a stock of zero.

The code you listed cannot help you there as that is only executed during ordering.

Treasurer MFC

Link to comment
Share on other sites

what this code does is when a product is ordered and the resulting stock becomes zero and that product is part of an active 2gether combination, that 2gether combination is disabled.

 

The 2gether module itself does not check if the products in it have sufficient stock, it checks if the combination is still active. That namely saves additional database joins with the product table for all those products which do not feature in 2gether discount.

 

So I assume that you now have products in 2gether discount which already have a stock of zero.

The code you listed cannot help you there as that is only executed during ordering.

 

Hi Amanda,

 

Thanks for the reply. You way you describe it is how I expect it to work, but if I set a product to have a quantity of 1 in stock, then order that product as part of a 2gether offer, the 2gether offer is still there afterwards even though the quantity of one of the products is now 0.

Link to comment
Share on other sites

Hi Amanda,

 

Thanks for the reply. You way you describe it is how I expect it to work, but if I set a product to have a quantity of 1 in stock, then order that product as part of a 2gether offer, the 2gether offer is still there afterwards even though the quantity of one of the products is now 0.

 

that should not happen, where exactly in checkout_process do you have this code?

Treasurer MFC

Link to comment
Share on other sites

that should not happen, where exactly in checkout_process do you have this code?

 

I've tried it in a couple of places:

 

just before:

 

// unregister session variables used during checkout

 

and just before:

 

// lets start with the email confirmation

Link to comment
Share on other sites

I've tried it in a couple of places:

 

just before:

 

// unregister session variables used during checkout

 

and just before:

 

// lets start with the email confirmation

 

OK, looks like I have sorted it. I added the code above // Update products_ordered (for bestsellers list) and it's working now.

Link to comment
Share on other sites

OK, looks like I have sorted it. I added the code above // Update products_ordered (for bestsellers list) and it's working now.

 

well, normally you would put it in the same place as where a product is disabled if the remaining qty becomes zero:

 

if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {

tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");

}

 

after that :

 

// disable 2gether products entry

$together_query = tep_db_query("select status from " . TABLE_2GETHER . " where status = 1 and (product_1_id = '" . tep_get_prid($order->products[$i]['id']) . "' or product_2_id = '" . tep_get_prid($order->products[$i]['id']) . "')");

if ((tep_db_num_rows($together_query) > 0) && ($stock_left < 1) ) {

tep_db_query("update " . TABLE_2GETHER . " set status = 0 where status = 1 and (product_1_id = '" . tep_get_prid($order->products[$i]['id']) . "' or product_2_id = '" . tep_get_prid($order->products[$i]['id']) . "')");

}

Treasurer MFC

Link to comment
Share on other sites

Amanda,

 

I have noticed that your 2gether contrib is storing html in the 'orders_total' table..... is there any way to stop that from happening?

 

The reason I ask is that when the PDF Invoice mod. calls the data from the 'orders_total' table the html formatting is being displayed as though it were plain text and not interpreting it as html.

 

thanks,

zoe

Link to comment
Share on other sites

Help,

 

I'm new here and have the following error:

 

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-20, 20' at line 7

 

select tid, product_1_id as product1_id, product_2_id as product2_id, discount, type, status from products_2gether limit -20, 20

 

cane someone make me a file that i can inport in the database for my table for the 2gether contribute?

Link to comment
Share on other sites

Help,

 

I'm new here and have the following error:

 

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-20, 20' at line 7

 

select tid, product_1_id as product1_id, product_2_id as product2_id, discount, type, status from products_2gether limit -20, 20

 

cane someone make me a file that i can inport in the database for my table for the 2gether contribute?

 

Thanks

Link to comment
Share on other sites

Hi,

 

I had the same problem (although I detected it when installing the discount coupon contribution). The formal solution is documented here: http://www.oscommerce.com/community/bugs,1605/. See the final entry dated 29 Sep 2005 19:21:49.

 

I applied the solution (caused by a newer version of MySQL) and I'm now back up and running.

 

Help,

 

I'm new here and have the following error:

 

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-20, 20' at line 7

 

select tid, product_1_id as product1_id, product_2_id as product2_id, discount, type, status from products_2gether limit -20, 20

 

cane someone make me a file that i can inport in the database for my table for the 2gether contribute?

 

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

Hello,

 

First, to solve the issue I had with tax calculation above, I changed what was posted in this post very slightly.

 

Replace the function process () in catalog/includes/modules/ot_together.php with:

 

function process() {
  global $order, $currencies, $ot_subtotal, $cart, $together_product_names;

  $od_amount = $this->calculate_2gether_discount();

  if ($od_amount > 0) {
	$this->deduction = $od_amount;
	$this->output[] = array('title' => sprintf(MODULE_2GETHER_DISCOUNT_FORMATED_TITLE, $together_product_names),
							'text' => sprintf(MODULE_2GETHER_DISCOUNT_FORMATED_TEXT, $currencies->format($od_amount)),
							'value' => $od_amount);

	 /*****START_TAX_CALCULATIONS*****/
	$discount_percentage = ($od_amount/$order->info['subtotal']);

	if ($order->info['tax'] > 0) {

		$tod_amount = ($order->info['tax'] * $discount_percentage);  
		reset($order->info['tax_groups']);

		while (list($key, $value) = each($order->info['tax_groups'])) {

			$god_amount = $value * $discount_percentage;
			$order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
		}
	}

//			$order->info['total']	 -= $order->info['tax'];
	$order->info['total'] -= $this->deduction;
		$order->info['tax']	 -= $tod_amount;
//			$order->info['total']	  = ($order->info['total'] - $od_amount) + $order->info['tax'];
	/*****END_TAX_CALCULATIONS*****/

	if ($this->sort_order < $ot_subtotal->sort_order) $order->info['subtotal'] -= $this->deduction;
  }
}

 

However, note that with this method, the tax are correct if 100% of your shopping cart content is a 2gether bundle. If you add any other product (for example from another tax class), the subtotal and total prices stay correct, but the tax amount are wrong.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...