Post by stenci » Wed Feb 21, 2018 2:32 am

I am trying to make a new shipping extension. I want to send the address and the cart content to another server, the server will check how many shipping options are available and return an array of shipping options. OpenCart should show all the options available and allow the user to select one.
I was able to do everything until the last step, that is OpenCart shows all the options returned by the external calculator.
The problem is that when the user selects one of the options and clicks on Continue, the following warning appears:
Warning: Shipping method required!
What am I doing wrong?

Here is my code:

Code: Select all

  $response = file_get_contents($anvil_url, false, $context);
  $options  = json_decode($response);

  $quote_data = array();

  $n = 0;
  foreach ($options as $option) {
    $n += 1;
    $quote_data['universe' . $n] = array(
      'code'         => 'universe.universe',
      'title'        => $option->title,
      'cost'         => $option->cost,
      'tax_class_id' => 0,
      'text'         => $this->currency->format($option->cost, $this->session->data['currency'])
    );
  }

  $method_data = array(
    'code'       => 'universe' . $n,
    'title'      => $this->language->get('text_title'),
    'quote'      => $quote_data,
    'sort_order' => $this->config->get('shipping_universe_sort_order'),
    'error'      => false
  );

Newbie

Posts

Joined
Tue Dec 05, 2017 4:50 am

Post by Johnathan » Wed Feb 21, 2018 11:28 pm

Based on your code, I think you've missed setting the internal "code" value of each element in the array. It should match the array key that you're setting. I think this change should fix it:

Code: Select all

REPLACE:
'code'         => 'universe.universe',

WITH:
'code'         => 'universe.universe' . $n,

Also, your $method_data array should only have the internal shipping extension code as its "code", so you should remove the $n value from that line:

Code: Select all

'code'       => 'universe',

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am

Who is online

Users browsing this forum: No registered users and 254 guests