Post by konk » Wed Apr 28, 2010 2:14 am

Hello, For the site im currently working on i need a cart module to display a max of 5 items and limit any extra additions from showing. I have had a look in the cart.tpl and coded up a simple fix, But this only works aslong as another item isn't added to the cart. If the add to cart button is clicked the #module_cart will resize. Im assuming i need to change some code somewhere else. Any help is greatly appreciated. Thanks in advance O0

Code: Select all

<div id="module_cart" class="box">
  <div class="middle">
    	<?php $pd=0; ?>  <!-- CART MAX ITEMS EDIT -->
    <?php if ($products) { 
	
	
	?>
	
    <table cellpadding="2" cellspacing="0" style="width: 100%;">
	
      <?php foreach ($products as $product) { 
	  if ($pd <=4){ ?> <!-- CART MAX ITEMS EDIT -->
      <tr>
        <td valign="top" align="right" width="1"><?php echo $product['quantity']; ?>&nbsp;x&nbsp;</td>
        <td align="left" valign="top"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a>
          <div>
            <?php foreach ($product['option'] as $option) { ?>
            - <small style="color: #999;"><?php echo $option['name']; ?> <?php echo $option['value']; ?></small><br />
            <?php } ?>
          </div></td>
      </tr>
	  <?php $pd++; } else { break; } ?> <!-- CART MAX ITEMS EDIT -->
      <?php } ?>
    </table>
    <br />
    <div style="text-align: right;"><?php echo $text_subtotal; ?>&nbsp;<?php echo $subtotal; ?></div>
    <?php } else { ?>
    <div style="text-align: center;"><?php echo $text_empty; ?></div>
    <?php } ?>
  </div>
</div>
<?php if ($ajax) { ?>
<script type="text/javascript"><!--
$(document).ready(function () {
	$('#add_to_cart').replaceWith('<a onclick="" id="add_to_cart" class="button">' + $('#add_to_cart').html() + '</a>');

	$('#add_to_cart').click(function () {
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/callback',
			dataType: 'html',
			data: $('#product :input'),
			success: function (html) {
				$('#module_cart .middle').html(html);
			},	
			complete: function () {
				var image = $('#image').offset();
				var cart  = $('#module_cart').offset();
	
				$('#image').before('<img src="' + $('#image').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');
	
				params = {
					top : cart.top + 'px',
					left : cart.left + 'px',
					opacity : 0.0,
					width : $('#module_cart').width(),  
					heigtht : $('#module_cart').height() 
				};		
	
				$('#temp').animate(params, 'slow', false, function () {
					$('#temp').remove();
				});		
			}			
		});			
	});			
});
//--></script>
<?php } ?>

Newbie

Posts

Joined
Sat Apr 24, 2010 12:08 am

Post by channelcommerce » Wed Apr 28, 2010 6:03 pm

When you click add to cart on the 6th item does it increase in size? What about if you refresh or navigate away from the page, does it revert back to your fix?

The way Opencart works is using Ajax to update the cart without refreshing the whole page, any changes to the style in cart.tpl also need to be made to the callback() function in /catalog/controller/module/cart.php where the $output string is created.

The callback code only runs after clicking add to cart, it reverts back to the template file if you refresh the page so get it working in the template first by manually refreshing the page then update the callback to match.

Opencart Themes and eCommerce Solutions


New member

Posts

Joined
Tue Apr 13, 2010 4:46 am

Post by Qphoria » Wed Apr 28, 2010 7:50 pm

The ajax callback calls the callback function in catalog/controller/module/cart.php
You might need to add the logic there as well since you aren't able to stop the javascript click captuer

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by konk » Wed Apr 28, 2010 8:09 pm

yep i had a look at it last night. It was the callback function. I did the same to the data returned and its working perfectly.. Would be great to be able to change it from the admin section, but its good enough for what im working on as the design does not allow anymore.


Thanks

O0

Newbie

Posts

Joined
Sat Apr 24, 2010 12:08 am
Who is online

Users browsing this forum: No registered users and 11 guests