0

I have just successfully updated to 1.9.4.3 from 1.9.4.2. However, in one of my custom blocks the add to basket doesn't work, item does not get added to the basket.

Analysing the url from $this->helper('checkout/cart')->getAddUrl($_product) it looks to be loading a wrong form key.

Further confusing me is that it is working on the chrome browser on my laptop. But, not on chrome on my phone or safari or firefox on the laptop and other computers.

Would anyone kindly see the error? I am struggling to work out as to what is occurring here.

The pcarousel.phtml

    <?php $cruid = $this->getPcarouselId(); $crudata = Mage::getModel('pcarousel/pcarousel')->load($cruid)->getData(); $categoryid = $crudata['categories']; $category = new Mage_Catalog_Model_Category(); $category->load($categoryid); $collection = $category->getProductCollection(); $collection->addAttributeToSelect('*'); $count = count($collection); ?>
<?php ?>
<?php if($crudata['status']==1 && $count>0) { ?>
<div class="vp-product owl-carousel">
            <?php foreach ($collection as $_product) { ?>
            <div class="item">
           <a href="<?php echo $_product->getProductUrl() ?>"> 
               <img class="lazy" data-src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" alt="<?php echo $_product->getName().' - '.$_product->getData('sku'); ?>" />
               </a>
                <div class="productName"> 
                    <a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a>
                    </div>
    <?php if($this->htmlEscape($_product->getExtraInfo() !="")):?> <span class="icon icon-info-circle tooltip" title="<?php echo $this->htmlEscape($_product->getExtraInfo())?>"></span>
    <?php endif;?>
    <div class="productCode">
        <?php echo $this->__('Product Code: ') . $this->htmlEscape($_product->getData('sku'));?>
    </div>
    <div class="sizeCode">
        <?php if($_product->getData('size')):?>
        <?php echo $this->__('Size: ') . $this->htmlEscape($_product->getData('size'));?>
        <?php endif; ?>
    </div>
    <div class="price-box">
        <?php echo Mage::helper('core')->currency($_product->getFinalPrice(),true,true);?>
    </div>
    <?php if($_product->isSaleable()): ?> <button type="button" title="<?php echo $this->__('Add to Basket') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->helper('checkout/cart')->getAddUrl($_product) ?>')"><span><?php echo $this->__('Add to Basket') ?></span></button>
    <?php else: ?>
    <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
    <?php endif; ?>
    <div class="add-to-links">
        <?php if ($this->helper('wishlist')->isAllow()) : ?>
        <div><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></div>
        <?php endif; ?>
        <?php if($_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
        <div><a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></div>
        <?php endif; ?>
    </div>
                    </div>
    <?php }?>

    </div>
<?php }?>

The pcarousel.php block file:

    <?php
class Pcarousel_Pcarousel_Block_Pcarousel extends Mage_Core_Block_Template
{
    protected function _construct()
    {
        $this->addData(array(
            'cache_lifetime' => 604800,
            'cache_tags'        => array(Mage_Core_Model_Store::CACHE_TAG, Mage_Cms_Model_Block::CACHE_TAG)
        ));
    }
    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }

     public function getInsurance()     
     { 
        if (!$this->hasData('pcarousel')) {
            $this->setData('pcarousel', Mage::registry('pcarousel'));
        }
        return $this->getData('pcarousel');

    }
    public function getCacheKeyInfo()
{
    return array(
       $this->getData('pcarousel_id'),
        Mage::app()->getStore()->getId(),
        (int)Mage::app()->getStore()->isCurrentlySecure(),
        Mage::getDesign()->getPackageName(),
        Mage::getDesign()->getTheme('template')
    );
}
}

Update

I am fairly confident it is a cache issue. Whereby, an old/wrong form key is being cached.

I tested by disabling the block cache, and it worked. Back tracing this. I believe it worked on my laptops chrome browser as it was the first hit. so this form key was cached. Subsequently, I cleared cache and went on my mobile first, and it duly worked.

So, my question now would be: How can I get it to respect the form key and not use an old key?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.