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/ */
$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',
],
];
// 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();