-1

I have created some custom cart alert but I am having an issue at the moment with some scripts running some ajax responses that was supposed to refresh the cart in Business Catalyst.

I am not sure what it is but to give me time to look into whats happening I need to do something depending on the alert message so lets say:

1 item has been added to your cart this will do some window.location.reload();

or if it just says: you need to choose a size DO NOTHING

at he moment moment my alert is:

window.alert = function(message) {

$('.shop-main').addClass('blur');
$('.messageAlert').fadeIn().text(message).prepend('<img src="/images/ui-pieces/shopping-cart.png" width="40" height="40" alt="cart alert"/>');

setTimeout(function() { 

$('.messageAlert').fadeOut(); 
$('.shop-main').removeClass('blur');


  // window.location.reload();

}, 4000);
};

Please let me know I can do at this stage.

L84
  • 45,514
  • 58
  • 177
  • 257
Ricardo Alves
  • 561
  • 1
  • 5
  • 21
  • 2
    [`switch`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch) – Teemu Mar 15 '16 at 15:01

2 Answers2

1

Your close, you need to check the alert and run code based upon that.

Here is what I do within BC:

window.alert = function(text) {
    if (text.indexOf("Please choose relevant options before") > -1) {
        //CODE TO RUN IF ALERT MATCHES THE ABOVE TEXT
        $('#choose-option').foundation('reveal', 'open');
    } else if (text.indexOf("item(s) added to your cart") > -1) {
        //CODE TO RUN IF ALERT MATCHES THE ABOVE TEXT
        $('#store-modal').foundation('reveal', 'open');
    } else if (text.indexOf("Quantity entered is too large, please enter a smaller quantity.") > -1) {
        //CODE TO RUN IF ALERT MATCHES THE ABOVE TEXT
        $('#limited-quantity').foundation('reveal', 'open');
    } 
}; 

In my case I'm opening certain modals I have on the page. In place of the modal code you could insert your own JS.

L84
  • 45,514
  • 58
  • 177
  • 257
  • Thanks Lynda, worked well and I could actually do some other interactive calls too. do you normally get an prototype error message like: prototype-core.ashx Refused to set unsafe header "Connection" basically the reason why I have to use a custom alert response to refresh the page when something is added to cart, the funny thing is that it only happens when added to cart I went trough clearing all conflicts and nothing! much appreciated your help any ways and I will post it on another query. – Ricardo Alves Mar 18 '16 at 09:56
  • @Skwashy - I've never seen that message, so I am unsure. You can ask on the [Adobe BC Forums](https://forums.adobe.com/community/business_catalyst) and see if someone can shed more light on that problem. – L84 Mar 19 '16 at 20:17
  • I've already done it but only one person gave me some suggestions but didn't quite work I need to study how this works maybe I'll find the root of the problem. Thanks anyway. – Ricardo Alves Mar 20 '16 at 12:09
0

Use this code to - Develop => Layout => OnlineShop => small_product.html (Past the below code to bottom of the page)

<span class="cartalert" style="display:none"></span>
<style>
.cartalert {
    position: fixed;
    bottom: 10%;
    right: 10%;
    padding: 15px 20px;
    text-align: center;
    background: #333;
    color: #fff !important;
    z-index:999999;
    border-radius: 5px;
    font-size: 16px;
}
</style>
<script>
$(function() {
     window.alert = function(msg) {
        msg = msg.replace('ERROR: ','');
        $('.cartalert').text(msg).fadeIn().delay(1000).fadeOut()
     } 
});
</script>
Nehemiah
  • 1,063
  • 7
  • 15