Custom Shipping Logic failed?

ChubbRckChubbRck Member
in Help edited June 2013
Hi there,

I'm wondering if someone can help me with this, because I'm stumped. I implemented the following custom shipping logic to force items in the 'overnight' category to overnight shipping with Fedex, but somehow a customer was able to choose 'home delivery' -- does anyone have any idea how this could happen? It's very disconcerting and my client is freaking out :( Is this a known issue with certain browsers or something? The only item in the customer's cart was one belonging to the 'overnight' category.

---
FC.customLiveShipping.logic = function() {
/* BEGIN CUSTOM SHIPPING LOGIC */

console.log("custom shipping logic");
var overnight = 0;
var threeMonth = 0;
var sixMonth = 0;
var twelveMonth= 0;
for (p in fc_json.products) {
console.log(fc_json.products[p].category);
switch (fc_json.products[p].category) {
case "overnight":
overnight += fc_json.products[p].quantity;
break;
case "threeMonth":
overnight += fc_json.products[p].quantity;
threeMonth +=fc_json.products[p].quantity;
break;
case "sixMonth":
overnight += fc_json.products[p].quantity;
sixMonth +=fc_json.products[p].quantity;
break;
case "twelveMonth":
overnight += fc_json.products[p].quantity;
twelveMonth +=fc_json.products[p].quantity;
break;
}
}
console.log(overnight);
if (twelveMonth > 0){
FC.customLiveShipping.update('overnight', '*12');
}
else if (sixMonth > 0) {
FC.customLiveShipping.update('overnight', '*6');
}
else if (threeMonth > 0) {
FC.customLiveShipping.update('overnight', '*3');

}

if (overnight > 0) {
// Hide all shipping options
FC.customLiveShipping.hide('all');
// Show only the overnight options
FC.customLiveShipping.show('overnight');
}
}
---

Thanks,

Nick
Comments
  • fc_adamfc_adam FoxyCart Team
    @ChubbRck,

    At a guess I'd say it's because you have the 'console.log' calls in there - if they're using a browser that doesn't support console.log then that will error in the javascript and stop your code from doing it's thing. Remove those and see if it comes up again.
  • Hey Adam,

    Thanks for your response. Indeed, just after I wrote my message, I took out the console.logs, remembering how some old versions of IE can choke on them. Hopefully it won't come up again. Thanks!
  • Hey Adam et. al,

    Things looked like they were working well, but the client has continued to complain that some users are able to choose 'home delivery' when they should be forced to overnight by custom shipping logic. Here is my current shipping logic:
    FC.customLiveShipping = {}
    
      FC.customLiveShipping.config = {
        autoSelect: false  // Set to true if you'd like the top shipping option to be automatically selected for the user
      };
    
      FC.customLiveShipping.logic = function() {
       /* BEGIN CUSTOM SHIPPING LOGIC */
    
      FC.customLiveShipping.hide('all');
      // Show only the overnight options
      FC.customLiveShipping.show('overnight');
       
       var overnight = 0;
       var threeMonth = 0;
       var sixMonth = 0;
       var twelveMonth= 0;
       
       for (p in fc_json.products) {
        
          switch (fc_json.products[p].category) {
           case "overnight":
           overnight += fc_json.products[p].quantity;
           break;
           case "threeMonth":
           overnight += fc_json.products[p].quantity;
           threeMonth +=fc_json.products[p].quantity;
           break;
           case "sixMonth":
           overnight += fc_json.products[p].quantity;
           sixMonth +=fc_json.products[p].quantity;
           break;
           case "twelveMonth":
           overnight += fc_json.products[p].quantity;
           twelveMonth +=fc_json.products[p].quantity;
           break;
          }
        }
     
    if (twelveMonth > 0){
      FC.customLiveShipping.update('overnight', '*12');
    } 
    else if (sixMonth > 0) {
      FC.customLiveShipping.update('overnight', '*6');
    }
    else if (threeMonth > 0) {
      FC.customLiveShipping.update('overnight', '*3');
      /* END CUSTOM SHIPPING LOGIC */
    }
    
     if (overnight < 1) {
      // Hide all shipping options
      //FC.customLiveShipping.hide('all');
      // Show only the home delivery options
      FC.customLiveShipping.show('home');
    }
     
    
    
    }
    

    Any ideas?
  • fc_adamfc_adam FoxyCart Team
    @ChubbRck,

    Could you give us an example transaction ID we could look at where they were able to select home delivery when they shouldn't?
  • Hi Adam, certainly --

    Processor Response:
    USA ePay Transaction ID:481594557
    Merchant:
    Coolhaus Online Store
    Date:
    Thu 25 Jul 2013 02:45:08 PM PDT
    order information

    Order ID:
    102325891
    Card Number:
    xxxxxxxxxxxx2382 (Visa)
    Subtotal:
    $29.00
    Shipping:
    $19.22
    Order Total:
    $48.22

    CART

    Pint Club 3 Month Delivery
    Code: pcd3
    Category: threeMonth
    Weight: 6 LBS
    Quantity: 1
    Price: $29.00
    Subtotal: $29.00
    Shipping & Handling: $19.22
    Order Total: $48.22
  • winstonwinston FoxyCart Team
    @ChubbRck

    I noticed that in the code you posted originally the line
    FC.CustomLiveShipping.hide('all');
    
    is not commented out, but in the latest post it is. Was this intentional? The line is in the last if statement.
  • Hi WInston,

    Yes, that is intentional. In the original code, I hide all choices and show 'overnight' if there is 1 or more overnight item.

    In the new code, I do the reverse. I start with all options hidden except 'overnight'. (See the lines below /* BEGIN CUSTOM SHIPPING LOGIC */) -- then, I only show 'home delivery' if there are 0 overnight items.

    I did this because I'd rather have home delivery not show when it should then to let it show when it shouldn't -- but I fear it's moot because I don't think the shipping logic is getting executed at all in these fail cases.

    Nick
  • winstonwinston FoxyCart Team
    @ChubbRck

    I'm still looking over things, but I did notice that when I ran a test transaction on your store with the same information as the transaction id you posted above (using the billing and shipping addresses that transaction used, but an epay test card) that the transaction errored out (card declined; expected) and once the page reloaded to give me that error, Home Delivery was shown.

    I'll keep digging into the code to see if I can find anything else, but I wonder if part of the issue comes from a user somehow reloading the page with all the info still available but the custom shipping logic isn't being executed as you mentioned.
  • fc_adamfc_adam FoxyCart Team
    @ChubbRck,

    I can't replicate it - apart from what @winston noted above - if the page has a gateway error, the custom shipping logic doesn't run and so the original rates are displayed. That said though, I'm not seeing any errors in your stores error logs for that customer's particular transaction.

    I've updated the code on the wiki, to account for the bug that Winston found - try updating to that code and see if it rectifies the issue moving forward: http://wiki.foxycart.com/snippets/shipping/live_rate_shipping_modification?&#step_2add_javascript
Sign In or Register to comment.