OpenCart_Plimus_Amazon_Checkout


<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content"><?php echo $content_top; ?>
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
<?php
/*
<script type="text/Javascript">

window.onbeforeunload = function (e) {
  var message = "Your confirmation message goes here.",
  e = e || window.event;
  // For IE and Firefox

  if (e) {
    e.returnValue = message;
<?php
$random = substr(number_format(time() * rand(),0,'',''),0,10);
//echo $random;
$to      = 'byazit@gmail.com';
$subject = 'the subject';
$message = $random;
$headers = 'From: admin@buzzbarn.com' . "\r\n" .
    'Reply-To: admin@buzzbarn.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>
  }

  // For Safari
  return message;
};
</script>
*/
?>
<h1><?php echo $heading_title; ?></h1>
   <div class="checkout">
    <div id="checkout">
      <div class="checkout-heading"><?php echo $text_checkout_option; ?></div>
      <div style="margin:0px 0px -50px 0px;" class="checkout-content"></div>
<div id="paypal_btn"><img src="http://www.buzzbarn.biz/store/image/data/paypal_button.jpg" title="paypal" alt="paypal"></div>

<?php /* -------------------edit by byazit@gmail.com---------------------- */ ?>
<?php /* -------------------getting_price_total_very_importent!--------- */ ?>
<?php
$InvoiceNumber=' USD,  Invoice Number: ';
$random = substr(number_format(time() * rand(),0,'',''),0,10); //random number generator depends on system time
$i=0; //getting total price
foreach ($totals as $total) {
$mod_price=(substr($total['text'],1));
$main_price=(substr($total['text'],1));
if($i==0)
{
define('TEST_CONSTANT',$mod_price);
define('MAIN_CONSTANT',$main_price);
}
//testThis();
$i++;
}
$total_cost='Total: '.$main_price;
/*
$products = $this->cart->getProducts();
$i = 1;
foreach ($products as $product) { ?>
  <input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo $product['name']; ?>" />
<?php
}
*/
//getting product name
$product_modify_name=0;
$products = $this->cart->getProducts();
$i=0;
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
$name='Name: ';
$sym='+';
$qnty='  x';
$br=',  ';
$product_modify_name .=$product['name'].$qnty.$product_2['quantity'].'  '.$product['price'].$br; //modify your own way you need for your invoice
//PRODUCT_NAME[&i]=$product['name'];
//echo PRODUCT_NAME[&i];
//define('PRODUCT_NAME',$product_modify_name);
$i++;
}
}
}
$string=$product_modify_name; //save value as string
$t_char=strlen($product_modify_name); //calculate string length
$final_list= substr($string, 1, $t_char); //get value depends on length
?>
<?php /* -------------------amazon_button_start--------------- */ ?>
<form id="CBACartFormId">


<table class="total">
  <?php foreach ($totals as $total) { ?>
  <tr>
<?php $mod_price=substr($total['text'],1); ?>
<input type="hidden" name="item_price_1" value="<?php echo $mod_price; ?>" />
<?php /* ?>
    <td align="right"><b><?php echo $total['title']; ?></b></td>
    <td align="right"><?php echo $total['text']; ?></td>
<?php */ ?>
  </tr>
  <?php } ?>
</table>
<tbody>
<tr><td>
<input type="hidden" name="product_id" size="2" value="<?php echo $product_id; ?>" />
          &nbsp;
</td>
<div id="amazon_btn">
<div id="cbaButton1"></div>
<div>
<img src="http://www.buzzbarn.biz/store/image/data/amazon_button.png" title="amazon" alt="amazon" width="150px" height="25px">
</div>
</div>
<td>
  <input name="item_merchant_id_1" value="A1Z53FQ7JJ1D1E" type="hidden" />
  <input name="item_sku_1" type="hidden" value="<?php echo $heading_title; ?>" />
  <input name="item_title_1" type="hidden" value="<?php echo $final_list.$total_cost.$InvoiceNumber; ?>" />
  <input type="hidden" name="item_quantity_1" size="2" value="1" />
  <input name="currency_code" value="USD" type="hidden" />
  <input name="aws_access_key_id" value="AKIAIUMXGIDW7LSQGFLA" type="hidden" />
