Results 1 to 8 of 8
  1. #1
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,296
    Plugin Contributions
    22

    Default Add an error to the message stack for checkout shipping?

    Have added the order delivery date module so that the customer chooses the date on the checkout shipping page which inserts a session parameter of the order delivery date. I want to require that so the original code is:

    if (zen_not_null($_POST['order_delivery_date'])) {
    $_SESSION['order_delivery_date'] = zen_db_prepare_input($_POST['order_delivery_date']);
    }
    $order_delivery_date = $_SESSION['order_delivery_date'];

    I just added this below that:

    if (!$order_delivery_date) {
    $messageStack->add('checkout_shipping', ERROR_PLEASE_CHOOSE_DELIVERY_DATE, 'error');
    }
    I've tried !$_SESSION['order_delivery_date'] and !$_POST['order_delivery_date'] as well but since none are working, I assume I've done something else wrong.

    Is there a specific place in the header.php.php that an error message should go? Or is the use of check_shipping incorrect in that line? Forgive me, this is the first time I've ever tried adding to the message stack in my 5 plus years experience in zen cart!
    The full-time Zen Cart Guru. WizTech4ZC.com

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: How to add an error to the message stack for checkout shipping?

    Try $messageStack->add_session( instead of just ->add(
    .

    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.

  3. #3
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,296
    Plugin Contributions
    22

    Default Re: How to add an error to the message stack for checkout shipping?

    That didn't work either. Hadn't tried it because it didn't sound like that was what I needed but a good suggestion. Since this is the second time I've worked with the mod and the second time I've been asked for this, I think it needs adding into the mod. I tried switching it around by requiring the error message if the session variable is there (and it is) - tried it with add and with add_session. No dice.
    The full-time Zen Cart Guru. WizTech4ZC.com

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: How to add an error to the message stack for checkout shipping?

    I suspect there's more context needed for this discussion to go anywhere.
    .

    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
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,296
    Plugin Contributions
    22

    Default Re: How to add an error to the message stack for checkout shipping?

    All the mod does is allow the buyer to choose a delivery date. That date is inserted as a session variable and entered into the order itself in the database. So the files changed are the classes/order.php, modules/pages/checkout_shipping/header_php.php, languages files and templates- tpl_checkout_shipping.php and tpl_checkout_confirmation.php (it just displays it). So here's the contents of the header file with the changes in red for the mod:
    Code:
    // This should be first line of the script:
      $zco_notifier->notify('NOTIFY_HEADER_START_CHECKOUT_SHIPPING');
    
      require_once(DIR_WS_CLASSES . 'http_client.php');
    
    // if there is nothing in the customers cart, redirect them to the shopping cart page
      if ($_SESSION['cart']->count_contents() <= 0) {
        zen_redirect(zen_href_link(FILENAME_TIME_OUT));
      }
    
    // if the customer is not logged on, redirect them to the login page
      if (!isset($_SESSION['customer_id']) || !$_SESSION['customer_id']) {
        $_SESSION['navigation']->set_snapshot();
        zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
      } else {
        // validate customer
        if (zen_get_customer_validate_session($_SESSION['customer_id']) == false) {
          $_SESSION['navigation']->set_snapshot(array('mode' => 'SSL', 'page' => FILENAME_CHECKOUT_SHIPPING));
          zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
        }
      }
    
    // Validate Cart for checkout
      $_SESSION['valid_to_checkout'] = true;
      $_SESSION['cart']->get_products(true);
      if ($_SESSION['valid_to_checkout'] == false) {
        $messageStack->add('header', ERROR_CART_UPDATE, 'error');
        zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
      }
    
    // Stock Check
      if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
        $products = $_SESSION['cart']->get_products();
        for ($i=0, $n=sizeof($products); $i<$n; $i++) {
          if (zen_check_stock($products[$i]['id'], $products[$i]['quantity'])) {
            zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
            break;
          }
        }
      }
    // if no shipping destination address was selected, use the customers own address as default
      if (!$_SESSION['sendto']) {
        $_SESSION['sendto'] = $_SESSION['customer_default_address_id'];
      } else {
    // verify the selected shipping address
        $check_address_query = "SELECT count(*) AS total
                                FROM   " . TABLE_ADDRESS_BOOK . "
                                WHERE  customers_id = :customersID
                                AND    address_book_id = :addressBookID";
    
        $check_address_query = $db->bindVars($check_address_query, ':customersID', $_SESSION['customer_id'], 'integer');
        $check_address_query = $db->bindVars($check_address_query, ':addressBookID', $_SESSION['sendto'], 'integer');
        $check_address = $db->Execute($check_address_query);
    
        if ($check_address->fields['total'] != '1') {
          $_SESSION['sendto'] = $_SESSION['customer_default_address_id'];
          $_SESSION['shipping'] = '';
        }
      }
    
      require(DIR_WS_CLASSES . 'order.php');
      $order = new order;
    
    // register a random ID in the session to check throughout the checkout procedure
    // against alterations in the shopping cart contents
    if (isset($_SESSION['cart']->cartID)) {
      if (!isset($_SESSION['cartID']) || $_SESSION['cart']->cartID != $_SESSION['cartID']) {
        $_SESSION['cartID'] = $_SESSION['cart']->cartID;
      }
    } else {
      zen_redirect(zen_href_link(FILENAME_TIME_OUT));
    }
    
    // if the order contains only virtual products, forward the customer to the billing page as
    // a shipping address is not needed
      if ($order->content_type == 'virtual') {
        $_SESSION['shipping'] = 'free_free';
        $_SESSION['shipping']['title'] = 'free_free';
        $_SESSION['sendto'] = false;
        zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
      }
    
      $total_weight = $_SESSION['cart']->show_weight();
      $total_count = $_SESSION['cart']->count_contents();
    
    // load all enabled shipping modules
      require(DIR_WS_CLASSES . 'shipping.php');
      $shipping_modules = new shipping;
    
      $pass = true;
      if ( defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') ) {
        $pass = false;
    
        switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
          case 'national':
            if ($order->delivery['country_id'] == STORE_COUNTRY) {
              $pass = true;
            }
            break;
          case 'international':
            if ($order->delivery['country_id'] != STORE_COUNTRY) {
              $pass = true;
            }
            break;
          case 'both':
            $pass = true;
            break;
        }
    
        $free_shipping = false;
        if ( ($pass == true) && ($_SESSION['cart']->show_total() >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {
          $free_shipping = true;
        }
      } else {
        $free_shipping = false;
      }
    
      require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
    
      if (isset($_SESSION['comments'])) {
        $comments = $_SESSION['comments'];
      }
    
      // BEGIN Order Delivery Date
      if (isset($_SESSION['order_delivery_date'])) {
        $order_delivery_date = $_SESSION['order_delivery_date'];
      }
      // END Order Delivery Date
    
    // process the selected shipping method
      if ( isset($_POST['action']) && ($_POST['action'] == 'process') ) {
        if (zen_not_null($_POST['comments'])) {
          $_SESSION['comments'] = zen_db_prepare_input($_POST['comments']);
        }
        $comments = $_SESSION['comments'];
        $quote = array();
    
        //BEGIN Order Delivery Date
        if (zen_not_null($_POST['order_delivery_date'])) {
          $_SESSION['order_delivery_date'] = zen_db_prepare_input($_POST['order_delivery_date']);
        }
        $order_delivery_date = $_SESSION['order_delivery_date'];    
        if ($_SESSION['order_delivery_date']) {
             $messageStack->add('checkout_shipping', ERROR_PLEASE_CHOOSE_DELIVERY_DATE, 'error');
        }
        // END Order Delivery Date
    
        if ( (zen_count_shipping_modules() > 0) || ($free_shipping == true) ) {
          if ( (isset($_POST['shipping'])) && (strpos($_POST['shipping'], '_')) ) {
            /**
             * check to be sure submitted data hasn't been tampered with
             */
            if ($_POST['shipping'] == 'free_free' && ($order->content_type != 'virtual' && !$pass)) {
              $quote['error'] = 'Invalid input. Please make another selection.';
            } else {
              $_SESSION['shipping'] = $_POST['shipping'];
            }
    
            list($module, $method) = explode('_', $_SESSION['shipping']);
            if ( is_object($$module) || ($_SESSION['shipping'] == 'free_free') ) {
              if ($_SESSION['shipping'] == 'free_free') {
                $quote[0]['methods'][0]['title'] = FREE_SHIPPING_TITLE;
                $quote[0]['methods'][0]['cost'] = '0';
              } else {
                $quote = $shipping_modules->quote($method, $module);
              }
              if (isset($quote['error'])) {
                $_SESSION['shipping'] = '';
              } else {
                if ( (isset($quote[0]['methods'][0]['title'])) && (isset($quote[0]['methods'][0]['cost'])) ) {
                  $_SESSION['shipping'] = array('id' => $_SESSION['shipping'],
                                    'title' => (($free_shipping == true) ?  $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')'),
                                    'cost' => $quote[0]['methods'][0]['cost']);
    
                  zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
                }
              }
            } else {
              $_SESSION['shipping'] = false;
            }
          }
        } else {
          $_SESSION['shipping'] = false;
    
          zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
        }
      }
    
    // get all available shipping quotes
      $quotes = $shipping_modules->quote();
    
      // check that the currently selected shipping method is still valid (in case a zone restriction has disabled it, etc)
      if (isset($_SESSION['shipping']) && $_SESSION['shipping'] != FALSE && $_SESSION['shipping'] != '') {
        $checklist = array();
        foreach ($quotes as $key=>$val) {
          foreach($val['methods'] as $key2=>$method) {
            $checklist[] = $val['id'] . '_' . $method['id'];
          }
        }
        $checkval = (is_array($_SESSION['shipping']) ? $_SESSION['shipping']['id'] : $_SESSION['shipping']);
        if (!in_array($checkval, $checklist)) {
          $messageStack->add('checkout_shipping', ERROR_PLEASE_RESELECT_SHIPPING_METHOD, 'error');
        }
      }
    
    // if no shipping method has been selected, automatically select the cheapest method.
    // if the modules status was changed when none were available, to save on implementing
    // a javascript force-selection method, also automatically select the cheapest shipping
    // method if more than one module is now enabled
      if ( !$_SESSION['shipping'] || ( $_SESSION['shipping'] && ($_SESSION['shipping'] == false) && (zen_count_shipping_modules() > 1) ) ) $_SESSION['shipping'] = $shipping_modules->cheapest();
    
    
      // Should address-edit button be offered?
      $displayAddressEdit = (MAX_ADDRESS_BOOK_ENTRIES >= 2);
    
      // if shipping-edit button should be overridden, do so
      $editShippingButtonLink = zen_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, '', 'SSL');
      if (isset($_SESSION['payment']) && method_exists($$_SESSION['payment'], 'alterShippingEditButton')) {
        $theLink = $$_SESSION['payment']->alterShippingEditButton();
        if ($theLink) {
          $editShippingButtonLink = $theLink;
          $displayAddressEdit = true;
        }
      }
    
      $breadcrumb->add(NAVBAR_TITLE_1, zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
      $breadcrumb->add(NAVBAR_TITLE_2);
    
    // This should be last line of the script:
      $zco_notifier->notify('NOTIFY_HEADER_END_CHECKOUT_SHIPPING');
    The full-time Zen Cart Guru. WizTech4ZC.com

  6. #6
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: How to add an error to the message stack for checkout shipping?

    I suspect that the reason for it not working is more to do with your "if" logic than with the messageStack itself.

    As far as the "add" vs "add_session", the add_session is used when you're immediately following it with a redirect, since the message won't survive a redirect if it's not added to the session.
    However, if the message is intended to display immediately on the page (such as it would for any "default" text or re-displayed content such as pre-filled or previously-filled input fields would) then using "add" is the right way.
    .

    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
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,296
    Plugin Contributions
    22

    Default Re: How to add an error to the message stack for checkout shipping?

    Okay, I thought add was correct. Looking at the choices now, realize that it doesn't insert the variable into checkout_shipping. The session variable shows up afterwards. So then using $_POST should be correct to use, either as !$_POST['order_delivery_date'] or $_POST['order_delivery_date'] == '' but neither work. Since the calendar itself is controlled by javascript (mootools), I do believe I'm out of my depth here. Javascript is not my forte at all.

    Thanks for at least looking at it.
    The full-time Zen Cart Guru. WizTech4ZC.com

  8. #8
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,296
    Plugin Contributions
    22

    Default Re: How to add an error to the message stack for checkout shipping?

    Found the answer:

    if (zen_not_null($_POST['order_delivery_date'])) {
    $_SESSION['order_delivery_date'] = zen_db_prepare_input($_POST['order_delivery_date']);
    } else {
    $messageStack->add_session('checkout_shipping', ERROR_PLEASE_CHOOSE_DELIVERY_DATE, 'error');

    zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));

    It was the zen_redirect that I was missing as well as the use of the zen_not_null / else to avoid the post problems. Such simplicity. Thanks to Scott Wilson, That Software Guy who does such a great job with Zen Cart coding!
    The full-time Zen Cart Guru. WizTech4ZC.com

 

 

Similar Threads

  1. v153 Adding a message into the message stack
    By delia in forum General Questions
    Replies: 9
    Last Post: 22 Oct 2014, 05:29 PM
  2. message stack error
    By enzo-ita in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 23 Dec 2012, 02:48 PM
  3. HELP! how to add error message to shipping module in checkout
    By newbie456 in forum Addon Shipping Modules
    Replies: 0
    Last Post: 9 Dec 2011, 03:47 AM
  4. Add span class to the message stack text
    By LissaE in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 4 Mar 2010, 11:55 AM
  5. Message Stack Error - Changing the text
    By rkmoore11 in forum General Questions
    Replies: 2
    Last Post: 16 Sep 2007, 02:09 AM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR