Вывод текущей метки в заголовке группы товаров по этой метке

#
Re: Вывод текущей метки в заголовке группы товаров по этой метке
Dmitry K.,
Формирование тайтла, кейвордс и дискрипшена у динамических страниц, происходит в настройках ТДС.
То есть вам нужно добавить проверку, если идёт показ тегов, то подставлять значение из тегов.
Код из стандартной ТДС:
if (!is_null($Shop_Controller_Show->tag) && Core::moduleIsActive('tag'))
{
   $oTag = Core_Entity::factory('Tag')->getByPath($Shop_Controller_Show->tag);
   if ($oTag)
   {
      $aTitle[] = $oTag->seo_title != '' ? $oTag->seo_title : Core::_('Shop.tag', $oTag->name);
      $aDescription[] = $oTag->seo_description != '' ? $oTag->seo_description : $oTag->name;
      $aKeywords[] = $oTag->seo_keywords != '' ? $oTag->seo_keywords : $oTag->name;
   }
}
skype: mcross82
#
Re: Вывод текущей метки в заголовке группы товаров по этой метке
Mcross, спасибо!
Я в настройках ТДС интернет-магазина использовал вот такую конструкцию (по аналогии):

if ($Shop_Controller_Show->tag) {
$oTag = Core_Entity::factory('Tag', $Shop_Controller_Show->tag);
Core_Page::instance()->title($oTag->seo_title != ''
? $oTag->seo_title
: $oTag->name);
Core_Page::instance()->description($oTag->seo_description != ''
? $oTag->seo_description
: $oTag->name);
Core_Page::instance()->keywords($oTag->seo_keywords != ''
? $oTag->seo_keywords
: $oTag->name);
}


