Skip to content

Instantly share code, notes, and snippets.

@cscartjp
Last active August 29, 2015 14:19
Show Gist options
  • Save cscartjp/0f4588e1667a21bbeb00 to your computer and use it in GitHub Desktop.
Save cscartjp/0f4588e1667a21bbeb00 to your computer and use it in GitHub Desktop.
CS-Cart Advanced Add-on Tutorial
<?php
/***************************************************************************
* *
* (c) 2004 Vladimir V. Kalynyak, Alexey V. Vinokurov, Ilya M. Shalnev *
* *
* This is commercial software, only users who have purchased a valid *
* license and accept to the terms of the License Agreement can install *
* and use this program. *
* *
****************************************************************************
* PLEASE READ THE FULL TEXT OF THE SOFTWARE LICENSE AGREEMENT IN THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE. *
****************************************************************************/
if (!defined('BOOTSTRAP')) { die('Access denied'); }
/*
PHPコード・フックの関数名は命名規則に従って書いて下さい:
fn_ + [addon id] +_+ [hook name]
命名規則が正しくない関数は無視されます。
*/
function fn_advanced_addon_get_category_data_pre($category_id, $field_list, $get_main_pair, $skip_company_condition, $lang_code)
{
//ログイン中のユーザーIDをセッションから取得する
$auth = $_SESSION['auth'];
//ログイン中のユーザーがストアフロントにいるかどうかの判定
if (!empty($auth['user_id']) && AREA == 'C') {
//データベースにユーザーのデータが存在するかチェック
//必要に応じてアクセスデータを作成
$viewed_categories = db_get_field('SELECT categories FROM ?:advanced_addon_data WHERE user_id = ?i', $auth['user_id']);
if (!empty($viewed_categories)) {
$viewed_categories = unserialize($viewed_categories);
}
$viewed_categories[$category_id] = true;
$viewed_categories = serialize($viewed_categories);
//データベースに書き込む
db_query('REPLACE INTO ?:advanced_addon_data VALUES (?i, ?s)', $auth['user_id'], $viewed_categories);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment