VbzCart/v1/class/vcPageContent ckout/HandlePageRequest

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to: navigation, search

Calls

Code

    /*----
      ACTION: Based on what page the user is *requesting* (as determined by DetectPageRequest())
	and the current conditions (mainly: was the previous page's form filled out properly?),
	determine what page to display next.
    */
    protected function HandlePageRequest() {
	// figure out if user is trying to advance, and if so whether to allow it:
	$sPgShow = $this->GetPageKey_forShow();	// 2018-07-22 This probably needs to come from the Content object now.

	// DEBUGGING
	//echo "PAGE KEY FOR SHOW = [$sPgShow]<br>";
	
	// TODO: why don't we just say $formSeqShow = $sPgShow, after checking for a valid $sPgShow?
	switch ($sPgShow) {
	  case KSQ_PAGE_CART:	$formSeqShow = KI_SEQ_CART;	break;
	  case KSQ_PAGE_SHIP:	$formSeqShow = KI_SEQ_SHIP;	break;
	  case KSQ_PAGE_PAY:	$formSeqShow = KI_SEQ_PAY;	break;
	  case KSQ_PAGE_CONF:	$formSeqShow = KI_SEQ_CONF;	break;
	  case KSQ_PAGE_RCPT:	$formSeqShow = KI_SEQ_RCPT;	break;
//	  default: $formSeqShow = 0;	break;
	  default: throw new exception("Page key is [$sPgShow]. How did we get here?");
	}
	//echo "FORMSEQDATA=[".$this->formSeqData."] FORMSEQSHOW=[$formSeqShow]<br>";
	//$didRequestAdvance = !is_null($this->formSeqData) && ($formSeqShow > $this->GetFormSeqData());
	$didRequestAdvance = $this->IsFormSeq_AnAdvanceRequest($formSeqShow);
	//$this->DidRequestAdvance($didRequestAdvance);

	
	$arMissed = $this
	  ->GetCartRecord()
	  ->FieldsManager()		// object that manages checkout data forms
	  ->GetMissingArray()		// array of required fields the user hasn't filled in, so we can complain
	  ;
	if (count($arMissed) > 0) {
	    $okToAdvance = FALSE;
	    if ($didRequestAdvance) {
		// The user tried to advance, so alert user to any missing fields:
		$sList = NULL;
		foreach ($arMissed as $ctrl) {
		    $sAlias = $ctrl->DisplayAlias();
		    if (!is_null($sList)) {
			$sList .= ', ';
		    }
		    $sList .= $sAlias;
		}
		$sMsg = '<b>Some information is missing</b> &ndash; we really need the following items in order to process your order correctly: <b>'
		  .$sList
		  .'</b>'
		  ;
		  //echo 'ARMISSED:'.fcArray::Render($arMissed);
		  //echo 'COUNT: '.count($arMissed).'<br>';
		//die('MISSED STUFF: '.$sMsg);
		$this->FormAlertMessage($sMsg);
	    }
	} else {
	    // For now, we can move on if there aren't any fields missing.
	    $okToAdvance = TRUE;
	    // Later there might be other reasons not to advance.
	}
	
	//echo "REQ ADVANCE?[$didRequestAdvance] OK TO ADVANCE?[$okToAdvance]";
	if ($didRequestAdvance && !$okToAdvance) {
	    // user tried to advance when it wasn't ok -- stay on the same page
	    $this->SetPageKey_forShow($this->GetPageKey_forData());
	}
    }