/** * Gets shipping cost and information about possible errors * * @param string $response * @return array Shipping cost and errors * @internal param string $resonse Reponse from Shipping service server */ public function processResponse($response) { $return = array('cost' => false, 'error' => false, 'delivery_time' => false); $shipping_type = $this->_shipping_info['service_params']['shipping_type']; $response = json_decode($response, true); if ($response['msg']['type'] == 'done') { foreach ($response['calc'] as $calc) { if ($calc['type'] == $shipping_type) { if ($calc['cost'] != 0) { $cost = $calc['cost']; if (CART_PRIMARY_CURRENCY != 'RUB') { $cost = fn_rus_russianpost_format_price_down($cost, 'RUB'); } if (!empty($this->_shipping_info['delivery_time'])) { $plus_day = (int) $this->_shipping_info['delivery_time']; } else { $plus_day = 0; } $return['cost'] = $cost; if (!empty($plus_day)) { $return['delivery_time'] = $calc['days'] . '-' . ($calc['days'] + $plus_day) . ' ' . __('days'); } else { $return['delivery_time'] = $calc['days'] . ' ' . __('days'); } break; } else { $this->_internalError(__('error_occurred')); } } } } else { $return['error'] = $this->processErrors($response); } return $return; }
/** * Gets shipping cost and information about possible errors * * @param string $resonse Reponse from Shipping service server * @return array Shipping cost and errors */ public function processResponse($response) { $return = array('cost' => false, 'error' => false); $matches = array(); preg_match('/<span id=\\"TarifValue\\">([0-9]*[,|][0-9]*)<\\/span>/i', $response, $matches); $shipping_cost = !empty($matches[1]) ? preg_replace('/,/', '.', $matches[1]) : ''; if (CART_PRIMARY_CURRENCY != 'RUB') { $shipping_cost = fn_rus_russianpost_format_price_down($shipping_cost, 'RUB'); } if (empty($this->_error_stack) && $shipping_cost) { $return['cost'] = $shipping_cost; } else { $return['error'] = $this->processErrors($response); } return $return; }
/** * Gets shipping cost and information about possible errors * * @param string $resonse Reponse from Shipping service server * @return array Shipping cost and errors */ public function processResponse($response) { $return = array('cost' => false, 'error' => false); $shipping_settings = $this->_shipping_info['service_params']; $result = (array) json_decode($response, true); if (!empty($result['status']) && $result['status'] == 'OK') { $data_result = $result['data']; if (CART_PRIMARY_CURRENCY != 'RUB') { $data_result['costEntity']['cost'] = fn_rus_russianpost_format_price_down($data_result['costEntity']['cost'], 'RUB'); } $return['cost'] = $data_result['costEntity']['cost']; if ($shipping_settings['shipping_option'] == 'EMS') { $return['delivery_time'] = $data_result['timeEntity']['emsDeliveryTimeRange'] . ' дн.'; } elseif ($shipping_settings['shipping_option'] == 'AVIA') { $return['delivery_time'] = $data_result['timeEntity']['firstClassTime'] . ' дн.'; } else { $return['delivery_time'] = $data_result['timeEntity']['deliveryTime'] . ' дн.'; } } else { $return['error'] = $this->processErrors($response); } return $return; }
/** * Gets shipping cost and information about possible errors * * @param string $resonse Reponse from Shipping service server * @return array Shipping cost and errors */ public function processResponse($response) { $return = array('cost' => false, 'error' => false, 'delivery_time' => false); $cost = json_decode($response, true); if (empty($this->_error_stack) && !empty($cost['rsp']['price'])) { $result = $cost['rsp']['price']; if (CART_PRIMARY_CURRENCY != 'RUB') { $result = fn_rus_russianpost_format_price_down($result, 'RUB'); } if (!empty($cost['rsp']['term']) && !empty($cost['rsp']['term']['min']) && !empty($cost['rsp']['term']['max'])) { if (!empty($this->_shipping_info['service_params']['delivery_time_plus'])) { $plus_day = $this->_shipping_info['service_params']['delivery_time_plus']; } else { $plus_day = 0; } $min_time = $cost['rsp']['term']['min'] + $plus_day; $max_time = $cost['rsp']['term']['max'] + $plus_day; $return['delivery_time'] = $min_time . '-' . $max_time . ' ' . __('days'); } $return['cost'] = $result; } else { $return['error'] = $this->processErrors($cost); } return $return; }