$params['id_mr_method'] = Tools::getValue('id_mr_method'); $params['relayPointInfo'] = Tools::getValue('relayPointInfo'); break; default: } // Try to instanciate the method object name and call the necessaries method try { if (class_exists($method, false)) { $obj = new $method($params); // Verify that the class implement correctly the interface // Else use a Management class to do some ajax stuff if ($obj instanceof IMondialRelayWSMethod) { $obj->init(); $obj->send(); $result = $obj->getResult(); } unset($obj); } else { if (($management = new MRManagement($params)) && method_exists($management, $method)) { $result = $management->{$method}(); } else { throw new Exception('Method Class : ' . $method . ' can\'t be found'); } } unset($management); } catch (Exception $e) { echo MRTools::jsonEncode(array('other' => array('error' => array($e->getMessage())))); exit(-1); } echo MRTools::jsonEncode($result); exit(0);
public function hookExtraCarrier($params) { // TODO : Makes it work with multi-shipping if (!MondialRelay::isAccountSet()) { return ''; } $id_carrier = false; $preSelectedRelay = $this->getRelayPointSelected($this->context->cart->id); $carriersList = MondialRelay::_getCarriers(); $address = new Address($this->context->cart->id_address_delivery); $id_zone = Address::getZoneById((int) $address->id); // Check if the defined carrier are ok foreach ($carriersList as $k => $row) { // For now works only with single shipping (>= 1.5 compatibility) if (method_exists($this->context->cart, 'carrierIsSelected')) { if ($this->context->cart->carrierIsSelected($row['id_carrier'], $params['address']->id)) { $id_carrier = $row['id_carrier']; } } // Temporary carrier for some test $carrier = new Carrier((int) $row['id_carrier']); if (Configuration::get('PS_SHIPPING_METHOD') && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false || !Configuration::get('PS_SHIPPING_METHOD') && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false) { unset($carriersList[$k]); } else { if ($row['range_behavior']) { // Get id zone $id_zone = isset($this->context->cart->id_address_delivery) && $this->context->cart->id_address_delivery ? Address::getZoneById((int) $this->context->cart->id_address_delivery) : (int) $this->context->country->id_zone; if (Configuration::get('PS_SHIPPING_METHOD') && !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->context->cart->getTotalWeight(), $id_zone) || !Configuration::get('PS_SHIPPING_METHOD') && (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $this->context->cart->getOrderTotal(true, MondialRelay::BOTH_WITHOUT_SHIPPING), $id_zone, $this->context->cart->id_currency) || !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $this->context->cart->getOrderTotal(true, MondialRelay::BOTH_WITHOUT_SHIPPING), $id_zone, $this->context->cart->id_currency))) { unset($carriersList[$k]); } } } } $carrier = NULL; if (_PS_VERSION_ >= '1.5') { $id_carrier = (int) $this->context->cart->id_carrier; } if ($id_carrier && ($method = MondialRelay::getMethodByIdCarrier($id_carrier))) { $carrier = new Carrier((int) $id_carrier); // Add dynamically a new field $carrier->id_mr_method = $method['id_mr_method']; $carrier->mr_dlv_mode = $method['dlv_mode']; } $this->context->smarty->assign(array('MR_Data' => MRTools::jsonEncode(array('carrier_list' => $carriersList, 'carrier' => $carrier, 'PS_VERSION' => _PS_VERSION_, 'pre_selected_relay' => isset($preSelectedRelay['MR_selected_num']) ? $preSelectedRelay['MR_selected_num'] : 0)))); return $this->fetchTemplate('/tpl/', 'checkout_process'); }
public function hookExtraCarrier($params) { /* TODO : Makes it work with multi-shipping */ if (!MondialRelay::isAccountSet()) { return ''; } $id_carrier = false; $preSelectedRelay = $this->getRelayPointSelected($this->context->cart->id); $carriersList = MondialRelay::_getCarriers(); $address = new Address($this->context->cart->id_address_delivery); $country = new Country($address->id_country); $id_zone = Address::getZoneById((int) $address->id); /* Check if the defined carrier are ok */ foreach ($carriersList as $k => $row) { /* For now works only with single shipping (>= 1.5 compatibility) */ if (method_exists($this->context->cart, 'carrierIsSelected')) { if ($this->context->cart->carrierIsSelected($row['id_carrier'], $params['address']->id)) { $id_carrier = $row['id_carrier']; } } /* Temporary carrier for some test */ $carrier = new Carrier((int) $row['id_carrier']); if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false) { unset($carriersList[$k]); } else { if ($row['range_behavior']) { /* Get id zone */ $id_zone = isset($this->context->cart->id_address_delivery) && $this->context->cart->id_address_delivery ? Address::getZoneById((int) $this->context->cart->id_address_delivery) : (int) $this->context->country->id_zone; if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->context->cart->getTotalWeight(), $id_zone) || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $this->context->cart->getOrderTotal(true, MondialRelay::BOTH_WITHOUT_SHIPPING), $id_zone, $this->context->cart->id_currency) || !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $this->context->cart->getOrderTotal(true, MondialRelay::BOTH_WITHOUT_SHIPPING), $id_zone, $this->context->cart->id_currency))) { unset($carriersList[$k]); } } } } $carrier = null; if ($id_carrier && ($method = MondialRelay::getMethodByIdCarrier($id_carrier))) { $carrier = new Carrier((int) $id_carrier); /* Add dynamically a new field */ $carrier->id_mr_method = $method['id_mr_method']; $carrier->mr_dlv_mode = $method['dlv_mode']; } if (Configuration::get('PS_SSL_ENABLED') || !empty($_SERVER['HTTPS']) && Tools::strtolower($_SERVER['HTTPS']) != 'off') { $ssl = 'true'; } else { $ssl = 'false'; } $this->context->smarty->assign(array('address' => $address, 'account_shop' => $this->account_shop, 'country' => $country, 'ssl' => $ssl, 'MR_Data' => MRTools::jsonEncode(array('carrier_list' => $carriersList, 'carrier' => $carrier, 'PS_VERSION' => _PS_VERSION_, 'pre_selected_relay' => isset($preSelectedRelay['MR_selected_num']) ? $preSelectedRelay['MR_selected_num'] : -1)))); if (Configuration::get('MONDIAL_RELAY_MODE') == 'widget') { return $this->fetchTemplate('/views/templates/front/', 'checkout_process_widget'); } else { return $this->fetchTemplate('/views/templates/front/', 'checkout_process'); } }