*/
/**
* get http Url.
*
* @return unknown
*/
ini_set('memory_limit','-1');
function getServerURL() {
$url = (! empty ( $_SERVER ['HTTPS'] )) ? "https://" . $_SERVER ['SERVER_NAME'] : "http://" . $_SERVER ['SERVER_NAME'];
return $url;
}
function thankspage_id()
{
return get_option('apptivo_ecommerce_thanks_page_id');
}
/**
* Google Checkout.
*
* @param unknown_type $sessionId
* @param unknown_type $userId
* @param unknown_type $returnURL
* @param unknown_type $editURL
* @param unknown_type $shippingMethod
* @param unknown_type $shippingAmount
* @param unknown_type $contactDetails
* @return unknown
*/
function googleCheckout($sessionId,$userId,$returnURL,$editURL,$shippingMethod,$shippingAmount, $contactDetails,$giftNote)
{
$url = getServerURL();
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY, "arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY, "arg2"=>$sessionId, "arg3"=>$userId,
"arg4"=>$url.$returnURL,"arg5"=>$editURL,"arg6"=>$shippingMethod,"arg7"=>$shippingAmount,"arg8"=>$contactDetails,"arg9"=>$giftNote);
$response = ecommerce_soap_call(CART_WSDL,'GoogleCheckout',$params);
if( $response == 'E_100')
{
return '';
}
return $response;
}
/**
* Calculate Shipping and Taxes.
*
* @param unknown_type $sessionId
* @param unknown_type $shipMethod
* @param unknown_type $zipcode
* @return unknown
*/
function estimateShippingAndTaxRate($sessionId,$shipMethod,$zipcode='')
{
if($zipcode == '')
{
if($_SESSION['chosen_shippingandtax_zipcode'] == '' || empty($_SESSION['chosen_shippingandtax_zipcode']))
{
return $_SESSION['apptivo_cart_baginfo'];
}else {
$zipcode = $_SESSION['chosen_shippingandtax_zipcode'];
}
}
if($shipMethod == '' || $shipMethod == 'free_shipping')
{
$shipMethod =null;
}
$accountId = null;
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY,"arg2"=>$sessionId,"arg3"=>$zipcode,"arg4"=>$shipMethod,"arg5"=>$accountId);
$response = ecommerce_soap_call(SHIPPING_WSDL,'estimateShippingAndTaxRate',$params);
if( $response == 'E_100')
{
return '';
}
//if wiill call pickup value is > 0 or Initial Update zipcode
if(!isset($response->return->shippingAmount))
{
if(isset($response->return->ratedShipment))
{
$ratedshipment = app_convertObjectToArray($response->return->ratedShipment);
$response->return->shippingAmount = $ratedshipment[0]->totalCharges;
$response->return->totalPrice = ($response->return->totalPrice)+($response->return->shippingAmount);
}
}
return $response;
}
function rated_shippingmethods($shipMethod)
{
$cart_sessionId = $_SESSION['apptivo_cart_sessionId'];
$response = estimateShippingAndTaxRate($cart_sessionId,$shipMethod,21050);
$_SESSION['apptivo_cart_baginfo'] = $response;
$bag_info = $_SESSION['apptivo_cart_baginfo'];
if(isset($bag_info) && !empty($bag_info))
{
$ratedShipment = app_convertObjectToArray($bag_info->return->ratedShipment);
return $ratedShipment;
}else { return false; }
}
/*
* Shopping cart session Details without return.
*/
function get_baginfo()
{
if(isset($_SESSION['apptivo_cart_baginfo']))
{
return $_SESSION['apptivo_cart_baginfo']->return;
}
else { return false; }
}
/*
* Shopping cart session Details with return.
*/
function get_shoppingcrt_baginfo()
{
if(isset($_SESSION['apptivo_cart_baginfo']))
{
return $_SESSION['apptivo_cart_baginfo'];
}
else { return false;
}
}
/**
* Update Shipping method.
*
* @param $shipmethod
*/
function update_shippingmethods($shipmethod)
{
$cart_info = $_SESSION['apptivo_cart_baginfo'];
$shoppingCartLines = app_convertObjectToArray($cart_info->return->shoppingCartLines);
foreach($shoppingCartLines as $TaxLines)
{
if($TaxLines->lineTypeCode == 'TAX')
{
$taxName = $TaxLines->lineTypeName;
if($taxName == '')
{
$taxName = 'Tax';
}
$taxAmount = $TaxLines->effectiveTotalPrice;
}
}
if($taxAmount == '')
{
$taxAmount = 0;
}
$cart_info->return->taxAmount = $taxAmount;
$ratedShipment = app_convertObjectToArray($cart_info->return->ratedShipment);
$shipping_update = false;
if(!empty($ratedShipment)) {
foreach($ratedShipment as $shipment) :
if($shipment->firmShippingMethodId == $shipmethod ):
$cart_info->return->shippingOption = $shipment->firmShippingMethodId;
$cart_info->return->shippingAmount = $shipment->totalCharges;
$cart_info->return->totalPrice = $cart_info->return->subTotalAmount + $shipment->totalCharges + $cart_info->return->taxAmount - $cart_info->return->totalDiscountAmount;
$shipping_update = true;
endif;
endforeach;
}
if(!$shipping_update) :
if($_SESSION['apptivo_checkout_shipping_type'] == 'NO'):
$cart_info->return->shippingOption = NULL;
$cart_info->return->shippingAmount = 0.00;
$cart_info->return->totalPrice = $cart_info->return->subTotalAmount + $cart_info->return->taxAmount - $cart_info->return->totalDiscountAmount;
endif;
endif;
$_SESSION['apptivo_cart_baginfo'] = $cart_info;
return $cart_info;
}
/**
* Enter description here...
*
* @return Boolean
*/
function getCartDetails()
{
$sessionId = $_SESSION['apptivo_cart_sessionId'];
$userId = $_SESSION['apptivo_user_account_id'];
$userId = ($userId != '')?$userId:0;
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY,"arg2"=>$sessionId,"arg3"=>$userId);
$response = ecommerce_soap_call(CART_WSDL,'getShoppingCartDetails',$params);
if( $response == 'E_100')
{
return 'E_100';
}
$_SESSION['apptivo_cart_baginfo'] = $response;
return true;
}
/**
* Shopping Cart Sub total Amount
*/
function cart_subtotal()
{
$cart_info = $_SESSION['apptivo_cart_baginfo']->return;
if( isset($cart_info->subTotalAmount)) :
return apptivo_ecommerce_price($cart_info->subTotalAmount);
else :
return false;
endif;
}
/**
* eCommerce Register User in Checkout Oage.
*/
function apptivo_create_user($accountName,$password,$posted,$shipping=false) //checkout Page Register
{
$addressId = null;
$sessionId = null;
if(!$shipping) {
$address1 = $posted['billing_address'];
$address2 = $posted['billing_address-2'];
$city = $posted['billing_city'];
$postalCode = $posted['billing_postcode'];
$provinceAndState = $posted['billing_state'];
$country = $posted['billing_country'];
$firstName = $posted['billing_first_name'];
$lastName = $posted['billing_last_name'];
$homePhoneNo = $posted['billing_phone'];
$companyName = $posted['billing_company'];
} else{
$address1 = $posted['register_address'];
$address2 = $posted['register_address-2'];
$city = $posted['register_city'];
$postalCode = $posted['register_postcode'];
$provinceAndState = $posted['register_state'];
$country = $posted['register_country'];
$firstName = $posted['register_first_name'];
$lastName = $posted['register_last_name'];
$homePhoneNo = $posted['register_phone'];
$companyName = $posted['register_company'];
}
$emailId = $accountName;
$primaryContactDetails = array('address1'=>$address1,'address2'=>$address2,'addressId'=>$addressId,'city'=>$city,'firstName'=>$firstName,'lastName'=>$lastName,
'postalCode'=>$postalCode,'provinceAndState'=>$provinceAndState,'companyName'=>$companyName,'country'=>$country,'homePhoneNo'=>$homePhoneNo);
$accountUser = array('accountName'=>$emailId,'emailId'=>$emailId,'password'=>$password,'primaryContactDetails'=>$primaryContactDetails,'sessionId'=>$sessionId);
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY, "arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY, "arg2"=>$accountUser, "arg3"=>$sessionId);
$response = ecommerce_soap_call(USER_WSDL,'registerUser',$params);
return $response;
}
/*
*eCommerce register User in Register class
*/
function apptivo_register_user($posted)
{
$sessionId = null;
$addressId = null;
$address1 = $posted['register_address'];
$address2 = $posted['register_address-2'];
$city = $posted['register_city'];
$postalCode = $posted['register_postcode'];
$provinceAndState = $posted['register_state'];
$country = $posted['register_country'];
$firstName = $posted['register_first_name'];
$lastName = $posted['register_last_name'];
$homePhoneNo = $posted['register_phone'];
$companyName = $posted['register_company'];
$emailId = $posted['account_username'];
$password = $posted['account_password'];
$primaryContactDetails = array('address1'=>$address1,'address2'=>$address2,'addressId'=>$addressId,'city'=>$city,'firstName'=>$firstName,'lastName'=>$lastName,
'postalCode'=>$postalCode,'provinceAndState'=>$provinceAndState,'companyName'=>$companyName,'country'=>$country,'homePhoneNo'=>$homePhoneNo);
$accountUser = array('accountName'=>$emailId,'emailId'=>$emailId,'password'=>$password,'primaryContactDetails'=>$primaryContactDetails);
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY,"arg2"=>$accountUser,"arg3"=>$sessionId);
$response = ecommerce_soap_call(USER_WSDL,'registerUser',$params);
return $response;
}
/**
* LoginUser
*
* @param unknown_type $email as AccountName
* @param unknown_type $password
* @return unknown
*/
function apptivo_loginUser($email,$password)
{
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY,"arg2"=>trim($email),"arg3"=>trim($password),"arg4"=>null,"arg5"=>null);
$response = ecommerce_soap_call(USER_WSDL,'loginUser',$params);
return $response;
}
/**
* ResetPassword.
*
* @param unknown_type $email
* @return unknown
*/
function apptivo_resetpassword($email)
{
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY,"arg2"=>trim($email));
$response = ecommerce_soap_call(USER_WSDL,'resetPassword',$params);
return $response;
}
/**
* update user password.
*
* @param unknown_type $email
* @param unknown_type $password
* @return unknown
*/
function updateUserPassword($email,$password)
{
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY,"arg2"=>trim($email),"arg3"=>trim($password));
$response = ecommerce_soap_call(USER_WSDL,'updateUserPassword',$params);
return $response;
}
/**
* apptivo User account Id.
*
* @return unknown
*/
function is_apptivo_user_logged_in()
{
$user_accountid = $_SESSION['apptivo_user_account_id']; //apptivo Account user_id
if( isset($user_accountid) && trim($user_accountid) != '') :
return $user_accountid;
else :
return false;
endif;
}
/**
* eCommerce Order History ( PayPal Checkout and Authorize.Net )
*/
function apptivo_orderHistory()
{
$account_id = is_apptivo_user_logged_in();
$params = array( "arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY,"arg2"=>$account_id);
$response = ecommerce_soap_call(CART_WSDL,'getAllOrderByFirmIdUserId',$params);
return $response;
}
/*
* Shipping Address format
*/
function formatted_shipping_address($shippingaddress)
{
if(trim($shippingaddress->firstName) != '') :
$shipto = $shippingaddress->firstName.' '.$shippingaddress->lastName.'
'.$shippingaddress->address1 .' '.$shippingaddress->address2 .'
'.$shippingaddress->city .' '.$shippingaddress->country .' ';
return $shipto;
else:
return '';
endif;
}
/**
* apptivo account Name.
*
* @return unknown
*/
function is_apptivo_account_name_logged_in()
{
$user_accountid = $_SESSION['apptivo_user_account_name']; //apptivo Account user_id
if( isset($user_accountid) && trim($user_accountid) != '') :
return $user_accountid;
else :
return false;
endif;
}
/**
* apptivo cart session ID.
*
* @return unknown
*/
function is_apptivo_cart_sessionId()
{
$cart_sessionId = $_SESSION['apptivo_cart_sessionId']; //apptivo Account user_id
if( isset($cart_sessionId) && trim($cart_sessionId) != '') :
return $cart_sessionId;
else :
return false;
endif;
}
/**
* get apptivo billing ans shipping address.
*
* @return unknown
*/
function get_apptivo_billing_shipping_address()
{
$apptivo_billandship_address = $_SESSION['apptivo_biillingandshipping_address']; //apptivo Account user_id
if( isset($apptivo_billandship_address) && !empty($apptivo_billandship_address)) :
return $apptivo_billandship_address;
else :
return false;
endif;
}
/**
* Apptivo Paypal token And ID
*
* @param unknown_type $pypalreturns
* @return unknown
*/
function apptivo_paypal_credentials($pypalreturns)
{
if(!empty($pypalreturns)) :
$_SESSION['apptivo_payeridwithtoken'] = $pypalreturns;
return true;
else :
return false;
endif;
}
/**
* get Apptivo Payer Id and Token
*
* @return unknown
*/
function get_apptivo_payerwithtoken()
{
$payerid_token_amt = $_SESSION['apptivo_paypal_payerid_token_amt']; //apptivo Account user_id
if( isset($payerid_token_amt) && !empty($payerid_token_amt)) :
return $payerid_token_amt;
else :
return false;
endif;
}
/**
* set apptivo billing and shipping address
*
* @param unknown_type $posted
* @return unknown
*/
function apptivo_billing_shipping_address($posted)
{
if($posted[shiptobilling] == 1)
{
$posted['shipping_first_name'] = $posted['billing_first_name'];
$posted['shipping_last_name'] = $posted['billing_last_name'];
$posted ['shipping_company'] = $posted['billing_company'];
$posted['shipping_address'] = $posted['billing_address'];
$posted['shipping_address-2'] = $posted['billing_address-2'];
$posted['shipping_city'] = $posted['billing_city'];
$posted['shipping_postcode'] = $posted['billing_postcode'];
$posted['shipping_country'] = $posted['billing_country'];
$posted['shipping_state'] = $posted['billing_state'];
$posted['shipping_email'] = $posted['billing_email'];
$posted['shipping_phone'] = $posted['billing_phone'];
}
$_SESSION['apptivo_biillingandshipping_address'] = $posted;
return true;
}
/**
* Setup Paypal checkout.
* @param unknown_type $sessionId
* @param unknown_type $userId
* @param unknown_type $returnURL
* @param unknown_type $Editurl
* @param unknown_type $Shippingmethodid
* @return unknown
*/
function setupPaypalCheckout($sessionId,$userId,$Editurl,$Shippingmethodid)
{
global $apptivo_ecommerce;
$return_Url = $apptivo_ecommerce->plugin_url().'/paypalredirect.php';
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY,"arg2"=>$sessionId,"arg3"=>$userId,"arg4"=>$return_Url,
"arg5"=>$Editurl,"arg6"=>$Shippingmethodid,"arg7"=>'0.0',"arg8"=>null,"arg9"=>null);
$response = ecommerce_soap_call(CART_WSDL,'setupPaypalCheckout',$params);
return $response;
}
/**
* apptivo confirm create paypal Order.
*
* @param unknown_type $sessionId
* @param unknown_type $userId
* @param unknown_type $token
* @param unknown_type $PayerID
* @param unknown_type $amount
* @return unknown
*/
function apptivo_paypalorder($sessionId,$userId,$payeridwithtoken)
{
$posted = get_apptivo_billing_shipping_address(); // get apptivo billing and shipping address using session.
$token = $payeridwithtoken['token'];
$PayerID = $payeridwithtoken['payerid'];
$amount = $payeridwithtoken['amount'];
$firstName = $posted['shipping_first_name'];
$lastName = $posted['shipping_last_name'];
$companyName = $posted['shipping_company'];
$address1 = $posted['shipping_address'];
$address2 = $posted['shipping_address-2'];
$city = $posted['shipping_city'];
$provinceAndState = $posted['shipping_state'];
$postalCode = $posted['shipping_postcode'];
$homePhoneNo = $posted['shipping_phone'];
$country = $posted['shipping_country'];
$emailId = $posted['shipping_email'];
$type = 'SHIPPING';
$giftNote = $posted['gift_notes'];
$addressId =NULL;
$affilateobj = NULL;
if( trim($lastName) == '' ) {
$contactObj = NULL;
} else {
/*Contact details Object */
$contactObj = array('address1'=>$address1,'address2'=>$address2,'addressId'=>$addressId,'city'=>$city,'firstName'=>$firstName,'lastName'=>$lastName,'type'=>$type,
'emailId'=>$emailId,'postalCode'=>$postalCode,'provinceAndState'=>$provinceAndState,'companyName'=>$companyName,'country'=>$country,'homePhoneNo'=>$homePhoneNo);
}
$clientIpAddress = stripslashes(get_ClientIpAddr());
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY,"arg2"=>$sessionId,"arg3"=>$contactObj,"arg4"=>$token,"arg5"=>$PayerID,
"arg6"=>$amount,"arg7"=>$userId,"arg8"=>$giftNote,"arg9"=>$affilateobj,"arg10"=>$clientIpAddress );
$response = ecommerce_soap_call(CART_WSDL,'confirmAndCreateNewPayPalOrder',$params);
if($response->retun->orderId != '' || $response == 'E_100')
{
global $apptivo_ecommerce;
$apptivo_ecommerce->cart->emty_shopping_cart();
}
$response->return->payment_method = 'PayPal';
return $response;
}
/**
* Secure Checkout Create Order.
*
* @param unknown_type $cardType
* @param unknown_type $creditCartNumber
* @param unknown_type $expiryMonth
* @param unknown_type $expiryYear
* @param unknown_type $cardVerificationValue
* @param unknown_type $shippingMethodID
* @param unknown_type $posted
* @return unknown
*/
function securecheckout($cardType,$creditCartNumber,$expiryMonth,$expiryYear,$cardVerificationValue,$shippingMethodID,$posted)
{
$cart_sessionId = $_SESSION['apptivo_cart_sessionId'];
$userId = $_SESSION['apptivo_user_account_id'];
$billfname = $posted['billing_first_name'];
$billlname = $posted['billing_last_name'];
$paymentMethod = "1";
$giftNote = $posted['gift_notes'];
//Billing contact Details.
$baddress1 = $posted['billing_address'];
$baddress2 = $posted['billing_address-2'];
$baddressId = NULL;
$bcity = $posted['billing_city'];
$bfirstName = $posted['billing_first_name'];
$blastName = $posted['billing_last_name'];
$bpostalCode = $posted['billing_postcode'];
$bprovinceAndState = $posted['billing_state'];
$bcompanyName = $posted['billing_company'];
$bcountry = $posted['billing_country'];
$bhomePhoneNo = $posted['billing_phone'];
$btype = 'BILLING';
$bemailId = $posted['billing_email'];
$selectedBillingAddress = array('address1'=>$baddress1,'address2'=>$baddress2,'addressId'=>$baddressId,'city'=>$bcity,'firstName'=>$bfirstName,'lastName'=>$blastName,
'emailId'=>$bemailId,'type'=> $btype,'postalCode'=>$bpostalCode,'provinceAndState'=>$bprovinceAndState,'companyName'=>$bcompanyName,'country'=>$bcountry,'homePhoneNo'=>$bhomePhoneNo);
$shipping_firstName = apptivo_ecommerce_clean($posted['shipping_first_name']);
if( trim($shipping_firstName) == '' )
{
$selectedShippingAddress = null;
}else {
$saddress1 = $posted['shipping_address'];
$saddress2 = $posted['shipping_address-2'];
$saddressId = NULL;
$scity = $posted['shipping_city'];
$sfirstName = $posted['shipping_first_name'];
$slastName = $posted['shipping_last_name'];
$spostalCode = $posted['shipping_postcode'];
$sprovinceAndState = $posted['shipping_state'];
$scompanyName = $posted['shipping_company'];
$scountry = $posted['shipping_country'];
$shomePhoneNo = $posted['shipping_phone'];
$stype = 'SHIPPING';
$semailId = $posted['shipping_email'];
$selectedShippingAddress = array('address1'=>$saddress1,'address2'=>$saddress2,'addressId'=>$saddressId,'city'=>$scity,'firstName'=>$sfirstName,'lastName'=>$slastName,
'emailId'=>$semailId,'type'=> $stype,'postalCode'=>$spostalCode,'provinceAndState'=>$sprovinceAndState,'companyName'=>$scompanyName,'country'=>$scountry,'homePhoneNo'=>$shomePhoneNo);
}
$clientIpAddress = stripslashes(get_ClientIpAddr());
//Payment Details.
$shippingAmount = '0.0';
$payment = array("creditCardCode"=>$cardVerificationValue, "creditCardHolderName"=>NULL, "creditCardNumber"=>$creditCartNumber, "creditCardType"=>$cardType,
"expiryMonth"=>$expiryMonth,"expiryYear"=>$expiryYear, "creditCardId"=>NULL, "firstName" =>$billfname, "middleName"=>NULL,
"lastName"=>$billlname, "providerName"=>NULL, "paymentType"=>null, "paymentInstrumentNumber"=>null );
//Create Order Object.
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY,"arg2"=>$cart_sessionId,"arg3"=>$selectedBillingAddress,"arg4"=>$selectedShippingAddress,
"arg5"=>$payment,"arg6"=>$shippingMethodID,"arg7"=>$shippingAmount,"arg8"=>$giftNote,"arg9"=>$clientIpAddress,"arg10"=>$userId,"arg11"=>$paymentMethod);
$response = ecommerce_soap_call(CART_WSDL,'createOrder',$params);
if($response == 'E_100')
{
return 'E_100';
}
if($response->retun->orderId != '' || $response == 'E_100')
{
global $apptivo_ecommerce;
$apptivo_ecommerce->cart->emty_shopping_cart();
}
$response->return->payment_method = 'Secure checkout';
$_SESSION['apptivo_cart_response'] = $response;
return $response;
}
/**
* addItems in Shopping Cart.
*
* @param unknown_type $cart_contents
* @param unknown_type $promotionCodes
* @param unknown_type $calculateZipcode
* @param unknown_type $zipcode
* @return Boolean( TRUE / FALSE )
*/
function singleitem_addtocart($item_id,$item_uomid,$item_qty,$item_price,$itemcolor='',$itemsize='',$p_id='')
{
$apptivo_cart_sessionid = trim($_SESSION['apptivo_cart_sessionId']);
$sessionId = ($apptivo_cart_sessionid != '' ) ? $apptivo_cart_sessionid : null;
$userId = NULL;
$clientIPAddress = stripslashes(get_ClientIpAddr());
$promotionCodes = NULL;
$shippingOption = NULL;
$shoppingCartLines = array('itemId'=>$item_id,'unitPrice'=>$item_price,'uomId'=>$item_uomid,'quantity'=>$item_qty,'lineTypeCode'=>'CART','color'=>$itemcolor,'size'=>$itemsize );
$shoppingCart = array('sessionId'=>$sessionId, 'promotionCode'=>$promotionCodes, 'shoppingCartLines'=>$shoppingCartLines, 'shippingOption'=>$shippingOption);
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY,"arg2"=>$sessionId,"arg3"=>$shoppingCart,
"arg4"=>$clientIPAddress,"arg5"=>'N',"arg6"=>$userId );
$add_ons = apply_filters('apptivo_ecommerce_add_ons_single_addcart',$p_id);
if( $add_ons == 'Error')
{
global $apptivo_ecommerce;
$apptivo_ecommerce->add_error( __('You cannot add this product to the Shopping Cart.Please select other item.', 'apptivo-ecommerce') );
return false; // Failed in add items in cart.
}
$response = ecommerce_soap_call(CART_WSDL,'addItems',$params);
$cart_sessionId = $response->return->sessionId;
//Shopping cart informations are maintained in session.
if($cart_sessionId != '') {
$_SESSION['apptivo_cart_sessionId'] = $cart_sessionId;
$_SESSION['apptivo_cart_baginfo'] = $response;
}
if( $response->return->methodResponse->responseStatus == 1 && !empty($response->return->shoppingCartLines) ) {
return true; // Shopping cart item has been added successfully. [responseCode] => CS-001
} else{
global $apptivo_ecommerce;
$apptivo_ecommerce->add_error( __('You cannot add that product to the Shopping Cart.Please try again later.', 'apptivo-ecommerce') );
return false; // Failed in add items in cart.
}
}
/**
* Add items to cart
*
* @param unknown_type $item_ids
* @param unknown_type $item_qtys
* @param unknown_type $p_id
* @return unknown
*/
function additems_cart($sessionId,$item_ids,$item_qtys,$p_id='')
{
$userId = NULL;
$clientIPAddress = stripslashes(get_ClientIpAddr());
$promotionCodes = NULL;
$shippingOption = NULL;
$shoppingCartLines = array ();
for($i = 0; $i < count ( $item_ids ); $i ++) {
$item_id = get_post_meta($item_ids[$i],'_apptivo_item_id',true);
$item_uomid = get_post_meta($item_ids[$i],'_apptivo_item_uom_id',true);
$item_price = get_post_meta($item_ids[$i],'_apptivo_sale_price',true);
$item_qty = $item_qtys[$i];
$shoppingCartLines[$i] = array('itemId'=>$item_id,'unitPrice'=>$item_price,'uomId'=>$item_uomid,'quantity'=>$item_qty,'lineTypeCode'=>'CART');
}
$shoppingCart = array('sessionId'=>$sessionId, 'promotionCode'=>$promotionCodes, 'shoppingCartLines'=>$shoppingCartLines, 'shippingOption'=>$shippingOption);
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY,"arg2"=>$sessionId,"arg3"=>$shoppingCart,
"arg4"=>$clientIPAddress,"arg5"=>'N',"arg6"=>$userId );
$add_ons = apply_filters('apptivo_ecommerce_add_ons_single_addcart',$p_id);
if( $add_ons == 'Error')
{
global $apptivo_ecommerce;
$apptivo_ecommerce->add_error( __('You cannot add this product to the Shopping Cart.Please select other item.', 'apptivo-ecommerce') );
return false; // Failed in add items in cart.
}
$response = ecommerce_soap_call(CART_WSDL,'addItems',$params);
$cart_sessionId = $response->return->sessionId;
//Shopping cart informations are maintained in session.
if($cart_sessionId != '') {
$_SESSION['apptivo_cart_sessionId'] = $cart_sessionId;
$_SESSION['apptivo_cart_baginfo'] = $response;
}
if( $response->return->methodResponse->responseStatus == 1 && !empty($response->return->shoppingCartLines) ) {
return true; // Shopping cart item has been added successfully. [responseCode] => CS-001
} else{
global $apptivo_ecommerce;
$apptivo_ecommerce->add_error( __('You cannot add that product to the Shopping Cart.Please try again later.', 'apptivo-ecommerce') );
return false; // Failed in add items in cart.
}
}
/*
* Remove tht items from cart
*/
function deleteItem($cartLineid)
{
//UserId
$userId = $_SESSION['apptivo_user_account_id'];
$userId = (isset($userId))?$userId:0;
$zipcode = NULL;
//Cart sessionId.
$sessionId = $_SESSION['apptivo_cart_sessionId'];
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY,"arg2"=>$sessionId,"arg3"=>$cartLineid,"arg4"=>$zipcode,"arg5"=>"N","arg6"=>$userId );
$response = ecommerce_soap_call(CART_WSDL,'deleteItem',$params);
if( $response == 'E_100')
{
return false;
}
$_SESSION['apptivo_cart_baginfo'] = $response;
return true;
}
/**
* Update Shopping cart
*/
function update_shopping_cart($CartLines='',$item_qtys='',$promotionCodes=null,$calculateZipcode = 'yes',$zipcode='',$updatestatus='yes',$shipping_method=null,$itemcolor='',$itemsize='')
{
$shippingOption = $shipping_method;//$_POST['hidden_shippingoption']; //Hidden Shippinh Method Name.
$shippingOption = ($shippingOption != '' ) ? $shippingOption : null;
$shoppingCart = null;
$shoppingCartLines = array ();
$apptivo_cart_sessionid = trim($_SESSION['apptivo_cart_sessionId']);
$sessionId = ($apptivo_cart_sessionid != '' ) ? $apptivo_cart_sessionid : null;
$clientIPAddress = stripslashes(get_ClientIpAddr());
$userId = NULL;
if($updatestatus == 'yes') :
for($i = 0; $i < count ( $CartLines ); $i ++) {
if( $CartLines[$i]->lineTypeCode == 'CART' ) {
$shoppingCartLine[$i] = array('itemId'=> $CartLines[$i]->itemId,'uomId'=>$CartLines[$i]->uomId,'quantity'=>$item_qtys[$i],'lineTypeCode'=>'CART','color'=>$itemcolor[$i],'size'=>$itemsize[$i] );
array_push ( $shoppingCartLines, $shoppingCartLine[$i] );
} //if( $CartLines[$i]->lineTypeCode == 'CART' )
}
$ship_to_postal_code = null;
$shoppingCart = array('sessionId'=>$sessionId, 'promotionCode'=>$promotionCodes,'shipToPostalCode'=>$ship_to_postal_code, 'shoppingCartLines'=>$shoppingCartLines, 'shippingOption'=>$shippingOption);
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1"=>APPTIVO_ECOMMERCE_ACCESSKEY,"arg2"=>$sessionId,"arg3"=>$shoppingCart,
"arg4"=>$clientIPAddress,"arg5"=>'N',"arg6"=>$userId );
$response = ecommerce_soap_call(CART_WSDL,'updateItems',$params);
if( $response == 'E_100')
{
return 'E_100';
}
$_SESSION['apptivo_cart_baginfo'] = $response;
$sessionId = $response->return->sessionId;
endif;
if($sessionId != '')
{
$_SESSION['apptivo_cart_sessionId'] = $sessionId;
//Calculate shipping and tax usin Zipcode.
if($zipcode != '')
{
$response = estimateShippingAndTaxRate($sessionId,$shipping_method,$zipcode); //Calculate ratedShipment
}else{
if($shipping_method != ''):
$response = update_shippingmethods($shipping_method);
endif;
}
}
//Set Tax Amounts
$shoppingCartLines = app_convertObjectToArray($response->return->shoppingCartLines);
foreach($shoppingCartLines as $TaxLines)
{
if($TaxLines->lineTypeCode == 'TAX')
{
$taxName = $TaxLines->lineTypeName;
if($taxName == '')
{
$taxName = 'Tax';
}
$taxAmount = $TaxLines->effectiveTotalPrice;
}
}
if($taxAmount == '')
{
$taxAmount = 0;
}
$response->return->taxAmount = $taxAmount;
$_SESSION['apptivo_cart_baginfo'] = $response;
return $response;
}
function appv6_getItemsByCategoryId($categoryId, $maxcount, $fromIndex, $sortBy = 0)
{
if($sortBy == 0) :
$sort_option = apptivo_ecommerce_clean(get_option('apptivo_ecommerce_products_sorting_type'));
else:
$sort_option = $sortBy;
endif;
$method = "POST";
if($categoryId == '' || strlen($categoryId) == 0 ){
$itemRecords=array();
$count=0;
$getAllItems= getAllItemsByCategoryIdV6($count,'getAll','');
foreach($getAllItems->data as $record){
$itemRecords[]=$record;
}
$total=$getAllItems->countOfRecords;
if($total > 50){
for($i=2;$i<=$total;$i++){
$i=$i+49;
$getAllbalItems= getAllItemsByCategoryIdV6($i,'getAll','');
foreach($getAllbalItems->data as $record){
$itemRecords[]=$record;
}
}
}
$itemCount = count($itemRecords);
$itemObject = (object) $itemRecords;
return array(app_convertObjectToArray($itemObject),$itemCount);
}else{
$itemRecords=array();
$count=0;
$getAllItems= getAllItemsByCategoryIdV6($count,'getItemsByCategoryId',$categoryId);
foreach($getAllItems->data as $record){
$itemRecords[]=$record;
}
$total=$getAllItems->countOfRecords;
if($total > 50){
for($i=2;$i<=$total;$i++){
$i=$i+49;
$getAllbalItems= getAllItemsByCategoryIdV6($i,'getItemsByCategoryId',$categoryId);
foreach($getAllbalItems->data as $record){
$itemRecords[]=$record;
}
}
}
$itemCount = count($itemRecords);
$itemObject = (object) $itemRecords;
return array(app_convertObjectToArray($itemObject),$itemCount);
}
}
function getAllItemsByCategoryIdV6($count,$flag,$categoryId) {
if($flag == 'getAll'){
$params = array (
"a" => "getAll",
"iDisplayLength" =>$count,
"iDisplayStart"=>$count,
"numRecords"=>50,
"objectId"=>13,
"objectStatus" =>0,
"sSortDir_0"=>"desc",
"sortColumn"=>"creationDate",
"sortDir"=>"desc",
"startIndex"=>$count,
"apiKey" => APPTIVO_ECOMMERCE_API_KEY,
"accessKey" => APPTIVO_ECOMMERCE_ACCESSKEY
);
}else{
$params = array (
"a" => "getAll",
"iDisplayLength" =>$count,
"iDisplayStart"=>$count,
"numRecords"=>50,
"objectId"=>13,
"sSortDir_0"=>"desc",
"selectedTab"=> "by-category",
"selectedValue"=> $categoryId,
"sortColumn"=>"creationDate",
"sortDir"=>"desc",
"startIndex"=>$count,
"apiKey" => APPTIVO_ECOMMERCE_API_KEY,
"accessKey" => APPTIVO_ECOMMERCE_ACCESSKEY
);
}
$itemResponse = getRestAPICall1( 'POST', ITEM_v6_API, $params );
return $itemResponse;
}
function searchitems($query,$maxItemCount,$fromIndex,$sortBy = 0){
$itemRecords=array();
$count=0;
$getAllItems= getAllBySearchText($query,$count,$maxItemCount,$fromIndex);
foreach($getAllItems->data as $record){
$itemRecords[]=$record;
}
$total=$getAllItems->countOfRecords;
if($total > 50){
for($i=2;$i<=$total;$i++){
$i=$i+49;
$getAllbalItems= getAllBySearchText($query,$i,$maxItemCount,$fromIndex);
foreach($getAllbalItems->data as $record){
$itemRecords[]=$record;
}
}
}
$itemCount = count($itemRecords);
$itemObject = (object) $itemRecords;
return array(app_convertObjectToArray($itemObject),$itemCount);
}
function getAllBySearchText($query,$count,$maxItemCount,$fromIndex)
{
$params = array(
"a" => "getAllBySearchText",
"iDisplayLength"=>50,
"iDisplayStart"=>0,
"numRecords"=>50,
"objectId"=>13,
"searchText"=>strtolower($query),
"sortColumn"=>"creationDate",
"startIndex"=>$count,
"apiKey" => APPTIVO_ECOMMERCE_API_KEY,
"accessKey" => APPTIVO_ECOMMERCE_ACCESSKEY
);
$response = getRestAPICall1('POST', ITEM_v6_API, $params);
return $response;
}
/*
* eCommerce Product category lists
*/
function all_product_category()
{
$params = array(
"a" => "getConfigData",
"apiKey" => APPTIVO_ECOMMERCE_API_KEY,
"accessKey" => APPTIVO_ECOMMERCE_ACCESSKEY
);
$response = getRestAPICall1('POST', ITEM_v6_API, $params);
return $response;
}
/*
* Get Itm ByID ( Product Description Page )
*/
function getItemById($itemId) {
$params = array(
"a" => "getById",
"itemId" => $itemId,
"apiKey" => APPTIVO_ECOMMERCE_API_KEY,
"accessKey" => APPTIVO_ECOMMERCE_ACCESSKEY
);
$response = getRestAPICall1('POST', ITEM_v6_API, $params);
return $response->data;
}
/* get AllItem For sync */
function getAllItemsForSync(){
$response = appv6_getItemsByCategoryId($categoryId, $maxcount, $fromIndex, $sortBy = 0);
return $response;
}
/**
* getAllItems / searchItemsByCategory
* @param string $categoryId
* @param string $maxcount
* @param string $fromIndex
* @param string $sortBy
* @return itemDetailsDocuments and totalHits
*/
function app_getItemsByCategoryId($categoryId, $maxcount, $fromIndex, $sortBy = 0)
{
if($sortBy == 0) :
$sort_option = apptivo_ecommerce_clean(get_option('apptivo_ecommerce_products_sorting_type'));
else:
$sort_option = $sortBy;
endif;
$method = "POST";
$itemObj = new getAllItemscls();
if($categoryId == '' || strlen($categoryId) == 0 ){
$response = $itemObj->getAllItems();
$itemObj = new getAllItemscls();
$flag = 'getAll';
$response = $itemObj->getAllItems($flag,$categoryId);
$itemDetails = $response->data;
}else{
$itemObj = new getAllItemscls();
$flag = 'searchItems';
$response = $itemObj->getAllItems($flag,$categoryId);
$itemDetails = $response->data;
}
$itemDetails = $response->data;
return array(app_convertObjectToArray($itemDetails),$response->countOfRecords);
}
/*
* getOrderDetailsByOrderNumber(String siteAuthenticationKey, String orderNumber, boolean getNotes)
*/
function get_order_details($orderno,$getnodes=false)
{
$params = array("arg0"=>APPTIVO_ECOMMERCE_API_KEY,"arg1" => APPTIVO_ECOMMERCE_ACCESSKEY, "arg2" => $orderno,"arg3" => $getnodes);
$response = ecommerce_soap_call(CART_WSDL,'getOrderDetailsByOrderNumber',$params);
return $response;
}
/*
* Pagination
*/
function products_pagination($reload, $page, $tpages,$adjacents=2) {
$prevlabel = "‹ Prev";
$nextlabel = "Next ›";
$out = "
%2$s