Created
August 25, 2015 09:45
-
-
Save iBasit/a1f3909ddd943876162c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
var _bsw = _bsw || []; | |
_bsw.push(['_bswId', '4d127e6d5d74be0e70b15e482e1cdda738cd157eb6a556d11fa1482bb14f6221']); | |
(function() { | |
var bsw = document.createElement('script'); bsw.type = 'text/javascript'; bsw.async = true; | |
bsw.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'js.bronto.com/s/b.min.js'; | |
var t = document.getElementsByTagName('script')[0]; t.parentNode.insertBefore(bsw, t); | |
})(); | |
</script> | |
<?php | |
/** | |
* bronto abandon cart function | |
*/ | |
function bronto_cart () | |
{ | |
global $cart, $currencies, $order, $orders; | |
$bronto_products = array(); | |
if (isset($cart) && $cart->count_contents() > 0) | |
{ | |
$products = $cart->get_products(); | |
$grand_total = $cart->show_total(); | |
$subtotal = 0; | |
$tax_amount = 0; //tep_get_tax_rate($products[0]['tax_class_id']); | |
$order_id = 0; | |
for ($i = 0, $n = sizeof($products); $i < $n; $i++) | |
{ | |
$id = substr($products[$i]['id'], 0, stripos($products[$i]['id'], '{')); | |
$str = strtolower(trim($products[$i]['name'])); | |
$str = preg_replace('/[^a-z0-9-]/', '-', $str); | |
$name = preg_replace('/-+/', "-", $str); | |
$products_link = 'http://everything5pounds.com/' . $name . '-p-' . $id . '.html'; | |
$bronto_products[] = '{ | |
"other": null, | |
"imageUrl": "http://everything5pounds.com/' . tep_image_link(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], CART_IMAGE_WIDTH, CART_IMAGE_HEIGHT, '') . '", | |
"unitPrice": ' . $currencies->calculate_price($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id'])) . ', | |
"sku": ' . str_ireplace(array('{3}','{2}','{1}'), '-', $products[$i]['id']) . ', | |
"category": null, | |
"description": null, | |
"productUrl": "' . $products_link . '", | |
"name": "' . $products[$i]['name'] . '", | |
"quantity": ' . $products[$i]['quantity'] . ', | |
"salePrice": 0, | |
"totalPrice": ' . number_format((float)$currencies->calculate_price($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']), 2, '.', '') . ' | |
}'; | |
} | |
} | |
else if (isset($order) && isset($orders) && !empty($orders['orders_id'])) | |
{ | |
$products = $order->products; | |
$grand_total = $order->info['display_total']; | |
$subtotal = 0; | |
$tax_amount = 0; //tep_get_tax_rate(1); | |
$order_id = $orders['orders_id']; | |
for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) | |
{ | |
$id = substr($products[$i]['id'], 0, stripos($products[$i]['id'], '{')); | |
$str = strtolower(trim($products[$i]['name'])); | |
$str = preg_replace('/[^a-z0-9-]/', '-', $str); | |
$name = preg_replace('/-+/', "-", $str); | |
$products_link = 'http://everything5pounds.com/' . $name . '-p-' . $products[$i]['id'] . '.html'; | |
$bronto_products[] = '{ | |
"other": null, | |
"imageUrl": "http://everything5pounds.com/' . tep_image_link(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], CART_IMAGE_WIDTH, CART_IMAGE_HEIGHT, '') . '", | |
"unitPrice": ' . $currencies->calculate_price($products[$i]['final_price'], tep_get_tax_rate(1)) . ', | |
"sku": ' . str_ireplace(array('{3}','{2}','{1}'), '-', $products[$i]['id']) . ', | |
"category": null, | |
"description": null, | |
"productUrl": "' . $products_link . '", | |
"name": "' . $products[$i]['name'] . '", | |
"quantity": ' . $products[$i]['qty'] . ', | |
"salePrice": 0, | |
"totalPrice": ' . number_format((float)$currencies->calculate_price($products[$i]['final_price'], tep_get_tax_rate(1), $products[$i]['qty']), 2, '.', '') . ' | |
}'; | |
} | |
} | |
if (!empty($bronto_products)) | |
{ | |
?> | |
<script> | |
var jsonCart = { | |
"customerCartId": "", | |
"url": "http://everything5pounds.com/shopping_cart.php", | |
"grandTotal": <?php echo number_format((float)$grand_total, 2, '.', ''); ?>, | |
"subtotal": <?php echo number_format((float)$subtotal, 2, '.', ''); ?>, | |
"discountAmount": 0, | |
"taxAmount": <?php echo number_format((float)$tax_amount, 2, '.', ''); ?>, | |
"currency": "GBP", | |
"order_id": <?php echo $order_id; ?>, | |
"lineItems": [ | |
<?php echo implode(',', $bronto_products); ?> | |
] | |
} | |
</script> | |
<?php | |
} | |
} | |
?> | |
<!-- /Bronto Abandon Cart --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment