Pregunta

I am working on a carrier module. Delivery price is dynamically fetched from remote server. After that price is included in order details using getOrderShippingCost() method in modulename.php. So, when customer sets a correct address, everything works fine, price is calculated properly. But if there is an error in any address field, for example zipcode is not found, price is just set to 0.

Instead of having 0 I would like to insert a note about what field is wrong and block carrier, but not hide it.

I can identify what field is wrong from response of remote server, but how do I display this information on shipping step of order process? At the moment just I use return false if there is an error. So carrier is just not shown.

Here is the basic code scheme I am using right now:

public function getOrderShippingCost($params)
{
  ...
  if (no errors found)
    return $ret['total'];
  else
    return false;
    // instead of return false I would need something like
    // Tools::displayError('Error text'), or trigger a JS event
}

PS 1.5.4.1

¿Fue útil?

Solución

If somebody else needs this, here is how I managed to display the warning message:

public function getOrderShippingCost($params)
{
  ...
  //error is defined as public variable
  $this->carrierError = $ret['errormsg'];
  if (no errors found)
    return $ret['total'];
  else
    return false;
  // when false is returned, carrier is not displayed, but warning message is displayed using hookDisplayHeader
}

public function hookDisplayHeader($params)
{
  if (isset($this->carrierError) &&
  Tools::getValue('controller') == 'order' &&
  Tools::getValue('step') == '2')
  {
     //running JS do display a warning message that carrier may be available if you fix the wrong field
     ...
  }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top