Post by shizzzzzzzzz » Wed Jun 17, 2015 1:48 am

In my latest module, when I click on products to be added to shopping cart, no message appears. Can someone help me?

This is my code:

Code: Select all

<div id="latest-products-width">
    <?php foreach ($products as $product) { ?>
        <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12"> 
            <div class="latest-products-bg"> 
                <div class="latest-products">
                    <a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" /></a>

                    <div class="product-title">
                    <div class="product-name">
                    <p><span><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></span></p>

                     <?php if ($product['price']) { ?>
                      <?php if (!$product['special']) { ?>
                       <p><i class="fa fa-gbp"></i><?php echo $product['price']; ?></p>
                      <?php } else { ?>
                      <p><i class="fa fa-gbp"></i><b><?php echo $product['price']; ?></b><?php echo $product['special']; ?></p>
                      <?php } ?>
                      <?php } ?>


                    </div>     
                    </div>

                    <div class="clearfix"></div>
                    <div class="product-content">
                    <p><?php echo $product['description']; ?></p>
                    </div>

                    <div class="product-btn">
                    <a href="<?php echo $product['href']; ?>">
                    <div class="col-xs-4 col-sm-6 view-details">
                    <i class="fa fa-search-plus"></i> Details
                    </div>
                    </a>
                    <a onclick="cart.add('<?php echo $product['product_id']; ?>');" id="button-cart">
                    <div class="col-xs-8 col-sm-6 add-to-cart">
                    <i class="fa fa-shopping-cart"></i> Add Cart
                    </div>
                    </a>
                    </div>        
                </div>      
                 <?php if ($product['price']) { ?>
                      <?php if (!$product['special']) { ?>
                      <?php } else { ?>
                     <div id="sale">Sale</div>
                      <?php } ?>
                      <?php } ?>
            </div>
        </div>
    <?php } ?>
 </div>


 <script type="text/javascript"><!--
$('#button-cart').on('click', function() {
    $.ajax({
        url: 'index.php?route=checkout/cart/add',
        type: 'post',
        data: $('#product input[type=\'text\'], #product input[type=\'hidden\'], #product input[type=\'radio\']:checked, #product input[type=\'checkbox\']:checked, #product select, #product textarea'),
        dataType: 'json',
        beforeSend: function() {
            $('#button-cart').button('loading');
        },
        complete: function() {
            $('#button-cart').button('reset');
        },
        success: function(json) {
            $('.alert, .text-danger').remove();
            $('.form-group').removeClass('has-error');

            if (json['error']) {
                if (json['error']['option']) {
                    for (i in json['error']['option']) {
                        var element = $('#input-option' + i.replace('_', '-'));

                        if (element.parent().hasClass('input-group')) {
                            element.parent().after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
                        } else {
                            element.after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
                        }
                    }
                }

                if (json['error']['recurring']) {
                    $('select[name=\'recurring_id\']').after('<div class="text-danger">' + json['error']['recurring'] + '</div>');
                }

                // Highlight any found errors
                $('.text-danger').parent().addClass('has-error');
            }

            if (json['success']) {
                $('.nav').after('<div class="alert alert-success">' + json['success'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');

                $('#cart-total').html(json['total']);

                $('html, body').animate({ scrollTop: 0 }, 'slow');

                $('#cart > div').load('index.php?route=common/cart/info .cart_menu .cart_items, .cart_totals, .cart_view_bottom');
            }
        }
    });
});
//--></script> 
Another problem is that instead the message appear in part of template. Can someone help me put it in floating box looks like if it was a Facebook notification (and disappear after X seconds)?

Newbie

Posts

Joined
Wed Jun 17, 2015 1:47 am
Who is online

Users browsing this forum: No registered users and 4 guests