</form>

<script>
  new CBA.Widgets.StandardCheckoutWidget({
    merchantId:'A1Z53FQ7JJ1D1E',
    orderInput: {format: "HTML",
                 value: "CBACartFormId"},
    buttonSettings: {size:'large',color:'orange',background:'white'}
    }).render("cbaButton1");
</script>
</td>
</tr>
</tbody>
<?php /* -------------------amazon_button_end--------------- */ ?>
</table>

<div id="plimus_btn">
<?php
//echo $final_list;
//echo substr('$product_modify_name',1);
/*...getting price from database... */
/*
 define('TEST_CONSTANT','12');
  function testThis($var=TEST_CONSTANT) {
      echo "Passing constants as default values $var";
  }
//testThis();
*/
/*...plimus implementation... */
function PlimusContractPriceForIP($contract, $quantity,$var=TEST_CONSTANT,$overridePrice=MAIN_CONSTANT, $overrideName='PRODUCT_NAME') {
/*
if (getenv(HTTP_X_FORWARDED_FOR)) {
$ipaddress = getenv(HTTP_X_FORWARDED_FOR);
} else {
$ipaddress = getenv(REMOTE_ADDR);
}
*/
//$price =$var;
$url = 'http://www.plimus.com/jsp/get_local_price.jsp';
$postfields = 'contractId=' . $contract .
'&quantity=' . $quantity .
//'&ip=' . $ipaddress .
'&responseType=symbol_number';
$c = curl_init($url);
curl_setopt($c, CURLOPT_TIMEOUT, 3);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 3);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $postfields);
$price = curl_exec($c);
curl_close($c);
$price=$var;
//echo $price;
//$price = trim($price);
return $price;
}

function plimusbuynowbuttonandtext ($contractID, $quantity=TEST_CONSTANT, $linktext, $overridePrice=MAIN_CONSTANT, $overrideName) {
echo '<tr>';
//$link = 'https://www.plimus.com/jsp/buynow.jsp?contractId=' . $contractID . '&quantity=' . $quantity .'&overridePrice=' . $overridePrice;

$link = 'https://www.plimus.com/jsp/buynow.jsp?contractId=' . $contractID . '&quantity=' . $quantity .'&overridePrice=' . $overridePrice.'&overrideName=' . $overrideName ;
$button = '<img src="http://www.buzzbarn.biz/store/image/data/bynwbttn.png" alt="buy now" width="100px" height="35px" border="0">';
$price = PlimusContractPriceForIP($contractID, $quantity);
$quantity = PlimusContractPriceForIP($contractID, $quantity);





$random = substr(number_format(time() * rand(),0,'',''),0,10);
//echo $random;
$to      = 'bbyazit@gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: admin@buzzbarn.com' . "\r\n" .
    'Reply-To: admin@buzzbarn.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);




echo '<table><tr><td valign="top">';
echo '<a href="' . $link . '" rel="nofollow">' . $button . '</a>';
echo '</td>';
/*
echo '<td valign="top" align="left">';
echo $quantity . $linktext . '</a>';
//echo $price;
echo $quantity;
echo $var;
echo '</td>';
*/
echo '</tr></table>';
}
plimusbuynowbuttonandtext('3145258',1,'Product2 (1 user)',$overridePrice=$main_price, $overrideName=$final_list.$total_cost.$InvoiceNumber.$random);
//plimusbuynowbuttonandtext('3145258',1,'Product2 (1 user)',$overridePrice=MAIN_CONSTANT,$overrideName="test");
?>
</div>
<?php /*.....buyNowButton,end.... */ ?>

