Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic custom block problem #323

Open
rafaelpatro opened this issue May 29, 2018 · 1 comment
Open

Dynamic custom block problem #323

rafaelpatro opened this issue May 29, 2018 · 1 comment

Comments

@rafaelpatro
Copy link
Contributor

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 product_list 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
Copy link
Contributor Author

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

My layout catalog_category_default inside product_list block:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant