product-url in related products is linked to wrong direction

Started by old_fritz, September 29, 2013, 00:31:49 AM

Previous topic - Next topic

old_fritz

hi there,

i got a problem with a customized code of the related products in product details view.
the related products are shown an image of the related product and the price of it - that works alright.
the customization a link to an external url is shown but it linked to the url of the product, which is shown (as the bright image) above the related product.

here´s the complete code of the related_products.php:

<?php defined '_JEXEC' ) or die ( 'Restricted access' ); 
$model = new VirtueMartModelProduct();
$calculator calculationHelper::getInstance();
$currency CurrencyDisplay::getInstance();

$iCol 1;
$iItem 1;
$items_per_row 4;
$item_cellwidth ' width' floor(100 $items_per_row);
$verticalseparator " vertical-separator";

?>

<div class="related-items">
<h3 class="related-title"><?php echo JText::_('COM_VIRTUEMART_RELATED_PRODUCTS'); ?></h3>
<?php foreach ($this->product->customfieldsRelatedProducts as $field) { 
if ($iCol == && $iItem $items_per_row) {?>

    <div class="horizontal-separator"></div>
<?php }
if ($iCol == 1) { ?>

<div class="row">
    <?php }
    if ($iItem == $items_per_row or $iItem $items_per_row == 0) {
$show_vertical_separator ' ';
    } else {
$show_vertical_separator $verticalseparator;
    } ?>


<div class="product-field product-field-type-<?php echo $field->field_type ?> floatleft<?php echo $item_cellwidth $show_vertical_separator ?>">
<div class="spacer">
<span class="product-field-display"><?php echo $field->display ?></span>
</div>
</div>
<div class="spacer">
    <span class="product-field-desc"><?php


$product 
$model->getProductSingle($field->custom_value,false);
$price $calculator -> getProductPrices($product);
echo 
$currency->priceDisplay($price['salesPrice']);


?>
</span>


  <div class="addtocart-bar">

<a target="_blank" <?php echo JHTML::link ($this->product->product_url,  JText::_('zum Shop'), array('title' => $product->product_name,'class' => 'product-details')) ?></a>


<?php  if (!empty($this->product->customfieldsSorted['ontops'])) {
   
$this->position 'ontops';
   echo 
$this->loadTemplate('customfields');
    } 
// Product Custom ontops end
    
?>


    </div>


<?php 
$iItem++;
if ($iCol == $items_per_row) {
    ?>

<div class="clear"></div>
</div>
<?php
$iCol 1;
    } else {
$iCol++;
    }
}
// Do we need a final closing row tag?
if ($iCol != 1) {
    
?>

        <div class="clear"></div>
</div>
    <?php

?>

</div>



this is the part with the link, which is to be fixed:

<div class="addtocart-bar">

<a target="_blank" <?php echo JHTML::link ($this->product->product_url,  JText::_('zum Shop'), array('title' => $product->product_name,'class' => 'product-details')) ?></a>


don´t know how to modified that
Quotelink ($this->product->product_url
is not the url from the product above, but the url from the related product.

there´s also a logo (of the shop from the company) behind the link. this image is probably also just taken from the above product and not from the related product.
i am not really sure, because both products are in this case from the same company.

the code for the logo is just behind the one of the link in the related_products.php:

<?php  if (!empty($this->product->customfieldsSorted['ontops'])) {
   
$this->position 'ontops';
   echo 
$this->loadTemplate('customfields');
    } 
// Product Custom ontops end
    
?>


so this two pieces works pretty good in category view and details view for the major product.
but i need to give vm the information that the link and the logo in related products should not the major, but the related product.

thanks in advance!


old_fritz

Quote from: Maxim Pishnyak on October 01, 2013, 10:47:17 AM
So this couldn't be helpful for you?
https://forum.virtuemart.net/index.php?topic=114544

thanks maxim for your idea.
unfortunatelly it does not work for me.
... or may i don´t get it together for my needs.

1.
it´s not exactly what i want.
in this thread there´s a button added which add the related product to cart.

but i want a button that link to the related product of a third party, means to an external url from another shop.

in my code above is already included a button with an external link embedded in related products.
so far so good...

unfortunatelly it links not to the related product of the external shop itself, but to the external shop of the major product.

2.
if i change the code to my needs from the thread, which you have gave me, it will make no real difference.
just the button appears a bit different - it still links to the wrong external url-page.


i think it´s just a tiny thing wrong in this code line, which rules the link to the wrong direction:

<a target="_blank" <?php echo JHTML::link ($this->product->product_url,  JText::_('zum Shop'), array('title' => $product->product_name,'class' => 'product-details')) ?></a>

particular this part:

JHTML::link ($this->product->product_url

there must have been something like this:

JHTML::link ($this->relatedproduct->product_url

but this doesn´t work (of course).

don´t know if you know what i mean.
but may there´s a simple solution, which tells the button, that i don´t want the url-link from the details view product, but from the related product one.

thanks again!

old_fritz

OK, then - did it on my own.
So it was as easy as I thought.

I am not too familiar with php, so it´s hard to find even a simple solution by nature.

However, for those who will run in similar problems,
here´s the code to include an external link in the related products.

just exchange this piece of code (from above related_products.php):

JHTML::link ($this->product->product_url

with this:

JHTML::link ($product->product_url

and you´re done.

So the
Quote$this
seems always to be for the major product in product view
and the direct
Quote$product
for all minor products.

here are some further explanation:
http://forum.virtuemart.net/index.php?topic=97744.0