我正在使用prestashop 1.7。我连接模块。有一个问题:未显示标题,描述,关键字。您需要从同一服务器上托管的另一个站点集成来自prestashop 1.7的数据。没有prestashop的第二个站点可以正常工作,并且可以根据需要显示标题,描述和关键字 这是集成代码
<?if(!defined("TDM_PROLOG_INCLUDED") || TDM_PROLOG_INCLUDED!==true)die();
//define('_PS_MODE_DEV_', true);
$tm=time();
require($_SERVER["DOCUMENT_ROOT"].'/config/config.inc.php');
//$sql = 'SELECT * FROM `ps_1product` WHERE `id_product` = 10 ';
//$arRes = Db::getInstance()->executeS($sql);
//echo '<br><pre>';print_r($arRes);echo '</pre>';
global $TDMCore;
if(!$context){$context = Context::getContext();}
$PS_LANG = (string)$context->language->iso_code;
//Groups:
//$arPsUGroups = $context->customer->getGroups(); //array of linked groups
$PsDefGroup = $context->customer->id_default_group;
if(!TDM_ISADMIN){
$arPGID = $TDMCore->arPriceGID;
foreach($arPGID as $TDM_GID=>$CMS_GID){
if($PsDefGroup==$CMS_GID){
if($_SESSION['TDM_USER_GROUP']!=$TDM_GID){$_SESSION['TDM_USER_GROUP']=$TDM_GID; Header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);}
break;
}
}
}
//Lang
// PhpMadman
// Should fix undefined index error
if(!isset($_GET['ulng']) || $_GET['ulng'] == '') {
// if($_GET['ulng']==''){
if($PS_LANG AND TDM_LANG!=$PS_LANG AND in_array($PS_LANG,$TDMCore->arLangs)){
$_SESSION['TDM_LANG']=$PS_LANG;
TDMRedirect($_SERVER['REQUEST_URI']);
}
}
if(!TDM_ISADMIN){
$arPGID = $TDMCore->arPriceGID;
global $USER;
$arGroups = array((int)Group::getCurrent()->id);
$isAuthorisedGroup = false;
foreach($arPGID as $TDM_GID=>$CMS_GID){
if(in_array($CMS_GID,$arGroups)){
$isAuthorisedGroup = true;
if($_SESSION['TDM_USER_GROUP']!=$TDM_GID){
$_SESSION['TDM_USER_GROUP']=$TDM_GID;
header('Location: '.$_SERVER['REQUEST_URI']);
}
break;
}
}
if (!$isAuthorisedGroup) {
unset($_SESSION['TDM_USER_GROUP']);
}
}
//Add to cart
if(defined('TDM_ADD_TO_CART') AND TDM_ADD_TO_CART){
global $arCartPrice;
if(is_array($arCartPrice)){
if($_REQUEST['QTY']>1){$QUANTITY=intval($_REQUEST['QTY']);}else{$QUANTITY=1;}
// PhpMadman
// Should fix undefined index
if (isset($arCartPrice['OPTIONS']['MINIMUM'])) {
if ($arCartPrice['OPTIONS']['MINIMUM'] > 1 AND $QUANTITY < $arCartPrice['OPTIONS']['MINIMUM']) {
$QUANTITY=$arCartPrice['OPTIONS']['MINIMUM'];
}
}
if($arCartPrice['OPTIONS']['MINIMUM']>1 AND $QUANTITY<$arCartPrice['OPTIONS']['MINIMUM']){$QUANTITY=$arCartPrice['OPTIONS']['MINIMUM'];}
if($QUANTITY>$arCartPrice['AVAILABLE_NUM']){$QUANTITY=$arCartPrice['AVAILABLE_NUM'];}
$DefaultCategory = intval($TDMCore->arSettings["CMS_DEFCATID"]);
$Price = TDMConvertPrice($arCartPrice['CURRENCY'],$TDMCore->arSettings["CMS_ADDCART_CURRENCY"],$arCartPrice['PRICE']);
$DefaultTaxGroup = 1;
$VAT = 1.22;
$PriceVAT = round($Price/$VAT,2);
$Reference = $arCartPrice['ARTICLE'].' / '.$arCartPrice['BRAND'];
//Presta init
$logged = $context->cookie->__get('logged');
$id_cart = $context->cookie->__get('id_cart');
$id_lang = $context->cookie->__get('id_lang');
$id_guest = $context->cookie->__get('id_guest');
$id_currency = $context->cookie->__get('id_currency');
// Add cart if no cart found
if (!$id_cart){
$context->cart = new Cart();
$context->cart->id_customer = $context->customer->id;
$context->cart->id_currency = $id_currency;
$context->cart->add();
if($context->cart->id){
$context->cookie->id_cart = (int)$context->cart->id;
}
$id_cart = (int)$context->cart->id;
}
$doAdd="Y";
//if(!$logged>0){$doAdd="N"; $TCore->arErrorMessages[] = 'You must be <a href="/index.php?controller=my-account">logged in</a> to buy products';}
//if(trim($Reference)=='' OR !$Price>0 OR !$QUANTITY>0){$doAdd="N"; $TCore->arErrorMessages[] = 'Add to cart data is missing!';}
if(!$id_cart>0){$doAdd="N"; ErAdd("Your cookie <b>id_cart</b> is wrong!",1);}
if(!$id_lang>0){$doAdd="N"; ErAdd("Your cookie <b>id_lang</b> is wrong!",1);}
if($doAdd!="N"){
//Check avail. tecdoc item in Presta
$sql = 'SELECT p.`id_product`, pl.`name` FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product`)
WHERE pl.`id_lang` = '.$id_lang.' AND
p.`price` = '.$PriceVAT.' AND
p.`reference` = "'.$Reference.'"
';
$arRes = Db::getInstance()->executeS($sql);
if(count($arRes)>0){
$NewTID = $arRes[0]['id_product'];
}else{
//Supplier data (for 1C integration)
$supplierName = $arCartPrice['SUPPLIER_STOCK'];
/*
$supplierId = SupplierCore::getIdByName($supplierName);
if(!$supplierId){
$obSupp = new SupplierCore(null,$id_lang);
$obSupp->name = $supplierName;
$obSupp->active = 1;
$obSupp->add();
$supplierId = $obSupp->id;
}*/
//echo '<br><pre>';print_r($obSupp);echo '</pre>';die();
$obProduct = new Product(false,false,$id_lang);
$obProduct->id_category_default = $DefaultCategory;
$obProduct->id_category = $DefaultCategory;
$obProduct->redirect_type = '404';
$obProduct->unity = $arCartPrice['ADD_URL'];
// $obProduct->name = substr($arCartPrice['NAME'],0,128);
// $obProduct->description = 'CARCONNECTION - ricambi auto per tutte le autovetture sul mercato a prezzi di concorrenza';
// $obProduct->description_short = $arCartPrice['SUPPLIER_STOCK'].' ['.$arCartPrice['DAY'].' days]';
$obProduct->price = $PriceVAT;
$obProduct->show_price = 1;
$obProduct->reference = $Reference;
// $obProduct->link_rewrite = $arCartPrice['CPID'];
$obProduct->available_for_order = 1; //true
$obProduct->visibility = 'none'; //both
$obProduct->is_virtual = 0;
$obProduct->id_tax_rules_group = 8;
//PhpMadman
// Sets same texts for all languages
$languages = Language::getLanguages();
foreach($languages as $lang) {
$obProduct->name[$lang] = substr($arCartPrice['NAME'],0,128);
$obProduct->description[$lang] = 'CARCONNECTION - ricambi auto per tutte le autovetture sul mercato a prezzi di concorrenza';
$obProduct->link_rewrite[$lang] = $arCartPrice['CPID'];
$obProduct->description_short[$lang] = $arCartPrice['SUPPLIER_STOCK'].' ['.$arCartPrice['DAY'].' days]';
}
if(isset($arCartPrice['OPTIONS']['WEIGHT']) AND $arCartPrice['OPTIONS']['WEIGHT']>0){$obProduct->weight = round($arCartPrice['OPTIONS']['WEIGHT']/1000,2);}
if(isset($arCartPrice['OPTIONS']['MINIMUM']) AND $arCartPrice['OPTIONS']['MINIMUM']>0){$obProduct->minimal_quantity = $arCartPrice['OPTIONS']['MINIMUM']; $QUANTITY=$arCartPrice['OPTIONS']['MINIMUM'];}
if(isset($arCartPrice['OPTIONS']['USED']) AND $arCartPrice['OPTIONS']['USED']>0){$obProduct->condition = 'used';}
if(isset($arCartPrice['OPTIONS']['RESTORED']) AND $arCartPrice['OPTIONS']['RESTORED']>0){$obProduct->condition = 'refurbished';}
//supplier
//$obProduct->supplier_name = $supplierName;
//$obProduct->id_supplier = $supplierId;
//echo '<br><pre>';print_r($obProduct);echo '</pre>';
$obProduct->add();
if($obProduct->id>0){
$NewTID = $obProduct->id;
$obProduct->addToCategories(array($DefaultCategory));
//$obProduct->setWsCategories(Array("id"=>$DefaultCategory));
//Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'category_product` (`id_category`, `id_product`, `position`) VALUES ('.$DefaultCategory.','.$NewTID.',0)');
//Add image
if($arCartPrice['IMG_SRC']!='' AND $NewTID>0){
$shops = Shop::getShops(true, null, true);
$image = new Image();
$image->id_product = $NewTID;
$image->position = Image::getHighestPosition($NewTID)+1;
$image->cover = true; // or false;
if(($image->validateFields(false, true)) === true && ($image->validateFieldsLang(false, true)) === true && $image->add()){
$image->associateTo($shops);
$tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import');
if(Tools::copy($arCartPrice['IMG_SRC'], $tmpfile)){
$path = $image->getPathForCreation();
ImageManager::resize($tmpfile, $path.'.jpg');
}
unlink($tmpfile);
}
}
}else{
ErAdd("Prestashop new Item ID is false",1);
}
unset($obProduct);
}
if($NewTID>0){
if($arCartPrice['AVAILABLE_NUM']>0){StockAvailable::setQuantity($NewTID, false, $arCartPrice['AVAILABLE_NUM']);}
$obCart = new Cart($id_cart);
$obCart->id_lang = $id_lang;
$obCart->id_currency = $id_currency;
if($obCart->updateQty($QUANTITY,$NewTID)){
Header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); die();
}else{
ErAdd("Prestashop Add to Cart is false. NewTID=".$NewTID.', CartID="'.$id_cart.'"', 1);
}
}
}
}
}
?>
<script src="/<?=TDM_ROOT_DIR?>/media/js/jquery214.min.js"></script>
<?php
$_GET=Array();
$controller = new FrontController();
$tm=time();
$controller->init();
//echo 'init() '.(time()-$tm).' sec.<br>'; $tm=time();
//$controller->initContent();
//echo 'initContent() '.(time()-$tm).' sec.<br>'; $tm=time();
$controller->setMedia();
//$controller->initHeader();
$context->smarty->tpl_vars['page']->value['page_name'] = 'TDMod';
$context->smarty->tpl_vars['page']->value['meta']['title'] = TDM_TITLE;
$context->smarty->tpl_vars['page']->value['meta']['description'] = TDM_DESCRIPTION;
$context->smarty->tpl_vars['page']->value['meta']['keywords'] = TDM_KEYWORDS;
$context->smarty->tpl_vars['page']->value['meta']['robots'] = '';
$controller->displayHeader();
//echo 'displayHeader() '.(time()-$tm).' sec.<br>'; $tm=time();
?>
<script src="/<?=TDM_ROOT_DIR?>/media/js/jquery214.min.js"></script>
<script src="/<?=TDM_ROOT_DIR?>/media/js/colorbox/jquery.colorbox-min.js"></script>
<link rel="stylesheet" href="/<?=TDM_ROOT_DIR?>/media/js/colorbox/cmain.css" />
<table><tr><td><?$arMSParams["LANG"]='it';
require_once($_SERVER["DOCUMENT_ROOT"].'/autoparts/addons/vin/component.php');?>
</td><td>
<?$arKTParams["LANG"]='it';
require_once($_SERVER["DOCUMENT_ROOT"].'/autoparts/addons/mselect/component.php');?>
</table>
<?
require_once($_SERVER["DOCUMENT_ROOT"].'/autoparts/addons/vin/component.php');
ErShow();
echo $TDMContent;
$controller->displayFooter();
/*
$_GET=Array();
//require($_SERVER["DOCUMENT_ROOT"]."/header.php");
ob_start();
require($_SERVER["DOCUMENT_ROOT"]."/header.php");
?>
<script src="/<?=TDM_ROOT_DIR?>/media/js/jquery214.min.js"></script>
<?php
$PrestaHeader = ob_get_contents();
$PrestaHeader = str_replace(array('</body>','</html>'),'',$PrestaHeader);
$PrestaHeader = str_replace('id="pagenotfound"','',$PrestaHeader);
$PrestaHeader = str_replace('class="pagenotfound"','',$PrestaHeader);
ob_end_clean();
echo $PrestaHeader;
?>
<script src="/<?=TDM_ROOT_DIR?>/media/js/jquery214.min.js"></script>
<script src="/<?=TDM_ROOT_DIR?>/media/js/colorbox/jquery.colorbox-min.js"></script>
<link rel="stylesheet" href="/<?=TDM_ROOT_DIR?>/media/js/colorbox/cmain.css" />
<table><tr><td><?$arMSParams["LANG"]='it';
require_once($_SERVER["DOCUMENT_ROOT"].'/autoparts/addons/vin/component.php');?>
</td><td>
<?$arKTParams["LANG"]='it';
require_once($_SERVER["DOCUMENT_ROOT"].'/autoparts/addons/mselect/component.php');?>
</table>
<?
require_once($_SERVER["DOCUMENT_ROOT"].'/autoparts/addons/vin/component.php');
ErShow();
echo $TDMContent;
require($_SERVER["DOCUMENT_ROOT"]."/footer.php");
*/
?>