Jump to content

Create new products with php with automatic filled multilanguage mandatory fields


Recommended Posts

hi guys,

i'm writing you cause i can't solve a problem related to the creation of new products through php in multilanguage,
in few words:

I want my site (presta 1.6.1.9) integrated with tecdoc-module,


this integration is creating a new product in prestashop database as soon as a product is added to the cart but i'm not able to make it work for products that are added when a secondary language is selected.
my problem is that when a product is added to the cart the multilanguage fields (name, short descripion, description, category, link rewrite) are created only for default language and stay empty for the secondary languages. Anothed thing is that the products can be added to the cart only if default presta language is selected but i get an error when i try to add the products to the cart with a secondary language (not default one). 

what i need to do is to edit the php file responsible to tecdoc-module integration with prestashop so that when a product is created all the mandatory fields will be automatically filled for all the languages 
(is not important the translation is enough that the mandatory multilanguage fields will be filled the same in prestashop database for each active prestashop language) but i really don't know how :(


i'm sure that is a stupid thing but i don't know php so for me is quiet impossible to solve this problem.
i will be greatful if you could give a look (i think the interested lines are about 56-67 and 118-138...

many thanks in advance,
Enrico

p.s. i read the post: 
https://www.prestashop.com/forums/topic/514708-add-new-product-programmatically/

i think that is related to my problem but i don't know php so i don't know how to use this suggestion in my specific case

 

<?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
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;}
		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;
					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");
*/
?>

 

Link to comment
Share on other sites

hi,

it's because is the only way to add products that are not present in prestashop database through the tecdoc-module integration (about 4 milions products).

here how it works: when a customer add a product to the cart through tecdoc-module integration the product is automatically created in prestashop database and so you can continue the order with prestashop standard cart and make the payment.

If the product is not created into prestashop database through php command you can't proceed with payment in prestashop cart cause the product is not existent in presta...

 

this is the only way so that only the products that customers want to buy are created into prestashop database and all the 4.000.000 milion product stay into tecdoc database

Link to comment
Share on other sites

is working perfectly if i activate only the default language, i i try to add products with languages that are not default i get an error cause mandatory fields of new products are empty.

i think i should add the function: createMultiLangField  

into the above php for multilanguage field of new created products but i don't know how...

Link to comment
Share on other sites

I took a look into the link you added. This is not a real help there. Prestashop works with dependencies on database. You need to feed also other tables (not only ps_products, ps_lang and ps_suppliers). You can take a look into the database structure you will find here:

PS 1.6 - http://doc.prestashop.com/download/attachments/21463263/mpd16.pdf?version=1&modificationDate=1411047693000&api=v2

For PS 1.7. I don't know where it is, cause it is still in development version.

Link to comment
Share on other sites

what do you think regarding the possibility to edit the original line:

 

$obProduct->name = substr($arCartPrice['NAME'],0,128);

 

as

 

$obProduct->name = AdminImportController::createMultiLangField (substr($arCartPrice['NAME'],0,128));

 

but i don't know if the syntax is correct and the same for other multilanguage fields as link rewrite and short description etc... ?

Link to comment
Share on other sites

here is the debug of the error when i try to insert a product into cart with english language (default language is italian):

 

Notice: Undefined index: ulng in /var/www/autoparts/tocms/PrestaShop.1.6.x.php on line 28

Notice: Undefined index: MINIMUM in /var/www/autoparts/tocms/PrestaShop.1.6.x.php on line 60

Fatal error: Uncaught exception 'PrestaShopException' with message 'Property Product->link_rewrite is empty' in /var/www/classes/ObjectModel.php:954 Stack trace: #0 /var/www/classes/ObjectModel.php(295): ObjectModelCore->validateFieldsLang() #1 /var/www/classes/ObjectModel.php(511): ObjectModelCore->getFieldsLang() #2 /var/www/classes/Product.php(530): ObjectModelCore->add(true, false) #3 /var/www/autoparts/tocms/PrestaShop.1.6.x.php(144): ProductCore->add() #4 /var/www/autoparts/index.php(0): unknown() #5 {main} thrown in /var/www/classes/ObjectModel.php on line 954

 

Link to comment
Share on other sites

other languages are available, active and are working in prestashop database.

the tecdoc module integration is not sending link rewrite, name and other multilanguage information to prestashop if is not selected the default language.

what will i need is a modification of the attached file prestashop.1.6.x.php  so that the module will write to prestashop database also if english language is selected (english because is the language other than default).

 

something like:

WHATEVER IS THE LANGUAGE SELECTED

when you add to cart -> create a new product in prestashop database AND FILL MULTILANGUAGES MANDATORY FIELDS

 

but now is like this:

when you add to cart -> create a new product (working only for default language)

 

Link to comment
Share on other sites

Hi.