...но система, похоже, требует что-то ещё.
То ли определить какую-то переменную, которая, по всей видимости, не определена, то ли что-то в таком же духе!
#
Re: Вывод текущей метки в заголовке группы товаров по этой метке
Dmitry K.,
Сложно сказать в чем проблема, не видя её.
Скиньте полностью код ТДС с вашими изменениями, которые вызывают ошибку, ну и текст самой ошибки.
skype: mcross82
#
Re: Вывод текущей метки в заголовке группы товаров по этой метке
Настройка ТДС интернет-магазина:
<?php
$oShop = Core_Entity::factory('Shop', Core_Array::get(Core_Page::instance()->libParams, 'shopId'));
$Shop_Controller_Show = new Shop_Controller_Show($oShop);
$Shop_Controller_Show
->limit($oShop->items_on_page)
->parseUrl();
// Обработка скачивания файла электронного товара
$guid = Core_Array::getGet('download_file');
if (strlen($guid)) {
$oShop_Order_Item_Digital = Core_Entity::factory('Shop_Order_Item_Digital')->getByGuid($guid);
if (!is_null($oShop_Order_Item_Digital) && $oShop_Order_Item_Digital->Shop_Order_Item->Shop_Order->shop_id == $oShop->id) {
$iDay = 7;
// Проверяем, доступна ли ссылка (Ссылка доступна в течение суток после оплаты)
if (Core_Date::sql2timestamp($oShop_Order_Item_Digital->Shop_Order_Item->Shop_Order->payment_datetime) > time() - 24 * 60 * 60 * $iDay) {
$oShop_Item_Digital = $oShop_Order_Item_Digital->Shop_Item_Digital;
if ($oShop_Item_Digital->filename != '') {
Core_File::download($oShop_Item_Digital->getFullFilePath(), $oShop_Item_Digital->filename);
exit();
}}
else {
Core_Message::show(Core::_('Shop_Order_Item_Digital.time_is_up', $iDay));
}}
Core_Page::instance()->response->status(404)->sendHeaders()->showBody();
exit();
}
// Сравнение товаров
if (Core_Array::getRequest('compare')) {
$shop_item_id = intval(Core_Array::getRequest('compare'));
if (Core_Entity::factory('Shop_Item', $shop_item_id)->shop_id == $oShop->id) {
Core_Session::start();
if (isset($_SESSION['hostcmsCompare'][$oShop->id][$shop_item_id])) {
unset($_SESSION['hostcmsCompare'][$oShop->id][$shop_item_id]);
} else {
$_SESSION['hostcmsCompare'][$oShop->id][$shop_item_id] = 1;
}}
exit();
}
// Если мы находимся на странице товара
if ($Shop_Controller_Show->item) {
$oShop_Item = Core_Entity::factory('Shop_Item', $Shop_Controller_Show->item);

// Текущий элемент и группа
$cur_elem = $Shop_Controller_Show->item;
$cur_group = $oShop_Item->shop_group_id;
$shop_id = $oShop->id;

// Выберите * из shop_items где shop_items.id < $cur_elem ORDER BY shop_items.id DESC предел 1
$oCore_QueryBuilder_Select = Core_QueryBuilder::select()
->select('shop_items.path')
->from('shop_items')
->open()
->where('shop_items.id', '<', $cur_elem)
->setAnd()
->where('shop_items.shop_group_id', '=', $cur_group)
->setAnd()
->where('shop_items.shop_id', '=', $shop_id)
->setAnd()
->where('shop_items.deleted', '=', '0')
->close()
->clearOrderBy()
->orderBy('id', 'DESC')
->limit(1);
$prev = $oCore_QueryBuilder_Select->execute()->asAssoc()->current();
$prev = $prev['path'];
// Выберите * из shop_items где shop_items.id > $cur_elem ORDER BY shop_items.id предел 1
$oCore_QueryBuilder_Select = Core_QueryBuilder::select()
->select('shop_items.path')
->from('shop_items')
->open()
->where('shop_items.id', '>', $cur_elem)
->setAnd()
->where('shop_items.shop_group_id', '=', $cur_group)
->setAnd()
->where('shop_items.shop_id', '=', $shop_id)
->setAnd()
->where('shop_items.deleted', '=', '0')
->close()
->clearOrderBy()
->orderBy('id')
->limit(1);
$next = $oCore_QueryBuilder_Select->execute()->asAssoc()->current();
$next = $next ['path'];
$Shop_Controller_Show
->addEntity(Core::factory('Core_Xml_Entity')
->name('neighboring_items')
->addEntity(Core::factory('Core_Xml_Entity')->name('prev_item')->value($prev))
->addEntity(Core::factory('Core_Xml_Entity')->name('next_item')->value($next))
);
}

// Смотреть товары
if ($Shop_Controller_Show->item) {
   $view_item_id = $Shop_Controller_Show->item;
   if (Core_Entity::factory('Shop_Item', $view_item_id)->shop_id == $oShop->id) {
      Core_Session::start();
      if (isset($_SESSION['hostcmsViewed'][$oShop->id]) && in_array($view_item_id, $_SESSION['hostcmsViewed'][$oShop->id])) {
         unset($_SESSION['hostcmsViewed'][$oShop->id][
            array_search($view_item_id, $_SESSION['hostcmsViewed'][$oShop->id])
         ]);
      } else {
         $_SESSION['hostcmsViewed'][$oShop->id][] = $view_item_id;
      }
   }
}
// Текстовая информация для указания номера страницы, например "страница"
$pageName = Core_Array::get(Core_Page::instance()->libParams, 'page')
? Core_Array::get(Core_Page::instance()->libParams, 'page')
: 'страница';
// Разделитель в заголовке страницы
$pageSeparator = Core_Array::get(Core_Page::instance()->libParams, 'separator')
? Core_Page::instance()->libParams['separator']
: ' | ';

if ($Shop_Controller_Show->group) {
$oShop_Group = Core_Entity::factory('Shop_Group', $Shop_Controller_Show->group);
Core_Page::instance()->title($oShop_Group->seo_title != ''
? $oShop_Group->seo_title
: $oShop_Group->name);
Core_Page::instance()->description($oShop_Group->seo_description != ''
? $oShop_Group->seo_description
: $oShop_Group->name);
Core_Page::instance()->keywords($oShop_Group->seo_keywords != ''
? $oShop_Group->seo_keywords
: $oShop_Group->name);
}

