Jump to content
ednique

[Contribution] Ship In Cart

Recommended Posts

@@Tsimi,

 

Are you sure you modified the right file?

For me it works, but I just had this issue. I removed them in teststore A and checked in teststore B o:)

        				if ( !empty($quotes[$i]['error']) ) {
        					$ShipTxt .= '<tr><td>' . $quotes[$i]['module'] . ' (' . $quotes[$i]['error'] . ')</td></tr>';
        				} else {
        					if ( $selected_shipping['id'] == $thisquoteid) {
        						$ShipTxt.='<tr class="success"><td onclick="return shipincart_submit(\''.$thisquoteid.'\');">' . tep_draw_radio_field('', true, true) . '<a href="_" title="' . MODULE_CONTENT_CART_SHIPPING_ESTIMATOR_SELECT_THIS_METHOD .'"> <strong>' . $quotes[$i]['module'] . ' ';
        						$ShipTxt.= $quotes[$i]['methods'][0]['title'].'</strong>   </a></td><td class="text-right"><strong>' . $currencies->format(tep_add_tax($quotes[$i]['methods'][0]['cost'], ((!empty($quotes[$i]['tax']))? $quotes[$i]['tax'] : null ))) . '</strong></td></tr>';
        					} else {
        						$ShipTxt .= '<tr><td onclick="return shipincart_submit(\''.$thisquoteid.'\');">' . tep_draw_radio_field('', false, false) . '<a href="_" title="' . MODULE_CONTENT_CART_SHIPPING_ESTIMATOR_SELECT_THIS_METHOD . '"> ' . $quotes[$i]['module'] . ' ';
        						$ShipTxt .= $quotes[$i]['methods'][0]['title'] . '   </a></td><td class="text-right">' . $currencies->format(tep_add_tax($quotes[$i]['methods'][0]['cost'], ((!empty($quotes[$i]['tax']))? $quotes[$i]['tax'] : null ))) . '</td></tr>';
        					}
        				}
        				// added to Display Message when No Shipping Options are Available
        				$at_least_one_quote_printed = true;
		          	} elseif ( sizeof($quotes[$i]['methods'])>1 ) {
		          		// shipping method with sub methods (multipickup)
		          		for ( $j=0, $n2=sizeof($quotes[$i]['methods']); $j<$n2; $j++ ) {
		          			$thisquoteid = $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'];
		          			$ShipTxt .= '';
		          			if ( $quotes[$i]['error'] ) {
		          				$ShipTxt .= '<tr><td>' . $quotes[$i]['module'] . ' (' . $quotes[$i]['error'] . ')</td></tr>';
		          			} else {
		          				if ( $selected_shipping['id'] == $thisquoteid ) {
		          					$ShipTxt .= '<tr class="success"><td onclick="return shipincart_submit(\''.$thisquoteid.'\');"><a href="_" title="' . MODULE_CONTENT_CART_SHIPPING_ESTIMATOR_SELECT_THIS_METHOD .'">' . tep_draw_radio_field('', true, true) . ' <strong>'.$quotes[$i]['module'] . ' ';
		          					$ShipTxt .= $quotes[$i]['methods'][$j]['title'] . '</strong>   </a></td><td class="text-right"><strong>' . $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax'])) . '</strong></td></tr>';
		          				} else {
		          					$ShipTxt .='<tr><td onclick="return shipincart_submit(\''.$thisquoteid.'\');"><a href="_" title="' . MODULE_CONTENT_CART_SHIPPING_ESTIMATOR_SELECT_THIS_METHOD . '">' . tep_draw_radio_field('', false, false) . $quotes[$i]['module'] . ' ';
		          					$ShipTxt .= $quotes[$i]['methods'][$j]['title'] . '   </a></td><td class="text-right">' . $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax'])) . '</td></tr>';
		          				}
		          			}
		          		}

If yes, try to get a new passport with a different birthday :thumbsup:

 

But serious: you are right these bracket should be removed or conditioned !empty($quotes[$i]['methods'][$j]['title'])...

I'll do that in the next update.

 

rgds

Rainer

Edited by raiwa

Share this post


Link to post
Share on other sites

@@raiwa

 

yeah, looking at the right store, editing the right files.

What you just explained, I've been there, done that. Those mistakes rarely happen but they do happen but this time I'm pretty sure that I am editing the right files and looking at the right store.

Cursed are those brackets!

Well, I'll just keep digging then...

 

Danke! :)

Edited by Tsimi

Share this post


Link to post
Share on other sites

@@Tsimi,

 

Screenshot of my teststore before and after the change:

 

 

Share this post


Link to post
Share on other sites

OK, it looks like that the checkout_shipping changes have no effect on your modules order totals.

Usually if I uncomment this

'title' => (($free_shipping == true) ?  $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')'),

the shipping should disappear from the order totals listing but it doesn't.

So logically removing the brackets code inside the checkout_shipping.php has no effect inside the estimate module.

Just a small visual issue and probably not really a big deal. But it might disturb one or the other person.

Share this post


Link to post
Share on other sites

@@Tsimi,

 

