Jump to content
  • 0

Problem z miniaturkami "viewed products"


nitek

Question

witam,

 

mam problem z miniaturkami w module, "viewed products".

Miniaturki produktów dostępnych nie wyświetlają się, natomiast miniaturki produktów niedostępnych - tak. W czym problem? ma ktoś jakiś pomysł?

fxcyfo.png

 

Z góry dziękuje za pomoc :)

Link to comment
Share on other sites

13 answers to this question

Recommended Posts

  • 0

upewnij się, że masz backup modułu blockviewed, następnie:

 

modules/blockviewed/blockviewed.php

 

około lini 108 masz:

LEFT JOIN '.DB_PREFIX.'image i ON (i.id_product = p.id_product)'.

 

zmień to na:

LEFT JOIN '.DB_PREFIX.'image i ON (i.id_product = p.id_product AND i.cover = 1)'.

  • Like 2
Link to comment
Share on other sites

  • 0

Hej,

 

nie wiem czy to pomoże - nie próbowałem (może to być nawet głupie :) ) ale wpadłem na taki pomysł:

 

w modułach / w folderze blockviewed / w pliku blockviewed.tpl / linia 34

 

<img src="{if isset($viewedProduct->id_image) &amp;amp;amp;&amp;amp;amp; $viewedProduct->id_image}{$link->getImageLink($viewedProduct->link_rewrite, $viewedProduct->cover, 'medium_default')}{else}{$img_prod_dir}{$lang_iso}-default-medium_default.jpg{/if}" alt="{$viewedProduct->legend|escape:html:'UTF-8'}">

 

zamienić średnie zdjęcie (medium) na duże (large) i do tagu img dodać wymiary width / height, tak żeby je zmniejszyć.

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

  • 0

U mnie przy wersji 1.5.4.1 po zmienieniu linijki 108 moduł się nie wyświetla. Co sądzicie? Jak mogę w tym przypadku naprawić wyświetlanie się miniaturek (przywróciłem do oryginału i wyświetlają się tylko niektóre) - generowanie nowych miniatur nie zmienia nic

Link to comment
Share on other sites

  • 0

U mnie przy wersji 1.5.4.1 po zmienieniu linijki 108 moduł się nie wyświetla. Co sądzicie? Jak mogę w tym przypadku naprawić wyświetlanie się miniaturek (przywróciłem do oryginału i wyświetlają się tylko niektóre) - generowanie nowych miniatur nie zmienia nic

 

możesz pokazać kod? szczególnie ten po zmianie ;)

Link to comment
Share on other sites

  • 0

przed zmianą:

 

<?php

 

 

if (!defined('_PS_VERSION_'))

exit;

 

class BlockViewed extends Module

