Пример #1
0
 function byCountry($options, $supplementItem, $order, $supplement_choice, $calcul)
 {
     $defOpt = array('keyPath' => array('order.ShopOrder.shipping_country', 'settings.defaultCountry'), 'subMethod' => null, 'modifProp' => 'total', 'list' => array());
     if (!count(array_intersect_key($options, $defOpt))) {
         $options = array('list' => $options);
     }
     $opt = array_merge($defOpt, $options);
     App::import('Lib', 'Shop.ShopConfig');
     $settings = ShopConfig::load();
     $dataSource = array('settings' => $settings, 'order' => $order, 'calcul' => $calcul);
     App::import('Lib', 'Shop.SetMulti');
     $country = SetMulti::extractHierarchic($opt['keyPath'], $dataSource);
     $val = null;
     if (array_key_exists($country, $opt['list'])) {
         $val = $opt['list'][$country];
     } else {
         App::import('Lib', 'O2form.Geography');
         $continent = Geography::getContinent($country);
         if (array_key_exists($continent, $opt['list'])) {
             $val = $opt['list'][$continent];
         } elseif (array_key_exists('default', $opt['list'])) {
             $val = $opt['list']['default'];
         }
     }
     if (!is_null($val)) {
         if (!empty($opt['subMethod'])) {
             return $this->calculFunct($opt['subMethod'], $val, $supplementItem, $order, $supplement_choice, $calcul);
         }
         $supplementItem[$opt['modifProp']] = $val;
     }
     return $supplementItem;
 }