1

I am adding Custom shipping rates according to state of UAE in Table rates shipping method. But getting an error because region or state is incorrect.

anyone have idea which is correct region/state code for UAE states (Dubai, Abu Dhabi, Sharjah, Ajman, Fujairah, Ras Al-Khaimah & Umm Al Quwain)

Please check attached screenshots of Table Rate file.

enter image description here

1 Answer 1

1

You can check validation rules in the vendor/magento/module-offline-shipping/Model/ResourceModel/Carrier/Tablerate/CSV/RowParser.php:

/**
 * Retrieve region id from provided row data.
 *
 * @param array $rowData
 * @param int $rowNumber
 * @param ColumnResolver $columnResolver
 * @param int $countryId
 * @return array
 * @throws ColumnNotFoundException
 * @throws RowException
 */
private function getRegionIds(array $rowData, $rowNumber, ColumnResolver $columnResolver, $countryId)
{
    $regionCode = $columnResolver->getColumnValue(ColumnResolver::COLUMN_REGION, $rowData);
    if ($countryId !== '0' && $this->locationDirectory->hasRegionId($countryId, $regionCode)) {
        $regionIds = $this->locationDirectory->getRegionIds($countryId, $regionCode);
    } elseif ($regionCode === '*' || $regionCode === '') {
        $regionIds = [0];
    } else {
        throw new RowException(
            __(
                'The "%1" region or state in row number "%2" is incorrect. '
                . 'Verify the region or state and try again.',
                $regionCode,
                $rowNumber
            )
        );
    }
    return $regionIds;
}

By default the 2.4.4 Magento did not have predefined regions for the UAE, so you can't specify a region in the CSV (except empty string or * which means Any Region).

If you want to use regions you must add them manually in the table directory_country_region (it is pretty easy) or you could use this module (paid!) to add them through admin side.

Seems like this is a correct sql for adding the UAE regions (taken from Magento2 : How to add state options for UAE ):

INSERT INTO directory_country_region VALUES (NULL , 'AE', 'AUH','Abu Dhabir'), (NULL , 'AE', 'AJM','Ajman'), (NULL , 'AE', 'SHJ','Sharjah'), (NULL , 'AE', 'DXB','Dubai'), (NULL , 'AE', 'FUJ','Fujairah'), (NULL , 'AE', 'RAK','Ras Al Khaimah'), (NULL , 'AE', 'UAQ','Umm Al Quwain');
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.