Jump to content

[Тема закрыта]Blockwishlist вывести изображение в списке товаров


Recommended Posts

Знает кто как можно вывести фотку товара в этом модуле в списке товаров в левой колонке?

 

Пытался вывести фотку тремя разными ссылками, но везде Id картинки не выводится...

 

В $product айди картинки не передается, да и картинка там должна быть того цвета которого добавили в список желаний...

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

{$product|print_r} выдает следующие:

 

 Array
(
[id_product] => 11958
[quantity] => 2
[product_quantity] => 9
[name] => WMS041304 LG Selena
[id_product_attribute] => 20501
[priority] => 1
[link_rewrite] => wms041304-lg-selena
[category_rewrite] => serenity
[attributes_small] => мультиколор, 36B
[attribute_quantity] => 3
)

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

<img src="{$link->getImageLink($product.link_rewrite, $product.cover, 'small')}"

 

Выводит ссылку без image_id:

 

http://site.ru/-medium/wpb041302-lg-salvadora.jpg

 

Ссылка вида:

<img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'small')}" />

 

Выводит точно такую же ссылку...

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

Я не совсем понимаю где именно там в файле этом нужно этот запрос вывести.

 

Сам файл:

 

<?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 BlockWishList extends Module
{
const INSTALL_SQL_FILE = 'install.sql';
private $_html = '';
private $_postErrors = array();
public function __construct()
{
 $this->name = 'blockwishlist';
 $this->tab = 'front_office_features';
 $this->version = 0.3;
 $this->author = 'PrestaShop';
 $this->need_instance = 0;
 parent::__construct();
 $this->displayName = $this->l('Wishlist block');
 $this->description = $this->l('Adds a block containing the customer\'s wishlists.');
 $this->default_wishlist_name = $this->l('My wishlist');
}
public function install()
{
 if (!file_exists(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE))
  return (false);
 elseif (!$sql = file_get_contents(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE))
  return (false);
 $sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql);
 $sql = preg_split("/;\s*[\r\n]+/", $sql);
 foreach ($sql AS $query)
  if ($query)
   if (!Db::getInstance()->Execute(trim($query)))
 return false;
 if (!parent::install() ||
  !$this->registerHook('rightColumn') ||
  !$this->registerHook('productActions') ||
  !$this->registerHook('cart') ||
  !$this->registerHook('customerAccount') ||
  !$this->registerHook('header') ||
  !$this->registerHook('adminCustomers') ||
  !$this->registerHook('authentication'))
  return false;
 /* This hook is optional */
 $this->registerHook('myAccountBlock');
 return true;
}
public function uninstall()
{
 return (Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'wishlist') &&
  Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'wishlist_email') &&
  Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'wishlist_product') &&
  Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'wishlist_product_cart') &&
  parent::uninstall()
 );
}
public function getContent()
{
 $this->_html = '<h2>'.$this->displayName.'</h2>';
 if (Tools::isSubmit('submitSettings'))
 {
  $activated = Tools::getValue('activated');
  if ($activated != 0 AND $activated != 1)
   $this->_html .= '<div class="alert error">'.$this->l('Activate module : Invalid choice.').'</div>';
  $this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.$this->l('Settings updated').'</div>';
 }
 $this->_displayForm();
 return ($this->_html);
}
private function _displayForm()
{
 $this->_displayFormView();
}
private function _displayFormView()
{
 global $cookie;
 $customers = Customer::getCustomers();
 if (!sizeof($customers))
  return;
 $id_customer = (int)(Tools::getValue('id_customer'));
 if (!$id_customer)
  $id_customer = $customers[0]['id_customer'];
 $this->_html .= '<br />
 <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" id="listing">
  <fieldset>
   <legend><img src="'.$this->_path.'img/icon/package_go.png" alt="" title="" />'.$this->l('Listing').'</legend>
   <label>'.$this->l('Customers').'</label>
   <div class="margin-form">
 <select name="id_customer" onchange="$(\'#listing\').submit();">';
 foreach ($customers as $customer)
 {
  $this->_html .= '<option value="'.(int)($customer['id_customer']).'"';
  if ($customer['id_customer'] == $id_customer)
   $this->_html .= ' selected="selected"';
  $this->_html .= '>'.htmlentities($customer['firstname'], ENT_COMPAT, 'UTF-8').' '.htmlentities($customer['lastname'], ENT_COMPAT, 'UTF-8').'</option>';
 }
 $this->_html .= '
 </select>
   </div>';
 require_once(dirname(__FILE__).'/WishList.php');
 $wishlists = WishList::getByIdCustomer($id_customer);
 if (!sizeof($wishlists))
  return ($this->_html .= '</fieldset></form>');
 $id_wishlist = false;
 foreach ($wishlists AS $row)
  if ($row['id_wishlist'] == Tools::getValue('id_wishlist'))
  {
   $id_wishlist = (int)(Tools::getValue('id_wishlist'));
   break;
  }
 if (!$id_wishlist)
  $id_wishlist = $wishlists[0]['id_wishlist'];
 $this->_html .= '
   <label>'.$this->l('Wishlists').'</label>
   <div class="margin-form">
 <select name="id_wishlist" onchange="$(\'#listing\').submit();">';
 foreach ($wishlists as $wishlist)
 {
  $this->_html .= '<option value="'.(int)($wishlist['id_wishlist']).'"';
  if ($wishlist['id_wishlist'] == $id_wishlist)
  {
   $this->_html .= ' selected="selected"';
   $counter = $wishlist['counter'];
  }
  $this->_html .= '>'.htmlentities($wishlist['name'], ENT_COMPAT, 'UTF-8').'</option>';
 }
 $this->_html .= '
 </select>
   </div>';
 $this->_displayProducts((int)($id_wishlist));
 $this->_html .=  '</fieldset>
 </form>';
}
public function hookAuthentication()
{
 global $cookie;
 if (isset($cookie->id_wishlist))
 {
  unset($cookie->id_wishlist);
  $cookie->write();
 }
}
public function hookHeader($params)
{
 Tools::addCSS(($this->_path).'blockwishlist.css', 'all');
 return $this->display(__FILE__, 'blockwishlist-header.tpl');
}
public function hookRightColumn($params)
{
 global $smarty, $errors;
 require_once(dirname(__FILE__).'/WishList.php');
 if ($params['cookie']->isLogged())
 {
  $wishlists = Wishlist::getByIdCustomer($params['cookie']->id_customer);
  if (empty($params['cookie']->id_wishlist) === true ||
   WishList::exists($params['cookie']->id_wishlist, $params['cookie']->id_customer) === false)
  {
   if (!sizeof($wishlists))
 $id_wishlist = false;
   else
   {
 $id_wishlist = (int)($wishlists[0]['id_wishlist']);
 $params['cookie']->id_wishlist = (int)($id_wishlist);
   }
  }
  else
   $id_wishlist = $params['cookie']->id_wishlist;
  $smarty->assign(array(
   'id_wishlist' => $id_wishlist,
   'isLogged' => true,
   'wishlist_products' => ($id_wishlist == false ? false : WishList::getProductByIdCustomer($id_wishlist, $params['cookie']->id_customer, $params['cookie']->id_lang, null, true)),
   'wishlists' => $wishlists,
   'ptoken' => Tools::getToken(false)));
 }
 else
  $smarty->assign(array('wishlist_products' => false, 'wishlists' => false));
 return ($this->display(__FILE__, 'blockwishlist.tpl'));
}
public function hookLeftColumn($params)
{
 return $this->hookRightColumn($params);
}
public function hookProductActions($params)
{
 global $smarty;
 $smarty->assign('id_product', (int)(Tools::getValue('id_product')));
 return ($this->display(__FILE__, 'blockwishlist-extra.tpl'));
}
public function hookCustomerAccount($params)
{
 global $smarty;
 return $this->display(__FILE__, 'my-account.tpl');
}
public function hookMyAccountBlock($params)
{
 return $this->hookCustomerAccount($params);
}
private function _displayProducts($id_wishlist)
{
 global $cookie, $link;
 include_once(dirname(__FILE__).'/WishList.php');
 $wishlist = new WishList((int)($id_wishlist));
 $products = WishList::getProductByIdCustomer((int)($id_wishlist), (int)($wishlist->id_customer), (int)($cookie->id_lang));
 for ($i = 0; $i < sizeof($products); ++$i)
 {
  $obj = new Product((int)($products[$i]['id_product']), false, (int)($cookie->id_lang));
  if (!Validate::isLoadedObject($obj))
   continue;
  else
  {
   $images = $obj->getImages((int)($cookie->id_lang));
   foreach ($images AS $k => $image)
   {
 if ($image['cover'])
 {
  $products[$i]['cover'] = $obj->id.'-'.$image['id_image'];
  break;
 }
   }
   if (!isset($products[$i]['cover']))
 $products[$i]['cover'] = Language::getIsoById((int)($cookie->id_lang)).'-default';
  }
 }
 $this->_html .= '
 <table class="table">
  <thead>
   <tr>
 <th class="first_item" style="width:600px;">'.$this->l('Product').'</th>
 <th class="item" style="text-align:center;width:150px;">'.$this->l('Quantity').'</th>
 <th class="item" style="text-align:center;width:150px;">'.$this->l('Priority').'</th>
   </tr>
  </thead>
  <tbody>';
  $priority = array($this->l('High'), $this->l('Medium'), $this->l('Low'));
  foreach ($products as $product)
  {
   $this->_html .= '
   <tr>
 <td class="first_item">
  <img src="'.$link->getImageLink($product['link_rewrite'], $product['cover'], 'small').'" alt="'.htmlentities($product['name'], ENT_COMPAT, 'UTF-8').'" style="float:left;" />
  '.$product['name'];
   if (isset($product['attributes_small']))
 $this->_html .= '<br /><i>'.htmlentities($product['attributes_small'], ENT_COMPAT, 'UTF-8').'</i>';
   $this->_html .= '
 </td>
 <td class="item" style="text-align:center;">'.(int)($product['quantity']).'</td>
 <td class="item" style="text-align:center;">'.$priority[(int)($product['priority']) % 3].'</td>
   </tr>';
  }
 $this->_html .= '</tbody></table>';
}
public function hookAdminCustomers($params)
{
 require_once(dirname(__FILE__).'/WishList.php');
 $customer = new Customer((int)($params['id_customer']));
 if (!Validate::isLoadedObject($customer))
  die (Tools::displayError());
 $this->_html = '<h2>'.$this->l('Wishlists').'</h2>';
 $wishlists = WishList::getByIdCustomer((int)($customer->id));
 if (!sizeof($wishlists))
  $this->_html .= $customer->lastname.' '.$customer->firstname.' '.$this->l('No wishlist.');
 else
 {
  $this->_html .= '<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" id="listing">';
  $id_wishlist = (int)(Tools::getValue('id_wishlist'));
  if (!$id_wishlist)
 $id_wishlist = $wishlists[0]['id_wishlist'];
  $this->_html .= '<span>'.$this->l('Wishlist').': </span> <select name="id_wishlist" onchange="$(\'#listing\').submit();">';
  foreach ($wishlists as $wishlist)
  {
   $this->_html .= '<option value="'.(int)($wishlist['id_wishlist']).'"';
   if ($wishlist['id_wishlist'] == $id_wishlist)
   {
 $this->_html .= ' selected="selected"';
 $counter = $wishlist['counter'];
   }
   $this->_html .= '>'.htmlentities($wishlist['name'], ENT_COMPAT, 'UTF-8').'</option>';
  }
  $this->_html .= '</select>';
  $this->_displayProducts((int)($id_wishlist));
  $this->_html .= '</form><br />';
  return $this->_html;
 }
}
/*
* Display Error from controler
*/
public function errorLogged()
{
 return $this->l('You must be logged in to manage your wishlists.');
}
}

