Integrated GTM

This commit is contained in:
Prashant Singh 2019-08-23 08:56:25 +05:30
parent 9767e479f2
commit b62b277cac
25 changed files with 523 additions and 8 deletions

View File

@ -99,7 +99,9 @@
"Webkul\\CustomerCreditMax\\": "packages/Webkul/CustomerCreditMax",
"Webkul\\CustomerGroupCatalog\\": "packages/Webkul/CustomerGroupCatalog",
"Webkul\\ShowPriceAfterLogin\\": "packages/Webkul/ShowPriceAfterLogin/src",
"Webkul\\PreOrder\\": "packages/Webkul/PreOrder/src"
"Webkul\\PreOrder\\": "packages/Webkul/PreOrder/src",
"Webkul\\Webfont\\": "packages/Webkul/Webfont/src",
"Webkul\\GTM\\": "packages/Webkul/GTM/src"
}
},
"autoload-dev": {

View File

@ -249,6 +249,8 @@ return [
Webkul\CustomerDocument\Providers\CustomerDocumentServiceProvider::class,
Webkul\BulkAddToCart\Providers\BulkAddToCartServiceProvider::class,
Webkul\AdminAuthCheck\Providers\AdminAuthCheckServiceProvider::class,
Webkul\Webfont\Providers\WebfontServiceProvider::class,
Webkul\GTM\Providers\GTMServiceProvider::class,
Webkul\StripeConnect\Providers\StripeConnectServiceProvider::class,
Webkul\ShowPriceAfterLogin\Providers\ShowPriceAfterLoginServiceProvider::class,
Webkul\CustomerCreditMax\Providers\CustomerCreditMaxServiceProvider::class,

View File

@ -22,6 +22,7 @@ return [
\Webkul\Discount\Providers\ModuleServiceProvider::class,
\Webkul\CMS\Providers\ModuleServiceProvider::class,
\Webkul\StripeConnect\Providers\ModuleServiceProvider::class,
\Webkul\PreOrder\Providers\ModuleServiceProvider::class
\Webkul\PreOrder\Providers\ModuleServiceProvider::class,
\Webkul\Webfont\Providers\ModuleServiceProvider::class
]
];

View File

@ -0,0 +1,27 @@
{
"name": "bagisto/laravel-gtm",
"license": "MIT",
"authors": [
{
"name": "Prashant Singh",
"email": "prashant.singh852@webkul.com"
}
],
"require": {},
"autoload": {
"psr-4": {
"Webkul\\GTM\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Webkul\\GTM\\Providers\\GTMServiceProvider"
],
"aliases": {
}
}
},
"minimum-stability": "dev"
}

View File

@ -0,0 +1,52 @@
# Introduction:
Bagisto webfont is dynamic implementation of google web fonts. It allows you to choose fonts from google fonts directly from your own Bagisto instance. Choose as many google fonts at once and customize your font for storefront or backend or both within few steps.
# Feature of Bagisto webfont module
* Allows you to activate and deactivate module.
* Allow a default font in case you have chosen none.
* Separate control for using font in admin panel or storefront.
# Requirements
* Bagisto v0.1.7 or higher.
# Note:
Before proceeding you need google fonts API key. You can get your own key by following instructions after opening the link below:
> https://developers.google.com/fonts/docs/developer_api
# Installation
* Extract contents of the zip file in the root of your Bagisto instance.
* Do entry in composer.json in psr-4 object:
```
"Webkul\\Webfont\\": "packages/Webkul/Webfont/src"
```
* Do entry in config/app.php, inside providers array preferably at the end of it:
```
Webkul\Webfont\Providers\WebfontServiceProvider::class
```
* Do entry in config\concord.php file:
```
\Webkul\Webfont\Providers\ModuleServiceProvider::class
```
* Run command below:
1. composer dump-autoload
> Proceed if there are no errors encountered
2. php artisan migrate
3. php artisan route:cache
* You can now find the module configuration in admin panel under Configuration > General > Design.
* In the configuration page, there is a field for API key which will require to enter your own Google Fonts Developer API key.
* Find the module under CMS > Webfont.
> Congrats, you are all set to use Google fonts from your Bagisto instance.

View File

@ -0,0 +1,39 @@
<?php
return [
[
'key' => 'general.gtm',
'name' => 'gtm::app.gtm',
'sort' => 3,
], [
'key' => 'general.gtm.values',
'name' => 'gtm::app.values',
'sort' => 1,
'fields' => [
[
'name' => 'status',
'title' => 'gtm::app.gtm-status',
'type' => 'select',
'options' => [
[
'title' => 'Active',
'value' => true
], [
'title' => 'Inactive',
'value' => false
]
],
'channel_based' => false,
'locale_based' => false
], [
'name' => 'container_id',
'title' => 'gtm::app.container-id',
'type' => 'text',
'validation' => 'required',
'channel_based' => false,
'locale_based' => false
]
]
]
];

