Back to PhocacartShipping class

Method checkAndGetShippingMethods

public bool|array
checkAndGetShippingMethods
(mixed $selectedShippingId = 0, mixed $selected = 0, mixed $total = array())
Check current shipping method or all methods they meet criteria to be selected
Parameters
  • \number $selectedShippingId
  • \number $selected
Returns
  • bool|array

Method checkAndGetShippingMethods - Source code

/**
 * Check current shipping method or all methods they meet criteria to be selected
 * @param number $selectedShippingId
 * @param number $selected
 * @return boolean|array
 */
public function checkAndGetShippingMethods($selectedShippingId = 0, $selected = 0, $total = array())
{
    if (empty($total)) {
        $cart = new PhocacartCartRendercheckout();
        $cart->setType($this->type);
        $cart->setFullItems();
        $total = $cart->getTotal();
        $totalFinal = $total[0];
        //$currentShippingId 		= $cart->getShippingId();
    } else {
        $totalFinal = $total;
    }
    $user = PhocacartUser::getUser();
    $data = PhocacartUser::getUserData((int) $user->id);
    $fields = PhocacartFormUser::getFormXml('', '_phs', 1, 1, 0);
    $dataAddress = array();
    if (!empty($data)) {
        $dataAddress = PhocacartUser::getAddressDataOutput($data, $fields['array'], $user);
    } else {
        // Is this guest user
        $guest = PhocacartUserGuestuser::getGuestUser();
        if ($guest) {
            $data = PhocacartUserGuestuser::getUserAddressGuest();
            $dataAddress = PhocacartUser::getAddressDataOutput($data, $fields['array'], $user, 1);
        }
    }
    $country = $this->getUserCountryShipping($dataAddress);
    $region = $this->getUserRegionShipping($dataAddress);
    $zip = $this->getUserZipShipping($dataAddress);
    /*$country = 0;
    		if(isset($dataAddress['bcountry']) && (int)$dataAddress['bcountry']) {
    			$country = (int)$dataAddress['bcountry'];
    		}
    
    		$region = 0;
    		if(isset($dataAddress['bregion']) && (int)$dataAddress['bregion']) {
    			$region = (int)$dataAddress['bregion'];
    		}*/
    $shippingMethods = $this->getPossibleShippingMethods($totalFinal['netto'], $totalFinal['brutto'], $totalFinal['quantity'], $country, $region, $zip, $totalFinal['weight'], $totalFinal['length'], $totalFinal['width'], $totalFinal['height'], $selectedShippingId, $selected);
    if (!empty($shippingMethods)) {
        return $shippingMethods;
    }
    return false;
}