albert-sointula/yii2-shop

此包已废弃,不再维护。未建议替代包。
此包的最新版本(v0.2.3)没有可用的许可证信息。

Yii2框架的电子商务模块

安装: 313

依赖项: 0

建议者: 0

安全: 0

星标: 21

关注者: 6

分支: 11

类型:yii2-extension

v0.2.3 2018-03-01 10:34 UTC

This package is auto-updated.

Last update: 2024-01-23 06:07:54 UTC


README

Yii2框架的强大电子商务模块。

安装

1. 在项目中添加扩展

运行命令

composer require albert-sointula/yii2-shop

或在您的 composer.json 文件的 require 部分中添加

"albert-sointula/yii2-shop": "*"

2. 您应该在公共配置文件中配置 "authManager" 组件

    'authManager' => [
            'class' => 'yii\rbac\DbManager',
        ],

3. 在后端配置文件中设置 "Yii2-multi-lang" 组件

'components' => [

    'urlManager' => [
                'class' => bl\multilang\MultiLangUrlManager::className(),
                'baseUrl' => '/admin',
                'enablePrettyUrl' => true,
                'showScriptName' => false,
                'rules' => [
                ],
            ],
            'urlManagerFrontend' => [
                'class' => bl\multilang\MultiLangUrlManager::className(),
                'baseUrl' => '/',
                'showScriptName' => false,
                'enablePrettyUrl' => true,
                'enableDefaultLanguageUrlCode' => false,
                'rules' => [
                    [
                        'class' => bl\articles\UrlRule::className()
                    ],
                    [
                        'class' => xalberteinsteinx\shop\UrlRule::className(),
                        'prefix' => 'shop'
                    ],
                ]
            ],
]

4. 在前端配置文件中设置 "Yii2-locale" 扩展

'components' => [
    'urlManager' => [
                'class' => bl\locale\UrlManager::className(),
                'baseUrl' => '/',
                'showScriptName' => false,
                'detectInSession' => false,
                'detectInCookie' => false,
                'enablePrettyUrl' => true,
                'languageProvider' => [
                    'class' => bl\locale\provider\DbLanguageProvider::className(),
                    'db' => 'db',
                    'table' => 'language',
                    'localeField' => 'lang_id',
                    'languageCondition' => ['active' => true],
                ],
                'lowerCase' => true,
                'useShortSyntax' => false,
                'languageKey' => 'language',
                'showDefault' => false,
                'rules' => [
                    
                    [
                        'class' => albertgeeca\shop\UrlRule::className(),
                        'prefix' => 'shop'
                    ],
                    [
                        'class' => bl\seo\UniqueUrlRule::class,
                        'destination' => 'cart',
                        'duplicate' => [
                            'cart/cart/show',
                            'cart/cart'
                        ]
                    ],
                ]
            ],
]

5. 在前端配置中设置 Dektrium-user 模块

在后台配置中

 'modules' => [
    ...
    
    'user' => [
                'modelMap' => [
                    'RegistrationForm' => albertgeeca\shop\common\components\user\models\RegistrationForm::className(),
                    'RecoveryForm' => albertgeeca\shop\common\components\user\models\RecoveryForm::className(),
                    'LoginForm' => albertgeeca\shop\common\components\user\models\LoginForm::className(),
                    'SettingsForm' => albertgeeca\shop\common\components\user\models\SettingsForm::className(),
                ],
                'controllerMap' => [
                    'registration' => albertgeeca\shop\frontend\components\user\controllers\RegistrationController::className(),
                    'settings' => albertgeeca\shop\frontend\components\user\controllers\SettingsController::className(),
                    'security' => albertgeeca\shop\frontend\components\user\controllers\SecurityController::className(),
                    'recovery' => albertgeeca\shop\frontend\components\user\controllers\RecoveryController::className()
                ],
                'as frontend' => dektrium\user\filters\FrontendFilter::className(),
                'enableFlashMessages' => false
            ],
    
    ...
 
 ],
 
 'components' => [
 
    ...
    'user' => [
                'identityClass' => albertgeeca\shop\common\components\user\models\User::className(),
                'enableAutoLogin' => true,
                'identityCookie' => [
                    'name'     => '_frontendIdentity',
                    'path'     => '/',
                    'httpOnly' => true,
                ],
                'on afterLogin' => function() {
                    if (Yii::$app->cart->saveToDataBase) Yii::$app->cart->transportSessionDataToDB();
                },
                'on afterConfirm' => function() {
                    if (Yii::$app->cart->saveToDataBase) Yii::$app->cart->transportSessionDataToDB();
                },
            ],
    ...
    ],

