将Opencart标头拉到wordpress

时间:2015-03-30 18:20:10

标签: php wordpress opencart

我正在尝试将opencart标头转换为wordpress。 Opencart安装在“store”文件夹中的wordpress目录中。在一些帮助下,我可以将opencart页面转换为wordpress。下面的代码保存为headerX.php,并在page.php中使用wordpress调用。这将整个页面拉入wordpress主页。现在一切都很好,除了$response->output();将包含产品的整个opencart页面放到主页面中。

如何只将页眉和页脚放入wordpress并忽略(或不包括)之间的内容?

感谢您的帮助。

<?php

// Configuration
if (file_exists('store/config.php')) {
    require_once('store/config.php');
}  

// VirtualQMOD
require_once('store/vqmod/vqmod.php');
VQMod::bootup();

// VQMODDED Startup
require_once(VQMod::modCheck(DIR_SYSTEM . 'startup.php'));

// Application Classes
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/customer.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/affiliate.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/currency.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/tax.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/weight.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/length.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/cart.php'));

// Registry
$registry = new Registry();

// Loader
$loader = new Loader($registry);
$registry->set('load', $loader);

// Config
$config = new Config();
$registry->set('config', $config);

// Database 
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);

// Store
if (isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1'))) {
    $store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`ssl`, 'www.', '') = '" . $db->escape('https://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
} else {
    $store_query = $db->query("SELECT * FROM " . DB_PREFIX . "store WHERE REPLACE(`url`, 'www.', '') = '" . $db->escape('http://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/') . "'");
}

if ($store_query->num_rows) {
    $config->set('config_store_id', $store_query->row['store_id']);
} else {
    $config->set('config_store_id', 0);
}

// Settings
$query = $db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '0' OR store_id = '" . (int)$config->get('config_store_id') . "' ORDER BY store_id ASC");

foreach ($query->rows as $setting) {
    if (!$setting['serialized']) {
        $config->set($setting['key'], $setting['value']);
    } else {
        $config->set($setting['key'], unserialize($setting['value']));
    }
}

if (!$store_query->num_rows) {
    $config->set('config_url', HTTP_SERVER);
    $config->set('config_ssl', HTTPS_SERVER);   
}

// Url
$url = new Url($config->get('config_url'), $config->get('config_secure') ? $config->get('config_ssl') : $config->get('config_url'));    
$registry->set('url', $url);

// Log 
$log = new Log($config->get('config_error_filename'));
$registry->set('log', $log);

function error_handler($errno, $errstr, $errfile, $errline) {
    global $log, $config;

    switch ($errno) {
        case E_NOTICE:
        case E_USER_NOTICE:
            $error = 'Notice';
            break;
        case E_WARNING:
        case E_USER_WARNING:
            $error = 'Warning';
            break;
        case E_ERROR:
        case E_USER_ERROR:
            $error = 'Fatal Error';
            break;
        default:
            $error = 'Unknown';
            break;
    }

    if ($config->get('config_error_display')) {
        echo '<b>' . $error . '</b>: ' . $errstr . ' in <b>' . $errfile . '</b> on line <b>' . $errline . '</b>';
    }

    if ($config->get('config_error_log')) {
        $log->write('PHP ' . $error . ':  ' . $errstr . ' in ' . $errfile . ' on line ' . $errline);
    }

    return true;
}

// Error Handler
set_error_handler('error_handler');

// Request
$request = new Request();
$registry->set('request', $request);

// Response
$response = new Response();
$response->addHeader('Content-Type: text/html; charset=utf-8');
$response->setCompression($config->get('config_compression'));
$registry->set('response', $response); 

// Cache
$cache = new Cache();
$registry->set('cache', $cache); 

// Session
$session = new Session();
$registry->set('session', $session);

// Language Detection
$languages = array();

$query = $db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE status = '1'"); 

foreach ($query->rows as $result) {
    $languages[$result['code']] = $result;
}

$detect = '';

if (isset($request->server['HTTP_ACCEPT_LANGUAGE']) && $request->server['HTTP_ACCEPT_LANGUAGE']) { 
    $browser_languages = explode(',', $request->server['HTTP_ACCEPT_LANGUAGE']);

    foreach ($browser_languages as $browser_language) {
        foreach ($languages as $key => $value) {
            if ($value['status']) {
                $locale = explode(',', $value['locale']);

                if (in_array($browser_language, $locale)) {
                    $detect = $key;
                }
            }
        }
    }
}

if (isset($session->data['language']) && array_key_exists($session->data['language'], $languages) && $languages[$session->data['language']]['status']) {
    $code = $session->data['language'];
} elseif (isset($request->cookie['language']) && array_key_exists($request->cookie['language'], $languages) && $languages[$request->cookie['language']]['status']) {
   $code = $session->data['language'];
} elseif (isset($request->cookie['language']) && array_key_exists($request->cookie['language'], $languages)) {
    $code = $request->cookie['language'];
} elseif ($detect) {
    $code = $detect;
} else {
    $code = $config->get('config_language');
}

