Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Option Value URL parameter?

    Hi All,

    Is there a url parameter built into zencart where by if you add it to the product page url it can pre select the option?

    for example if option values were

    1 - small
    2 - medium
    3 - large

    is there a param I can add to a product page so that medium is pre-selected?

    eg:

    site.com/index.php?main_page=product_info&products_id=44&optionselected=2

    Cheers

    Phil
    Phil Rogers
    A problem shared is a problem solved.

  2. #2
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: Option Value URL parameter?

    Quote Originally Posted by philip937 View Post
    Hi All,

    Is there a url parameter built into zencart where by if you add it to the product page url it can pre select the option?

    for example if option values were

    1 - small
    2 - medium
    3 - large

    is there a param I can add to a product page so that medium is pre-selected?

    eg:

    site.com/index.php?main_page=product_info&products_id=44&optionselected=2

    Cheers

    Phil
    Not by design. Usually the default attribute is identified in the attributes controller on a per product basis. The recommended setup is to add a read only, default attribute that is not one of the product attributes to prevent the accidental selection of the attribute and instead require the customer to purposefully select one of the attributes.

    Could you identify the reason for needing a url version of assigning such a default, perhaps some assistance could be provided as a result?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: Option Value URL parameter?

    I wish to provide a link that is specific to the size required, as per the requirement detailed above.

    As there is nothing built in I will add some custom code to use php GET from the parameter and set the "selected" attribute to the drop down box where the selected attribute is relevant.
    Phil Rogers
    A problem shared is a problem solved.

  4. #4
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: Option Value URL parameter?

    So im thinking, if the ouput is liek this:

    HTML Code:
    <select name="id[3]" id="attrib-3">
      <option value="2">Choose Size..</option>
      <option value="5">Medium</option>
      <option value="6">Large</option>
    </select>
    The default selected is the top (which is defined by the sort order which controls the order they are written to the page.

    So if the url has ?optionselected=6

    I could use a php GET and use the result to manipulate the select box liek this:

    HTML Code:
    <select name="id[3]" id="attrib-3">
      <option value="2">Choose Size..</option>
      <option value="5">Medium</option>
      <option value="6" selected>Large</option>
    </select>
    so im guessing it'll be a variable that is set to nothing by default, for example
    $selected = "";
    and then
    if option value == GET optionselected {
    $selected = "selected";
    }

    What d'ya think?
    Last edited by philip937; 8 Aug 2014 at 03:01 PM. Reason: removed colour format again
    Phil Rogers
    A problem shared is a problem solved.

  5. #5
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: Option Value URL parameter?

    Quote Originally Posted by philip937 View Post
    So im thinking, if the ouput is liek this:

    HTML Code:
    <select name="id[3]" id="attrib-3">
      <option value="2">Choose Size..</option>
      <option value="5">Medium</option>
      <option value="6">Large</option>
    </select>
    The default selected is the top (which is defined by the sort order which controls the order they are written to the page.

    So if the url has ?optionselected=6

    I could use a php GET and use the result to manipulate the select box liek this:

    HTML Code:
    <select name="id[3]" id="attrib-3">
      <option value="2">Choose Size..</option>
      <option value="5">Medium</option>
      <option value="6" selected>Large</option>
    </select>
    so im guessing it'll be a variable that is set to nothing by default, for example
    $selected = "";
    and then
    if option value == GET optionselected {
    $selected = "selected";
    }

    What d'ya think?
    Couple of things, would want to consider the situation where the default (selected) is identified as something other than the first item/is an item that is to be selected ahead of the desired item to select.

    Also, regarding your check on the get, you want to be sure that the data passed via the get doesn't get abused to do something undesirable, so a couple of things come to mind and may not be all inclusive. Check/verify if the get variable is set, then want to send the variable through the ZC html cleaning function (sorry I have forgotten what it is called) before attempting to validat it's value(s). In the value checks maintain positive control of what has been provided ie, do something for each selection and if not part of that, then basically disregard the value. Don't rely on the data when choosing the third of three options to necessarily mean that since not one of the first 2 that it must be the third option.

    Assuming that the link is something to be "passed out" or posted elsewhere, shouldn't be too much of a problem; however, if the link is to be autogenerated by ZC for display to the customer, that would require additional code to handle that.

    Regarding the code suggested, I would assign a variable to the value of the get, do. The cleanup on it, then inside the loop of the attributes, yes that sequence appears as if it would work.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #6
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: Option Value URL parameter?

    Thinking about it some more, I believe that unless the sort order equals the option_value_id that the numerical sequence of the values does not equate to the sort order. (Ie, could be just as possible that the numbers are reversed but the resulting size description is the same.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #7
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: Option Value URL parameter?

    Quote Originally Posted by mc12345678 View Post
    Thinking about it some more, I believe that unless the sort order equals the option_value_id that the numerical sequence of the values does not equate to the sort order. (Ie, could be just as possible that the numbers are reversed but the resulting size description is the same.
    not sure what you mean by this?

    from what I can see the sort order on the attributes is only used to organise the order of the output to the page.

    the attribute id is unique to each field, therefore if there was some code added inlide to the bit that creates the drop down that does a check on each through the loop:

    PHP Code:
    $selected "";
    if (
    $option_value_id == GET['optionselected']) {
    $selected "selected";

    then which ever attribute was the match would have the "selected" added to the HTML ?
    Last edited by philip937; 15 Aug 2014 at 01:14 PM. Reason: php
    Phil Rogers
    A problem shared is a problem solved.

  8. #8
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: Option Value URL parameter?

    Quote Originally Posted by philip937 View Post
    not sure what you mean by this?

    from what I can see the sort order on the attributes is only used to organise the order of the output to the page.

    the attribute id is unique to each field, therefore if there was some code added inlide to the bit that creates the drop down that does a check on each through the loop:

    PHP Code:
    $selected "";
    if (
    $option_value_id == GET['optionselected']) {
    $selected "selected";

    then which ever attribute was the match would have the "selected" added to the HTML ?
    In your previous post, you had this:
    The default selected is the top (which is defined by the sort order which controls the order they are written to the page.
    Without further discussion/explanation, I didn't want to imply that just because something appears first in the list that it is necessarily to be identified as the default. It was not identified that the option that happened to be first in the list also happened to be the default.

    Further, if in the ZC attributes controller a default option is selected, and then the method applied above of passing a "default" selection is used, if the desired default is below in sort order the attribute controller default, the passed in default/selected will be the selected option, or possibly both may end up selected (haven't tested that thought), either way, the result would be incorrect for the desired action. Prior to assigning the passed in selection, other selections in the list should be "unselected" as a common practice, although the code cycle could be shortened to only unselect those items that appear above the passed in selection assuming that the passed in selection exists in the list.

    So, sorry for the confusion, but the statement was made in relation to the above quoted portion of the previous post.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  9. #9
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: Option Value URL parameter?

    my understanding is that by default the initially selected option isnt selected as such it simply displays the first in the list so in this case:

    HTML Code:
    <select name="id[3]" id="attrib-3">
      <option value="2">Choose Size..</option>
      <option value="5">Medium</option>
      <option value="6">Large</option>
    </select>
    the option "Choose Size.." is writted to the page first becasuse it has the lowest sort value.

    the sort value is irrelevant in what I am trying to achieve becase I plan to utilise the HTML "selected" attribute to make the option I want selected. So in the exaple the order of the list is the same but because Large has the HTML "selected" attribute, when the page loads the large should be pre-selected:

    HTML Code:
    <select name="id[3]" id="attrib-3">
      <option value="2">Choose Size..</option>
      <option value="5">Medium</option>
      <option value="6" selected>Large</option>
    </select>
    does that sound right or am I completly misunderstanding?
    Phil Rogers
    A problem shared is a problem solved.

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

    Default Re: Option Value URL parameter?

    Quote Originally Posted by philip937 View Post
    my understanding is that by default the initially selected option isnt selected as such it simply displays the first in the list so in this case:

    HTML Code:
    <select name="id[3]" id="attrib-3">
      <option value="2">Choose Size..</option>
      <option value="5">Medium</option>
      <option value="6">Large</option>
    </select>
    the option "Choose Size.." is writted to the page first becasuse it has the lowest sort value.

    the sort value is irrelevant in what I am trying to achieve becase I plan to utilise the HTML "selected" attribute to make the option I want selected. So in the exaple the order of the list is the same but because Large has the HTML "selected" attribute, when the page loads the large should be pre-selected:

    HTML Code:
    <select name="id[3]" id="attrib-3">
      <option value="2">Choose Size..</option>
      <option value="5">Medium</option>
      <option value="6" selected>Large</option>
    </select>
    does that sound right or am I completly misunderstanding?
    For the "response" action that you are seeing you are correct; however, the expectation when setting up a first attribute like "Please select..." Is that it is identified as both read only and default. (Therefore would be selected when seen on screen.). So yes, the way the cart is setup (incorrectly as compared to information available in the FAQ for attributes), assigning the selected "large" as the selection would work until someone comes by later and changes/decides on say that first option to be the default/selected. At that point as said before if action is not taken to unselect that option before selecting the desired default, the desired default will not be selected as expected.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v150 Pre Select Attributes With Parameter in URL
    By ShopVille in forum Setting Up Categories, Products, Attributes
    Replies: 7
    Last Post: 3 Feb 2015, 10:31 PM
  2. v151 zen_image ambiguous value for $src parameter
    By chicagoitsystems in forum Bug Reports
    Replies: 6
    Last Post: 19 Dec 2012, 11:58 PM
  3. How to suppress URL &sort= Parameter?
    By rarpsl in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 15 Jan 2012, 11:11 PM
  4. 2nd option value need to be changed by 1st option value
    By userman in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 15 Jan 2008, 03:04 PM
  5. URL Parameter Passing
    By digger149 in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 29 Jun 2007, 12:53 PM

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