Simple Cart Compliance Checkbox
8 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: April 21, 2014 (RSS)
By Perchpole - April 8, 2014
Hello, All -
I would like to add a compliance checkbox to the Simple Cart order page. This will make users acknowledge they have read the terms and conditions before being able to proceed with payment.
I thought it would be a fairly simple thing to do myself - by adding an additional error to $errorsAndAlerts but I can't seem to follow the code.
Any tips would be most welcome!
:0)
Perch
By Chris - April 11, 2014
Hi Perch,
Add this to the bottom of your customCart.php:
addFilter('sc_order_final_validation', 'my_final_validation', null, 3);
function my_final_validation($errorsAndAlerts, $orderNum, $order) {
if (!@$_REQUEST['agree']) {
$errorsAndAlerts .= "You must agree to the terms!<br>\n";
}
return $errorsAndAlerts;
}
Hope this helps!
Chris
By Perchpole - April 12, 2014
Hi, Chris -
Thanks for this. I added the code as suggested - and added a checkbox to the order page. Sadly however, it doesn't seem to have any effect on the process. The order proceeds to PayPal whether the box is ticked or not!
:0/
Perch
By Chris - April 14, 2014
Hi Perch,
What are your $GLOBALS['SC_PAYMENT_PROCESSOR_FUNCTION'] and/or $GLOBALS['SC_ORDER_OVERRIDE_FUNCTION'] set to?
Chris
By Perchpole - April 15, 2014
Hi, Chris -
$GLOBALS['SC_ORDER_OVERRIDE_FUNCTION'] = 'payPalStandard_simpleCartCheckout';
$GLOBALS['SC_PAYMENT_PROCESSOR_FUNCTION'] isn't set.
Thanks,
Perch
By Chris - April 16, 2014
A ha! It looks like the payPalStandard plugin is missing the sc_order_final_validation plugin hook. Please edit payPalStandard.php, search for "_sc_validateOrderRequest", and add the code in red below after it:
//Simple Cart validation task
$errorsAndAlerts = _sc_validateOrderRequest($order);
if ($errorsAndAlerts) { return $errorsAndAlerts; }
// last-chance order validation before payment (e.g. for inventory remaining checks)
$errorsAndAlerts = applyFilters('sc_order_final_validation', '', $order['num'], $order);
if ($errorsAndAlerts) { return $errorsAndAlerts; }
list($grandTotal, $subTotal, $extraLineItems, $cartItems) = sc_tallyCart($order['num']);
I've added this to our development branch of the plugin, so it will appear in the next version released.
Does that help?
Chris
By Perchpole - April 17, 2014
Hi, Chris -
Perfect. It works now.
If I wanted to go the extra mile - and I always do - how could I print this particular error message at the bottom of the page (where the compliance checkbox is located)?
I supose I'm asking, how do you break apart the $errorsAndAlerts array into it's component parts?
:0)
Perch
By Chris - April 21, 2014
Hi Perch,
$errorsAndAlerts is intended to be used as a string so that it can easily be injected into the top of a page. I think the approach I would take would be to extract the specific error message from $errorsAndAlerts and set a true/false flag for that one field, then check for the flag later down the page:
<?php
$messageToSearchFor = "You must agree to the terms!<br>\n";
$termsCheckboxError = contains($messageToSearchFor, $errorsAndAlerts); // look for the specific error message
if ($termsCheckboxError) {
$errorsAndAlerts = str_replace($messageToSearchFor, '', $errorsAndAlerts); // remove the specific error message
}
?>
<?php if ($errorsAndAlerts): ?>
Errors: <?php echo $errorsAndAlerts ?>
<?php endif ?>
...
<input type="checkbox">
<?php if ($termsCheckboxError): ?>
Please check the box!
<?php endif ?>
Does that help?
Chris