opencart将脚本添加到checkout.php

opencart将脚本添加到checkout.php,opencart,Opencart,我正在使用opencart作为我的在线商店的平台,我必须在提交订单的页面上添加一个脚本,我不知道如何操作,也不知道需要使用什么文件 以下是脚本: <?php /******************************************************************************* * Pazaruvaj.com trusted shop program * Example code integration to the webshop *

我正在使用opencart作为我的在线商店的平台,我必须在提交订单的页面上添加一个脚本,我不知道如何操作,也不知道需要使用什么文件

以下是脚本:

<?php

/*******************************************************************************
 * Pazaruvaj.com trusted shop program
 * Example code integration to the webshop
 * 
 *
 * Please note, that the example detailed below can not be simply copy-pasted
 * into your webshop’s code, it has to be customized adequately.
 *
 * Setup steps:
 * 1. Copy TrustedShop.php file to a place accessible by the webshop engine.
 * 2. Copy this example code to the page of the webshop where the e-mail address
 *    of the customer and the names of the purchased products are retrievable
 *    from the webshop engine. Generally this is the webshop’s confirmation
 *    page of the purchase.
 * 3. Customize the pasted example code according to the following:
 *    - Modify path of TrustedShop.php in require_once() in such a way that
 *      the webshop engine can use it.
 *    - Check that the proper WebAPI key is set, if not, modify it. You can find
 *      the WebAPI key on the partner portal.
 *    - Set the customer’s e-mail address.
 *    - Add the names of the purchased products.
 *    - Implement an error handling if you want (optional).
 *
 ******************************************************************************/

require_once 'TrustedShop.php';

try {

  // Provide your own WebAPI key.
  // You can find your WebAPI key on your partner portal.

  $Client = new TrustedShop('4eee39583f06aab1460277f41be9e0e7');

  // Provide the e-mail address of your customer.
  // You can retrieve the e-amil address from the webshop engine.

  $Client->SetEmail($data['email']);

  // Provide the name of the purchased products.
  // You can get the name of the products from the webshop engine.
  // The AddProduct method must be called for each of the purchased products.
  // 
  // It is optional to provide the name of the products, so if this data is not
  // available, you can leave out the AddProduct calls.

  $Client->AddProduct('Name of first purchased product');
  $Client->AddProduct('Name of second purchased product');

  // This method sends us the e-mail address and the name of the purchased
  // products set above. After the data arrived to us, we store them
  // with the time stamp and the WebAPI key.
  // This lets us know that someone has purchased at your webshop, to whom
  // we later have to send the questionnaire for evaluating your shop.
  // The "Send()" operation doesn't send immediately. It generates a HTML output, 
  // puts into source of the page and the customer's browser will send the 
  // required informations us.

  $Client->Send();

} catch (Exception $Ex) {

  // Here you can implement error handling. The error message can be obtained
  // in the manner shown below. Implementing error handling is optional.

  $ErrorMessage = $Ex->getMessage();
}

?>

and this is the included ThrustedShop.php 

<?php

class TrustedShop {

  const ServiceHost = 'www.pazaruvaj.com';

  const ServiceUrl = '/affiliation/TrustedShop.php';

  const ErrorEmail = 'Ne ste zadali email adres na klienta Vi.';

  const ErrorService = 'Zapazvaneto na dannite na klienta e neuspeshno.';

  private $WebApiKey;

  private $Email;

  private $Products = array();

  private $Protocol;

  public function __construct($WebApiKey) {
    $this->WebApiKey = $WebApiKey;
    $this->Protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https' : 'http';
  }

  public function SetEmail($Email) {
    $this->Email = $Email;
  }

  public function AddProduct($ProductName) {
    $this->Products[] = $ProductName;
  }

