Commit cd35381b by dhn

Merge branch 'developer' of http://47.99.244.21:9999/root/joshine into Branchs_developer

parents 123ef8b9 6ea330bc
<?php
namespace Joshine\GoogleFeed\Helper;
use \Magento\Framework\App\Helper\AbstractHelper;
class GAHelper extends AbstractHelper
{
public static function normalizeAndHash(string $hashAlgorithm, string $value): string
{
return hash($hashAlgorithm, strtolower(trim($value)));
}
public static function normalizeAndHashEmailAddress(
string $hashAlgorithm,
string $emailAddress
): string {
$normalizedEmail = strtolower($emailAddress);
$emailParts = explode("@", $normalizedEmail);
if (
count($emailParts) > 1
&& preg_match('/^(gmail|googlemail)\.com\s*/', $emailParts[1])
) {
$emailParts[0] = str_replace(".", "", $emailParts[0]);
$normalizedEmail = sprintf('%s@%s', $emailParts[0], $emailParts[1]);
}
return self::normalizeAndHash($hashAlgorithm, $normalizedEmail);
}
}
\ No newline at end of file
......@@ -4,25 +4,11 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
$lid = $block->getOrderId();
$totalPrice = 0;
$googleItems = [];
if ($lid) {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($lid);
if ($order) {
$totalPrice = $order->getGrandTotal();
$_itemsTmp = $order->getAllItems();
foreach ($_itemsTmp as $value) {
$_item['google_business_vertical'] = 'retail';
$_item['id'] = $value->getSku();
$googleItems[] = $_item;
}
}
}
$currency = $block->getCurrency();
$tracking_show = $block->getTrackingEnabled();
$tracking_conversion = $block->getTrackingConversion();
?>
<div class="checkout-success">
......@@ -72,18 +58,62 @@ $tracking_conversion = $block->getTrackingConversion();
</style>
<script>
dataLayer = [];
dataLayer.push({
'event': 'purchase',
'value': <?= $totalPrice ?>,
'items': <?= json_encode($googleItems, true) ?>
});
//window.dataLayer = window.dataLayer || [];
//dataLayer.push({
// 'event': 'purchase',
// 'value': <?php //= $totalPrice ?>//,
// 'items': <?php //= json_encode($googleItems, true) ?>
//});
<?php if ($block->getOrderId() && $tracking_show > 0 && !empty($tracking_conversion)) :?>
gtag('event', 'conversion', {
'send_to': '<?= /* @noEscape */ $tracking_conversion ?>',
'value': <?= /* @noEscape */ $totalPrice ?>,
'currency': '<?= /* @noEscape */ $currency ?>',
'transaction_id': '<?= /* @noEscape */ $block->getOrderId() ?>'
});
<?php
$lid = $block->getOrderId();
$totalPrice = 0;
$googleItems = [];
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
if ($lid) {
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($lid);
if ($order) {
$totalPrice = $order->getGrandTotal();
$_itemsTmp = $order->getAllVisibleItems();
foreach ($_itemsTmp as $value) {
$_item['google_business_vertical'] = 'retail';
$_item['id'] = $value->getSku();
$_item['item_name'] = $value->getName();
$_item['quantity'] = intval($value->getQtyOrdered());
$googleItems[] = $_item;
}
$email = $order->getCustomerEmail();
}
}
$helper = $objectManager->get('Joshine\GoogleFeed\Helper\GAHelper');
?>
setTimeout(function () {
<?php if (isset($email) && !empty($email)) :?>
gtag('set' , 'user_data' , {
"sha256_email_address" : '<?= $helper::normalizeAndHashEmailAddress("sha256", $email); ?>'
});
<?php endif; ?>
gtag('event', 'conversion', {
'send_to': '<?= /* @noEscape */ $tracking_conversion ?>',
'value': '<?= /* @noEscape */ $totalPrice ?>',
'currency': '<?= /* @noEscape */ $currency ?>',
'transaction_id': '<?= /* @noEscape */ $block->getOrderId() ?>'
});
gtag('event', 'purchase', {
"transaction_id": '<?= /* @noEscape */ $block->getOrderId() ?>',
"value": '<?= /* @noEscape */ $totalPrice ?>',
"currency": '<?= /* @noEscape */ $currency ?>',
"items": <?= json_encode($googleItems, true); ?>
});
}, 1500);
<?php endif;?>
</script>
......@@ -543,34 +543,28 @@ define([
if (!this.hasOwnProperty('products') || this.products.length <= 0) {
attr += ' data-option-empty="true"';
}
var selectedStr = '';
if(index == 0)
{
selectedStr = ' selected';
}
if (type === 0) {
// Text
html += '<div class="' + optionClass + ' text' + selectedStr + '" ' + attr + '>' + (value ? value : label) +
html += '<div class="' + optionClass + ' text' + '" ' + attr + '>' + (value ? value : label) +
'</div>';
} else if (type === 1) {
// Color
html += '<div class="' + optionClass + ' color' + selectedStr + '" ' + attr +
html += '<div class="' + optionClass + ' color' + '" ' + attr +
' style="background: ' + value +
' no-repeat center; background-size: cover;">' + '' +
'</div>';
} else if (type === 2) {
// Image
html += '<div class="' + optionClass + ' image' + selectedStr + '" ' + attr +
html += '<div class="' + optionClass + ' image' + '" ' + attr +
' style="background: url(' + value + ') no-repeat center; background-size: cover;width:' +
swatchImageWidth + 'px; height:' + swatchImageHeight + 'px">' + '' +
'</div>';
} else if (type === 3) {
// Clear
html += '<div class="' + optionClass + selectedStr + '" ' + attr + '></div>';
html += '<div class="' + optionClass + '" ' + attr + '></div>';
} else {
// Default
html += '<div class="' + optionClass + selectedStr + '" ' + attr + '>' + label + '</div>';
html += '<div class="' + optionClass + '" ' + attr + '>' + label + '</div>';
}
});
......@@ -800,34 +794,30 @@ define([
if (!this.hasOwnProperty('products') || this.products.length <= 0) {
attr += ' data-option-empty="true"';
}
var selectedStr = '';
if(index == 0)
{
selectedStr = ' selected';
}
if (type === 0) {
// Text
html += '<div class="' + optionClass + ' text' + selectedStr + '" ' + attr + '>' + (value ? value : label) +
html += '<div class="' + optionClass + ' text' + '" ' + attr + '>' + (value ? value : label) +
'</div>';
} else if (type === 1) {
// Color
html += '<div class="' + optionClass + ' color' + selectedStr + '" ' + attr +
html += '<div class="' + optionClass + ' color' + '" ' + attr +
' style="background: ' + value +
' no-repeat center; background-size: cover;">' + '' +
'</div>';
} else if (type === 2) {
// Image
html += '<div class="' + optionClass + ' image' + selectedStr + '" ' + attr +
html += '<div class="' + optionClass + ' image' + '" ' + attr +
' style="background: url(' + value + ') no-repeat center; background-size: cover;width:' +
swatchImageWidth + 'px; height:' + swatchImageHeight + 'px">' + '' +
'</div>';
} else if (type === 3) {
// Clear
html += '<div class="' + optionClass + selectedStr + '" ' + attr + '></div>';
html += '<div class="' + optionClass + '" ' + attr + '></div>';
} else {
// Default
html += '<div class="' + optionClass + selectedStr + '" ' + attr + '>' + label + '</div>';
html += '<div class="' + optionClass + '" ' + attr + '>' + label + '</div>';
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment