2016-11-01 50 views
0

類別,因爲2012年左右沒有繼承老Joomla網站1 2.5've升級,現在VirtueMart 3.6.4 3.0.16(使用PHP7.0)。VirtueMart的搜索結果指向產品詳情頁面

的Joomla搜索模塊的結果顯示爲:

[Lorem存有產品鏈接]
Lorem存有胡蘿蔔,生態番茄湯。茉莉花層是肯定的,比一個週末的下午。科學家們大量攝影和蛋白質產品說明。

除產品稱號的超級鏈接錯誤地指向了產品類別,而不是商品詳細頁。

1相信1已經找到了問題,在此位置:/plugins/search/virtuemart/virtuemart.php。約。線223

$row->virtuemart_product_id . '&virtuemart_category_id=' . $row->cat_id; 

1不知道如何改變PHP到正確的格式爲指向產品本身。 1試圖改變從產品類別到這個聲明的語言,但是這會導致產品結構相匹配的鏈接。

:如何可以編輯這個文件,使產品的標題鏈接指向實際的產品詳細信息頁面,而不是類別?

<?php 

/** 
* 
* A search plugin for com_search 
* 
* @author Valérie Isaksen 
* @author Samuel Mehrbrodt 
* @version $Id: authorize.php 5122 2011-12-18 22:24:49Z alatak $ 
* @package VirtueMart 
* @subpackage search 
* @copyright Copyright (C) 2004-2008 soeren - All rights reserved. 
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php 
* VirtueMart is free software. This version may have been modified pursuant 
* to the GNU General Public License, and as distributed it includes or 
* is derivative of works licensed under the GNU General Public License or 
* other free or open source software licenses. 
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details. 
* 
* http://virtuemart.net 
* @modified by Jeno Kovacs --- Offlajn.com 2014 
* @description image & price support for Universal AJAX Live Search 
*/ 
// no direct access 
defined ('_JEXEC') or die('Restricted access'); 

class PlgSearchVirtuemart extends JPlugin { 
    /** 
    * @return array An array of search areas 
    */ 
    function onContentSearchAreas() { 
     $this->loadLanguage(); 
     static $areas = array(
      'virtuemart' => 'PLG_SEARCH_VIRTUEMART_PRODUCTS' 
     ); 
     return $areas; 
    } 

    /** 
    * Content Search method 
    * The sql must return the following fields that are used in a common display 
    * routine: href, title, section, created, text, browsernav 
    * 
    * @param string $text Target search string 
    * @param string $phrase matching option, exact|any|all 
    * @param string $ordering ordering option, newest|oldest|popular|alpha|category 
    * @param mixed $areas An array if the search it to be restricted to areas, null if search all 
    * 
    * @return array An array of database result objects 
    */ 
    function onContentSearch ($text, $phrase = '', $ordering = '', $areas = NULL) { 
     $db = JFactory::getDbo(); 

     if (is_array($areas)) { 
      if (!array_intersect ($areas, array_keys ($this->onContentSearchAreas()))) { 
       return array(); 
      } 
     } 

     $limit = $this->params->get('search_limit', 50); 
     switch($this->params->get('subtitledisplay', '1')) { 
      case '1': 
       $category_field = 'category_name'; 
       break; 
      case '2': 
       $category_field = 'customtitle'; 
       break; 
     } 
     $search_product_description = (bool) $this->params->get('enable_product_description_search', TRUE); 
     $search_product_s_description = (bool) $this->params->get('enable_product_short_description_search', TRUE); 
     $search_customfields = (bool) $this->params->get('enable_customfields', TRUE); 
     $customfield_ids_condition = ""; 
     if ($search_customfields) { 
      $value = trim($this->params->get('customfields', "")); 

      // Remove all spaces 
      $value = str_replace(' ', '', $value); 
      if (!empty($value)){ 
       $customfield_ids = explode(",", $value); 

       // Make sure we have only integers 
       foreach($customfield_ids as &$id) { 
        $id = intval($id); 
       } 
       // The custom field ID must be either in the list specified or NULL. 
       $customfield_ids_condition = "AND cf.virtuemart_custom_id IN (" . 
        implode(',', $customfield_ids) . ")"; 
      } 

     } 

     if (!class_exists('VmConfig')) { 

     // FIX THE MISSING DS ERROR ON JOOMLA 3 VM BETTER SEARCH PLUGIN : https://forum.virtuemart.net/index.php?topic=125681.0 
     defined('DS') or define('DS', DIRECTORY_SEPARATOR); 

     require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'config.php'); 
     } 
     VmConfig::loadConfig(); 