  public function Send() {
    if (empty($this->Email)) {
      throw new Exception(self::ErrorEmail);
    }

    $String = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    $C = '';
    for ($i = 0; $i < 20; $i++) {
      $C .= $String{mt_rand(0, strlen($String) - 1)};
    }

    $Timestamp = time();
    $HashedKey = md5($this->WebApiKey . $Timestamp);

    $Query = 'HashedKey=' . $HashedKey . '&Email=' . urlencode($this->Email);
    foreach ($this->Products as $ProductName) {
      $Query .= '&Products[]=' . urlencode($ProductName);
    }
    $Query .= '&Timestamp=' . $Timestamp;

    echo '<script type="text/javascript" src="' . $this->Protocol . '://' . self::ServiceHost . '/fc.js"></script>';
    echo
      '<script type="text/javascript">',
      'function fc_request_done(C) { var I = new Image(); I.src=\'' . $this->Protocol . '://' . self::ServiceHost . self::ServiceUrl . "?" . $Query . '&C=\'+C; }',
      'set_fc("' . self::ServiceHost . '", "__aku","' . $C . '");',
      '</script>';

    echo
      '<noscript>',
      '<img src="' . $this->Protocol . '://' . self::ServiceHost . self::ServiceUrl . "?" . $Query . '&C=' . $C . '">',
      '</noscript>';
  }
}

?>
require_once 'TrustedShop.php'; // make sure the path is correct here!
$Client = new TrustedShop('4eee39583f06aab1460277f41be9e0e7');
$Client->SetEmail($order_info['email']);
try {
    $Client->Send();
} catch(Exception $e) {
    $this->log->write($e->getMessage());
}

这是包含的structedshop.php

您必须将脚本(并相应地修改它)放入
目录/model/checkout/order.php
-方法
确认()

此方法用于保存订单数据,并将订单设置为已确认(或已付款),并向客户和管理员发送电子邮件(可选)。在这种方法中,可以访问客户的电子邮件地址和产品(及其名称),以满足脚本的要求

确认()

