TOPIC:

Resource booking based on user subscription. 2 weeks 3 days ago #245698

  • Topic Author
  • snappysites
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 39
  • Thanks: 0
Thank you, that's be much appreciated.

This message contains confidential information

Please Log in or Create an account to join the conversation.

Resource booking based on user subscription. 1 week 4 days ago #246129

  • Topic Author
  • snappysites
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 39
  • Thanks: 0
Hi, Markus

Any luck?

Please Log in or Create an account to join the conversation.

Resource booking based on user subscription. 1 week 3 days ago #246154

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 9789
  • Karma: 167
  • Thanks: 785
Sorry, I got swamped.
However, I am in the process of putting it together and got stuck on this part

"a) first getting the user_id and associated commencement_date (most recent date in case this is not their first membership) from the 'members' database table mentioned in point 2 above,"

You referenced being the form "members" the actual "database". Does that mean you want to let people fill out this form prior purchasing anything or do you have an actual, breezingforms unrelated db table "members" that I should hook into?

Regards,
Markus

Please Log in or Create an account to join the conversation.

Resource booking based on user subscription. 1 week 3 days ago #246179

  • Topic Author
  • snappysites
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 39
  • Thanks: 0
There is a form, "Members", which I intend to integrate with the membership products in Breezing Commerce.
That way, each time someone buys a membership, a new form record is created.
I'm assuming, hopefully correctly, that those records would then exist as rows in a database table associated with the form

Please Log in or Create an account to join the conversation.

Resource booking based on user subscription. 1 week 2 days ago #246226

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 9789
  • Karma: 167
  • Thanks: 785
Hi,

here is the before form piece.
I don't think you don't need anything from the form submission because it solely depends on the membership duration if you can pick up anything (if I understood that part correctly).

Please note the comments in the code, they are very important.

Also important is the small setup. There you basically add the allowed groups and allowed product ids that the code is supposed to check for.

The script will only take a look at the latest order being made based on the allowed product ids.

It was not easy to test on your server as your test users don't appear to be actual customers (not having ordered anything), so I tested it locally.

Regarding point e) in your previous post: I think you need to address this using a custom validation.
/**
 * Small Setup
 */
$allowed_groups = array(1,2,10,13);
$allowed_product_ids = array(1735, 1750);

/**
 * First checking if the user is in a membership group
 */
$user   = JFactory::getUser();
$groups = JAccess::getGroupsByUser(JFactory::getUser()->get('id', 0));

$allowed = false;
foreach($groups As $group){
    if(in_array($group, $allowed_groups)){
        $allowed = true;
        break;
    }
}

// if not forbid to submit the form
if(!$allowed){

    // I would suggest to link to an article saying "please purchase a membership first"
    JFactory::getApplication()->redirect("https://path/to/article/with/error.html");
    exit;
}

JArrayHelper::toInteger($allowed_product_ids);

/**
 * Checking if the membership itself is still valid
 */

$db = JFactory::getDbo();
$db->setQuery("Select id From #__breezingcommerce_customers Where userid = " . $db->quote(JFactory::getUser()->get('id', 0)) . " Limit 1");
$customer_id = $db->loadResult();

if(!$customer_id){

    // error for not being a customer
    JFactory::getApplication()->redirect("https://path/to/article/with/nocustomer.html");
    exit;
}

$db->setQuery("Select * From #__breezingcommerce_orders Where customer_id = " . $db->quote($customer_id) . " Order By checkout_date Limit 1");
$last_order = $db->loadObject();

if(!isset($last_order->id) || !$last_order->id){

    // error for not having ordered anything
    JFactory::getApplication()->redirect("https://path/to/article/with/noorder.html");
    exit;
}

$db->setQuery("Select * From #__breezingcommerce_order_items Where product_id In (" . implode(',', $allowed_product_ids) . ") And order_id = " . $db->quote($last_order->id) . " Limit 1");
$last_order_item = $db->loadObject();

if(!isset($last_order_item->id) || !$last_order_item->id){

    // error for not having ordered any item from the main order
    JFactory::getApplication()->redirect("https://path/to/article/with/no_order_item.html");
    exit;
}

// date comparison: if now > expiration date, then we fire an error
// make sure the server has the right timezone enabled or use Joomla's JHtml::Date object to retrieve the website settings and compare with that instead
if( strtotime('now') >= strtotime($last_order_item->verfication_expiration_date)){

    // error page for expired membership
    // here is a little special thing in the end: the expiration date will be transferred to the receiving page and can be picked up there and being displayed
    JFactory::getApplication()->redirect("https://path/to/article/with/membership_expired.html?expired=".urlencode($last_order_item->verfication_expiration_date));
    exit;
}

Please Log in or Create an account to join the conversation.

Time to create page: 0.050 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

Summer Sale!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!