Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2007
    Location
    Essex, UK
    Posts
    137
    Plugin Contributions
    1

    Default Shopping cart coding problem with my payment module

    Hi, I have some code that should send the details of the shopping cart to sagepay/protx when an order is made, but I have found that when it is enabled you are unable to confirm the order as the button dissappers and so does the secruity cert for the site.

    It kind of acts like the coding stops the footer from working. If anyone can look at the code and find the problem it would be a great help.

    Code:
    function getShoppingCartInfo()
        {
            global $cart, $order;
    
       		$retStr = "";
    
            if (MODULE_PAYMENT_PROTX_SHOPCART == 'true') {
    		$shipping = $order->info['shipping_cost'];
    		$shipping = number_format($shipping, 2, '.', '');
     		$products = $cart->get_products();
    		$no_lines = sizeof($products);
    		$no_lines = $no_lines + 1;
    
    		$shippingStr .= ":Shipping:1:".$shipping.":----:".$shipping.":".$shipping;
    		$basketStr = "Basket=".$no_lines;
    		$moreStr .= ":More products...See Order.:1:----:----:----:----";
            $moreLen = strlen( $moreStr );
    		/*
    		      Maxmium size of the basket field according to SAGEPAY Form Documentation V2.22
    		      is 7500 characters. Allowing 7495 as a small safety net.
    		*/
    		$charCount = 7495 - strlen( $shippingStr ) - strlen( $basketStr );
    
    		$detail = "";
            $linesAdded = 0;
            $i = 0;
            $n=sizeof($products);
            $finished = false;
    
        	while ( ( $i<$n ) && ( !$finished ) ) {
       				$desc = $products[$i]['name'];
    				$desc  = str_replace(":", "", $desc);
    				$qty = $products[$i]['quantity'];
    				$price = $products[$i]['price'] + $cart->attributes_price($products[$i]['id']);
    				$tax = $price/100 * zen_get_tax_rate($products[$i]['tax_class_id']);
    				$tax = number_format($tax, 2, '.', '');
    				$finalPrice = $price + $tax;
    				$finalPrice = number_format($finalPrice, 2, '.', '');
    				$lineTotal = $qty * $finalPrice;
    				$lineTotal = number_format($lineTotal, 2, '.', '');
    				$line = ":".$desc.":".$qty.":".$price.":".$tax.":".$finalPrice.":".$lineTotal;
    				$line = str_replace("\n", "", $line);
    		        $line = str_replace("\r", "", $line);
    		        $len = strlen( $line );
    		        if ( ( $charCount - $moreLen - $len) > 0 ) {
    		            $linesAdded ++;
    		            $charCount -= $len;
    		            $detail .= $line;
    		        } else if ( $charCount - $moreLen > 0 ) {
    		            $detail .= $moreStr;
    		            $charCount -= $len;
    		            $linesAdded ++;
    		            $finished = true;
    		        }
    		        else {
    		            // We should not hit this point, but if we do lets fininsh
    		            $finished = true;
    		        }
    		        $i++;
       		}
    
       		if ( strlen( $detail ) > 0 )
       		{
       		    $linesAdded ++;
       		    $retStr = "&" . "Basket=" . $linesAdded . $detail . $shippingStr;
       		}
          }
          return $retStr;
        }
    Whoops nearly forgot to say im using zen-cart v1.3.8a
    Last edited by Nixak; 20 Jul 2009 at 06:03 PM. Reason: including zen cart version no.

  2. #2
    Join Date
    Nov 2007
    Location
    Essex, UK
    Posts
    137
    Plugin Contributions
    1

    Default Re: Shopping cart coding problem

    Here are some screenshots to show you what I ment about this problem.

    This is how the site should look and does when the send shopping cart details to sagepay (code in post above) is switched off.



    This is what happens when I have the send shopping cart details to sagepay switched on.



    A friend of mine thinks that somehow the coding may be affected/affecting this piece of code taken by viewing source.

    Code:
    function showHideDiv(id) {
      var style = document.getElementById(id).style;
      if (style.visibility == "hidden") {
        style.visibility = "visible";
      } else {  
        style.visibility = "hidden";
      }
      if (style.display == "none") {
        style.display = "block";
      } else {
        style.display = "none";
      }
    }
    If anyone can help it would be brilliant as this is the only error I have in a module that would benifit alot of people.

  3. #3
    Join Date
    Nov 2007
    Location
    Essex, UK
    Posts
    137
    Plugin Contributions
    1

    Default Re: Shopping cart coding problem

    I fixed the problem but unfortunatly I've found another one lol.

    Everthing works except when I get sent to the sagepay simulator the shopping cart field is empty (i.e. nothing was sent)

    I have the function called "getshoppingcartinfo" the function grabs alot of variables.

    Code:
    function getShoppingCartInfo()
        {
            global $cart, $order;
    
             $retStr = "";
    
            if (MODULE_SHOPCART == 'true') {
          $shipping = $order->info['shipping_cost'];
          $shipping = number_format($shipping, 2, '.', '');
           $products = $cart->get_products();
          $no_lines = sizeof($products);
          $no_lines = $no_lines + 1;
    
          $shippingStr .= ":Shipping:1:".$shipping.":----:".$shipping.":".$shipping;
          $basketStr = "BasketSt=".$no_lines;
          $moreStr .= ":More products...See Order.:1:----:----:----:----";
            $moreLen = strlen( $moreStr );
          /*
                Maxmium size of the basket field according to Documentation V2.22
                is 7500 characters. Allowing 7495 as a small safety net.
          */
          $charCount = 7495 - strlen( $shippingStr ) - strlen( $basketStr );
    
          $detail = "";
            $linesAdded = 0;
            $i = 0;
            $n=sizeof($products);
            $finished = false;
    
           while ( ( $i<$n ) && ( !$finished ) ) {
                   $desc = $products[$i]['name'];
                $desc  = str_replace(":", "", $desc);
                $qty = $products[$i]['quantity'];
                $price = $products[$i]['price'] + $cart->attributes_price($products[$i]['id']);
                $tax = $price/100 * zen_get_tax_rate($products[$i]['tax_class_id']);
                $tax = number_format($tax, 2, '.', '');
                $finalPrice = $price + $tax;
                $finalPrice = number_format($finalPrice, 2, '.', '');
                $lineTotal = $qty * $finalPrice;
                $lineTotal = number_format($lineTotal, 2, '.', '');
                $line = ":".$desc.":".$qty.":".$price.":".$tax.":".$finalPrice.":".$lineTotal;
                $line = str_replace("\n", "", $line);
                  $line = str_replace("\r", "", $line);
                  $len = strlen( $line );
                  if ( ( $charCount - $moreLen - $len) > 0 ) {
                      $linesAdded ++;
                      $charCount -= $len;
                      $detail .= $line;
                  } else if ( $charCount - $moreLen > 0 ) {
                      $detail .= $moreStr;
                      $charCount -= $len;
                      $linesAdded ++;
                      $finished = true;
                  }
                  else {
                      // We should not hit this point, but if we do lets fininsh
                      $finished = true;
                  }
                  $i++;
             }
    
             if ( strlen( $detail ) > 0 )
             {
                 $linesAdded ++;
                 $retStr = "&" . "BasketSt=" . $linesAdded . $detail . $shippingStr;
             }
          }
          return $retStr;
        }
    then later on ther is this code that should send the information from the function along with loads of other info.

    Code:
    if (MODULE_SHOPCART == 'true') {
             $plain .= "Basket=" . $cart->basket['shopping_cart'] . "";
          }
    Do I need assign an output name to the function? (and if so how?) So later on I can grab the output of that function or have I just missed the ouput name somwhere?

    Any help woud be greatly appreciated

  4. #4
    Join Date
    Nov 2007
    Location
    Essex, UK
    Posts
    137
    Plugin Contributions
    1

    Default Re: Shopping cart coding problem

    LOL ignore my last post.

    The problem still remains as per my first two posts. If anyone can help please let me know thank you.

  5. #5
    Join Date
    Nov 2007
    Location
    Essex, UK
    Posts
    137
    Plugin Contributions
    1

    Default Re: Shopping cart coding problem

    Never mind I have found the code problems and fixed it.

 

 

Similar Threads

  1. Need simple coding help for Shopping Cart in Header
    By georgiepants in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 14 Apr 2010, 03:25 AM
  2. Problem with payment Module
    By alexipr in forum Addon Payment Modules
    Replies: 1
    Last Post: 9 Dec 2009, 11:17 PM
  3. Problem with Payment Module
    By artistwantab in forum Built-in Shipping and Payment Modules
    Replies: 1
    Last Post: 16 Nov 2008, 05:04 AM
  4. Where can i locate the shopping cart coding.
    By namae in forum General Questions
    Replies: 2
    Last Post: 30 Oct 2008, 05:19 PM
  5. shopping cart with non payment gateway
    By dellvostro in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 14 Oct 2008, 04:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR