Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8788175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:05:59+00:00 2026-06-13T22:05:59+00:00

I have a problem I can’t find out myself so any help appreciated. I

  • 0

I have a problem I can’t find out myself so any help appreciated.

I have a dynamic cart which is filled with some JSON data. In the cart the shipping costs are also filled from the same json data. The script itself works when a method is available. When a shipping method isn’t available for that country the script should say “not available” or something like that. Instead it returns an undefined error which causes the cart not to work. After some searching I found out that when an user comes from country A (which is supported by the cart) the variable “methods” is present in the Json string. When a user comes from country B (which isn’t supported) the variable “methods” is not present in the json string. Obviously that causes the error.
So what I try to achieve is to check if the variable “methods” is present or not.
I found some answers like using typeof, HasOwnProperty, lenght() etc but I can’t figure out how I should implement that in the script below.

My script

 <script type="text/javascript">

        function getPriceDynamicCart(price){
          price = parseFloat(price).toFixed(2);
            price = '€ ' + price.replace('.', ',');
          return price;
        }
        function loadDynamicCart(){
          var url = "{{ '/cart/' | url }}?format=json";

          $.getJSON(url,function(data){

            var cartHtml = '';
            var priceTotal = 0;
            var foundShipment = false;

             $.each(data.cart.products, function(index, product){                  

              priceTotal = priceTotal + parseFloat(product.price.price_incl);
              productTitleLimit = jQuery.trim(product.fulltitle).substring(0, 19);

              cartHtml = cartHtml +
                '<div class="cart-product"><div class="cart-quantity">' +product.quantity+'&nbsp;x&nbsp;</div><div class="cart-title"><a href="'+ product.url +'" alt="'+ product.fulltitle + '" title="'+ product.fulltitle + '">' + productTitleLimit + '</a></div><div class="cart-price">' + getPriceDynamicCart(product.price.price_incl) + '</div></div>';
            });

            $.each(data.cart.shipping.methods, function(index, method){

              if(!foundShipment && !method.cod && !method.pickup) {
                priceTotal = priceTotal + parseFloat(method.price.price_incl);
                cartHtml = cartHtml +
                  '<div class="cart-shipping"><a class="vracht" style="cursor:pointer;" rel="nofollow">Verzendkosten:<br />(Vervallen bij afhalen)</a><div class="cart-price"> ' + getPriceDynamicCart(method.price.price_incl) + '</div></div>';

                foundShipment = true;                
              }
            });

            cartHtml = cartHtml +
              '<div class="cart-total"><div class="total">Totaal(incl. btw): <span>' + getPriceDynamicCart(priceTotal) + '</span></div>';

            $('#dynamic_cart').html(cartHtml);

          });
        }

        $().ready(function(){
          loadDynamicCart();
        });
      </script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:06:00+00:00Added an answer on June 13, 2026 at 10:06 pm
    if(data.cart.shipping.methods !== undefined){
    
        $.each(data.cart.shipping.methods, function(index, method){
    
              if(!foundShipment && !method.cod && !method.pickup) {
                priceTotal = priceTotal + parseFloat(method.price.price_incl);
                cartHtml = cartHtml +
                  '<div class="cart-shipping"><a class="vracht" style="cursor:pointer;" rel="nofollow">Verzendkosten:<br />(Vervallen bij afhalen)</a><div class="cart-price"> ' + getPriceDynamicCart(method.price.price_incl) + '</div></div>';
    
                foundShipment = true;                
              }
            });
    }else{
      cartHtml = cartHtml +
                  '<div class="cart-shipping"><a class="vracht" style="cursor:pointer;" rel="nofollow">Verzendkosten:<br />(Vervallen bij afhalen)</a><div class="cart-price">**Anything you care to write**</div></div>';
    }
    

    That should work.

    Edit, I’ve added an else statement for setting the cartHtml variable, so you have more flexibility for future use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem i can't solve by myself and which I coudn't find
I have a problem which i can't seem to find the solution to. I
I have a problem which can't solve by myself. Here is timestamp 1308085200 taken
I have some problem so can you help me. Is instance of AmqpTemplate class
i have a c problem can any one help me . i wrote a
I have a problem and can't find a solution. I am making an accordion
can anyone help, i have problem doing a sort, I thought i had it
Hy, I have a problem and I can't figure it out... declare @start_date datetime,
I have this problem I can't solve, I'm trying to add a zoom-in/out cursor
I have this problem I can't figure out, I query the DB this way:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.