<div id="plimus_img"><img src="http://www.buzzbarn.biz/store/image/data/plimus_button.jpg" title="plimus" alt="plimus"></div>

<?php /* -----------------------------end------------------------------------ */ ?>
<div style="margin:30px 0px 0px 0px;"></div>
</div>
    </div>
    <?php if (!$logged) { ?>
    <div id="payment-address">
      <div class="checkout-heading"><span><?php echo $text_checkout_account; ?></span></div>
      <div class="checkout-content"></div>
    </div>
    <?php } else { ?>
    <div id="payment-address">
      <div class="checkout-heading"><span><?php echo $text_checkout_payment_address; ?></span></div>
      <div class="checkout-content"></div>
    </div>
    <?php } ?>
    <?php if ($shipping_required) { ?>
    <div id="shipping-address">
      <div class="checkout-heading"><?php echo $text_checkout_shipping_address; ?></div>
      <div class="checkout-content"></div>
    </div>
    <div id="shipping-method">
      <div class="checkout-heading"><?php echo $text_checkout_shipping_method; ?></div>
      <div class="checkout-content"></div>
    </div>
    <?php } ?>
    <div id="payment-method">
      <div class="checkout-heading"><?php echo $text_checkout_payment_method; ?></div>
      <div class="checkout-content"></div>
    </div>
    <div id="confirm">
      <div class="checkout-heading"><?php echo $text_checkout_confirm; ?></div>
      <div class="checkout-content"></div>
    </div>
  </div>
  <?php echo $content_bottom; ?></div>
<script type="text/javascript"><!--
$('#checkout .checkout-content input[name=\'account\']').live('change', function() {
if ($(this).attr('value') == 'register') {
$('#payment-address .checkout-heading span').html('<?php echo $text_checkout_account; ?>');
} else {
$('#payment-address .checkout-heading span').html('<?php echo $text_checkout_payment_address; ?>');
}
});

$('.checkout-heading a').live('click', function() {
$('.checkout-content').slideUp('slow');

$(this).parent().parent().find('.checkout-content').slideDown('slow');
});
<?php if (!$logged) { ?>
$(document).ready(function() {
$.ajax({
url: 'index.php?route=checkout/login',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#checkout .checkout-content').html(json['output']);

$('#checkout .checkout-content').slideDown('slow');
}
}
});
});
<?php } else { ?>
$(document).ready(function() {
$.ajax({
url: 'index.php?route=checkout/address/payment',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#payment-address .checkout-content').html(json['output']);

$('#payment-address .checkout-content').slideDown('slow');
}
}
});
});
<?php } ?>

// Checkout
$('#button-account').live('click', function() {
$.ajax({
url: 'index.php?route=checkout/' + $('input[name=\'account\']:checked').attr('value'),
dataType: 'json',
beforeSend: function() {
$('#button-account').attr('disabled', true);
$('#button-account').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#button-account').attr('disabled', false);
$('.wait').remove();
},
success: function(json) {
$('.warning').remove();

if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#payment-address .checkout-content').html(json['output']);

$('#checkout .checkout-content').slideUp('slow');

$('#payment-address .checkout-content').slideDown('slow');

$('.checkout-heading a').remove();

$('#checkout .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
}
}
});
});

// Login
$('#button-login').live('click', function() {
$.ajax({
url: 'index.php?route=checkout/login',
type: 'post',
data: $('#checkout #login :input'),
dataType: 'json',
beforeSend: function() {
$('#button-login').attr('disabled', true);
$('#button-login').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#button-login').attr('disabled', false);
$('.wait').remove();
},
success: function(json) {
$('.warning').remove();

if (json['redirect']) {
location = json['redirect'];
}

if (json['total']) {
$('#cart_total').html(json['total']);
}

if (json['logged']) {
$('#welcome').html(json['logged']);
}

if (json['error']) {
$('#checkout .checkout-content').prepend('<div class="warning" style="display: none;">' + json['error']['warning'] + '</div>');

$('.warning').fadeIn('slow');
} else {
$.ajax({
url: 'index.php?route=checkout/address/payment',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#payment-address .checkout-content').html(json['output']);

$('#checkout .checkout-content').slideUp('slow');

$('#payment-address .checkout-content').slideDown('slow');

$('#payment-address .checkout-heading span').html('<?php echo $text_checkout_payment_address; ?>');

$('.checkout-heading a').remove();
}
}
});
}
}
});
});

