hmac cart validation errors with bundled product

loopedlooped Member
I currently have hmac validation working fine on single products on a live sites.
I set up a duplicate test site in which I am trying out a 'repeat order' product which requires a parent product with bundled products.
There must be something I have misunderstood about bundled products or hmac validation and any advice would be much appreciated.
I am using your current hmac verification helper function.

When I just add the parent product to the cart, as below, the validation works fine.

<input type="hidden" name="<?= get_verification('name', $page->repeat_title, 'subscribe') ?>" value="<?= $page->repeat_title ?>" />
<input type="hidden" name="<?= get_verification('price', $total_price, 'subscribe') ?>" value="<?= $total_price ?>" />
<input type="hidden" name="<?= get_verification('code', 'subscribe', 'subscribe') ?>" value="subscribe" />
<input type="hidden" name="<?= get_verification('frequency', $page->frequency, 'subscribe') ?>" value="<?= $page->frequency ?>" />
<input type="hidden" name="<?= get_verification('deliveries', $page->deliveries, 'subscribe') ?>" value="<?= $page->deliveries ?>" />
<input type="hidden" name="<?= get_verification('category', 'REPEAT', 'subscribe') ?>" value="REPEAT" />
This is the result from the verification helper:

<input type="hidden" name="fcsid" value="jgrup7eql3elpmhjms7o7668j3">
<input type="hidden" value="Repeat Order - A total of 4 deliveries. A delivery every 30 days" name="name||add6c2818ce825bf0efd4c122ecacd0f81b116f7a654745f633071133b8bce4c">
<input type="hidden" value="4.75" name="price||4396b5201996185d94b38b837d547228f408dd8ec4622ad40c66943c009668c4">
<input type="hidden" value="subscribe" name="code||72513c303b492750e35ff24ddec3bef521dcba3c01236734ceeb83aa5cac336d">
<input type="hidden" value="30" name="frequency||d7ffd243491fbcd68a77fa4f38f40bcad0d23578e6f066bce4c97497b3a76b1b">
<input type="hidden" value="4" name="deliveries||2b5216030dfee58eb0c7f3714245f51dd94ce2aff932672f0f7b697f9ff1d129">
<input type="hidden" value="REPEAT" name="category||dd18c3c331c18d61659159a027e88e2c061d04ffe81455c61ec295bce18784d6">

However, if I then also include a bundled product in the form, as below, the validation fails with multiple errors.

<input type="hidden" name="<?= get_verification('name', $coffee['title'], $coffee['id'], 'subscribe') ?>" value="<?= $coffee['title'] ?>" />
<input type="hidden" name="<?= get_verification('price', $coffee['price'], $coffee['id'], 'subscribe') ?>" value="<?= $coffee['price'] ?>" />
<input type="hidden" name="<?= get_verification('code', $coffee['id'], $coffee['id'], 'subscribe') ?>" value="<?= $coffee['id'] ?>" />
<input type="hidden" name="<?= get_verification('quantity', $coffee['quantity'], $coffee['id'], 'subscribe') ?>" value="<?= $coffee['quantity'] ?>" />
<input type="hidden" name="<?= get_verification('grind', $coffee['grind'].$coffee['option'], $coffee['id'], 'subscribe') ?>" value="<?= $coffee['grind'] ?>" />
<input type="hidden" name="<?= get_verification('parent_code', 'subscribe', $coffee['id'], 'subscribe') ?>" value="subscribe" />
<input type="hidden" name="<?= get_verification('category', 'REPEAT', $coffee['id'], 'subscribe') ?>" value="REPEAT" />
This is the result from the verification helper:

<input type="hidden" value="Monsoon Malabar" name="name||5c15f3e521af8a0b1779c57c31107e4e39a38de483a5b5673fc07e8de60508c9">
<input type="hidden" value="4.75" name="price||74d54aac7aacb7c58962031499ea0cce0be9801c703223717b71b0acfc7b30ef">
<input type="hidden" value="coffee1-1014" name="code||04c4c632e0a5049c611c51625d0b13e6254377daa36d613072d31c40ab9a7ecd">
<input type="hidden" value="4" name="quantity||2f27ddb83bf9cf8f35a1c1e90feba987570e335f2b38426678103714abfa4111">
<input type="hidden" value="Whole Bean" name="grind||800f57208aa4e861abc2f61ae33d9587c4f0bd40044f89cb542982b0446233b9">
<input type="hidden" value="subscribe" name="parent_code||4734cc10b23a1b5579fd69339869b48dcc385b9110ca62465b80e417d24eab0d">
<input type="hidden" value="REPEAT" name="category||f54c129a9911ce0753f5b922d336d77ef00761fcf6af8d0cad250fb8d3003147">
Thank you for any advice you can give me on where I have gone wrong.
I will actually be needing to add multiple products to that one parent but started testing with just the one.