在公共配置文件中

'modules' => [

    ...
    'user' => [
                'enableRegistration' => false,
                'enableConfirmation' => false,
                'admins' => ['admin'],
                'adminPermission' => 'rbacManager',
                'controllerMap' => [
                    'admin' => albertgeeca\shop\backend\components\user\controllers\AdminController::className(),
                    'security' => albertgeeca\shop\frontend\components\user\controllers\SecurityController::className()
                ],
                'as backend' => [
                    'class' => 'dektrium\user\filters\BackendFilter',
                    'only' => ['register'], // Block View Register Backend
                ],
            ],
    ...
],

'components' => [

    ...
    'user' => [
                'identityClass' => dektrium\user\models\User::className(),
                'enableAutoLogin' => true,
                'returnUrl' => '/',
                'identityCookie' => [
                    'name'     => '_backendIdentity',
                    'path'     => '/admin',
                    'httpOnly' => true,
                ],
            ],
    ...
    
    'view' => [
                'theme' => [
                    'basePath' => '@backend/themes/' . $params['themeName'],
                    'baseUrl' => '@web/themes/' . $params['themeName'],
                    'pathMap' => [
                        '@dektrium/user/views' => '@vendor/sointula/yii2-shop/backend/views/user',
                    ],
                ],
            ],
],

在后台配置中

'modules' => [

        'user' => [
            'class' => dektrium\user\Module::className(),
            'modelMap' => [
                'Profile' => albertgeeca\shop\common\components\user\models\Profile::className(),
                'User' => albertgeeca\shop\common\components\user\models\User::className()
            ],
        ],

6. 应用迁移

- php yii migrate --migrationPath=@vendor/dektrium/yii2-user/migrations
- php yii migrate --migrationPath=@yii/rbac/migrations
- php yii migrate --migrationPath=@vendor/black-lamp/yii2-multi-lang/migration
- php yii migrate --migrationPath=@vendor/black-lamp/yii2-seo/migrations
- php yii migrate --migrationPath=@vendor/black-lamp/blcms-staticpage/migrations
- php yii migrate --migrationPath=@vendor/black-lamp/yii2-email-templates/src/migrations
- php yii migrate --migrationPath=@vendor/albert-sointula/yii2-shop/migrations

7. 在公共配置文件中添加 Imagable 模块的配置

        'shop_imagable' => [
            'class' => bl\imagable\Imagable::className(),
            'imageClass' => \bl\imagable\instances\CreateImageImagine::className(),
            'nameClass' => bl\imagable\name\CRC32Name::className(),
            'imagesPath' => '@frontend/web/images',
            'categories' => [
                'origin' => false,
                'category' => [
                    'shop-product' => [
                        'origin' => false,
                        'size' => [
                            'big' => [
                                'width' => 1500,
                                'height' => 500
                            ],
                            'thumb' => [
                                'width' => 500,
                                'height' => 500,
                            ],
                            'small' => [
                                'width' => 150,
                                'height' => 150
                            ]
                        ]
                    ],
                    'shop-vendors' => [
                        'origin' => false,
                        'size' => [
                            'big' => [
                                'width' => 1500,
                                'height' => 500
                            ],
                            'thumb' => [
                                'width' => 320,
                                'height' => 240,
                            ],
                            'small' => [
                                'width' => 150,
                                'height' => 150
                            ]
                        ]
                    ],
                    'delivery' => [
                        'origin' => false,
                        'size' => [
                            'big' => [
                                'width' => 1500,
                                'height' => 500
                            ],
                            'thumb' => [
                                'width' => 500,
                                'height' => 500,
                            ],
                            'small' => [
                                'width' => 150,
                                'height' => 150
                            ]
                        ]
                    ],
                    'shop-category/cover' => [
                        'origin' => false,
                        'size' => [
                            'big' => [
                                'width' => 1500,
                                'height' => 500
                            ],
                            'thumb' => [
                                'width' => 500,
                                'height' => 500,
                            ],
                            'small' => [
                                'width' => 150,
                                'height' => 150
                            ]
                        ]
                    ],
                    'shop-category/thumbnail' => [
                        'origin' => false,
                        'size' => [
                            'big' => [
                                'width' => 1500,
                                'height' => 500
                            ],
                            'thumb' => [
                                'width' => 500,
                                'height' => 500,
                            ],
                            'small' => [
                                'width' => 150,
                                'height' => 150
                            ]
                        ]
                    ],
                    'shop-category/menu_item' => [
                        'origin' => false,
                        'size' => [
                            'big' => [
                                'width' => 1500,
                                'height' => 500
                            ],
                            'thumb' => [
                                'width' => 500,
                                'height' => 500,
                            ],
                            'small' => [
                                'width' => 150,
                                'height' => 150
                            ]
                        ]
                    ],
                    'payment' => [
                        'origin' => false,
                        'size' => [
                            'big' => [
                                'width' => 1500,
                                'height' => 500
                            ],
                            'thumb' => [
                                'width' => 500,
                                'height' => 500,
                            ],
                            'small' => [
                                'width' => 150,
                                'height' => 150
                            ]
                        ]
                    ],
                ]
            ]
        ],

8. 将模块添加到您的后台配置

    'bootstrap' => [
        //'albertgeeca\shop\backend\components\events\PartnersBootstrap',
        'albertgeeca\shop\backend\components\events\ShopLogBootstrap',
        'albertgeeca\shop\backend\components\events\CartBootstrap',
    ],
    'modules' => [
        'shop' => [
            'class' => 'albertgeeca\shop\backend\Module',
            'enableCurrencyConversion' => true
        ]
    ]

9. 将模块添加到您的前端配置

    'modules' => [
    	...
        'shop' => [
                    'class' => albertgeeca\shop\frontend\Module::className(),
                    'enableCurrencyConversion' => true,
                    'partnerManagerEmail' => $params['partnerManagerEmail'],
                    'senderEmail' => $params['senderEmail'],
                    'showChildCategoriesProducts' => false
                ],
        ...
    ],
    
    'components' => [
        ...
        
        'partnerMailer' => [
                    'class' => yii\swiftmailer\Mailer::className(),
                    'useFileTransport' => false,
                    'messageConfig' => [
                        'charset' => 'UTF-8',
                    ],
                    'viewPath' => '@vendor/albert-sointula/yii2-shop/frontend/views/partner-request/mail',
                    'htmlLayout' => '@vendor/albert-sointula/yii2-shop/frontend/views/partner-request/mail/layout',
                    'transport' => [
                        'class' => 'Swift_SmtpTransport',
                        'username' => 'info@mail.com',
                        'password' => '55555555',
                        'host' => 'pop.mail.com',
                        'port' => '587',
                    ],
                ],
        ...
    ]

    'bootstrap' => [
        'albertgeeca\shop\frontend\components\events\PartnersBootstrap',
        'albertgeeca\shop\frontend\components\events\UserRegistrationBootstrap'
    ],

10. 在前端配置文件中设置 "Yii2-email-templates" 模块

https://github.com/black-lamp/yii2-email-templates

11. 设置静态页面模块

将 StaticPageManager 角色添加到您的 auth_assignment 表中的管理员用户。创建具有页面键 "shop" 和 "cart" 的新静态页面。在您的后台配置文件中添加以下内容

        'seo' => [
                    'class' => 'bl\cms\seo\backend\Module'
                ],
],