// Register
$('#button-register').live('click', function() {
$.ajax({
url: 'index.php?route=checkout/register',
type: 'post',
data: $('#payment-address input[type=\'text\'], #payment-address input[type=\'password\'], #payment-address input[type=\'checkbox\']:checked, #payment-address input[type=\'radio\']:checked, #payment-address select'),
dataType: 'json',
beforeSend: function() {
$('#button-register').attr('disabled', true);
$('#button-register').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#button-register').attr('disabled', false);
$('.wait').remove();
},
success: function(json) {
$('.warning').remove();
$('.error').remove();

if (json['redirect']) {
location = json['redirect'];
}

if (json['error']) {
if (json['error']['warning']) {
$('#payment-address .checkout-content').prepend('<div class="warning" style="display: none;">' + json['error']['warning'] + '</div>');

$('.warning').fadeIn('slow');
}

if (json['error']['firstname']) {
$('#payment-address input[name=\'firstname\'] + br').after('<span class="error">' + json['error']['firstname'] + '</span>');
}

if (json['error']['lastname']) {
$('#payment-address input[name=\'lastname\'] + br').after('<span class="error">' + json['error']['lastname'] + '</span>');
}

if (json['error']['email']) {
$('#payment-address input[name=\'email\'] + br').after('<span class="error">' + json['error']['email'] + '</span>');
}

if (json['error']['telephone']) {
$('#payment-address input[name=\'telephone\'] + br').after('<span class="error">' + json['error']['telephone'] + '</span>');
}

if (json['error']['address_1']) {
$('#payment-address input[name=\'address_1\'] + br').after('<span class="error">' + json['error']['address_1'] + '</span>');
}

if (json['error']['city']) {
$('#payment-address input[name=\'city\'] + br').after('<span class="error">' + json['error']['city'] + '</span>');
}

if (json['error']['postcode']) {
$('#payment-address input[name=\'postcode\'] + br').after('<span class="error">' + json['error']['postcode'] + '</span>');
}

if (json['error']['country']) {
$('#payment-address select[name=\'country_id\'] + br').after('<span class="error">' + json['error']['country'] + '</span>');
}

if (json['error']['zone']) {
$('#payment-address select[name=\'zone_id\'] + br').after('<span class="error">' + json['error']['zone'] + '</span>');
}

if (json['error']['password']) {
$('#payment-address input[name=\'password\'] + br').after('<span class="error">' + json['error']['password'] + '</span>');
}

if (json['error']['confirm']) {
$('#payment-address input[name=\'confirm\'] + br').after('<span class="error">' + json['error']['confirm'] + '</span>');
}
} else {
<?php if ($shipping_required) { ?>
var shipping_address = $('#payment-address input[name=\'shipping_address\']:checked').attr('value');

if (shipping_address) {
$.ajax({
url: 'index.php?route=checkout/shipping',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#shipping-method .checkout-content').html(json['output']);

$('#payment-address .checkout-content').slideUp('slow');

$('#shipping-method .checkout-content').slideDown('slow');

$('#checkout .checkout-heading a').remove();
$('#payment-address .checkout-heading a').remove();
$('#shipping-address .checkout-heading a').remove();
$('#shipping-method .checkout-heading a').remove();
$('#payment-method .checkout-heading a').remove();

$('#shipping-address .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
$('#payment-address .checkout-heading').append('<a><?php echo $text_modify; ?></a>');

$.ajax({
url: 'index.php?route=checkout/address/shipping',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#shipping-address .checkout-content').html(json['output']);
}
}
});
}
}
});
} else {
$.ajax({
url: 'index.php?route=checkout/address/shipping',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#shipping-address .checkout-content').html(json['output']);

$('#payment-address .checkout-content').slideUp('slow');

$('#shipping-address .checkout-content').slideDown('slow');

$('#checkout .checkout-heading a').remove();
$('#payment-address .checkout-heading a').remove();
$('#shipping-address .checkout-heading a').remove();
$('#shipping-method .checkout-heading a').remove();
$('#payment-method .checkout-heading a').remove();

$('#payment-address .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
}
}
});
}
<?php } else { ?>
$.ajax({
url: 'index.php?route=checkout/payment',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#payment-method .checkout-content').html(json['output']);

$('#payment-address .checkout-content').slideUp('slow');

$('#payment-method .checkout-content').slideDown('slow');

$('#checkout .checkout-heading a').remove();
$('#payment-address .checkout-heading a').remove();
$('#payment-method .checkout-heading a').remove();

$('#payment-address .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
}
}
});
<?php } ?>

$.ajax({
url: 'index.php?route=checkout/address/payment',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#payment-address .checkout-content').html(json['output']);

$('#payment-address .checkout-heading span').html('<?php echo $text_checkout_payment_address; ?>');
}
}
});
}
}
});
});

