Results 1 to 8 of 8
  1. #1
    Join Date
    May 2012
    Posts
    22
    Plugin Contributions
    0

    Default Attribute Display based on user login / logged out status

    Hi,

    Newby to the forum and fairly new to ZenCart, although I've just finished on a project that involved a decent amount of customisation, so I'm also "fairly" familiar with it.

    I've a project for which I'm finalising the spec and I think it should be possible, although I've come up against a few wee issues. Wondered if someone might be able to help.

    Basically each product can have 2 buying options - supply only, supply with fitting.

    I can create these attributes and alter the product pricing based on selection, which is fine. But there are 2 key things I'd like to setup and struggling (despite hours / days of digging around) how to do it. These are:

    1) Only show the "Supply with Fitting" option if the user is logged in, else just show the supply only option.

    2) Be able to check the attributes of products already in the cart, and use the result to determine the attributes shown on other products. Basically we only want the customer to either order by supply only OR by supply and fit. So, if they add a supply only product to the cart and continue shopping, we'd like the attribute selector on other products to only offer supply only until they clear the cart or purchase.

    3) Force through a specific delivery address if Supply & Fit is chosen. Basically, if the customer chooses the fit option, we want the products delivered to the client, who will then deliver them to their customer on the day of fitting. So in such an instance, we'd need to be able to hide the shipping address (or at least the edit option) from the customer and ensure the product is delivered to the client, not the customer

    Hope all this make sense ... and hopefully someone has some input on some of it :-)

    Cheers.

  2. #2
    Join Date
    May 2012
    Posts
    22
    Plugin Contributions
    0

    Default Re: Attribute Display based on user login / logged out status

    Hi,

    After a review of the spec, along with changes to it, much of the above is no longer needed. The core part I'm still struggling with is hiding certain attribute options based on users logged in / logged out status. Is this possible?

    Ta.

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,401
    Plugin Contributions
    87

    Default Re: Attribute Display based on user login / logged out status

    It's certainly doable, with an override modification of /includes/modules/attributes.php. Essentially, you're looking to display the data differently based on the value returned (true/false) by
    Code:
    isset($_SESSION['customer_id'])

  4. #4
    Join Date
    May 2012
    Posts
    22
    Plugin Contributions
    0

    Default Re: Attribute Display based on user login / logged out status

    Excellent. This is the first definitive indication that it's at least possible. Now I know what file to look at, I can at least now start testing ... or at least have a bit more focus on my research into this. It's a custom attribute option that we want to show / hide, so I guess I just need to find the name of it in the DB once I've created it, then write a script within the attribute.php file that states whether to hide or show it?

    Don't like asking people to write the code for me, but this is a file / feature of Zencart I've not had to touch in the past, so if you did have any rough examples of code it'd be much appreciated. Though the response you've provided already is already a huge help!

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,401
    Plugin Contributions
    87

    Default Re: Attribute Display based on user login / logged out status

    You'll want to copy the /includes/modules/attributes.php file to /includes/modules/YOUR_TEMPLATE/attributes.php before you start your modifications, so that it's not overwritten during any future upgrade ... you'll also want to look at /includes/templates/template_default/templates/tpl_modules_attributes.php (the file that actually formats the display). Again, make sure to copy the file from template_default to YOUR_TEMPLATE before you make any modifications.

    There are two parts to an attribute: the option_name and the option_value; you can find out what these numbers are using your admin's Catalog->Attribute Controller.
    Last edited by lat9; 15 May 2012 at 08:52 PM.

  6. #6
    Join Date
    May 2012
    Posts
    22
    Plugin Contributions
    0

    Default Re: Attribute Display based on user login / logged out status

    Hi,

    Just wanted to update this thread since we had success in doing exactly what we wanted, thanks largely to the pointer given by lat9 on what files to look at. We wanted to have an attribute dropdown where the 3 option in the dropdown only displayed if customers were logged in AND were within a certain postcode area. We now have a dropdown attribute on our products that ...

    1) Has 3 options, only 2 of which show by default.
    2) Checks if the user is logged in before starting to deal with the 3rd dropdown option.
    3) If the customer IS logged in, checks that the customers postcode matches a pre-created list of postcodes. If so, 3rd option in dropdown is shown.

    To do this, we copied attributes.php from includes>modules>attributes.php over to includes>modules>our-template>attributes.php. We then wrote an If / Else statement around line 598 of that file (near the bottom, where the code starts for the dropdown. We basicaully duplicated the bit of script and wrote that IF the attribute option in the DB equalled a certain ID, then show X, ELSE, show Y. The only difference between X and Y in this case was that we changed the function name from zen_draw_pull_down_menu to zen_draw_pull_down_menu_xxxx. So, if the attribute option ID equalled a specific number, use our custom function instead.

    We then edited includes>functions>html_output.php by copying / pasting lines 508 - 530 (roughly). This is the script that controls the output of the zen_draw_pull_down_menu function. We renamed the duplicate zen_draw_pull_down_menu_xxxx and manipulated it using standard PHP checks and Zen Sessions.

    So, first off we check if ($_SESSION['customer_id']) is set. If so, we pull the customers postcode from the database and run it against a pre-populated list of postcodes. If both of these are true, then we allow all dropdown values to show. If either isn't true, then we tell the script to show all dropdown values EXCEPT the specific value we want to hide, based on it's ID in the database.

    Took a while, and a lot of testing, but it works exactly as we wanted.

  7. #7
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,262
    Plugin Contributions
    3

    Default Re: Attribute Display based on user login / logged out status

    What a fantastic thread!

    ailtait... THANKS so much for coming back to this discussion to describe how you found your solution...
    19 years a Zencart User

  8. #8
    Join Date
    May 2012
    Posts
    22
    Plugin Contributions
    0

    Default Re: Attribute Display based on user login / logged out status

    I should point out that we did change the spec slightly. We eliminated steps 2 and 3 from my original post, by allowing the customer to add a mixture of fitting types to their basket and a few other mods ... but the core requirement was the functionality of the attribute dropdown, to only show certain items if certain conditions were met.

    Hopefully it's of some use to someone!

 

 

Similar Threads

  1. v151 Product URL on tpl_product_info_display.php to display only when user is logged in?
    By Matt Staines in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 24 Oct 2013, 09:39 AM
  2. Sub Categories based on User login
    By cruddydan in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 31 Jan 2011, 11:31 PM
  3. Replies: 4
    Last Post: 23 Sep 2010, 09:28 PM
  4. display user name in nav bar once logged in
    By Sushigal in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 7 Jul 2010, 11:02 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