if ($Shop_Controller_Show->item) {
$oShop_Item = Core_Entity::factory('Shop_Item', $Shop_Controller_Show->item);
Core_Page::instance()->title($oShop_Item->seo_title != ''
? $oShop_Item->seo_title
: $oShop_Item->name);
Core_Page::instance()->description($oShop_Item->seo_description != ''
? $oShop_Item->seo_description
: $oShop_Item->name);
Core_Page::instance()->keywords($oShop_Item->seo_keywords != ''
? $oShop_Item->seo_keywords
: $oShop_Item->name);
}

if ($Shop_Controller_Show->tag) {
$oTag = Core_Entity::factory('Tag', $Shop_Controller_Show->tag);
Core_Page::instance()->title($oTag->seo_title != ''
? $oTag->seo_title
: $oTag->name);
Core_Page::instance()->description($oTag->seo_description != ''
? $oTag->seo_description
: $oTag->name);
Core_Page::instance()->keywords($oTag->seo_keywords != ''
? $oTag->seo_keywords
: $oTag->name);
}

Core_Page::instance()->object = $Shop_Controller_Show;
#
Re: Вывод текущей метки в заголовке группы товаров по этой метке
А сам код ТДС такой:
<?php
$Shop_Controller_Show = Core_Page::instance()->object;
$xslName = $Shop_Controller_Show->item
? Core_Array::get(Core_Page::instance()->libParams, 'shopItemXsl')
: Core_Array::get(Core_Page::instance()->libParams, 'shopXsl');
$Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('ТекущаяГруппа')->value($Shop_Controller_Show->group))
->addEntity(Core::factory('Core_Xml_Entity')
->name('show_comments')->value(Core_Array::get(Core_Page::instance()->libParams, 'showComments', 1)))
->addEntity(Core::factory('Core_Xml_Entity')
->name('show_add_comments')->value(Core_Array::get(Core_Page::instance()->libParams, 'showAddComment', 2))
);
$Shop_Controller_Show
->tags(TRUE)
->comments(TRUE)
->associatedItems(TRUE)
->modifications(TRUE);
if ($Shop_Controller_Show->item == 0) {
$Shop_Controller_Show->itemsForbiddenTags(array('text'));
if (Core_Array::getGet('filter') || Core_Array::getGet('sorting')) {
$Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('filter')
->value(1)
);
$oShop = $Shop_Controller_Show->getEntity();
$sorting = intval(Core_Array::getGet('sorting'));
$Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('sorting')
->value($sorting)
);
$Shop_Controller_Show->addCacheSignature('sorting=' . $sorting);
// Цены
$price_from = intval(Core_Array::getGet('price_from'));
$price_to = intval(Core_Array::getGet('price_to'));
if ($price_from || $price_to || $sorting == 1 || $sorting == 2) {
// Получаем список валют магазина
$aShop_Currencies = Core_Entity::factory('Shop_Currency')->findAll();
$query_currency_switch = 'price';
foreach ($aShop_Currencies as $oShop_Currency) {
// Получаем коэффициент пересчета для каждой валюты
$currency_coefficient = Shop_Controller::instance()->getCurrencyCoefficientInShopCurrency(
$oShop_Currency, $oShop->Shop_Currency
);
$query_currency_switch = "IF (`shop_items`.`shop_currency_id` = '{$oShop_Currency->id}', IF (shop_discounts.percent, price * (100 - shop_discounts.percent) * {$currency_coefficient} / 100, shop_items.price * {$currency_coefficient}), {$query_currency_switch})";
}
$current_date = date('Y-m-d H:i:s');
$Shop_Controller_Show->shopItems()
->queryBuilder()
->select(array(Core_QueryBuilder::expression($query_currency_switch), 'absolute_price'))
->leftJoin('shop_item_discounts', 'shop_items.id', '=', 'shop_item_discounts.shop_item_id')
->leftJoin('shop_discounts', 'shop_item_discounts.shop_discount_id', '=', 'shop_discounts.id', array(
array('AND (' => array('shop_discounts.end_datetime', '>=', $current_date)),
array('OR' => array('shop_discounts.end_datetime', '=', '0000-00-00 00:00:00')),
array('AND' => array('shop_discounts.start_datetime', '<=', $current_date)),
array(')' => NULL)
));
if ($price_from) {
$Shop_Controller_Show->shopItems()->queryBuilder()->having('absolute_price', '>=', $price_from) && $Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('price_from')->value($price_from)
);
$Shop_Controller_Show->addCacheSignature('price_from=' . $price_from); }
if ($price_to) {
$Shop_Controller_Show->shopItems()->queryBuilder()->having('absolute_price', '<=', $price_to);
$Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('price_to')->value($price_to)
);
$Shop_Controller_Show->addCacheSignature('price_to=' . $price_to); }
$Shop_Controller_Show->shopItems()->queryBuilder()
->clearOrderBy()
->orderBy('absolute_price', $sorting == 1 ? 'ASC' : 'DESC');
}
$sorting == 3 && $Shop_Controller_Show->shopItems()->queryBuilder()
->clearOrderBy()
->orderBy('shop_items.name', 'ASC');
// Дополнительные свойства
$oShop_Item_Property_List = Core_Entity::factory('Shop_Item_Property_List', $oShop->id);
$aProperties = $Shop_Controller_Show->group !== FALSE && is_null($Shop_Controller_Show->tag)
? $oShop_Item_Property_List->getPropertiesForGroup($Shop_Controller_Show->group)
: $oShop_Item_Property_List->Properties->findAll();
$aTmpProperties = array();
$havingCount = 0;
foreach ($aProperties as $oProperty) {
// Св-во может иметь несколько значений
$aPropertiesValue = Core_Array::getGet('property_' . $oProperty->id);
if ($aPropertiesValue) {
!is_array($aPropertiesValue) && $aPropertiesValue = array($aPropertiesValue);
foreach ($aPropertiesValue as $sPropertyValue) {
$aTmpProperties[] = array($oProperty, strval($sPropertyValue));
}
$havingCount++;
}
elseif (!is_null(Core_Array::getGet('property_' . $oProperty->id . '_from'))) {
// From ... to ...
$aTmpProperties[] = array($oProperty, array(
'from' => intval(Core_Array::getGet('property_' . $oProperty->id . '_from')),
'to' => intval(Core_Array::getGet('property_' . $oProperty->id . '_to'))
));
$havingCount++;
}}
if (count($aTmpProperties)) {
$aTableNames = array();
$Shop_Controller_Show->shopItems()->queryBuilder()
->leftJoin('shop_item_properties', 'shop_items.shop_id', '=', 'shop_item_properties.shop_id')
->setAnd()
->open();
reset($aTmpProperties);
while(list(, list($oProperty, $propertyValue)) = each($aTmpProperties)) {
$tableName = $oProperty->createNewValue(0)->getTableName();
!in_array($tableName, $aTableNames) && $aTableNames[] = $tableName;
$Shop_Controller_Show->shopItems()->queryBuilder()
->where('shop_item_properties.property_id', '=', $oProperty->id);
if (!is_array($propertyValue)) {
// Для строк фильтр LIKE %...%
if ($oProperty->type == 1) {
$Shop_Controller_Show->shopItems()->queryBuilder()
->where($tableName . '.value', 'LIKE', "%{$propertyValue}%");
}
else {
// Checkbox
$oProperty->type == 7 && $propertyValue != '' && $propertyValue = 1;
$Shop_Controller_Show->shopItems()->queryBuilder()
->where($tableName . '.value', '=', $propertyValue);
}
$Shop_Controller_Show->shopItems()->queryBuilder()
->setOr();
$Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('property_' . $oProperty->id)->value($propertyValue)
);
$Shop_Controller_Show->addCacheSignature("property{$oProperty->id}={$propertyValue}");
}
else {
$from = trim(strval(Core_Array::get($propertyValue, 'from')));
$from && $Shop_Controller_Show->shopItems()->queryBuilder()
->where($tableName . '.value', '>=', $from)
->setAnd();
$to = trim(strval(Core_Array::get($propertyValue, 'to')));
$to && $Shop_Controller_Show->shopItems()->queryBuilder()
->where($tableName . '.value', '<=', $to);
$Shop_Controller_Show->shopItems()->queryBuilder()
->setOr();
$Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('property_' . $oProperty->id . '_from')
->value($from)
)->addEntity(Core::factory('Core_Xml_Entity')
->name('property_' . $oProperty->id . '_to')->value($to)
);
$Shop_Controller_Show
->addCacheSignature("property{$oProperty->id}_from={$from}")
->addCacheSignature("property{$oProperty->id}_to={$to}");
}}
$Shop_Controller_Show->shopItems()->queryBuilder()
->close()
->groupBy('shop_items.id')
->having(Core_Querybuilder::expression('COUNT(DISTINCT `shop_item_properties`.`property_id`)'), '=', $havingCount);
foreach ($aTableNames as $tableName) {
$Shop_Controller_Show->shopItems()->queryBuilder()
->leftJoin($tableName, 'shop_items.id', '=', $tableName . '.entity_id',
array(
array('AND' => array('shop_item_properties.property_id', '=', Core_QueryBuilder::expression($tableName . '.property_id')))
)
);
}}}}
else {
if (Core_Array::getPost('add_comment') && Core_Array::get(Core_Page::instance()->libParams, 'showComments', 1)) {
$oShop = $Shop_Controller_Show->getEntity();
$Shop_Controller_Show->cache(FALSE);
$oLastComment = Core_Entity::factory('Comment')->getLastCommentByIp(Core_Array::get($_SERVER, 'REMOTE_ADDR')
);
$oXmlCommentTag = Core::factory('Core_Xml_Entity')
->name('document');
$siteuser_id = 0;
if (Core::moduleIsActive('siteuser')) {
$oSiteuser = Core_Entity::factory('Siteuser')->getCurrent();
if ($oSiteuser) {
$siteuser_id = $oSiteuser->id;
}}
$oComment = Core_Entity::factory('Comment');
$allowable_tags = '<b><strong><i><em><br><p><u><strike><ul><ol><li>';
$oComment->parent_id = intval(Core_Array::getPost('parent_id', 0));
$oComment->active = $oShop->comment_active;
$oComment->author = Core_Str::stripTags(Core_Array::getPost('author'));
$oComment->email = Core_Str::stripTags(Core_Array::getPost('email'));
$oComment->phone = Core_Str::stripTags(Core_Array::getPost('phone'));
$oComment->grade = intval(Core_Array::getPost('grade', 0));
$oComment->subject = Core_Str::stripTags(Core_Array::getPost('subject'));
$oComment->text = nl2br(Core_Str::stripTags(Core_Array::getPost('text'), $allowable_tags));
$oComment->siteuser_id = $siteuser_id;
$oShop_Item = Core_Entity::factory('Shop_Item', $Shop_Controller_Show->item);
$oXmlCommentTag
->addEntity($oComment)
->addEntity($oShop_Item);
if (is_null($oLastComment) || time() > Core_Date::sql2timestamp($oLastComment->datetime) + ADD_COMMENT_DELAY) {
if ($oShop->use_captcha == 0 || $siteuser_id > 0 || Core_Captcha::valid(Core_Array::getPost('captcha_id'), Core_Array::getPost('captcha'))) {
$oComment->save();
$oShop_Item->add($oComment);
$oXmlCommentTag->addEntity($oShop);
// Отправка письма администратору
$sText = Xsl_Processor::instance()
->xml($oXmlCommentTag->getXml())
->xsl(Core_Entity::factory('Xsl')->getByName(Core_Array::get(Core_Page::instance()->libParams, 'addCommentAdminMailXsl')))
->process();
Core_Mail::instance()
->to(EMAIL_TO)
->from(Core_Valid::email($oComment->email)
? $oComment->email
: EMAIL_TO
)
->subject(Core::_('Shop.comment_mail_subject'))
->message(trim($sText))
->contentType(Core_Array::get(Core_Page::instance()->libParams, 'commentMailNoticeType', 0) == 0
? 'text/plain'
: 'text/html'
)
->send();
}
else {
$oXmlCommentTag->addEntity(Core::factory('Core_Xml_Entity')
->name('error_captcha')->value(1)
);
$oComment->text = Core_Str::br2nl($oComment->text);
$Shop_Controller_Show->addEntity($oComment);
}}
else {
$oXmlCommentTag->addEntity(Core::factory('Core_Xml_Entity')
->name('error_time')->value(1)
);
$oComment->text = Core_Str::br2nl($oComment->text);
$Shop_Controller_Show->addEntity($oComment);
}
// Результат добавления комментария
$xsl_result = Xsl_Processor::instance()
->xml($oXmlCommentTag->getXml())
->xsl(Core_Entity::factory('Xsl')->getByName(Core_Array::get(Core_Page::instance()->libParams, 'addCommentNoticeXsl')))
->process();
$Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('message')->value($xsl_result)
);
}}
// В корне выводим из всех групп
/*if ($Shop_Controller_Show->group == 0) {
$Shop_Controller_Show->group(FALSE);}*/