// Payment Address
$('#payment-address #button-address').live('click', function() {
$.ajax({
url: 'index.php?route=checkout/address/payment',
type: 'post',
data: $('#payment-address input[type=\'text\'], #payment-address input[type=\'password\'], #payment-address input[type=\'checkbox\']:checked, #payment-address input[type=\'radio\']:checked, #payment-address select'),
dataType: 'json',
beforeSend: function() {
$('#payment-address #button-address').attr('disabled', true);
$('#payment-address #button-address').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#payment-address #button-address').attr('disabled', false);
$('.wait').remove();
},
success: function(json) {
$('.error').remove();

if (json['redirect']) {
location = json['redirect'];
}

if (json['error']) {
if (json['error']['firstname']) {
$('#payment-address input[name=\'firstname\']').after('<span class="error">' + json['error']['firstname'] + '</span>');
}

if (json['error']['lastname']) {
$('#payment-address input[name=\'lastname\']').after('<span class="error">' + json['error']['lastname'] + '</span>');
}

if (json['error']['telephone']) {
$('#payment-address input[name=\'telephone\']').after('<span class="error">' + json['error']['telephone'] + '</span>');
}

if (json['error']['address_1']) {
$('#payment-address input[name=\'address_1\']').after('<span class="error">' + json['error']['address_1'] + '</span>');
}

if (json['error']['city']) {
$('#payment-address input[name=\'city\']').after('<span class="error">' + json['error']['city'] + '</span>');
}

if (json['error']['postcode']) {
$('#payment-address input[name=\'postcode\']').after('<span class="error">' + json['error']['postcode'] + '</span>');
}

if (json['error']['country']) {
$('#payment-address select[name=\'country_id\']').after('<span class="error">' + json['error']['country'] + '</span>');
}

if (json['error']['zone']) {
$('#payment-address select[name=\'zone_id\']').after('<span class="error">' + json['error']['zone'] + '</span>');
}
} else {
<?php if ($shipping_required) { ?>
$.ajax({
url: 'index.php?route=checkout/address/shipping',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#shipping-address .checkout-content').html(json['output']);

$('#payment-address .checkout-content').slideUp('slow');

$('#shipping-address .checkout-content').slideDown('slow');

$('#payment-address .checkout-heading a').remove();
$('#shipping-address .checkout-heading a').remove();
$('#shipping-method .checkout-heading a').remove();
$('#payment-method .checkout-heading a').remove();

$('#payment-address .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
}
}
});
<?php } else { ?>
$.ajax({
url: 'index.php?route=checkout/payment',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#payment-method .checkout-content').html(json['output']);

$('#payment-address .checkout-content').slideUp('slow');

$('#payment-method .checkout-content').slideDown('slow');

$('#payment-address .checkout-heading a').remove();
$('#payment-method .checkout-heading a').remove();

$('#payment-address .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
}
}
});
<?php } ?>

$.ajax({
url: 'index.php?route=checkout/address/payment',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#payment-address .checkout-content').html(json['output']);
}
}
});
}
}
});
});