if (!isset($session->data['language']) || $session->data['language'] != $code) {
    $session->data['language'] = $code;
}

if (!isset($request->cookie['language']) || $request->cookie['language'] != $code) {      
    setcookie('language', $code, time() + 60 * 60 * 24 * 30, '/', $request->server['HTTP_HOST']);
}           

$config->set('config_language_id', $languages[$code]['language_id']);
$config->set('config_language', $languages[$code]['code']);

// Language 
$language = new Language($languages[$code]['directory']);
$language->load($languages[$code]['filename']); 
$registry->set('language', $language); 

// Document
$document = new Document();
$registry->set('document', new Document());         

// Customer
$registry->set('customer', new Customer($registry));

// Affiliate
$registry->set('affiliate', new Affiliate($registry));

if (isset($request->get['tracking'])) {
    setcookie('tracking', $request->get['tracking'], time() + 3600 * 24 * 1000, '/');
}

// Currency
$registry->set('currency', new Currency($registry));

// Tax
$registry->set('tax', new Tax($registry));

// Weight
$registry->set('weight', new Weight($registry));

// Length
$registry->set('length', new Length($registry));

// Cart
$registry->set('cart', new Cart($registry));

//OpenBay Pro
$registry->set('openbay', new Openbay($registry));

// Encryption
$registry->set('encryption', new Encryption($config->get('config_encryption')));

// Front Controller 
$controller = new Front($registry);

// Maintenance Mode
$controller->addPreAction(new Action('common/maintenance'));

// SEO URL's
$controller->addPreAction(new Action('common/seo_url'));    

// Router
if (isset($request->get['route'])) {
    $action = new Action($request->get['route']);
} else {
    $action = new Action('common/home');
}

// Dispatch
$controller->dispatch($action, new Action('error/not_found'));

// Output
$response->output();
?>

2 个答案:

答案 0 :(得分:0)

有许多方法可以做到这一点,这也是很多人都在寻找的常见功能;您可以在互联网上找到大量与wordpress解决方案集成的开放式购物车。很好,这很常见。

您是否尝试过使用opencart插件进行wordpress?

Wordpress或Opencart,所有这些系统都有单独的页眉和页脚包含,您可以在其他系统上调用;您需要包含所有必需的文件才能成功包含它。

我发现这篇文章很有用:https://wordpress.org/support/topic/opencart-wordpress-integration

您可以尝试以下操作并试一试。 (确保您修复了正确的路径)

<强> 1。使用以下代码创建文件headerX.php并将其保存到主站点的根目录(或您在OC商店之外选择的其他位置)。

<?php
// Config
require_once('shop/config.php');

// VirtualQMOD
require_once('shop/vqmod/vqmod.php');
$vqmod = new VQMod();

// VQMODDED Startup
require_once($vqmod->modCheck(DIR_SYSTEM . 'startup.php'));

// Application Classes
require_once($vqmod->modCheck(DIR_SYSTEM . 'library/customer.php'));
require_once($vqmod->modCheck(DIR_SYSTEM . 'library/affiliate.php'));
require_once($vqmod->modCheck(DIR_SYSTEM . 'library/currency.php'));
require_once($vqmod->modCheck(DIR_SYSTEM . 'library/tax.php'));
require_once($vqmod->modCheck(DIR_SYSTEM . 'library/weight.php'));
require_once($vqmod->modCheck(DIR_SYSTEM . 'library/length.php'));
require_once($vqmod->modCheck(DIR_SYSTEM . 'library/cart.php'));

$myVar = array();

$myVar = array();

// Registry
$registry = new Registry();

// Loader
$loader = new Loader($registry);
$registry->set('load', $loader);

// Config
$config = new Config();
$registry->set('config', $config);

// Database
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);

// Url
$url = new Url($config->get('config_url'), $config->get('config_use_ssl') ? $config->get('config_ssl') :

$config->get('config_url'));   
$registry->set('url', $url);

// Log
$log = new Log($config->get('config_error_filename'));
$registry->set('log', $log);

function error_handler($errno, $errstr, $errfile, $errline) {
   global $log, $config;

   switch ($errno) {
      case E_NOTICE:
      case E_USER_NOTICE:
         $error = 'Notice';
         break;
      case E_WARNING:
      case E_USER_WARNING:
         $error = 'Warning';
         break;
      case E_ERROR:
      case E_USER_ERROR:
         $error = 'Fatal Error';
         break;
      default:
         $error = 'Unknown';
         break;
   }

   if ($config->get('config_error_display')) {
      echo '<b>' . $error . '</b>: ' . $errstr . ' in <b>' . $errfile . '</b> on line <b>' . $errline . '</b>';
   }

   if ($config->get('config_error_log')) {
      $log->write('PHP ' . $error . ':  ' . $errstr . ' in ' . $errfile . ' on line ' . $errline);
   }

   return true;
}

