[英]Updating main product url on magento product page
我对当前正在构建的magento项目有一个探索。 我的产品页面下面有一个主图像(可配置产品)和缩略图。 我已经将代码添加到了阶段,在该阶段中单击缩略图会将图像添加到主图像区域,但是我需要包含链接的href并将其附加到该imgs URL。 希望这有道理,欢迎任何帮助。
<?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; ?>
我假设您要尝试单击大图像时,它将具有缩略图的网址
给这个href一个ID
<a href="" id="img_href"><?php echo $_helper->productAttribute($_product, $_img, 'image'); ?></a>
您使用的是jquery还是原型(如果使用默认的magento,则使用此选项)
原型
$('img_href').setAttribute('href', this.href);
//$('img_href').href = this.href; // or
jQuery的
$("#img_href").attr("href", this.href);
纯Javascript
document.getElementById('img_href')。href = this.href;
更新缩略图onclick
onclick="$('image').src = this.href; $('img_href').setAttribute('href', this.href); return false;"
$('image')。parentNode.href ='您的网址'; ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.