Back to PhocacartShipping class

Method getShippingMethodIdByMethodName

protected mixed
getShippingMethodIdByMethodName
(mixed $methodName, mixed $return = 3, mixed $onlyPublished = false)
Parameters
  • $methodName
  • int $return 1 ... Association list, 2 ... Object list, 3 ... ID (be aware when setting 3, only first ID will be returned even more methods with the same method name can exist)
  • bool $onlyPublished
Returns
  • mixed

Method getShippingMethodIdByMethodName - Source code

/**
 * @param $methodName
 * @param int $return 1 ... Association list, 2 ... Object list, 3 ... ID (be aware when setting 3, only first ID will be returned even more methods with the same method name can exist)
 * @param bool $onlyPublished
 * @return mixed
 */
protected function getShippingMethodIdByMethodName($methodName, $return = 3, $onlyPublished = false)
{
    $db = Factory::getDBO();
    $query = ' SELECT s.id' . ' FROM #__phocacart_shipping_methods AS s' . ' WHERE s.method = ' . $db->quote($methodName);
    if ($onlyPublished) {
        $query .= ' AND s.published = 1';
    }
    $query .= ' ORDER BY s.id';
    if ($return == 3) {
        $query .= ' LIMIT 1';
    }
    $db->setQuery($query);
    if ($return == 1) {
        return $db->loadAssocList();
    } else {
        if ($return == 2) {
            return $db->loadObjectList();
        } else {
            if ($return == 3) {
                $result = (array) $db->loadObject();
                return $result["id"];
            }
        }
    }
    return false;
}