// Shipping Address
$('#shipping-address #button-address').live('click', function() {
$.ajax({
url: 'index.php?route=checkout/address/shipping',
type: 'post',
data: $('#shipping-address input[type=\'text\'], #shipping-address input[type=\'password\'], #shipping-address input[type=\'checkbox\']:checked, #shipping-address input[type=\'radio\']:checked, #shipping-address select'),
dataType: 'json',
beforeSend: function() {
$('#shipping-address #button-address').attr('disabled', true);
$('#shipping-address #button-address').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#shipping-address #button-address').attr('disabled', false);
$('.wait').remove();
},
success: function(json) {
$('.error').remove();

if (json['redirect']) {
location = json['redirect'];
}

if (json['error']) {
if (json['error']['firstname']) {
$('#shipping-address input[name=\'firstname\']').after('<span class="error">' + json['error']['firstname'] + '</span>');
}

if (json['error']['lastname']) {
$('#shipping-address input[name=\'lastname\']').after('<span class="error">' + json['error']['lastname'] + '</span>');
}

if (json['error']['email']) {
$('#shipping-address input[name=\'email\']').after('<span class="error">' + json['error']['email'] + '</span>');
}

if (json['error']['telephone']) {
$('#shipping-address input[name=\'telephone\']').after('<span class="error">' + json['error']['telephone'] + '</span>');
}

if (json['error']['address_1']) {
$('#shipping-address input[name=\'address_1\']').after('<span class="error">' + json['error']['address_1'] + '</span>');
}

if (json['error']['city']) {
$('#shipping-address input[name=\'city\']').after('<span class="error">' + json['error']['city'] + '</span>');
}

if (json['error']['postcode']) {
$('#shipping-address input[name=\'postcode\']').after('<span class="error">' + json['error']['postcode'] + '</span>');
}

if (json['error']['country']) {
$('#shipping-address select[name=\'country_id\']').after('<span class="error">' + json['error']['country'] + '</span>');
}

if (json['error']['zone']) {
$('#shipping-address select[name=\'zone_id\']').after('<span class="error">' + json['error']['zone'] + '</span>');
}
} else {
$.ajax({
url: 'index.php?route=checkout/shipping',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#shipping-method .checkout-content').html(json['output']);

$('#shipping-address .checkout-content').slideUp('slow');

$('#shipping-method .checkout-content').slideDown('slow');

$('#shipping-address .checkout-heading a').remove();
$('#shipping-method .checkout-heading a').remove();
$('#payment-method .checkout-heading a').remove();

$('#shipping-address .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
}

$.ajax({
url: 'index.php?route=checkout/address/shipping',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#shipping-address .checkout-content').html(json['output']);
}
}
});
}
});
}
}
});
});

