Back to PhocacartUser class

Method convertAddressTwo

public static
convertAddressTwo
(mixed $data, mixed $array = 1)

Method convertAddressTwo - Source code

public static function convertAddressTwo($data, $array = 1)
{
    $dataNew = array();
    if ($array == 1) {
        $dataNew[0] = array();
        // billing
        $dataNew[1] = array();
        // shipping
        $dataNew[2] = array();
        // shipping including postfix _phs
    } else {
        $dataNew[0] = new StdClass();
        $dataNew[1] = new StdClass();
        $dataNew[2] = new StdClass();
    }
    if (!empty($data)) {
        foreach ($data as $k => $v) {
            $pos = strpos($k, '_phs');
            if ($pos === false) {
                if ($array == 1) {
                    $dataNew[0][$k] = $v;
                } else {
                    $dataNew[0]->{$k} = $v;
                }
            } else {
                $kx = str_replace('_phs', '', $k);
                if ($array == 1) {
                    $dataNew[1][$kx] = $v;
                    $dataNew[2][$k] = $v;
                } else {
                    $dataNew[1]->{$kx} = $v;
                    $dataNew[2]->k = $v;
                }
            }
        }
    }
    if (!empty($dataNew[1])) {
        // Set right type for shipping address
        if ($array == 1) {
            $dataNew[1]['type'] = 1;
            $dataNew[2]['type'] = 1;
        } else {
            $dataNew[1]->type = 1;
            $dataNew[2]->type = 1;
        }
    }
    return $dataNew;
}