black-lamp / blcms-cart

Blcms-shop模块的购物车组件

安装: 422

依赖: 2

建议者: 0

安全: 0

星星: 0

关注者: 7

分支: 1

公开问题: 0

类型:yii2-extension

v0.1.7 2017-03-17 10:11 UTC

README

Blcms-shop模块的购物车模块和组件

安装

安装此扩展的首选方式是通过 composer

运行以下命令

php composer.phar require --prefer-dist black-lamp/blcms-cart "*"

或者将以下内容添加到您的 composer.json 文件的 require 部分中

"black-lamp/blcms-cart": "*"

如果您需要将订单保存到数据库,应用以下迁移

迁移

  • php yii migrate --migrationPath=@vendor/black-lamp/blcms-staticpage/migrations
  • php yii migrate --migrationPath=@vendor/black-lamp/blcms-cart/migrations

通用配置

'name' => 'ProjectName',
'components' => [
    'cart' => [
                'class' => bl\cms\cart\CartComponent::className(),
                'emailNotifications' => true,
                'sender' => 'info@mail.com',
                'sendTo' => [
                    'test@mail.com'
                ],
                'saveToDataBase' => true,
                
                'enablePayment' => true, //If true, you need to add blcms-payment module to your composer.json file.
            ],
],

前端配置

'modules' => [
    'cart' => [
                'class' => bl\cms\cart\frontend\Module::className(),
            ],
    'user' => [
                'class' => 'dektrium\user\Module',
                'modelMap' => [
                    'User' => 'bl\cms\shop\common\components\user\models\User',
                    'Profile' => 'bl\cms\cart\common\components\user\models\Profile',
                ],
                'controllerMap' => [
                    'registration' => 'bl\cms\cart\common\components\user\controllers\RegistrationController',
                    'settings' => 'bl\cms\cart\frontend\components\user\controllers\SettingsController',
                ],
                'as frontend' => 'dektrium\user\filters\FrontendFilter',
            ],
'components' => [
    //For Dektrium User module
    'mailer' => [
                'class' => yii\swiftmailer\Mailer::className(),
                'useFileTransport' => false,
                'messageConfig' => [
                    'charset' => 'UTF-8',
                ],
                'transport' => [
                    'class' => 'Swift_SmtpTransport',
                    'username' => 'info@mail.com',
                    'password' => '123456789',
                    'host' => 'mail.server.com',
                    'port' => '587',
                ],
            ],
    //For cart
   'shopMailer' => [
        'class' => yii\swiftmailer\Mailer::className(),
        'useFileTransport' => false,
        'messageConfig' => [
            'charset' => 'UTF-8',
        ],
        'viewPath' => '@vendor/black-lamp/blcms-cart/frontend/views/mail',
        'htmlLayout' => '@vendor/black-lamp/blcms-cart/frontend/views/mail/layout',
        'transport' => [
                'class' => 'Swift_SmtpTransport',
                'username' => 'info@host.ua',
                'password' => 'password',
                'host' => 'pop.host.ua',
                'port' => '587',
            ],
    ],
]

后端配置

'modules' => [
        'cart' => [
            'class' => bl\cms\cart\backend\Module::className(),
        ],
        'user' => [
                    'class' => 'dektrium\user\Module',
                    'enableRegistration' => false,
                    'enableConfirmation' => false,
                    'admins' => ['admin'],
                    'adminPermission' => 'rbacManager',
                    'modelMap' => [
                        'Profile' => 'bl\cms\cart\common\components\user\models\Profile',
                    ],
                    'as backend' => [
                        'class' => 'dektrium\user\filters\BackendFilter',
                        'only' => ['register'], // Block View Register Backend
                    ],
                ],
        
        'seo' => [
            'class' => 'bl\cms\seo\backend\Module'
        ],
    ],

参数 'adminEmail' => 'info@mail.ua',

使用

添加到购物车

Yii::$app->cart->add($productId, $count, $priceId);

获取总成本

$totalCost = Yii::$app->cart->getTotalCost();

获取所有用户订单 ''' $orders = Yii::$app->cart->getAllUserOrders(); '''

清空购物车

Yii::$app->cart->clearCart();

静态页面

静态页面模块中有页面用于在前端显示购物车。它有键 'cart'。您需要配置它:添加标题、SEO数据等。http://YOUR_DOMAIN.com/admin/seo/static

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

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

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

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

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

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

'enableLog' => true,

### 邮件模板 配置前端组件

components => [
    'emailTemplates' => [
        'class' => bl\emailTemplates\components\TemplateManager::class
    ],
]

应用迁移后,将有两个邮件记录 - 'new-order' 和 'order-success'。您可以在管理面板中找到它:/admin/email-templates/default/list 在邮件主题和对象中,您可以使用以下变量:{name},{surname},{patronymic},{email},{phone},{orderUid},{zip},{country},{region},{city},{street},{house},{apartment},{products},{totalCost}。变量 {products} 渲染视图 @bl\cms\cart\frontend\views\mail\products 您可以在前端配置中为 shopMailer 组件设置邮件布局。现在它使用 @bl\cms\cart\frontend\views\mail\layout

欢迎邮件 您可以在这里创建模板:/admin/email-templates/default/list(使用 'welcome' 键)使用以下变量:{token} => 确认令牌

恢复邮件 创建 'recovery' 模板。使用以下变量:{token} => 确认令牌