Create custom coupons directly in the database


  • Default avatar
    alexandra8    
     10 years ago
    0

    Hi there,

    I am trying to generate personalised coupons directly via a joomla database call as users fill out a email subscription form.

    The concept was working in AWOCoupon 1.x (Free) but seems to no longer work in AWOCoupon Pro 2. I guessed the problem was due to the new passcode field, which appears to be a hash of the coupon code.

    From models/coupon.php it looks like this passcode hash should be:

     
    substr( md5((string)time().rand(1,1000).$_POST['coupon']), 0, 6);


    But this does not seem to work. Is there something in the db request below that would be causing the problem? (The generated coupons neither work nor show up in AWO Coupon in the Back End.

                    $db = JFactory::getDBO();

                            $data =new stdClass();
                $data->id = null;
                $data->coupon_code = $_POST['coupon'];
                $data->num_of_uses_type = 'total';
                $data->num_of_uses = '1';
                $data->coupon_value_type = 'percent'; 
                $data->coupon_value_def = '1-25;4-25;5-0;';   
                $data->min_value = null;
                $data->discount_type = 'overall'; 
                $data->function_type = 'coupon';  
                $data->expiration = $_POST['couponexp'];     
                $data->published = '1';      
                $data->user_type = 'user';

                 /* THIS IS WHERE I GUESS THE PROBLEM IS... */
                            $pcode = substr( md5((string)time().rand(1,1000).$_POST['coupon']), 0, 6);     
                $data->passcode = $pcode;             
                            
                            $db->insertObject( 'j25_awocoupon', $data, id );     


    Thanks
    Will
  • Your avatar
    seyi    
     10 years ago
    0

    Hello,

    Is this a coupon that always as all the same values, except for the coupon code? If so, its much easier to create a template of it, then call
    www/administrator/components/com_awocoupon/helpers/plgautogenerate.php, function generatecoupon. Doing it that way, you dont have to worry about the specifics and the changes. I am not sure why it is failing, but maybe you can review that function (assuming you cannot use it) to find the problem.
  • Default avatar
    alexandra8    
     10 years ago
    0

    Hi Seyi -

    Thanks for the recommendation, definitely looks like it should make things a lot easier, but still doesn't seem to be working.

    In my template I am simply calling the lines below, which is generating a coupon which looks correct in the database, but neither functions nor is visible in the AWOCoupon back end?

    require_once JPATH_ADMINISTRATOR.'/components/com_awocoupon/helpers/plgautogenerate.php'; 
     // print_r(get_declared_classes());
    $coop = new awoAutoGenerate();
    $coop->generateCoupon(332,$_POST['coupon'],$_POST['couponexp']);


    332 - is the template coupon.
    $_POST['coupon'] is a random string - ie: VV62Zm
    $_POST['couponexp'] = is the date two weeks in the future in the format "YYYY-MM-DD"

    Thanks again for the fantastic customer support!!
    Will
  • Your avatar
    seyi    
     10 years ago
    0

    Hello,

    In backend, awocoupon->coupon list, are you able to generate coupons? If so, there must be something wrong within the code that is failing. And you should look at
    www/administrator/components/com_awocoupon/models/coupon.php, where it is used for generating coupons.

    If that is not working, you might have a mysql error in your database. go to global configuration and turn on debug mode and try again to see why its failing.
  • Default avatar
    alexandra8    
     10 years ago
    0

    Ah, problem solved, was a silly mistake at my end. Our estore name is 'virtuemart1' and not 'virtuemart' for some reason, and I wasn't specifying this in the generateCoupon() function.

    Adding the correct estore name to the function parameters fixed the issue.

    Thanks,
    Will