Magento 2 - Stock levels are not pushed for sku(s) with slash

Magento 2 - Stock levels are not pushed for sku(s) with slash

Overview

When myFulfillment push product stock levels to Magento 2, it uses the following API endpoint :
PUT products/SKU/stockItems/XXX
  1. SKU is the product SKU
  2. XXX is the stock item ID
However, if the SKU contains a slash, it could break the url and create the error "Unable to find stock item ID for sku XXXXXX"
Magento itself recommends to apply a double encoding on SKUs sent to their API, then Boostmyshop uses the following PHP encoding function to make it work : urlencode(rawurlencode($sku))
For example, SKU "ABCD/E" would be transformed to "ABCD%252FE" to make the API call to Magento 2 work. Here the slash "/" is replaced by "%252F" to make the call work.

However, your Apache/Ngnix server must be configured properly to accept this encoding.


How to fix

Here are the different cases to check to ensure your server is properly configured:


1) Apache believes that's an invalid url

==> Add the following instruction in httpd.conf file : AllowEncodedSlashes On


2) Apache decodes the encoded slashes

==> Add the following instruction in httpd.conf file (Requires Apache 2.3.12+) : AllowEncodedSlashes NoDecode

3) "mod_proxy" attempts to re-encode (double encode) the URL

The result will be "mod_proxy" encoding again the already encoded slash "%2F" to "%252F".
For example, http://www.someurl.com would be transformed into http:%252F%252Fwww.someurl.com/)

==> In httpd.conf file, use the ProxyPass keyword nocanon to pass the raw URL through the proxy.
Example httpd.conf file:
AllowEncodedSlashes NoDecode

<Location /example/>
</Location>

Final check

To check if everything is working well after your changes, in myFulfillment go to menu Integrations > [Select your Magento 2 integration] > Tools tab.
There, you will find a "API debug" section containing a "Stock item" field.
In this field, enter the SKU you want to test (use a SKU containing a slash ("/") to check if your previous changes work) :



==> If product details are displayed, that means myFulfillment is well able to process call to your Magento 2 server for SKUs with slash(es).
If you still get the error message "Unable to find stock item ID for sku XXXXXX", that means your changes did not work.
    • Related Articles

    • Stock Helper

      Stock Helper The stock helper screen has been designed to help you to optimize your products ideal & warning stock levels depending of procurement and sales history data. To reach the stock helper screen : In the stock helper grid, you will find one ...
    • Stock levels backup

      Stock level backup Boostmyshop myFulfillment is able to process a backup of your warehouse(s) stock levels everyday, saving results in CSV files that will then be available for download from the warehouse screen. Setup All the stock levels backup ...
    • Magento 2 - Connect your instance to myFulfillment

      Overview The integration between Connect and Magento 2 will : import products and orders from Magento to Connect Send shipping confirmation and stock updates to Magento. When you integrate Connect with a Magento 2 website, you must keep in mind the ...
    • Stock take

      Stock Take The stock take feature has been designed to help you to check at given times your warehouse(s) stock levels. You can access it from menu Inventory >  Stock take. This will lead you to a grid where all stock takes already created will be ...
    • Stock export

      How works stock export Many integrations (Magento, Shopify, Hiboutik, Prestashop etc....) supports the stock export feed. This feed sends the stock available to the external system. The stock sent is calculated using several parameters : First, only ...