I found it. The brackets are added here when it writes the shipping method into the order:

        			$order->info['shipping_method'] = $selected_quote[0]['module'].' ('.$selected_quote[0]['methods'][0]['title'].')';

Share this post


Link to post
Share on other sites

@@raiwa

 

Still no luck.  :mellow:

I had removed those already, in fact I have removed every single non-code bracket in your module and checkout_shipping.php

Still there that %#$&'%#(. :x

Like I said not really a very big issue. If you stumble across some lost brackets just tell me please.

Edited by Tsimi

Share this post


Link to post
Share on other sites

@@Tsimi,

 

you need to change the selected shipping module at least once to get the change applied to the order and the ot updated.

 

 

Edited by raiwa

Share this post


Link to post
Share on other sites

@@Tsimi,

 

Thanks for the push, I'll include a !empty statement for all places in the next update.

Share this post


Link to post
Share on other sites

@@raiwa

 

Rainer may I ask you for help on something?

Regarding the Discount Code 3.2.

Somehow it does not calculate the total correctly when adding discounts. In the confirmation page and inside the estimator.

Tax calculation inside osC code-wise is not my forte. 

Shop setup: Display prices with tax = false

 

Example:

 

Sub-Total: 18.90

Discount (10%): -1.89

Flat Rate: 8.90

Tax (19%): 4.98

-------------------------------

Total: 31.19

 

The total is wrong it should say, 30.89. My guess is it calculates 19% tax on the discount price (1.89). It doesn't recognize the price as discount and as minus amount. I have a black out at the moment and cannot see what place does the calculation. I know you are busy and all but if you find some free time in between could you please take a look at it? Thanks.

Edited by Tsimi

Share this post


Link to post
Share on other sites

Hello Lambros @@Tsimi,

 

Could you please give this a fast try:

		    			if ( !empty($order->info['tax']) ) {
		    				$order->info['tax'] += $tax_val;
		    			} else {
		    				$order->info['tax'] = $tax_val;
		    			}
		    			if ( !empty($order->info['tax_groups']) ) {
		    				$order->info['tax_groups']["$products_tax_description"] += $tax_val;
		    			} else {
		    				$order->info['tax_groups']["$products_tax_description"] = $tax_val;
		    			}

change to:

		    			$order->info['tax'] += $tax_val;
		    			$order->info['tax_groups']["$products_tax_description"] += $tax_val;

maybe I messed something up with the undefined variable fix introduced in 2.4.8.

 

Otherwise I'll have a deeper look when I find some time.

 

rgds

Rainer

Share this post


Link to post
Share on other sites

@@raiwa  Just wanted to say thanks to Rainer for both the excellent contributions and the support that the provides.   He goes way above what you might expect in trying to resolve issues and generally help out.  A BIG Thumbs up Rainer.  :thumbsup:

 

Dan

Share this post


Link to post
Share on other sites

Thanks @@raiwa

 

I do not think that it is an issue in your addon but more in the Discount Code addon.

I have an older version of your estimate addon (2.4.6) and the code you recommend is already there.

I think something needs to be changed inside the ot_tax.php module to make it understand to not charge/calculate taxes on a discount or something that subtracts an amount.

 

I will try to dig into it as soon I find more time. Need to get something else done first.

Thanks again for looking into it.

 

Gruss

Tsimi

 

@@Dan Cole

Well said! :thumbsup:

Edited by Tsimi

Share this post


Link to post
Share on other sites

Hello Lambros @@Tsimi,

 


Sub-Total: 18.90

Discount (10%): -1.89

Flat Rate: 8.90

Tax (19%): 4.98

-------------------------------

Total: 31.19

 

The total is wrong it should say, 30.89. My guess is it calculates 19% tax on the discount price (1.89). It doesn't recognize the price as discount and as minus amount. I have a black out at the moment and cannot see what place does the calculation. I know you are busy and all but if you find some free time in between could you please take a look at it? Thanks.

 

I think I found the fix. We have to loop through the products to accumulate a global tax correction applying the global discount to each products tax rate.

Then apply the global tax correction to the orders total.

 

ot_discount.php:

                	$order_tax = 0;
                	for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
                    if (!empty($order->products[$i]['tax'])) {
                      $global_tax_correction += $this->format_raw($discount - $discount / (1.0 + $order->products[$i]['tax'] / 100));
                    }
                  }
                  $order->info['total'] -= $global_tax_correction;
                  
                  
                  if (is_array($order->info['tax_groups']) && count($order->info['tax_groups']) > 0) {
                    foreach ($order->info['tax_groups'] as $key => $value) {
                      if (!empty($value)) {
                        $order->info['tax_groups'][$key] = $this->format_raw(($order->info['subtotal'] - $discount) * ($value / $order->info['subtotal']));
                        $order_tax += $order->info['tax_groups'][$key];
                      }
                    }
                  }
                  if (!empty($order_tax)) {
                    $order->info['tax'] = $order_tax;
                  }

Maybe needs some clean up and additional checks.

 

Hope this helps

 

rgds

Rainer

Edited by raiwa

Share this post


Link to post
Share on other sites

Thanks @@raiwa

 

