Good job for a first override. Keep them going 🙂
My insights:
Override should not contain anything that is not needed. You should delete all methods that you didn't modified, such as aliasExist or getAddressIdBySupplierId.
When you override method, you should always try to call parent version. Sometimes it's not possible, but in your case it is. Your getZoneById should look something like this:
public static function getZoneById($idAddress)
{
$postcode=self::getPostcodeByAddress($idAddress);
if (in_array($postcode,array(2450))) {
return 9;
}
return parent::getZoneById($idAddress);
}
Your new business logic at the very beginning of the method. If the postcode is 2450 then this method will return 9 (id of your new carrier). Otherwise, the original version of the method (from /classes/Address.php) will be called. Calling parent method is very important. It makes sure that your override will work correctly with future versions of thirtybees.
The result override might look like this:
class Address extends AddressCore
{
/**
* Return postcode of address
*
* @param int $id_address Address id
* @return string postcode
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
private static function getPostcodeByAddress($id_address)
{
$row = Db::getInstance()->getRow('
SELECT `postcode`
FROM '._DB_PREFIX_.'address a
WHERE a.`id_address` = '.(int)($id_address));
return $row['postcode'];
}
/**
* Get zone id for a given address
*
* @param int $idAddress Address id for which we want to get zone id
*
* @return int Zone id
*
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @since 1.0.0
* @version 1.0.0 Initial version
*/
public static function getZoneById($idAddress)
{
$postcode = static::getPostcodeByAddress($idAddress);
if (in_array($postcode,array(2450))) {
return 9;
}
return parent::getZoneById($idAddress);
}