$oShop_Item = Core_Entity::factory('Shop_Item', $Shop_Controller_Show->item);
$oTag_Shop_Items = $oShop_Item->Tag_Shop_Items->findAll();
// Минимальное количество тегов для совпадения.
$iSameTags = 3;
$aTagIds = array();
foreach($oTag_Shop_Items as $oTag_Shop_Item) {
$aTagIds[] = $oTag_Shop_Item->tag_id;
} if (count($aTagIds)) {
$oSameTag_Shop_Items = Core_Entity::factory('Tag_Shop_Item');
$oSameTag_Shop_Items->queryBuilder()
->select('tag_shop_items.*')
->where('tag_id', 'IN', $aTagIds)
->where('tag_shop_items.shop_item_id', '!=', $oShop_Item->id)
->join('shop_items', 'tag_shop_items.shop_item_id', '=', 'shop_items.id')
->join('shops', 'shop_items.shop_id', '=', 'shops.id')
->where('shops.site_id', '=', CURRENT_SITE)
->groupBy('shop_items.id')
->having('COUNT(tag_id)', '>=', $iSameTags)
->clearOrderBy()
->orderBy('RAND()')
->limit(4);
$aSameTag_Shop_Items = $oSameTag_Shop_Items->findAll();
$oXmlSamenews = Core::factory('Core_Xml_Entity')->name('samenews');
$Shop_Controller_Show->addEntity($oXmlSamenews);
foreach($aSameTag_Shop_Items as $oSameTag_Shop_Item) {
$oXmlSamenews->addEntity($oSameTag_Shop_Item->Shop_Item->clearEntities());
}}


$Shop_Controller_Show
->xsl( Core_Entity::factory('Xsl')->getByName($xslName) )
->itemsProperties(TRUE)
->show();
#
Re: Вывод текущей метки в заголовке группы товаров по этой метке
Дело в том, что конкретно сейчас просто пустой TITLE.
Например, по метке "стиль Прованс".
#
Re: Вывод текущей метки в заголовке группы товаров по этой метке
Dmitry K.,
Вы не верное получаете объект  
$oTag = Core_Entity::factory('Tag', $Shop_Controller_Show->tag);

Нужно так:
$oTag = Core_Entity::factory('Tag')->getByPath($Shop_Controller_Show->tag);
skype: mcross82
#
Re: Вывод текущей метки в заголовке группы товаров по этой метке
Mcross, Вы гений! Теперь всё работает как надо.
Большое спасибо!
#
Re: Вывод текущей метки в заголовке группы товаров по этой метке
Пожалуйста.
skype: mcross82
Авторизация