Virtuemart Related Products incorrectly open in a new page

Support desk for Multipurpose Quark Theme
GK User
Thu Feb 25, 2016 5:40 pm
12/3 ecommerce quark quick install
www.ahgoobaby.com/Redesign3

VM action using the default template is to open related products in the same window. I just tried doing this on Quark and notice that it is opening on a new window in a separate tab. See: https://www.ahgoobaby.com/Redesign3/index.php/our-store/change/the-ark (scroll to bottom and click the changing pad cover as the visible related item).

I found a virtuemart forum post re-stating and advising the "product details template overrides need fixing. Compare the code with those of the default VM files in components/com_virtuemart/views/productdetails/tmpl/ - probably you need to look at default_relatedproducts.php"

Not sure if the above helps, but please advise how to get the related items links to open in the same browser window/tab instead of opening a new one.
User avatar
Expert Boarder

teitbite
Mon Feb 29, 2016 12:55 pm
Hi

Can You please show me what You have in mind exactly ? I'm clicking through Your page, but cannot see a link opening new page.
User avatar
Moderator

GK User
Mon Feb 29, 2016 9:37 pm
Sorry - the site just went live so the URL changed.

See here: http://www.ahgoobaby.com/index.php/our-store/change/385/22/the-wipes-case/the-wipes-case-bubbles-in-juice-detail. Related items are found by scrolling to the bottom of this page. Note how selecting one of the related items results in it appearing in a new tab. The preferred way is to have it all stay in the same tab. Its awkward while putting items in your cart to have multiple browser tabs open during the process.
User avatar
Expert Boarder

teitbite
Thu Mar 03, 2016 11:17 am
Hi

Your site has some extra password so I cannot login to joomla panel to check this issue. Please send it to me. Also FTP access could be helpful with this issue, so please send it as well if You can.
User avatar
Moderator

GK User
Thu Mar 03, 2016 11:16 pm
I have turned it off temporarily for you. Please let me know what lines of what files I might need to change if necessary and I can do that with your instructions. It should be simple code change as the hyperlink is loading a new tab instead of same/parent tab. Default template related item hyperlinks load the same/parent tab so it seems localized to the quark template code, so this should be able for you to replicate on your own demo quark site to determine the fix as well.
User avatar
Expert Boarder

teitbite
Tue Mar 08, 2016 11:40 am
Hi

It's surely not in our template. Here is a part of the code responsible for showing related products and as You can see it's using Virtuemart functions:

Code: Select all
     <?php
          // RELATED PRODUCTS
          $product = $this->product;
          $position = 'product-related-productsrelated_products';
          $customTitle = true;
          $class = 'product-related-products';
         
          if (!empty($product->customfieldsSorted[$position])) :
          ?>
     <div class="<?php echo $class?>">
          <?php
             if($customTitle and isset($product->customfieldsSorted[$position][0])) :
                $field = $product->customfieldsSorted[$position][0]; ?>
          <h4><?php echo vmText::_ ($field->custom_title) ?></h4>
          <?php endif; ?>
          <?php foreach ($product->customfieldsSorted[$position] as $field) : ?>
          <?php if ( $field->is_hidden ) continue; //OSP http://forum.virtuemart.net/index.php?topic=99320.0 ?>
          <div class="product-field product-field-type-<?php echo $field->field_type ?>">
               <?php if (!empty($field->display)) : ?>
               <span class="product-field-display"><?php echo $field->display ?></span>
               <?php endif; ?>
          </div>
          <?php $custom_title = $field->custom_title; ?>
          <?php endforeach ?>
     </div>
     <?php endif ?>


I think this should be configured in Virtuemart setting, so VM support may know more about it. Since I'm not VM expert I would use a trick to force it to work as we want to.

Add this at the end of /layout/blocks/head.php

Code: Select all
   <script type="text/javascript">(function($) {$(document).ready(function() {
        $('.product-field-display > a').each(function(){ $(this).removeAttr('target'); });
   });})(jQuery)</script>
User avatar
Moderator

GK User
Tue Mar 08, 2016 9:56 pm
There's a google code that is placed at the end of this head.php file that I think needs to be the last thing there. Do I place it after the google code script:

<script type="text/javascript" src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

or do I put it above the google script, just above:

<!--[if IE 9]>
<link rel="stylesheet" href="<?php echo $this->API->URLtemplate(); ?>/css/ie/ie9.css" type="text/css" />
<![endif]-->

I tried doing it above it and it didn't work. I don't want to mess any of the google stuff up so I didn't want to try putting it after the google script without you ok'ing it first. Please confirm whether nothing with google will break if i put it after the google code. That said, as noted, if before the code, this didn't work and I'll need a different idea.

To be clear, on the default template with a normal joomla install, the related items refresh the parent site tab and do not create a separate tab as they do in your template version of joomla, so it would appear to NOT be related to virtuemart. There are already posts on virtuemart with similar new tabs from related items on this and the answer is it is not native to virtuemart and the result of template overrides.
User avatar
Expert Boarder

teitbite
Mon Mar 14, 2016 2:32 pm
Hi

It doesn't matter if You will copy it above or below google code. Anyway right now I cannot see it added at all, so I cannot check why isn't it working.

It's divided into tabs by our template, that's correct, but our template doesn't add target="_blank" to related items, that part has to be included by VM or some 3rd party plugin. And this is the part I'm trying to overwrite with my code.

Please put the code back and let me know.
User avatar
Moderator

GK User
Mon Mar 14, 2016 10:14 pm
I've added the updated head.php file. Please check and let me know. Also to confirm in the event there is still an issue, I've attached the updated head.php file in zip for you to confirm I've done it right.
User avatar
Expert Boarder

teitbite
Fri Mar 18, 2016 9:35 am
Hi

Code looks good, but since I cannot see any product has related item right now than I'm not able to check why it can not work.

Anyway try replace code with this one:

Code: Select all
<script type="text/javascript">(function($) {$(document).ready(function() {
   function rmTarget() {
      $('.product-field-display > a').each(function(){ $(this).removeAttr('target'); });
      setTimeout( rmTarget, 1 );
   }

   $(rmTarget);
});})(jQuery)</script>


this code will work even if the script messing with related product links is loaded as a last script.
User avatar
Moderator

GK User
Fri Mar 18, 2016 8:32 pm
That did the trick! OK to close the thread.
User avatar
Expert Boarder

GK User
Fri Mar 18, 2016 8:36 pm
Just one side question if I might ask b/c the thread to the more relevant one I was working on was closed:

From the earlier thread you helped me eliminate a lot of unnecessary text in the related items as it was default as well as clean up the fonts and sizes of fonts. Is it possible to ADD in JUST the add to cart button on these related items? I'd like the customer to not have to otherwise refresh to a new product details screen if they are comfortable adding the various related items to cart right there.

I only have a few related items set up as I wanted to wait until the links were loading to the parent browser tab. You can see an example of it here: http://ahgoobaby.com/index.php/our-store/carry/206/23/the-bottle-strap/the-wipes-case-retro-daisy-detail
User avatar
Expert Boarder

teitbite
Tue Mar 22, 2016 2:08 pm
Hi

I believe everything is possible, but I'm afraid that such task requires a lot more codding and changes to template and this is beyond our support.
User avatar
Moderator


cron