REQUIRES

  • PHP版本:7.0 或更高
  • PHP扩展:file-info, imagick, intl

角色及其权限:

attributeManager

  • addAttributeValue
  • deleteAttribute
  • saveAttribute
  • viewAttributeList

countryManager

  • saveCountry
  • viewCountryList
  • deleteCountry

currencyManager

  • updateCurrency
  • viewCurrencyList
  • deleteCurrency

deliveryMethodManager

  • saveDeliveryMethod
  • viewDeliveryMethodList
  • deleteDeliveryMethod

orderManager

  • deleteOrder
  • deleteOrderProduct
  • viewOrder
  • viewOrderList

orderStatusManager

  • saveOrderStatus
  • viewOrderStatusList
  • deleteOrderStatus

productAvailabilityManager

  • saveProductAvailability
  • 查看产品可用性列表
  • 删除产品可用性

产品管理器

  • 创建产品
  • 无需审核创建产品
  • 删除自己的产品
  • 删除产品
  • 更新自己的产品
  • 更新产品
  • 查看完整产品列表
  • 查看产品列表

产品合作伙伴

  • 访问管理面板
  • 创建产品
  • 无需审核创建产品
  • 删除自己的产品
  • 删除产品
  • 更新自己的产品
  • 更新产品
  • 查看完整产品列表
  • 查看产品列表

商店类别管理器

  • 保存商店类别
  • 查看商店类别列表

供应商管理器

  • 保存供应商
  • 查看供应商列表
  • 删除供应商

