在magento产品页面上更新主产品网址

时间:2012-10-25 14:14:09

标签: php javascript magento magento-1.7

我有一个正在建设的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; ?>

2 个答案:

答案 0 :(得分:2)

我假设您在点击大图片时尝试制作它将具有缩略图的网址

给这个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="$('image').src = this.href;  $('img_href').setAttribute('href', this.href); return false;"

答案 1 :(得分:0)

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