Skip to content

Commit

Permalink
Basic hero product module
Browse files Browse the repository at this point in the history
  • Loading branch information
indpurvesh committed Sep 21, 2020
1 parent b93c39c commit 3717817
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 23 deletions.
23 changes: 1 addition & 22 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,2 @@
/vendor/
node_modules/
npm-debug.log
yarn-error.log

# Laravel 4 specific
bootstrap/compiled.php
app/storage/

# Laravel 5 & Lumen specific
public/storage
public/hot

# Laravel 5 & Lumen specific with changed public path
public_html/storage
public_html/hot

storage/*.key
.env
Homestead.yaml
Homestead.json
/.vagrant
.phpunit.result.cache
.DS_Store
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Purvesh
Copyright (c) 2018 AvoRed E commerce

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
45 changes: 45 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name" : "avored/heroproduct",
"description" : "AvoRed Laravel E commerce - Hero Product Module",
"keywords" : [
"framework",
"banner",
"cart",
"laravel",
"e commerce",
"laravel5",
"shop",
"shopping-cart",
"e-commerce",
"shopping cart",
"e commerce"
],
"license" : "MIT",
"authors" : [{
"name" : "Purvesh ",
"email" : "[email protected]"
}
],
"type" : "avored-module",
"require" : {
"php": ">7.2",
"avored/module-installer" : "1.*",
"avored/framework" : "~3.1"
},
"autoload" : {
"classmap" : [
"database/migrations"
],
"psr-4" : {
"AvoRed\\HeroProduct\\" : "src/"
}
},
"homepage" : "https://avored.com",
"support" : {
"email" : "[email protected]",
"issues" : "https://avored.com/discussion",
"forum" : "https://avored.com/discussion",
"wiki" : "https://avored.com/docs",
"source" : "https://github.com/avored/banner"
}
}
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# AvoRed Hero Product Module

### Installation

composer require avored/heroproduct

### How to Use
5 changes: 5 additions & 0 deletions register.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: AvoRed HeroProduct
identifier: avored-heroproduct
status: active
description: AvoRed HeroProduct Module
namespace: AvoRed\HeroProduct\
5 changes: 5 additions & 0 deletions resources/lang/en/system.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'config-title' => 'Hero Product',
];
13 changes: 13 additions & 0 deletions resources/views/configuration/heroproduct.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@php
$value = $repository->getValueByCode('avored_hero_product');
$productRepository = app(\AvoRed\Framework\Database\Contracts\ProductModelInterface::class);
$productOptions = $productRepository->all()->pluck('name', 'id');
@endphp
<avored-select
field-name="avored_hero_product"
label-text="{{ __('avored-heroproduct::system.config-title') }}"
:options="{{ json_encode($productOptions) }}"
init-value="{{ $value }}"
></avored-select>
32 changes: 32 additions & 0 deletions resources/views/widget/hero-product.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@if ($heroProduct)
<section class="text-gray-700 body-font">
<div class="container mx-auto flex px-5 py-24 md:flex-row flex-col items-center">
<div class="lg:flex-grow md:w-1/2 lg:pr-24 md:pr-16 flex flex-col md:items-start md:text-left mb-16 md:mb-0 items-center text-center">
<h1 class="title-font text-re sm:text-4xl text-3xl mb-4 font-medium text-gray-700">
{{ $heroProduct->name }}
</h1>
<p class="leading-relaxed">
{{ $heroProduct->description }}
</p>
<div class="text-2xl text-red-700 font-semibold my-4">
{{ session()->get('default_currency')->symbol . number_format($heroProduct->price, 2) }}
</div>
<div class="flex justify-center">
<form method="post" action="{{ route('add.to.cart') }}">
@csrf
<input type="hidden" name="slug" value="{{ $heroProduct->slug }}" />
<input type="hidden" name="qty" value="1" />
<button type="submit" class="px-6 py-3 bg-red-500 text-white font-semibold rounded">
Add to cart
</button>
</form>

{{-- <button class="ml-4 inline-flex text-gray-700 bg-gray-200 border-0 py-2 px-6 focus:outline-none hover:bg-gray-300 rounded text-lg">Button</button> --}}
</div>
</div>
<div class="lg:max-w-lg lg:w-full md:w-1/2 w-5/6">
<img class="object-cover object-center rounded" alt="hero" src="{{ $heroProduct->mainImage->path ?? 'https://placehold.it/250x250' }}">
</div>
</div>
</section>
@endif
61 changes: 61 additions & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
namespace AvoRed\HeroProduct;

use AvoRed\Framework\Support\Facades\Tab;
use AvoRed\Framework\Support\Facades\Widget;
use AvoRed\Framework\Tab\TabItem;
use AvoRed\HeroProduct\Widget\HeroProductWidget;
use Illuminate\Support\ServiceProvider;

class Module extends ServiceProvider
{

/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->registerResources();
$this->registerTab();
$this->registerWidget();
}

/**
* Register any application services.
*
* @return void
*/
public function register()
{

}

/**
* Registering AvoRed HeroProduct Resource
* e.g. Route, View, Database & Translation Path
*
* @return void
*/
protected function registerResources()
{
//$this->loadRoutesFrom(__DIR__ . '/../routes/web.php');
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'avored-heroproduct');
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'avored-heroproduct');
}

public function registerTab()
{
Tab::put('system.configuration', function (TabItem $tab) {
$tab->key('system.configuration.hero.product')
->label('avored-heroproduct::system.config-title')
->view('avored-heroproduct::configuration.heroproduct');
});
}
public function registerWidget()
{
$widget = new HeroProductWidget();
Widget::make($widget->identifier(), $widget);
}
}
91 changes: 91 additions & 0 deletions src/Widget/HeroProductWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
namespace AvoRed\HeroProduct\Widget;

use AvoRed\Framework\Database\Contracts\ConfigurationModelInterface;
use AvoRed\Framework\Database\Contracts\OrderModelInterface;
use AvoRed\Framework\Database\Contracts\ProductModelInterface;

class HeroProductWidget
{
/**
* Widget View Path
* @var string $view
*/

protected $view = "avored-heroproduct::widget.hero-product";

/**
* Widget Label
* @var string $view
*/

protected $label = 'Hero Product';

/**
* Widget Type
* @var string $view
*/

protected $type = "cms";

/**
* Widget unique identifier
* @var string $identifier
*/
protected $identifier = "avored-hero-product";

public function view()
{
return $this->view;
}

/*
* Widget unique identifier
*
*/
public function identifier()
{
return $this->identifier;
}

/*
* Widget unique identifier
*
*/
public function label()
{
return $this->label;
}

/*
* Widget unique identifier
*
*/
public function type()
{
return $this->type;
}

/**
* View Required Parameters
*
* @return array
*/
public function with()
{
$config = app(ConfigurationModelInterface::class);
$productId = $config->getValueByCode('avored_hero_product');

$repository = app(ProductModelInterface::class);
$product = null;
if ($productId > 0) {
$product = $repository->find($productId);
}
return ['heroProduct' => $product];
}

public function render()
{
return view($this->view(), $this->with());
}
}

0 comments on commit 3717817

Please sign in to comment.