Group products + HMAC

cmoralescmorales Member
in Help edited April 2013
Hello,

I want to sell a "combo" of a PRODUCT1 + OPTIONAL_PRODUCT2 in my site. Clients should be able to select quantity for PRODUCT1, and that number would be applied to OPTIONAL_PRODUCT2 automatically (via JS).

My form looks like this:
<form id="level1" action="MYSTOREURL" method="post" accept-charset="utf-8">
                <label class="price-text"><strong>List Price:</strong></label>
                <label class="price">$150</label><br /><br />
                <strong>Qty:</strong>
                <input type="text" id="qty" name="quantity" size="2" maxlength="3" max="999" value="1">
                <br />
                <br />
                <input type="hidden" name="code" value="Level 1">
                <input type="hidden" name="name" value="PRODUCT NAME">
                <input type="hidden" name="price" value="150">
                <strong>Optional Extras:</strong>
                 <label for="extra1">
                 <input id="extra1" type="radio" name="2:name" value="" checked="checked" />No Extras</label><br />
                 <label for="extra2">
                   <input id="extra2" type="radio" name="2:name" value="EXTRA1_NAME" />EXTRA1_NAME
                 </label>
                 <input id="extra2-price" type="hidden" disabled="disabled" name"2:price" value="199" />
                 <input id="extra2-quantity" type="hidden" disabled="disabled" name"2:quantity" value="1" />
                 <label for="extra3">
                  <input id="extra3" type="radio" name="2:name" value="EXTRA2_NAME" />EXTRA2_NAME
                  <input id="extra3-price" type="hidden" disabled="disabled" name"2:price" value="199" />
                  <input id="extra3-quantity" type="hidden" disabled="disabled" name"2:quantity" value="1" />
                </label>

Through Javascript, I remove the "disabled" parameter from the "extra" hidden fields, if the user selects that he/she wants to add that extra product. So, if a user doesn't select any extra, this is sent:
<input type="text" id="qty" name="quantity" size="2" maxlength="3" max="999" value="1">
                <input type="hidden" name="code" value="Level 1">
                <input type="hidden" name="name" value="PRODUCT NAME">
                <input type="hidden" name="price" value="150">

If the user selects an extra, this is sent:
<input type="text" id="qty" name="quantity" size="2" maxlength="3" max="999" value="1">
                <input type="hidden" name="code" value="Level 1">
                <input type="hidden" name="name" value="PRODUCT NAME">
                <input type="hidden" name="price" value="150">

                 <input id="extra2" type="radio" name="2:name" value="EXTRA1_NAME" />
                 <input id="extra2-price" type="hidden" disabled="disabled" name"2:price" value="199" />
                 <input id="extra2-quantity" type="hidden" disabled="disabled" name"2:quantity" value="1" />

I am using automatic HMCA validation, with the PHP code provided. That code works ok on regular links on other places of the site. If I sent the form without any extras and with 1 as the quantity, it works ok. However,

if I enter a number other than 1 in the quantity, I get this error:
Cart Validation Error: quantity

if I try to add an extra product, I get this other error:
Cart Validation Error: 2:name_hash_present

Do I need to encode the extra products manually? Is there any easier way to acomplish what I am trying?

I am using 1.1

Thanks in advance
Comments
  • fc_adamfc_adam FoxyCart Team
    @cmorales,

    Both products would need to be hashed correctly for the add to cart to work with both present. So that means you'll need to give the extra product a code as well. In terms of being able to change the quantity - you'll need to specify that field as being open which you can do by giving it a value of "--open--" if you're using the automatic hashing method. More details on that here: http://wiki.foxycart.com/static/redirect/price_validation
  • Thanks for your help :)

    I have my input like this now:
    <input type="text" id="qty" name="quantity" size="2" maxlength="3" max="999" value="--OPEN--">
    

    And it works, the only problem being that the input shows the --OPEN-- text to the user at the start. Is that the expected behaviour or am I doing something wrong?

    (I am using the automatic hashing method, indeed)
  • It seems I had an error on my code and that prevented the hashing to happen too:
    name"2:price"
    

    I've fixed that and now the hashing does happen. However, errors are still appearing. If I select the first option, I get:
    Cart Validation Error: 2:name

    However, if I select the second option, I get:


    Cart Validation Error: 2:name
    Cart Validation Error: 2:price
    Cart Validation Error: 2:code
    Cart Validation Error: 2:quantity


    I must point out that I have two similar forms in that page. In the second one, hashing seems to "break" somewhere and it doesn't happen for the extra fields (even though I've fixed the "name"2:name" problem.
  • fc_adamfc_adam FoxyCart Team
    @cmorales, {in response to whisper}

    Looking at your page - the add to cart forms aren't being hashed - could you link us to a page where those inputs have been hashed for us to look at?
  • cmoralescmorales Member
    edited April 2013
    Sorry, I had disabled hashing to test other things, please try again in that same page now.
  • fc_adamfc_adam FoxyCart Team
    @cmorales,

    So I think what you're running into is how you've got your form set up - with multiple "2:" prefixed products. Trying incrementing the prefix for each unique product, and see if that changes anything.
  • That didn't work :(
  • brettbrett FoxyCart Team
    Sorry for the trouble you're having here. Could you whisper me some info?
    * What your site is built with? A CMS or what language, etc.
    * How you've got the hashing going? (How the hashing script is running, what settings you're passing in, etc.)
    * Try turning on the debugging in the hashing script?

    It's definitely not working, but the question is why. Incorrect settings (like having the store domain misconfigured in the hashing script) could be one reason why.
Sign In or Register to comment.