// Error Handler
set_error_handler('error_handler');

// Request
$request = new Request();
$registry->set('request', $request);

// Response
$response = new Response();
$response->addHeader('Content-Type: text/html; charset=utf-8');
$response->setCompression($config->get('config_compression'));
$registry->set('response', $response);

// Cache
$cache = new Cache();
$registry->set('cache', $cache);

// Session
$session = new Session();
$registry->set('session', $session);

// Language Detection
$languages = array();

$query = $db->query("SELECT * FROM " . DB_PREFIX . "language");

foreach ($query->rows as $result) {
   $languages[$result['code']] = $result;
}

$detect = '';

if (isset($request->server['HTTP_ACCEPT_LANGUAGE']) && ($request->server['HTTP_ACCEPT_LANGUAGE'])) {
   $browser_languages = explode(',', $request->server['HTTP_ACCEPT_LANGUAGE']);

   foreach ($browser_languages as $browser_language) {
      foreach ($languages as $key => $value) {
         if ($value['status']) {
            $locale = explode(',', $value['locale']);

            if (in_array($browser_language, $locale)) {
               $detect = $key;
            }
         }
      }
   }
}

if (isset($request->get['language']) && array_key_exists($request->get['language'], $languages) &&

$languages[$request->get['language']]['status']) {
   $code = $request->get['language'];
} elseif (isset($session->data['language']) && array_key_exists($session->data['language'], $languages)) {
   $code = $session->data['language'];
} elseif (isset($request->cookie['language']) && array_key_exists($request->cookie['language'], $languages)) {
   $code = $request->cookie['language'];
} elseif ($detect) {
   $code = $detect;
} else {
   $code = $config->get('config_language');
}

if (!isset($session->data['language']) || $session->data['language'] != $code) {
   $session->data['language'] = $code;
}

if (!isset($request->cookie['language']) || $request->cookie['language'] != $code) {    
   setcookie('language', $code, time() + 60 * 60 * 24 * 30, '/', $request->server['HTTP_HOST']);
}         

$config->set('config_language_id', $languages[$code]['language_id']);
$config->set('config_language', $languages[$code]['code']);

// Language   
$language = new Language($languages[$code]['directory']);
$language->load($languages[$code]['filename']);   
$registry->set('language', $language);

// Document
$document = new Document();
$registry->set('document', $document);       

// Customer
$registry->set('customer', new Customer($registry));

// Affiliate
$affiliate = new Affiliate($registry);      
$registry->set('affiliate', $affiliate);

if (isset($request->get['tracking']) && !isset($request->cookie['tracking'])) {
   setcookie('tracking', $request->get['tracking'], time() + 3600 * 24 * 1000, '/');
}

// Currency
$registry->set('currency', new Currency($registry));

// Tax
$tax = new Tax($registry);
$registry->set('tax', $tax);

// Weight
$registry->set('weight', new Weight($registry));

// Length
$registry->set('length', new Length($registry));

// Cart
$registry->set('cart', new Cart($registry));

// Front Controller
$controller = new Front($registry);

// Maintenance Mode
$controller->addPreAction(new Action('common/maintenance'));

// SEO URL's
$controller->addPreAction(new Action('common/seo_url'));

// Router
if (isset($request->get['route'])) {
   $action = new Action($request->get['route']);
} else {
   $action = new Action('common/home');
}

// Dispatch
$controller->dispatch($action, new Action('error/not_found'));

<强> 2。在page.php中包含headerX.php,即将下面的语句放在第1页的第1行.php

<?php require_once ('headerXYZ.php');?>

第3。在外部page.php页面的开始正文标记之后添加以下代码

  <?php
    require_once('shop/catalog/model/total/sub_total.php');
    require_once('shop/catalog/language/english/total/sub_total.php');
    require_once('shop/catalog/model/total/reward.php');
    require_once('shop/catalog/model/total/shipping.php');
    require_once('shop/catalog/model/total/coupon.php');
    require_once('shop/catalog/model/total/tax.php');
    require_once('shop/catalog/model/total/credit.php');
    require_once('shop/catalog/language/english/total/credit.php');
    require_once('shop/catalog/model/total/voucher.php');
    require_once('shop/catalog/model/total/total.php');
    require_once('shop/catalog/language/english/total/total.php');
    foreach($myVar as $key=>$value)
    {
       $$key = $value;
    }

    require_once('shop/catalog/controller/common/header.php');
    require_once('shop/catalog/view/theme/default/template/common/header.tpl');
    ?>

答案 1 :(得分:0)

我正在寻找类似的东西,我做的是在两个系统中为页脚和标题编写相同的html / css,之后,我写了一个额外的Wordpress插件,用于在用户登录opencart时显示用户和购物车信息。

这里的插件: https://github.com/saRca/op2wp