For some peculiar reason the upsell's on my product pages all have the same product url as the first upsell.

We are using Varnish for caching and I have added the esi to the upsell block in local.xml but still the issue persists.

Does anyone know why this is happening?


<?php if(count($this->getItemCollection()->getItems())): ?>
<div class="box-collateral box-up-sell">
    <h2><?php echo $this->__('You may also like...') ?></h2>
    <ul class="products-grid">
    <?php $this->resetItemsIterator() ?>
    <?php for($_i=0;$_i<$this->getRowCount();$_i++): ?>
        <?php for($_j=0;$_j<$this->getColumnCount();$_j++): ?>
            <?php if($_link=$this->getIterableItem()): ?>
            <?php $_product= Mage::getSingleton('catalog/product')->load($_link->getId()) ?>
            <li class="item first">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
                                        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(162,162); ?>" width="162" height="162" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
                <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php $_product->getName() ?>"><?php echo $_product->getName() ?></a></h2>
                <?php if($_product->getShortDescription()): ?>
                                <div class="short-description">
                                    <div class="std"><?php echo $_product->getShortDescription() ?></div>
                                <?php endif; ?>
                <div class="actions">
                    <?php echo $this->getPriceHtml($_link, true, '-upsell') ?>
                    <?php if($_product->isSaleable()): ?>
                                                <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
                    <?php endif; ?>
            <?php endif; ?>
        <?php endfor; ?>
    <?php endfor; ?>
    <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php endif ?>
  • 2
    can you provide some code? My psychic sensors are a bit off today :)
    – Marius
    Jan 28, 2014 at 11:59
  • I guess there's nothing to do with Varnish. Most likely there's a problem in you upsells template. Jan 28, 2014 at 12:04

1 Answer 1


There's your problem.

<?php $_product= Mage::getSingleton('catalog/product')->load($_link->getId()) ?>

First of all I don't understand why you need to load the product and not use the $_link object instead. But I assume you have a reason.
You need to replace that with

<?php $_product= Mage::getModel('catalog/product')->load($_link->getId()) ?>

When using getSingleton the same instance of the product model is used each time.
When you call load on that the _data member of the instance is merged with the values from the database.
When you try to get the product url you end up calling if ($product->hasUrlDataObject()) .... For the first item that expression evaluates to false and the url is retrieved correctly. The second time, because it's the same object that is evaluated to true and the url is returned based on the existing values. That's why you get the same url.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.