Jump to content

PHP Shopping cart coding problem


Nixak

Recommended Posts

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;
    }

Link to comment
https://forums.phpfreaks.com/topic/166651-php-shopping-cart-coding-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.