msdev2/shopify

设置基本的 Shopify 应用程序,如安装等

dev-main 2024-06-29 06:54 UTC

This package is auto-updated.

Last update: 2024-09-29 07:16:25 UTC


README

设置基本的 Shopify 应用程序,如安装等

composer require msdev2/shopify

php artisan vendor:publish --provider="Msdev2\Shopify\ShopifyServiceProvider"

  • 更新菜单项
  • 更新计划
  • 更新账单

添加到 config/app

'providers' => [
    /*
     * Package Service Providers...
     */
    Msdev2\Shopify\ShopifyServiceProvider::class,
]

安装商店

[domain]/install -- for ui
<a htef="{{ route('msdev2.install') }}">Install</a> -- for link of ui
https://[domain]/authenticate?shop=[shopify_domain] -- instent redirect

更新 Shopify 应用程序回调 URL

[shop]/auth/callback

更新 ENV 变量

SHOPIFY_API_KEY=63f2fa001d************
SHOPIFY_API_SECRET=47f72686a3************
SHOPIFY_APP_ID=548698745823
SHOPIFY_API_SCOPES=read_products,write_products
SHOPIFY_BILLING=true #false
SHOPIFY_FOOTER=<div>copyright @copy; all right reserved</div>
SHOPIFY_IS_EMBEDDED_APP=true #false //true if you want to open an app inside shopify else false
SHOPIFY_APPBRIDGE_ENABLED=true #true
SHOPIFY_ENABLE_ALPINEJS=true #true if you want to use vue make it false
SHOPIFY_ENABLE_TURBOLINKS=true #true if you want to use vue make it false
SHOPIFY_TEST_STORES=mraganksoni,msdev203
TAWK_URL=https://https://embed.tawk.to/64cbaca1cc26a871b02d0bcf/1h6tpkmh2
SHOPIFY_API_VERSION=2023-04

设置钩子

update env
SHOPIFY_WEBHOOKS=APP_UNINSTALLED,THEMES_PUBLISH,SHOP_UPDATE
create hook receiver file
app/Webhook/Handlers/AppUninstalled.php
app/Webhook/Handlers/ShopUpdate.php
app/Webhook/Handlers/ThemesPublish.php

中间件列表

msdev2.shopify.verify  //to verify shop exist in url
msdev2.shopify.auth //to authenticate shopify user
msdev2.shopify.installed //to check if shopify is installed

为 blade 设置布局

CSS 引用是 https://www.uptowncss.com/

@extends('msdev2::layout.master')
@section('content')
<div class="mt-20">
    //your code here
</div>
@endsection
@section('scripts')
    @parent
    <script type="text/javascript">
        actions.TitleBar.create(app, { title: 'Welcome' });
    </script>
@endsection

辅助函数

路由辅助函数

\Msdev2\Shopify\Utils::Route('home',['app'=>'home']) or mRoute('home',['app'=>'home])
\Msdev2\Shopify\Utils::Route('home') or mRoute('home')
\Msdev2\Shopify\Utils::Route('home.name') or mRoute('home.name')
\Msdev2\Shopify\Utils::Route('/pagename') or mRoute('/pagename')

其他常用辅助函数

\Msdev2\Shopify\Utils::$shop;
\Msdev2\Shopify\Utils::getShop(?$shopname) or mShop(?$shopname)
\Msdev2\Shopify\Utils::getShopName() or mShopName()
\Msdev2\Shopify\Utils::rest(?$shop) or mRest(?$shop)
\Msdev2\Shopify\Utils::graph(?$shop) or mGraph(?$shop)
\Msdev2\Shopify\Utils::makeUrltoLinkFromString($string) or mUrltoLinkFromString($string)
\Msdev2\Shopify\Utils::successResponse(?$message,?$array,?$code) or mSuccessResponse(?$message,?$array,?$code)
\Msdev2\Shopify\Utils::errorResponse(?$message,?$array,?$code) or mErrorResponse(?$message,?$array,?$code)
mLog($message, ?$array, ?$logLevel, ?$channel)

用于 vuejs 路由辅助

window.$GLOBALS.push(path)
window.$GLOBALS.push(path, params)
window.$GLOBALS.push(name)
window.$GLOBALS.push(name, params)
window.$GLOBALS.shop
window.$GLOBALS.host
window.$GLOBALS.csrfToken
window.$GLOBALS.processRequest(url, data, isImageRequest) # url = 'POST /url'  data = {} isImageRequest=false
window.$GLOBALS.showToast(msg,isError,subscribeFun,clearFun) # msg = string isError=false subscribeFun=callback function clearFun=callback function
showToast(msg,isError,subscribeFun,clearFun) # msg = string isError=false subscribeFun=callback function clearFun=callback function

将表格保存到 metafield

class ModelName extend \Msdev2\Shopify\Models\Model
{
    /** set true to save this data into metafield*/
    public $metaField = true;
    
}

使用 Shopify 日志

$shop->log('message',[],'type','channel') 
$shop->log('log added successfully',['test'=>'info'],'alert','shopify')

无 SSL 加载

\vendor\shopify\shopify-api\src\Clients\HttpClientFactory.php    
return new Client(['verify' => false]);