faisal/shopify-inject

此包旨在通过 Shopify 管理API将内容注入到 Shopify liquid 文件中。为我的项目开发和包装而创建。如果它有帮助,让我们把它做得更好。

dev-master 2021-11-12 19:09 UTC

This package is auto-updated.

Last update: 2021-11-12 19:09:35 UTC


README

# 注入代码到 Shopify 商店前端

## 此包旨在通过 Shopify 管理API将内容注入到 Shopify liquid 文件中。

此包基于 "osiset/laravel-shopify": "^17.1" 包。因此,您必须先安装和配置此包才能使其工作。以下是 Osiset/laravel-shopify 包的详细信息。https://github.com/osiset/laravel-shopify。请完全安装和配置它,然后使用我的包。

它需要一个实现 Osiset 的 IShopModel 的用户。这可以是任何已注册域的用户。如果您对此有任何疑问,请参阅 osiset 文档。

$injectService = new Shopify\Inject\InjectService(\App\Models\User::first());

//shopify storefront liquid files file path.
$filePath = 'layout/theme.liquid';

//content to be searched. My package will search this string in the given file and update the file with provided content.
$mainContent = '{{ content_for_layout }}';

// provided content to be added before or after the search content
$contentToAdd = "<script> console.log('script added by inject app by editing theme.liquid file'); </script>";

//calling the function for updating the asset. if it will update it it will return true otherwise false.
if($injectService->updateContentToAsset($filePath,$mainContent,$contentToAdd)){
    return "Content Updated Successfully.";
}else{
    return "Content Already Exists";
}