The problem is that you don't set an array on name, description and link_rewrite.

I have added an foreach loop on the products, so it adds the product and sets the same texts on all languages.

I also think I have fixed the undefined indexes.
You can find my changes by searching for //PhpMadman in the script.

Hopefully it will get you what you want, or in the right direction.
I'm note sure I have the time to help any more today.

 

<?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");
*/
?>

 

Link to comment
Share on other sites

MANY MANY thanks for the useful answer,

 

now it seems that i PHP is writing only with secondary language into prestashop database but not with the default one...

when i try to add a product to the cart in italian language (default) i get:

 

Notice: Undefined index: MINIMUM in /var/www/autoparts/tocms/PrestaShop.1.6.x.php on line 73

Warning: Illegal offset type in /var/www/autoparts/tocms/PrestaShop.1.6.x.php on line 157

Warning: Illegal offset type in /var/www/autoparts/tocms/PrestaShop.1.6.x.php on line 159

Warning: Illegal offset type in /var/www/autoparts/tocms/PrestaShop.1.6.x.php on line 162

Warning: Illegal offset type in /var/www/autoparts/tocms/PrestaShop.1.6.x.php on line 164

Warning: Illegal offset type in /var/www/autoparts/tocms/PrestaShop.1.6.x.php on line 157

Warning: Illegal offset type in /var/www/autoparts/tocms/PrestaShop.1.6.x.php on line 159

Warning: Illegal offset type in /var/www/autoparts/tocms/PrestaShop.1.6.x.php on line 162

Warning: Illegal offset type in /var/www/autoparts/tocms/PrestaShop.1.6.x.php on line 164

Fatal error: Uncaught exception 'PrestaShopException' with message 'Property Product->link_rewrite is empty' in /var/www/classes/ObjectModel.php:954 Stack trace: #0 /var/www/classes/ObjectModel.php(295): ObjectModelCore->validateFieldsLang() #1 /var/www/classes/ObjectModel.php(511): ObjectModelCore->getFieldsLang() #2 /var/www/classes/Product.php(530): ObjectModelCore->add(true, false) #3 /var/www/autoparts/tocms/PrestaShop.1.6.x.php(176): ProductCore->add() #4 /var/www/autoparts/index.php(0): unknown() #5 {main} thrown in /var/www/classes/ObjectModel.php on line 954

 

how to have both the languages (default and secondary) writing to prestashop database?

thankssss

 

you can't imagine how much time i spent on this...

Link to comment
Share on other sites

edit,

now with PHPmadman modification i have only ONE UNDEFINED notice:

the line: 

if($arCartPrice['OPTIONS']['MINIMUM']>1 

 

and still the Fatal error:

Uncaught exception 'PrestaShopException' with message 'Property Product->link_rewrite is empty' 

for added products to cart when language is not default one :(

presta database is still editable only from the cart in default language also if i added the lines:

 

 

$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]';
                                        }

 

any idea?

Edited by soundsystemconnection (see edit history)
Link to comment
Share on other sites

i noted that if i paste the lines:

 

$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]';
                                        }

Instead of having the multilanguages fields automatically filled each time that i add a product to the presta cart i'm still having the multilanguages fields filled only for default language :(:(  all the other languages are empty

also in the field ['NAME']  written in default language instead of having the correct name for example: DRIVE SHAFT i get DDIVE SHAFT

another example: CILINDRETTO and i get CCLINDRETTO as the first letter overwrite the second one

 

waiting for your suggestions ,

thankssss

Link to comment
Share on other sites

  • 1 year later...

Hello. I am using prestashop 1.7. I connect the module. There is a problem: not showing title, description, keywords.

 

<?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");
*/
?>
Link to comment
Share on other sites

  • 11 months later...

 

//PhpMadman
// Sets fields to array() first otherwise don't run
	$obProduct->name= array();
    $obProduct->description = array();
    $obProduct->link_rewrite = array();
    $obProduct->description_short= array();
	$languages = Language::getLanguages(false,false,true);
// change this ($languages = Language::getLanguages();)  for this $languages = Language::getLanguages(false,false,true);
// and get only the language id
// if you want get translations by prestashop use this on your strings
// $translator = $this->context->getTranslator();
// $string_translated =$translator->trans($your_string) ;
foreach($languages as $lang) {
  $obProduct->name[$lang] = substr($arCartPrice['NAME'],0,128);  //this is a required field
  $obProduct->description[$lang] = 'CARCONNECTION - ricambi auto per tutte le autovetture sul mercato a prezzi di concorrenza';
  $obProduct->link_rewrite[$lang] = $arCartPrice['CPID'];  //this is a required field
  $obProduct->description_short[$lang] = $arCartPrice['SUPPLIER_STOCK'].' ['.$arCartPrice['DAY'].' days]';
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...