- Posts: 15
- Thank you received: 0
Conditional Display of Custom Fields in Checkout
14 years 7 months ago #40593
by ddmulro
Conditional Display of Custom Fields in Checkout was created by ddmulro
I run a site that does registrations and equipment orders for a sports club. As part of the checkout process additional information is requested for program registrations (emergency contact, etc) which is not desirable when ordering only equipment. I would like to be able to manipulate the display/input of custom fields in the checkout based on the contents of the cart. My expected approach is to modify the checkout/custom_fields.php view to select which fields are displayed based on the ordered products.
Is there a straightforward method for checking the contents of the cart within the checkout/custom_fields.php view so that the information can be used in conditional statements?
Is there a straightforward method for checking the contents of the cart within the checkout/custom_fields.php view so that the information can be used in conditional statements?
Please Log in or Create an account to join the conversation.
14 years 7 months ago #40771
by nicolas
Replied by nicolas on topic Re: Conditional Display of Custom Fields in Checkout
That's the correct approach.
The cart products should be available in the variable $this->rows
So you could have some foreach on it, like that:
$myproduct_in_the_cart=false;
foreach($this->rows as $row){
if($row->product_code =="myproduct"){
$myproduct_in_the_cart=true;
}
}
The cart products should be available in the variable $this->rows
So you could have some foreach on it, like that:
$myproduct_in_the_cart=false;
foreach($this->rows as $row){
if($row->product_code =="myproduct"){
$myproduct_in_the_cart=true;
}
}
Please Log in or Create an account to join the conversation.
14 years 7 months ago #40805
by ddmulro
Replied by ddmulro on topic Re: Conditional Display of Custom Fields in Checkout
Thanks very much for the reply.
I have tried the code in custom_fields.php, terms.php and cart.php. In the custom_fields.php and terms.php I get the following error:
"Warning: Invalid argument supplied for foreach() in /home/gohsa/public_html/dev/templates/go-hsa/html/com_hikashop/checkout/terms.php on line 23"
In cart.php the code works as desired. Any suggestions as to what else needs to be changed to provide access to the cart information in custom_fields.php and terms.php?
I have tried the code in custom_fields.php, terms.php and cart.php. In the custom_fields.php and terms.php I get the following error:
"Warning: Invalid argument supplied for foreach() in /home/gohsa/public_html/dev/templates/go-hsa/html/com_hikashop/checkout/terms.php on line 23"
In cart.php the code works as desired. Any suggestions as to what else needs to be changed to provide access to the cart information in custom_fields.php and terms.php?
Please Log in or Create an account to join the conversation.
14 years 7 months ago #41009
by nicolas
Replied by nicolas on topic Re: Conditional Display of Custom Fields in Checkout
ah yes, that's because you're not displaying the views together like it is by default so the cart is not loaded by the system. You will have first to load the cart manually like that:
$cartClass = hikashop_get('class.cart');
$cart = $cartClass->loadFullCart(true);
$this->rows =& $cart->products;
$cartClass = hikashop_get('class.cart');
$cart = $cartClass->loadFullCart(true);
$this->rows =& $cart->products;
Please Log in or Create an account to join the conversation.
14 years 7 months ago #41336
by ddmulro
Replied by ddmulro on topic Re: Conditional Display of Custom Fields in Checkout
That works. Thank you very much.
Please Log in or Create an account to join the conversation.
14 years 3 months ago #54856
by Devine
Replied by Devine on topic Re: Conditional Display of Custom Fields in Checkout
I would like to do something similar except I would like to not just hide the fields but hide the entire step. My checkout has Fields as a single step. When I hide the fields I just end up with an empty step.
I'm guessing I need to edit the step.php file. How should I go about this and are there any other issues in just hiding a step?
For example if a field is required, do I need to handle this also?
I'm guessing I need to edit the step.php file. How should I go about this and are there any other issues in just hiding a step?
For example if a field is required, do I need to handle this also?
Please Log in or Create an account to join the conversation.
14 years 3 months ago #54945
by nicolas
Replied by nicolas on topic Re: Conditional Display of Custom Fields in Checkout
Hi,
If you want to remove the whole fields step conditionally, the best will be to create a joomla system plugin which would include the hikashop helper, do your checks, load the config of HikaShop and set the "checkout" of the config based on the result of your checks.
If you remove the whole fields step directly like that, the system won't do any checks on the fields data during the checkout so even if they are required it won't bug you.
If you try to do it via the views like explained on that thread and that you have required fields, the checkout controller won't let you proceed to the next step and you will have to hack the controller. So I would recommend the joomla system plugin overriding the config setting.
If you want to remove the whole fields step conditionally, the best will be to create a joomla system plugin which would include the hikashop helper, do your checks, load the config of HikaShop and set the "checkout" of the config based on the result of your checks.
If you remove the whole fields step directly like that, the system won't do any checks on the fields data during the checkout so even if they are required it won't bug you.
If you try to do it via the views like explained on that thread and that you have required fields, the checkout controller won't let you proceed to the next step and you will have to hack the controller. So I would recommend the joomla system plugin overriding the config setting.
Please Log in or Create an account to join the conversation.
Time to create page: 0.165 seconds