View File

@ -0,0 +1,28 @@
<?php
namespace Webkul\GTM\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Event;
use View;
class EventServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
if (core()->getConfigData('general.gtm.values.status')) {
Event::listen('bagisto.shop.layout.head', function($viewRenderEventManager) {
$viewRenderEventManager->addTemplate('gtm::head');
});
Event::listen('bagisto.shop.layout.body.before', function($viewRenderEventManager) {
$viewRenderEventManager->addTemplate('gtm::body');
});
}
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace Webkul\GTM\Providers;
use Illuminate\Support\ServiceProvider;
use Webkul\GTM\Providers\EventServiceProvider;
class GTMServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
$this->loadViewsFrom(__DIR__ . '/../Resources/views', 'gtm');
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'gtm');
$this->app->register(EventServiceProvider::class);
}
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->registerConfig();
}
/**
* Registers config
*/
protected function registerConfig()
{
$this->mergeConfigFrom(
dirname(__DIR__) . '/Config/system.php', 'core'
);
}
}

View File

@ -0,0 +1,8 @@
<?php
return [
'gtm' => 'Tag Manager',
'container-id' => 'Container ID',
'values' => 'Settings',
'gtm-status' => 'Status'
];

View File

@ -0,0 +1,17 @@
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id={{ core()->getConfigData('general.gtm.values.container_id') }}" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
@if (\Route::current()->getName() == 'shop.products.index')
@include('gtm::product')
@endif
@if (\Route::current()->getName() == 'shop.categories.index')
@include('gtm::category')
@endif
@if (\Route::current()->getName() == 'shop.checkout.cart.index')
@include('gtm::cart')
@endif
@if (\Route::current()->getName() == 'shop.checkout.success')
@include('gtm::checkout-success')
@endif

View File

@ -0,0 +1,50 @@
@inject ('priceHelper', 'Webkul\Product\Helpers\Price')
@inject('productFlat', 'Webkul\Product\Repositories\ProductFlatRepository')
<script>
dataLayer.push({
'pageCategory': 'shop.checkout.cart.index',
@php
$cart = \Cart::getCart();
@endphp
@if ($cart)
@foreach($cart->items as $item)
@php
$product = $item->product;
@endphp
@if ($product->type == 'configurable')
'ecommerce': {
'currencyCode': '{{ core()->getCurrentCurrency()->code }}',
'impressions': [{
'id': '{{ $product->id ?? null }}',
'sku': '{{ $product->sku ?? null }}'
'category': '{{ $category ?? null }}',
'name': '{{ $product->name ?? null }}',
'price': '{{ core()->currency($priceHelper->getMinimalPrice($product)) ?? null }}'
}]
}
@else
'ecommerce': {
'currencyCode': '{{ core()->getCurrentCurrency()->code }}',
'impressions': [{
'id': '{{ $product->id ?? null }}',
'name': '{{ $product->name ?? null }}',
'category': '{{ $category ?? null }}',
@if ($priceHelper->haveSpecialPrice($product))
'price': '{{ core()->currency($priceHelper->getSpecialPrice($product)) ?? null }}'
@else
'price': '{{ core()->currency($product->price) ?? null }}'
@endif
}]
}
@endif
@endforeach
@endif
});
</script>

View File

