Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1
    Join Date
    Oct 2006
    Posts
    149
    Plugin Contributions
    0

    Default [Done v1.3.9a] Double Discount Coupon message

    Hi All,

    I am getting a double discount coupon congratulations message on the Step 2 of checkout (zen 1.3.8)

    Congratulations you have redeemed the Discount Coupon
    Congratulations you have redeemed the Discount Coupon

    it loooks as either ot_coupon.php is called twice or writes two values to the $messageStack


    Any ideas what could be wrong here?

    Thanks

    A

  2. #2
    Join Date
    Oct 2006
    Posts
    149
    Plugin Contributions
    0

    Default Re: Double Discount Coupon message

    I have found the reason and here is a quick fix. The problem is in the message_stack.php:

    Code:
      function messageStack() {
    
        $this->messages = array();
    
        if (isset($_SESSION['messageToStack']) && $_SESSION['messageToStack']) {
          $messageToStack = $_SESSION['messageToStack'];
          for ($i=0, $n=sizeof($messageToStack); $i<$n; $i++) {
            $this->add($messageToStack[$i]['class'], $messageToStack[$i]['text'], $messageToStack[$i]['type']);
          }
          $_SESSION['messageToStack']= '';
        }
      }
    If $_SESSION['messageToStack'] is not empty, this function adds a double message to $messageToStack

    This is a quick fix (for the message type "success" only, because I had troubles with this type of messages only):

    Code:
     function add($class, $message, $type = 'error') {
        global $template, $current_page_base;
    
        $message = trim($message);
        if (strlen($message) > 0) {
        //checking if it is not a double message
        $double = 0;
        for ($i=0, $n=sizeof($this->messages); $i<$n; $i++) {
        if($this->messages[$i]['text'] ==  zen_image($template->get_template_dir(ICON_IMAGE_SUCCESS, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_SUCCESS, ICON_SUCCESS_ALT) . '  ' . $message) $double = 1;
        }
        if($double == 0) {
          if ($type == 'error') {
            $this->messages[] = array('params' => 'class="messageStackError larger"', 'class' => $class, 'text' => zen_image($template->get_template_dir(ICON_IMAGE_ERROR, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_ERROR, ICON_ERROR_ALT) . '  ' . $message);
          } elseif ($type == 'warning') {
            $this->messages[] = array('params' => 'class="messageStackWarning larger"', 'class' => $class, 'text' => zen_image($template->get_template_dir(ICON_IMAGE_WARNING, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_WARNING, ICON_WARNING_ALT) . '  ' . $message);
          } elseif ($type == 'success') {
            $this->messages[] = array('params' => 'class="messageStackSuccess larger"', 'class' => $class, 'text' => zen_image($template->get_template_dir(ICON_IMAGE_SUCCESS, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_SUCCESS, ICON_SUCCESS_ALT) . '  ' . $message);
          } elseif ($type == 'caution') {
            $this->messages[] = array('params' => 'class="messageStackCaution larger"', 'class' => $class, 'text' => zen_image($template->get_template_dir(ICON_IMAGE_WARNING, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_WARNING, ICON_WARNING_ALT) . '  ' . $message);
          } else {
            $this->messages[] = array('params' => 'class="messageStackError larger"', 'class' => $class, 'text' => $message);
          }
          }
        }
      }

  3. #3
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Double Discount Coupon message

    This would probably be somewhat more efficient:
    Code:
      function add($class, $message, $type = 'error') {
        global $template, $current_page_base;
        $message = trim($message);
        $duplicate = false;
        if (strlen($message) > 0) {
          if ($type == 'error') {
            $theMessage[] = array('params' => 'class="messageStackError larger"', 'class' => $class, 'text' => zen_image($template->get_template_dir(ICON_IMAGE_ERROR, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_ERROR, ICON_ERROR_ALT) . '  ' . $message);
          } elseif ($type == 'warning') {
            $theMessage[] = array('params' => 'class="messageStackWarning larger"', 'class' => $class, 'text' => zen_image($template->get_template_dir(ICON_IMAGE_WARNING, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_WARNING, ICON_WARNING_ALT) . '  ' . $message);
          } elseif ($type == 'success') {
            $theMessage[] = array('params' => 'class="messageStackSuccess larger"', 'class' => $class, 'text' => zen_image($template->get_template_dir(ICON_IMAGE_SUCCESS, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_SUCCESS, ICON_SUCCESS_ALT) . '  ' . $message);
          } elseif ($type == 'caution') {
            $theMessage[] = array('params' => 'class="messageStackCaution larger"', 'class' => $class, 'text' => zen_image($template->get_template_dir(ICON_IMAGE_WARNING, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_WARNING, ICON_WARNING_ALT) . '  ' . $message);
          } else {
            $theMessage[] = array('params' => 'class="messageStackError larger"', 'class' => $class, 'text' => $message);
          }
          for ($i=0, $n=sizeof($this->messages); $i<$n; $i++) {
            if (strip_tags($theMessage['text']) == strip_tags($this->messages[$i]['text']) && $theMessage['class'] == $this->messages[$i]['class']) $duplicate = true;
          }
          if (!$duplicate) $this->messages[] = $theMessage;
        }
      }
    Last edited by DrByte; 20 Mar 2008 at 05:21 AM. Reason: fix duplicate=true to false
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Double Discount Coupon message

    However, the bug is NOT that the messageStack is displaying duplicates.
    The real issue is that the coupon module is registering the message twice.

    But, at least you have a bandage for now.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Oct 2006
    Posts
    149
    Plugin Contributions
    0

    Default Re: Double Discount Coupon message

    yes, it is a better structured code, but it does not work. The first instance of $duplicate should be false.

    Even after I changed it to false, it does not show any messages at all. I will debbug it later to see what is happening here.

    Also, I have been checking it step-by-step in phpEd. The first instance of success message is added by

    $messageToStack = $_SESSION['messageToStack']; (line 28)

    The second one appears as a result of cycling through, i.e.

    $this->add($messageToStack[$i]['class'], $messageToStack[$i]['text'], $messageToStack[$i]['type']); (line 30)

    Note that $_SESSION['messageToStack']; includes only one instance of that message correctly

  6. #6
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Double Discount Coupon message

    Quote Originally Posted by andy1234 View Post
    The first instance of $duplicate should be false.
    Oops ... correct.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    Nov 2006
    Location
    Toronto, Ontario
    Posts
    65
    Plugin Contributions
    0

    Default Re: Double Discount Coupon message

    I too have this issue of the double message. Where abouts in the message_stack.php do i drop your code to fix this?

  8. #8
    Join Date
    Oct 2006
    Posts
    149
    Plugin Contributions
    0

    Default Re: Double Discount Coupon message

    Just replace the function add (about the line 37 of message_stack.php) by that code:

    Code:
     function add($class, $message, $type = 'error') {
        global $template, $current_page_base;
        $message = trim($message);
        if (strlen($message) > 0) {
     //checking if it is not a double message
     $double = 0;
     for ($i=0, $n=sizeof($this->messages); $i<$n; $i++) {
     if($this->messages[$i]['text'] ==  zen_image($template->get_template_dir(ICON_IMAGE_SUCCESS, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_SUCCESS, ICON_SUCCESS_ALT) . '  ' . $message) $double = 1;
     }
     if($double == 0) {
          if ($type == 'error') {
            $this->messages[] = array('params' => 'class="messageStackError larger"', 'class' => $class, 'text' => zen_image($template->get_template_dir(ICON_IMAGE_ERROR, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_ERROR, ICON_ERROR_ALT) . '  ' . $message);
          } elseif ($type == 'warning') {
            $this->messages[] = array('params' => 'class="messageStackWarning larger"', 'class' => $class, 'text' => zen_image($template->get_template_dir(ICON_IMAGE_WARNING, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_WARNING, ICON_WARNING_ALT) . '  ' . $message);
          } elseif ($type == 'success') {
            $this->messages[] = array('params' => 'class="messageStackSuccess larger"', 'class' => $class, 'text' => zen_image($template->get_template_dir(ICON_IMAGE_SUCCESS, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_SUCCESS, ICON_SUCCESS_ALT) . '  ' . $message);
          } elseif ($type == 'caution') {
            $this->messages[] = array('params' => 'class="messageStackCaution larger"', 'class' => $class, 'text' => zen_image($template->get_template_dir(ICON_IMAGE_WARNING, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_WARNING, ICON_WARNING_ALT) . '  ' . $message);
          } else {
            $this->messages[] = array('params' => 'class="messageStackError larger"', 'class' => $class, 'text' => $message);
          }
       }
        }
      }
    Note that it will eliminate the double message of the "success" type only. If you have other type double messages the "if" condition should be changed accordingly. I have not managed to get the code of DrByte working and did not have time to debug it.

  9. #9
    Join Date
    Nov 2006
    Location
    Toronto, Ontario
    Posts
    65
    Plugin Contributions
    0

    Default Re: Double Discount Coupon message

    awesome...thanks

  10. #10
    Join Date
    Mar 2008
    Posts
    76
    Plugin Contributions
    0

    Default Re: Double Discount Coupon message

    These seems like it should work. I modified the add function and I'm still sending out dups.

    Did this work for other folks?

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 6
    Last Post: 19 Jun 2011, 07:06 AM
  2. [Done v1.3.9e] 1.3.9a Double Orders
    By ToniScraparoni in forum Bug Reports
    Replies: 32
    Last Post: 27 Jul 2010, 06:32 AM
  3. Replies: 17
    Last Post: 26 Jul 2010, 03:18 PM
  4. [Done v1.3.9] Duplicate coupon confirmation message
    By karma-lab in forum Bug Reports
    Replies: 2
    Last Post: 13 Aug 2009, 12:28 AM
  5. Coupon welcome message showing discount when coupon is expired
    By tracyselena in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 4
    Last Post: 26 Jan 2007, 06:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg