2024年3月19日(火) 17:56 JST

自分用備忘録です

オープンソースCMSのGeeklog及び
オープンソースECサイト構築システムZen CartおよびEC-CUBEの自分用備忘録です。
自分用備忘録ですので、コピペして動作できない等の苦情は勘弁して下さい。
Zen Cartについては、1.3.8a UTF-8 版をベースにしています。EC-CUBEは2.12.2をベースにしています。

ECCUBEにNPカード

記事を友だちにメール印刷用ページ
EC-CUBE

NPカード用のプラグインが用意されてないため、取りあえず一時的データベースにカード情報等を保存するためのカスタマイズをしました。
カード情報等はあれなもんで、都度手動で削除するという運用です。

配送業者別及び商品種別(mtb_product_type)に 送料無料条件設定

記事を友だちにメール印刷用ページ
EC-CUBE EC-CUBE カスタマイズ 配送業者別及び商品種別(mtb_product_type)に 送料無料条件設定

EC-CUBEではデフォルトで送料無料条件、いくら以上購入時無料という設定ができます。
送料無料条件は配送業者及び商品種別に関係なく合計金額で算出されてしまうので、
たとえば、メーカー直送商品など出荷先が違う場合は、デフォルトでは、対応できません。

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

記事を友だちにメール印刷用ページ
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;
	  }

特定商品を特定支払にする場合

記事を友だちにメール印刷用ページ
ZenCart

※この場合特定の配送方法を特定の支払方法にすることで対応
例えばゆうパックの代引きの場合
includes/modules/payment/cod.php(代金引換モジュールを複製変更)65行目以降を下記に変更

if ($this->enabled == true) { 
        if ($order->content_type != 'physical') { 
          $this->enabled = false; 
        } 
if ($_SESSION['shipping']['id'] != 'yuupack_yuupack') { 
$this->enabled = false; 
         } 
        } 
    } 

上記は配送モジュールでゆうパックの場合適用する場合

特定商品を特定配送にする場合(メーカー直送等の場合)

記事を友だちにメール印刷用ページ
ZenCart

特定商品を特定配送にする場合(メーカー直送等の場合)

includes/modules/shipping/maker.phpを作成(配送モジュールを複製変更)

makerでクラス・コードを定義57行目に下記を追加

if($restrict->fields['master_categories_id'] == '1'){ 
$this->enabled = false; 
}

上記場合はマスターカテゴリの1をメーカー直送から排除
メーカー直送を適用したくないカテゴリーidを追加していく

if($restrict->fields['master_categories_id'] == '1'){ 
$this->enabled = false; 
}
if($restrict->fields['master_categories_id'] == '2'){ 
$this->enabled = false; 
}

 

サイドボックスの追加方法

記事を友だちにメール印刷用ページ
ZenCart

サイドボックスの追加方法

モジュール
includes/modules/sideboxes/sample_sb.phpを作成(他のページを複製内容を変更)

$title =  BOX_HEADING_SAMPLE_SIDEBOX;
$title_link = "sample_page";
//(1)テンプレートを使わない場合
//$content = '<div id="samplesbContent" class="sideBoxContent">サイドボックスのサンプルです</div>';
//(2)テンプレートを使う場合
require($template->get_template_dir('tpl_sample_sb_sidebox.php',
                                    DIR_WS_TEMPLATE, 
                                    $current_page_base,
                                    'sideboxes') . 
        '/tpl_sample_sb_sidebox.php');
require($template->get_template_dir($column_box_default, 
                                    DIR_WS_TEMPLATE, 
                                    $current_page_base,
                                    'common') . 
        '/' . $column_box_default);
?>

言語パック
includes/languages/japanese/extra_definitions/sample_sb.phpを作成(他のページを複製内容を変更)

<?php
/** 
 * LIST:5-11
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 */

define('BOX_HEADING_SAMPLE_SIDEBOX', 'サンプル');
?>

テンプレート
includes/templates/template_default/sideboxes/tpl_sample_sb_sidebox.phpを作成(他のページを複製内容を変更)

<?php
/** 
 * LIST:5-13, LIST:6-2
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 */

  $content  = '';
  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">';
  $content .= 'サイドボックスのサンプルです<br />';
  if(CONFIG_SAMPLE_1 == 'true') {
    $content .= CONFIG_SAMPLE_2;
  }
  $content .= '</div>';
?>

以上で追加できる

※現在はEZ-Pagesがあるのでそこからページを増加したほうが

 

定番ページの増加作成方法

記事を友だちにメール印刷用ページ
ZenCart

定番ページの増加作成方法

includes/modules/pages/sample_page/
にheader_php.phpを作成(他のページを複製OK)定数をFILENAME_DEFINE_SAMPLE_PAGEに

言語パック
includes/languages/japanese/sample_page.phpを作成(他のページを複製内容を変更)

ページファイル名の定義
includes/extra_datafiles/sample_page.phpを作成(他のページを複製内容を変更)

ページコンテンツの作成
includes/languages/japanese/html_includes/define_sample_page.phpを作成(他のページを複製内容を変更)

テンプレート
includes/templates/template_default/templates/tpl_sample_page_default.phpを作成(他のページを複製内容を変更)

下記SQLを実行

insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) values ('Define Page 5', 'DEFINE_SAMPLE_PAGE_STATUS', '1', 'Enable the Defined sample Page text?<br />0= OFF<br />1= ON', '25', '85', now(), now(), NULL, 'zen_cfg_select_option(array(\'0\', \'1\'),'); 
UPDATE configuration SET configuration_title = '自由編集ページ(Define Page) sample page', configuration_description = '自由編集ページ(Define Page) sample pageを表示しますか?<br />\r\n・0= OFF<br />\r\n・1= ON' WHERE configuration_key = 'DEFINE_SAMPLE_PAGE_STATUS';

※現在はEZ-Pagesがあるのでそこからページを増加したほうが

 

代引手数料をゆうパックや送料無料商品で適応させる

記事を友だちにメール印刷用ページ
ZenCart

代引手数料をゆうパックや送料無料商品で適応させるには、

配送モジュール ゆうパック(yuupack)、送料無料商品(wfree)で作成した場合

/includes/order_total/ot_cod_fee.php 49行目から

if ($_SESSION['payment'] == 'cod' || $_SESSION['payment'] == 'freeshippercod' || $_SESSION['payment'] == 'wfreecod') {
          //process installed shipping modules
          if (substr_count($_SESSION['shipping']['id'], 'flat') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_FLAT);
          if (substr_count($_SESSION['shipping']['id'], 'free') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_FREE);
          if (substr_count($_SESSION['shipping']['id'], 'freeshipper') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_FREESHIPPER);
          if (substr_count($_SESSION['shipping']['id'], 'freeoptions') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_FREEOPTIONS);
          if (substr_count($_SESSION['shipping']['id'], 'item') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_ITEM);
          if (substr_count($_SESSION['shipping']['id'], 'perweightunit') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_PERWEIGHTUNIT);
          if (substr_count($_SESSION['shipping']['id'], 'table') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_TABLE);
          if (substr_count($_SESSION['shipping']['id'], 'ups') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_UPS);
          if (substr_count($_SESSION['shipping']['id'], 'usps') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_USPS);
          if (substr_count($_SESSION['shipping']['id'], 'fedex') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_FEDEX);
          if (substr_count($_SESSION['shipping']['id'], 'zones') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_ZONES);
          if (substr_count($_SESSION['shipping']['id'], 'ap') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_AP);
          if (substr_count($_SESSION['shipping']['id'], 'dp') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_DP);
	  //satt inn av Pompel
	  if (substr_count($_SESSION['shipping']['id'], 'servicepakke') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_SERVICEPAKKE);
          // 2行追加:ゆうパック代金引換 2005.11.15
	  if (substr_count($_SESSION['shipping']['id'], 'yuupack') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_YUUPACK);
          if (substr_count($_SESSION['shipping']['id'], 'wfree') !=0) $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_WFREE);

