conflict resolve

This commit is contained in:
rahul shukla 2018-10-26 09:50:46 +05:30
commit c8fd85fe4b
16 changed files with 557 additions and 1377 deletions

View File

@ -76,31 +76,31 @@ class CategoryDataGrid
'columns' => [
[
'name' => 'cat.id',
'alias' => 'catID',
'alias' => 'cat_id',
'type' => 'number',
'label' => 'Category ID',
'sortable' => true,
], [
'name' => 'ct.name',
'alias' => 'catName',
'alias' => 'cat_name',
'type' => 'string',
'label' => 'Category Name',
'sortable' => false,
], [
'name' => 'cat.position',
'alias' => 'catPosition',
'alias' => 'cat_position',
'type' => 'string',
'label' => 'Category Position',
'sortable' => false,
], [
'name' => 'cta.name',
'alias' => 'parentName',
'alias' => 'parent_name',
'type' => 'string',
'label' => 'Parent Name',
'sortable' => true,
], [
'name' => 'cat.status',
'alias' => 'catStatus',
'alias' => 'cat_status',
'type' => 'string',
'label' => 'Visible in Menu',
'sortable' => true,
@ -110,8 +110,17 @@ class CategoryDataGrid
else
return "True";
},
],
], [
'name' => 'cta.locale',
'alias' => 'cat_locale',
'type' => 'string',
'label' => 'Locale',
'sortable' => true,
'filter' => [
'function' => 'where',
'condition' => ['cta.locale', app()->getLocale()]
],
]
],
'filterable' => [

View File

@ -165,7 +165,7 @@ class EventServiceProvider extends ServiceProvider
'icon-class' => '',
], [
'key' => 'settings.sliders',
'name' => 'Create Sliders',
'name' => 'Sliders',
'route' => 'admin.sliders.index',
'sort' => 7,
'icon-class' => '',

View File

@ -74,6 +74,19 @@ class CategoryRepository extends Repository
: Category::orderBy('position', 'ASC')->get()->toTree();
}
/**
* get visible category tree
*
* @param integer $id
* @return mixed
*/
public function getVisibleCategoryTree($id = null)
{
return $id
? Category::orderBy('position', 'ASC')->where('id', '!=', $id)->where('status', '=', '1')->get()->toTree()
: Category::orderBy('position', 'ASC')->where('status', '=', '1')->get()->toTree();
}
/**
* Checks slug is unique or not based on locale
*

View File

@ -123,6 +123,17 @@ class Cart {
$child = $childData = null;
if($product->type == 'configurable') {
$child = $this->product->findOneByField('id', $data['selected_configurable_option']);
$productAddtionalData = $this->getProductAttributeOptionDetails($child);
unset($productAddtionalData['html']);
$additional = [
'request' => $data,
'variant_id' => $data['selected_configurable_option'],
'attributes' => $productAddtionalData
];
$childData = [
'product_id' => $data['selected_configurable_option'],
'sku' => $child->sku,
@ -145,7 +156,8 @@ class Cart {
'base_total' => $price * $data['quantity'],
'weight' => $weight = ($product->type == 'configurable' ? $child->weight : $product->weight),
'total_weight' => $weight * $data['quantity'],
'base_total_weight' => $weight * $data['quantity']
'base_total_weight' => $weight * $data['quantity'],
'additional' => json_encode($additional)
];
return ['parent' => $parentData, 'child' => $childData];
@ -507,25 +519,51 @@ class Cart {
if($id == $item->id) {
if($item->type == "configurable") {
$canBe = $this->canAddOrUpdate($item->child->id, $quantity);
if($canBe == false) {
session()->flash('warning', trans('shop::app.checkout.cart.quantity.inventory_warning'));
return $cart;
}
$item->update([
'quantity' => $quantity,
'total' => core()->convertPrice($item->price * ($quantity)),
'base_total' => $item->price * ($quantity),
'total_weight' => $item->weight * ($quantity),
'base_total_weight' => $item->weight * ($quantity)
]);
} else {
$canBe = $this->canAddOrUpdate($id, $quantity);
if($canBe == false) {
session()->flash('warning', trans('shop::app.checkout.cart.quantity.inventory_warning'));
return $cart;
}
$prevQty = $item->quantity;
$item->update([
'quantity' => $quantity,
'total' => core()->convertPrice($item->price * ($quantity)),
'base_total' => $item->price * ($quantity),
'total_weight' => $item->weight * ($quantity),
'base_total_weight' => $item->weight * ($quantity)
]);
}
if($canBe == false) {
session()->flash('warning', trans('shop::app.checkout.cart.quantity.inventory_warning'));
return $cart;
}
$item->update(['quantity' => $quantity]);
}
}
}
$this->collectTotals();
session()->flash('success', trans('shop::app.checkout.cart.quantity.success'));
}
return $cart;
return $cart;
} else {
session()->flash('warning', trans('shop::app.checkout.cart.integrity.missing_fields'));
return false;
}
}
/**
@ -629,21 +667,22 @@ class Cart {
}
/**
* Returns cart
* Returns the items details of the configurable and simple products
*
* @return Mixed
*/
public function getItemAttributeOptionDetails($item)
public function getProductAttributeOptionDetails($product)
{
$data = [];
$labels = [];
foreach($item->product->super_attributes as $attribute) {
$option = $attribute->options()->where('id', $item->child->product->{$attribute->code})->first();
foreach($product->parent->super_attributes as $attribute) {
$option = $attribute->options()->where('id', $product->{$attribute->code})->first();
$data['attributes'][$attribute->code] = [
'attribute_name' => $attribute->name,
'option_id' => $option->id,
'option_label' => $option->label,
];
@ -756,6 +795,8 @@ class Cart {
if(!$cart = $this->getCart())
return false;
$this->validateItems();
$this->calculateItemsTax();
$cart->grand_total = $cart->base_grand_total = 0;
@ -790,6 +831,60 @@ class Cart {
$cart->save();
}
/**
* To validate if the product information is changed by admin and the items have
* been added to the cart before it.
*
* @return boolean
*/
public function validateItems() {
$cart = $this->getCart();
if(count($cart->items) == 0) {
$this->cart->delete($cart->id);
return redirect()->route('shop.home.index');
} else {
$items = $cart->items;
foreach($items as $item) {
if($item->product->type == 'configurable') {
if($item->product->sku != $item->sku) {
$item->update(['sku' => $item->product->sku]);
} else if($item->product->name != $item->name) {
$item->update(['name' => $item->product->name]);
} else if($item->child->product->price != $item->price) {
$item->update([
'price' => $item->child->product->price,
'base_price' => $item->child->product->price,
'total' => core()->convertPrice($item->child->product->price * ($item->quantity)),
'base_total' => $item->child->product->price * ($item->quantity),
]);
}
} else if($item->product->type == 'simple') {
if($item->product->sku != $item->sku) {
$item->update(['sku' => $item->product->sku]);
} else if($item->product->name != $item->name) {
$item->update(['name' => $item->product->name]);
} else if($item->product->price != $item->price) {
$item->update([
'price' => $item->product->price,
'base_price' => $item->product->price,
'total' => core()->convertPrice($item->child->product->price * ($item->quantity)),
'base_total' => $item->child->product->price * ($item->quantity),
]);
}
}
}
return true;
}
}
/**
* Calculates cart items tax
*
@ -1044,6 +1139,16 @@ class Cart {
$price = ($product->type == 'configurable' ? $child->price : $product->price);
$productAddtionalData = $this->getProductAttributeOptionDetails($child);
unset($productAddtionalData['html']);
$additional = [
'request' => $data,
'variant_id' => $data['selected_configurable_option'],
'attributes' => $productAddtionalData
];
$parentData = [
'sku' => $product->sku,
'product_id' => $productId,
@ -1056,7 +1161,8 @@ class Cart {
'base_total' => $price,
'weight' => $weight = ($product->type == 'configurable' ? $child->weight : $product->weight),
'total_weight' => $weight,
'base_total_weight' => $weight
'base_total_weight' => $weight,
'additional' => json_encode($additonal)
];
return ['parent' => $parentData, 'child' => $childData];

View File

@ -67,12 +67,12 @@ class RegistrationController extends Controller
if ($this->customer->create($data)) {
session()->flash('success', 'Account created successfully.');
session()->flash('success', 'Account Created Successfully');
return redirect()->route($this->_config['redirect']);
} else {
session()->flash('error', 'Cannot Create Your Account.');
session()->flash('error', 'Cannot Create Your Account');
return redirect()->back();
}

View File

@ -44,7 +44,7 @@ class CategoryComposer
{
$categories = [];
foreach ($this->category->getCategoryTree() as $category) {
foreach ($this->category->getVisibleCategoryTree() as $category) {
array_push($categories, collect($category));
}

View File

@ -1,4 +1,3 @@
<template>
<li>
<a :href="url+'/categories/'+this.item['translations'][0].slug">{{ this.item['translations'][0].name }}&emsp;<i class="icon dropdown-right-icon"
@ -17,6 +16,7 @@
</ul>
</li>
</template>
<script>
// define the item component
export default {

View File

@ -1,8 +1,255 @@
@import "variables";
@import "icons";
@import "mixins";
@import "components";
@import "override";
//override UA
body {
margin: 0;
padding: 0;
font-weight: 500;
max-width: 100%;
width: auto;
color: $font-color;
font-size: 16px;
}
* {
font-family: "Montserrat", sans-serif;
}
*::-webkit-input-placeholder {
font-family: "Montserrat", sans-serif;
}
*::-webkit-input-placeholder {
font-family: "Montserrat", sans-serif;
}
.btn.btn-primary{
border-radius: 0px;
}
//margin bottom classes
.mb-10 {
margin-bottom: 10px;
}
.mb-15 {
margin-bottom: 15px;
}
.mb-20 {
margin-bottom: 20px;
}
.mb-25 {
margin-bottom: 25px;
}
.mb-30 {
margin-bottom: 30px;
}
.mb-35 {
margin-bottom: 35px;
}
.mb-40 {
margin-bottom: 40px;
}
.mb-45 {
margin-bottom: 45px;
}
.mb-50 {
margin-bottom: 50px;
}
.mb-60 {
margin-bottom: 60px;
}
.mb-70 {
margin-bottom: 70px;
}
.mb-80 {
margin-bottom: 80px;
}
.mb-90 {
margin-bottom: 90px;
}
//margin-top
.mt-5 {
margin-top: 5px;
}
.mt-10 {
margin-top: 10px;
}
.mt-15 {
margin-top: 15px;
}
.mt-20 {
margin-top: 20px;
}
.mt-25 {
margin-top: 25px;
}
.mt-30 {
margin-top: 30px;
}
.mt-35 {
margin-top: 35px;
}
.mt-40 {
margin-top: 40px;
}
.mt-45 {
margin-top: 45px;
}
.mt-50 {
margin-top: 50px;
}
.mt-60 {
margin-top: 60px;
}
.mt-70 {
margin-top: 70px;
}
.mt-80 {
margin-top: 80px;
}
.mt-90 {
margin-top: 90px;
}
//components
//wishlist icon hover properties
.add-to-wishlist {
.wishlist-icon {
&:hover {
background-image: url('../images/wishadd.svg');
}
}
}
//product page price styles
.product-price {
margin-bottom: 14px;
width: 100%;
font-weight: 600;
.price-label {
font-size: 14px;
font-weight: 400;
}
.regular-price {
color: #A5A5A5;
text-decoration: line-through;
margin-right: 10px;
}
.special-price {
color: #FF6472;
}
}
//horizontal rule
.horizontal-rule {
width: 100%;
height: 1px;
background: $border-color;
}
//Customer account section header
.account-head {
.account-heading {
font-size: 28px;
color: $font-color;
text-transform: capitalize;
text-align: left;
}
.account-action {
font-size: 17px;
margin-top: 1%;
color: $brand-color;
float: right;
}
.horizontal-rule {
margin-top: 1.1%;
width: 100%;
height: 1px;
vertical-align: middle;
background: $border-color;
}
}
//denotes the item card that are used in account pages
.account-item-card {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
width: 100%;
height: 125px;
.media-info {
display: flex;
flex-direction: row;
.media {
height: 125px;
width: 125px;
}
.info {
display: block;
margin-left: 20px;
}
}
.operations {
height: 120px;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
a {
width: 100%;
span {
float: right;
}
}
}
}
//Account items list
.account-items-list {
display: block;
width: 100%;
}
//main store front layouting
.main-container-wrapper {
@ -101,6 +348,7 @@
.addtocart {
margin-right: 10px;
text-transform: uppercase;
text-align: left;
}
.add-to-wishlist {

View File

@ -1,110 +0,0 @@
//wishlist icon hover properties
.add-to-wishlist {
.wishlist-icon {
&:hover {
background-image: url('../images/wishadd.svg');
}
}
}
//product page price styles
.product-price {
margin-bottom: 14px;
width: 100%;
font-weight: 600;
.price-label {
font-size: 14px;
font-weight: 400;
}
.regular-price {
color: #A5A5A5;
text-decoration: line-through;
margin-right: 10px;
}
.special-price {
color: #FF6472;
}
}
//horizontal rule
.horizontal-rule {
width: 100%;
height: 1px;
background: $border-color;
}
//Customer account section header
.account-head {
.account-heading {
font-size: 28px;
color: $font-color;
text-transform: capitalize;
text-align: left;
}
.account-action {
font-size: 17px;
margin-top: 1%;
color: $brand-color;
float: right;
}
.horizontal-rule {
margin-top: 1.1%;
width: 100%;
height: 1px;
vertical-align: middle;
background: $border-color;
}
}
//denotes the item card that are used in account pages
.account-item-card {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
width: 100%;
height: 125px;
.media-info {
display: flex;
flex-direction: row;
.media {
height: 125px;
width: 125px;
}
.info {
display: block;
margin-left: 20px;
}
}
.operations {
height: 120px;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
a {
width: 100%;
span {
float: right;
}
}
}
}
//Account items list
.account-items-list {
display: block;
width: 100%;
}

View File

@ -1,128 +0,0 @@
body {
margin: 0;
padding: 0;
font-weight: 500;
max-width: 100%;
width: auto;
color: $font-color;
font-size: 16px;
}
* {
font-family: "Montserrat", sans-serif;
}
.btn.btn-primary{
border-radius: 0px;
}
//margin bottom classes
.mb-10 {
margin-bottom: 10px;
}
.mb-15 {
margin-bottom: 15px;
}
.mb-20 {
margin-bottom: 20px;
}
.mb-25 {
margin-bottom: 25px;
}
.mb-30 {
margin-bottom: 30px;
}
.mb-35 {
margin-bottom: 35px;
}
.mb-40 {
margin-bottom: 40px;
}
.mb-45 {
margin-bottom: 45px;
}
.mb-50 {
margin-bottom: 50px;
}
.mb-60 {
margin-bottom: 60px;
}
.mb-70 {
margin-bottom: 70px;
}
.mb-80 {
margin-bottom: 80px;
}
.mb-90 {
margin-bottom: 90px;
}
//margin-top
.mt-5 {
margin-top: 5px;
}
.mt-10 {
margin-top: 10px;
}
.mt-15 {
margin-top: 15px;
}
.mt-20 {
margin-top: 20px;
}
.mt-25 {
margin-top: 25px;
}
.mt-30 {
margin-top: 30px;
}
.mt-35 {
margin-top: 35px;
}
.mt-40 {
margin-top: 40px;
}
.mt-45 {
margin-top: 45px;
}
.mt-50 {
margin-top: 50px;
}
.mt-60 {
margin-top: 60px;
}
.mt-70 {
margin-top: 70px;
}
.mt-80 {
margin-top: 80px;
}
.mt-90 {
margin-top: 90px;
}

View File

@ -55,7 +55,7 @@
<div class="summary">
{{ Cart::getItemAttributeOptionDetails($item)['html'] }}
{{ Cart::getProductAttributeOptionDetails($item->child->product)['html'] }}
</div>
@endif

View File

@ -87,7 +87,7 @@
<div class="summary" >
{{ Cart::getItemAttributeOptionDetails($item)['html'] }}
{{ Cart::getProductAttributeOptionDetails($item->child->product)['html'] }}
</div>
@endif

View File

@ -446,7 +446,6 @@ class DataGrid
* Adds expressional verbs to be used
* @return $this
*/
public function setOperators(array $operators)
{
$this->operators = $operators ?: [];
@ -458,7 +457,6 @@ class DataGrid
*
* @return $this
*/
public function addPagination($pagination = [])
{
if ($pagination instanceof Pagination) {
@ -477,7 +475,6 @@ class DataGrid
* make from controller.
* @return $this
*/
private function getSelect()
{
$select = [];
@ -501,7 +498,6 @@ class DataGrid
* name.
* @return string
*/
public function findAlias($column_alias) {
foreach($this->columns as $column) {
if($column->alias == $column_alias) {
@ -515,7 +511,6 @@ class DataGrid
* and get it ready
* to be used.
*/
private function parse()
{
$parsed = [];
@ -534,7 +529,6 @@ class DataGrid
* ->join('contacts', 'users.id', '=', 'contacts.user_id')
* @return $this->query
*/
private function getQueryWithJoin()
{
foreach ($this->join as $join) {
@ -546,7 +540,8 @@ class DataGrid
{
foreach ($this->columns as $column) {
if ($column->filter) { // if the filter bag in array exists then these will be applied.
if (count($column->filter['condition']) == count($column->filter['condition'], COUNT_RECURSIVE)) {
// if (count($column->filter['condition']) == count($column->filter['condition'], COUNT_RECURSIVE)) {
if (count($column->filter['condition']) == 2) {
$this->query->{$column->filter['function']}(...$column->filter['condition']);
} else {
if (count($column->filter['condition']) == 3) {
@ -570,10 +565,9 @@ class DataGrid
}
/**
* Function runs when
* filters, sort, search
* any of it is applied
* @return $this->query
* Function runs when filters, sort, search any of it is applied
*
* @return QueryBuilder object
*/
private function getQueryWithFilters()
@ -753,7 +747,6 @@ class DataGrid
$alias_proper_secondary = true;
} else {
throw new \Exception('Aliases of Join table and the secondary key columns do not match');
}
} else {
throw new \Exception('Improper aliasing on secondary/join column for join');
@ -781,7 +774,7 @@ class DataGrid
$this->results = $this->query->get();
$this->results = $this->query->paginate($this->perpage)->appends(request()->except('page'));
$this->results = $this->query->distinct()->paginate($this->perpage)->appends(request()->except('page'));
return $this->results;

View File

@ -1,968 +0,0 @@
<?php
namespace Webkul\Ui\DataGrid;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Validate;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\DB;
use Webkul\Ui\DataGrid\Helpers\Column;
use Webkul\Ui\DataGrid\Helpers\Pagination;
use Webkul\Ui\DataGrid\Helpers\Css;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Product\Repositories\ProductAttributeValueRepository;
use Webkul\Product\Models\ProductAttributeValue;
use URL;
/**
* DataGrid controller
*
* @author Nikhil Malik <nikhil@webkul.com> @ysmnikhil
* &
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
*
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class ProductGrid
{
/**
* Name of DataGrid
*
* @var string
*/
protected $name;
/**
* select from table(s)
*
* @var string
*/
protected $select;
/**
* Table
* @var Boolean for aliasing
*/
protected $aliased;
/**
* Pagination variable
* @var String
*/
protected $perpage;
/**
* Table
*
* @var String Classs name $table
*/
protected $table;
/**
* Join
*
* @var Array name $join
*
* [
* 'join' => 'left',
* 'table' => 'posts',
* 'primaryKey' => 'user.id',
* 'condition' => '=',
* 'secondryKey' => 'posts.user_id',
* 'callback' => 'not supported yet'
* ]
*/
protected $join;
/**
* Collection Object of Column $columns
*
* @var Collection
*/
protected $columns;
/**
* array of columns
* to be filtered
* @var Array
*/
protected $filterable;
/**
* array of columns
* to be searched
*
* @var Array
*/
protected $searchable;
/**
* mass operations
*
* @var Array
*/
protected $massoperations;
/**
* Pagination $pagination
*
* @var Pagination
*/
protected $pagination;
/**
* Css $css
*
* @var Css
*/
protected $css;
/**
* Actions $action
* @var action
*/
protected $actions;
/**
* Attribute Columns
* for columns which
* are attributes.
*
* @var $attributeColumns
*/
protected $attributeColumns;
/**
* URL parse $parsed
* @var parse
*/
protected $parsed;
/**
* To store the
* attribute columns aliases
* for search, filter and
* sort.
*
* @var attributeAliases
*/
private $attributeAliases = [];
//Prepares the input parameters passed as the configuration for datagrid.
public function make($args)
{
// list($name, $select, $table, $join, $columns) = array_values($args);
$name = $select = $aliased = $table = false;
$join = $columns = $filterable = $searchable =
$massoperations = $attributeColumns = $css = $operators = $actions = [];
extract($args);
return $this->build($name, $select, $filterable, $searchable, $massoperations, $attributeColumns , $aliased, $perpage, $table, $join, $columns, $css, $operators,$actions);
}
//contructor for getting the current locale and channel
private $locale;
private $channel;
private $attributes;
private $allAttributes;
public function __construct(AttributeRepository $attributes) {
$this->channel = request()->get('channel') ?: core()->getDefaultChannelCode();
$this->locale = request()->get('locale') ?: app()->getLocale();
$this->attributes = $attributes;
}
//This assigns the private and public properties of the datagrid classes from make functions
public function build(
$name = null,
$select = false,
array $filterable = [],
array $searchable = [],
array $massoperations = [],
array $attributeColumns = [],
bool $aliased = false,
$perpage = 0,
$table = null,
array $join = [],
array $columns = null,
array $css = [],
array $operators = [],
array $actions = [],
Pagination $pagination = null
) {
$this->request = Request::capture();
$this->setName($name);
$this->setSelect($select);
$this->setFilterable($filterable);
$this->setSearchable($filterable);
$this->setMassOperations($massoperations);
$this->setAttributeColumns($attributeColumns);
$this->setAlias($aliased);
$this->setPerPage($perpage);
$this->setTable($table);
$this->setJoin($join);
$this->addColumns($columns, true);
$this->setCss($css);
$this->setOperators($operators);
$this->setActions($actions);
// $this->addPagination($pagination);
return $this;
}
/**
* Set Name.
*
* @return $this
*/
public function setName(string $name)
{
$this->name = $name ?: 'Default' . time();
return $this;
}
/**
* Set Select.
*
* @return $this
*/
public function setSelect($select)
{
$this->select = $select ? : false;
return $this;
}
/**
* Set Filterable
* @return $this
*/
public function setFilterable(array $filterable)
{
$this->filterable = $filterable ? : [];
return $this;
}
/**
* Set Searchable columns
* @return $this
*/
public function setSearchable($searchable)
{
$this->searchable = $searchable ? : [];
return $this;
}
/**
* Set mass operations
* @return $this
*/
public function setMassOperations($massops)
{
$this->massoperations = $massops ? : [];
return $this;
}
/**
* Set alias parameter
* to know whether
* aliasing is true or not.
*
* @return $this.
*/
public function setAlias(bool $aliased)
{
$this->aliased = $aliased ? : false;
return $this;
}
/**
* Set the default
* pagination for
* data grid.
*
* @return $this
*/
public function setPerPage($perpage)
{
$this->perpage = $perpage ? : 5;
return $this;
}
/**
* Set table name in front
* of query scope.
*
* @return $this
*/
public function setTable(string $table)
{
$this->table = $table ?: false;
return $this;
}
/**
* Set join bag if
* present.
*
* @return $this
*/
public function setJoin(array $join)
{
$this->join = $join ?: [];
return $this;
}
/**
* Adds the custom css rules
* @retun $this
*/
private function setCss($css = [])
{
$this->css = new Css($css);
return $this->css;
}
/**
* To set the attributes
* bag on product datagrid.
*
* @return $this
*/
private function setAttributeColumns($attributes = []) {
$this->attributeColumns = $attributes;
return $this->attributeColumns;
}
/**
* setFilterableColumns
* @return $this
*/
// public function setFilterableColumns($filterable_columns = [])
// {
// $this->join = $filterable_columns ?: [];
// return $this;
// }
/**
* Section actions bag
* here.
* @return $this
*/
public function setActions($actions = []) {
$this->actions = $actions ?: [];
return $this;
}
/**
* Add Columns.
*
* @return $this
*/
public function addColumns($columns = [], $reCreate = false)
{
if ($reCreate) {
$this->columns = new Collection();
}
if ($columns) {
foreach ($columns as $column) {
$this->addColumn($column);
}
}
return $this;
}
/**
* Add Column.
*
* @return $this
*/
public function addColumn($column = [])
{
if ($column instanceof Column) {
$this->columns->push($column);
} elseif (gettype($column) == 'array' && $column) {
$this->columns->push(new Column($column, $this->request));
} else {
throw new \Exception("DataGrid: Add Column argument is not valid!");
}
return $this;
}
/**
* Add ColumnMultiple.
* Currently is not
* of any use.
* @return $this
*/
private function addColumnMultiple($column = [], $multiple = false)
{
if ($column instanceof Column) {
if ($multiple) {
if ($this->columns->offsetExists($column->getName())) {
$this->columns->offsetSet($column->getName(). time(), $column);
} else {
$this->columns->offsetSet($column->getName(), $column);
}
} else {
$this->columns->offsetSet($column->getName(), $column);
}
} elseif (gettype($column) == 'array' && $column) {
$columnObj = new Column($column);
if ($multiple) {
if ($this->columns->offsetExists($columnObj->getName())) {
$this->columns->offsetSet($columnObj->getName(). time(), $columnObj);
} else {
$this->columns->offsetSet($columnObj->getName(), $columnObj);
}
} else {
$this->columns->offsetSet($columnObj->getName(), $columnObj);
}
} else {
throw new \Exception("DataGrid: Add Column argument is not valid!");
}
return $this;
}
/**
* Adds expressional verbs to be used
* @return $this
*/
public function setOperators(array $operators)
{
$this->operators = $operators ?: [];
return $this;
}
/**
* Add Pagination.
*
* @return $this
*/
public function addPagination($pagination = [])
{
if ($pagination instanceof Pagination) {
$this->pagination = $pagination;
} elseif (gettype($pagination) == 'array' && $pagination) {
$this->pagination = new Pagination($pagination);
} else {
throw new \Exception("DataGrid: Pagination argument is not valid!");
}
return $this;
}
/**
* Used for selecting
* the columns got in
* make from controller.
* @return $this
*/
private function getSelect()
{
$select = [];
foreach ($this->columns as $column) {
$select[] = $column->name.' as '.$column->alias;
}
$this->query->select(...$select);
if ($this->select) {
$this->query->addselect($this->select);
}
}
/**
* This function will
* map and resolve the
* product attributes
* and thier values
* per channel and per
* locale.
*
* @return Array
*/
private function resolveOrMapAttributes () {
return $this->query->get();
}
/**
* To find the alias
* of the column and
* by taking the column
* name.
* @return string
*/
public function findAlias($column_alias) {
foreach($this->columns as $column) {
if($column->alias == $column_alias) {
return $column->name;
}
}
}
/**
* Parse the URL
* and get it ready
* to be used.
*
* @return String
*/
private function parse()
{
$parsed = [];
$unparsed = url()->full();
if (count(explode('?', $unparsed))>1) {
$to_be_parsed = explode('?', $unparsed)[1];
parse_str($to_be_parsed, $parsed);
unset($parsed['page']);
return $parsed;
} else {
return $parsed;
}
}
/**
* Getting all attributes from the repository instance
* type hinted in the contructor of product grid.
*
* @return $this
*/
public function getAttributes() {
return $this->attributes->all();
}
public function filterProductByAttributes($attributes) {
foreach($attributes as $key => $value) {
$filterAlias = 'filter_' . $attribute->code;
$qb->leftJoin('product_attribute_values as ' . $filterAlias, 'products.id', '=', $filterAlias . '.product_id');
$qb->where($filterAlias . '.' . ProductAttributeValue::$attributeTypeFields[$attribute->type], 'Product Name');
}
}
/**
* ->join('contacts', 'users.id', '=', 'contacts.user_id')
* @return $this->query
*/
private function getQueryWithJoin()
{
foreach ($this->join as $join) {
// if(array_key_exists('withAttributes',$join)) {
// $qb = $this->query;
// $channel = $this->channel;
// $locale = $this->locale;
// foreach ($this->attributeColumns as $code) {
// $attribute = $this->attributes->findOneByField('code', $code);
// $productValueAlias = 'pav' . $attribute->code;
// array_push($this->attributeAliases, $productValueAlias);
// $qb->leftJoin('product_attribute_values as ' . $productValueAlias, function ($leftJoin) use ($channel, $locale, $attribute, $productValueAlias) {
// $leftJoin->on('prods.id', $productValueAlias . '.product_id');
// if ($attribute->value_per_channel) {
// if ($attribute->value_per_locale) {
// $leftJoin->where($productValueAlias . '.channel', $channel)->where($productValueAlias . '.locale', $locale);
// } else {
// $leftJoin->where($productValueAlias . '.channel', $channel);
// }
// } else {
// if ($attribute->value_per_locale) {
// $leftJoin->where($productValueAlias . '.locale', $locale);
// }
// }
// $leftJoin->where($productValueAlias . '.attribute_id', $attribute->id);
// });
// $qb->addSelect($productValueAlias . '.' . ProductAttributeValue::$attributeTypeFields[$attribute->type] . ' as ' . $code);
// }
// }
// else
if(array_key_exists('withAttributes', $join)) {
$this->query->{$join['join']}($join['table'], $join['primaryKey'], $join['condition'], $join['secondaryKey'])->where('attribute_id','=',2)->addSelect('name as product_name');
}
else
$this->query->{$join['join']}($join['table'], $join['primaryKey'], $join['condition'], $join['secondaryKey']);
}
// dd($this->query->toSql());
$this->query->get();
}
/**
* Use this function
* when taking filters
* on columns while
* fetching columns
*
* @return array
*/
private function getQueryWithColumnFilters()
{
foreach ($this->columns as $column) {
if ($column->filter) { // if the filter bag in array exists then these will be applied.
if (count($column->filter['condition']) == count($column->filter['condition'], COUNT_RECURSIVE)) {
$this->query->{$column->filter['function']}(...$column->filter['condition']);
} else {
if (count($column->filter['condition']) == 3) {
$this->query->{$column->filter['function']}(
extract(
array_combine(
// ['key', 'condition', 'value'],
array_fill( //will work with all kind of where conditions
0,
(count($column->filter['condition']) - 1),
'array_fill_nikhil'.time()
),
$column->filter['condition']
)
)
);
}
}
}
}
}
/**
* Function runs when
* filters, sort, search
* any of it is applied
* @return $this->query
*/
private function getQueryWithFilters()
{
$parsed = $this->parse();
if ($this->aliased) { //aliasing is expected in this case or it will be changed to presence of join bag
foreach ($parsed as $key=>$value) {
if ($key=="sort") {
//resolve the case with the column helper class
if(substr_count($key,'_') >= 1)
$column_name = $this->findAlias($key);
//case that don't need any resolving
$count_keys = count(array_keys($value));
if ($count_keys==1) {
$this->query->orderBy(
str_replace('_', '.', array_keys($value)[0]),
array_values($value)[0]
);
} else {
throw new \Exception('Multiple Sort keys Found, Please Resolve the URL Manually.');
}
} elseif ($key=="search") {
$count_keys = count(array_keys($value));
if($count_keys==1)
$this->query->where(function ($query) use ($parsed) {
foreach ($this->searchable as $search) {
$query->orWhere($search['column'], 'like', '%'.$parsed['search']['all'].'%');
}
});
} else {
$column_name = $this->findAlias($key);
if (array_keys($value)[0]=="like" || array_keys($value)[0]=="nlike") {
foreach ($value as $condition => $filter_value) {
$this->query->where(
$column_name,
$this->operators[$condition],
'%'.$filter_value.'%'
);
}
} else {
foreach ($value as $condition => $filter_value) {
$this->query->where(
$column_name,
$this->operators[$condition],
$filter_value
);
}
}
}
}
} else {
//this is the case for the non aliasing.
foreach ($parsed as $key=>$value) {
if ($key=="sort") {
//case that don't need any resolving
$count_keys = count(array_keys($value));
if ($count_keys==1) {
$this->query->orderBy(
array_keys($value)[0],
array_values($value)[0]
);
} else {
throw new \Exception('Multiple Sort keys Found, Please Resolve the URL Manually.');
}
} elseif ($key=="search") {
$count_keys = count(array_keys($value));
if($count_keys==1)
$this->query->where(function ($query) use ($parsed) {
foreach ($this->searchable as $search) {
$query->orWhere($search['column'], 'like', '%'.$parsed['search']['all'].'%');
}
});
else
throw new \Exception('Multiple Search keys Found, Please Resolve the URL Manually.');
} else {
// $column_name = $key;
$column_name = $this->findAlias($key);
if (array_keys($value)[0]=="like" || array_keys($value)[0]=="nlike") {
foreach ($value as $condition => $filter_value) {
$this->query->where(
$column_name,
$this->operators[$condition],
'%'.$filter_value.'%'
);
}
} else {
foreach ($value as $condition => $filter_value) {
$this->query->where(
$column_name,
$this->operators[$condition],
$filter_value
);
}
}
}
}
}
}
private function getDbQueryResults()
{
$parsed = $this->parse();
if ($this->aliased==true) {
//flags
$table_alias = false;
$join_table_alias = false;
$allowed_joins = false;
$other_joins = false;
$join_good = false;
//prepare query object
$this->query = DB::table($this->table);
//explode if alias is available
if (strpos('.', $this->table)) {
throw new \Exception("Dot(s) cannot be used in table names in Database.");
} else {
$exploded = explode('as', $this->table);
}
//check whether exploded string still has same table name
if ($exploded[0]==$this->table) {
$table_alias = false;
} else { // (isset($exploded))
$table_alias = true;
$table_name = trim($exploded[0]);
$table_alias = trim($exploded[1]);
}
//Run this if there are any selects priorly.
if (!empty($this->select)) {
$this->getSelect();
}
//Run this if there are joins
if (!empty($this->join)) {
foreach ($this->join as $index => $join) {
$name = strtolower($join['join']);
//Allow joins i.e left or right
if ($name=='leftjoin' || $name=='rightjoin') {
//check if the aliasing on the primary table and primaryKey in join is also the same
$primary_key_alias = trim(explode('.', $join['primaryKey'])[0]);
if ($primary_key_alias == $table_alias) {
$join_table_alias = explode('as', $join['table']);
if (isset($join_table_alias)) {
$alias1 = trim($join_table_alias[1]); //important!!!!!
//check if the secondary table match column is not having '.' and has proper alias
$secondary_join_column = $join['secondaryKey'];
if (isset($secondary_join_column)) {
$exploded_secondary = explode('.', $secondary_join_column);
$alias2 = trim($exploded_secondary[0]);
if ($alias1 == $alias2) {
if($index==count($this->join)-1)
$this->getQueryWithJoin();
$alias_proper_secondary = true;
} else {
throw new \Exception('Aliases of Join table and the secondary key columns do not match.');
}
} else {
throw new \Exception('Improper aliasing on secondary/join column for join.');
}
} else {
throw new \Exception('Join/Secondary table alias is not found for join.');
}
} else {
throw new \Exception('Primary key and primary table aliases do not match for join.');
}
} else {
$other_joins = true;
throw new \Exception('Please check if there is some fault in your aliasing and do not use as in column names or you might have been using a join that is not allowed i.e cross, inner, etc use left and right join only.');
}
}
}
//Check for column filter bags and resolve aliasing
$this->getQueryWithColumnFilters();
if (!empty($parsed)) {
$this->getQueryWithFilters();
}
$this->results = $this->query->paginate($this->perpage)->appends(request()->input());
return $this->results;
} else {
$this->query = DB::table($this->table);
$this->getSelect();
$this->getQueryWithColumnFilters();
if (!empty($parsed)) {
$this->getQueryWithFilters();
}
$this->results = $this->query->distinct()->paginate($this->perpage)->appends(request()->input());
return $this->results;
}
}
/**
* Main Render Function,
* it renders views responsible
* for loading datagrid.
*
* @return view
*/
public function render()
{
$this->allAttributes = $this->getAttributes();
$this->getDbQueryResults();
// dd($this->results);
return view('ui::datagrid.index', [
'css' => $this->css,
'results' => $this->results,
'columns' => $this->columns,
'attribute_columns' => $this->attributeColumns,
'attributeAliases' => $this->attributeAliases,
'filterable' =>$this->filterable,
'operators' => $this->operators,
'massoperations' => $this->massoperations,
'actions' => $this->actions,
]);
}
}

View File

@ -133,6 +133,140 @@
height: 32px;
}
body {
margin: 0;
padding: 0;
font-weight: 500;
max-width: 100%;
width: auto;
color: #242424;
font-size: 16px;
}
* {
font-family: "Montserrat", sans-serif;
}
*::-webkit-input-placeholder {
font-family: "Montserrat", sans-serif;
}
*::-webkit-input-placeholder {
font-family: "Montserrat", sans-serif;
}
.btn.btn-primary {
border-radius: 0px;
}
.mb-10 {
margin-bottom: 10px;
}
.mb-15 {
margin-bottom: 15px;
}
.mb-20 {
margin-bottom: 20px;
}
.mb-25 {
margin-bottom: 25px;
}
.mb-30 {
margin-bottom: 30px;
}
.mb-35 {
margin-bottom: 35px;
}
.mb-40 {
margin-bottom: 40px;
}
.mb-45 {
margin-bottom: 45px;
}
.mb-50 {
margin-bottom: 50px;
}
.mb-60 {
margin-bottom: 60px;
}
.mb-70 {
margin-bottom: 70px;
}
.mb-80 {
margin-bottom: 80px;
}
.mb-90 {
margin-bottom: 90px;
}
.mt-5 {
margin-top: 5px;
}
.mt-10 {
margin-top: 10px;
}
.mt-15 {
margin-top: 15px;
}
.mt-20 {
margin-top: 20px;
}
.mt-25 {
margin-top: 25px;
}
.mt-30 {
margin-top: 30px;
}
.mt-35 {
margin-top: 35px;
}
.mt-40 {
margin-top: 40px;
}
.mt-45 {
margin-top: 45px;
}
.mt-50 {
margin-top: 50px;
}
.mt-60 {
margin-top: 60px;
}
.mt-70 {
margin-top: 70px;
}
.mt-80 {
margin-top: 80px;
}
.mt-90 {
margin-top: 90px;
}
.add-to-wishlist .wishlist-icon:hover {
background-image: url("../images/wishadd.svg");
}
@ -254,132 +388,6 @@
width: 100%;
}
body {
margin: 0;
padding: 0;
font-weight: 500;
max-width: 100%;
width: auto;
color: #242424;
font-size: 16px;
}
* {
font-family: "Montserrat", sans-serif;
}
.btn.btn-primary {
border-radius: 0px;
}
.mb-10 {
margin-bottom: 10px;
}
.mb-15 {
margin-bottom: 15px;
}
.mb-20 {
margin-bottom: 20px;
}
.mb-25 {
margin-bottom: 25px;
}
.mb-30 {
margin-bottom: 30px;
}
.mb-35 {
margin-bottom: 35px;
}
.mb-40 {
margin-bottom: 40px;
}
.mb-45 {
margin-bottom: 45px;
}
.mb-50 {
margin-bottom: 50px;
}
.mb-60 {
margin-bottom: 60px;
}
.mb-70 {
margin-bottom: 70px;
}
.mb-80 {
margin-bottom: 80px;
}
.mb-90 {
margin-bottom: 90px;
}
.mt-5 {
margin-top: 5px;
}
.mt-10 {
margin-top: 10px;
}
.mt-15 {
margin-top: 15px;
}
.mt-20 {
margin-top: 20px;
}
.mt-25 {
margin-top: 25px;
}
.mt-30 {
margin-top: 30px;
}
.mt-35 {
margin-top: 35px;
}
.mt-40 {
margin-top: 40px;
}
.mt-45 {
margin-top: 45px;
}
.mt-50 {
margin-top: 50px;
}
.mt-60 {
margin-top: 60px;
}
.mt-70 {
margin-top: 70px;
}
.mt-80 {
margin-top: 80px;
}
.mt-90 {
margin-top: 90px;
}
.main-container-wrapper {
max-width: 1300px;
width: auto;
@ -484,6 +492,7 @@ body {
.main-container-wrapper .product-card .cart-wish-wrap .addtocart {
margin-right: 10px;
text-transform: uppercase;
text-align: left;
}
.main-container-wrapper .product-card .cart-wish-wrap .add-to-wishlist {

File diff suppressed because one or more lines are too long