У меня есть модуль для показа баннеров (и наклеек) на товаре. Функция баннера показывает баннер только на странице конкретного продукта, наклейки на странице конкретного продукта и миниатюру списка продуктов.
(вы можете увидеть скриншот) исходная страница: http://miofantasy.it/shampoo/ 2192-antica-erboristeria-shampoo-girasole-250-ml.html
скриншот
Я хочу показать БАННЕР на миниатюре списка продуктов, помимо этого продукта изменена страница, как на следующем снимке экрана (как это уже сделано в Stichers)
Изменен скриншот
исходная страница: http://miofantasy.it/
Я не разбираюсь в редактировании кода и не знаю, как это делать.
Любой может сказать мне, что мне следует изменить.
Внутри файла php модуля я нашел это код, который, я думаю, управляет баннером на странице продукта:
Код: Выделить всё
public function hookDisplayProductButtons()
{
//Its an alternative, use only if productfooter hook is not available.
// get rid of 1 > 2 condition to activate
if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=') && 1 > 2) {
return $this-> hookDisplayFooterProduct();
}
}
public function hookDisplayFooterProduct()
{
$type = (int)Configuration::get('sticker_type_val');
$type = empty($type) ? 1 : $type;
if ($type > 0) {
$object = new Stickers();
$rules = new Rules();
$id = Tools::getValue('id_product');
$product = new Product((int)$id, true, $this->context->language->id);
$category_data = $product->getCategories();
$stickers_pro = $object->getProductStickers($id);
**$stickers_banner = $object->getProductBanner($id);**
$_price = Tools::ps_round($product->price);
//For Stickers Rules if any matches - Tags
$tags_exist = Tag::getProductTags((int)$id);
$new_stickers_colllection = $rules->keyNewExists();
$is_discounted = (int)$product->isDiscounted($product->id);
if (!empty($tags_exist)) {
$stickers_colllection = $rules->keyTagExists($tags_exist);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Check for reference match
if (!empty($product->reference)) {
$stickers_colllection = $rules->keyRefExists($product->reference);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Check for Price match
if ($_price > 0) {
$stickers_colllection = $rules->keyPriceExists($_price);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
$_stickers_colllection = $rules->keyPriceGreaterExists($_price);
if (!empty($_stickers_colllection)) {
foreach ($_stickers_colllection as $_stick) {
array_push($stickers_pro, $object->getSticker($_stick));
}
}
}
//Check for new Products match
if (!empty($new_stickers_colllection) && (int)$product->new > 0) {
foreach ($new_stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Check for Dsicounted Product rules
if ($is_discounted > 0) {
$stickers_colllection = $rules->keySaleExists();
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Finally check for category rule existance
$rule_category = $rules->getAllApplicable('category');
if (count($rule_category) > 0)
{
$category_applicable = array();
foreach ($category_data as $key)
{
$return = $rules->getIsCategoryStickerApplicable($key);
if (!empty($return))
{
$return = array_shift($return);
array_push($category_applicable, $return);
}
}
if (count($category_applicable) > 0)
{
foreach ($category_applicable as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Now check for brands rule existance
$rule_brands = $rules->getAllApplicable('brand');
if (count($rule_brands) > 0)
{
$stickers_colllection = $rules->keyBrandsExists($rule_brands, (int)$product->id_manufacturer);
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Now check for supplier rule existance
$rule_supplier = $rules->getAllApplicable('supplier');
if (count($rule_supplier) > 0 && (int)$product->id_supplier > 0)
{
$stickers_colllection = $rules->keySupplierExists($rule_supplier, (int)$product->id_supplier);
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
//echo '
'; print_r($stickers_colllection); exit;
}
$base_image = __PS_BASE_URI__.'img/';
$position = Configuration::get('sticker_pos');
$size = Configuration::get('sticker_size');
$this->context->smarty->assign('base_image', $base_image);
$this->context->smarty->assign('size', $size);
$this->context->smarty->assign('position', $position);
$this->context->smarty->assign('id', $id);
$this->context->smarty->assign('stickers', $stickers_pro);
$this->context->smarty->assign('module_dir', _PS_MODULE_DIR_);
**$this->context->smarty->assign('stickers_banner', $stickers_banner);**
$force_ssl = (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'));
$this->context->smarty->assign(array(
'base_dir' => _PS_BASE_URL_.__PS_BASE_URI__,
'base_dir_ssl' => _PS_BASE_URL_SSL_.__PS_BASE_URI__,
'force_ssl' => $force_ssl
)
);
if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=') == true) {
return $this->display(__FILE__, 'views/templates/hook/productfooter_17.tpl');
} else {
return $this->display(__FILE__, 'views/templates/hook/productfooter.tpl');
}
}
}
'views/templates/hook/productfooter_17. tpl» — это файл, в котором я нахожу файл, который, по моему мнению, управляет макетом баннера, например:
Код: Выделить всё
{if !empty($stickers_banner.title)}
{if empty($stickers)}
{/if}
{literal}
$('.product-price').after({/literal}'bottom:10px; text-align:center;background:
{$stickers_banner.bg_color|escape:'htmlall':'UTF-8'};color:
{$stickers_banner.color|escape:'htmlall':'UTF-8'};border:1px solid
{$stickers_banner.border_color|escape:'htmlall':'UTF-8'};font-family:
{$stickers_banner.font|escape:'htmlall':'UTF-8'};font-size:
{$stickers_banner.font_size|escape:'htmlall':'UTF-8'}px;font-weight:
{$stickers_banner.font_weight|escape:'htmlall':'UTF-8'};">
{$stickers_banner.title|escape:'htmlall':'UTF-8'}'{literal});
{/literal}
{/if}
Код: Выделить всё
public function hookdisplayProductListFunctionalButtons($params)
{
$id = (int)$params['product']['id_product'];
$id = ($id context->language->id);
$category_data = $product->getCategories();
$type = Configuration::get('sticker_type_val');
$type = empty($type) ? 1 : $type;
$stickers_pro = array();
$object = new Stickers();
$rules = new Rules();
$_price = Tools::ps_round($product->price);
//$page_name = Dispatcher::getInstance()->getController();
if ($type == 1) {
$new_stickers_colllection = $rules->keyNewExists();
$is_discounted = (int)$product->isDiscounted($product->id);
//For Stickers Rules if any matches
$tags_exist = Tag::getProductTags((int)$id);
if (!empty($tags_exist)) {
$stickers_colllection = $rules->keyTagExists($tags_exist);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Check for reference match
if (!empty($product->reference)) {
$stickers_colllection = $rules->keyRefExists($product->reference);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Check for Price match
if ($_price > 0) {
$stickers_colllection = $rules->keyPriceExists($_price);
if (!empty($stickers_colllection)) {
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
$_stickers_colllection = $rules->keyPriceGreaterExists($_price);
if (!empty($_stickers_colllection)) {
foreach ($_stickers_colllection as $_stick) {
array_push($stickers_pro, $object->getSticker($_stick));
}
}
}
//Check for new Products match
if (!empty($new_stickers_colllection) && (int)$product->new > 0) {
foreach ($new_stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Check for Discounted Product rules
if ($is_discounted > 0) {
$stickers_colllection = $rules->keySaleExists();
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Finally check for category rule existance
$rule_category = $rules->getAllApplicable('category');
if (count($rule_category) > 0)
{
$category_applicable = array();
foreach ($category_data as $key)
{
$return = $rules->getIsCategoryStickerApplicable($key);
if (!empty($return))
{
$return = array_shift($return);
array_push($category_applicable, $return);
}
}
if (count($category_applicable) > 0)
{
foreach ($category_applicable as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
}
//Now check for brands rule existance
$rule_brands = $rules->getAllApplicable('brand');
if (count($rule_brands) > 0)
{
$stickers_colllection = $rules->keyBrandsExists($rule_brands, (int)$product->id_manufacturer);
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
}
//Now check for supplier rule existance
$rule_supplier = $rules->getAllApplicable('supplier');
if (count($rule_supplier) > 0 && (int)$product->id_supplier > 0)
{
$stickers_colllection = $rules->keySupplierExists($rule_supplier, (int)$product->id_supplier);
foreach ($stickers_colllection as $stick) {
array_push($stickers_pro, $object->getSticker($stick));
}
//echo '
'; print_r($stickers_colllection); exit;
}
}
$position = Configuration::get('sticker_pos');
$size = Configuration::get('sticker_size');
$base_image = __PS_BASE_URI__.'img/';
$this->context->smarty->assign('base_image', $base_image);
$this->context->smarty->assign('name', $params['product']['name']);
$this->context->smarty->assign('size', $size);
$this->context->smarty->assign('position', $position);
$this->context->smarty->assign('module_dir', _PS_MODULE_DIR_);
$this->context->smarty->assign('id', $id);
if ($type == 1) {
$stickercollection_ = $object->getProductStickers($params['product']['id_product']);
foreach ($stickercollection_ as $stick) {
array_push($stickers_pro, $stick);
}
}
$this->context->smarty->assign('stickers', $stickers_pro);
$force_ssl = (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'));
$this->context->smarty->assign(array(
'base_dir' => _PS_BASE_URL_.__PS_BASE_URI__,
'base_dir_ssl' => _PS_BASE_URL_SSL_.__PS_BASE_URI__,
'force_ssl' => $force_ssl
)
);
if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=') == true) {
return $this->display(__FILE__, 'views/templates/hook/listing_17.tpl');
} else {
return $this->display(__FILE__, 'views/templates/hook/listing.tpl');
}
}
Что я могу изменить для отображения баннера в списке продуктов.
Кто-нибудь может мне помочь?
Спасибо
ОБНОВЛЕНИЕ:
Мне нужно добавить код
Код: Выделить всё
public function hookDisplayProductPriceBlock($params)
{
if ($params['type'] == 'before_price') {
// old_price or unit_price or weight
$id = (int)$params['product']['id_product'];
$_POST('id_product') = $id;
return $this->hookDisplayFooterProduct();
}
}
Код: Выделить всё
public function install()
{
if (!$this->existsTab($this->tab_class)) {
if (!$this->addTab($this->tab_class, 0)) {
return false;
}
}
mkdir(_PS_IMG_DIR_.'stickers', 0777, true);
if (!parent::install()
|| !$this->installDb()
|| !$this->registerHook('displayCatalogListing')
|| !$this->registerHook('displayProductListFunctionalButtons')
|| !$this->registerHook('displayProductPriceBlock')
|| !$this->registerHook('displayAdminProductsExtra')
|| !$this->registerHook('actionProductUpdate')
|| !$this->registerHook('displayBackOfficeHeader')
|| !$this->registerHook('displayProductListReviews')
|| !$this->registerHook('displayProductButtons')
|| !$this->registerHook('displayFooterProduct')) {
return false;
}
return true;
}
Код: Выделить всё
public function hookDisplayProductListReviews($params)
{
if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=')) {
return $this->hookdisplayProductListFunctionalButtons($params);
}
}
Я подумал, что если перенаправитьookDisplayProductListReviews наookdisplayProductListFunctionalButtons, можно отредактироватьookdisplayProductListFunctionalButtons и добавить код для показа баннер, как в ookDisplayFooterProduct, где написан конкретный код для показа Баннера?
Как сделать?
Спасибо
Подробнее здесь: https://stackoverflow.com/questions/528 ... oduct-list
Мобильная версия