Jump to content

Need some help with an old file that worked in version 1.4 but not in 1.6


x-sat.no

Recommended Posts

Hi 

After some time and many weeks of work i have finaly managed to update from 1.4 version to 1.6 version of the Prestashop.

 

All have gonne well untill i try to install one module / file that was working in PS1.4.  this file is a price compare file that helps generate a text file that the Price compare sites gets from our server

 

This is the file prisjakt copy.php that im attaching here. this file has worked very well in PS1.4. 

I have installed the same file on our new PS1.6.1.5 server and this is working, but the problem is that the link being reported is not the correct one.  If you take a look here http://www.x-sat.no/prisjakt.php the file is being generated but to the old format of the PS 1.4

 

Now if i take a link from the generated file the link looks like this 

http://www.x-sat.no/product.php?id_product=1623  and this link does not work as it give me a 404 ERROR

 

the product is self is here http://www.x-sat.no/koaksialkabler/1623-2m-koaksialkabel-med-kompresjons-f-plugg.html
and as you can see the link from the generetaed file is diferent to the link on the product.

 

Now my question is as followed, is there any one that can explain or help me modifie this file / module  to work with the latest prestashop. 

As i can see it the file works, but not as it should and my knowledge to php or programing is very limited, even that i have try to fix this i have not managed but made a mess up on my site. 

 

Any help or suggestion is welcome

 

Thank you in advance

prisjakt copy.php

Link to comment
Share on other sites


// the above lets you add categories whose products should not appear in the output /mohsart

$link = new Link();

echo htmlentities(utf8_decode($product['name'])).";".

number_format(Tools::convertPrice($price, $currency), 2, '.', '').";".

// $category->name[$lang].";". // changed the hardcoded language to default /mohsart

$categoryname.";".

//curPageURL().'/product.php?id_product='.$product['id_product'].";". //PRINT PRODUCT DIRECT URl

getProductLink($product['id_product']).";".

curPageURL()._THEME_PROD_DIR_.$product['id_product']."-".$imageUrl['id_image']."-large.jpg;". //PRINT IMAGE URL {$img_prod_dir}{$cover.id_image}-large.jpg

$product['quantity'].";". //IN STOCK STATUS

$product['manufacturer_name'].";". // added manufacturers /mohsart

$product['location']. //ISBN // added isbn /mohsart

"\n";

}

}

 

Edited by Eolia (see edit history)
  • Like 1
Link to comment
Share on other sites

Try this guy ;)

<?php
/*
YOU CAN DO WHAT YOU WANT WITH THIS FILE AS LONG AS YOU LEAVE THIS COPYRIGHT NOTICE IN THE FILE
CREATED BY WWW.PRESTAWORKS.SE - HOSTING AND E-COMMERCE
INSTALLATION: COPY THE FILE TO YOUR PRESTASHOP ROOT FOLDER
Version 1.3 ONLY FOR PRESTASHOP 1.5+ BY EOLIA
*/
include(dirname(__FILE__).'/config/config.inc.php');

function getShopUrl($id_shop = 1) {
	
	$ShopUrl = Db::getInstance()->getRow("
	SELECT
		domain,
		domain_ssl,
		physical_uri,
		virtual_uri
	FROM
		`"._DB_PREFIX_."shop_url`
	WHERE  id_shop = ".$id_shop); 
	
	if(Configuration::get('PS_SSL_ENABLED') || (!empty($_SERVER['HTTPS'])&& strtolower($_SERVER['HTTPS']) != 'off'))
		return 'https://'.$ShopUrl['domain_ssl'].$ShopUrl['physical_uri'].$ShopUrl['virtual_uri'];
	else
		return 'http://'.$ShopUrl['domain'].$ShopUrl['physical_uri'].$ShopUrl['virtual_uri'];

}

function GetCategory($category, $lang) {

	$return = array();
	$return[0] = $category->name;
	if($category->level_depth>0) {

		$i = $category->level_depth;
		$s = 1;
		do {
			$subcategory = new Category(intval($category->id_parent), $lang);
			if($subcategory->id!=1)
				$return[$s] = $subcategory->name;
			$i = $subcategory->level_depth;
			$category = $subcategory;
			$s++;
		} 
		while ($i > 0);

	}
	$result = array_reverse($return);
	$categorystring = "";
	foreach($result AS $str) {
	
		$catname = explode('.', $str);
		if(sizeof($catname) > 1)
			$categorystring .= $catname[1].' | ';
		else
			$categorystring .= $str.' | ';
	}
	return rtrim($categorystring,' | ');
}

// Create fake context 
$context = Context::getContext();
$context->controller = new stdClass();
$context->controller->controller_type = 'back';
$context->employee = true;
$lang = $context->language->id;
$productClass = new Product();
$id_currency = (int)Configuration::get('PS_CURRENCY_DEFAULT');
$currency = new Currency((int)$id_currency);

echo "Produktnamn;Pris inkl moms;Kategori;Produkt-URL;Bild-URL;Lagerstatus;Tillverkare;ISBN<br/>";

$products = $productClass->getProducts($lang, 0, null, 'name', 'ASC', false);
foreach ($products as $key => $product) {

	$price = Product::getPriceStatic($product['id_product']);
	$category = new Category(intval($product['id_category_default']), $lang);
	$categoryname = GetCategory($category, $lang);
	$imageUrl = Product::getCover(intval($product['id_product']));

	if(!$product['name'])
		$product['name'] = "-";
	if(!$product['manufacturer_name'])
		$product['manufacturer_name'] = "-";
	if(!$product['reference'])
		$product['reference'] = "-";

	switch (utf8_decode($categoryname)) {
	
		case "Västerås Goklubb": 
			break;
		default:
			$link = new Link();
			echo $product['name'].";".
			Tools::displayPrice($price, $currency).";".
			$categoryname.";".
			$link->getProductLink($product['id_product']).";".
			getShopUrl().'img/p/'.$product['id_product']."-".$imageUrl['id_image']."-large.jpg;".
			Product::getQuantity($product['id_product']).";".
			$product['manufacturer_name'].";".
			$product['reference'].";"."<br/>";
	}
}
Edited by Eolia (see edit history)
  • Like 1
Link to comment
Share on other sites

Thank you very much indeed , this file works fine now on my server. Much appritiated for your help :-)

Edit: I found one small error in the last script you fixed Eolia, the erros is that the link to the product image is not showing at all, the link from the cript looks like this http://www.x-sat.no/img/p/1623-557-large.jpg    while the link from the image it self looks like this  hhttp://www.x-sat.no/557-large_default/2m-koaksialkabel-med-kompresjons-f-plugg.jpg

As you can see the script try to get the image from the folder /img/p/    while the link to the image is different 


the script it self is working good and i thank you for that :-)  it is only the images that are not working and all the products on the price compare site will show with ni images at all. Could you please make an effort to fix this last thing Please and thank you very very much for your kind help :-)

Edited by x-sat.no (see edit history)
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...