[Liquid]在庫チェック

function_get_variant_status.liquid

{%- comment -%}在庫チェック{%- endcomment -%}
{%- assign is_in_stock = false -%}
{%- if 0 < variant.inventory_quantity -%}
{%- assign is_in_stock = true -%}
{%- endif -%}

{%- comment -%}在庫あり カートに入れる{%- endcomment -%}
{%- if is_in_stock -%}
    {%- assign get_variant_status = 1 -%}

{%- comment -%}在庫なし 「在庫切れの場合でも販売を続ける」がチェックされている カートに入れる{%- endcomment -%}
{%- elsif is_in_stock == false and variant.inventory_policy == 'continue' -%}
    {%- assign get_variant_status = 2 -%}

{%- comment -%}在庫なし 再入荷待ち{%- endcomment -%}
{%- elsif is_in_stock == false and variant.incoming -%}
    {%- assign get_variant_status = 3 -%}

{%- comment -%}在庫なし 完売しました{%- endcomment -%}
{%- elsif is_in_stock == false -%}
    {%- assign get_variant_status = 4 -%}

{%- comment -%}不明{%- endcomment -%}
{%- else -%}
    {%- assign get_variant_status = 99 -%}

{%- endif -%}

[WordPress]アップロード画像の複数サイズ自動生成停止

下記実行

update wp_options set option_value='0' where option_name = 'thumbnail_size_w';
update wp_options set option_value='0' where option_name = 'thumbnail_size_h';
update wp_options set option_value='0' where option_name = 'medium_size_w';
update wp_options set option_value='0' where option_name = 'medium_size_h';
update wp_options set option_value='0' where option_name = 'large_size_w';
update wp_options set option_value='0' where option_name = 'large_size_h';
update wp_options set option_value='0' where option_name = 'medium_large_size_w';
update wp_options set option_value='0' where option_name = 'medium_large_size_h';

 
functions.phpに下記追加

function disable_image_sizes( $new_sizes ) {
    unset( $new_sizes['1536x1536'] );
    unset( $new_sizes['2048x2048'] );
    unset( $new_sizes['post-thumbnail'] );
    unset( $new_sizes['category-thumb'] );
    unset( $new_sizes['homepage-thumb'] );
    return $new_sizes;
}
add_filter( 'intermediate_image_sizes_advanced', 'disable_image_sizes' );

add_filter( 'big_image_size_threshold', '__return_false' );

[Liquid]デフォルトファイル一覧

本記事の情報は古いです。Shopify公式ドキュメントをご確認ください。

必須 ファイル名 備考
customers/account.liquid 会員情報ページ
姓名、メールアドレス、住所、注文履歴、住所編集ページへのリンクを表示する
customers/activate_account.liquid アカウントを有効にするページ
顧客情報インポート後、顧客へ招待メールを送信した際、顧客がメールのリンクをクリックして来るページ
パスワード、パスワード(確認)を入力するフォームがあり、「アカウントを有効にする」「招待を断る」ボタンを配置する。
customers/addresses.liquid 住所一覧・編集ページ
住所は複数登録出来る。
customers/login.liquid ログインページ
「パスワードをお忘れですか?」のフォームも含む
customers/order.liquid 注文詳細ページ
商品、配送、価格、数量、合計を表示する
customers/register.liquid 会員登録ページ
姓、名、メールアドレス、パスワードを入力する
customers/reset_password.liquid パスワードリセットページ
「パスワードをお忘れですか?」のフォームに入力されたメールアドレスへこのページへのリンクが記載されている
新パスワード、新パスワード(確認)を入力する
404.liquid 404ページ
article.liquid ブログ記事ページ
blog.liquid ブログ記事一覧ページ
cart.liquid カートページ
連絡事項欄を作成可能。
attributesで任意の入力欄を作成出来る。
collection.liquid コレクションページ
collection.favorites.liquidのように複数のバージョンを作成し、コレクション作成時にどのバージョンを適用させるか選択出来る
collection.list.liquid コレクション内商品一覧ページ
gift_card.liquid ギフトカードページ
index.liquid TOPページ
list-collections.liquid コレクション一覧ページ
page.contact.liquid お問い合わせページ
項目は任意に作成できる。サーバサイドのバリデーションは特定の項目のみなのでhtml,jsでバリデーションを実装すべし。確認画面は無い。
page.liquid 固定ページ
page.v2.jpのように複数のバージョンを作成し、固定ページ作成時にどのバージョンを適用させるか選択出来る
product.liquid 商品詳細ページ
search.liquid 検索結果ページ
フリーワードやタグで検索出来る。並び替え機能は無い。並び替えはliquid上で作れるが商品数が多い場合処理が重くなるのでやめたほうがいい。

[Liquid]/searchの仕様

公式説明ページ

 

/search?type=product

検索対象:商品

 

/search?type=article

検索対象:記事

 

/search?q=あいうえお

タイトルや説明に「あいうえお」が含まれるもの

 

/search?q=tag:apple

タグに「apple」が含まれるもの

 

/search?q=あいうえお tag:apple

タイトルや説明に「あいうえお」が含まれる かつ タグに「apple」が含まれるもの

 

/search?q=tag:apple tag:carrot

タグに「apple」「carrot」が両方含まれるもの

 

