{"id":4014,"date":"2017-09-07T10:48:29","date_gmt":"2017-09-07T10:48:29","guid":{"rendered":"http:\/\/www.plumrocket.com\/blog\/?p=4014"},"modified":"2021-06-30T11:59:21","modified_gmt":"2021-06-30T11:59:21","slug":"fixing-magento-usps-api-issue","status":"publish","type":"post","link":"https:\/\/plumrocket.com\/blog\/fixing-magento-usps-api-issue","title":{"rendered":"Fixing Magento USPS API issue with First-Class Mail Parcel"},"content":{"rendered":"<p>Critical changes to Magento USPS API!<\/p>\n<p>On September 1st 2017 USPS announced a number of changes to take place, including the reclassification of their &#8220;First-Class Mail Parcel&#8221; Service to &#8220;First-Class Package Service \u2013 Retail&#8221;. 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 &#8211; please follow the easy steps below to rectify the issue:<\/p>\n<p>To resolve the issue, you will need to update your USPS implementation to utilize the new Shipping Method Name.<\/p>\n<p><strong>Important:\u00a0<\/strong><span style=\"color: #ff0000;\">It is not recommended to update your Magento core files directly. Hopefully Magento Inc will come up with the patch soon.<\/span><\/p>\n<h2>Fix for\u00a0<strong>Magento 1.x.x<\/strong><\/h2>\n<p>1. In your server, locate the file:<\/p>\n<pre><pre class=\"brush: php; title: ; notranslate\" title=\"\">\napp\/code\/local\/Mage\/Usa\/Model\/Shipping\/Carrier\/Usps.php\n<\/pre>\n<p>2. Copy this file to the path:<\/p>\n<pre><pre class=\"brush: php; title: ; notranslate\" title=\"\">\napp\/code\/local\/Mage\/USA\/Model\/Shipping\/Carrier\/Usps.php\n<\/pre>\n<p>3. Look for <strong>&#8220;method_to_code&#8221;<\/strong>.<\/p>\n<p>4. Locate the following part of the code:<\/p>\n<pre><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\/\/ Added because USPS has different services but with same CLASSID value, which is &quot;0&quot;\n'method_to_code' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; array(\n'First-Class Mail Large Envelope' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; '0_FCLE',\n'First-Class Mail Letter' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; '0_FCL',\n'First-Class Mail Parcel' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; '0_FCP',\n),\n<\/pre>\n<p>5. Replace the <strong>\u2018First-Class Mail Parcel\u2019<\/strong> with <strong>\u2018First-Class Package Service \u2013 Retail\u2019 <\/strong>(single dash). Make sure the spelling is correct, otherwise Magento will not be able to handle the new naming.<\/p>\n<pre><pre class=\"brush: php; highlight: [5]; title: ; notranslate\" title=\"\">\n\/\/ Added because USPS has different services but with same CLASSID value, which is &quot;0&quot;\n'method_to_code' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; array(\n'First-Class Mail Large Envelope' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; '0_FCLE',\n'First-Class Mail Letter' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; '0_FCL',\n'First-Class Package Service - Retail' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; '0_FCP',\n),\n<\/pre>\n<p>6. Double check if there are no more occurrences of \u2019First-Class Mail Parcel\u2019. If found, make sure to replace these with \u2018First-Class Package Service &#8211; Retail\u2019 .<\/p>\n<p>7. Optionally, you can also rename Shipping method name. Look for \u20180_FCP\u2019 and change \u2018First-Class Mail Parcel\u2019 to \u2018First-Class Package Service &#8211; Retail\u2019<\/p>\n<h2>Fix For Magento 2.x.x<\/h2>\n<p><strong>Since you should not edit core Magento 2 files &#8211; you need to create the extension that overrides the model &#8220;Magento\\Usps\\Model\\Carrier&#8221;<\/strong>.<\/p>\n<p>The steps below will outline where is the problem in Magento 2 core files.<\/p>\n<p>1. In your server, locate the file:<\/p>\n<pre><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nvendor\/magento\/module-usps\/Model\/Carrier.php\n<\/pre>\n<p>2. Look for <strong>&#8220;method_to_code&#8221;<\/strong>.<\/p>\n<p>3. Locate the following part of the code:<\/p>\n<pre><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\/\/ Added because USPS has different services but with same CLASSID value, which is &quot;0&quot;\n'method_to_code' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; array(\n'First-Class Mail Large Envelope' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; '0_FCLE',\n'First-Class Mail Letter' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; '0_FCL',\n'First-Class Mail Parcel' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; '0_FCP',\n),\n<\/pre>\n<p>4. Replace the <strong>\u2018First-Class Mail Parcel\u2019<\/strong> with <strong>\u2018First-Class Package Service &#8211; Retail\u2019 <\/strong>(single dash). Make sure the spelling is correct, otherwise Magento will not be able to handle the new naming.<\/p>\n<pre><pre class=\"brush: php; highlight: [5]; title: ; notranslate\" title=\"\">\n\/\/ Added because USPS has different services but with same CLASSID value, which is &quot;0&quot;\n'method_to_code' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; array(\n'First-Class Mail Large Envelope' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; '0_FCLE',\n'First-Class Mail Letter' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; '0_FCL',\n'First-Class Package Service - Retail' =&amp;amp;amp;amp;amp;amp;amp;amp;gt; '0_FCP',\n),\n<\/pre>\n<p>5. <strong>Reminder:<\/strong> Make sure not to edit core Magento 2 files. Instead you need to create the extension that overrides the model &#8220;Magento\\Usps\\Model\\Carrier&#8221;. To learn more on how to override model file please <a title=\"How to override model file for Magento 2\" href=\"https:\/\/magento.stackexchange.com\/questions\/160041\/magento2-how-to-override-model-file\" target=\"_blank\" rel=\"noopener\">read here<\/a>.<\/p>\n<h3>Follow Us on Social Media<\/h3>\n<div class=\"calendar-links\"><a href=\"https:\/\/www.facebook.com\/plumrocket\" target=\"_blank\" rel=\"noopener\"><span class=\"soc-button facebook\"><span class=\"soc-icon\">\u00a0<\/span>Follow us on Facebook<\/span><\/a> <a href=\"https:\/\/twitter.com\/plumrocket\" target=\"_blank\" rel=\"noopener\"><span class=\"soc-button twitter\"><span class=\"soc-icon\">\u00a0<\/span>Follow us on Twitter<\/span><\/a> <a href=\"https:\/\/plus.google.com\/+Plumrocket\/\" target=\"_blank\" rel=\"noopener\"><span class=\"soc-button google-plus\"><span class=\"soc-icon\">\u00a0<\/span>Follow us on Google +<\/span><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Critical changes to Magento USPS API! On September 1st 2017 USPS announced a number of changes to take place, including the reclassification of their &#8220;First-Class Mail Parcel&#8221; Service to &#8220;First-Class Package Service \u2013 Retail&#8221;. This results in Magento Shipping Methods service being affected. For those of you who are experiencing troubles getting proper shipping rates&#133; <a class=\"read-more\" href=\"https:\/\/plumrocket.com\/blog\/fixing-magento-usps-api-issue\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":4021,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22,11,12],"tags":[438,439,327,425],"table_tags":[],"_links":{"self":[{"href":"https:\/\/plumrocket.com\/blog\/wp-json\/wp\/v2\/posts\/4014"}],"collection":[{"href":"https:\/\/plumrocket.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/plumrocket.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/blog\/wp-json\/wp\/v2\/comments?post=4014"}],"version-history":[{"count":35,"href":"https:\/\/plumrocket.com\/blog\/wp-json\/wp\/v2\/posts\/4014\/revisions"}],"predecessor-version":[{"id":7014,"href":"https:\/\/plumrocket.com\/blog\/wp-json\/wp\/v2\/posts\/4014\/revisions\/7014"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/blog\/wp-json\/wp\/v2\/media\/4021"}],"wp:attachment":[{"href":"https:\/\/plumrocket.com\/blog\/wp-json\/wp\/v2\/media?parent=4014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/plumrocket.com\/blog\/wp-json\/wp\/v2\/categories?post=4014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/plumrocket.com\/blog\/wp-json\/wp\/v2\/tags?post=4014"},{"taxonomy":"table_tags","embeddable":true,"href":"https:\/\/plumrocket.com\/blog\/wp-json\/wp\/v2\/table_tags?post=4014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}