예제 #1
0
 private function _generateMD5SecurityKey()
 {
     $concatenationValue = '';
     foreach ($this->_fields['list'] as $paramName => &$valueDetailed) {
         if ($paramName != 'Texte' && $paramName != 'Security') {
             // Mac server make an empty string instead of a cleaned string
             // TODO : test on windows and linux server
             $cleanedString = MRTools::removeAccents($valueDetailed['value']);
             $valueDetailed['value'] = !empty($cleanedString) ? Tools::strtoupper($cleanedString) : Tools::strtoupper($valueDetailed['value']);
             $valueDetailed['value'] = Tools::strtoupper($valueDetailed['value']);
             // Call a pointer function if exist to do different test
             if (isset($valueDetailed['methodValidation']) && method_exists('MRTools', $valueDetailed['methodValidation']) && isset($valueDetailed['params']) && MRTools::$valueDetailed['methodValidation']($valueDetailed['value'], $valueDetailed['params'])) {
                 $concatenationValue .= $valueDetailed['value'];
             } else {
                 if (isset($valueDetailed['regexValidation']) && preg_match($valueDetailed['regexValidation'], $valueDetailed['value'], $matches)) {
                     $concatenationValue .= $valueDetailed['value'];
                 } elseif (!Tools::strlen($valueDetailed['value']) && $valueDetailed['required'] || Tools::strlen($valueDetailed['value'])) {
                     $error = $this->_mondialRelay->l('This key') . ' [' . $paramName . '] ' . $this->_mondialRelay->l('hasn\'t a valide value format') . ' : ' . $valueDetailed['value'];
                     $this->_resultList['error'][] = $error;
                 }
             }
         }
     }
     $concatenationValue .= $this->_webServiceKey;
     $this->_fields['list']['Security']['value'] = Tools::strtoupper(md5($concatenationValue));
 }
예제 #2
0
    public function addSelectedCarrierToDB()
    {
        $db = Db::getInstance();
        // insutance
        $sql = 'SELECT insurance FROM ' . _DB_PREFIX_ . 'mr_method WHERE id_mr_method = ' . (int) $this->_params['id_mr_method'];
        $insurance = $db->getValue($sql);
        $query = 'SELECT `id_mr_selected` FROM `' . _DB_PREFIX_ . 'mr_selected` WHERE `id_cart` = ' . (int) $this->_params['id_cart'] . ' ';
        // Not exist and needed for database
        unset($this->_params['relayPointInfo']['permaLinkDetail']);
        // Update if Exist else add a new entry
        if ($db->getRow($query)) {
            $query = 'UPDATE `' . _DB_PREFIX_ . 'mr_selected` 
				SET `id_method` = ' . (int) $this->_params['id_mr_method'] . ', 
				`MR_insurance` = ' . (int) $insurance . ',';
            if (is_array($this->_params['relayPointInfo'])) {
                foreach ($this->_params['relayPointInfo'] as $nameKey => $value) {
                    $query .= '`MR_Selected_' . MRTools::bqSQL($nameKey) . '` = "' . pSQL($value) . '", ';
                }
            } else {
                // Clean the existing relay point data
                $query .= '
					MR_Selected_Num = NULL,
					MR_Selected_LgAdr1 = NULL, 
					MR_Selected_LgAdr2 = NULL,
					MR_Selected_LgAdr3 = NULL,
					MR_Selected_LgAdr4 = NULL,
					MR_Selected_CP = NULL,
					MR_Selected_Pays = NULL,
					MR_Selected_Ville = NULL, ';
            }
            $query = rtrim($query, ', ') . ' WHERE `id_cart` = ' . (int) $this->_params['id_cart'];
        } else {
            $query = 'INSERT INTO `' . _DB_PREFIX_ . 'mr_selected`
				(`id_customer`, `id_method`, `id_cart`, MR_insurance, ';
            if (is_array($this->_params['relayPointInfo'])) {
                foreach ($this->_params['relayPointInfo'] as $nameKey => $value) {
                    $query .= '`MR_Selected_' . MRTools::bqSQL($nameKey) . '`, ';
                }
            }
            $query = rtrim($query, ', ') . ') VALUES (
					' . (int) $this->_params['id_customer'] . ',
					' . (int) $this->_params['id_mr_method'] . ',
					' . (int) $this->_params['id_cart'] . ', 
					' . (int) $insurance . ', ';
            if (is_array($this->_params['relayPointInfo'])) {
                foreach ($this->_params['relayPointInfo'] as $nameKey => $value) {
                    $query .= '"' . pSQL($value) . '", ';
                }
            }
            $query = rtrim($query, ', ') . ')';
        }
        $db->execute($query);
    }
예제 #3
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');
 }
예제 #4
0
파일: ajax.php 프로젝트: greench/prestashop
        $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);
예제 #5
0
 public function checkPreValidation()
 {
     $errorList = array('error' => array(), 'warn' => array());
     $list = array('Expe_Langage' => array('value' => $this->_mondialrelay->account_shop['MR_LANGUAGE'], 'error' => $this->_mondialrelay->l('Please check your language configuration', $this->class_name)), 'Expe_Ad1' => array('value' => Configuration::get('PS_SHOP_NAME'), 'error' => $this->_mondialrelay->l('Please check your shop name configuration', $this->class_name)), 'Expe_Ad3' => array('value' => Configuration::get('PS_SHOP_ADDR1'), 'error' => $this->_mondialrelay->l('Please check your address 1 configuration', $this->class_name)), 'Expe_Ville' => array('value' => Configuration::get('PS_SHOP_CITY'), 'error' => $this->_mondialrelay->l('Please check your city configuration', $this->class_name)), 'Expe_CP' => array('value' => Configuration::get('PS_SHOP_CODE'), 'error' => $this->_mondialrelay->l('Please check your zipcode configuration', $this->class_name)), 'Expe_Pays' => array('value' => _PS_VERSION_ >= '1.4' ? Country::getIsoById(Configuration::get('PS_SHOP_COUNTRY_ID')) : substr(Configuration::get('PS_SHOP_COUNTRY'), 0, 2), 'error' => $this->_mondialrelay->l('Please check your country configuration', $this->class_name)), 'Expe_Tel1' => array('value' => MRTools::getFormatedPhone(Configuration::get('PS_SHOP_PHONE')), 'error' => $this->_mondialrelay->l('Please check your Phone configuration', $this->class_name)), 'Expe_Mail' => array('value' => Configuration::get('PS_SHOP_EMAIL'), 'error' => $this->_mondialrelay->l('Please check your mail configuration', $this->class_name)));
     foreach ($list as $name => $tab) {
         // Mac server make an empty string instead of a cleaned string
         // TODO : test on windows and linux server
         $cleanedString = MRTools::removeAccents($tab['value']);
         $tab['value'] = !empty($cleanedString) ? strtoupper($cleanedString) : strtoupper($tab['value']);
         if ($name == 'Expe_CP') {
             if (version_compare(_PS_VERSION_, '1.4', '>=')) {
                 if (!($zipcodeError = MRTools::checkZipcodeByCountry($tab['value'], array('id_country' => Configuration::get('PS_COUNTRY_DEFAULT'))))) {
                     $errorList['error'][$name] = $tab['error'];
                 }
             } else {
                 $errorList['warn'][$name] = $this->_mondialrelay->l('Post code cannot be validated with PrestaShop versions older than 1.4', $this->class_name);
             }
         } else {
             if (isset($this->_fields['list'][$name]['regexValidation']) && !preg_match($this->_fields['list'][$name]['regexValidation'], $tab['value'], $matches)) {
                 $errorList['error'][$name] = $tab['error'];
             }
         }
     }
     return $errorList;
 }
