grayloon / magento-laravel-api

A simple Magento 2 REST API Object Oriented wrapper for Laravel applications.
MIT License
63 stars 46 forks source link

SKU with slash #61

Closed jeroen-hso closed 3 years ago

jeroen-hso commented 3 years ago

Hi Andy,

How to handle sku's with slashes (/)? Do I have to urlencode all the sku's before using an API endpoint or is there setting for this? Is the urlencoding only needed for the url or also for the Postdata?

Thanks!

ahinkle commented 3 years ago

Interesting - haven't come across that before.

Are you able to access the API endpoint(s) by accessing the API directly? e.g. via curl: rest/default/V1/products/some-product-with-a/-slash

I came across this article but it's ages old: https://magento.stackexchange.com/questions/142056/how-to-get-magento2-product-with-rest-if-sku-has-slash

jeroen-hso commented 3 years ago

I found the same issue on stackexchange.

This doesn't work:

     public function getProduct($sku) { // $sku = '1234/56'
         $result = $this->api('products')->show($sku); 
         if ($result->status() == 200) {
             return $result->json();
     }

And this works:

     public function getProduct($sku) { // $sku = '1234/56'
         $sku = urlencode($sku);
         $result = $this->api('products')->show($sku); 
         if ($result->status() == 200) {
             return $result->json();
     }
ahinkle commented 3 years ago

@jeroen-hso ,

Are there any problems with URL encoding as the default on SKUs? I'm open to the idea if not :)

jeroen-hso commented 3 years ago

@ahinkle sorry for the late reply. I don't think there are any problems when the URL for SKU is default encoded. But I'm not a expert on this.

jeroen-hso commented 3 years ago

@ahinkle just found out one problem, when the SKU contains a space URL encoding changes the space to + (I don't understand why suppliers create SKU's with spaces)

https://stackoverflow.com/questions/5572718/php-convert-spaces-in-string-into-20 --> rawurlencode()

ahinkle commented 3 years ago

Yeah, good point. I think for now I'll keep the current implementation and leave it up to the users to pass it how they would like in their own applications. Just feels a bit finicky and could break some applications.