dvizh/yii2-shop

yii2-shop 是一个用于网站商店后端的模块

安装数: 1,189

依赖者: 2

建议者: 0

安全性: 0

星标: 32

关注者: 9

分支: 20

开放问题: 8

类型:yii2-extension

This package is not auto-updated.

Last update: 2024-09-14 19:47:53 UTC


README

该模块代表了一个网络商店的后端。

yii2-shop

包含管理(CRUD)的功能

  • 类别
  • 生产者
  • 商品
  • 价格
  • 筛选器(选项)
  • 附加字段

如果有需要,也可以拉取我的其他模块

安装

建议在 common/modules/dvizh 目录下安装

git clone https://github.com/dvizh/yii2-shop.git

并通过 composer.json 中的 psr-4 部分

"autoload": {
    "psr-4": {
        "dvizh\\shop\\": "common/modules/dvizh/yii2-shop"
    }
}

该模块依赖于许多其他包,请从我的 composer.json 中复制它们到自己的 composer.json 的 require 部分。之后,不要忘记执行 composer update 和每个模块的迁移。

如果您想通过 composer 将其安装到 vendor 目录并保持不变,请在命令行中按标准方式安装:'php composer require dvizh/yii2-shop "@dev"'

迁移

php yii migrate --migrationPath=vendor/dvizh/yii2-shop/src/migrations

配置

在配置文件(可能是 bootstrap.php)中添加

Yii::setAlias('@storageUrl','/frontend/web/images');

在配置文件的 modules 部分添加

    'modules' => [
        //..
        'shop' => [
            'class' => 'dvizh\shop\Module',
            'adminRoles' => ['administrator', 'superadmin', 'admin'],
            'defaultPriceTypeId' => 1, //Цена по умолчанию
        ],
        'filter' => [
            'class' => 'dvizh\filter\Module',
            'adminRoles' => ['administrator'],
            'relationFieldName' => 'category_id',
            'relationFieldValues' =>
                function() {
                    return \dvizh\shop\models\Category::buildTextTree();
                },
        ],
        'field' => [
            'class' => 'dvizh\field\Module',
            'relationModels' => [
                'dvizh\shop\models\Product' => 'Продукты',
                'dvizh\shop\models\Category' => 'Категории',
                'dvizh\shop\models\Producer' => 'Производители',
            ],
            'adminRoles' => ['administrator'],
        ],
        'relations' => [
            'class' => 'dvizh\relations\Module',
            'fields' => ['code'],
        ],
        'gallery' => [
            'class' => 'dvizh\gallery\Module',
            'imagesStorePath' => dirname(dirname(__DIR__)).'/storage/web/images/store',
            'imagesCachePath' => dirname(dirname(__DIR__)).'/storage/web/images/cache',
            'graphicsLibrary' => 'GD',
            'placeHolderPath' => dirname(dirname(__DIR__)).'/storage/web/images/placeHolder.png',
        ],
        //..
    ]

在 components 部分添加

    'components' => [
        //..
        'fileStorage' => [
            'class' => '\trntv\filekit\Storage',
            'baseUrl' => '@storageUrl/source',
            'filesystem'=> function() {
                $adapter = new \League\Flysystem\Adapter\Local(dirname(dirname(__DIR__)).'/frontend/web/images/source');
                return new League\Flysystem\Filesystem($adapter);
            },
        ],
        //..
    ]

使用

  • ?r=shop/product - 产品
  • ?r=shop/category - 类别
  • ?r=shop/producer - 生产者
  • ?r=filter/filter - 筛选器(选项)
  • ?r=field/field - 附加字段

小部件

  • dvizh\shop\widgets\ShowPrice - 传递 'model',输出价格。通过 jQuery 触发器与 dvizh\cart\widgets\ChangeOptions 关联,可以确定选择的修改并动态更改价格。

示例商品卡片,其中包含所有商店和购物车小部件,它们协同工作并动态更改彼此的数据。

<?php
use dvizh\shop\widgets\ShowPrice;
use dvizh\cart\widgets\BuyButton;
use dvizh\cart\widgets\TruncateButton;
use dvizh\cart\widgets\CartInformer;
use dvizh\cart\widgets\ElementsList;
use dvizh\cart\widgets\ChangeCount;
use dvizh\cart\widgets\ChangeOptions;

$product = \dvizh\shop\models\Product::findOne(1); //from controller
?>
<div class="site-index">
    <h1><?=$product->name;?></h1>
    
    <h2>Shop</h2>
    <div class="block row">
        <h3>ShowPrice</h3>
        <?=ShowPrice::widget(['model' => $product]);?>
    </div>
    
    <h2>Cart</h2>
    <div class="block row">
        <div class="col-md-3">
            <h3>ChangeCount</h3>
            <?=ChangeCount::widget(['model' => $product]);?>
        </div>
        <div class="col-md-3">
            <h3>ChangeOptions</h3>
            <?=ChangeOptions::widget(['model' => $product]);?>
        </div>
        <div class="col-md-3">
            <h3>BuyButton</h3>
            <?=BuyButton::widget(['model' => $product]);?>
        </div>
        <div class="col-md-3">
            <h3>TruncateButton</h3>
            <?=TruncateButton::widget();?>
        </div>
        <div class="col-md-3">
            <h3>CartInformer</h3>
            <?=CartInformer::widget();?>
        </div>
        <div class="col-md-3">
            <h3>ElementsList</h3>
            <?=ElementsList::widget(['type' => 'dropdown']);?>
        </div>
    </div>
    
    <style>
        .block {
            border: 2px solid blue;
        }
    </style>
    
</div>