I'll test that.

 

Looking at the code above the place where yours goes there seems to be a tax_correction code. Not sure when that applies though.

                    if (!empty($order->products[$i]['tax'])) {
                      $tax_correction = $this->format_raw($products_discount - $products_discount / (1.0 + $order->products[$i]['tax'] / 100));
                      $order->info['tax'] -= $tax_correction;
                      $order->info['tax_groups'][$order->products[$i]['tax_description']] -= $tax_correction;
                    }
                    $order->info['total'] -= $products_discount;
                    $discount += $products_discount;
Edited by Tsimi

Share this post


Link to post
Share on other sites

@@Tsimi, Yes, I know, but I got $tax_correction = null when I checked it.

              if (!empty($check['products_id']) || !empty($check['categories_id']) || !empty($check['manufacturers_id'])) {
// products, categories, manufacturers based discount
              } elseif (!empty($check['orders_total'])) {
//order totals based discount
}

Maybe I'm wrong, but it corrected the ot

Edited by raiwa

Share this post


Link to post
Share on other sites

@@jamo32, @@Tsimi, @@Dan Cole,

 

I prepared the next update version 2.5.

I included all the fixes for the issues you reported and some more which I found myself.

 

- Added fix to keep the shipping address selected in address drop down if coming back from checkout.
- Added hidden fields for country and zone to ensure the value is posted if these drop downs are disabled. Thanks to @@Dan Cole for the report
- Added default Zip code configuration field to show it on first load if show zip code is enabled.
- Enable shipping module selection if quote is 0 (zero). Thanks to @@jamo32 for the report.
- Remove empty brackets in shipping module titles if shipping way text is empty. Thanks to @@Tsimi for the report.
 

Could you please give it a try and cjheck if all works as it should.

I'll then upload the new version.

 

Please uninstall, upload, install again. There is a new configuration entry.

 

Thank you a lot

Rainer

Share this post


Link to post
Share on other sites

@@raiwa

 

Your new file seems to work fine. :thumbsup:

 

Still the tax or total issue persists. Damn tax calculations <_<  Es ist zum Haare raus reisen. :x

Can you once try the following situation.

 

- Setup 19% tax

- Set Show prices with tax to false

- Add test product with $18.90 netto price

- set flat rate shipping to $8.90 (taxable goods)

- Create discount code 10% to the test product or all categories or all products

- Order total setup;

 

1 Sub Total

2 Discount

3 Shipping

4 Tax

5 Total

 

Tell me what total you get.

 

When I try the above setup but create the discount code for order totals only then it works like a charm.

Edited by Tsimi

Share this post


Link to post
Share on other sites

I think I got the total right at least.

Replace this (ot_discount.php)

     $order->info['total'] -= $products_discount;
     $discount += $products_discount;
    
  }
}

with this

     $order->info['total'] -= $products_discount;
     $discount += $products_discount;
    
  }
}
$order->info['total'] -= $tax_correction;

Now I get the right total but tax is still showing $4.98 instead of $4.92. Getting closer now...

Edited by Tsimi

Share this post


Link to post
Share on other sites

@@Tsimi,
 
I get the correct 30.89 with the subtotal discount and my posted modification.
 
 Subtotal discount:

1 x  The Matrix $18.90 Sub-Total: $18.90 Discount: -$1.89 Flat Rate (): $8.90 FL TAX 19.0%: $4.92 Total: $30.89

 

Product discount:

1 x  The Matrix $18.90 Sub-Total: $18.90 Discount: -$1.89 Flat Rate (): $8.90 FL TAX 19.0%: $4.98 Total: $31.19

 

Then it seems the old product discount tax correction needs to be fixed too.

 

I tried the following:

                    if (!empty($order->products[$i]['tax'])) {
                      $tax_correction = $this->format_raw($products_discount - $products_discount / (1.0 + $order->products[$i]['tax'] / 100));
                      $global_tax_correction += $this->format_raw($products_discount - $products_discount / (1.0 + $order->products[$i]['tax'] / 100));
                      $order->info['tax'] -= $tax_correction;
                      $order->info['tax_groups'][$order->products[$i]['tax_description']] -= $tax_correction;
                    }
                    $order->info['total'] -= $products_discount;
                    $discount += $products_discount;
                  }
                }
                $order->info['total'] -= $global_tax_correction;

and it corrects the order total, tax is still wrong:

product discount:

1 x  The Matrix $18.90 Sub-Total: $18.90 Discount: -$1.89 Flat Rate (): $8.90 FL TAX 19.0%: $4.98 Total: $30.89

Share this post


Link to post
Share on other sites

@@raiwa

 

Yep that is what I got too thus far.

Everything is right except that tax I don't really understand why it is not working though, the code seems to be right. But then again I am by far no expert.

Share this post


Link to post
Share on other sites

@@Tsimi I'm stuck in the same, I'll continue tomorrow. :lol:

Share this post


Link to post
Share on other sites

:lol: Yeah me too, 1:35am here and the beer doesn't help much either. A good nights sleep might help. 

Thanks again for your help, very, very appreciated. :thumbsup:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×