Jump to content

Recommended Posts

Hello, I am trying to add something to this php script and I don't know how...The following is a validation type script which is used within an online store.  It's purpose is to make sure that when a person chooses a certain size of mattress, that person can then remove a certain size of box spring - and the size must match or they get an error message in their cart via this validation.  This is in a "checkbox" form and I need to add the ability for the person to choose "no thanks"  which would include the box spring..(change their mind), and still allow this validation to work.  If you need to see this in action, please go to http://www.bedstore.com/store/index.php?main_page=product_info&cPath=1_9&products_id=2

 

Thanks for any help

 

<?php

 

function valid_cart(&$reason) {

  $products = $_SESSION['cart']->get_products();

  $total = 0;

 

  for ($i=0, $n=sizeof($products); $i<$n; $i++) {

      $no_foundation = 0;

      // no foundation attribute id is 2

      // values: 6 (full), 8 (King), 7 (Queeen), 5 (Twin)

      if (isset($products[$i]['attributes']['2'])) {

          $no_foundation = $products[$i]['attributes']['2'];

      }

      // size attribute id is 1

      // values 1 (Twin), 2 (Full), 3 (Queen), 4 (King)

      $size = 0;

      if (isset($products[$i]['attributes']['1'])) {

          $size = $products[$i]['attributes']['1'];

      }

      if ($no_foundation != 0) {

          if ($no_foundation == 6 && $size == 2) continue;

          if ($no_foundation == 8 && $size == 4) continue;

          if ($no_foundation == 7 && $size == 3) continue;

          if ($no_foundation == 5 && $size == 1) continue;

          $reason = VALID_FAIL; 

          return false;

      }

  }

  return true;

}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/53440-please-help-a-novice/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.