예제 #6
0
 /**
  * Converts all accent characters to ASCII characters.
  *
  * If there are no accent characters, then the string given is just returned.
  *
  * @param string $string Text that might have accent characters
  * @return string Filtered string with replaced "nice" characters.
  */
 public static function removeAccents($string)
 {
     if (!preg_match('/[\\x80-\\xff]/', $string)) {
         return $string;
     }
     if (MRTools::seemsUTF8($string)) {
         $chars = array(chr(195) . chr(128) => 'A', chr(195) . chr(129) => 'A', chr(195) . chr(130) => 'A', chr(195) . chr(131) => 'A', chr(195) . chr(132) => 'A', chr(195) . chr(133) => 'A', chr(195) . chr(135) => 'C', chr(195) . chr(136) => 'E', chr(195) . chr(137) => 'E', chr(195) . chr(138) => 'E', chr(195) . chr(139) => 'E', chr(195) . chr(140) => 'I', chr(195) . chr(141) => 'I', chr(195) . chr(142) => 'I', chr(195) . chr(143) => 'I', chr(195) . chr(145) => 'N', chr(195) . chr(146) => 'O', chr(195) . chr(147) => 'O', chr(195) . chr(148) => 'O', chr(195) . chr(149) => 'O', chr(195) . chr(150) => 'O', chr(195) . chr(153) => 'U', chr(195) . chr(154) => 'U', chr(195) . chr(155) => 'U', chr(195) . chr(156) => 'U', chr(195) . chr(157) => 'Y', chr(195) . chr(159) => 's', chr(195) . chr(160) => 'a', chr(195) . chr(161) => 'a', chr(195) . chr(162) => 'a', chr(195) . chr(163) => 'a', chr(195) . chr(164) => 'a', chr(195) . chr(165) => 'a', chr(195) . chr(167) => 'c', chr(195) . chr(168) => 'e', chr(195) . chr(169) => 'e', chr(195) . chr(170) => 'e', chr(195) . chr(171) => 'e', chr(195) . chr(172) => 'i', chr(195) . chr(173) => 'i', chr(195) . chr(174) => 'i', chr(195) . chr(175) => 'i', chr(195) . chr(177) => 'n', chr(195) . chr(178) => 'o', chr(195) . chr(179) => 'o', chr(195) . chr(180) => 'o', chr(195) . chr(181) => 'o', chr(195) . chr(182) => 'o', chr(195) . chr(182) => 'o', chr(195) . chr(185) => 'u', chr(195) . chr(186) => 'u', chr(195) . chr(187) => 'u', chr(195) . chr(188) => 'u', chr(195) . chr(189) => 'y', chr(195) . chr(191) => 'y', chr(196) . chr(128) => 'A', chr(196) . chr(129) => 'a', chr(196) . chr(130) => 'A', chr(196) . chr(131) => 'a', chr(196) . chr(132) => 'A', chr(196) . chr(133) => 'a', chr(196) . chr(134) => 'C', chr(196) . chr(135) => 'c', chr(196) . chr(136) => 'C', chr(196) . chr(137) => 'c', chr(196) . chr(138) => 'C', chr(196) . chr(139) => 'c', chr(196) . chr(140) => 'C', chr(196) . chr(141) => 'c', chr(196) . chr(142) => 'D', chr(196) . chr(143) => 'd', chr(196) . chr(144) => 'D', chr(196) . chr(145) => 'd', chr(196) . chr(146) => 'E', chr(196) . chr(147) => 'e', chr(196) . chr(148) => 'E', chr(196) . chr(149) => 'e', chr(196) . chr(150) => 'E', chr(196) . chr(151) => 'e', chr(196) . chr(152) => 'E', chr(196) . chr(153) => 'e', chr(196) . chr(154) => 'E', chr(196) . chr(155) => 'e', chr(196) . chr(156) => 'G', chr(196) . chr(157) => 'g', chr(196) . chr(158) => 'G', chr(196) . chr(159) => 'g', chr(196) . chr(160) => 'G', chr(196) . chr(161) => 'g', chr(196) . chr(162) => 'G', chr(196) . chr(163) => 'g', chr(196) . chr(164) => 'H', chr(196) . chr(165) => 'h', chr(196) . chr(166) => 'H', chr(196) . chr(167) => 'h', chr(196) . chr(168) => 'I', chr(196) . chr(169) => 'i', chr(196) . chr(170) => 'I', chr(196) . chr(171) => 'i', chr(196) . chr(172) => 'I', chr(196) . chr(173) => 'i', chr(196) . chr(174) => 'I', chr(196) . chr(175) => 'i', chr(196) . chr(176) => 'I', chr(196) . chr(177) => 'i', chr(196) . chr(178) => 'IJ', chr(196) . chr(179) => 'ij', chr(196) . chr(180) => 'J', chr(196) . chr(181) => 'j', chr(196) . chr(182) => 'K', chr(196) . chr(183) => 'k', chr(196) . chr(184) => 'k', chr(196) . chr(185) => 'L', chr(196) . chr(186) => 'l', chr(196) . chr(187) => 'L', chr(196) . chr(188) => 'l', chr(196) . chr(189) => 'L', chr(196) . chr(190) => 'l', chr(196) . chr(191) => 'L', chr(197) . chr(128) => 'l', chr(197) . chr(129) => 'L', chr(197) . chr(130) => 'l', chr(197) . chr(131) => 'N', chr(197) . chr(132) => 'n', chr(197) . chr(133) => 'N', chr(197) . chr(134) => 'n', chr(197) . chr(135) => 'N', chr(197) . chr(136) => 'n', chr(197) . chr(137) => 'N', chr(197) . chr(138) => 'n', chr(197) . chr(139) => 'N', chr(197) . chr(140) => 'O', chr(197) . chr(141) => 'o', chr(197) . chr(142) => 'O', chr(197) . chr(143) => 'o', chr(197) . chr(144) => 'O', chr(197) . chr(145) => 'o', chr(197) . chr(146) => 'OE', chr(197) . chr(147) => 'oe', chr(197) . chr(148) => 'R', chr(197) . chr(149) => 'r', chr(197) . chr(150) => 'R', chr(197) . chr(151) => 'r', chr(197) . chr(152) => 'R', chr(197) . chr(153) => 'r', chr(197) . chr(154) => 'S', chr(197) . chr(155) => 's', chr(197) . chr(156) => 'S', chr(197) . chr(157) => 's', chr(197) . chr(158) => 'S', chr(197) . chr(159) => 's', chr(197) . chr(160) => 'S', chr(197) . chr(161) => 's', chr(197) . chr(162) => 'T', chr(197) . chr(163) => 't', chr(197) . chr(164) => 'T', chr(197) . chr(165) => 't', chr(197) . chr(166) => 'T', chr(197) . chr(167) => 't', chr(197) . chr(168) => 'U', chr(197) . chr(169) => 'u', chr(197) . chr(170) => 'U', chr(197) . chr(171) => 'u', chr(197) . chr(172) => 'U', chr(197) . chr(173) => 'u', chr(197) . chr(174) => 'U', chr(197) . chr(175) => 'u', chr(197) . chr(176) => 'U', chr(197) . chr(177) => 'u', chr(197) . chr(178) => 'U', chr(197) . chr(179) => 'u', chr(197) . chr(180) => 'W', chr(197) . chr(181) => 'w', chr(197) . chr(182) => 'Y', chr(197) . chr(183) => 'y', chr(197) . chr(184) => 'Y', chr(197) . chr(185) => 'Z', chr(197) . chr(186) => 'z', chr(197) . chr(187) => 'Z', chr(197) . chr(188) => 'z', chr(197) . chr(189) => 'Z', chr(197) . chr(190) => 'z', chr(197) . chr(191) => 's', chr(226) . chr(130) . chr(172) => 'E', chr(194) . chr(163) => '');
         $string = strtr($string, $chars);
     } else {
         // Assume ISO-8859-1 if not UTF-8
         $chars['in'] = chr(128) . chr(131) . chr(138) . chr(142) . chr(154) . chr(158) . chr(159) . chr(162) . chr(165) . chr(181) . chr(192) . chr(193) . chr(194) . chr(195) . chr(196) . chr(197) . chr(199) . chr(200) . chr(201) . chr(202) . chr(203) . chr(204) . chr(205) . chr(206) . chr(207) . chr(209) . chr(210) . chr(211) . chr(212) . chr(213) . chr(214) . chr(216) . chr(217) . chr(218) . chr(219) . chr(220) . chr(221) . chr(224) . chr(225) . chr(226) . chr(227) . chr(228) . chr(229) . chr(231) . chr(232) . chr(233) . chr(234) . chr(235) . chr(236) . chr(237) . chr(238) . chr(239) . chr(241) . chr(242) . chr(243) . chr(244) . chr(245) . chr(246) . chr(248) . chr(249) . chr(250) . chr(251) . chr(252) . chr(253) . chr(255);
         $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
         $string = strtr($string, $chars['in'], $chars['out']);
         $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
         $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
         $string = str_replace($double_chars['in'], $double_chars['out'], $string);
     }
     return $string;
 }