{

private $_html = '';

private $_postErrors = array();

 

public function __construct()

{

$this->name = 'blockviewed';

$this->tab = 'front_office_features';

$this->version = 0.9;

$this->author = 'PrestaShop';

$this->need_instance = 0;

 

parent::__construct();

 

$this->displayName = $this->l('Viewed products block.');

$this->description = $this->l('Adds a block displaying recently viewed products.');

}

 

public function install()

{

if (!parent::install()

|| !$this->registerHook('leftColumn')

|| !$this->registerHook('header')

|| !Configuration::updateValue('PRODUCTS_VIEWED_NBR', 2))

return false;

return true;

}

 

public function getContent()

{

$output = '<h2>'.$this->displayName.'</h2>';

if (Tools::isSubmit('submitBlockViewed'))

{

if (!($productNbr = Tools::getValue('productNbr')) || empty($productNbr))

$output .= '<div class="alert error">'.$this->l('You must fill in the \'Products displayed\' field.').'</div>';

elseif ((int)($productNbr) == 0)

$output .= '<div class="alert error">'.$this->l('Invalid number.').'</div>';

else

{

Configuration::updateValue('PRODUCTS_VIEWED_NBR', (int)$productNbr);

$output .= '<div class="conf confirm">'.$this->l('Settings updated').'</div>';

}

}

return $output.$this->displayForm();

}

 

public function displayForm()

{

$output = '

<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">

<fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>

<label>'.$this->l('Products displayed').'</label>

<div class="margin-form">

<input type="text" name="productNbr" value="'.(int)Configuration::get('PRODUCTS_VIEWED_NBR').'" />

<p class="clear">'.$this->l('Define the number of products displayed in this block.').'</p>

</div>

<center><input type="submit" name="submitBlockViewed" value="'.$this->l('Save').'" class="button" /></center>

</fieldset>

</form>';

return $output;

}

 

public function hookRightColumn($params)

{

$id_product = (int)Tools::getValue('id_product');

$productsViewed = (isset($params['cookie']->viewed) && !empty($params['cookie']->viewed)) ? array_slice(explode(',', $params['cookie']->viewed), 0, Configuration::get('PRODUCTS_VIEWED_NBR')) : array();

 

if (count($productsViewed))

{

$defaultCover = Language::getIsoById($params['cookie']->id_lang).'-default';

 

$productIds = implode(',', $productsViewed);

$productsImages = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('

SELECT image_shop.id_image, p.id_product, il.legend, product_shop.active, pl.name, pl.description_short, pl.link_rewrite, cl.link_rewrite AS category_rewrite

FROM '._DB_PREFIX_.'product p

'.Shop::addSqlAssociation('product', 'p').'

LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product'.Shop::addSqlRestrictionOnLang('pl').')

LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product)'.

Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'

LEFT JOIN '._DB_PREFIX_.'image_lang il ON (il.id_image = i.id_image)

LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')

WHERE p.id_product IN ('.$productIds.')

AND pl.id_lang = '.(int)($params['cookie']->id_lang).'

AND cl.id_lang = '.(int)($params['cookie']->id_lang).'

GROUP BY product_shop.id_product'

);

 

$productsImagesArray = array();

foreach ($productsImages as $pi)

$productsImagesArray[$pi['id_product']] = $pi;

 

$productsViewedObj = array();

foreach ($productsViewed as $productViewed)

{

$obj = (object)'Product';

if (!isset($productsImagesArray[$productViewed]) || (!$obj->active = $productsImagesArray[$productViewed]['active']))

continue;

else

{

$obj->id = (int)($productsImagesArray[$productViewed]['id_product']);

$obj->id_image = (int)$productsImagesArray[$productViewed]['id_image'];

$obj->cover = (int)($productsImagesArray[$productViewed]['id_product']).'-'.(int)($productsImagesArray[$productViewed]['id_image']);

$obj->legend = $productsImagesArray[$productViewed]['legend'];

$obj->name = $productsImagesArray[$productViewed]['name'];

$obj->description_short = $productsImagesArray[$productViewed]['description_short'];

$obj->link_rewrite = $productsImagesArray[$productViewed]['link_rewrite'];

$obj->category_rewrite = $productsImagesArray[$productViewed]['category_rewrite'];

// $obj is not a real product so it cannot be used as argument for getProductLink()

$obj->product_link = $this->context->link->getProductLink($obj->id, $obj->link_rewrite, $obj->category_rewrite);

 

if (!isset($obj->cover) || !$productsImagesArray[$productViewed]['id_image'])

{

$obj->cover = $defaultCover;

$obj->legend = '';

}

$productsViewedObj[] = $obj;

}

}

 

if ($id_product && !in_array($id_product, $productsViewed))

{

// Check if the user to the right of access to this product

$product = new Product((int)$id_product);

if ($product->checkAccess((int)$this->context->customer->id))

array_unshift($productsViewed, $id_product);

}

$viewed = '';

foreach ($productsViewed as $id_product_viewed)

$viewed .= (int)($id_product_viewed).',';

$params['cookie']->viewed = rtrim($viewed, ',');

 

if (!count($productsViewedObj))

return;

 

$this->smarty->assign(array(

'productsViewedObj' => $productsViewedObj,

'mediumSize' => Image::getSize('medium')));

 

return $this->display(__FILE__, 'blockviewed.tpl');

}

elseif ($id_product)

$params['cookie']->viewed = (int)($id_product);

return;

}

 

public function hookLeftColumn($params)

{

return $this->hookRightColumn($params);

}

 

public function hookHeader($params)

{

$this->context->controller->addCSS(($this->_path).'blockviewed.css', 'all');

}

}

 

 

oraz po:

 

 

<?php

 

if (!defined('_PS_VERSION_'))

exit;

 

class BlockViewed extends Module

