Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I copied the ups.inc file in the shipcalc partners folder and am modifying it to create my own basic shipping calculation.
I am just wondering what exactly the $rate array needs to look like when it comes out of the get_rates function? Are there nested arrays or does it matter?
Comment | File | Size | Author |
---|---|---|---|
#29 | shipcalc.weight2.setup.jpg | 24.42 KB | dkashen |
#27 | weight_2.inc | 18.22 KB | chueewowee |
#25 | quantity.inc | 10.47 KB | alynner |
#9 | weight_1.inc | 18.22 KB | stella |
#8 | weight_0.inc | 10.12 KB | stella |
Comments
Comment #1
alynner CreditAttribution: alynner commentedand it works like a charm:
Comment #2
gordon CreditAttribution: gordon commentedThis looks good, call you please add this as an attachment, so that it can be included in cvs.
Comment #3
Darren OhComment #4
alynner CreditAttribution: alynner commentedI have attached. Try it out and let me know, I'm sure it can use some tweaks.
alynner
Comment #5
Darren OhComment #6
stella CreditAttribution: stella commentedThis basic shipping functionality looks very useful. However it assumes that region 1 has to be a state in the US. What about online stores based outside the US? For them, their local country would be region 1, then there might be a region 2 for neighbouring countries and region 3 for the rest of the world (incl the States). I think the e-commerce module should be able to work for all countries, not just the US.
As a side note, I'd like to be able to associate a weight with each product and then apply the shipping cost based on what weight range the product falls into. If I get this working, I'll let you know!
Cheers,
Stella
Comment #7
stella CreditAttribution: stella commentedI created a new file "weight.inc" to handle a basic flat fee per region and a weight based shipping rate per region. There are 3 different regions (region 1, region 2 and everywhere else). The shipping cost is calculated like : region_flat_rate + (region_weight_rate * total_weight).
For both region 1 and 2 you can choose multiple countries from each list. If the US is chosen, then another select box for the list of states appears. The showing of the states list requires javascript, which meant I had to make the following changes to shipcalc.module:
new function:
changes to shipcalc_settings_form():
The weight.inc file is attached.
Hope this is of use to someone else.
Cheers,
Stella
Comment #8
stella CreditAttribution: stella commentedmodified weight.inc, so the first pound has one rate, and then each additional pound is charged differently.
updated file attached.
Comment #9
stella CreditAttribution: stella commentedok final version of weight.inc attached. I made some changes to allow the user to specify different rates dependant on whether the method chosen is parcel or large envelope. This last change is slightly hacky and i'm not sure what happens if the user picks both postal options. Perhaps someone else can suggest a better method.
Cheers,
Stella
Comment #10
Darren OhComment #11
nedjoI'd like to see this committed to shipcalc as currently we have no basic shipping options. Can someone who's used this give a detailed review? Are there any significant outstanding issues? Then we can fix any remaining issues and get this in.
Some quick comments:
* Looks generally good, I've not tested.
* There are some minor formatting issues: else or elseif should be on a separate line, there's inconsistency in the indents of e.g. form arrays, etc.
* The Javascript is a bit clunky, though I know we're doing similar things elsewhere in ecommerce. It would be nice to have a Drupal-like approach, where we used classes to attach behaviours to elements, and the js in a separate file. But, since we're only copying and not introducing this approach, it's a separate issue I guess.
Comment #12
nedjoSome further questions:
Why is shipcalc the place to implement this? I had assumed previously that we would do basic shipping directly as an additional shipping-based module, rather than through shipcalc (which I though of as for interacting with web services, e.g., UPS, USPS, Canada Post).
How does this relate to the shipbasic work at http://drupal.org/node/68363? Is the basic shipping need now covered off by flexicharge, or do we still need a basic shipping module (or extension to an existing module)?
Comment #13
nedjoSome further questions:
Why is shipcalc the place to implement this? I had assumed previously that we would do basic shipping directly as an additional shipping-based module, rather than through shipcalc (which I though of as for interacting with web services, e.g., UPS, USPS, Canada Post).
How does this relate to the shipbasic work at http://drupal.org/node/68363? Is the basic shipping need now covered off by flexicharge, or do we still need a basic shipping module (or extension to an existing module)?
Comment #14
simeHi nedjo
I think it's the "scratch your itch" effect. The people with time to develop will choose what they develop.
I will commit this if you think it is ok as a new shipcalc provider.
Re. flexicharge. I personally will be using it for basic charges (like shipping) - the foundation has been laid ready for various projects that are coming up. I wish I could say it's ready to go and really sell it to everyone, but since I can't do that yet, I understand why people are picking their own course.
Comment #15
simeOh wait, you have CVS access. You just need a review, I will try and do this soon.
Comment #16
simeWorks. I'll be using this! Thanks @snpower.
nedjo, re flexicharge:
I actually think this is better in shipcalc rather than flexicharge because it avoids me having to emulate the weight stuff that shipcalc is doing so well. I'll leave the final decision to you.
Comment #17
chueewowee CreditAttribution: chueewowee commentedI have weight_1.inc and basic.inc installed. When I select weight_1 and shipcalc settings I only get the 'save weight_1 settings' button in the form, but no settings to select.
Also, in the create product (apperel or shippable , I get no weight attributes in the form.
Naturally I have modified the shipcal.module as advised. What must I do to get it working, and what should I see?
Comment #18
gordon CreditAttribution: gordon commentedThe javascript needs to be put into it's own file, and then loaded the drupal way.
Comment #19
chueewowee CreditAttribution: chueewowee commentedThank you gordon. How do I load the javascript 'the Drupal way', and where should I place the file containing:
/**
* Invoke _settings_form_javascript in shipping partner .inc files.
*
*/
function shipcalc_settings_form_javascript($partner) {
$partners = _shipcalc_partners();
$settings_form_javascript = $partner .'_settings_form_javascript';
if (function_exists($settings_form_javascript)) {
return $settings_form_javascript();
}
return '';
}
Comment #20
chueewowee CreditAttribution: chueewowee commentedI created a separate file 'shipcalc_settings_form.js' in the partners folder. But his doean't work. I am not sure precisely how to place the drupal_call_js() function
I still need step by step instructions, even after reading relavant posts:
http://drupal.org/node/45531
http://drupal.org/node/42544
http://drupal.org/node/57760
Comment #21
simeUse drupal_add_js().
http://api.drupal.org/api/4.7/function/drupal_add_js
You want to pass the path of javascript file in such a way that it doesn't matter where ecommerce is installed.
http://api.drupal.org/api/4.7/function/drupal_get_path
Hope these help
Comment #22
chueewowee CreditAttribution: chueewowee commentedThanks, they help to a point, but also means I just need to learn more and search more. A step by step example for the case in hand would be great: what to put where and how.
Otherwise I think sadly I shal have to abandon this effort to produce a cart with Drupal with proper checkout for weight and zone. The time spent soars unless you get direct help with a problem in some cases, and the errors are merely the effect of not being able to take on much more self-tuition at that time.
Comment #23
chueewowee CreditAttribution: chueewowee commentedWHat I did is as follows, placeing the code in the shipcalc moduleafter line 70, but I get a 'Parse error: syntax error, unexpected T_RETURN on line 72'
Your help is most appreciated.
Sincerely,
John plumridge.
Comment #24
simeSorry, it will need nedjo to have a good look at this I think.
Comment #25
alynner CreditAttribution: alynner commentedI just tried out the weight.inc version of my original post and its great! thanks!
I have also decided I wanted to do the shipping for my most recent cart by quantity, so I copied the weight.inc file and made it quantity instead. I just had to change the get_rates function a bit and bingo bango bongo there we have it.
alynner
Comment #26
dkashen CreditAttribution: dkashen commentedHi,
I'd like to modify quantity to have a cost= base+$/lb
that would involved 3 distinct regions: 1 US, and 2 overseas.
In playing with quantity.inc's setup,
it looks like only adjacent states and countries can be selected with mouse clicks.
Is that true ?
If so (and maybe regardless),
I might prefer to hard code the cost function and countries per region .
Can someone point me to the best examples of a hardcoded .inc file that avoids
the javascript ?
I'm trying to avoid JS and learn just enough PHP (for now) .
Thank you,
Comment #27
chueewowee CreditAttribution: chueewowee commentedOK. I found a weight.inc which works, posted in the ecommerce mail list (see attached file). I tried the versions above, which do not work, with the latest ecommerce from 4.7 depository.
I 'll also say that I found it doesn't work with apperell and sub-products, but only 'shippable items' (even though sub-products are shippable items, I see, in practise)
I haven't tried the quantity.inc module yet.
Also:
I noticed the weight attribute disappeared from the product form when both ups.inc and canada.inc were removed.
The Shipcalc _product_form hook was not doing its job:
Instead, if modified to be the same as the ups and canada files, it does indeed enhance the product form, and weight.inc does its job of adding a shipping charge to the cart:
function weight_product_attributes($form) {
$fields = array();
$fields['weight'] = array(
'#type' => 'textfield',
'#title' => t('Product weight'),
'#description' => t('The weight of the product (in %unit)', array('%unit'=> (variable_get('shipcalc_units', 'LBS')) ? t('pounds') : t('kilograms'))),
'#default_value' => $form['#node']->product_attributes['weight']
);
return $fields;
}
The original code seems to be copied from 'usps.inc', which may not work either.
Thanks.
Comment #28
dkashen CreditAttribution: dkashen commentedTo get weight_2.inc working
do we replace the definition of
function weight_product_form(&$form){...}
with
function weight_product_attributes($form){...}
or do we add
function weight_product_attributes($form){...}
?
Thank you,
Comment #29
dkashen CreditAttribution: dkashen commentedoh, here's a snapshot
when I insert the above weight_2.inc file
at shipcalc/partners/
None of the settings are accessible.
is this along the lines of the problems you were seeing ?
Comment #30
ñull CreditAttribution: ñull commentedIn the Invoice there is supposed to be the shipping method displayed. This remains blank however and I cannot find this information anywhere else in the transaction administration. Where is this set? What is missing in the partners module? Or is this a bug in shipcalc or shipping module?
Comment #31
ñull CreditAttribution: ñull commentedI your code is a confusion about the use of #key #service and #method. The error of not appearing the shipping method in the Invoice has to do with this.
I try to explain:
#service must be the same as the key defined in _shipping_methods(), in your case it should be 'weight'
#key must be the same as the key of the used method as defined in _shipping_methods(), in your case it should be 'Flat Rate & Weight Based'.
#method is the string that would appear in the checkout shipping choice.
In this issue I explain more about it and the confusion I see between #key and #method and my proposal to get rid of #key.
Comment #32
Darren OhGot tired of small print.
Comment #33
Darren Oh?>?>?>
Comment #34
Darren OhLet's open a new issue.
Comment #35
Thomas Sewell CreditAttribution: Thomas Sewell commentedFor those who just wanted local or instore pickup for v3, see http://drupal.org/node/379572.