Location: PHPKode > scripts > Allegro script > allegro-script/auctionSold.php
<?php 
require_once 'lib/nusoap.php';
require_once 'lib/moneycurrency.class.php';
require_once 'conf.php';

class AuctionSold{

	var $soap;
	var $sesja=array();
	var $countryCode=1;

	
//////////////////////////////Funkcja zmienia zlotowki na dolary/////////////	
function getPlnZl($oldPrice){
	
	$api = new MoneyAPI;

	$from = 'PLN';
	$want = constant('MYCURRENCY');
	$total = $oldPrice;

	$stream = $api->open() or die('Unable to locate stream!');
	return $result = $api->convert($stream, $from, $want, $total, true, 2);
		
}	

function getBuyerInfo($auctionId){
		
	$param = array(
		'session-handle' => $this->sesja['session-handle-part'],
      	'auction-id-list' => array($auctionId), 			//(ArrayOfAuctionID)
     	'offset' => 0, 
      	'desc' =>0 
	);
	
	$buyerData=$this->soap->call('doMyContact',$param);
	return $buyerData[0];

}

/////////////////////Function returns squ or false///////////////
function getSqu($allegroId){
	$squhandle = fopen("/home/ftpuser/orders/squId.txt", "r+");
	while (($data = fgetcsv($squhandle, 200, "	")) !== FALSE) {			//not deleting yet
			if($data[0]==$allegroId){	
			fclose($squhandle);
			return $data[1];
			} 
	}
	fclose($squhandle);		
	return false;
}

/////////////////////Function return ups or false/////////////////
function getUps($allegroID){

	$squhandle = fopen("/home/ftpuser/orders/squId.txt", "r+");
	while (($data = fgetcsv($squhandle, 200, "\t")) !== FALSE) {			//not deleting yet
			if($data[0]==$allegroId){	
			fclose($squhandle);
			return $data[4];
			} 
	}
	fclose($squhandle);		
	return false;
}

function getTitles(){
	$titles=
	"payments-status\torder-id\torder-item-id\tpayments-date\tpayments-transaction-id\titem-name\tlisting-id\tsku\tprice\tshipping-fee\tquantity-purchased\ttotal-price\tpurchase-date\tbatch-id\tbuyer-email\tbuyer-name\trecipient-name\tship-address-1\tship-address-2\tship-city\tship-state\tship-zip\tship-country\tspecial-comments\tupc\tship-method\tcommission\r\n";
	return $titles;
}
///////////////////////////////Store sold auction in output file////////////
function storeSold(array $item,$squ){
	
	$buyerId = $item[8];
	$ups=$this->getUps($item[0]);
	$buyerInfo = $this->getBuyerInfo($item[0]);
	$price = $this->getPlnZl($item[4]);
	$shipcost =$this->getPlnZl(constant('SHIPCOST'));
	if($buyerInfo['contact-country']==1) $country ='Poland'; 
	
	$soldItem = array(
	
	'payments-status'=>' ',             						# A note of the status of the payment (Credit card, Paid, etc. the interpretation is up to you)
	'order-id'=>$item[0],                    						# A user-wide unique order ID
	'order-item-id'=>$item[0],               				# A user-wide unique order item ID (you may have multiple order items per order
	'payments-date'=>$item[7],               						# The payment date
	'payments-transaction-id'=>' ',     						# Transaction ID for this order (future use)
	'item-name'=>$item[9],                  			    # Item title or name
	'listing-id'=>' ',                  						# Unused
	'sku'=>$squ,                         					# The seller's SKU

	'price'=>$price,                       					# Price
	'shipping-fee'=>$shipcost,                				# Shipping fee the user is paid
	'quantity-purchased'=>$item[5],          				# The qty of item purchased
	'total-price'=>($price+$shipcost)*$item[5],                # The total of the line item
	'purchase-date'=>$item[7],              				# The purchase date
	'batch-id'=>$item[21],                    				# Buyer login
	'buyer-email'=>$buyerInfo['contact-email'],             # Email of the buyer
	'buyer-name'=>$buyerInfo['contact-first-name']." ".$buyerInfo['contact-last-name'],                  # Name of the buyer
	'recipient-name'=>$buyerInfo['contact-first-name']." ".$buyerInfo['contact-last-name'],              # The ship to name

	'ship-address-1'=>$buyerInfo['contact-street'],         # Shipping address line 1
	'ship-address-2'=>' ',             						# Shipping address line 2
	'ship-city'=>$buyerInfo['contact-city'],                # Shipping city
	'ship-state'=>' ',                  					# Shipping state
	'ship-zip'=>$buyerInfo['contact-postcode'],             # Shipping ZIP
	'ship-country'=>$country,    						    # Shipping Country
	'special-comments'=>' ',            					# other notes for order
	'upc'=>$ups,                         					# UPC of item
	'ship-method'=>'courier',                 				# Desired ship method
	'commission'=>$item[35]                 				# Commission paid
	
);
	//echo "<br>";
	//print_r($soldItem);
	
	$squhandle = fopen("/home/ftpuser/orders/open_orders.txt", "a+");
		if(fgetc($squhandle)==false) fwrite($squhandle,$this->getTitles());
		
		foreach($soldItem as $field)
			fwrite($squhandle,$field."\t");	
		
			fwrite($squhandle,"\r\n");
	$logs = new Logs(" SOLD Item Squ->".$squ." was sold.");
	unset($logs);
	fclose($squhandle);

}

///////Funkcja sprawdza czy aukcjia nie zostala juz dodana///////
///////do zakonczonych~ czy nie zostala juz zdjeta z squId.txt///
function delFromSqu($allegroId){
	$row=0;
	$found=false;
	$lines = array();
	$squhandle = fopen("/home/ftpuser/orders/squId.txt" , "r+");
	while (($data = fgetcsv($squhandle, 200, "\t")) !== FALSE) {			//not deleting yet
			if($data[0]!=$allegroId){
				$lines[$row]=$data;
				$row++;
			}
			else{ $found = true; } 
	}
	if($found==true){
		fclose($squhandle);
		$squhandle = fopen("/home/ftpuser/orders/squId.txt", "w+");	//clears file
		foreach($lines as $line){
			foreach($line as $cell)
				fwrite($squhandle,$cell."\t");
		fwrite($squhandle,"\r\n");		
		}
		fclose($squhandle);
		return true;
	}else{
		fclose($squhandle);		
		return false;
		}
}

//////////////////////////////////Konstruktor///////////////////		
function AuctionSold(nusoap_client $soap , array $sesja, $data ){
	if(($soap==null)||($sesja==null))echo "przekazal null do auction";
	$this->soap = $soap;
	$this->sesja = $sesja;

	//if it's not in the squId.txt it's has been removed form allegro already
	//if it is in squId.txt we're going to remove it
 	$squ = $this->getSqu($data[0]);
 	if($squ==false) return null;
 		else{
  		$this->storeSold($data,$squ);
 		$this->delFromSqu($data[0]);
 		}

}
	

} /////////////////////////////end of the class//////////////////


?>
Return current item: Allegro script