{

private $_html = '';

private $_postErrors = array();

 

public function __construct()

{

$this->name = 'blockviewed';

$this->tab = 'front_office_features';

$this->version = 0.9;

$this->author = 'PrestaShop';

$this->need_instance = 0;

 

parent::__construct();

 

$this->displayName = $this->l('Viewed products block.');

$this->description = $this->l('Adds a block displaying recently viewed products.');

}

 

public function install()

{

if (!parent::install()

|| !$this->registerHook('leftColumn')

|| !$this->registerHook('header')

|| !Configuration::updateValue('PRODUCTS_VIEWED_NBR', 2))

return false;

return true;

}

 

public function getContent()

{

$output = '<h2>'.$this->displayName.'</h2>';

if (Tools::isSubmit('submitBlockViewed'))

{

if (!($productNbr = Tools::getValue('productNbr')) || empty($productNbr))

$output .= '<div class="alert error">'.$this->l('You must fill in the \'Products displayed\' field.').'</div>';

elseif ((int)($productNbr) == 0)

$output .= '<div class="alert error">'.$this->l('Invalid number.').'</div>';

else

{

Configuration::updateValue('PRODUCTS_VIEWED_NBR', (int)$productNbr);

$output .= '<div class="conf confirm">'.$this->l('Settings updated').'</div>';

}

}

return $output.$this->displayForm();

}

 

public function displayForm()

{

$output = '

<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">

<fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>

<label>'.$this->l('Products displayed').'</label>

<div class="margin-form">

<input type="text" name="productNbr" value="'.(int)Configuration::get('PRODUCTS_VIEWED_NBR').'" />

<p class="clear">'.$this->l('Define the number of products displayed in this block.').'</p>

</div>

<center><input type="submit" name="submitBlockViewed" value="'.$this->l('Save').'" class="button" /></center>

</fieldset>

</form>';

return $output;

}

 

public function hookRightColumn($params)

{

$id_product = (int)Tools::getValue('id_product');

$productsViewed = (isset($params['cookie']->viewed) && !empty($params['cookie']->viewed)) ? array_slice(explode(',', $params['cookie']->viewed), 0, Configuration::get('PRODUCTS_VIEWED_NBR')) : array();

 

if (count($productsViewed))

{

$defaultCover = Language::getIsoById($params['cookie']->id_lang).'-default';

 

$productIds = implode(',', $productsViewed);

$productsImages = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('

SELECT image_shop.id_image, p.id_product, il.legend, product_shop.active, pl.name, pl.description_short, pl.link_rewrite, cl.link_rewrite AS category_rewrite

FROM '._DB_PREFIX_.'product p

'.Shop::addSqlAssociation('product', 'p').'

LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product'.Shop::addSqlRestrictionOnLang('pl').')

LEFT JOIN '.DB_PREFIX.'image i ON (i.id_product = p.id_product AND i.cover = 1)'.

Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'

LEFT JOIN '._DB_PREFIX_.'image_lang il ON (il.id_image = i.id_image)

LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')

WHERE p.id_product IN ('.$productIds.')

AND pl.id_lang = '.(int)($params['cookie']->id_lang).'

AND cl.id_lang = '.(int)($params['cookie']->id_lang).'

GROUP BY product_shop.id_product'

);

 

$productsImagesArray = array();

foreach ($productsImages as $pi)

$productsImagesArray[$pi['id_product']] = $pi;

 

$productsViewedObj = array();

foreach ($productsViewed as $productViewed)

{

$obj = (object)'Product';

if (!isset($productsImagesArray[$productViewed]) || (!$obj->active = $productsImagesArray[$productViewed]['active']))

continue;

else

{

$obj->id = (int)($productsImagesArray[$productViewed]['id_product']);

$obj->id_image = (int)$productsImagesArray[$productViewed]['id_image'];

$obj->cover = (int)($productsImagesArray[$productViewed]['id_product']).'-'.(int)($productsImagesArray[$productViewed]['id_image']);

$obj->legend = $productsImagesArray[$productViewed]['legend'];

$obj->name = $productsImagesArray[$productViewed]['name'];

$obj->description_short = $productsImagesArray[$productViewed]['description_short'];

$obj->link_rewrite = $productsImagesArray[$productViewed]['link_rewrite'];

$obj->category_rewrite = $productsImagesArray[$productViewed]['category_rewrite'];

// $obj is not a real product so it cannot be used as argument for getProductLink()

$obj->product_link = $this->context->link->getProductLink($obj->id, $obj->link_rewrite, $obj->category_rewrite);

 

if (!isset($obj->cover) || !$productsImagesArray[$productViewed]['id_image'])

{

$obj->cover = $defaultCover;

$obj->legend = '';

}

$productsViewedObj[] = $obj;

}

}

 

if ($id_product && !in_array($id_product, $productsViewed))

{

// Check if the user to the right of access to this product

$product = new Product((int)$id_product);

if ($product->checkAccess((int)$this->context->customer->id))

array_unshift($productsViewed, $id_product);

}

$viewed = '';

foreach ($productsViewed as $id_product_viewed)

$viewed .= (int)($id_product_viewed).',';

$params['cookie']->viewed = rtrim($viewed, ',');

 

if (!count($productsViewedObj))

return;

 

$this->smarty->assign(array(

'productsViewedObj' => $productsViewedObj,

'mediumSize' => Image::getSize('medium')));

 

return $this->display(__FILE__, 'blockviewed.tpl');

}

elseif ($id_product)

$params['cookie']->viewed = (int)($id_product);

return;

}

 

