PWaddict

Members
  • Content Count

    535
  • Joined

  • Last visited

Community Reputation

252 Excellent

About PWaddict

  • Rank
    Hero Member

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

1,744 profile views
  1. Already tried that and it doesn't even getting required at all.
  2. I would like a field to be required only if a float field has 0 value (not blank). So, adding this: my_float_field=0 on "Required only if" section it makes the field required when it has 0 value and when it's empty too. Is it possible to get the field required ONLY when it has 0 value?
  3. PWaddict

    @blynx Unfortunately the showinfo parameter doesn't work anymore since it's deprecated. You should remove it from the module.
  4. PWaddict

    I had it there since the beginning where I was actually only validating the title (see first post). So removing title!='' and adding include=all does the job.
  5. PWaddict

    It seems that the problem is caused by the selector: title!='' cause the title on alternate languages is actually empty. EDIT: Removing title!='' and adding include=all now getting the proper json on all languages.
  6. PWaddict

    @kongondo Validating coupons while browsing the site on alternate languages always return "Discount code not found" because the json on those languages is empty. Only on the default language the json is returned properly. Why is this happening???
  7. PWaddict

    and here is the final code for the php template for the hidden page that will get all the available coupons ONLY via ajax: <?php namespace ProcessWire; $couponsArray = array(); $couponsJSON = ''; $coupons = $pages->find("template=paddiscount, title!='', pad_percentage!=''"); if($coupons->count) { foreach($coupons as $coupon) { $couponValidUntil = $coupon->pad_valid_until ? date("Y-m-d", $coupon->pad_valid_until) : ''; $couponsArray[$coupon->title] = $couponValidUntil; } header('Content-Type: application/json'); $couponsJSON = json_encode($couponsArray); } if($config->ajax) { echo $couponsJSON; } ?> If I did something wrong please let me know.
  8. PWaddict

    I think I figured it out. I had to set the template with the hidden coupons page to json header and then modify the js code like this: $.get('../my-hidden-coupons-page/', function (data) { var coupons = data; if (discount != '' && (!coupons.hasOwnProperty(discount))) { alert('Discount not found'); } else if (discount != '' && coupons[discount] != '' && coupons[discount] <= today) { alert('Discount expired'); } });
  9. PWaddict

    @kongondo The coupons are actually exposed in my checkout page source. So I created a new hidden page with a different template and added there only your code to avoid exposing them but now I'm not sure how to proceed. <?php namespace ProcessWire; $couponsArray = array(); $couponsJSON = ''; $coupons = $pages->find("template=paddiscount, title!='', pad_percentage!=''"); if($coupons->count) { foreach($coupons as $coupon) { $couponValidUntil = $coupon->pad_valid_until ? date("Y-m-d", $coupon->pad_valid_until) : ''; $couponsArray[$coupon->title] = $couponValidUntil; } $couponsJSON = json_encode($couponsArray); } ?> <?php if($coupons->count) { ?> <script type="text/javascript">var coupons = <?= $couponsJSON ?>;</script> <?php } else { ?> <script type="text/javascript">var coupons = '';</script> <?php } ?> On checkout page I'm getting the error: "coupons is not defined" on console which is obvious cause this is a different page.
  10. PWaddict

    I'm doing the client side validation cause I have ajaxified the checkout form.
  11. PWaddict

    @kongondo I will try it with your code. Thanks. Isn't the server-side checking done by Padloper? If you go to PadOrderProcess.php on the line 95 there is a piece of code for checking the checkout form for invalid and expired coupons.
  12. PWaddict

    Ok I found how to do it: On php template: <script type="text/javascript">var coupons = <?php $coupons = $pages->find("template=paddiscount, title!='', pad_percentage!=''"); echo "{"; foreach($coupons as $coupon) { if ($coupon->pad_valid_until) { echo " '" . $coupon->title . "' : " . "'" . date("Y-m-d", $coupon->pad_valid_until) . "'" . ","; } else { echo " '" . $coupon->title . "' : " . "'" . "" . "'" . ","; } } echo "};"; ?></script> Outputs something like this: <script type="text/javascript">var coupons = { 'CODE1' : '', 'CODE2' : '2018-09-30',};</script> And the related code on main.js: var discount = $form.find('input[name=pad_discount_code]').val(); var today = new Date(); var dd = today.getDate(); var mm = today.getMonth() + 1; var yyyy = today.getFullYear(); if (dd < 10) { dd = '0' + dd; } if (mm < 10) { mm = '0' + mm; } today = yyyy + '-' + mm + '-' + dd; if (discount != '' && (!coupons.hasOwnProperty(discount))) { alert('Discount code not found'); } else if (discount != '' && coupons[discount] != '' && coupons[discount] <= today) { alert('Discount code expired'); }
  13. I'm currently using this on my php template which outputs this: <script type="text/javascript">var coupons = ['CODE1','CODE2',];</script> <script type="text/javascript">var coupons = <?php $coupons = $pages->find("template=paddiscount, title!='', pad_percentage!=''"); echo "["; foreach($coupons as $coupon) { echo "'" . $coupon->title . "',"; } echo "];"; ?></script> and the related code on my main.js is this: var discount = $form.find('input[name=pad_discount_code]').val(); if (discount != '' && $.inArray(discount, coupons) == -1) { alert('Discount code not found'); } The above is working properly but now on the php template I need to add in the array also a timestamp value ($coupon->pad_valid_until) and on main.js I need to also check if there is timestamp associated with the coupon entered and if that timestamp is less than today then alert('Discount code expired'); I don't have much experience with this stuff and I don't know how to proceed. Can you please help me?
  14. I just converted a Textarea field to Textarea (Multi-language) and the module is working properly for every language.
  15. PWaddict

    This actually works. I forgot earlier to modify the url. So it seems the problem is caused from the way I ajaxified the site. Anyway, thanks for the help.