Real numbers at value definition


  • Default avatar
    mokospeti    
     14 years ago
    0

    Hi!

    Thanks for the great component!

    Is it possible to apply reals numbers at value definition? As normal value (not definition) I can use numbers up to two decimals, but at value definition just integers are accepted. It gives the following error: "Please enter a valid value definition".

    And an other question: is it possible to increase the accuracy to 5 decimals?

    Thanks:

    Peter
  • Your avatar
    seyi    
     14 years ago
    0

    Hi Peter,

    You will need to make some changes to the code to get this working.

    within www/administrator/components/com_awocoupon/tables/coupons
    replace line 48
    <?php
    if(!empty($this->coupon_value_def) && !preg_match("/^(\d+\-\d+;)+$/",$this->coupon_value_def)) $err[] = JText::_('PLEASE ENTER A VALID VALUE DEFINITION');
    ?>


    with this
    <?php
    if(!empty($this->coupon_value_def) && !preg_match("/^(\d+\-\d+([.]\d+)?;)+$/",$this->coupon_value_def)) $err[] = JText::_('PLEASE ENTER A VALID VALUE DEFINITION');
    ?>


    and within www/administrator/components/com_awocoupon/views/coupon/tmpl/default.php
    replace line 187
    if(form.coupon_value_def.value!='' && !/^(\d+\-\d+;)+$/.test(form.coupon_value_def.value)) err += '\n<?php echo JText::_('PLEASE ENTER A VALID VALUE DEFINITION'); ?>';


    with this
    if(form.coupon_value_def.value!='' && !/^(\d+\-\d+([.]\d+)?;)+$/.test(form.coupon_value_def.value)) err += '\n<?php echo JText::_('PLEASE ENTER A VALID VALUE DEFINITION'); ?>';


    For the 5 decimal places, that should already work with value definition. If you want that to work with the value field also, you would need to make a small database change. Run this query to modify the value field:
    ALTER TABLE jos_awocoupon MODIFY coupon_value DECIMAL(12,5);



    I will make these changes for the next version: 1.0.2

    Thanks
  • Your avatar
    seyi    
     14 years ago
    0

    Oh and there is one more place to update

    in www/administrator/components/com_awocoupon/assets/virtuemart/ps_coupon_process.php
    alter line 332:
    <?php
    && preg_match("/^(\d+-\d+;)+$/",$coupon_row->coupon_value_def)) {
    ?>


    to
    <?php
    && preg_match("/^(\d+-\d+([.]\d+)?;)+$/",$coupon_row->coupon_value_def)) {
    ?>
  • Default avatar
    mokospeti    
     14 years ago
    0

    Thanks, this works fine.

    One comment: I had the code in line 310 instead of 332 (I have not modified the code before).

    With this modification we can partly solve "Buy One Get One 50% off and the likes" issue:
    https://awodev.com/forum/awocoupon/help-section/buy-one-get-one-50-and-likes.

    You don't need to set up minimum amount for the coupon, just set up a percent coupon, with the following value definition:
    1 - 0;
    2 - 25;
    3 - 16.66667
    4 - 25;
    5 - 20;
    6 - 25;
    7 - 21.42857;
    8 - 25;
    9 - 22.22222;
    etc.

    But this solves just the easier part... this can be used only for one product (unless all of the products price is the same). The coupon grouping is steel needed for the complete solution.
  • Your avatar
    seyi    
     14 years ago
    0

    I have to say, that is a pretty smart solution, would not have thought of that.

    As for being able to combine a bunch of coupons into one, yes, i have toyed with the idea, i just feel there might be too many unintended consequences. For example if more then one coupon applies do you apply them all or just the first one? Im sure that would have to be an option. Another example would be what if you are supposed to apply them all and a product is in more then one coupon, do you discount twice or just the first time you see it?

    Right now its pretty complicated to add a coupon, and this might just add a level of complexity nobody understands, including me.