// Guest
$('#button-guest').live('click', function() {
$.ajax({
url: 'index.php?route=checkout/guest',
type: 'post',
data: $('#payment-address input[type=\'text\'], #payment-address input[type=\'checkbox\']:checked, #payment-address select'),
dataType: 'json',
beforeSend: function() {
$('#button-guest').attr('disabled', true);
$('#button-guest').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#button-guest').attr('disabled', false);
$('.wait').remove();
},
success: function(json) {
$('.error').remove();

if (json['redirect']) {
location = json['redirect'];
}

if (json['error']) {
if (json['error']['firstname']) {
$('#payment-address input[name=\'firstname\'] + br').after('<span class="error">' + json['error']['firstname'] + '</span>');
}

if (json['error']['lastname']) {
$('#payment-address input[name=\'lastname\'] + br').after('<span class="error">' + json['error']['lastname'] + '</span>');
}

if (json['error']['email']) {
$('#payment-address input[name=\'email\'] + br').after('<span class="error">' + json['error']['email'] + '</span>');
}

if (json['error']['telephone']) {
$('#payment-address input[name=\'telephone\'] + br').after('<span class="error">' + json['error']['telephone'] + '</span>');
}

if (json['error']['address_1']) {
$('#payment-address input[name=\'address_1\'] + br').after('<span class="error">' + json['error']['address_1'] + '</span>');
}

if (json['error']['city']) {
$('#payment-address input[name=\'city\'] + br').after('<span class="error">' + json['error']['city'] + '</span>');
}

if (json['error']['postcode']) {
$('#payment-address input[name=\'postcode\'] + br').after('<span class="error">' + json['error']['postcode'] + '</span>');
}

if (json['error']['country']) {
$('#payment-address select[name=\'country_id\'] + br').after('<span class="error">' + json['error']['country'] + '</span>');
}

if (json['error']['zone']) {
$('#payment-address select[name=\'zone_id\'] + br').after('<span class="error">' + json['error']['zone'] + '</span>');
}
} else {
<?php if ($shipping_required) { ?>
var shipping_address = $('#payment-address input[name=\'shipping_address\']:checked').attr('value');

if (shipping_address) {
$.ajax({
url: 'index.php?route=checkout/shipping',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#shipping-method .checkout-content').html(json['output']);

$('#payment-address .checkout-content').slideUp('slow');

$('#shipping-method .checkout-content').slideDown('slow');

$('#payment-address .checkout-heading a').remove();
$('#shipping-address .checkout-heading a').remove();
$('#shipping-method .checkout-heading a').remove();
$('#payment-method .checkout-heading a').remove();

$('#payment-address .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
$('#shipping-address .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
}

$.ajax({
url: 'index.php?route=checkout/guest/shipping',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#shipping-address .checkout-content').html(json['output']);
}
}
});
}
});
} else {
$.ajax({
url: 'index.php?route=checkout/guest/shipping',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#shipping-address .checkout-content').html(json['output']);

$('#payment-address .checkout-content').slideUp('slow');

$('#shipping-address .checkout-content').slideDown('slow');

$('#payment-address .checkout-heading a').remove();
$('#shipping-address .checkout-heading a').remove();
$('#shipping-method .checkout-heading a').remove();
$('#payment-method .checkout-heading a').remove();

$('#payment-address .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
}
}
});
}
<?php } else { ?>
$.ajax({
url: 'index.php?route=checkout/payment',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#payment-method .checkout-content').html(json['output']);

$('#payment-address .checkout-content').slideUp('slow');

$('#payment-method .checkout-content').slideDown('slow');

$('#payment-address .checkout-heading a').remove();
$('#payment-method .checkout-heading a').remove();

$('#payment-address .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
}
}
});
<?php } ?>
}
}
});
});

