[Shopify]shopify公式カスタムフィールド

設定 > メタフィールド



 

商品



 

定義を追加する



 

全ての項目へ入力する



 

入力後保存する



 

保存後



 

Liquidコード

<a href="{{ product.url | within: collection }}">
    <div class="image"><img src="{{ product.featured_image.src | img_url: 'large' }}" alt="{{ product.featured_image.alt | escape }}"></div>
    <h3>{{ product.title | escape }}</h3>
    {%- if product.metafields.my_fields.cf_text -%}
        <p>{{ product.metafields.my_fields.cf_text.value | escape }}</p>
    {%- else -%}
        <p>あいうえお</p>
    {%- endif -%}
</a>

 

商品管理画面でカスタムフィールドへ入力



 

出力結果

[Liquid]税込税抜切替

tax-text.liquid

{%- if shop.taxes_included -%}(税込){%- else -%}(税抜){%- endif -%}

管理画面「設定 > 税金」の「すべての価格を税込価格で表示する」チェックならばshop.taxes_includedはtrue

[Laravel]AES_ENCRYPT

$result = DB::table('users')->insert([
                ['email' => \DB::raw("AES_ENCRYPT('{$xxx}',SHA2('".env('DB_ENCRYPT_KEY')."',512))"), 'token' => \DB::raw("AES_ENCRYPT('{$yyy}',SHA2('".env('DB_ENCRYPT_KEY')."',512))")]
            ]);

[Liquid]会員登録、ログイン

{%- if shop.customer_accounts_enabled -%}
    {%- if customer -%}
    <a href="{{ routes.account_url }}">会員情報</a>
    <a href="{{ routes.account_logout_url }}">ログアウト</a>
    {%- else -%}
    <a href="{{ routes.account_register_url }}">会員登録</a>
    <a href="{{ routes.account_login_url }}">ログイン</a>
    {%- endif -%}
{%- endif -%}

[Laravel]AES_DECRYPT

$record = DB::table('xxx')
            ->selectRaw("id,AES_DECRYPT(`yyy`,SHA2(:key1,512)) AS shop,AES_DECRYPT(`zzz`,SHA2(:key2,512)) AS token",['key1'=>env('DB_ENCRYPT_KEY'),'key2'=>env('DB_ENCRYPT_KEY')])
            ->whereRaw("AES_DECRYPT(`yyy`,SHA2(:key,512)) = :yyy", ['key'=>env('DB_ENCRYPT_KEY'),'yyy'=>$yyy])
            ->first();

[Liquid]商品ハンドルから商品オブジェクト取得

all_productsは最大20件の商品情報しか保持しないため、コレクションを使用する必要がある。
予め全商品を含みコレクションハンドル「created-descending」のコレクションを作成しておく
function_get_product_by_handle.liquid

{%- assign get_product_by_handle = nil -%}
{%- paginate collections['created-descending'].products by collections['created-descending'].all_products_count -%}
    {%- for model_product in collections['created-descending'].products -%}
        {%- if model_product.handle == target_handle -%}
            {%- assign product = model_product -%}
            {%- break -%}
        {%- endif -%}
    {%- endfor -%}
{%- endpaginate -%}

[PHP]idiorm #6 select_expr + AES_DECRYPT

define('DB_ENCRYPT_KEY','aabbccddeeff');
require_once __DIR__ . '/idiorm.php';
ORM::configure('mysql:host=localhost;dbname=xxxx');
ORM::configure('username', 'yyy');
ORM::configure('password', 'zzz');
ORM::configure('driver_options', [
    PDO::MYSQL_ATTR_INIT_COMMAND       => 'SET NAMES utf8',
]);
$email = "xxxx@gmail.com";

ORM::configure('logging', true);
try{
    $orm = ORM::for_table('users')->select("id")->select_expr("AES_DECRYPT(`email`,'".DB_ENCRYPT_KEY."')","email")->select_expr("AES_DECRYPT(`name`,'".DB_ENCRYPT_KEY."')","name");
    $orm->where_raw("AES_DECRYPT(`email`,?) = ?",array(DB_ENCRYPT_KEY,$email));
    $record = $orm->find_one();
}catch (PDOException $e){
    return null;
}
echo "<pre>";
var_dump(ORM::get_last_query());
echo "</pre>";
if(!empty($record)) {
    echo "<pre>";
    echo $record->id;
    echo $record->email;
    echo $record->name;
    echo "</pre>";
}

[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' );