Forums / Addon Payment Modules / Shopping cart coding problem with my payment module

Shopping cart coding problem with my payment module

Locked

Started by nixak on 20 Jul 2009, 4:59 PM · Views: 2,257

Results 1 to 5 of 5
This thread is locked. New replies are disabled.
20 Jul 2009, 4:59 PM
#1
nixak avatar

nixak

Zen Follower

Join Date:
Nov 2007
Location:
Essex, UK
Posts:
137
Plugin Contributions:
1

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.

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

22 Jul 2009, 11:04 AM
#2
nixak avatar

nixak

Zen Follower

Join Date:
Nov 2007
Location:
Essex, UK
Posts:
137
Plugin Contributions:
1

Re: Shopping cart coding problem with my payment module

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.

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.

23 Jul 2009, 3:29 PM
#3
nixak avatar

nixak

Zen Follower

Join Date:
Nov 2007
Location:
Essex, UK
Posts:
137
Plugin Contributions:
1

Re: Shopping cart coding problem with my payment module

:clap: 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.

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.

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

10 Aug 2009, 10:07 AM
#4
nixak avatar

nixak

Zen Follower

Join Date:
Nov 2007
Location:
Essex, UK
Posts:
137
Plugin Contributions:
1

Re: Shopping cart coding problem with my payment module

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.

20 Aug 2009, 1:06 PM
#5
nixak avatar

nixak

Zen Follower

Join Date:
Nov 2007
Location:
Essex, UK
Posts:
137
Plugin Contributions:
1

Re: Shopping cart coding problem with my payment module

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