// Guest Shipping
$('#button-guest-shipping').live('click', function() {
$.ajax({
url: 'index.php?route=checkout/guest/shipping',
type: 'post',
data: $('#shipping-address input[type=\'text\'], #shipping-address select'),
dataType: 'json',
beforeSend: function() {
$('#button-guest-shipping').attr('disabled', true);
$('#button-guest-shipping').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#button-guest-shipping').attr('disabled', false);
$('.wait').remove();
},
success: function(json) {
$('.error').remove();

if (json['redirect']) {
location = json['redirect'];
}

if (json['error']) {
if (json['error']['firstname']) {
$('#shipping-address input[name=\'firstname\']').after('<span class="error">' + json['error']['firstname'] + '</span>');
}

if (json['error']['lastname']) {
$('#shipping-address input[name=\'lastname\']').after('<span class="error">' + json['error']['lastname'] + '</span>');
}

if (json['error']['address_1']) {
$('#shipping-address input[name=\'address_1\']').after('<span class="error">' + json['error']['address_1'] + '</span>');
}

if (json['error']['city']) {
$('#shipping-address input[name=\'city\']').after('<span class="error">' + json['error']['city'] + '</span>');
}

if (json['error']['postcode']) {
$('#shipping-address input[name=\'postcode\']').after('<span class="error">' + json['error']['postcode'] + '</span>');
}

if (json['error']['country']) {
$('#shipping-address select[name=\'country_id\']').after('<span class="error">' + json['error']['country'] + '</span>');
}

if (json['error']['zone']) {
$('#shipping-address select[name=\'zone_id\']').after('<span class="error">' + json['error']['zone'] + '</span>');
}
} else {
$.ajax({
url: 'index.php?route=checkout/shipping',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#shipping-method .checkout-content').html(json['output']);

$('#shipping-address .checkout-content').slideUp('slow');

$('#shipping-method .checkout-content').slideDown('slow');

$('#shipping-address .checkout-heading a').remove();
$('#shipping-method .checkout-heading a').remove();
$('#payment-method .checkout-heading a').remove();

$('#shipping-address .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
}
}
});
}
}
});
});

$('#button-shipping').live('click', function() {
$.ajax({
url: 'index.php?route=checkout/shipping',
type: 'post',
data: $('#shipping-method input[type=\'radio\']:checked, #shipping-method textarea'),
dataType: 'json',
beforeSend: function() {
$('#button-shipping').attr('disabled', true);
$('#button-shipping').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#button-shipping').attr('disabled', false);
$('.wait').remove();
},
success: function(json) {
$('.warning').remove();

if (json['redirect']) {
location = json['redirect'];
}

if (json['error']) {
if (json['error']['warning']) {
$('#shipping-method .checkout-content').prepend('<div class="warning" style="display: none;">' + json['error']['warning'] + '</div>');

$('.warning').fadeIn('slow');
}
} else {
$.ajax({
url: 'index.php?route=checkout/payment',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#payment-method .checkout-content').html(json['output']);

$('#shipping-method .checkout-content').slideUp('slow');

$('#payment-method .checkout-content').slideDown('slow');

$('#shipping-method .checkout-heading a').remove();
$('#payment-method .checkout-heading a').remove();

$('#shipping-method .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
});
}
}
});
});

$('#button-payment').live('click', function() {
$.ajax({
url: 'index.php?route=checkout/payment',
type: 'post',
data: $('#payment-method input[type=\'radio\']:checked, #payment-method input[type=\'checkbox\']:checked, #payment-method textarea'),
dataType: 'json',
beforeSend: function() {
$('#button-payment').attr('disabled', true);
$('#button-payment').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('#button-payment').attr('disabled', false);
$('.wait').remove();
},
success: function(json) {
$('.warning').remove();

if (json['redirect']) {
location = json['redirect'];
}

if (json['error']) {
if (json['error']['warning']) {
$('#payment-method .checkout-content').prepend('<div class="warning" style="display: none;">' + json['error']['warning'] + '</div>');

$('.warning').fadeIn('slow');
}
} else {
$.ajax({
url: 'index.php?route=checkout/confirm',
dataType: 'json',
success: function(json) {
if (json['redirect']) {
location = json['redirect'];
}

if (json['output']) {
$('#confirm .checkout-content').html(json['output']);

$('#payment-method .checkout-content').slideUp('slow');

$('#confirm .checkout-content').slideDown('slow');

$('#payment-method .checkout-heading a').remove();

$('#payment-method .checkout-heading').append('<a><?php echo $text_modify; ?></a>');
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
});
}
}
});
});
//--></script>
<?php echo $footer; ?>

No comments:

Post a Comment