Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2010
    Posts
    42
    Plugin Contributions
    0

    Default Passing variable when directing to cart

    Hi, I am looking for a little help.

    I have a separate system for managing club memberships. When someone wants to renew membership, I direct them to our cart (used by members and many non-members) to make the payment.

    I would like to be able to connect that payment with the member's renewal. I figure the easiest approach would be to pass the member's ID number in the membership system to the cart in the redirection, and then load it as an attribute value.

    My question is: Is it possible to pass a variable to Zen Cart when it is initiated from another program, and if so, what is the best method to use?

    [I've spent a few hours searching for an answer here, and while there are some postings on this, I could not find a definite answer, or method.]

    Any help greatly appreciated!

  2. #2
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,114
    Plugin Contributions
    9

    Default Re: Passing variable when directing to cart

    i think you are talking about $_GET vars, which would be part of the URL that one would use in your redirect to the cart.

    you would then have to do something with that var; hopefully using an observer...

    https://www.php.net/manual/en/reserv...iables.get.php

    best.
    help with WCAG is now here! PM if you want some help with this. (or any ZC issue).
    if you feel so inclined, feel free to send some cake....

  3. #3
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    8,216
    Plugin Contributions
    111

    Default Re: Passing variable when directing to cart

    I would suggest just sending them to the page of the membership product with instructions to add to cart and purchase.

    YOURSITE.com/index.php?main_page=product_info&products_id=ID-of-Membership-product
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  4. #4
    Join Date
    Feb 2010
    Posts
    42
    Plugin Contributions
    0

    Default Re: Passing variable when directing to cart

    Quote Originally Posted by swguy View Post
    I would suggest just sending them to the page of the membership product with instructions to add to cart and purchase.

    YOURSITE.com/index.php?main_page=product_info&products_id=ID-of-Membership-product
    Yes, that is exactly what I am doing. But I want to associate the eventual purchase with the specific membership in our membership system, hence the desire to bring across the ID and include it in the purchase process. (I am comfortable pre-loading attributes with values when the user selects a product - I just need the value available to be used.)

  5. #5
    Join Date
    Feb 2010
    Posts
    42
    Plugin Contributions
    0

    Default Re: Passing variable when directing to cart

    Quote Originally Posted by carlwhat View Post
    i think you are talking about $_GET vars, which would be part of the URL that one would use in your redirect to the cart.

    you would then have to do something with that var; hopefully using an observer...

    https://www.php.net/manual/en/reserv...iables.get.php

    best.
    I was anticipating using GET, but I am unsure if there are any restrictions on using it in ZC, or exactly where I should put the statement and make the value passed useable in the session - my own session variable perhaps?

  6. #6
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    8,216
    Plugin Contributions
    111

    Default Re: Passing variable when directing to cart

    There are no restrictions. Yes, create your own session variable. Put your logic in includes/modules/pages/product_info/main_template_vars.php.
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  7. #7
    Join Date
    Feb 2010
    Posts
    42
    Plugin Contributions
    0

    Default Re: Passing variable when directing to cart

    Quote Originally Posted by swguy View Post
    There are no restrictions. Yes, create your own session variable. Put your logic in includes/modules/pages/product_info/main_template_vars.php.
    Thanks very much!

  8. #8
    Join Date
    Feb 2010
    Posts
    42
    Plugin Contributions
    0

    Default Re: Passing variable when directing to cart

    Okay, I have tried this approach, but can't seem to get it working. The application runs okay, but does not populate the displayed attribute with the value I have provided.

    I believe I have the coding done correctly, so my suspicion is that that value is being stripped off in passing the url parameters because it is not an expected parameter by ZC.

    (But I could have got it totally wrong at any step!?!)

    Here is my call from my other system:

    header('Location: https://www.athleticsnortheast.com/cart/index.php?main_page=product_info&cPath=4&products_id=3&mymemno=$memno');

    And this is my code in main_template_vars.php to capture the value, place it in a $_SESSION variable, and make it available to further use.

    $_SESSION['anememno'] = NULL;
    if (isset($_GET['mymemno'])){
    $_SESSION['anememno'] = $_GET['mymemno'];
    }


    In attributes.php, where I preset values for other fields such as name and address (from the customer record, and this works just fine), I attempt to use that $_SESSION variable.

    if (isset($_SESSION['anememno'])) {
    if (($products_options_names->fields['products_options_id'] == "88")) {
    $prefill_fld_select = $_SESSION['anememno'];
    }
    }


    Does this look right? Is my suspicion about the value being removed from the url possibly correct?

  9. #9
    Join Date
    Feb 2010
    Posts
    42
    Plugin Contributions
    0

    Default Re: Passing variable when directing to cart

    Final Report - I have it working now.

    A bit of fiddling with the url call to get the variable value correctly, and ended up doing the $_GET code in attributes.php.

    header('Location: https://www.athleticsnortheast.com/cart/index.php?main_page=product_info&cPath=4&products_id=3&mymemno='.$memno);

    and

    if (isset($_GET['mymemno'])) {
    if (($products_options_names->fields['products_options_id'] == "88")) {
    $prefill_fld_select = $_GET['mymemno'];
    }
    }

  10. #10
    Join Date
    Jul 2012
    Posts
    16,173
    Plugin Contributions
    17

    Default Re: Passing variable when directing to cart

    Quote Originally Posted by sdelaney View Post
    Final Report - I have it working now.

    A bit of fiddling with the url call to get the variable value correctly, and ended up doing the $_GET code in attributes.php.

    header('Location: https://www.athleticsnortheast.com/cart/index.php?main_page=product_info&cPath=4&products_id=3&mymemno='.$memno);

    and

    if (isset($_GET['mymemno'])) {
    if (($products_options_names->fields['products_options_id'] == "88")) {
    $prefill_fld_select = $_GET['mymemno'];
    }
    }
    Is $mymmno expected to be a number? if so, I highly suggest sanitizing your $prefill_fld_select value to expect only a number. Even if not, it would be a really good idea to provide some sanitization to the data so that something doesn't go wrong down the line with attempts to use whatever desired on the URL...

    In the previous post stated that are prefilling the name and address from "other fields", is that prefill from within Zen Cart or from your "other system"? Would be bad mojo if someone were able to trial by error various numbers and those fields get populated from the other system...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. v155 Payeezy JS not passing CVV2 variable via Payeezy Developer API
    By adkinsdm in forum Built-in Shipping and Payment Modules
    Replies: 2
    Last Post: 19 Mar 2018, 05:26 AM
  2. v155 Passing variable to function process_button()
    By yaseent in forum General Questions
    Replies: 3
    Last Post: 24 Apr 2017, 04:08 AM
  3. Help directing cart as index page
    By nickohorny in forum Installing on a Linux/Unix Server
    Replies: 1
    Last Post: 17 Nov 2010, 04:31 PM
  4. Passing variable to contact us for To field in store settings
    By MaxBodine in forum General Questions
    Replies: 4
    Last Post: 6 May 2009, 09:19 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