DavKan DavKan - 11 days ago 5
PHP Question

Opencart: 3 Buttons in "Add to Cart" Success notification

I had given a lot of try in achieving this, but i think i was not doing good enough as it was not working.

In opencart, when user click on Add to Cart, he is shown a "Success notification in popup" with a text "Success you have added ITEM to your cart".

I want to add 3 buttons in this popup.


  1. Continue shopping: It will Close the popup

  2. Buy Now: redirect to checkout.

  3. View Cart: redirect to cart.



i tried modifying catalog/language/english/checkout/cart.php with below code but not successful.

<div class="checkout">
<a class="button" id="close_cart"><?php echo $this->language->get('theme_close'); ?></a>
<a href="<?php echo $cart; ?>" class="button"><?php echo $text_cart; ?></a>
<a href="<?php echo $checkout; ?>" id="checkout-button" class="button"><?php echo $text_checkout; ?></a>
</div>


I am not aware if its possible to edit this catalog/language/english/checkout/cart.php as it contains messages. As i find the pop up text in this cart.php so tried editing it.

I inserted above code in
$_['text_success']
in cart.php

Could you please help..I have also attached a snapshot what i want to achieve.enter image description here

Answer

You were trying very correctly - You indeed need to modify the $_['text_success'] in mentioned language file, so that it looks like this (re-using Your code):

$_['text_success'] = 'Success: You have added <a href="%s">%s</a> to your <a href="%s">shopping cart</a>!<div class="checkout"><a class="button" id="close_cart">Continue Shopping</a><a href="index.php?route=checkout/checkout" id="checkout-button" class="button">Buy Now</a><a href="index.php?route=checkout/cart" class="button">View Cart</a></div>';

notice that all the <?php echo ... ?> are replaced by corresponding strings only.

For closing this success notice by clicking on Continue Shopping link You need to register a click event listener, e.g. in catalog/view/javascript/common.js add this somewhere at the end:

$(document).ready(function() {
    $('#close_cart').on('click', function() {
        $('.success').remove();
    });
});

This was not the scope of the question so consider it as extra value to the answer...