@ -0,0 +1,92 @@
@inject ('priceHelper', 'Webkul\Product\Helpers\Price')
@inject('productFlat', 'Webkul\Product\Repositories\ProductFlatRepository')
@php
$uri = request()->getRequestUri();
$uri = explode('/', $uri);
$slug = last($uri);
$productRepository = app('Webkul\Product\Repositories\ProductRepository');
$categoryRepository = app('Webkul\Category\Repositories\CategoryRepository');
$category = $categoryRepository->findBySlugOrFail($slug);
$products = $productRepository->getAll($category->id);
$toolbarHelper = app('Webkul\Product\Helpers\Toolbar');
@endphp
<script>
dataLayer.push({
'pageCategory': 'shop.categories.index',
@if ($toolbarHelper->getCurrentMode() == 'grid')
@foreach ($products as $productFlat)
@if ($productFlat->product->type == 'configurable')
'ecommerce': {
'currencyCode': '{{ core()->getCurrentCurrency()->code }}',
'impressions': [{
'id': '{{ $productFlat->id ?? null }}',
'sku': '{{ $productproductFlat->sku ?? null }}'
'category': '{{ $slug ?? null }}',
'name': '{{ $productFlat->name ?? null }}',
'price': '{{ core()->currency($priceHelper->getMinimalPrice($productFlat->product)) ?? null }}'
}]
}
@else
'ecommerce': {
'currencyCode': '{{ core()->getCurrentCurrency()->code }}',
'impressions': [{
'id': '{{ $productFlat->product->id ?? null }}',
'name': '{{ $productFlat->name ?? null }}',
'category': '{{ $slug ?? null }}',
@if ($priceHelper->haveSpecialPrice($productFlat->product))
'price': '{{ core()->currency($priceHelper->getSpecialPrice($productFlat->product)) ?? null }}'
@else
'price': '{{ core()->currency($productFlat->price) ?? null }}'
@endif
}]
}
@endif
@endforeach
@else
@foreach ($products as $productFlat)
@if ($productFlat->product->type == 'configurable')
'ecommerce': {
'currencyCode': '{{ core()->getCurrentCurrency()->code }}',
'impressions': [{
'id': '{{ $productFlat->id ?? null }}',
'sku': '{{ $productFlat->sku ?? null }}'
'category': '{{ $category ?? null }}',
'name': '{{ $productFlat->name ?? null }}',
'price': '{{ core()->currency($priceHelper->getMinimalPrice($productFlat->product)) ?? null }}'
}]
}
@else
'ecommerce': {
'currencyCode': '{{ core()->getCurrentCurrency()->code }}',
'impressions': [{
'id': '{{ $productFlat->id ?? null }}',
'name': '{{ $productFlat->name ?? null }}',
'category': '{{ $category ?? null }}',
@if ($priceHelper->haveSpecialPrice($productFlat->product))
'price': '{{ core()->currency($priceHelper->getSpecialPrice($productFlat->product)) ?? null }}'
@else
'price': '{{ core()->currency($product->price) ?? null }}'
@endif
}]
}
@endif
@endforeach
@endif
});
</script>

View File

@ -0,0 +1,13 @@
<script>
dataLayer.push({
'pageCategory': 'Checkout',
'pagetype': 'shop.checkout.success',
'list': 'checkout'
});
dataLayer.push({
'transactionId': {{ $order->id ?? 0 }},
'transactionTotal': {{ $order->grand_total ?? 0 }},
'transactionTaxAmount': {{ $order->tax_amount ?? 0 }}
});
</script>

View File

@ -0,0 +1 @@
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','{{ core()->getConfigData('general.gtm.values.container_id') }}');</script>

View File

@ -0,0 +1,60 @@
@inject ('priceHelper', 'Webkul\Product\Helpers\Price')
@inject('productFlat', 'Webkul\Product\Repositories\ProductFlatRepository')
@php
$uri = request()->getRequestUri();
$uri = explode('/', $uri);
$slug = last($uri);
$product = $productFlat->findWhere([
'url_key' => $slug,
'locale' => app()->getLocale(),
'channel' => core()->getCurrentChannel()->code
]);
@endphp
@if (count($product))
@php
$product = $product->first()->product;
$category = $product->categories->first()->slug;
@endphp
<script>
dataLayer.push({
'pageCategory': 'shop.products.index',
@if ($product->type == 'configurable')
'ecommerce': {
'currencyCode': '{{ core()->getCurrentCurrency()->code }}',
'impressions': [{
'id': '{{ $product->id ?? null }}',
'sku': '{{ $product->sku ?? null }}'
'category': '{{ $category ?? null }}',
'name': '{{ $product->name ?? null }}',
'price': '{{ core()->currency($priceHelper->getMinimalPrice($product)) ?? null }}'
}]
}
@else
'ecommerce': {
'currencyCode': '{{ core()->getCurrentCurrency()->code }}',
'impressions': [{
'id': '{{ $product->id ?? null }}',
'name': '{{ $product->name ?? null }}',
'category': '{{ $category ?? null }}',
@if ($priceHelper->haveSpecialPrice($product))
'price': '{{ core()->currency($priceHelper->getSpecialPrice($product)) ?? null }}'
@else
'price': '{{ core()->currency($product->price) ?? null }}'
@endif
}]
}
@endif
});
</script>
@endif

View File

