Смена картинок по наведению мыши в карточке товара Virtuemart 2

Почему-то по умолчанию такой возможности в Virtuemart 2 не предусмотрено. Но нам ли быть в печали? jQuery уже прикручен, что же нам еще надо. Поехали.

Чтобы заюзать сию фичу, открываем файл с шаблоном карточки товара \components\com_virtuemart\views\productdetails\tmpl\default.php и в самом начале ищем код, начинающийся ориентировочно с 29 строки:

$document->addScriptDeclaration("
jQuery(document).ready(function($) {
   $('a.ask-a-question').click( function(){
   $.facebox({
      iframe: '".$url."',
      rev: 'iframe

—> Вот тут текст статьи обрезался… Почему — не известно. Возможно, это случилось из-за кривого переезда. Спасибо серге за то, что обратил внимание 🙂

В общем, дополняю в двух словах:

Вот этот кусок

$('a.ask-a-question').click( function(){

как раз нам и нужен. Тут вместо «click» надо поставить «mouseOver»

Вот и все. То есть, вместо события click, скрипт будет реагировать на движение мыши над ссылкой.


0

Смена картинок по наведению мыши в карточке товара Virtuemart 2: 6 комментариев

  1. Владислав

    Подскажите пожалуйста.
    Кручу на локалке сайт Joomla 2.5.28 + Virtuemart 2.6.22
    не получается сделать этот эффект при наведении мыши. Код отличается от того что у вас в примере.

    1. Владислав

      product)) {
      echo JText::_('COM_VIRTUEMART_PRODUCT_NOT_FOUND');
      echo ' ' . $this->continue_link_html;
      return;
      }

      if(JRequest::getInt('print',false)){
      ?>

      product->virtuemart_product_id . '&virtuemart_category_id=' . $this->product->virtuemart_category_id . '&tmpl=component';

      $boxFuncReco = '';
      $boxFuncAsk = '';
      if(VmConfig::get('usefancy',1)){
      vmJsApi::js( 'fancybox/jquery.fancybox-1.3.4.pack');
      vmJsApi::css('jquery.fancybox-1.3.4');
      if(VmConfig::get('show_emailfriend',0)){
      $boxReco = "jQuery.fancybox({
      href: '" . $MailLink . "',
      type: 'iframe',
      height: '550'
      });";
      }
      if(VmConfig::get('ask_question', 0)){
      $boxAsk = "jQuery.fancybox({
      href: '" . $this->askquestion_url . "',
      type: 'iframe',
      height: '550'
      });";
      }

      } else {
      vmJsApi::js( 'facebox' );
      vmJsApi::css( 'facebox' );
      if(VmConfig::get('show_emailfriend',0)){
      $boxReco = "jQuery.facebox({
      iframe: '" . $MailLink . "',
      rev: 'iframe|550|550'
      });";
      }
      if(VmConfig::get('ask_question', 0)){
      $boxAsk = "jQuery.facebox({
      iframe: '" . $this->askquestion_url . "',
      rev: 'iframe|550|550'
      });";
      }
      }
      if(VmConfig::get('show_emailfriend',0) ){
      $boxFuncReco = "jQuery('a.recommened-to-friend').click( function(){
      ".$boxReco."
      return false ;
      });";
      }
      if(VmConfig::get('ask_question', 0)){
      $boxFuncAsk = "jQuery('a.ask-a-question').click( function(){
      ".$boxAsk."
      return false ;
      });";
      }

      if(!empty($boxFuncAsk) or !empty($boxFuncReco)){
      $document = JFactory::getDocument();
      $document->addScriptDeclaration("
      //
      ");
      }

      ?>

      product->neighbours ['previous'][0])) {
      $prev_link = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $this->product->neighbours ['previous'][0] ['virtuemart_product_id'] . '&virtuemart_category_id=' . $this->product->virtuemart_category_id, FALSE);
      echo JHTML::_('link', $prev_link, $this->product->neighbours ['previous'][0]
      ['product_name'], array('rel'=>'prev', 'class' => 'previous-page'));
      }
      if (!empty($this->product->neighbours ['next'][0])) {
      $next_link = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $this->product->neighbours ['next'][0] ['virtuemart_product_id'] . '&virtuemart_category_id=' . $this->product->virtuemart_category_id, FALSE);
      echo JHTML::_('link', $next_link, $this->product->neighbours ['next'][0] ['product_name'], array('rel'=>'next','class' => 'next-page'));
      }
      ?>

      product->virtuemart_category_id) {
      $catURL = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$this->product->virtuemart_category_id, FALSE);
      $categoryName = $this->product->category_name ;
      } else {
      $catURL = JRoute::_('index.php?option=com_virtuemart');
      $categoryName = jText::_('COM_VIRTUEMART_SHOP_HOME') ;
      }
      ?>

      <a href="" class="product-details" title="">

      product->product_name ?>

      product->event->afterDisplayTitle ?>

      edit_link;
      // Product Edit Link END
      ?>

      product->virtuemart_product_id;

      echo $this->linkIcon($link . '&format=pdf', 'COM_VIRTUEMART_PDF', 'pdf_button', 'pdf_icon', false);
      echo $this->linkIcon($link . '&print=1', 'COM_VIRTUEMART_PRINT', 'printButton', 'show_printicon');
      echo $this->linkIcon($MailLink, 'COM_VIRTUEMART_EMAIL', 'emailButton', 'show_emailfriend', false,true,false,'class="recommened-to-friend"');
      ?>

      product->product_s_desc)) {
      ?>

      product->product_s_desc);
      ?>

      product->customfieldsSorted['ontop'])) {
      $this->position = 'ontop';
      echo $this->loadTemplate('customfields');
      } // Product Custom ontop end
      ?>

      loadTemplate('images');
      ?>

      product->virtuemart_vendor_id);
      $text = JText::_('COM_VIRTUEMART_VENDOR_FORM_INFO_LBL');
      echo ''. JText::_('COM_VIRTUEMART_PRODUCT_DETAILS_VENDOR_LBL'). ''; ?><a class="modal" href="">
      */
      ?>

      showRating) {
      $maxrating = VmConfig::get('vm_maximum_rating_scale', 5);

      if (empty($this->rating)) {
      ?>

      rating->rating * 24; //I don't use round as percetntage with works perfect, as for me
      ?>

      rating->rating) . '/' . $maxrating; ?>
      <span title=" rating->rating) . '/' . $maxrating) ?>" class="ratingbox" style="display:inline-block;">
      <span class="stars-orange" style="width:">

      productDisplayShipments)) {
      foreach ($this->productDisplayShipments as $productDisplayShipment) {
      echo $productDisplayShipment . '';
      }
      }
      if (is_array($this->productDisplayPayments)) {
      foreach ($this->productDisplayPayments as $productDisplayPayment) {
      echo $productDisplayPayment . '';
      }
      }
      // Product Price
      // the test is done in show_prices
      //if ($this->show_prices and (empty($this->product->images[0]) or $this->product->images[0]->file_is_downloadable == 0)) {
      echo $this->loadTemplate('showprices');
      //}
      ?>

      product->prices) and !empty($this->product->images[0]) and $this->product->images[0]->file_is_downloadable==0 ) {
      // if (!VmConfig::get('use_as_catalog', 0) and !empty($this->product->prices['salesPrice'])) {
      echo $this->loadTemplate('addtocart');
      // } // Add To Cart Button END
      ?>

      product->product_available_date,0,10);
      $current_date = date("Y-m-d");
      if (($this->product->product_in_stock - $this->product->product_ordered) < 1) {
      if ($product_available_date != '0000-00-00' and $current_date
      product->product_available_date, JText::_('DATE_FORMAT_LC4')); ?>

      product->product_availability)) {
      ?>
      'availability')) : JText::_(VmConfig::get('rised_availability')); ?>

      product->product_availability)) {
      ?>

      product->product_availability)) ? JHTML::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' . $this->product->product_availability, $this->product->product_availability, array('class' => 'availability')) : JText::_($this->product->product_availability); ?>

      <?php
      }
      }
      else if ($product_available_date != '0000-00-00' and $current_date
      product->product_available_date, JText::_('DATE_FORMAT_LC4')); ?>

      <a class="ask-a-question" href="askquestion_url ?>" rel="nofollow" >
      <!--<a class="ask-a-question modal" rel="{handler: 'iframe', size: {x: 700, y: 550}}" href="askquestion_url ?>">-->

      product->virtuemart_manufacturer_id)) {
      echo $this->loadTemplate('manufacturer');
      }
      ?>

      product->event->beforeDisplayContent; ?>

      product->product_desc)) {
      ?>

      product->product_desc; ?>

      product->customfieldsSorted['normal'])) {
      $this->position = 'normal';
      echo $this->loadTemplate('customfields');
      } // Product custom_fields END
      // Product Packaging
      $product_packaging = '';
      if ($this->product->product_box) {
      ?>

      product->product_box;
      ?>

      product->images as $fkey => $file) {
      // Todo add downloadable files again
      // if( $file->filesize > 0.5) $filesize_display = ' ('. number_format($file->filesize, 2,',','.')." MB)";
      // else $filesize_display = ' ('. number_format($file->filesize*1024, 2,',','.')." KB)";

      /* Show pdf in a new Window, other file types will be offered as download */
      // $target = stristr($file->file_mimetype, "pdf") ? "_blank" : "_self";
      // $link = JRoute::_('index.php?view=productdetails&task=getfile&virtuemart_media_id='.$file->virtuemart_media_id.'&virtuemart_product_id='.$this->product->virtuemart_product_id);
      // echo JHTMl::_('link', $link, $file->file_title.$filesize_display, array('target' => $target));
      // }
      if (!empty($this->product->customfieldsRelatedProducts)) {
      echo $this->loadTemplate('relatedproducts');
      } // Product customfieldsRelatedProducts END

      if (!empty($this->product->customfieldsRelatedCategories)) {
      echo $this->loadTemplate('relatedcategories');
      } // Product customfieldsRelatedCategories END
      // Show child categories
      if (VmConfig::get('showCategory', 1)) {
      echo $this->loadTemplate('showcategory');
      }
      if (!empty($this->product->customfieldsSorted['onbot'])) {
      $this->position='onbot';
      echo $this->loadTemplate('customfields');
      } // Product Custom ontop end
      ?>

      product->event->afterDisplayContent; ?>

      loadTemplate('reviews');

      echo vmJsApi::writeJS();

      ?>

    2. merinovkv Автор записи

      В целом, суть проблемы, похоже, ясна. Есть мнение, что у вас где-то в js файле, или в сидит этот (похожий) код.
      Вот это: $(‘a.ask-a-question’).click( function(){
      у вас может быть другим (скорее всего, так оно и есть).

      1. Владислав

        У меня есть только такая конструкция:
        if(VmConfig::get(‘ask_question’, 0)){
        $boxFuncAsk = «jQuery(‘a.ask-a-question’).mouseover( function(){
        «.$boxAsk.»
        return false ;
        });»;
        }
        и только в \components\com_virtuemart\views\productdetails\tmpl\default.php

        а само значение a.ask-a-question — Total находит только в:
        \components\com_virtuemart\assets\css\vmsite-ltr.css (удалял не помогает)
        \components\com_virtuemart\views\productdetails\tmpl\default.php (изменил на mouseOver — по наведению не работает 🙁 )

Добавить комментарий