Updating the main product URL on the magento product page

I have a problem with the magento project that I am currently creating. On my product page there is a main image (custom product) and thumbnails below. I have the code at the point where clicking on the thumbnail adds the image to the main area of ​​the image, however I need href for the link it contains to add imgs to this URL. Hope this makes sense, any help is appreciated.

<?php $_product = $this->getProduct(); $_helper = $this->helper('catalog/output'); ?> <div class="grid_12 grid_spacer_bottom"> <?php $_img = '<img id="image" class="img-left img-inlineblock responsive-img" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->htmlEscape($this->getImageLabel()).'" />'; //echo $_helper->productAttribute($_product, $_img, 'image'); ?> <a href=""><?php echo $_helper->productAttribute($_product, $_img, 'image'); ?></a> </div> <div class="clear"></div> <?php if (count($this->getGalleryImages()) > 0): ?> <div class="more-views"> <?php foreach ($this->getGalleryImages() as $_image): ?> <div class="grid_4 grid_spacer_bottom"> <a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" title="<?php echo $_product->getName();?>" onclick="$('image').src = this.href; return false;"> <img class="img-left img-inlineblock responsive-img" src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile()); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /> </a> </div> <?php endforeach; ?> </div> <?php endif; ?> 
+4
source share
2 answers

I guess what you are trying to do is when you click on a large image, it will have a thumbnail URL

Give this href id

  <a href="" id="img_href"><?php echo $_helper->productAttribute($_product, $_img, 'image'); ?></a> 

Do you use jquery or prototype (if it is magento by default)

Prototype

 $('img_href').setAttribute('href', this.href); //$('img_href').href = this.href; // or 

JQuery

 $("#img_href").attr("href", this.href); 

Plain javascript

document.getElementById ('img_href'). href = this.href;

Update onclick thumbnail

 onclick="$('image').src = this.href; $('img_href').setAttribute('href', this.href); return false;" 
+2
source

$ ('image'). parentNode.href = 'your url';

0
source

Source: https://habr.com/ru/post/1442072/


All Articles