andrewdanilov / yii2-shop
Yii2 Shop
Requires
- php: >=5.6.0
- ext-json: *
- 2amigos/yii2-date-picker-widget: ~1.0
- andrewdanilov/yii2-behaviors: ~1.0.25
- andrewdanilov/yii2-ckeditor: ~1.0.1
- andrewdanilov/yii2-fancybox: ~1.0.0
- andrewdanilov/yii2-grid-tools: ~1.0.2
- andrewdanilov/yii2-helpers: ~1.0.16
- andrewdanilov/yii2-input-images: ~1.0.2
- kartik-v/yii2-widget-select2: @dev
- yiisoft/yii2: ~2.0.0
- yiisoft/yii2-bootstrap: ^2.0
- dev-main
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.43
- 1.0.42
- 1.0.41
- 1.0.40
- 1.0.39
- 1.0.38
- 1.0.37
- 1.0.36
- 1.0.35
- 1.0.34
- 1.0.33
- 1.0.32
- 1.0.31
- 1.0.30
- 1.0.29
- 1.0.28
- 1.0.27
- 1.0.26
- 1.0.25
- 1.0.24
- 1.0.23
- 1.0.22
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
This package is auto-updated.
Last update: 2024-09-25 16:56:23 UTC
README
可定制的商店模块,具有层次分类、产品属性和选项、购物车、产品标签。支持国际化。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一
composer require andrewdanilov/yii2-shop "~1.1.0"
或
"andrewdanilov/yii2-shop": "~1.1.0"
将以下内容添加到您的 composer.json
文件的 require
部分。
然后运行数据库迁移,创建所需的表
php yii migrate --migrationPath=@andrewdanilov/shop/console/migrations
更新扩展后,也请运行迁移。
用法
在后台主配置文件 modules
部分,添加以下内容
$config = [ // ... 'modules' => [ // ... 'shop' => [ 'class' => 'andrewdanilov\shop\backend\Module', // access role for module controllers, optional, default is ['@'] 'access' => ['admin'], // path to user translates, optional, default is '@andrewdanilov/shop/common/messages' 'translatesPath' => '@common/messages/shop', // file manager configuration, optional, default is: 'fileManager' => [ 'basePath' => '@frontend/web', 'paths' => [ [ 'name' => 'Product images', 'path' => 'upload/images/product', ], [ 'name' => 'Category images', 'path' => 'upload/images/category', ], [ 'name' => 'Brand images', 'path' => 'upload/images/brand', ], [ 'name' => 'Sticker images', 'path' => 'upload/images/sticker', ], [ 'name' => 'Documents', 'path' => 'upload/images/docs', ], ], ], ], ], ];
在这里,access
选项允许限制对定义角色的访问。
在前端主配置文件 modules
部分和 bootstrap
部分,添加 shop
模块
$config = [ // ... 'modules' => [ // ... 'shop' => [ 'class' => 'andrewdanilov\shop\frontend\Module', // path to template views, optional, default is '@andrewdanilov/shop/frontend/views' 'templatesPath' => '@frontend/views/shop', // path to mail template views, optional, default is '@andrewdanilov/shop/common/mail' 'mailTemplatesPath' => '@common/mail/shop', // path to user translates, optional, default is '@andrewdanilov/shop/common/messages' 'translatesPath' => '@common/messages/shop', // main currency, using by shop, optional, default is 'USD' 'currency' => '$', ], ], // If you use own templates paths, you need to add `shop` module to `bootstrap` section // to enable i18n and other settings before using module parts. // This is optional, but recommended in any way. 'bootstrap' => [ // ... 'shop', ], ];
在 common/config/params.php
配置文件中添加/修改 adminEmail
、senderEmail
和 senderName
参数,如下所示
return [ // ... 'adminEmail' => ['admin@example.com', 'admin2@example.com'], 'senderEmail' => 'noreply@example.com', 'senderName' => 'Robot', // ... ];
您将收到系统消息(例如,网站订单)来自 senderEmail
电子邮件的 adminEmail
电子邮件之一。
要传输电子邮件消息,您必须在 common/config/main-local.php
中正确设置 mailer
组件。例如 SMTP 传输
return [ 'components' => [ // ... 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'useFileTransport' => false, 'transport' => [ 'class' => 'Swift_SmtpTransport', 'username' => 'sender@example.com', 'password' => 'example_password', 'host' => 'smtp.example.com', 'port' => '465', 'encryption' => 'ssl', ], ], ], ];
后台菜单项
$shop_menu_items = [ ['label' => 'Orders', 'url' => ['/shop/order'], 'icon' => 'shopping-cart'], ['label' => 'Products', 'url' => ['/shop/product'], 'icon' => 'shopping-bag'], ['label' => 'Brands', 'url' => ['/shop/brand'], 'icon' => 'leaf'], ['label' => 'Options', 'url' => ['/shop/option'], 'icon' => 'check-square'], ['label' => 'Properties', 'url' => ['/shop/property'], 'icon' => 'list'], ['label' => 'Property groups', 'url' => ['/shop/group'], 'icon' => 'tags'], ['label' => 'Linking', 'url' => ['/shop/relation'], 'icon' => 'share-alt'], ['label' => 'Pay methods', 'url' => ['/shop/pay'], 'icon' => 'credit-card'], ['label' => 'Shipping methods', 'url' => ['/shop/delivery'], 'icon' => 'truck'], ['label' => 'Stickers', 'url' => ['/shop/sticker'], 'icon' => 'bookmark'], ]; echo \yii\widgets\Menu::widget(['items' => $shop_menu_items]);
小部件
您可以使用这些小部件将购物车、迷你购物车、模态窗口和购买按钮添加到您的商店
// Place this widget everywhere you want to see buy button echo \andrewdanilov\shop\frontend\widgets\Buttons\Buy::widget([ 'product_id' => 123, // optional, text label displaying on buy button 'label' => 'Buy it!', // optional, html tag uset for representing buy button 'tag' => 'div', // optional, extended classes for buy button 'classes' => 'orange-buy-button', // optional, use to define own template for buy button 'template' => '@frontend/views/shop/buy-button', ]); // Place these two widgets on checkout page. // First is for displaying form to retrieve client information like e-mail, phone, etc. // Second is for displaying cart contents table. \andrewdanilov\shop\frontend\widgets\Checkout\Client::widget(); \andrewdanilov\shop\frontend\widgets\Checkout\FullCart::widget(); // Widget for mini-cart button. Place it somewhere in main layout. \andrewdanilov\shop\frontend\widgets\Checkout\MiniCart::widget(); // Widget for placing modal windows on page \andrewdanilov\shop\frontend\widgets\Forms\Modals::widget();
如果您需要在小部件内部使用自己的内容,您可以复制小部件目录到您希望的位置,然后从那里调用它们。如果这样做,请记住相应地更改命名空间。
功能
I18n
扩展支持国际化。您可以在 common/config/main.php
中设置您的语言。
return [ // ... 'language' => 'ru-RU', // ... ];
目前您可以使用以下语言之一:英语、俄语。此外,您可以通过定义商店模块的 translatesPath
属性来创建和使用自己的翻译(见上文)。因此,您需要将语言文件放置在 translatesPath
路径内的 xx-XX
文件夹中。您可以从扩展的 src/common/messages
路径中复制示例。