PHP code example of andrewdanilov / yii2-shop

1. Go to this page and download the library: Download andrewdanilov/yii2-shop library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

andrewdanilov / yii2-shop example snippets


$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',
                    ],
                ],
            ],
        ],
    ],
];

$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',
    ],
];

return [
    // ...
    'adminEmail' => ['[email protected]', '[email protected]'],
    'senderEmail' => '[email protected]',
    'senderName' => 'Robot',
    // ...
];

return [
    'components' => [
        // ...
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'useFileTransport' => false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'username' => '[email protected]',
                '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();

return [
    // ...
    'language' => 'ru-RU',
    // ...
];

php yii migrate --migrationPath=@andrewdanilov/shop/console/migrations