抱歉我的英文不好,但我真的需要知道为什么这个插件根本不起作用。
所以我有Joomla 3.5.1 + JoomShopping 4.14.1
我想连接属性过滤器插件。但它不起作用。
请帮帮我!!!
<?php
// No direct access.
defined('_JEXEC') or die;
class plgJShoppingOxboxAttribsFilter extends JPlugin
{
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
}
public function onBeforeQueryCountProductList($controller, &$adv_result, &$adv_from, &$adv_query, &$order_query, &$filters = array())
{
$this->onBeforeQueryGetProductList($controller, &$adv_result, &$adv_from, &$adv_query, &$order_query, &$filters);
}
public function onBeforeQueryGetProductList($controller, &$adv_result, &$adv_from, &$adv_query, &$order_query, &$filters = array())
{
// Ïîëó÷àåì îáúåêò áàçû äàííûõ
$db = JFactory::getDBO();
//
$query = $db->getQuery(true);
//
$query->select('params');
//
$query->from('#__modules');
//
$query->where('module = "mod_oxbox_jshopping_attribute_filter"');
//
$query->where('published = 1');
//
$db->setQuery($query);
//
$list = $db->loadObjectList();
//
if (is_array($list) && count($list))
{
//
foreach ($list as $item)
{
//
$registry = new JRegistry();
//
$registry->loadString($item->params);
//
$item->params = $registry->toArray();
// Ïîëó÷àåì çíà÷åíèå
$vals = JRequest::getVar($item->params->get('param_name'), '');
//
$vals = urldecode($vals);
// Åñëè çíà÷åíèå íå ïóñòîå
if (!empty($vals))
{
// Åñëè ñîäåðæèò òî÷êó ñ çàïÿòîé
if (JString::strpos($vals, ';'))
{
// Ïðåîáðàçóåì â ìàññèâ
$vals = explode(';', $vals);
}
// Åñëè â ìàññèâå òîëüêî îäèí ýëåìåíò
if (is_array($vals) && count($vals) == 1)
{
//
$vals = $vals[1];
}
//
$attr_id = $item->params->get('attr_id');
//
$db->setQuery('SELECT independent FROM #__jshopping_attr WHERE attr_id = '.$attr_id);
// Ïîëó÷àåì ðåçóëüòàò
$independent = $db->loadResult();
// Åñëè àòðèáóò íåçàâèñèìûé
if ($independent)
{
$table = '#__jshopping_products_attr2';
$attr_value_id_field = 'attr_value_id';
}
else
{
$table = '#__jshopping_products_attr';
$attr_value_id_field = 'attr_'.$attr_id;
}
// Åñëè ôèëüòðóåì ïî çíà÷åíèÿì àòðèáóòîâ
if ($item->params->get('param_type', 'value') == 'value')
{
// Åñëè ýòî ìàññèâ
if (is_array($vals))
{
$adv_query .= 'AND prod.product_id IN (SELECT product_id FROM `'.$table.'` AS attr LEFT JOIN #__jshopping_attr_values AS attr_values ON attr_values.value_id = attr.'.$attr_value_id_field.' WHERE `name_ru-RU` in ('.implode(',', $vals).'))';
}
else
{
$adv_query .= 'AND prod.product_id IN (SELECT product_id FROM `'.$table.'` AS attr LEFT JOIN #__jshopping_attr_values AS attr_values ON attr_values.value_id = attr.'.$attr_value_id_field.' WHERE `name_ru-RU`="'.$vals.'")';
}
}
else // èíà÷å ôèëüòðóåì ïî èäåíòèôèêàòîðàì çíà÷åíèé àòðèáóòîâ
{
// Åñëè ýòî ìàññèâ
if (is_array($vals))
{
$adv_query .= ' AND prod.product_id IN (SELECT product_id FROM `'.$table.'` AS attr WHERE attr.'.$attr_value_id_field.' in ('.implode(',', $vals).'))';
}
else
{
$adv_query .= ' AND prod.product_id IN (SELECT attr.product_id FROM `'.$table.'` AS attr WHERE attr.'.$attr_value_id_field.' = '.$vals.')';
}
}
}
}
}
}
}