/search?q=tag:apple OR tag:carrot

タグに「apple」又は「carrot」が含まれるもの

 

/search?q=tag:apple (tag:carrot OR tag:radish)

タグに「apple」が含まれる かつ タグ「carrot」「radish」どちらか一方又は両方含まれるもの

 

/search?q=-tag:apple

タグに「apple」を含まないもの

 

/search?q=

検索結果に何も出ない。よって、この時のみ特別な処理(全商品表示)をする必要がある。

 

[Liquid]GETクエリの値を取得

参考:https://community.shopify.com/c/Shopify-Design/URL-Parameters-in-LIQUID/td-p/149761/page/2

function_get_query_value_by_key.liquid

{%- capture contentForQuerystring -%}{{ content_for_header }}{%- endcapture -%}
{%- assign pageUrl = contentForQuerystring | split:'"pageurl":"' | last | split:'"' | first | replace:'\/','/' | replace:'%20',' ' | replace:'\u0026','&' -%}
{%- assign get_query_value_by_key = '' -%}
{%- if pageUrl contains "?" -%}
    {%- assign pageQuerystring = pageUrl | split:'?' | last | replace:'=','&' -%}
    {%- assign tmp = pageQuerystring | split:'&' -%}
    {%- for kv in tmp -%}
        {%- if kv == key -%}
            {%- assign get_query_value_by_key = tmp[forloop.index] -%}
            {%- break -%}
        {%- endif -%}
    {%- endfor -%}
{%- endif -%}

使用時 typeの値を取得する

{%- include "function_get_query_value_by_key" key:"type" -%}
get_query_value_by_key:{{get_query_value_by_key}}

※renderを使用すると親テンプレートへ値を渡せないためincludeを使用

[WordPress]get_post_by_post_name

public function get_post_by_post_name($post_name, $post_type = '', $post_status = 'publish')
{
    global $wpdb;
    $sql = array();
    $sql[] = "SELECT p.*";
    $sql[] = "FROM $wpdb->posts AS p";
    $sql[] = "WHERE p.post_name " . $this->__get_sql_for_in($post_name);
    if (!empty($post_type))
        $sql[] = "AND p.post_type = '$post_type'";
    if(!empty($post_status))
        $sql[] = "AND p.post_status = '$post_status'";
    $result = $wpdb->get_results(implode(' ', $sql));
    if (empty($result))
        return null;
    return is_array($post_name) ? $result : $result[0];
}
protected function __get_sql_for_in($values, $is_number = false)
{
    $quote    = $is_number ? "" : "'";
    $is_array = is_array($values);
    $not      = ($is_array && is_string($values[0]) && preg_match('/^.*\!=.+$/',$values[0])) || (!$is_array && is_string($values) && preg_match('/^.*\!=.+$/',$values));
    $in       = $not ? ' NOT IN' : ' IN';
    $eq       = $not ? '!=' : '=';
    if($is_array){
        foreach ($values as $i => $value) {
            $values[$i] = preg_replace('/^(\!=|=)/', '', esc_sql($value));
            $values[$i] = preg_replace('/^ /', '', esc_sql($value));
        }
    }else{
        $values = preg_replace('/^(\!=|=)/','',esc_sql($values));
        $values = preg_replace('/^ /','',esc_sql($values));
    }
    return $is_array && 1 < count($values) ? "{$in} ({$quote}" . implode("{$quote},{$quote}", $values) . "{$quote})" : ($is_array ? "{$eq} {$quote}{$values[0]}{$quote}" : "{$eq} {$quote}$values{$quote}");
}

[GAS]セルの値をコピー

function copy_values() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var get_range;
  var set_range;
  for(var i = 4 ; i < 30 ; i+=2){
    get_range = sheet.getRange("J"+i+":K"+i);
    set_range = sheet.getRange("J"+(i+1)+":K"+(i+1));
    set_range.setValues(get_range.getValues());
  }
}

[PHP]get_url_by_regex

public function get_url_by_regex($url = null,$replaces = null,$suffix = null)
{
    $tmp = explode('?',empty($url) ? $_SERVER['REQUEST_URI'] : $url);
    $url = 0<count($tmp) ? array_shift($tmp) : '';
    $tmp = 0<count($tmp) ? array_pop($tmp) : '';
    $tmp = explode('&',$tmp);
    for($i=0;$i<count($replaces);$i+=2){
        foreach ($tmp as $j => $q){
            $tmp[$j] = preg_replace($replaces[$i],$replaces[$i+1],$q);
        }
    }
    $tmp = array_diff($tmp,array(''));
    $is_empty = empty($tmp);
    return $url.($is_empty?'':'?'.implode('&',$tmp)) . (is_null($suffix)?'':($is_empty?'?':'&').preg_replace('/^[\?&]/','',$suffix));
}

[SSH]SSHトンネル@WinSCP

SFTP
xxx.xxx.xxx.xxx
22
ID:xxxxxx
PW:yyyyyy
・設定
-トンネル
チェック:SSHトンネルを経由して接続する
nnn.nnn.nnn.nnn 50001
ID:mmmmmm
PW:pppppp
ローカルトンネルポート 自動選択
秘密鍵 id_rsa.ppk
-SSH 認証
チェック エージェントの転送を許可する
秘密鍵 filename.ppk