regards,
Louise
Tagged:
Comments
  • fc_adamfc_adam FoxyCart Team
    @looped,

    Sorry to hear you're having trouble! Nothing is immediately clear to me as being an issue at first look. Would it be possible for you to whisper me the store your using for this so we can take a closer look? You can whisper by checking the checkbox and entering my forum username in the text input that appears.
  • fc_adamfc_adam FoxyCart Team
    @looped,

    Thanks for whispering me your store details, I believe I can see the issue.

    You're attempting to add multiple products from within the same form - but you're missing the number prefix for the different products. When adding multiple products at once, each product should be prefixed by a number. For example:
    <input type="hidden" name="name" value="Product 1" />
    <input type="hidden" name="price" value="10" />
    <input type="hidden" name="code" value="prod1" />
    <input type="hidden" name="2:name" value="Product 2" />
    <input type="hidden" name="2:price" value="10" />
    <input type="hidden" name="2:code" value="prod2" />
    When encrypting the add to carts - you encrypt them without the prefix (so the name for the price input for the second product would still be price rather than 2:price), and just add the prefix into the rendered markup.

    Give that a try and see if it fixes the issue you're experiencing.
  • loopedlooped Member
    Thank you for your reply.
    Yes, it was not clear to me from reading the documentation exactly how to proceed with multiple bundled products whilst using the hmac helper.

    Please could you let me know what rendered markup I need to add the prefix to.
    The final page that allows the customer to add the products to the cart purely contains a form with hidden input fields, each with an hmac helper call.
    Where would I add the prefix in the following markup:
    <input type="hidden" name="<?= get_verification('name', $coffee['title'], $coffee['id'], 'subscribe') ?>"  value="<?= $coffee['title'] ?>" />
    <input type="hidden" name="<?= get_verification('price', $coffee['price'], $coffee['id'], 'subscribe') ?>" value="<?= $coffee['price'] ?>" />
    <input type="hidden" name="<?= get_verification('code', $coffee['id'], $coffee['id'], 'subscribe') ?>" value="<?= $coffee['id'] ?>" />
    <input type="hidden" name="<?= get_verification('quantity', $coffee['quantity'], $coffee['id'], 'subscribe') ?>" value="<?= $coffee['quantity'] ?>" />
    <input type="hidden" name="<?= get_verification('grind', $coffee['grind'].$coffee['option'], $coffee['id'], 'subscribe') ?>" value="<?= $coffee['grind'] ?>" />
    <input type="hidden" name="<?= get_verification('parent_code', 'subscribe', $coffee['id'], 'subscribe') ?>" value="subscribe" />
    <input type="hidden" name="<?= get_verification('category', 'REPEAT', $coffee['id'], 'subscribe') ?>" value="REPEAT" />
    Would a prefix still be required even when just adding a single bundled product with the parent product?

    Thanks again for your help clarifying things.
  • fc_adamfc_adam FoxyCart Team
    @looped,

    Happy to help - sorry for the confusion.

    The number prefixes are required as soon as you're adding multiple products within a single form. Otherwise you end up submitting two name fields, two price fields, two code fields - and the form will only actually respect the last one in each instance of a duplication. The number prefixes allow for each product to still be added with the same add to cart.

    Within your HTML it would look like this:

    <pre><input type="hidden" name="2:<?= get_verification('name', $coffee['title'], $coffee['id'], 'subscribe') ?>" value="<?= $coffee['title'] ?>" />
    <input type="hidden" name="2:<?= get_verification('price', $coffee['price'], $coffee['id'], 'subscribe') ?>" value="<?= $coffee['price'] ?>" />


    Note the 2: at the start of the name attribute value itself - but not included in the verification value at all.
  • loopedlooped Member
    Great. That makes complete sense.
    I have now added a number prefix to the parent product and bundled product for testing.
    It looks like that has worked since I am only getting one validation error now on the grind option input.
    Thank you.
  • fc_adamfc_adam FoxyCart Team
    @looped,

    Glad you've made progress! Looking at your form, it looks like the value you pass to the encryption function is different to what you set as the value in the input:
    <input type="hidden" name="<?= get_verification('grind', $coffee['grind'].$coffee['option'], $coffee['id'], 'subscribe') ?>" value="<?= $coffee['grind'] ?>" />
    . Value is just grind, but the value in the encryption is grind with option appended.
  • loopedlooped Member
    Thank you for your reply - yes I corrected it and the validation is working well now.
Sign In or Register to comment.