I have made in layouts/main.php code to render cart as partial:
$session = Yii::app()->session;
$cart = Cart::GetCart($session['cart']);
$this->renderPartial('//layouts/cart', array(
'cart' => $cart,
), false, true );
Then the page is loaded I receive code 2 times in the bottom of the page and in rendered partial section #cart-content:
page bottom:
jQuery(function($) {
$('body').on('click','#yt1',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=0','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
$('body').on('click','#yt2',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=1','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
...
$('body').on('click','#yt8',function(){jQuery.ajax({'url':'en/index.php?r=cart/clear','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
});
/*]]>*/
from /layouts/cart.php:
<script type="text/javascript">
/*<![CDATA[*/
$('body').on('click','#yt1',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=0','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
$('body').on('click','#yt2',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=1','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
$('body').on('click','#yt3',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=2','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
$('body').on('click','#yt4',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=3','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
$('body').on('click','#yt5',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=4','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
$('body').on('click','#yt6',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=5','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
$('body').on('click','#yt7',function(){jQuery.ajax({'url':'en/index.php?r=cart/delete&id=6','cache':false,'success':function(html){jQuery("#cart-content").html(html)}});return false;});
/*]]>*/
</script>
Delete item from the cart is called mutiple times, so the two items deleted.
When the #cart-content is reloaded i get yt0 id for delete link which is stands for add to cart button id.
I have tryed several solutions but they either don’t work or delete miltiply times. I can use html options
to set uniqid() ids, but the links does not work, nothing deleted from cart.
Please give me a short path.
Thanks.