foreach ($order_product_query->rows as $product) {
之前添加脚本的开头:

<?php

/*******************************************************************************
 * Pazaruvaj.com trusted shop program
 * Example code integration to the webshop
 * 
 *
 * Please note, that the example detailed below can not be simply copy-pasted
 * into your webshop’s code, it has to be customized adequately.
 *
 * Setup steps:
 * 1. Copy TrustedShop.php file to a place accessible by the webshop engine.
 * 2. Copy this example code to the page of the webshop where the e-mail address
 *    of the customer and the names of the purchased products are retrievable
 *    from the webshop engine. Generally this is the webshop’s confirmation
 *    page of the purchase.
 * 3. Customize the pasted example code according to the following:
 *    - Modify path of TrustedShop.php in require_once() in such a way that
 *      the webshop engine can use it.
 *    - Check that the proper WebAPI key is set, if not, modify it. You can find
 *      the WebAPI key on the partner portal.
 *    - Set the customer’s e-mail address.
 *    - Add the names of the purchased products.
 *    - Implement an error handling if you want (optional).
 *
 ******************************************************************************/

require_once 'TrustedShop.php';

try {

  // Provide your own WebAPI key.
  // You can find your WebAPI key on your partner portal.

  $Client = new TrustedShop('4eee39583f06aab1460277f41be9e0e7');

  // Provide the e-mail address of your customer.
  // You can retrieve the e-amil address from the webshop engine.

  $Client->SetEmail($data['email']);

  // Provide the name of the purchased products.
  // You can get the name of the products from the webshop engine.
  // The AddProduct method must be called for each of the purchased products.
  // 
  // It is optional to provide the name of the products, so if this data is not
  // available, you can leave out the AddProduct calls.

  $Client->AddProduct('Name of first purchased product');
  $Client->AddProduct('Name of second purchased product');

  // This method sends us the e-mail address and the name of the purchased
  // products set above. After the data arrived to us, we store them
  // with the time stamp and the WebAPI key.
  // This lets us know that someone has purchased at your webshop, to whom
  // we later have to send the questionnaire for evaluating your shop.
  // The "Send()" operation doesn't send immediately. It generates a HTML output, 
  // puts into source of the page and the customer's browser will send the 
  // required informations us.

  $Client->Send();

} catch (Exception $Ex) {

  // Here you can implement error handling. The error message can be obtained
  // in the manner shown below. Implementing error handling is optional.

  $ErrorMessage = $Ex->getMessage();
}

?>

and this is the included ThrustedShop.php 

<?php

class TrustedShop {

  const ServiceHost = 'www.pazaruvaj.com';

  const ServiceUrl = '/affiliation/TrustedShop.php';

  const ErrorEmail = 'Ne ste zadali email adres na klienta Vi.';

  const ErrorService = 'Zapazvaneto na dannite na klienta e neuspeshno.';

  private $WebApiKey;

  private $Email;

  private $Products = array();

  private $Protocol;

  public function __construct($WebApiKey) {
    $this->WebApiKey = $WebApiKey;
    $this->Protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https' : 'http';
  }

  public function SetEmail($Email) {
    $this->Email = $Email;
  }

  public function AddProduct($ProductName) {
    $this->Products[] = $ProductName;
  }

  public function Send() {
    if (empty($this->Email)) {
      throw new Exception(self::ErrorEmail);
    }

    $String = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    $C = '';
    for ($i = 0; $i < 20; $i++) {
      $C .= $String{mt_rand(0, strlen($String) - 1)};
    }

    $Timestamp = time();
    $HashedKey = md5($this->WebApiKey . $Timestamp);

    $Query = 'HashedKey=' . $HashedKey . '&Email=' . urlencode($this->Email);
    foreach ($this->Products as $ProductName) {
      $Query .= '&Products[]=' . urlencode($ProductName);
    }
    $Query .= '&Timestamp=' . $Timestamp;

    echo '<script type="text/javascript" src="' . $this->Protocol . '://' . self::ServiceHost . '/fc.js"></script>';
    echo
      '<script type="text/javascript">',
      'function fc_request_done(C) { var I = new Image(); I.src=\'' . $this->Protocol . '://' . self::ServiceHost . self::ServiceUrl . "?" . $Query . '&C=\'+C; }',
      'set_fc("' . self::ServiceHost . '", "__aku","' . $C . '");',
      '</script>';

    echo
      '<noscript>',
      '<img src="' . $this->Protocol . '://' . self::ServiceHost . self::ServiceUrl . "?" . $Query . '&C=' . $C . '">',
      '</noscript>';
  }
}

?>
require_once 'TrustedShop.php'; // make sure the path is correct here!
$Client = new TrustedShop('4eee39583f06aab1460277f41be9e0e7');
$Client->SetEmail($order_info['email']);
try {
    $Client->Send();
} catch(Exception $e) {
    $this->log->write($e->getMessage());
}
现在在该
foreach
行之后添加以下内容:

$Client->AddProduct($product['name']);
现在,在带有注释的行前面的
confirm()
结尾处添加脚本的最后一部分:

<?php

/*******************************************************************************
 * Pazaruvaj.com trusted shop program
 * Example code integration to the webshop
 * 
 *
 * Please note, that the example detailed below can not be simply copy-pasted
 * into your webshop’s code, it has to be customized adequately.
 *
 * Setup steps:
 * 1. Copy TrustedShop.php file to a place accessible by the webshop engine.
 * 2. Copy this example code to the page of the webshop where the e-mail address
 *    of the customer and the names of the purchased products are retrievable
 *    from the webshop engine. Generally this is the webshop’s confirmation
 *    page of the purchase.
 * 3. Customize the pasted example code according to the following:
 *    - Modify path of TrustedShop.php in require_once() in such a way that
 *      the webshop engine can use it.
 *    - Check that the proper WebAPI key is set, if not, modify it. You can find
 *      the WebAPI key on the partner portal.
 *    - Set the customer’s e-mail address.
 *    - Add the names of the purchased products.
 *    - Implement an error handling if you want (optional).
 *
 ******************************************************************************/

require_once 'TrustedShop.php';

try {

  // Provide your own WebAPI key.
  // You can find your WebAPI key on your partner portal.

  $Client = new TrustedShop('4eee39583f06aab1460277f41be9e0e7');

  // Provide the e-mail address of your customer.
  // You can retrieve the e-amil address from the webshop engine.

  $Client->SetEmail($data['email']);

  // Provide the name of the purchased products.
  // You can get the name of the products from the webshop engine.
  // The AddProduct method must be called for each of the purchased products.
  // 
  // It is optional to provide the name of the products, so if this data is not
  // available, you can leave out the AddProduct calls.

  $Client->AddProduct('Name of first purchased product');
  $Client->AddProduct('Name of second purchased product');

  // This method sends us the e-mail address and the name of the purchased
  // products set above. After the data arrived to us, we store them
  // with the time stamp and the WebAPI key.
  // This lets us know that someone has purchased at your webshop, to whom
  // we later have to send the questionnaire for evaluating your shop.
  // The "Send()" operation doesn't send immediately. It generates a HTML output, 
  // puts into source of the page and the customer's browser will send the 
  // required informations us.

  $Client->Send();

} catch (Exception $Ex) {

  // Here you can implement error handling. The error message can be obtained
  // in the manner shown below. Implementing error handling is optional.

  $ErrorMessage = $Ex->getMessage();
}

?>

and this is the included ThrustedShop.php 

<?php

class TrustedShop {

  const ServiceHost = 'www.pazaruvaj.com';

  const ServiceUrl = '/affiliation/TrustedShop.php';

  const ErrorEmail = 'Ne ste zadali email adres na klienta Vi.';

  const ErrorService = 'Zapazvaneto na dannite na klienta e neuspeshno.';

  private $WebApiKey;

  private $Email;

  private $Products = array();

  private $Protocol;

  public function __construct($WebApiKey) {
    $this->WebApiKey = $WebApiKey;
    $this->Protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https' : 'http';
  }

  public function SetEmail($Email) {
    $this->Email = $Email;
  }

  public function AddProduct($ProductName) {
    $this->Products[] = $ProductName;
  }

  public function Send() {
    if (empty($this->Email)) {
      throw new Exception(self::ErrorEmail);
    }

    $String = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    $C = '';
    for ($i = 0; $i < 20; $i++) {
      $C .= $String{mt_rand(0, strlen($String) - 1)};
    }

    $Timestamp = time();
    $HashedKey = md5($this->WebApiKey . $Timestamp);

    $Query = 'HashedKey=' . $HashedKey . '&Email=' . urlencode($this->Email);
    foreach ($this->Products as $ProductName) {
      $Query .= '&Products[]=' . urlencode($ProductName);
    }
    $Query .= '&Timestamp=' . $Timestamp;

    echo '<script type="text/javascript" src="' . $this->Protocol . '://' . self::ServiceHost . '/fc.js"></script>';
    echo
      '<script type="text/javascript">',
      'function fc_request_done(C) { var I = new Image(); I.src=\'' . $this->Protocol . '://' . self::ServiceHost . self::ServiceUrl . "?" . $Query . '&C=\'+C; }',
      'set_fc("' . self::ServiceHost . '", "__aku","' . $C . '");',
      '</script>';

    echo
      '<noscript>',
      '<img src="' . $this->Protocol . '://' . self::ServiceHost . self::ServiceUrl . "?" . $Query . '&C=' . $C . '">',
      '</noscript>';
  }
}

?>
require_once 'TrustedShop.php'; // make sure the path is correct here!
$Client = new TrustedShop('4eee39583f06aab1460277f41be9e0e7');
$Client->SetEmail($order_info['email']);
try {
    $Client->Send();
} catch(Exception $e) {
    $this->log->write($e->getMessage());
}
应该是这样的