lyrasoft/shopgo

Luna ShopGo 包

安装: 711

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 2

开放问题: 27

类型:luna-package

0.1.20 2023-12-11 09:47 UTC

README

安装

通过 composer 安装

composer require lyrasoft/shopgo

ShopGo 依赖于 lyrasoft/sequencelyrasoft/favorite 包。请先阅读它们的 README 并进行配置。

然后复制文件到项目中

php windwalker pkg:install lyrasoft/shopgo -t routes -t migrations -t seeders
php windwalker pkg:install lyrasoft/favorite -t routes -t migrations

种子文件

将这些文件添加到 resources/seeders/main.php

return [
    // ...
    
    __DIR__ . '/payment-seeder.php',
    __DIR__ . '/shipping-seeder.php',
    __DIR__ . '/manufacturer-seeder.php',
    __DIR__ . '/product-feature-seeder.php',
    __DIR__ . '/product-attribute-seeder.php',
    __DIR__ . '/product-tab-seeder.php',
    __DIR__ . '/product-seeder.php',
    __DIR__ . '/discount-seeder.php',
    __DIR__ . '/address-seeder.php',
    __DIR__ . '/additional-purchase-seeder.php',
    __DIR__ . '/order-seeder.php',
];

将这些类型添加到 category-seeder.php

    static function () use ($seeder, $orm, $db) {
        $types = [
            // ...
            
            'product' => [
                'max_level' => 2,
                'number' => 30,
            ],
            'attribute' => [
                'max_level' => 1,
                'number' => 10,
            ],
        ];

全局设置

打开 /etc/packages/shopgo.php,你可以在那里配置设置

<?php
// ...

return [
    'shopgo' => [
        // ...

        'currency' => [
            'main' => 'USD' // Can be ID or code
        ],

        'fixtures' => [
            // The migration/seeder faker locale
            'locale' => 'en_US',
        ],

        'address' => [
            // Use fullname or firstname/lastname
            'use_fullname' => false,
            'use_fulladdress' => false,
        ],

        'order_no' => [
            // Order No mode, cab be:
            // INCREMENT_ID: S0000000123
            // DAILY_SEQUENCE: S20230105000123
            // SEQUENCE_HASHES: SfY5Sv8fhJ
            // RANDOM_HASHES: Skf8q2FgHJ38kl (longer)
            'mode' => OrderNoMode::INCREMENT_ID(),
            'prefix' => 'S',
            'hash_offsets' => 100000, // Add offset to hash seed to make no un-guessable
            'sequence_day_format' => 'Ymd',
            // Base62
            // If you want to update this, run:
            // `php -r "echo str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');"`
            'hash_seed' => 'E7G5FHBK9NTifV8tZban2ASvQLeRyYwMWqdhDXs61OuPg0Iploc3kUj4rCJmxz'
        ],

        'payment_no' => [
            // This is the max length of payment No.
            // For intance, Ecpay's limit is 20
            'maxlength' => 20,
        ],

        'invoice_no' => [
            'prefix' => 'INV'
        ],
    ]
];

配置完基本设置后,发布网站后不应再更改。然后你可以运行 migtaiotns/seeders,所有订单编号和 faker 本地化将使用此设置。

php windwalker mig:reset -fs

环境

你可以添加 SHOPGO_MPDF_FONT_DIR 来配置发票 PDF 字体位置。

在开发中,提供 Mac 默认字体目录

SHOPGO_MPDF_FONT_DIR=/Library/Fonts/

你可以在部署到服务器后更改此目录。

会话

由于 ShopGo 可能需要重定向到外部支付服务来处理结账,你必须禁用 SameSite cookie 政策并将 secure 设置为 TRUE

// etc/packages/session.php

return [
    'session' => [
        // ...

        'cookie_params' => [
            // ...
            'secure' => true, // <-- Set this to TRUE
            // ...
            'samesite' => CookiesInterface::SAMESITE_NONE, // Set this to `SAMESITE_NONE`
        ],

收藏夹类型

ShopGo 将自动安装 lyrasoft/favorite 并复制配置文件。你必须将 product 添加到 allow_types 中以允许 AJAX 调用。

return [
    'favorite' => [
        // ...

        'ajax' => [
            'type_protect' => true,
            'allow_types' => [
                'article',
                'product' // <-- Add this
            ]
        ],
    ]
];

语言文件

如果你不想覆盖语言,请将此行添加到管理 & 前端中间件中

$this->lang->loadAllFromVendor('lyrasoft/shopgo', 'ini');
$this->lang->loadAllFromVendor('lyrasoft/favorite', 'ini');

或者运行此命令来复制语言文件

php windwalker pkg:install lyrasoft/shopgo -t lang
php windwalker pkg:install lyrasoft/favorite -t lang

CSS/JS

ShopGo 依赖于 lyrasoft/favorite,你必须将这些供应商添加到 fusionfile.mjs

export async function install() {
    return installVendors(
        [
            // ...

            // Add these below
            'sweetalert',
            'swiper',
        ],
        [
            // Add these 2 lines
            'lyrasoft/shopgo',
            'lyrasoft/favorite',
        ]
    );
}

然后运行此命令来安装 npm 供应商

yarn add swiper sweetalert

ShopGo 脚本将自动在目标页面中注册。但如果你想,你可以在 FrontMiddleware 中全局注册它。

class FrontMiddleware extends AbstractLifecycleMiddleware
{
    // ...

    public function __construct(
        // ...
        protected ShopGoScript $shopGoScript,
    ) {
    }

    protected function preprocess(ServerRequestInterface $request): void
    {
        // ...

        $this->shopGoScript->sweetAlert();
        $this->shopGoScript->productCart();

如果你想使所有 JS 警告都显示为 SweetAlert 样式,你可以在 main.js 中替换 u.alert

// main.js

// ...

u.alert = swal;

添加购物车按钮

当前 ShopGo 测试版没有购物车按钮小部件。你必须手动将其添加到 HTML 中。

你必须包含这两个属性才能使 JS 工作

  • [data-role=cart-button]
  • [data-role=cart-quantity]
<?php
$cartStorage = $app->service(\Lyrasoft\ShopGo\Cart\CartStorage::class);
$cartQuantity = $cartStorage->count();
?>
<div class="c-cart-button"
    data-role="cart-button">
    <div class="c-cart-button__quantity">
        <i class="fa fa-cart-shopping"></i>
        
        <span class="badge bg-danger"
            data-role="cart-quantity">
            {{ $cartQuantity }}
        </span>
    </div>
</div>

注册管理员菜单

编辑 resources/menu/admin/sidemenu.menu.php

$menu->link('商城管理', '#')
    ->icon('fal fa-shop');

$menu->registerChildren(
    function (MenuBuilder $menu) use ($nav, $lang) {
        $menu->link($lang('shopgo.product.category.title'))
            ->to($nav->to('category_list', ['type' => 'product']))
            ->icon('fal fa-sitemap');

        $menu->link($lang('unicorn.title.grid', title: $lang('shopgo.product.title')))
            ->to($nav->to('product_list'))
            ->icon('fal fa-box-open');

        $menu->link($lang('unicorn.title.grid', title: $lang('shopgo.additional.purchase.title')))
            ->to($nav->to('additional_purchase_list'))
            ->icon('fal fa-cart-plus');

        $menu->link($lang('unicorn.title.grid', title: $lang('shopgo.product.feature.title')))
            ->to($nav->to('product_feature_list'))
            ->icon('fal fa-object-ungroup');

        $menu->link($lang('unicorn.title.grid', title: $lang('shopgo.product.attribute.group.title')))
            ->to($nav->to('product_attribute_group_list'))
            ->icon('fal fa-object-group');

        $menu->link($lang('unicorn.title.grid', title: $lang('shopgo.product.attribute.title')))
            ->to($nav->to('product_attribute_list'))
            ->icon('fal fa-rectangle-list');

        $menu->link($lang('unicorn.title.grid', title: $lang('shopgo.product.tab.title')))
            ->to($nav->to('product_tab_list'))
            ->icon('fal fa-pager');

        $menu->link($lang('unicorn.title.grid', title: $lang('shopgo.manufacturer.title')))
            ->to($nav->to('manufacturer_list'))
            ->icon('fal fa-building');
    }
);

$menu->link('優惠', '#')
    ->icon('fal fa-cart-arrow-down');

$menu->registerChildren(
    function (MenuBuilder $menu) use ($nav, $lang) {
        $menu->link($lang('unicorn.title.grid', title: $lang('shopgo.discount.title')))
            ->to($nav->to('discount_list'))
            ->icon('fal fa-percent');
    }
);

$menu->link('訂單', '#')
    ->icon('fal fa-file-invoice-dollar');

$menu->registerChildren(
    function (MenuBuilder $menu) use ($nav, $lang) {
        $menu->link($lang('unicorn.title.grid', title: $lang('shopgo.order.title')))
            ->to($nav->to('order_list'))
            ->icon('fal fa-file-invoice-dollar');

        $menu->link($lang('unicorn.title.grid', title: $lang('luna.order_state.title')))
            ->to($nav->to('order_state_list'))
            ->icon('fal fa-list');
    }
);

$menu->link('商城設定', '#')
    ->icon('fal fa-cogs');

$menu->registerChildren(
    function (MenuBuilder $menu) use ($nav, $lang) {
        $menu->link($lang('unicorn.title.grid', title: $lang('shopgo.currency.title')))
            ->to($nav->to('currency_list'))
            ->icon('fal fa-sterling-sign');

        $menu->link($lang('unicorn.title.grid', title: $lang('luna.location.title')))
            ->to($nav->to('location_list'))
            ->icon('fa-solid fa-marker')
            ->icon('fal fa-earth-asia');

        $menu->link($lang('unicorn.title.grid', title: $lang('luna.payment.title')))
            ->to($nav->to('payment_list'))
            ->icon('fa-solid fa-dollar')
            ->icon('fal fa-cash-register');

        $menu->link($lang('unicorn.title.grid', title: $lang('luna.shipping.title')))
            ->to($nav->to('shipping_list'))
            ->icon('fal fa-truck');

        $menu->link($lang('luna.config.title', $lang('shopgo.config.type.shop')))
            ->to($nav->to('config_shopgo_shop'))
            ->icon('fal fa-gear');
    }
);

前端可用的路由

  • product_list
  • product_item
  • my_wishlist
  • my_order_list
  • my_order_item