Link to comment
Share on other sites

нужно найти функцию WishList::getProductByIdCustomer() и модифицировать её.она в

файле WishList.php строка примерно 266.

 

строка 272

$products = Db::getInstance()->executeS('
 SELECT

добавить

$products = Db::getInstance()->executeS('
 SELECT pi.*,...........

275 стр

 LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = wp.`id_product`

добавить на след. строку

 LEFT JOIN `'._DB_PREFIX_.'image` pi ON p.`id_product` = pi.`id_product`

теперь у вас будет доступен

$product.id_image

в смарти

файл прикрепил правленный, лежит в корне модуля.

если я вас правильно понял то должно работать.

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

Тем не менее я для 1.4 файл сделал по вашей инструкции, но ссылка все равно не та, сейчас так:

 

 

http://site.ru/883-small/ricardo-sausalito-20-xl.jpg

 

А должно быть так:

 

http://site.ru/159-479-small/ricardo-sausalito-20-xl.jpg

 

159, с этого номера у конкретного товара начинаются все фотки.

 

Еще после модификации, появился баг, когда добавляешь один товар то в списке появляется столько же аналогичных товаров сколько доп. фоток у товара...т.е. если у товара 5 доп. фоток, то добавляется 5 товаров аналогичных.

Link to comment
Share on other sites

Попробовал вот так:

 

SELECT p.*, wp.`id_product`, wp.`quantity`, p.`quantity` AS product_quantity, pl.`name`, wp.`id_product_attribute`, wp.`priority`, i.`id_image`, pl.link_rewrite, cl.link_rewrite AS category_rewrite

 

и

 

JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)

 

Теперь добовляеться только 1 товар как надо, но опять ссылка не такая:

 

http://site.ru/479-small/ricardo-sausalito-20-xl.jpg

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

Сделал {$product|print_r} теперь намного больше выводит:

 

   Product Object
(
   [tax_name] => deprecated
   [tax_rate] => 0
   [id_tax_rules_group] => 0
   [id_manufacturer] => 3
   [id_supplier] => 0
   [id_category_default] => 1000
   [id_color_default] => 0
   [manufacturer_name] => ###########
   [supplier_name] =>
   [name] => ###########
   [description] => ###########
   [description_short] =>
   [quantity] => 100
   [minimal_quantity] => 1
   [available_now] =>
   [available_later] =>
   [price] => 6790
   [additional_shipping_cost] => 0.00
   [wholesale_price] => 0.000000
   [on_sale] => 0
   [online_only] => 0
   [unity] =>
   [unit_price] => 0
   [unit_price_ratio] => 0.000000
   [ecotax] => 0.000000
   [reference] => 15004-0002-21
   [supplier_reference] =>
   [location] =>
   [width] => 34
   [height] => 55
   [depth] => 23
   [weight] => 3
   [ean13] =>
   [upc] =>
   [link_rewrite] => ###########
   [meta_description] => ###########
   [meta_keywords] => ###########
   [meta_title] => ###########
   [out_of_stock] => 2
   [quantity_discount] => 0
   [customizable] => 0
   [new] =>
   [uploadable_files] => 0
   [text_fields] => 0
   [active] => 1
   [available_for_order] => 1
   [condition] => new
   [show_price] => 1
   [indexed] => 1
   [date_add] => 2013-03-16 19:30:16
   [date_upd] => 2013-05-20 15:49:33
   [tags] =>
   [cache_is_pack] => 0
   [cache_has_attachments] => 0
   [cache_default_attribute] => 252
   [tables:protected] => Array
    (
	    [0] => product
	    [1] => product_lang
    )
   [fieldsRequired:protected] => Array
    (
	    [0] => quantity
	    [1] => price
    )
   [fieldsSize:protected] => Array
    (
	    [reference] => 32
	    [supplier_reference] => 32
	    [location] => 64
	    [ean13] => 13
	    [upc] => 12
	    [unity] => 10
    )
   [fieldsValidate:protected] => Array
    (
	    [id_tax_rules_group] => isUnsignedId
	    [id_manufacturer] => isUnsignedId
	    [id_supplier] => isUnsignedId
	    [id_category_default] => isUnsignedId
	    [id_color_default] => isUnsignedInt
	    [minimal_quantity] => isUnsignedInt
	    [price] => isPrice
	    [additional_shipping_cost] => isPrice
	    [wholesale_price] => isPrice
	    [on_sale] => isBool
	    [online_only] => isBool
	    [ecotax] => isPrice
	    [unit_price] => isPrice
	    [unity] => isString
	    [reference] => isReference
	    [supplier_reference] => isReference
	    [location] => isReference
	    [width] => isUnsignedFloat
	    [height] => isUnsignedFloat
	    [depth] => isUnsignedFloat
	    [weight] => isUnsignedFloat
	    [out_of_stock] => isUnsignedInt
	    [quantity_discount] => isBool
	    [customizable] => isUnsignedInt
	    [uploadable_files] => isUnsignedInt
	    [text_fields] => isUnsignedInt
	    [active] => isBool
	    [available_for_order] => isBool
	    [condition] => isGenericName
	    [show_price] => isBool
	    [ean13] => isEan13
	    [upc] => isUpc
	    [indexed] => isBool
	    [cache_is_pack] => isBool
	    [cache_has_attachments] => isBool
    )
   [fieldsRequiredLang:protected] => Array
    (
	    [0] => link_rewrite
	    [1] => name
    )
   [fieldsSizeLang:protected] => Array
    (
	    [meta_description] => 255
	    [meta_keywords] => 255
	    [meta_title] => 128
	    [link_rewrite] => 128
	    [name] => 128
	    [available_now] => 255
	    [available_later] => 255
    )
   [fieldsValidateLang:protected] => Array
    (
	    [meta_description] => isGenericName
	    [meta_keywords] => isGenericName
	    [meta_title] => isGenericName
	    [link_rewrite] => isLinkRewrite
	    [name] => isCatalogName
	    [description] => isString
	    [description_short] => isString
	    [available_now] => isGenericName
	    [available_later] => IsGenericName
    )
   [table:protected] => product
   [identifier:protected] => id_product
   [webserviceParameters:protected] => Array
    (
	    [objectMethods] => Array
		    (
			    [add] => addWs
			    [update] => updateWs
		    )
	    [objectNodeNames] => products
	    [fields] => Array
		    (
			    [id_manufacturer] => Array
				    (
					    [xlink_resource] => manufacturers
				    )
			    [id_supplier] => Array
				    (
					    [xlink_resource] => suppliers
				    )
			    [id_category_default] => Array
				    (
					    [xlink_resource] => categories
				    )
			    [out_of_stock] => Array
				    (
					    [required] => 1
				    )
			    [new] => Array
				    (
				    )
			    [cache_default_attribute] => Array
				    (
				    )
			    [id_default_image] => Array
				    (
					    [getter] => getCoverWs
					    [setter] => setCoverWs
					    [xlink_resource] => Array
						    (
							    [resourceName] => images
							    [subResourceName] => products
						    )
				    )
			    [id_default_combination] => Array
				    (
					    [getter] => getWsDefaultCombination
					    [setter] => setWsDefaultCombination
					    [xlink_resource] => Array
						    (
							    [resourceName] => combinations
						    )
				    )
			    [position_in_category] => Array
				    (
					    [getter] => getWsPositionInCategory
					    [setter] =>
				    )
			    [manufacturer_name] => Array
				    (
					    [getter] => getWsManufacturerName
					    [setter] =>
				    )
		    )
	    [associations] => Array
		    (
			    [categories] => Array
				    (
					    [resource] => category
					    [fields] => Array
						    (
							    [id] => Array
								    (
									    [required] => 1
								    )
						    )
				    )
			    [images] => Array
				    (
					    [resource] => image
					    [fields] => Array
						    (
							    [id] => Array
								    (
								    )
							    [legend] => Array
								    (
									    [i18n] => 1
								    )
						    )
				    )
			    [combinations] => Array
				    (
					    [resource] => combinations
					    [fields] => Array
						    (
							    [id] => Array
								    (
									    [required] => 1
								    )
						    )
				    )
			    [product_option_values] => Array
				    (
					    [resource] => product_options_values
					    [fields] => Array
						    (
							    [id] => Array
								    (
									    [required] => 1
								    )
						    )
				    )
			    [product_features] => Array
				    (
					    [resource] => product_feature
					    [fields] => Array
						    (
							    [id] => Array
								    (
									    [required] => 1
								    )
							    [id_feature_value] => Array
								    (
									    [required] => 1
									    [xlink_resource] => product_feature_values
								    )
						    )
				    )
			    [tags] => Array
				    (
					    [resource] => tag
					    [fields] => Array
						    (
							    [id] => Array
								    (
									    [required] => 1
								    )
						    )
				    )
		    )
    )
   [id] => 159
   [id_lang:protected] => 6
   [image_dir:protected] =>
   [image_format:protected] => jpg
   [specificPrice] =>
   [category] => ###########
)

 

И вот в самом конце идет:

 

[id] => 159

 

Как бы это выцепить?

Link to comment
Share on other sites

Все равно это не то -/ должно быть все по нормальному, а я чувствую что получается через ж...

Есть какие ни будь мысли?

Link to comment
Share on other sites

Толи у меня к вечеру уже голова не работает...не пойму куда эту строчку твою сунуть и как вывести картинку с ней...

Link to comment
Share on other sites

Утром, утром... :)

Там массив обработать нужно, способ зависит от вашего кода.

 

И подумайте трижды, нужны ли картинки в такой узкой колонке... у меня тоже есть этот модуль и я не стал их туда совать.

Link to comment
Share on other sites

×
×
  • Create New...