お問い合せ項目追加及び追加項目を必須に

記事を友だちにメール印刷用ページ
ZenCart

お問い合せ項目追加及び追加項目を必須にするには

includes/templates/template_default/templates/tpl_contact_us_default.php84行目付近に追加したい項目を記載(郵便番号、住所の追加例)

<label class="inputLabel" for="yuubin"><?php echo ENTRY_YUUBIN; ?></label>
<?php echo zen_draw_input_field('yuubin', ($error ? $_POST['yuubin'] : $yuubin), ' size="25" id="yuubin"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>
<br class="clearBoth" />

<label class="inputLabel" for="address"><?php echo ENTRY_ADDRESS; ?></label>
<?php echo zen_draw_input_field('address', ($error ? $_POST['address'] : $address), ' size="40" id="address"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>
<br class="clearBoth" />

includes/languages/japanese/contact_us.php追加した項目を記載並びに必須エラー時の文言を記載する
define('ENTRY_YUUBIN', '郵便番号:');
define('ENTRY_ADDRESS', 'ご住所:');

define('ENTRY_EMAIL_YUUBIN_CHECK_ERROR','郵便番号の入力がされていないようです。');
define('ENTRY_EMAIL_OFFICEADDRESS_CHECK_ERROR','ご住所の入力がされていないようです。');

 

includes/languages/japanese/email_extras.phpメール受信時の言語ファイルに下記を追加

define('OFFICE_YUUBIN','<strong>郵便番号:</strong>'); 
define('OFFICE_ADDRESS','<strong>住所:</strong>');

includes/modules/pages/contact_us/header_php.phpに必死項目設定及びメール受信項目設定する28行目に

else if ($zc_validate_email and !empty($enquiry) and !empty($name) and !empty($yuubin) and !empty($address)) {

59行目から

// Prepare Text-only portion of message
    $text_message = OFFICE_FROM . "\t" . $name . "\n" .
    OFFICE_EMAIL . "\t" . $email_address . "\n" . OFFICE_YUUBIN . "\t" . $yuubin . "\n". 
	OFFICE_ADDRESS . "\t" . $address . "\n" . 
    '------------------------------------------------------' . "\n\n" .
    strip_tags($_POST['enquiry']) .  "\n\n" .
    '------------------------------------------------------' . "\n\n" .
    $extra_info['TEXT'];
    // Prepare HTML-portion of message
    $html_msg['EMAIL_MESSAGE_HTML'] = strip_tags($_POST['enquiry']);
    $html_msg['CONTACT_US_OFFICE_FROM'] = OFFICE_FROM . ' ' . $name . '<br />' . OFFICE_EMAIL . '(' . $email_address . ')';
    $html_msg['EXTRA_INFO'] = $extra_info['HTML'];
    // Send message

73行目(エラー時メッセージ)

    zen_redirect(zen_href_link(FILENAME_CONTACT_US, 'action=success'));
  } else {
    $error = true;
    if (empty($name)) {
      $messageStack->add('contact', ENTRY_EMAIL_NAME_CHECK_ERROR);
    }
    if ($zc_validate_email == false) {
      $messageStack->add('contact', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
    }
	if (empty($yuubin)) {
      $messageStack->add('contact', ENTRY_EMAIL_YUUBIN_CHECK_ERROR);
    }
	if (empty($address)) {
      $messageStack->add('contact', ENTRY_EMAIL_OFFICEADDRESS_CHECK_ERROR);
    }
    if (empty($enquiry)) {
      $messageStack->add('contact', ENTRY_EMAIL_CONTENT_CHECK_ERROR);
    }
  }
} // end action==send

以上