New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shipping by Weight #72
Comments
I'm also in need of this! |
Anyone managed to sort this out? |
Here is a quick-dirty-hack I made to get shipping by weight working for SimpleCart It replaces the existing shipping function with my own, that gets the total weight of all products by checking if it has a "weight" field and adding this to the total. Then a function called "getDeliveryCost" is called - mine looks through an array of weights and costs and rounds the delivery cost up to the next weight limit. Help yourselves. var delivery_cols = ["Weight Limit", "Price"];
var delivery = [["10", "10"], ["20", "15"], ["40", "20"], ["60", "30"], ["70", "40"], ["100", "50"]];
var debug = false;
function getDeliveryCost(calculated_weight) {
if(0.0 == calculated_weight) {
return 0.0;
}
var i = 0;
while(calculated_weight > parseFloat(delivery[i][0]) && i < delivery.length) {
i++;
}
var calculated_delivery = parseFloat(delivery[i][1]);
if(debug) {
alert("Delivery cost " + calculated_delivery + " for weight " + calculated_weight + " limit is " + delivery[i][0] + " i is " + i);
}
return calculated_delivery;
}
simpleCart.shippingByWeight = true;
simpleCart.shipping_old=simpleCart.shipping;
simpleCart.shipping=function() {
if(true != simpleCart.shippingByWeight) {
return simpleCart.shipping_old();
}
if(debug) {
alert("shipping!");
}
if( parseInt(simpleCart.quantity,10)===0 )
return 0;
var shipping = parseFloat(simpleCart.shippingFlatRate) +
parseFloat(simpleCart.shippingTotalRate)*parseFloat(simpleCart.total) +
parseFloat(simpleCart.shippingQuantityRate)*parseInt(simpleCart.quantity,10),
nextItem,
next;
weight = 0.0;
for(next in simpleCart.items){
nextItem = simpleCart.items[next];
if(nextItem.weight) {
if(debug) {
alert("have weight " + nextItem.weight);
}
weight += parseFloat(nextItem.weight);
} else if( nextItem.shipping ){
if( typeof nextItem.shipping == 'function' ){
shipping += parseFloat(nextItem.shipping());
} else {
shipping += parseFloat(nextItem.shipping);
}
}
}
if(0.0 != weight) {
shipping = getDeliveryCost(weight);
}
return shipping;
} |
glenpike your the man!!! Thanks alot this helps me out!! |
Hi, Ok I’m a novice at js but slowly (very slowly) learning. I’m having trouble trying to figure out what I need to put in my html page ie <div class="simpleCart_shelfItem"> I know - I’m sure I’m way off but if you have a minute to help out it would be much appreciated. |
Hi, If you use the script above then add in your input field like this. <input type="hidden" class="item_weight" id="item_weight" name="item_weight" value="0"/> The getDeliveryCost is a function I wrote to use some variables I created to return a price based on the weight. This is shown on the Cart itself using the "shipping cost" element: <span class="simpleCart_shippingCost"></span> The cart script calculates this and my JavaScript above merely overrides the SimpleCart calculation if you set the variable: simpleCart.shippingByWeight = true; in your initialisation of the cart at the bottom of your HTML page. You should not have to change any SimpleCart scripts, just add the JavaScript above after you load the cart script. Have a look at:http://www.floating-shelves.com/beech-floating-shelves.html for an example - the "calculator" on each page fills in the cost and weight of the items, so when you add it to the cart, it refreshes the cart and calculates the shipping price. Hope this helps. Glen |
That's awesome Glen! Thank you so much for gettting back to me so soon and helping out. |
You know a problem I found with this code is when I add 2 different items of the same weight, it added a larger shipping amount as opposed to two of the same items... Wouldn't it be easier to just have a dollar amount that multiplies by the weight? |
The company I wrote the system for had a tier based shipping arrangement, e.g. 0-10kg = £10, 10.1-20kg =£20, etc. It is also possible there is a bug in the code - I will check it later to see... |
I suppose it's going to start getting tricky if you want to add GST on the shipping as well? |
Not sure about GST - I am guessing that is some tax like British VAT? All the prices on the website I worked for include the VAT, so the figures for shipping included that - not sure if that helps you, I guess if you are selling to commercial customers, you have to quote the tax added? Maybe just do a sum in the shopping cart that calculates the GST of the total? |
Hey Glen, I got it working but for some reason on my page it's not calculating the total weight quantity for the same item. Could you help me? Thanks, |
Looks like you are not multiplying the weight of each item by the quantity of items in the cart: You need to replace: weight += parseFloat(nextItem.weight); with: weight += parseFloat((nextItem.weight * nextItem.quantity)); e.g. for(next in simpleCart.items){ |
Hi to everybody! I am just a novice in simplecart and javascript , so please be patience :) Im using the simple cart in a web that distributes belts and i am using the script that Glen post here. Here my doubt or problem. When i show the cart without add any item the shipping and the total appears with the value 0 . How can i fix this? Code: me.updateTotals = function() {
When there's no wieght the me.shipping returns 0 and the me.update does that the me.finalcost and me.shippingCost appears with the 0 value or this is that i think :S So anybody can help me with some idea? Thanks you! if you need it I can put the url of the web so you can see what I mean! |
unrealsense - is it a problem that your cart is showing 0 when there is nothing in it? With http://www.floating-shelves.com/ if there is nothing in the cart, the totals and shipping show as 0 - for me this is correct. If you want your cart to change what it displays when there is nothing in it, you will have to have some extra javascript to show / hide the totals. The easiest way to do this would be in your update totals function add some script to set the visibility of the HTML for the total / shipping cost - it it == 0 hide the HTML, if not show it. I may have misunderstood your question, so sorry if I have. Glen |
Hi Glen , First at all thanks you for responding soo quickly :) . I think that you have misunderstood me , im sorry my english is not so good enough. I try to explain it again , this time i hope to do it better jeje I have made with php a little if to show in the same php page the product information (price , description , name , product id) or the cart with the products that you have added. the problem come when i want to check only the cart (without adding any product) when i do this the shipping and total appears with 0. If i go now to the form and i add the second product to the cart the shipping and total reappear with the correct value but already if i try to check only the cart without adding products shipping and total appears with the 0 value already. I think that its a problem of the code that i posted of the update function of the simplecart. I have fixed temporaly with a "dirty hack" when i load the page with the cart i just add a product with all values at 0 less the wight that have a value 0.01. With this i can check the cart separetly without adding any product. the dirty hack : onload="simpleCart.add( 'name=cart loader' , 'price=00.0' , 'quantity=0' , 'wight=0.01' );" To show separetly the product information with the cart and only the cart i use a if ( all the products came with a unique product id) if i have a product id i show the description , etc but if dont i show only the cart with the total and the number of items added. In the script of the other post maybe i think that i have to check the
but really i dont know how to solve it without the dirty hack :S If you need to see the code of the page i can sent you the url of both .php :D Thanks you, realy! |
Hello, I'm Italian and Lillina. To expose my questions, I will use the Google translator. Sorry, then, for some wrong word. Can you help? I set this function? |
Hi Lillina, If you want to calculate shipping cost by weight, you can use the same code as I posted above on May 15, 2011. You need to change the "delivery" array variable to your weights and prices - I have filled in the first 3 values from your rates in the code below:
So the first variable in each delivery array is the maximum weight limit for the price which is the second variable. For your values over 100kg, you will need to add in each 50kg jump, e.g. 151kg = 39+19?, 201=39+19+19 and same for values over 500kg Hopefully if you paste the code I created into your site, it will override the SimpleCartJS shipping calculation. In your website you will need to add a weight to each product using something like the following: You also need to have set simpleCart.shippingByWeight to true - this is done in the script I posted. Hope this helps. Glen |
Does this work with the current version 3.0.5? I can't seem to get it to work... |
Does not work in the last version of simplecartjs. |
hy glen,,, i need your help... thanks... email: leoghitolox99@gmail.com |
Hi - I've not used SimpleCart for a long time, so I don't know if my hack works for the latest version. Sorry! |
but please make as your own how to add 'weight' in every items...
I think... I it's so simple but I dont know how to make it.... please help
as you can....
Pada tanggal 2 Mar 2017 03:10, "Glen Pike" <notifications@github.com>
menulis:
… Hi - I've not used SimpleCart for a long time, so I don't know if my hack
works for the latest version. Sorry!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#72 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AVIV-scgfolb3xpP1nRBs9Y0JqFDKZMnks5rhdCXgaJpZM4AR9Xl>
.
|
but if you find nothing, thank you is for you... :)
Pada tanggal 2 Mar 2017 04:12, menulis:
… but please make as your own how to add 'weight' in every items...
I think... I it's so simple but I dont know how to make it.... please help
as you can....
Pada tanggal 2 Mar 2017 03:10, "Glen Pike" ***@***.***>
menulis:
> Hi - I've not used SimpleCart for a long time, so I don't know if my hack
> works for the latest version. Sorry!
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#72 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AVIV-scgfolb3xpP1nRBs9Y0JqFDKZMnks5rhdCXgaJpZM4AR9Xl>
> .
>
|
@leoghitolox - see comment #72 (comment) above. You need to add a hidden field with the weight value. As I said, the script may not still work with the current version, I haven't tried it. |
ok... thank you so much....
Pada tanggal 2 Mar 2017 07:06, "Glen Pike" <notifications@github.com>
menulis:
… @leoghitolox <https://github.com/leoghitolox> - see comment #72 (comment)
<#72 (comment)>
above. You need to add a hidden field with the weight value. As I said, the
script may not still work with the current version, I haven't tried it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#72 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AVIV-mpKNTA9AGYS4iFasX2q-l88hRUjks5rhgfxgaJpZM4AR9Xl>
.
|
Hello , I wish to create a parse cloud server function that estimate weight clothes from database type You will add an object that Name ClotheTypeClotheTypestring : type This function must naming : getClotheEstimation(type, weight) ==> price This function must read the type into database and
Type | basePrice |
help @glenpike |
@ghousshah something like this? |
its work for a parse server |
Hello
I have been trying to get the option of having a weight per product then making a price range for postage 0 to 100 = £3.90 101 to 200 = £5.90
The trouble is i can not get it to work i have little knowledge of javascript need help please
The text was updated successfully, but these errors were encountered: