Posted by brianV on December 14, 2007 at 9:25pm
One of the Ecommerce sites I am building cannot ship to several states as they don't allow alcohol to be shipped in for various legal reasons, so I am trying to prevent transactions with a shipping address in one of those states from being completed with a checkoutapi hook.
Unfortunately, it doesn't seem to kick in when I try to checkout with a shipping address from one of these states - it lets me continue on to Paypal. Where am I going wrong?
<?php
/* Implementation of hook_checkoutapi to make sure we don't ship to Mass, Pens, and Utah */
function vinvillage_checkoutapi(&$txn, $op) {
switch ($op) {
case 'review_validate':
$shipping = $txn->address['shipping'];
if ((drupal_strtoupper($shipping->state) == 'UT') ||
(drupal_strtoupper($shipping->state) == 'PA') ||
(drupal_strtoupper($shipping->state) == 'MA')) {
// setting the error on 'op', since that is the only visible form element.
form_set_error('op', t('Sorry, but we can not ship to Utah, Pennsylvania or Massachussetts.'));
}
break;
}
}
?>
Comments
Not sure, but because it's
Not sure, but because it's you, I'll stick my oar in anyway.
Two quick things: 1) if (in_array(drupal_strtoupper($shipping->state), array('UT', 'PA', 'MA')) { // stuff }
2) Could you not just remove these states from the taxonomy which I assume they are contained within? Hmm no that would prevent people in those states buying and shipping elsewhere... How about altering the shipping address form...?
Web Development in Nottingham, UK by Kineta Systems / Follow me on Twitter! @NikLP
1.) I'll give this a shot in
1.) I'll give this a shot in a few hours, when I get to the office.
2.) Doesn't work - shipping and billing addresses are just one base address type which is then used for both roles. Billing addresses in these states are allowed, provided that they ship somewhere else. If we were to remove the states from the list on the address form, then we couldn't create billing addresses to those states either.
Thanks for the reply!
Brian Vuyk
Senior Developer, PINGV Creative
bv@pingv.com | (315) 849-9733 | Skype: brianvuyk
so what?
So what happened after? I'm also intrested to blacklist all countries different by shop's country.
Hello. Prior to getting this
Hello.
Prior to getting this working, the client decided to go a different way with the store - he set up a deal with a distributer where the distributor took care of the ecommerce / product listing etc. while paying the client a percentage of the sales through the site.
Brian
Brian Vuyk
Senior Developer, PINGV Creative
bv@pingv.com | (315) 849-9733 | Skype: brianvuyk