AbanteCart Community

AbanteCart Development => API Development => Topic started by: Rawinder on October 21, 2020, 01:28:58 AM

Title: Shipping Method selection problem
Post by: Rawinder on October 21, 2020, 01:28:58 AM
i'm developing an android app . that interact with API.
all other Post Commands are working in app except one. and i'm not getting the reason behind this

In App i'm Sending Post Command

rt= a/checkout/shipping
token= xxxxxxxxx
mode=Select
shipping_method=default_free_shipping.default_free_shipping
api_key=112233

in android this command return result set of Mode=list command.(means all the data like Shipping Method list)

when i run this Post in Postman .
on first run it Returns Result set Of Mode=List(means all the data like Shipping Method list)
on 2nd run it return its actual out put (status=1, Shipping_method Select)

checking headers and other this but couldn't able to solve this problem
plz help


Title: Re: Shipping Method selection problem
Post by: maxter on October 21, 2020, 08:57:51 AM
I am trying to clarify the question. Are you expecting to see the same list all the time?

What version of Abantecart do you have?
Title: Re: Shipping Method selection problem
Post by: abantecart on October 21, 2020, 09:11:39 AM
I think this is related to the session used in the API. API and requests should be stateless and you will need to provide a full request every time.
What you experience with Android is correct behavior.

We will disable session in the API for version 1.2.17.
I have create an issue here: https://github.com/abantecart/abantecart-src/issues/1435
Feel free to add to it if you have any other suggestions.
Title: Re: Shipping Method selection problem
Post by: Rawinder Dhillon on October 21, 2020, 10:38:59 AM
I am trying to clarify the question. Are you expecting to see the same list all the time?

What version of Abantecart do you have?

no, from android app , (as i already know the shipping methods) i dont need to access list with mode =List
so i want to use "mode= Select" Command(that selects shipping Method)
but Mode=Select Command returns list of shipping Method options
its actual output must be
{
    "status": 1,
    "shipping_select": "success"
}


in postman it returns this output on when i Run this command 2nd time .



Title: Re: Shipping Method selection problem
Post by: Rawinder Dhillon on October 21, 2020, 10:39:27 AM
I am trying to clarify the question. Are you expecting to see the same list all the time?

What version of Abantecart do you have?


im using an older version
Title: Re: Shipping Method selection problem
Post by: Rawinder Dhillon on October 21, 2020, 01:13:10 PM
ok admin :-(
Title: Re: Shipping Method selection problem
Post by: Rawinder Dhillon on October 22, 2020, 12:06:33 PM
if (!isset($this->session->data[ 'shipping_methods' ]) || !$this->config->get('config_shipping_session')) {
         $quote_data = array();

         $results = $this->model_checkout_extension->getExtensions('shipping');
         foreach ($results as $result) {
            $this->loadModel('extension/' . $result[ 'key' ]);

            $quote = $this->{'model_extension_' . $result[ 'key' ]}->getQuote($shipping_address);

            if ($quote) {
               $quote_data[ $result[ 'key' ] ] = array(
                  'title' => $quote[ 'title' ],
                  'quote' => $quote[ 'quote' ],
                  'sort_order' => $quote[ 'sort_order' ],
                  'error' => $quote[ 'error' ]
               );
            }
         }

         $sort_order = array();

         foreach ($quote_data as $key => $value) {
            $sort_order[ $key ] = $value[ 'sort_order' ];
         }

         array_multisort($sort_order, SORT_ASC, $quote_data);

         $this->session->data[ 'shipping_methods' ] = $quote_data;
      }


this function from API print List of shipping methods when condition is true
can someone plz explain the line below?
 
!$this->config->get('config_shipping_session'))
Title: Re: Shipping Method selection problem
Post by: abantecart on October 26, 2020, 06:57:54 AM
config_shipping_session is used to be for optimize number of request to shipping providers and minimize re-qoute requests.
This will not be helpful in API case as session can not be used. 

 

 
Title: Re: Shipping Method selection problem
Post by: Rawinder Dhillon on October 26, 2020, 12:41:09 PM
Thx
Title: Re: Shipping Method selection problem
Post by: abantecart on October 26, 2020, 01:23:47 PM
Rawinder,

Please feel free to provide some feedback and we would be glad to work together and improve Abantecart storefront API.

Version 1.2.17 is active in development now, we can incorporate API updates as well.
Title: Re: Shipping Method selection problem
Post by: Rawinder Dhillon on October 28, 2020, 11:27:34 AM
ok admin , i will

for above problems i drop the idea of executing shipping selection command directly. instead i executed mode =list the select command.
this solved my problem. now im able to select shipping method.