Back to PhocacartText class

Method completeTextFormFields

public static
completeTextFormFields
(mixed $body, mixed $basB, mixed $basS)

Method completeTextFormFields - Source code

//public static function completeTextFormFields($body, $bas, $type = 1) {
public static function completeTextFormFields($body, $basB, $basS)
{
    $bas = array_merge($basB, $basS);
    /*if ($type == 1) {
    			$prefix = 'b_';
    		} else {
    			$prefix = 's_';
    		}
    		$commonprefix = 'bs_';
    		*/
    // Common prefix means that if you set:
    // {b_name} ... billing name will be displayed
    // {s_name} ... shipping name will be displayed
    // {bs_name} ... first displaying billing name and if it is not available then display shipping name
    // {sb_name} ... first displaying shipping name and if it is not available then display billing name
    if (!empty($bas)) {
        if (isset($basB['id'])) {
            unset($basB['id']);
        }
        if (isset($basB['order_id'])) {
            unset($basB['order_id']);
        }
        if (isset($basB['user_address_id'])) {
            unset($basB['user_address_id']);
        }
        if (isset($basB['user_token'])) {
            unset($basB['user_token']);
        }
        if (isset($basB['user_groups'])) {
            unset($basB['user_groups']);
        }
        if (isset($basB['ba_sa'])) {
            unset($basB['ba_sa']);
        }
        if (isset($basB['type'])) {
            unset($basB['type']);
        }
        if (isset($basS['id'])) {
            unset($basS['id']);
        }
        if (isset($basS['order_id'])) {
            unset($basS['order_id']);
        }
        if (isset($basS['user_address_id'])) {
            unset($basS['user_address_id']);
        }
        if (isset($basS['user_token'])) {
            unset($basS['user_token']);
        }
        if (isset($basS['user_groups'])) {
            unset($basS['user_groups']);
        }
        if (isset($basS['ba_sa'])) {
            unset($basS['ba_sa']);
        }
        if (isset($basS['type'])) {
            unset($basS['type']);
        }
        foreach ($bas as $k => $v) {
            if (isset($basB[$k]) && $basB[$k] != '') {
                $body = str_replace('{b_' . $k . '}', $basB[$k], $body);
                $body = str_replace('{bs_' . $k . '}', $basB[$k], $body);
            } else {
                if (isset($basS[$k]) && $basS[$k] != '') {
                    // bs_item: the value is not in billing, try to find it in shipping
                    $body = str_replace('{bs_' . $k . '}', $basS[$k], $body);
                }
            }
            if (isset($basS[$k]) && $basS[$k] != '') {
                $body = str_replace('{s_' . $k . '}', $basS[$k], $body);
                $body = str_replace('{sb_' . $k . '}', $basS[$k], $body);
            } else {
                if (isset($basB[$k]) && $basB[$k] != '') {
                    // sb_item: the value is not in shipping, try to find it in billing
                    $body = str_replace('{sb_' . $k . '}', $basB[$k], $body);
                }
            }
            // Nothing found - remove from text
            $body = str_replace('{b_' . $k . '}', '', $body);
            $body = str_replace('{bs_' . $k . '}', '', $body);
            $body = str_replace('{s_' . $k . '}', '', $body);
            $body = str_replace('{sb_' . $k . '}', '', $body);
            /*if ($v != '') {
                  // Replace the values
                  $body = str_replace('{'.$prefix.$k.'}', $v, $body);
                  // Replace common values
                  $body = str_replace('{'.$commonprefix.$k.'}', $v, $body);
              } else {
                  // Hide the empty variable (in case the value is empty, don't display variable name)
                  $body = str_replace('{'.$prefix.$k.'}', '', $body);
                  if ($type != 1) {
                      // Don't remove this common variable in billing cycle because we wait if it will be not transformed in shipping cycle
                      // And if it is not in billing even not in shipping then remove it.
                      $body = str_replace('{'.$commonprefix.$k.'}', '', $body);
                  }
              }*/
        }
    }
    return $body;
}