예제 #7
0
 private function _generateMD5SecurityKey()
 {
     // RootCase is the array case where the main information are stored
     // it's an array containing id_mr_selected and an array with the necessary fields
     foreach ($this->_fieldsList as &$rootCase) {
         $concatenationValue = '';
         foreach ($rootCase['list'] as $paramName => &$valueDetailed) {
             if ($paramName != 'Texte' && $paramName != 'Security') {
                 // Mac server make an empty string instead of a cleaned string
                 // TODO : test on windows and linux server
                 $cleanedString = MRTools::removeAccents($valueDetailed['value']);
                 $valueDetailed['value'] = !empty($cleanedString) ? strtoupper($cleanedString) : strtoupper($valueDetailed['value']);
                 // Call a pointer function if exist to do different test
                 if (isset($valueDetailed['methodValidation']) && method_exists('MRTools', $valueDetailed['methodValidation']) && isset($valueDetailed['params']) && MRTools::$valueDetailed['methodValidation']($valueDetailed['value'], $valueDetailed['params'])) {
                     $concatenationValue .= $valueDetailed['value'];
                 } else {
                     if (isset($valueDetailed['regexValidation']) && preg_match($valueDetailed['regexValidation'], $valueDetailed['value'], $matches)) {
                         $concatenationValue .= $valueDetailed['value'];
                     } else {
                         if (!strlen($valueDetailed['value']) && $valueDetailed['required'] || strlen($valueDetailed['value'])) {
                             if (empty($valueDetailed['value'])) {
                                 $error = $this->_mondialrelay->l('This key') . ' [' . $paramName . '] ' . $this->_mondialrelay->l('is empty and need to be filled');
                             } else {
                                 $error = 'This key [' . $paramName . '] hasn\'t a valid value format : ' . $valueDetailed['value'];
                             }
                             $this->_resultList['error'][$rootCase['list']['Num']['value']] = $error;
                         }
                     }
                 }
             }
         }
         $concatenationValue .= $this->_webServiceKey;
         $rootCase['list']['Security']['value'] = strtoupper(md5($concatenationValue));
     }
 }
 public function checkPreValidation()
 {
     $errorList = array();
     if (!$this->_mondialRelay) {
         $this->_mondialRelay = new MondialRelay();
     }
     $list = array('Expe_Langage' => array('value' => Configuration::get('MR_LANGUAGE'), 'error' => $this->_mondialRelay->l('Please check your language configuration')), 'Expe_Ad1' => array('value' => Configuration::get('PS_MR_SHOP_NAME'), 'error' => $this->_mondialRelay->l('Please check your shop name configuration')), 'Expe_Ad3' => array('value' => Configuration::get('PS_SHOP_ADDR1'), 'error' => $this->_mondialRelay->l('Please check your address 1 configuration')), 'Expe_Ville' => array('value' => Configuration::get('PS_SHOP_CITY'), 'error' => $this->_mondialRelay->l('Please check your city configuration')), 'Expe_CP' => array('value' => Configuration::get('PS_SHOP_CODE'), 'error' => $this->_mondialRelay->l('Please check your zipcode configuration')), 'Expe_Pays' => array('value' => _PS_VERSION_ >= '1.4' ? Country::getIsoById(Configuration::get('PS_SHOP_COUNTRY_ID')) : substr(Configuration::get('PS_SHOP_COUNTRY'), 0, 2), 'error' => $this->_mondialRelay->l('Please check your country configuration')), 'Expe_Tel1' => array('value' => str_replace(array('.', ' ', '-'), '', Configuration::get('PS_SHOP_PHONE')), 'error' => $this->_mondialRelay->l('Please check your Phone configuration')), 'Expe_Mail' => array('value' => Configuration::get('PS_SHOP_EMAIL'), 'error' => $this->_mondialRelay->l('Please check your mail configuration')));
     foreach ($list as $name => $tab) {
         $tab['value'] = strtoupper($tab['value']);
         if ($name == 'Expe_CP') {
             if (!MRTools::checkZipcodeByCountry($tab['value'], array('id_country' => Configuration::get('PS_COUNTRY_DEFAULT')))) {
                 $errorList[$name] = $tab['error'];
             }
         } else {
             if (isset($this->_fields['list'][$name]['regexValidation']) && !preg_match($this->_fields['list'][$name]['regexValidation'], $tab['value'], $matches)) {
                 $errorList[$name] = $tab['error'];
             }
         }
     }
     return $errorList;
 }
