inserting minimum quantity value in input field within product option to add to cart.

  • I have three product options that a user can buy/select; sample, a returnable sample and a length of fabric. If the user selects to buy a length of fabric they can enter the length required in a input field next to the radio button, this is not a perch generated input field just a standard hand-coded one. I'd like to fill the "placeholder=" and "min=" attributes with the value of the minimum order quantity for the product. This value is available in the perch:shop namespace but when I use <perch:shop id="spec_min"> nothing is inserted. Any thoughts as to what I'm doing wrong or is this something that simply can't be done?

  • Hi Byron, at that point the namespace is perch:productvalue however "spec_min" is in the perch:shop namespace or there is also min_qty in the perch:variant namespace. I guess the question is how (or is it possible) to call something from another namespace from within the current namespace?

  • Your best option is to then set the spec_min as a global variable. You can run a callback on the 'each' property when fetching the product and find the spec min key and assign it as a global variable there. Something along the lines of the following.


  • So I have…


    Should I now be able to use <perch:content id="spec_min"> to display the value of "spec_min" within the namespace "productvalues" or have I misunderstood. Also when I use…

    PHP
    1. <?php print_r(PerchSystem::get_vars()); ?>

    To see if the value of "spec_min" has been set, nothing is displayed. I was using this to see if the variable was being set

  • I'm not sure how your template is set up so the code supplied was a best guess. You can print out the array to check to see exactly how you need to set it. Once the spec_min is set you'll be able to use it in any namespace, but you'll still need to call the scoped namespace to use it. So in your case you'll need to use <perch:productvalues id="spec_min">.


    It could be the case that the spec_min is set in the variants, so you might need to do some more digging in the array.

  • I've added "spec_min" to the product template there is a (perch) "min_qty" in the variants template. As all the variants will have the same min_qty I thought setting for the product would mean that I wouldn't have to swap it out depending on which variant was selected.

    I'm pretty new to this side of perch so please excuse the dumb questions… but when you say print out the array, how do I do that?

  • In the each loop you can print out the array like you did with the PerchSystem::get_vars()

    PHP
    1. <?php
    2. perch_shop_product('my-product', [
    3. 'template' => 'my-template',
    4. 'each' => function ($item) {
    5. // check the array values
    6. print_r($item);
    7. return $item;
    8. }
    9. ]);
  • when I use print_r($item); "spec_min" is definitely in the mix, however its still not showing up on when I use <perch:productvalues id="spec_min">.
    Is there a way to test if the global variable is actually being set?