Adding SKUs via 'code', where multiple product variations exist

UPUP Member
Hi, I'm trying to establish how to add SKUs via 'code', where product variations exist (size) in v2.0. Can somebody please advise whether this is the correct approach, for the SKU (code) to be visible to me as the merchant and invisible to the customer, where the SKU for size Medium is 123456789 and Large is 987654321, or am I barking up the wrong tree:

<select name="size">
<option value="Medium&code=123456789">Medium</option>
<option value="Large&code=987654321">Large</option>
</select>


Many thanks
Matt
Comments
  • fc_adamfc_adam FoxyCart Team
    @UP,

    That's close - but not quite what you want. We have a feature called product option modifiers - which allow you to alter aspects of the product through form options like selects, radio inputs and checkboxes.

    For what you've pasted above, you would approach that like this:
    <input type="hidden" name="code" value="123456789" />
    <select name="size">
    <option value="Medium">Medium</option>
    <option value="Large{c:987654321}">Large</option>
    </select>
    When the customer selects the large - it will update the code parameter to be 987654321. Otherwise it will be the default code.

    To hide the code from the customer's view - if you're on 2.0 you can go to the configuration page of your store's admin and there is a setting there to customise the cart display - and deselect the code option there.
  • UPUP Member
    Thanks @fc_adam, that's really helpful.
  • UPUP Member
    Does anyone have a suggestion as to how the options of 'size' and 'code' from the above example would need to be expressed in PHP, if the data were held in a MySQL database and pulled from there? I assume that SELECT and ECHO are required, but I don't sufficiently understand PHP to express it.

    If it's a big job, is there someone who could be suggested to do the work for me?

    Thanks
    Matt
  • fc_jedfc_jed FoxyCart Team
    @UP

    Thinking about the logic, it's shaping up to be a bigger job than I had anticipated.

    Considering you already have an sql connection up and running, here is a sample code for just one specific product, from Adam's snippet, you could use (note, you would still need to edit this, was meant to be a blueprint):
    $sql = "SELECT `code`, `size` FROM `products` WHERE `product` = '$product'";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
    echo "<form action="https://INSERTYOURSTOREHERE.foxycart.com/cart" method="post" accept-charset="utf-8">";
    $ctr = 0;
    while($row = $result->fetch_assoc()) {
    if($ctr == 0) {
    echo "<input type=\"hidden\" name=\"code\" value=\"".$row["code"]." />";
    echo "<select name=\"size\">";
    echo " <option value=\"".$row["size"]."\">".$row["size"]."</option>";
    } else {
    echo " <option value=\"".$row["size"]."\">".$row["size"]."{c:".$row["code"]."</option>";
    }
    }
    echo "</select>";
    echo "</form>";
    } else {
    echo "0 results";
    }
    The above code would theoretically be wrapped in another while loop where you cycle through $product. The downside is that you would need to make a lot of sql calls.

    There are many more optimal ways to solve this, I just merely pointed out one example to show the complexity of the problem.

    If you don't have any developers working for you, we could send you a list of recommended developers to help you out.
  • UPUP Member
    @fc_jed

    That's very kind of you, thank you. I think it's going to be more difficult than I can handle, so if you could send me your list, that would be great. Thanks again.
Sign In or Register to comment.