GordonLesti / Lesti_Fpc

Simple Magento Fullpagecache
https://gordonlesti.com/lesti-fpc-documentationversion-1-4-5/
Other
358 stars 159 forks source link

Dynamic custom block problem #323

Open rafaelpatro opened 6 years ago

rafaelpatro commented 6 years ago

Hi guys

I'm trying to set a dynamic Add to Cart button without success. I put my custom block in dynamic blocks and I declared the block inside _productlist layout. When in login sometimes my code appears and sometimes not. Dynamic config are not working for me.

In catalog/product/list.phtml I put this:

<?php
    echo $this->getChild('catalog.addtocart.logged')->setData(array(
        'add_url' => $this->getAddToCartUrl($_product),
        'compare_url' => $this->getAddToCompareUrl($_product),
        'code' => $code,
        'product' => $product,
        'iterated_product' => $_product
    ))->toHtml();
?>

In my template catalog.addtocart.logged I put this:

<?php
$addUrl = $this->getAddUrl();
$compareUrl = $this->getCompareUrl();
$code = $this->getCode();
$product = $this->getProduct();
$_product = $this->getIteratedProduct();
?>
<?php if ($product): ?>
    <?php if(!Mage::getSingleton('customer/session')->isLoggedIn()): ?>
        <p><?php echo $this->__("To add to cart you must be logged in"); ?></p>
    <?php else: ?>
        <div class="actions">Here you see my code</div>
    <?php endif; ?>
<?php endif; ?>

What I'm doing wrong?

rafaelpatro commented 6 years ago

My template file above sometimes shows a null $product. This is weird because I'm setting data in parent block.

My layout _catalog_categorydefault inside _productlist block:

<block type="core/template" name="catalog.addtocart.logged" template="catalog/product/list/addtocart.phtml">
    <action method="unsetData"><key>cache_lifetime</key></action>
</block>