url to enable / disable coupons


  • Default avatar
    paypal4    
     11 years ago
    0

    Hi,

    Maybe this is an idea:

    A couple of days per x time (week or month or whatever) we want to offer discount in the form of a coupon.
    To enable and /or disable a certain coupon, it would be great if this could be done by calling a certain url. This url can be called from a cron job, making it all automatic.

    Example: on date x I want to enable a certain coupon, and 3 days later, disable it. 13 days later, enable it again for 3 days, etc. Again, 13 days later enable it again for 3 days, and so on...

    To get this working I only need two cron jobs. One that calls a url to enable certain coupon(s) and one that disables the coupon(s) 3 days later.

    When you do this, you have the advantage too of displaying a discount offer text or image, when the cron has enabled the coupon and hide this when the coupon is disabled again. This way you have a fully automatic system that once in a while offers discounts everywhere you want.


    Kind regards,
    Maurice


  • Your avatar
    seyi    
     10 years ago
    0

    Hi Maurice,

    You could accomplish this pretty easily with a little code. In
    www/components/com_awocoupon/controller.php, after this:
    <?php
        
    public function display($cachable false$urlparams false) {
            
    JRequest::setVar('view'JRequest::getCmd('view''coupons'));
            
    parent::display();
        }
    ?>


    add this
    <?php
        
    function publishcoupon() {
            
    // Check for request forgeries
            //JRequest::checkToken() or jexit( 'Invalid Token' );
            
    if(JRequest::getVar'pass')=='ksdfl8923juidh893489') {
                
    $cid     = (int)JRequest::getVar'cid');
                if(!empty(
    $cid)) {
                    require_once 
    JPATH_COMPONENT_ADMINISTRATOR.'/helpers/awocouponModel.php';
                    require_once 
    JPATH_COMPONENT_ADMINISTRATOR.'/models/coupons.php';
                    
    $model = new AwoCouponModelCoupons( );
                    
    $model->publish(array($cid), 1);
                }
            }
            exit;
        }
        function 
    unpublishcoupon() {
            
    // Check for request forgeries
            //JRequest::checkToken() or jexit( 'Invalid Token' );
            
            
    if(JRequest::getVar'pass')=='ksdfl8923juidh893489') {
                
    $cid     = (int)JRequest::getVar'cid');
                if(!empty(
    $cid)) {
                    require_once 
    JPATH_COMPONENT_ADMINISTRATOR.'/helpers/awocouponModel.php';
                    require_once 
    JPATH_COMPONENT_ADMINISTRATOR.'/models/coupons.php';
                    
    $model = new AwoCouponModelCoupons( );
                    
    $model->publish(array($cid), -1);
                }
            }
            exit;
        }
    ?>


    This on its own would not work, unless you can log in as a joomla user in the cron job. So you would need to disable the log in restriction for these tasks. In www/components/com_awocoupon/awocoupon.php change this
    <?php
    if(empty($user->id)) { JFactory::getApplication()->redirect'index.php' );}
    ?>


    to this
    <?php
    if(empty($user->id) && !in_array(JRequest::getCmd('task'),array('publishcoupon','unpublishcoupon'))) { JFactory::getApplication()->redirect'index.php' );}
    ?>



    The url to access and publish/unpublish is this:

    my_website/index.php?option=com_awocoupon&task=publishcoupon&cid=50&pass=ksdfl8923juidh893489
    my_website/index.php?option=com_awocoupon&task=unpublishcoupon&cid=50&pass=ksdfl8923juidh893489


    cid is the coupon_id
    pass is a random string you insert. This is for security so not just anybody can access the information. Be sure to change it within the code.
  • Default avatar
    onjkeeee    
     3 years ago
    0

    Hi, is it possible to customize coupons by day of the week? Let's say I want one coupon to work only on Thursdays, and the second coupon only on Saturday and Sunday.
  • Your avatar
    seyi    
     3 years ago
    0

    Hello,

    time of the day yes, but not day of the week.