Back to PhocacartRenderJs class

Method renderJsAddTrackingCode

public static
renderJsAddTrackingCode
(mixed $idSource, mixed $classDestination)
Shipping tracking code - add automatically tracking number to tracking link in edit of order - to see the link (while typing the id)
Parameters
  • string $idSource
  • string $classDestination

Method renderJsAddTrackingCode - Source code

/**
 * Shipping tracking code - add automatically tracking number to tracking link in edit of order - to see the link (while typing the id)
 * @param string $idSource
 * @param string $classDestination
 */
public static function renderJsAddTrackingCode($idSource, $classDestination)
{
    $s = array();
    $s[] = 'jQuery(document).ready(function() {';
    $s[] = '   var destGlobal 	= jQuery( \'.' . $classDestination . '\').text();';
    $s[] = '   var sourceGlobal	= jQuery(\'#' . $idSource . '\').val();';
    $s[] = '   var textGlobal 	= destGlobal + sourceGlobal';
    $s[] = '   jQuery( \'.' . $classDestination . '\').html(textGlobal);';
    $s[] = '   jQuery(\'#' . $idSource . '\').on("input", function() {';
    $s[] = '       var source	= jQuery(this).val();';
    $s[] = '       var text = destGlobal + source;';
    $s[] = '       jQuery( \'.' . $classDestination . '\').html(text);';
    $s[] = '   })';
    $s[] = '})';
    Factory::getDocument()->addScriptDeclaration(implode("\n", $s));
}