@ -29,6 +29,7 @@ class Handler extends ExceptionHandler
public function render($request, Exception $exception)
{
$path = 'saas';
dd($exception->getMessage());
if ($exception->getMessage() == 'domain_not_found') {
return $this->response($path, 400, trans('saas::app.exceptions.domain-not-found'), 'domain_not_found');

View File

@ -258,10 +258,8 @@ class StripeConnectController extends Controller
if (core()->getConfigData('stripe.connect.details.stripefees') == "customer") {
$applicationFee1 = $applicationFee + $cart->base_grand_total * (2.9 / 100);
$result = StripeCharge::create([
"amount" => round(Cart::getCart()->base_grand_total + $applicationFee1, 2) * 100,
"amount" => round(Cart::getCart()->base_grand_total + $applicationFee, 2) * 100,
"currency" => Cart::getCart()->base_currency_code,
"source" => $stripeToken,
"description" => "Purchased ".Cart::getCart()->items_count." items",

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"/js/ui.js": "/js/ui.js?id=7db236c965e423a0f307",
"/js/ui.js": "/js/ui.js?id=d45f30274094b316b081",
"/css/ui.css": "/css/ui.css?id=6520763c9aa81f1fc2e0"
}

View File

@ -7,5 +7,11 @@ return [
'route' => 'admin.cms.webfont',
'sort' => 2,
'icon-class' => '',
], [
'key' => 'cms.homeseo',
'name' => 'webfont::app.homeseo',
'route' => 'admin.cms.homeseo',
'sort' => 2,
'icon-class' => '',
]
];

View File

@ -59,6 +59,18 @@ return [
'value' => false
]
]
], [
'name' => 'primary_color',
'title' => 'webfont::app.webfont-primary',
'type' => 'text',
'channel_based' => false,
'locale_based' => false
], [
'name' => 'secondary_color',
'title' => 'webfont::app.webfont-secondary',
'type' => 'text',
'channel_based' => false,
'locale_based' => false
]
]
]

View File

@ -2,7 +2,6 @@
namespace Webkul\Webfont\Http\Controllers;
use Illuminate\Support\Facades\Storage;
use Webkul\Webfont\Repositories\WebfontRepository as Webfont;
use GuzzleHttp;
@ -119,4 +118,9 @@ class WebfontController extends Controller
return view('webfont::add-font');
}
public function homeSeo()
{
return redirect()->route('admin.cms.index');
}
}

View File

@ -10,4 +10,6 @@ Route::group(['middleware' => ['admin']], function () {
Route::get('admin/webfont/activate/{id}', 'Webkul\Webfont\Http\Controllers\WebfontController@activate')->name('admin.cms.webfont.activate');
Route::post('admin/webfont/remove/{id}', 'Webkul\Webfont\Http\Controllers\WebfontController@remove')->name('admin.cms.webfont.remove');
Route::get('admin/home/seo', 'Webkul\Webfont\Http\Controllers\WebfontController@homeSeo')->name('admin.cms.homeseo');
});

View File

@ -2,6 +2,9 @@
return [
'id' => 'ID',
'homeseo' => 'Home Page SEO',
'webfont-primary' => 'Primary accent color',
'webfont-secondary' => 'Secondary accent color',
'font' => 'Font',
'title' => 'Webfonts',
'save-btn-title' => 'Save Web Font',

View File

@ -3,6 +3,10 @@
@php
$activatedFont = app('Webkul\Webfont\Repositories\WebfontRepository');
$primaryColor = core()->getConfigData('general.design.webfont.primary_color') ?? '#02bb89';
$secondaryColor = core()->getConfigData('general.design.webfont.secondary_color') ?? '#436be0';
$font = $activatedFont->findOneWhere([
'activated' => 1
]);
@ -48,4 +52,52 @@
body {
font-family: "{{ $font }}", {{ $family }};
}
.btn.btn-primary {
background: {{ $primaryColor }};
color: #fff;
}
.btn.btn-black {
background: {{ $secondaryColor }};
color: #fff;
}
.btn.btn-white {
background: #c7c7c7;
color: #fff;
}
.btn:disabled, .btn[disabled="disabled"], .btn[disabled="disabled"]:hover, .btn[disabled="disabled"]:active {
cursor: not-allowed;
background: {{ $secondaryColor }};
-webkit-box-shadow: none;
box-shadow: none;
opacity: 1;
}
.tabs ul li.active a {
border-bottom: 3px solid {{ $secondaryColor }};
}
.dropdown-list .dropdown-container ul li a:hover {
color: {{ $secondaryColor }};
}
a:hover {
color: {{ $secondaryColor }};
}
a:link, a:hover, a:visited, a:focus, a:active {
color: {{ $secondaryColor }};
}
.control-group .control:focus {
border-color: {{ $primaryColor }};
}
.account-content .menu-block .menubar li.active a {
color: {{ $primaryColor }};
}
}
</style>