2024年11月21日(木) 15:58 JST

支払モジュールでどの配送モジュールを適用させるかリストから選択させる場合

ZenCart

includes/modules/payment/***.php   58行目付近

// disable the module if the order only contains virtual products
      if ($this->enabled == true) {
        if ($order->content_type != 'physical') {
          $this->enabled = false;
        }
      }
// 下記を追記
      if (MODULE_PAYMENT_***_PAYTO == '' && $this->enabled == true) {
      	$this->enabled = false;
      }
      if ($this->enabled == true) {
        $this->enabled = false;
        $shipping_modules = explode(', ', MODULE_PAYMENT_***_PAYTO);

        list($session_shipping) = explode('_', $_SESSION['shipping']['id']);
       // if (array_search($session_shipping, $shipping_modules)) $this->enabled = true;
        if (is_int(array_search($session_shipping, $shipping_modules))) $this->enabled = true;
      }
      //手数料の表示
      if ($this->enabled == true && (int)MODULE_PAYMENT_***_COST > 0 && MODULE_ORDER_TOTAL_***_STATUS != 'true') {
  		$this->enabled = false;
  	}
     }


  function install() {
    global $db;
    $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('配送モジュール:', 'MODULE_PAYMENT_***_PAYTO', '', '***を有効にする配送モジュールを選んで下さい。', '6', '1', 'zen_cfg_select_payment(', now());");

   function keys() {
    return array('MODULE_PAYMENT_***_PAYTO'追記);
  }
//管理画面に配送モジュールを表示させるため下記を追記
	function cc_string_format ($type ,$str) {
		if (strlen($str) < 1) return false;
		$str = @preg_replace('/("|,)/' ,'' ,$str);
		$moji_count = 0;
		$moji_code = 'utf-8';
		switch ($type) {
			case 'company':
				$moji_count = 30;
				break;
			case 'name':
				$moji_count = 15;
				break;
			case 'name_kana':
				$moji_count = 25;
				$str = mb_convert_kana($str, "KVC" ,$moji_code);
				break;
			case 'postcode':
				$moji_count = 7;
				$str = mb_convert_kana($str, "a" ,$moji_code);
				$str = @preg_replace('/[^0-9]/' ,'' ,$str);
				break;
			case 'address':
				$str = mb_convert_kana($str, "n" ,$moji_code);
				$str = str_replace('ー', "-" ,$str);
				$moji_count = 100;
				break;
			case 'telephone':
				$str = mb_convert_kana($str, "a" ,$moji_code);
				$str = preg_replace('/[^0-9]/' ,'' ,$str);
				if (@preg_match('/^0(5|7|9)0/' ,$str)) {
					$moji_count = 11;
				} else {
					$moji_count = 10;
				}
				break;
			case 'email_address':
				$moji_count = 100;
				break;	
			case 'product_name':
				$moji_count = 150;
				break;
		
			default:
				break;
		}
		$str = mb_substr($str ,0 ,$moji_count ,$moji_code);
		return $str;
	}
  }

  if (!function_exists('zen_cfg_select_payment')) {
	  function zen_cfg_select_payment($key_value, $key = '') {
	  	$key_value = explode(", " ,$key_value);
	    $string = '';
	    $file_extension = '.php';
		$module_directory = DIR_FS_CATALOG_MODULES . 'shipping/';
	  $directory_array = array();
	  if ($dir = @dir($module_directory)) {
	    while ($file = $dir->read()) {
	      if (!is_dir($module_directory . $file)) {
	        if (substr($file, strrpos($file, '.')) == $file_extension) {
	          $directory_array[] = $file;
	        }
	      }
	    }
	    sort($directory_array);
	    $dir->close();
	  }

		for ($i=0, $n=sizeof($directory_array); $i<$n; $i++) {
		    $file = $directory_array[$i];
		    include_once(DIR_FS_CATALOG_LANGUAGES . $_SESSION['language'] . '/modules/shipping/' . $file);
		    include_once($module_directory . $file);
		    $class = substr($file, 0, strrpos($file, '.'));
		    if (zen_class_exists($class)) {
		      $module = new $class;
		      if ($module->check() > 0) {
		        if ($module->sort_order > 0) {
		          if ($installed_modules[$module->sort_order] != '') {
		            $zc_valid = false;
		          }
		          $installed_modules[$module->sort_order] = $file;
		        } else {
		          $installed_modules[] = $file;
		        }
		      }
		    }
		    	    $name = ((zen_not_null($key)) ? 'configuration[' . $key . '][]' : 'configuration_value');
			    $string .= '<br><input type="checkbox" name="' . zen_output_string($name) . '"';
			    if (zen_not_null($module->code)) $string .= ' value="' . zen_output_string($module->code) . '"';
			    if (is_int(array_search($module->code,$key_value))) $string .= ' CHECKED';

				$string .= '>' .zen_output_string($module->title);
		}
	    return $string;
	  }