Yii2-shop
ΠΠΎΠ΄ΡΠ»Ρ ΠΏΡΠ΅Π΄ΡΡΠ°Π²Π»ΡΠ΅Ρ ΠΈΠ· ΡΠ΅Π±Ρ Π±Π΅ΠΊΠ΅Π½Π΄ Π΄Π»Ρ ΠΠ½ΡΠ΅ΡΠ½Π΅Ρ-ΠΌΠ°Π³Π°Π·ΠΈΠ½Π°., (*1)
, (*2)
Π ΡΠΎΡΡΠ°Π² Π²Ρ
ΠΎΠ΄ΠΈΡ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡΡ ΡΠΏΡΠ°Π²Π»ΡΡΡ (CRUD):, (*3)
- ΠΠ°ΡΠ΅Π³ΠΎΡΠΈΡΠΌΠΈ
- ΠΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»ΡΠΌΠΈ
- Π’ΠΎΠ²Π°ΡΠ°ΠΌΠΈ
- Π¦Π΅Π½Π°ΠΌΠΈ
- Π€ΠΈΠ»ΡΡΡΠ°ΠΌΠΈ (ΠΎΠΏΡΠΈΡΠΌΠΈ)
- ΠΠΎΠΏΠΎΠ»Π½ΠΈΡΠ΅Π»ΡΠ½ΡΠΌΠΈ ΠΏΠΎΠ»ΡΠΌΠΈ
ΠΡΠ»ΠΈ Π΅ΡΡΡ Π½Π΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠΎΡΡΡ, ΠΌΠΎΠΆΠ½ΠΎ ΡΠ°ΠΊΠΆΠ΅ ΠΏΠΎΠ΄ΡΡΠ½ΡΡΡ ΠΌΠΎΠΈ Π΄ΡΡΠ³ΠΈΠ΅ ΠΌΠΎΠ΄ΡΠ»ΠΈ:, (*4)
Π£ΡΡΠ°Π½ΠΎΠ²ΠΊΠ°
Π Π΅ΠΊΠΎΠΌΠ΅Π½Π΄ΡΡ ΡΡΡΠ°Π½Π°Π²Π»ΠΈΠ²Π°ΡΡ Π² common/modules/dvizh:, (*5)
git clone https://github.com/dvizh/yii2-shop.git
Π ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°ΡΡ ΡΠ΅ΡΠ΅Π· psr-4 ΡΠ΅ΠΊΡΠΈΡ composer.json:, (*6)
"autoload": {
"psr-4": {
"dvizh\\shop\\": "common/modules/dvizh/yii2-shop"
}
}
ΠΠΎΠ΄ΡΠ»Ρ Π·Π°Π²ΠΈΡΠΈΡ ΠΎΡ ΠΌΠ½ΠΎΠ³ΠΈΡ
Π΄ΡΡΠ³ΠΈΡ
ΠΏΠ°ΠΊΠ΅ΡΠΎΠ², ΡΠΊΠΎΠΏΠΈΡΡΠΉΡΠ΅ ΠΈΡ
ΠΈΠ· ΠΌΠΎΠ΅Π³ΠΎ Π² ΡΠ²ΠΎΠΉ composer.json Π² ΡΠ΅ΠΊΡΠΈΡ require. ΠΠΎΡΠ»Π΅ ΡΡΠΎΠ³ΠΎ Π½Π΅ Π·Π°Π±ΡΠ΄ΡΡΠ΅ Π²ΡΠΏΠΎΠ»Π½ΠΈΡΡ composer update ΠΈ ΠΌΠΈΠ³ΡΠ°ΡΠΈΠΈ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ ΠΌΠΎΠ΄ΡΠ»Ρ., (*7)
ΠΡΠ»ΠΈ Ρ
ΠΎΡΠΈΡΠ΅ ΡΡΡΠ°Π½ΠΎΠ²ΠΈΡΡ Π² ΠΏΠ°ΠΏΠΊΡ vendor ΡΠ΅ΡΠ΅Π· composer ΠΈ Π½ΠΈΡΠ΅Π³ΠΎ Π½Π΅ ΠΌΠ΅Π½ΡΡΡ ΠΏΠΎΡΠΎΠΌ, ΡΡΡΠ°Π½Π°Π²Π»ΠΈΠ²Π°ΠΉΡΠ΅ ΡΡΠ°Π½Π΄Π°ΡΡΠ½ΠΎ: 'php composer require dvizh/yii2-shop "@dev"' Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ ΡΡΡΠΎΠΊΠ΅., (*8)
ΠΠΈΠ³ΡΠ°ΡΠΈΡ:, (*9)
php yii migrate --migrationPath=vendor/dvizh/yii2-shop/src/migrations
ΠΠ°ΡΡΡΠΎΠΉΠΊΠ°
Π ΠΊΠΎΠ½ΡΠΈΠ³ (ΡΠΊΠΎΡΠ΅Π΅ Π²ΡΠ΅Π³ΠΎ, bootstrap.php) Π΄ΠΎΠ±Π°Π²ΠΈΡΡ:, (*10)
Yii::setAlias('@storageUrl','/frontend/web/images');
Π ΡΠ΅ΠΊΡΠΈΡ modules ΠΊΠΎΠ½ΡΠΈΠ³Π° Π΄ΠΎΠ±Π°Π²ΠΈΡΡ:, (*11)
'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:, (*12)
'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', Π²ΡΠ²ΠΎΠ΄ΠΈΡ ΡΠ΅Π½Ρ. Π‘Π²ΡΠ·Π°Π½ Ρ dvizh\cart\widgets\ChangeOptions ΡΠ΅ΡΠ΅Π· jQuery ΡΡΠΈΠ³Π³Π΅Ρ ΠΈ ΠΌΠΎΠΆΠ΅Ρ ΠΎΠΏΡΠ΅Π΄Π΅Π»ΡΡΡ, ΠΊΠ°ΠΊΠ°Ρ ΠΌΠΎΠ΄ΠΈΡΠΈΠΊΠ°ΡΠΈΡ Π²ΡΠ±ΡΠ°Π½Π° ΠΈ Π΄ΠΈΠ½Π°ΠΌΠΈΡΠ΅ΡΠΊΠΈ ΠΌΠ΅Π½ΡΡΡ ΡΠ΅Π½Ρ.
ΠΡΠΈΠΌΠ΅Ρ ΠΊΠ°ΡΡΠΎΡΠΊΠΈ ΡΠΎΠ²Π°ΡΠ° ΡΠΎ Π²ΡΠ΅ΠΌΠΈ Π²ΠΈΠ΄ΠΆΠ΅ΡΠ°ΠΌΠΈ ΠΌΠ°Π³Π°Π·ΠΈΠ½Π° ΠΈ ΠΊΠΎΡΠ·ΠΈΠ½Ρ, ΠΊΠΎΡΠΎΡΡΠ΅ ΡΠ°Π±ΠΎΡΠ°ΡΡ ΡΠΎΠΎΠ±ΡΠ° ΠΈ Π΄ΠΈΠ½Π°ΠΌΠΈΡΠ΅ΡΠΊΠΈ ΠΌΠ΅Π½ΡΡΡ Π΄Π°Π½Π½ΡΠ΅ Π΄ΡΡΠ³-Π΄ΡΡΠ³Π°., (*13)
=$product->name;?>
Shop
ShowPrice
=ShowPrice::widget(['model' => $product]);?>
Cart
ChangeCount
=ChangeCount::widget(['model' => $product]);?>
ChangeOptions
=ChangeOptions::widget(['model' => $product]);?>
BuyButton
=BuyButton::widget(['model' => $product]);?>
TruncateButton
=TruncateButton::widget();?>
CartInformer
=CartInformer::widget();?>
ElementsList
=ElementsList::widget(['type' => 'dropdown']);?>