支付管理器

  • 查看支付方式列表
  • 保存支付方式
  • 删除支付方式

商店管理员 从所有管理器扩展权限。

小工具

推荐产品

示例

<?= \albertgeeca\shop\widgets\RecommendedProducts::widget([
    'id' => $product->id,
]); ?>

您还可以在视图中使用 albertgeeca\shop\widgets\assets\RecommendedProductsAsset。

过滤小工具

要使用小工具,您必须在模型中设置关系。例如在模型 Product 中

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getProductCountry()
    {
        return $this->hasOne(ProductCountry::className(), ['id' => 'country_id']);
    }

日志记录

您的应用程序可以记录有多少人观看特定产品。要启用日志记录,您必须在前端配置文件中添加以下设置

public $log = [
        'enabled' => true,
        'maxProducts' => 10 // Max number of viewed products by one user.
    ];

在其中,您指定产品的数量,该数量存储在 shop_product_views 表中,用于一个用户。此值可以是 'all',即无限。

如果 'maxProducts' 属性值为 "all",则 Product 对象的 "views" 对注册用户增加一次。否则,每次注册用户查看产品时都会增加一次。

翻译

该模块支持多种语言的翻译。如果没有您的语言或您想自行更改它,您可以在后端或前端配置文件中进行配置

'i18n' => [
            'translations' => [
                'shop' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@backend/messages',
                    'sourceLanguage' => 'en-us',
                ]
            ],
        ],

管理页面

  • 商店主静态页面 /admin/seo/static/save-page?page_key=shop&languageId=2
  • 类别 /admin/shop/category/index
  • 产品 /admin/shop/product/index
  • 国家 /admin/shop/country/index
  • 供应商 /admin/shop/vendor/index
  • 属性 /admin/shop/attribute/index
  • 可用性状态 /admin/shop/product-availability/index
  • 货币 /admin/shop/currency/index

报告

  • "未找到类 'Imagick'"

如果您使用 OpenServer 与 PHP 7,您必须像这里一样安装 Imagick 扩展 http://open-server.ru/forum/viewtopic.php?f=4&t=2897&hilit=imagick

产品显示

您可以选择两种模式之一:显示当前类别及其子类别的产品或仅显示当前类别。在前端模块类配置中使用属性 $showChildCategoriesProducts。迁移

日志记录 此配置适用于商店模块和购物车模块。

要启用日志记录,将日志组件添加到您的通用配置文件中

'components' => [
        'log' => [
            'targets' => [
                [
                    'logTable' => 'shop_log',
                    'class' => 'yii\log\DbTarget',
                    'levels' => ['info'],
                    'categories' => [
                        'afterCreateProduct', 'afterDeleteProduct', 'afterEditProduct',
                        'afterCreateCategory', 'afterEditCategory', 'afterDeleteCategory',
                    ],
                ],
                [
                    'logTable' => 'cart_log',
                    'class' => 'yii\log\DbTarget',
                    'levels' => ['info'],
                    'categories' => [
                        'afterChangeOrderStatus'
                    ],
                ],
                [
                    'logTable' => 'user_log',
                    'class' => 'yii\log\DbTarget',
                    'levels' => ['info'],
                    'categories' => [
                        'afterRegister', 'afterConfirm'
                    ],
                ],
            ],
        ],

然后应用迁移,但只有在您配置了应用程序之后。迁移将创建配置中列出的日志目标的表。

php yii migrate --migrationPath=@yii/log/migrations/

在您的模块的后端和前端配置中添加

'enableLog' => true,

供应商列表

  • /shop/vendor

合作伙伴请求电子邮件 创建新的模板 'partner-request-manager' 和 'partner-request-partner':/admin/email-templates/default/list

您可以使用以下变量:'{contact_person}','{company_name}','{website}','{message}','{name}','{surname}','{patronymic}','{info}'

还可以创建不带变量的模板 'partner-request-accept'。

产品合作伙伴向经理发送新产品信息 - 模板 'new-product-to-manager'。您可以使用以下变量:{productId},{title},{ownerId},{ownerEmail},{owner},{link}。要向创建该产品的合作伙伴发送有关新产品的信息,请添加模板 'new-product-to-partner',并带有变量 {productId},{title},{ownerId},{ownerEmail},{owner},{link}。

如果产品经过审核且状态为'接受',则将发送邮件'accept-product-to-owner'。您可以使用以下变量:{title},{ownerEmail},{owner},{link}

链接

Dektrium-User模块: https://github.com/dektrium/yii2-user