예제 #9
0
 public function checkPreValidation()
 {
     $errorList = array('error' => array(), 'warn' => array());
     $list = array('Expe_Langage' => array('value' => $this->_mondialrelay->account_shop['MR_LANGUAGE'], 'error' => $this->_mondialrelay->l('Please check your language configuration')), 'Expe_Ad1' => array('value' => Configuration::get('PS_SHOP_NAME'), 'error' => $this->_mondialrelay->l('Please check your shop name configuration')), 'Expe_Ad3' => array('value' => Configuration::get('PS_SHOP_ADDR1'), 'error' => $this->_mondialrelay->l('Please check your address 1 configuration')), 'Expe_Ville' => array('value' => Configuration::get('PS_SHOP_CITY'), 'error' => $this->_mondialrelay->l('Please check your city configuration')), 'Expe_CP' => array('value' => Configuration::get('PS_SHOP_CODE'), 'error' => $this->_mondialrelay->l('Please check your zipcode configuration'), 'warn' => $this->_mondialrelay->l('It seems the layout of your zipcode country is not configured or you didn\'t set a right zipcode')), 'Expe_Pays' => array('value' => _PS_VERSION_ >= '1.4' ? Country::getIsoById(Configuration::get('PS_SHOP_COUNTRY_ID')) : substr(Configuration::get('PS_SHOP_COUNTRY'), 0, 2), 'error' => $this->_mondialrelay->l('Please check your country configuration')), 'Expe_Tel1' => array('value' => str_pad(substr(preg_replace('/[^0-9+\\(\\)]*/', '', Configuration::get('PS_SHOP_PHONE')), 0, 10), 10, '0'), 'error' => $this->_mondialrelay->l('Please check your Phone configuration')), 'Expe_Mail' => array('value' => Configuration::get('PS_SHOP_EMAIL'), 'error' => $this->_mondialrelay->l('Please check your mail configuration')));
     foreach ($list as $name => $tab) {
         // Mac server make an empty string instead of a cleaned string
         // TODO : test on windows and linux server
         $cleanedString = MRTools::replaceAccentedCharacters($tab['value']);
         $tab['value'] = !empty($cleanedString) ? strtoupper($cleanedString) : strtoupper($tab['value']);
         if ($name == 'Expe_CP') {
             if (version_compare(_PS_VERSION_, '1.4', '>=')) {
                 if (!($zipcodeError = MRTools::checkZipcodeByCountry($tab['value'], array('id_country' => Configuration::get('PS_COUNTRY_DEFAULT'))))) {
                     $errorList['error'][$name] = $tab['error'];
                 } else {
                     if ($zipcodeError < 0) {
                         $errorList['warn'][$name] = $tab['warn'];
                     }
                 }
             } else {
                 $errorList['warn'][$name] = $this->_mondialrelay->l('Using a PrestaShop version less than 1.4, we can\'t validate the zipcode');
             }
         } else {
             if (isset($this->_fields['list'][$name]['regexValidation']) && !preg_match($this->_fields['list'][$name]['regexValidation'], $tab['value'], $matches)) {
                 $errorList['error'][$name] = $tab['error'];
             }
         }
     }
     return $errorList;
 }
예제 #10
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);
     $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');
     }
 }