Beispiel #1
0
 public function getCountriesForMethod($method_id)
 {
     $method_id = intval($method_id);
     if (empty($method_id)) {
         return array();
     }
     $collection = $this->_countryMethodFactory->create()->getCollection();
     $collection->addFieldToSelect('*');
     $collection->addFieldToFilter('main_table.method_id', $method_id);
     $collection->getSelect()->join($collection->getTable('s2p_gp_countries'), 's2p_gp_countries.country_id = main_table.country_id');
     $collection->setOrder('s2p_gp_countries.name', $collection::SORT_ORDER_ASC);
     $return_arr = array();
     while ($country_obj = $collection->fetchItem() and $country_arr = $country_obj->getData()) {
         if (empty($country_arr['country_id'])) {
             continue;
         }
         $return_arr[$country_arr['country_id']] = $country_arr;
     }
     return $return_arr;
 }
 public function getConfiguredMethodsForCountryID($country_id, $params = false)
 {
     $country_id = intval($country_id);
     if (empty($country_id)) {
         return array();
     }
     if (empty($params) or !is_array($params)) {
         $params = array();
     }
     if (empty($params['id_in_index'])) {
         $params['id_in_index'] = false;
     }
     // 1. get a list of methods available for provided country
     // 2. get default surcharge (s2p_gp_methods_configured.country_id = 0)
     // 3. overwrite default surcharges for particular cases (if available) (s2p_gp_methods_configured.country_id = $country_id)
     //
     // START 1. get a list of methods available for provided country
     //
     $cm_collection = $this->_countryMethodFactory->create()->getCollection();
     $cm_collection->addFieldToSelect('*');
     $cm_collection->addFieldToFilter('country_id', $country_id);
     $cm_collection->getSelect()->join($cm_collection->getTable('s2p_gp_methods'), 's2p_gp_methods.method_id = main_table.method_id');
     $cm_collection->setOrder('priority', 'ASC');
     $methods_arr = array();
     $method_ids_arr = array();
     $enabled_method_ids_arr = array();
     while ($method_obj = $cm_collection->fetchItem() and $method_arr = $method_obj->getData()) {
         if (empty($method_arr['method_id'])) {
             continue;
         }
         $method_ids_arr[] = $method_arr['method_id'];
         $methods_arr[$method_arr['method_id']] = $method_arr;
     }
     //
     // END 1. get a list of methods available for provided country
     //
     //
     // START 2. get default surcharge (s2p_gp_methods_configured.country_id = 0)
     //
     $my_collection = $this->getCollection();
     $my_collection->addFieldToSelect('*');
     $my_collection->addFieldToFilter('country_id', 0);
     $my_collection->addFieldToFilter('method_id', array('in' => $method_ids_arr));
     while ($configured_method_obj = $my_collection->fetchItem() and $configured_method_arr = $configured_method_obj->getData()) {
         if (empty($configured_method_arr['method_id'])) {
             continue;
         }
         $methods_arr[$configured_method_arr['method_id']]['surcharge'] = $configured_method_arr['surcharge'];
         $methods_arr[$configured_method_arr['method_id']]['fixed_amount'] = $configured_method_arr['fixed_amount'];
         $enabled_method_ids_arr[$configured_method_arr['method_id']] = 1;
     }
     //
     // END 2. get default surcharge (s2p_gp_methods_configured.country_id = 0)
     //
     //
     // START 3. overwrite default surcharges for particular cases (if available) (s2p_gp_methods_configured.country_id = $country_id)
     //
     $my_collection = $this->getCollection();
     $my_collection->addFieldToSelect('*');
     $my_collection->addFieldToFilter('country_id', $country_id);
     $my_collection->addFieldToFilter('method_id', array('in' => $method_ids_arr));
     while ($configured_method_obj = $my_collection->fetchItem() and $configured_method_arr = $configured_method_obj->getData()) {
         if (empty($configured_method_arr['method_id'])) {
             continue;
         }
         $methods_arr[$configured_method_arr['method_id']]['surcharge'] = $configured_method_arr['surcharge'];
         $methods_arr[$configured_method_arr['method_id']]['fixed_amount'] = $configured_method_arr['fixed_amount'];
         $enabled_method_ids_arr[$configured_method_arr['method_id']] = 1;
     }
     //
     // END 3. overwrite default surcharges for particular cases (if available) (s2p_gp_methods_configured.country_id = $country_id)
     //
     // clean methods array of methods that are not enabled
     $methods_result = array();
     foreach ($methods_arr as $method_id => $method_arr) {
         if (empty($enabled_method_ids_arr[$method_id])) {
             continue;
         }
         if (empty($params['id_in_index'])) {
             $methods_result[] = $method_arr;
         } else {
             $methods_result[$method_id] = $method_arr;
         }
     }
     return $methods_result;
 }