close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

shipping calculations are not correctly calculated

Thread began 10/23/2016 12:07 pm by Christopher West | Last modified 10/24/2016 7:21 pm by Ray Borduin | 2686 views | 9 replies |

Christopher WestCommunity Expert

shipping calculations are not correctly calculated

Hi, I have a shipping system that calculates basket based on weight X size X ChargeDelivery(ChargeDelivery is a checkbox on products table).

(Also please see screenshots)
In my eCart General tab:
Number format: 10,000.00

In my eCart Columns tab:
ChargeDelivery = (this is a number)
Width = (this is a number)
Height = (this is a number)
Depth = (this is a number)

In my Calculations tab:
TotalWeight = [Weight] * [Quantity] * [ChargeDelivery]
TotalSize = ([Width] * [Height] * [Depth]) * [Quantity] * [ChargeDelivery]

QUESTION 1: is the above how it should be set up for the type of calculation I want?

My PHP code:

php:
<?php

$rsShippingZone 
= new WA_MySQLi_RS("rsShippingZone",$ecartdb,1);
$rsShippingZone->setQuery("SELECT * FROM shippingzones WHERE ShippingZoneCode = ? AND ShippingZoneEnabled = 1");
$rsShippingZone->bindParam("s""".(isset($_SESSION['ZonePostCode'])?$_SESSION['ZonePostCode']:"")  ."""-1"); //colname
$rsShippingZone->execute();
?>
<?php
$rsDeliveryCost 
= new WA_MySQLi_RS("rsDeliveryCost",$ecartdb,1);
$rsDeliveryCost->setQuery("SELECT * FROM shippingcosts WHERE ShippingCostZone = ? AND ShippingCostEnabled = 1 AND ShippingCostWeightTo >= ? AND ShippingCostSize >= ? ORDER BY ShippingCostValue ASC");
$rsDeliveryCost->bindParam("s""".$rsShippingZone->getColumnVal("ShippingZone")  ."""-1"); //colname
$rsDeliveryCost->bindParam("s""".$eCart->TotalColumn("TotalWeight")  ."""-1"); //colname2
$rsDeliveryCost->bindParam("s""".$eCart->TotalColumn("TotalSize")  ."""-1"); //colname3
$rsDeliveryCost->execute();?>



QUESTION 2 : in the above PHP code, is that how I should be defining the SQL query?

On many test of the basket, the delivery cost ends up being FREE (so obviously its unable to select a SQL query) or the delivery cost ends up being £2.5 (max size 900cm3) Even though the basket totalsize is way over 900cm3).

Can you see any obvious mistakes in my logic?

Take a look at my test screenshots and compare to the shipping rules screenshot. if you look at test3.png its showing £12.99 for delivery cost by the total size is 13,585cm3 and totalweight is 3kg (so I cant figure out why its selecting £12.99 if you compare the sipping rules screenshot.

the code that displays FREE is:

php:
<?php if ($eCart->GetShipping() > 0) { ?>

           <strong>£<?php echo $eCart->GetShipping(); ?></strong>
           
           <?php } else { ?>
           <strong>Free</strong>
<?php ?>




***UPDATE***
I think it maybe the sql query as I done a test outputting some sessions variables based on the 2 recordsets above. and it only displays a value from my rsShippingZone recordset. On the test page nothing is displayed from my sessions I used to grab some bindings from the rsDeliveryCost. Which would suggest that this recordset sql query is returning 0 results. Not sure why though?

I edited the recordset to the following and I am getting better results....but does the logic make sense as I remember Ray you suggested using >= and ASC for order by.

php:
<?php

$rsDeliveryCost 
= new WA_MySQLi_RS("rsDeliveryCost",$ecartdb,1);
$rsDeliveryCost->setQuery("SELECT * FROM shippingcosts WHERE ShippingCostZone = ? AND ShippingCostWeightTo <= ? AND ShippingCostSize <= ? ORDER BY ShippingCostValue DESC");
$rsDeliveryCost->bindParam("s""".$rsShippingZone->getColumnVal("ShippingZone")  ."""-1"); //colname
$rsDeliveryCost->bindParam("s""".$eCart->TotalColumn("TotalWeight")  ."""-1"); //colname2
$rsDeliveryCost->bindParam("s""".$eCart->TotalColumn("TotalSize")  ."""-1"); //colname3
$rsDeliveryCost->execute();?>



Chris

Sign in to reply to this post

Ray BorduinWebAssist

It looks like the data types for those columns are set to varchar instead of int or double. That would make it difficult to do number type of comparisons.

I think >= is the one that makes the most sense. I would think you would be saving the maximum weight and maximum volume for a given shipping option. That would mean you would want the value in the cart to be less than that maximum for the shipping to be applicable. Then you would sort by the cost ASC because you would want the lowest cost that was applicable for that size shipment.

Sign in to reply to this post
Did this help? Tips are appreciated...

Christopher WestCommunity Expert

Hi ok the wrong data type makes sense. I think in my database for some reason I had it as varchar (I think because when originally I had it in my CSV file the numbers were getting rounded up) So in my database should I set them to either Int, Double or Float? In the eCart object general, columns and calculations tab which drop down should I use (currently number).

Chris

Sign in to reply to this post

Ray BorduinWebAssist

Number is correct for the cart column type. Int appears appropriate for the database column since you have only whole numbers.

Sign in to reply to this post
Did this help? Tips are appreciated...

Christopher WestCommunity Expert

Before you replied I already change it. Could I just confirm (just in case there would be potential issues) the following:

(1) in eCart object instead of Number I used Integer (would this be a problem, what is the difference between those 2 options)

(2) in my database I ended up using Float for weight fields and Float for Sizes (because sizes will have a 2 decimal point value).

For weight even though I used Float would this cause any issues? Yes the delivery companies provide whole numbers. But also the shopping basket could have a weight of a 2 decimal value so I figured just to keep them as Floats. Any downsides?

Chris

Sign in to reply to this post

Ray BorduinWebAssist

Floats is fine. The only difference is weather it saves decimals or not.

Sign in to reply to this post
Did this help? Tips are appreciated...

Christopher WestCommunity Expert

Ok cool, but I'm the eCart Object what's the difference between the option 'Number' and 'Integer' (or was your reply referring to that and not my other database question) :)

Chris

Sign in to reply to this post

Ray BorduinWebAssist

Yes same thing.... allows decimals or not.

Sign in to reply to this post
Did this help? Tips are appreciated...

Christopher WestCommunity Expert

Ah so if I need decimal point numbers I need to use Number (not Integer) in the eCart object?

Chris

Sign in to reply to this post

Ray BorduinWebAssist

That is correct

Sign in to reply to this post
Did this help? Tips are appreciated...
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...