Bienvenido, Invitado
Recordarme

TEMA:

Resource booking based on user subscription. 8 meses 2 semanas antes #245698

  • Autor del tema
  • snappysites
  • Fuera de línea
  • Junior Breezer
  • Junior Breezer
  • Mensajes: 39
  • Gracias recibidas: 0
Thank you, that's be much appreciated.

Este mensaje contiene información confidencial

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Resource booking based on user subscription. 8 meses 1 semana antes #246129

  • Autor del tema
  • snappysites
  • Fuera de línea
  • Junior Breezer
  • Junior Breezer
  • Mensajes: 39
  • Gracias recibidas: 0
Hi, Markus

Any luck?

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Resource booking based on user subscription. 8 meses 1 semana antes #246154

  • Avatar de TheMuffinMan
  • TheMuffinMan
  • Fuera de línea
  • Developer
  • Developer
  • Mensajes: 10064
  • Karma: 167
  • Gracias recibidas: 808
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

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Resource booking based on user subscription. 8 meses 1 semana antes #246179

  • Autor del tema
  • snappysites
  • Fuera de línea
  • Junior Breezer
  • Junior Breezer
  • Mensajes: 39
  • Gracias recibidas: 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

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Resource booking based on user subscription. 8 meses 6 días antes #246226

  • Avatar de TheMuffinMan
  • TheMuffinMan
  • Fuera de línea
  • Developer
  • Developer
  • Mensajes: 10064
  • Karma: 167
  • Gracias recibidas: 808
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;
}

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Tiempo de carga de la página: 0.045 segundos