Jump to content

Limit number of submissions according to plan and profile


DanielH

Recommended Posts

Hi,

I have a category and user group for dealers as profiles then a category for sale by dealer to post their cars. I would like to limit number of submissions to the  for sale by dealer category unless they have a coupon code from paidlistings limiting their number of submissions or some other way to sell more submission access after they used up their quota using jreviews addons. Each dealer would purchase a plan for their userprofile and a unique coupon would be manually generated according to that plan with the number of or "block " of listing submissions access to the for sale by dealer category, ie:Plan a - coupon for 25 submissions, plan b - coupon for 50 submissions etc...

The question is how do I prohibit access to submissions unless a valid coupon has been generated or a way to go about this that might be cleaner then what I am doing? I know what what I am trying to achieve but now just confused on which way to go after tearing into it for the last two days.

Been working with the filter that only allows one submission per user as a start. Got that working limiting to five submissions using the code in the docs.

/templates/jreviews_overrides/filters/filter_functions.php

 <?php
defined('MVC_FRAMEWORK') or die;

function one_listing_limit_registered_user($permission, $params)
{
  // Uncomment line below to dump filter arguments to the screen
  // dd($permission, $params);
 
  $listingPermissions = (S2Object::make('perm'))->__('listing');
 
  $auth = S2Object::make('auth');
 
  if ( $auth->id > 0 )
  {
    $Model = new S2Model();
 
    $query = sprintf('SELECT count(*) FROM %s WHERE %s = %d AND state = 1', EverywhereComContentModel::_LISTING_TABLE, EverywhereComContentModel::_LISTING_USER_ID, $auth->id);
 
    $count = $Model->query($query,'loadResult');
 
    if ( $count > 5 )
    {
      $listingPermissions->setMessage('Sorry, you already created a listing and there\'s a limit of one listing per user');
 
      return false;
    }
  }
 
  return $permission;
}
 
Clickfwd\Hook\Filter::add('can_create_listing', 'one_listing_limit_registered_user', 10);

How can I tie this together WITH or WITHOUT using a coupon?

Plus if having to manually having to go back and delete all orders for every client when renewing their submission block quotas that might be more then its worth.

While writing this looked at setting the paidlistings plans for userprofile on dealers to expire that way the plan would expire and they could purchase another userprofile listing but wanted to allow dealers profile listing to be permanent being its also my directory. Plus one of the quota in the plan would go toward their profile and not actual vehicle listings. 

Thanks
Daniel

Edited by DanielH
Link to comment
×
×
  • Create New...