     $text = trim($text); 
     if (empty($text)) 
      return array(); 

     switch ($phrase) { 
      case 'exact': 
       $wheres2 = array(); 
       // product_sku should be exact match 
       $text = $db->quote("%$text%", TRUE); 
       $wheres2[] = "p.product_sku LIKE $text"; 
       $wheres2[] = "a.product_name LIKE $text"; 
       $wheres2[] = "b.$category_field LIKE $text"; 
       if ($search_product_s_description) 
        $wheres2[] = "a.product_s_desc LIKE $text"; 
       if ($search_product_description) 
        $wheres2[] = "a.product_desc LIKE $text"; 
       if ($search_customfields) 
        $wheres2[] = "(cf.customfield_value LIKE $text $customfield_ids_condition)"; 
       $where = '(' . implode (') OR (', $wheres2) . ')'; 
       break; 
      case 'all': 
      case 'any': 
      default: 
       $words = explode (' ', $text); 
       $wheres = array(); 
       foreach ($words as $word) { 
        $wheres2 = array(); 
        // product_sku should be exact match 
      $word = $db->quote("%$word%", TRUE); 
        $wheres2[] = "p.product_sku LIKE $word";      
        $wheres2[] = "a.product_name LIKE $word"; 
        $wheres2[] = "b.$category_field LIKE $word"; 
        if ($search_product_s_description) 
         $wheres2[] = "a.product_s_desc LIKE $word"; 
        if ($search_product_description) 
         $wheres2[] = "a.product_desc LIKE $word"; 
        if ($search_customfields) 
         $wheres2[] = "(cf.customfield_value LIKE $word $customfield_ids_condition)"; 

        $wheres[] = implode (' OR ', $wheres2); 
       } 
       $where = '(' . implode (($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')'; 
       break; 
     } 
     switch($ordering) { 
      case 'alpha': 
       $order = 'a.product_name ASC'; 
       break; 
      case 'category': 
       $order = 'b.category_name ASC, a.product_name ASC'; 
       break; 
      case 'popular': 
       $order = 'a.product_name ASC'; 
       break; 
      case 'newest': 
       $order = 'p.created_on DESC'; 
       break; 
      case 'oldest': 
       $order = 'p.created_on ASC'; 
       break; 
      default: 
       $order = 'a.product_name ASC'; 
     } 

     $shopper_group_condition=""; 
     $currentVMuser = VmModel::getModel('user')->getUser(); 
     $virtuemart_shoppergroup_ids = (array)$currentVMuser->shopper_groups; 

     if (is_array($virtuemart_shoppergroup_ids)) { 
      $sgrgroups = array(); 
      foreach($virtuemart_shoppergroup_ids as $virtuemart_shoppergroup_id) { 
       $sgrgroups[] = 'psgr.`virtuemart_shoppergroup_id`= "' . (int)$virtuemart_shoppergroup_id . '" '; 
      } 
      $sgrgroups[] = 'psgr.`virtuemart_shoppergroup_id` IS NULL '; 
      $shopper_group_condition = " AND (" . implode (' OR ', $sgrgroups) . ") "; 
     } 

     $uncategorized_products_condition = VmConfig::get('show_uncat_child_products') ? 
      '' : ' AND b.virtuemart_category_id > 0 '; 

     $query = " 
       SELECT DISTINCT 
        a.product_name AS title, 
        a.product_s_desc AS text, 
        p.created_on as created, 
        p.published, 
        '2' AS browsernav, 
       (SELECT m.file_url AS path 
        FROM #__virtuemart_medias AS m 
        LEFT JOIN #__virtuemart_product_medias AS me ON m.virtuemart_media_id = me.virtuemart_media_id 
        WHERE me.virtuemart_product_id = a.virtuemart_product_id ORDER BY me.ordering ASC LIMIT 1) AS image, 
        GROUP_CONCAT(DISTINCT b.$category_field 
         ORDER BY b.$category_field SEPARATOR ', ') as section, 
        (SELECT pc2.virtuemart_category_id 
         FROM #__virtuemart_product_categories as pc2 
         WHERE pc2.virtuemart_product_id = a.virtuemart_product_id LIMIT 1) AS cat_id 
       FROM `#__virtuemart_products_" . VmConfig::$vmlang . "` AS a 
       JOIN #__virtuemart_products AS p USING (`virtuemart_product_id`) 
       LEFT JOIN `#__virtuemart_product_categories` AS xref 
         ON xref.`virtuemart_product_id` = a.`virtuemart_product_id` 
       LEFT JOIN `#__virtuemart_categories_" . VmConfig::$vmlang . "` AS b 
         ON b.`virtuemart_category_id` = xref.`virtuemart_category_id` 
       LEFT JOIN `#__virtuemart_product_shoppergroups` as `psgr` 
         ON (`psgr`.`virtuemart_product_id`=`a`.`virtuemart_product_id`) 
       LEFT JOIN `#__virtuemart_product_customfields` AS cf 
         ON cf.virtuemart_product_id = a.virtuemart_product_id 
       LEFT JOIN `#__virtuemart_customs` AS customs 
         ON customs.virtuemart_custom_id = cf.virtuemart_customfield_id 
       WHERE 
         ($where) 
         AND p.published='1' 
         $shopper_group_condition 
         $uncategorized_products_condition 
       GROUP BY xref.virtuemart_product_id 
       ORDER BY $order"; 
     $db->setQuery($query, 0, $limit); 
//echo $query; exit; 
     $rows = $db->loadObjectList(); 
     if ($rows) { 
      foreach ($rows as $key => $row) { 
       $rows[$key]->href = 'index.php?option=com_virtuemart&view=productdetails' . 
        // line below somehow changes search result links without changing title 
        $row->virtuemart_product_id . '&virtuemart_category_id=' . $row->cat_id; 
      $rows[$key]->price = $this->getPrice($row->virtuemart_product_id); 
      if($row->image != "" && (false === strpos($row->image, "stories"))) { 
      $rows[$key]->image = "images/stories/virtuemart/product/".$row->image; 
      }   
      } 
     } 
     return $rows; 
    } 

    function getPrice($pid) { 
    if (!class_exists('CurrencyDisplay')) { 
      require_once(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php'); 
    } 
    $product_model = VmModel::getModel('product'); 
    $currency = CurrencyDisplay::getInstance(); 
     $product = $product_model->getProduct($pid,TRUE,TRUE,TRUE,1); 
     $p = str_replace("PricesalesPrice", "", $currency->createPriceDiv ('salesPrice', '', $product->prices)); 
    return $p; 
    } 
} 

回答

0

僞我的解決辦法是從使用匹配的版本凌晨1點香草Virtuemart導入上述virtuemart.php下載文件。

提取的文件中com_virtuemart.3.0.14_ext_aio.zip發現:/admin/plugins/search/virtuemart/virtuemart.php。

創作的原創PHP文件爲.bak和下跌了在同一個位置。的Joomla搜索結果現在表現就像股票(沒有所有的自定義樣式)。

相關問題