public function hookLeftColumn($params)

{

return $this->hookRightColumn($params);

}

 

public function hookHeader($params)

{

$this->context->controller->addCSS(($this->_path).'blockviewed.css', 'all');

}

}

 

Link to comment
Share on other sites

  • 0

faktycznie coś się wysypuje, sprawdziłem kod - jest sporo błędów, spróbuj z tym:

 

<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2013 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_'))
exit;
class BlockViewed extends Module
{
private $_html = '';
private $_postErrors = array();
public function __construct()
{
 $this->name = 'blockviewed';
 $this->tab = 'front_office_features';
 $this->version = 0.9;
 $this->author = 'PrestaShop';
 $this->need_instance = 0;
 parent::__construct();
 $this->displayName = $this->l('Viewed products block.');
 $this->description = $this->l('Adds a block displaying recently viewed products.');
}
public function install()
{
 if (!parent::install()
  || !$this->registerHook('leftColumn')
  || !$this->registerHook('header')
  || !Configuration::updateValue('PRODUCTS_VIEWED_NBR', 2))
  return false;
 return true;
}
public function getContent()
{
 $output = '<h2>'.$this->displayName.'</h2>';
 if (Tools::isSubmit('submitBlockViewed'))
 {
  if (!($productNbr = Tools::getValue('productNbr')) || empty($productNbr))
   $output .= '<div class="alert error">'.$this->l('You must fill in the \'Products displayed\' field.').'</div>';
  elseif ((int)($productNbr) == 0)
   $output .= '<div class="alert error">'.$this->l('Invalid number.').'</div>';
  else
  {
   Configuration::updateValue('PRODUCTS_VIEWED_NBR', (int)$productNbr);
   $output .= '<div class="conf confirm">'.$this->l('Settings updated').'</div>';
  }
 }
 return $output.$this->displayForm();
}
public function displayForm()
{
 $output = '
 <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
  <fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
   <label>'.$this->l('Products displayed').'</label>
   <div class="margin-form">
 <input type="text" name="productNbr" value="'.(int)Configuration::get('PRODUCTS_VIEWED_NBR').'" />
 <p class="clear">'.$this->l('Define the number of products displayed in this block.').'</p>
   </div>
   <center><input type="submit" name="submitBlockViewed" value="'.$this->l('Save').'" class="button" /></center>
  </fieldset>
 </form>';
 return $output;
}
public function hookRightColumn($params)
{
 $id_product = (int)Tools::getValue('id_product');
 $productsViewed = (isset($params['cookie']->viewed) && !empty($params['cookie']->viewed)) ? array_slice(explode(',', $params['cookie']->viewed), 0, Configuration::get('PRODUCTS_VIEWED_NBR')) : array();
 if (count($productsViewed))
 {
  $defaultCover = Language::getIsoById($params['cookie']->id_lang).'-default';
  $productIds = implode(',', $productsViewed);
  $productsImages = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
  SELECT image_shop.id_image, p.id_product, il.legend, product_shop.active, pl.name, pl.description_short, pl.link_rewrite, cl.link_rewrite AS category_rewrite
  FROM '._DB_PREFIX_.'product p
  '.Shop::addSqlAssociation('product', 'p').'
  LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product'.Shop::addSqlRestrictionOnLang('pl').')
  LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product AND i.cover=1)'.
  Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'
  LEFT JOIN '._DB_PREFIX_.'image_lang il ON (il.id_image = i.id_image)
  LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
  WHERE p.id_product IN ('.$productIds.')
  AND pl.id_lang = '.(int)($params['cookie']->id_lang).'
  AND cl.id_lang = '.(int)($params['cookie']->id_lang).'
  GROUP BY product_shop.id_product'
  );
  $productsImagesArray = array();
  foreach ($productsImages as $pi)
   $productsImagesArray[$pi['id_product']] = $pi;
  $productsViewedObj = array();
  foreach ($productsViewed as $productViewed)
  {
   $obj = (object)'Product';
   if (!isset($productsImagesArray[$productViewed]) || (!$obj->active = $productsImagesArray[$productViewed]['active']))
 continue;
   else
   {
 $obj->id = (int)($productsImagesArray[$productViewed]['id_product']);
 $obj->id_image = (int)$productsImagesArray[$productViewed]['id_image'];
 $obj->cover = (int)($productsImagesArray[$productViewed]['id_product']).'-'.(int)($productsImagesArray[$productViewed]['id_image']);
 $obj->legend = $productsImagesArray[$productViewed]['legend'];
 $obj->name = $productsImagesArray[$productViewed]['name'];
 $obj->description_short = $productsImagesArray[$productViewed]['description_short'];
 $obj->link_rewrite = $productsImagesArray[$productViewed]['link_rewrite'];
 $obj->category_rewrite = $productsImagesArray[$productViewed]['category_rewrite'];
 // $obj is not a real product so it cannot be used as argument for getProductLink()
 $obj->product_link = $this->context->link->getProductLink($obj->id, $obj->link_rewrite, $obj->category_rewrite);
 if (!isset($obj->cover) || !$productsImagesArray[$productViewed]['id_image'])
 {
  $obj->cover = $defaultCover;
  $obj->legend = '';
 }
 $productsViewedObj[] = $obj;
   }
  }
  if ($id_product && !in_array($id_product, $productsViewed))
  {
   // Check if the user to the right of access to this product
   $product = new Product((int)$id_product);
   if ($product->checkAccess((int)$this->context->customer->id))
 array_unshift($productsViewed, $id_product);
  }
  $viewed = '';
  foreach ($productsViewed as $id_product_viewed)
   $viewed .= (int)($id_product_viewed).',';
  $params['cookie']->viewed = rtrim($viewed, ',');
  if (!count($productsViewedObj))
   return;
  $this->smarty->assign(array(
   'productsViewedObj' => $productsViewedObj,
   'mediumSize' => Image::getSize('medium')));
  return $this->display(__FILE__, 'blockviewed.tpl');
 }
 elseif ($id_product)
  $params['cookie']->viewed = (int)($id_product);
 return;
}
public function hookLeftColumn($params)
{
 return $this->hookRightColumn($params);
}
public function hookHeader($params)
{
 $this->context->controller->addCSS(($this->_path).'blockviewed.css', 'all');
}
}

Link to comment
Share on other sites

  • 0

upewnij się, że masz backup modułu blockviewed, następnie:

Witam,

 

jestem całkowitym laikiem informatycznym. Do tej pory jakoś radziłam sobie z instalowanie sklepu na prestashop, ale teraz mam problem właśnie z przeglądanymi produktami. Bardzo chciałabym wpisać to co sugerowano, czyli:

 

modules/blockviewed/blockviewed.php

 

około lini 108 masz:

LEFT JOIN '.DB_PREFIX.'image i ON (i.id_product = p.id_product)'.

 

zmień to na:

LEFT JOIN '.DB_PREFIX.'image i ON (i.id_product = p.id_product AND i.cover = 1)'.

 

ale nie wiem gdzie :/ Jak wchodzę w paneli admina na moduły, wybieram moduł blockviewed i wchodzę w konfiguruj, to jedyne co mogę wpisać, to liczba produktów wyświetlanych w tym bloku.

Bardzo proszę o dokładniejszą instrukcję, taką dla małpy.

Pozdrawiam

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...