Jump to content

Getting no product list in Module


madmega
 Share

Recommended Posts

Hi, i have a problem concerning a module called PM_advancedpack, we've contacted the creator but they do not give support for older prestashop versions.
The problem we have with the module is as follows, when creating a new productpack, you have to choose what products you want into the pack, and there is where it goes wrong.

We cannot choose the products, when i click on CHOOSE button, nothing happens.
There is file called ajax.php that should be getting the products from the database.

And there is a file AdminAdvancedPack.php that is getting the results from ajax.php and should be displaying them (no, no TPL involved).
But all we are getting is a empty product list, were should i start looking ?
This is the ajax.php file
 

<?php

include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/../../init.php');
include_once(dirname(__FILE__).'/AdvancedPackClass.php');

if (isset($_GET['ajaxProduct']))
{

	$currentIndex = 'index.php?tab=AdminCatalog';
	$jsonArray = array();

	$products = Db::getInstance()->ExecuteS('
	SELECT p.`id_product`, pl.`name`, pl.`link_rewrite`, p.`reference`, i.`id_image`
	FROM `'._DB_PREFIX_.'product` p
	NATURAL LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
	LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
	WHERE pl.`id_lang` = '.intval(Tools::getValue('id_lang')).'');

	foreach ($products AS $accessory) {
		$curQty = Product::getQuantity($accessory['id_product']);
		if(_PS_VERSION_ < '1.4.3')
		$jsonArray[] = array("value"=>intval($accessory['id_product']).'-'.$accessory['name'].'-'.$accessory['reference'].' (stock : '.$curQty.')|'.$accessory['id_image'].'¤'.AdvancedPackClass::isProductPackPage($accessory['id_product']),"text"=>intval($accessory['id_product']).' - '.$accessory['name'].' - '.$accessory['reference'].' (stock : '.$curQty.')');
		else
			$jsonArray[] = array("value"=>intval($accessory['id_product']).'-'.$accessory['name'].'-'.$accessory['reference'].' (stock : '.$curQty.')|'.$link->getImageLink($accessory['link_rewrite'], Product::defineProductImage($accessory, Tools::getValue('id_lang')),'small').'¤'.AdvancedPackClass::isProductPackPage($accessory['id_product']),"text"=>intval($accessory['id_product']).' - '.$accessory['name'].' - '.$accessory['reference'].' (stock : '.$curQty.')');
	}
	echo json_encode($jsonArray);
	die();
}
if (isset($_GET['ajaxImage'],$_GET['id_product']))
{
	$id_product = intval($_GET['id_product']);
	$id_image = intval($_GET['id_image']);
	$images = Image::getImages(intval($cookie->id_lang), $id_product);
	$imagesTotal = Image::getImagesTotal($id_product);
	if (sizeof($images)) {
		echo '<select name="imgs_product[]" onchange="changeProductImg(this);">';
		foreach ($images AS $k => $image) {

			echo'<option value="'.intval($image['id_image']).'" '.($id_image == $image['id_image']?'selected=selected':'').'>'.$image['legend'].'</option>';
		}
		echo '</select>';
	}
}
?>

Share this post


Link to post
Share on other sites

I expect the problem is in the SQL string.

 

 

 

The string is spread over multiple lines. (i.e. there's a newline inside the string) Javascript doesn't like that. Either make it all on one line, like:

 

    $products = Db::getInstance()->ExecuteS(' SELECT p.`id_product`, pl.`name`, pl.`link_rewrite`, p.`reference`, i.`id_image` FROM `'._DB_PREFIX_.'product` p NATURAL LEFT JOIN `'._DB_PREFIX_.'product_lang` pl LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) WHERE pl.`id_lang` = '.intval(Tools::getValue('id_lang')).'');

 

 

or end every line with a  \

like:

 

    $products = Db::getInstance()->ExecuteS(' \
    SELECT p.`id_product`, pl.`name`, pl.`link_rewrite`, p.`reference`, i.`id_image`
 \
    FROM `'._DB_PREFIX_.'product` p \
    NATURAL LEFT JOIN `'._DB_PREFIX_.'product_lang` pl \
    LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) \
    WHERE pl.`id_lang` = '.intval(Tools::getValue('id_lang')).'');

 
 
Hope this does the trick,
pascal

Share this post


Link to post
Share on other sites

Hi, thank you for your answer, i've tried that but unfortunately, still no difference, i will post, the piece of code from the php file that loads the ajax.php

 

</div>
					<div class="clear"> </div>
							<script type="text/javascript">
								var formProduct;
								var accessories = new Array();
								function showReducOptions(e) {
									if($(e).val() && $(e).val()!=3) {
										$(".toReduc").slideDown("fast");
									}else {
										$(".toReduc").slideUp("fast");
									}
								}
								var filled = false;
								function fillAccessories()
								{
									if(filled) return;
									$.getJSON("'.__PS_BASE_URI__.'modules/pm_advancedpack/ajax.php",{ajaxProduct:1,id_lang:'.intval($cookie->id_lang).'},
										function(j) {
											filled = true;
											for (var i = 0; i < j.length; i++)
												accessories[i] = new Array(j[i].value, j[i].text);

											formProductSelection = document.layers ? document.forms.discount : document.discount;
											formProductSelection.selectProductSelection.length = accessories.length + 1;
											for (i = 0, j = 0; i < accessories.length; i++)
											{
												if (formProductSelection.filter.value)
													if (accessories[i][1].toLowerCase().indexOf(formProductSelection.filter.value.toLowerCase()) == -1)
														continue;
												formProductSelection.selectProductSelection.options[j].value = accessories[i][0];
												formProductSelection.selectProductSelection.options[j].text = accessories[i][1];
												j++;
											}
											if (j == 0)
											{
												formProductSelection.selectProductSelection.length = 2;
												formProductSelection.selectProductSelection.options[1].value = -1;
												formProductSelection.selectProductSelection.options[1].text = \''.$this->l('No match found').'\';
												formProductSelection.selectProductSelection.options.selectedIndex = 1;
											}
											else
											{
												formProductSelection.selectProductSelection.length = j;
												formProductSelection.selectProductSelection.options.selectedIndex = (formProductSelection.filter.value == \'\' ? 0 : 0);
											}
										}
									);
								}
							</script>
							<select id="selectProductSelection" name="selectProductSelection" style="width: 380px;" onfocus="fillAccessories();">
								<option value="0" selected="selected">-- '.$this->l('Choose').' --</option>
							</select>
							<span onclick="addProductToSelection('.($obj->id ? $obj->id : 0).');" style="cursor: pointer;"><img src="../img/admin/add.gif" alt="'.$this->l('Add an accessory').'" title="'.$this->l('Add an accessory').'" /></span>
							<br />'.$this->l('Filter:').' <input type="text" size="25" name="filter" onkeyup="filled = false;fillAccessories();" class="space" />
							<input type="hidden" value="" name="inputProductsSelection" id="inputProductsSelection" />
						</td>
					</tr></table>

Share this post


Link to post
Share on other sites

  • 3 weeks later...

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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More