【问题标题】:Updating main product url on magento product page在 magento 产品页面上更新主要产品 url
【发布时间】:2012-10-25 14:14:09
【问题描述】:

我有一个关于我目前正在构建的 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; ?>

【问题讨论】:

  • 我认为我已经取得了一些进展,在更新要显示为主图像的 img 的 js 上(在缩略图周围的 a 上)我试图添加更多的 js 来更新$image 的 href 并更新了构建 $image 的代码......但这仍然没有附加 imgs url。 onclick="$('image').src = this.href; return false;$('image').href = this.href; return false;"

标签: php javascript magento magento-1.7


【解决方案1】:

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

给这个 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;"

【讨论】:

  • 你这个传奇!我知道我是如此接近,并意识到这是几分钟前 onclick 功能所需要的东西。非常感谢您的帮助。
【解决方案2】:

$('image').parentNode.href='你的网址'; ?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多