Fixing Magento USPS API issue with First-Class Mail Parcel
Critical changes to Magento USPS API!
On September 1st 2017 USPS announced a number of changes to take place, including the reclassification of their “First-Class Mail Parcel” Service to “First-Class Package Service – Retail”. This results in Magento Shipping Methods service being affected. For those of you who are experiencing troubles getting proper shipping rates for USPS on their Magento websites – please follow the easy steps below to rectify the issue:
To resolve the issue, you will need to update your USPS implementation to utilize the new Shipping Method Name.
Important: It is not recommended to update your Magento core files directly. Hopefully Magento Inc will come up with the patch soon.
Fix for Magento 1.x.x
1. In your server, locate the file:
app/code/local/Mage/Usa/Model/Shipping/Carrier/Usps.php2. Copy this file to the path:
app/code/local/Mage/USA/Model/Shipping/Carrier/Usps.php3. Look for “method_to_code”.
4. Locate the following part of the code:
// Added because USPS has different services but with same CLASSID value, which is "0" 'method_to_code' => array( 'First-Class Mail Large Envelope' => '0_FCLE', 'First-Class Mail Letter' => '0_FCL', 'First-Class Mail Parcel' => '0_FCP', ),5. Replace the ‘First-Class Mail Parcel’ with ‘First-Class Package Service – Retail’ (single dash). Make sure the spelling is correct, otherwise Magento will not be able to handle the new naming.
// Added because USPS has different services but with same CLASSID value, which is "0" 'method_to_code' => array( 'First-Class Mail Large Envelope' => '0_FCLE', 'First-Class Mail Letter' => '0_FCL', 'First-Class Package Service - Retail' => '0_FCP', ),6. Double check if there are no more occurrences of ’First-Class Mail Parcel’. If found, make sure to replace these with ‘First-Class Package Service – Retail’ .
7. Optionally, you can also rename Shipping method name. Look for ‘0_FCP’ and change ‘First-Class Mail Parcel’ to ‘First-Class Package Service – Retail’
Fix For Magento 2.x.x
Since you should not edit core Magento 2 files – you need to create the extension that overrides the model “Magento\Usps\Model\Carrier”.
The steps below will outline where is the problem in Magento 2 core files.
1. In your server, locate the file:
vendor/magento/module-usps/Model/Carrier.php2. Look for “method_to_code”.
3. Locate the following part of the code:
// Added because USPS has different services but with same CLASSID value, which is "0" 'method_to_code' => array( 'First-Class Mail Large Envelope' => '0_FCLE', 'First-Class Mail Letter' => '0_FCL', 'First-Class Mail Parcel' => '0_FCP', ),4. Replace the ‘First-Class Mail Parcel’ with ‘First-Class Package Service – Retail’ (single dash). Make sure the spelling is correct, otherwise Magento will not be able to handle the new naming.
// Added because USPS has different services but with same CLASSID value, which is "0" 'method_to_code' => array( 'First-Class Mail Large Envelope' => '0_FCLE', 'First-Class Mail Letter' => '0_FCL', 'First-Class Package Service - Retail' => '0_FCP', ),5. Reminder: Make sure not to edit core Magento 2 files. Instead you need to create the extension that overrides the model “Magento\Usps\Model\Carrier”. To learn more on how to override model file please read here.
Follow Us on Social Media