I am creating an extension for Cartthrob. What I need it to do is not allow the customer to complete their order if there are a certain number of certain products in the cart (there are three products that they can only buy a total of 8 across all three, but two products that they can buy any number of).
I have the extension set up on the cartthrob_update_cart_end to check the items currently in the cart. I was hoping to set a variable (global?) that I could use later on in the checkout template in a conditional. Setting a global variable like this DID NOT work for me:
$this->EE->config->_global_vars['test_var'] = "test var";
When I try to output the variable as {test_var}, it only outputs the variable name (it wasn't parsed). This would most likely be a parse issue, but since this is an extension I thought parsing wouldn't matter.
Some pseudocode I was thinking:
- Update cart hook calls my function in ext.limit_items.php.
- My function counts up all the products and sets a variable "item_count_passed" to either true or false.
- My checkout template loads. Within the template is the following conditional: {if item_count_passed} then show checkout form, else show message.
Is this possible/is there a better way to do this? I am saying this is not specific to Cartthrob since I am just asking how to set a variable in extension code that can be used in a conditional in a template.
Thanks!
Edit: I realize that I am probably looking more for a session variable and not a global variable.
Edit #2: Just to be clear, the root question is: How can I set a variable in an extension that I am writing that would be available in a template, particularly within a conditional?