diff --git a/packages/Webkul/Admin/src/DataGrids/AddressDataGrid.php b/packages/Webkul/Admin/src/DataGrids/AddressDataGrid.php index d657c6202..f2e78df56 100644 --- a/packages/Webkul/Admin/src/DataGrids/AddressDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/AddressDataGrid.php @@ -2,10 +2,10 @@ namespace Webkul\Admin\DataGrids; -use Webkul\Ui\DataGrid\DataGrid; use Illuminate\Support\Facades\DB; use Webkul\Customer\Models\CustomerAddress; use Webkul\Customer\Repositories\CustomerRepository; +use Webkul\Ui\DataGrid\DataGrid; use Webkul\Ui\DataGrid\Traits\ProvideDataGridPlus; class AddressDataGrid extends DataGrid @@ -27,16 +27,16 @@ class AddressDataGrid extends DataGrid protected $sortOrder = 'desc'; /** - * CustomerRepository $customerRepository + * Customer repository instance. * - * @var object + * @var \Webkul\Customer\Repositories\CustomerRepository */ protected $customerRepository; /** * Create a new datagrid instance. * - * @param Webkul\Customer\Repositories\CustomerRepository $customerRepository + * @param \Webkul\Customer\Repositories\CustomerRepository $customerRepository * @return void */ public function __construct(CustomerRepository $customerRepository) @@ -148,8 +148,7 @@ class AddressDataGrid extends DataGrid 'type' => 'boolean', 'sortable' => true, 'searchable' => false, - 'closure' => true, - 'wrapper' => function ($row) { + 'closure' => function ($row) { if ($row->default_address == 1) { return '' . trans('admin::app.customers.addresses.yes') . ''; } else { diff --git a/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php b/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php index 9628508f3..bccf9960d 100755 --- a/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php @@ -7,10 +7,25 @@ use Webkul\Ui\DataGrid\DataGrid; class AttributeDataGrid extends DataGrid { + /** + * Set index columns, ex: id. + * + * @var string + */ protected $index = 'id'; + /** + * Default sort order of datagrid. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('attributes') @@ -24,6 +39,11 @@ class AttributeDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -68,7 +88,7 @@ class AttributeDataGrid extends DataGrid 'type' => 'boolean', 'sortable' => true, 'searchable' => false, - 'wrapper' => function($value) { + 'closure' => function ($value) { if ($value->is_required == 1) { return trans('admin::app.datagrid.true'); } else { @@ -84,7 +104,7 @@ class AttributeDataGrid extends DataGrid 'sortable' => true, 'searchable' => false, 'filterable' => true, - 'wrapper' => function($value) { + 'closure' => function ($value) { if ($value->is_unique == 1) { return trans('admin::app.datagrid.true'); } else { @@ -100,7 +120,7 @@ class AttributeDataGrid extends DataGrid 'sortable' => true, 'searchable' => false, 'filterable' => true, - 'wrapper' => function($value) { + 'closure' => function ($value) { if ($value->value_per_locale == 1) { return trans('admin::app.datagrid.true'); } else { @@ -116,7 +136,7 @@ class AttributeDataGrid extends DataGrid 'sortable' => true, 'searchable' => false, 'filterable' => true, - 'wrapper' => function($value) { + 'closure' => function ($value) { if ($value->value_per_channel == 1) { return trans('admin::app.datagrid.true'); } else { @@ -126,6 +146,11 @@ class AttributeDataGrid extends DataGrid ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ @@ -143,6 +168,11 @@ class AttributeDataGrid extends DataGrid ]); } + /** + * Prepare mass actions. + * + * @return void + */ public function prepareMassActions() { $this->addMassAction([ diff --git a/packages/Webkul/Admin/src/DataGrids/CampaignDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CampaignDataGrid.php index 2cfae4e31..aec8098d3 100755 --- a/packages/Webkul/Admin/src/DataGrids/CampaignDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CampaignDataGrid.php @@ -7,10 +7,25 @@ use Webkul\Ui\DataGrid\DataGrid; class CampaignDataGrid extends DataGrid { + /** + * Set index columns, ex: id. + * + * @var string + */ protected $index = 'id'; + /** + * Default sort order of datagrid. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('marketing_campaigns')->addSelect('id', 'name', 'subject', 'status'); @@ -20,6 +35,11 @@ class CampaignDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -56,7 +76,7 @@ class CampaignDataGrid extends DataGrid 'searchable' => true, 'sortable' => true, 'filterable' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { if ($value->status == 1) { return trans('admin::app.datagrid.active'); } else { @@ -66,6 +86,11 @@ class CampaignDataGrid extends DataGrid ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ @@ -83,4 +108,4 @@ class CampaignDataGrid extends DataGrid 'icon' => 'icon trash-icon', ]); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Admin/src/DataGrids/CartRuleCouponsDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CartRuleCouponsDataGrid.php index 4af55c2b2..88fb10f20 100644 --- a/packages/Webkul/Admin/src/DataGrids/CartRuleCouponsDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CartRuleCouponsDataGrid.php @@ -7,10 +7,25 @@ use Webkul\Ui\DataGrid\DataGrid; class CartRuleCouponsDataGrid extends DataGrid { + /** + * Index. + * + * @var string + */ protected $index = 'id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('cart_rules') @@ -20,6 +35,11 @@ class CartRuleCouponsDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -65,7 +85,7 @@ class CartRuleCouponsDataGrid extends DataGrid 'searchable' => false, 'sortable' => true, 'filterable' => true, - 'wrapper' => function($value) { + 'closure' => function ($value) { if ($value->end_other_rules == 1) { return trans('admin::app.datagrid.true'); } else { diff --git a/packages/Webkul/Admin/src/DataGrids/CartRuleDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CartRuleDataGrid.php index 4b9635edd..be4597ac6 100644 --- a/packages/Webkul/Admin/src/DataGrids/CartRuleDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CartRuleDataGrid.php @@ -7,20 +7,49 @@ use Illuminate\Support\Facades\DB; class CartRuleDataGrid extends DataGrid { + /** + * Set index columns, ex: id. + * + * @var string + */ protected $index = 'id'; + /** + * Default sort order of datagrid. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Customer group. + * + * @var string + */ protected $customer_group = 'all'; + /** + * Channel. + * + * @var string + */ protected $channel = 'all'; - /** @var string[] contains the keys for which extra filters to show */ + /** + * Contains the keys for which extra filters to show. + * + * @var string[] + */ protected $extraFilters = [ 'channels', 'customer_groups', ]; + /** + * Create a new datagrid instance. + * + * @return void + */ public function __construct() { parent::__construct(); @@ -30,6 +59,11 @@ class CartRuleDataGrid extends DataGrid $this->channel = core()->getRequestedChannelCode(false) ?? 'all'; } + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('cart_rules') @@ -37,8 +71,15 @@ class CartRuleDataGrid extends DataGrid $leftJoin->on('cart_rule_coupons.cart_rule_id', '=', 'cart_rules.id') ->where('cart_rule_coupons.is_primary', 1); }) - ->addSelect('cart_rules.id', 'name', 'cart_rule_coupons.code as coupon_code', - 'status', 'starts_from', 'ends_till', 'sort_order'); + ->addSelect( + 'cart_rules.id', + 'name', + 'cart_rule_coupons.code as coupon_code', + 'status', + 'starts_from', + 'ends_till', + 'sort_order' + ); $this->addFilter('id', 'cart_rules.id'); $this->addFilter('coupon_code', 'cart_rule_coupons.code'); @@ -50,6 +91,7 @@ class CartRuleDataGrid extends DataGrid '=', 'cart_rules.id' ); + $queryBuilder->where('cart_rule_customer_groups.customer_group_id', $this->customer_group); } @@ -58,7 +100,9 @@ class CartRuleDataGrid extends DataGrid 'cart_rule_channels', 'cart_rule_channels.cart_rule_id', '=', - 'cart_rules.id'); + 'cart_rules.id' + ); + $queryBuilder->where('cart_rule_channels.channel_id', $this->channel); } @@ -67,6 +111,11 @@ class CartRuleDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -121,7 +170,7 @@ class CartRuleDataGrid extends DataGrid 'searchable' => true, 'sortable' => true, 'filterable' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { if ($value->status == 1) { return trans('admin::app.datagrid.active'); } else if ($value->status == 0) { @@ -142,6 +191,11 @@ class CartRuleDataGrid extends DataGrid ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ @@ -164,6 +218,5 @@ class CartRuleDataGrid extends DataGrid 'route' => 'admin.cart-rules.delete', 'icon' => 'icon trash-icon', ]); - } } diff --git a/packages/Webkul/Admin/src/DataGrids/CatalogRuleDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CatalogRuleDataGrid.php index 4e79a0847..f2d01dd70 100644 --- a/packages/Webkul/Admin/src/DataGrids/CatalogRuleDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CatalogRuleDataGrid.php @@ -7,10 +7,25 @@ use Webkul\Ui\DataGrid\DataGrid; class CatalogRuleDataGrid extends DataGrid { + /** + * Index. + * + * @var string + */ protected $index = 'id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('catalog_rules') @@ -22,6 +37,11 @@ class CatalogRuleDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -67,7 +87,7 @@ class CatalogRuleDataGrid extends DataGrid 'searchable' => true, 'sortable' => true, 'filterable' => true, - 'wrapper' => function($value) { + 'closure' => function ($value) { if ($value->status == 1) { return trans('admin::app.datagrid.active'); } else { @@ -86,6 +106,11 @@ class CatalogRuleDataGrid extends DataGrid ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ diff --git a/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php index 26dcbeb27..95f8924bd 100755 --- a/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php @@ -8,12 +8,32 @@ use Webkul\Ui\DataGrid\DataGrid; class CategoryDataGrid extends DataGrid { + /** + * Index. + * + * @var string + */ protected $index = 'category_id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Locale. + * + * @var string + */ protected $locale = 'all'; + /** + * Create a new datagrid instance. + * + * @return void + */ public function __construct() { parent::__construct(); @@ -21,6 +41,11 @@ class CategoryDataGrid extends DataGrid $this->locale = core()->getRequestedLocaleCode(); } + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { if ($this->locale === 'all') { @@ -30,11 +55,17 @@ class CategoryDataGrid extends DataGrid } $queryBuilder = DB::table('categories as cat') - ->select('cat.id as category_id', 'ct.name', 'cat.position', 'cat.status', 'ct.locale', - DB::raw('COUNT(DISTINCT ' . DB::getTablePrefix() . 'pc.product_id) as count')) - ->leftJoin('category_translations as ct', function($leftJoin) use($whereInLocales) { + ->select( + 'cat.id as category_id', + 'ct.name', + 'cat.position', + 'cat.status', + 'ct.locale', + DB::raw('COUNT(DISTINCT ' . DB::getTablePrefix() . 'pc.product_id) as count') + ) + ->leftJoin('category_translations as ct', function ($leftJoin) use ($whereInLocales) { $leftJoin->on('cat.id', '=', 'ct.category_id') - ->whereIn('ct.locale', $whereInLocales); + ->whereIn('ct.locale', $whereInLocales); }) ->leftJoin('product_categories as pc', 'cat.id', '=', 'pc.category_id') ->groupBy('cat.id', 'ct.locale',); @@ -46,6 +77,11 @@ class CategoryDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -82,7 +118,7 @@ class CategoryDataGrid extends DataGrid 'sortable' => true, 'searchable' => true, 'filterable' => true, - 'wrapper' => function($value) { + 'closure' => function ($value) { if ($value->status == 1) { return trans('admin::app.datagrid.active'); } else { @@ -101,6 +137,11 @@ class CategoryDataGrid extends DataGrid ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ @@ -126,4 +167,4 @@ class CategoryDataGrid extends DataGrid 'method' => 'POST', ]); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php index 1e405203a..12e7d0c54 100755 --- a/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php @@ -7,13 +7,32 @@ use Webkul\Ui\DataGrid\DataGrid; class CustomerDataGrid extends DataGrid { - + /** + * Index. + * + * @var string + */ protected $index = 'customer_id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Items per page. + * + * @var int + */ protected $itemsPerPage = 10; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('customers') @@ -31,6 +50,11 @@ class CustomerDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -76,9 +100,8 @@ class CustomerDataGrid extends DataGrid 'searchable' => true, 'sortable' => true, 'filterable' => false, - 'closure' => true, - 'wrapper' => function ($row) { - if (! $row->phone) { + 'closure' => function ($row) { + if (!$row->phone) { return '-'; } else { return $row->phone; @@ -93,9 +116,8 @@ class CustomerDataGrid extends DataGrid 'searchable' => false, 'sortable' => true, 'filterable' => false, - 'closure' => true, - 'wrapper' => function ($row) { - if (! $row->gender) { + 'closure' => function ($row) { + if (!$row->gender) { return '-'; } else { return $row->gender; @@ -110,17 +132,21 @@ class CustomerDataGrid extends DataGrid 'searchable' => false, 'sortable' => true, 'filterable' => true, - 'closure' => true, - 'wrapper' => function ($row) { + 'closure' => function ($row) { if ($row->status == 1) { - return ''. trans('admin::app.customers.customers.active') .''; + return '' . trans('admin::app.customers.customers.active') . ''; } else { - return ''. trans('admin::app.customers.customers.inactive') .''; + return '' . trans('admin::app.customers.customers.inactive') . ''; } }, ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ @@ -145,6 +171,11 @@ class CustomerDataGrid extends DataGrid ]); } + /** + * Prepare mass actions. + * + * @return void + */ public function prepareMassActions() { $this->addMassAction([ @@ -165,4 +196,4 @@ class CustomerDataGrid extends DataGrid ], ]); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Admin/src/DataGrids/CustomerOrderDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CustomerOrderDataGrid.php index 739fefafe..341a120ee 100644 --- a/packages/Webkul/Admin/src/DataGrids/CustomerOrderDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CustomerOrderDataGrid.php @@ -3,31 +3,45 @@ namespace Webkul\Admin\DataGrids; use Illuminate\Support\Facades\DB; +use Webkul\Sales\Models\OrderAddress; use Webkul\Ui\DataGrid\DataGrid; use Webkul\Ui\DataGrid\Traits\ProvideDataGridPlus; -use Webkul\Sales\Models\OrderAddress; - class CustomerOrderDataGrid extends DataGrid { use ProvideDataGridPlus; + /** + * Index. + * + * @var string + */ protected $index = 'id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('orders') - ->leftJoin('addresses as order_address_shipping', function($leftJoin) { + ->leftJoin('addresses as order_address_shipping', function ($leftJoin) { $leftJoin->on('order_address_shipping.order_id', '=', 'orders.id') - ->where('order_address_shipping.address_type', OrderAddress::ADDRESS_TYPE_SHIPPING); + ->where('order_address_shipping.address_type', OrderAddress::ADDRESS_TYPE_SHIPPING); }) - ->leftJoin('addresses as order_address_billing', function($leftJoin) { + ->leftJoin('addresses as order_address_billing', function ($leftJoin) { $leftJoin->on('order_address_billing.order_id', '=', 'orders.id') - ->where('order_address_billing.address_type', OrderAddress::ADDRESS_TYPE_BILLING); + ->where('order_address_billing.address_type', OrderAddress::ADDRESS_TYPE_BILLING); }) - ->addSelect('orders.id','orders.increment_id', 'orders.base_sub_total', 'orders.base_grand_total', 'orders.created_at', 'channel_name', 'status') + ->addSelect('orders.id', 'orders.increment_id', 'orders.base_sub_total', 'orders.base_grand_total', 'orders.created_at', 'channel_name', 'status') ->addSelect(DB::raw('CONCAT(' . DB::getTablePrefix() . 'order_address_billing.first_name, " ", ' . DB::getTablePrefix() . 'order_address_billing.last_name) as billed_to')) ->addSelect(DB::raw('CONCAT(' . DB::getTablePrefix() . 'order_address_shipping.first_name, " ", ' . DB::getTablePrefix() . 'order_address_shipping.last_name) as shipped_to')) ->where('orders.customer_id', request('id')); @@ -40,6 +54,11 @@ class CustomerOrderDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -93,28 +112,32 @@ class CustomerOrderDataGrid extends DataGrid 'type' => 'string', 'sortable' => true, 'searchable' => true, - 'closure' => true, 'filterable' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { if ($value->status == 'processing') { - return ''. trans('admin::app.sales.orders.order-status-processing') .''; + return '' . trans('admin::app.sales.orders.order-status-processing') . ''; } elseif ($value->status == 'completed') { - return ''. trans('admin::app.sales.orders.order-status-success') .''; + return '' . trans('admin::app.sales.orders.order-status-success') . ''; } elseif ($value->status == "canceled") { - return ''. trans('admin::app.sales.orders.order-status-canceled') .''; + return '' . trans('admin::app.sales.orders.order-status-canceled') . ''; } elseif ($value->status == "closed") { - return ''. trans('admin::app.sales.orders.order-status-closed') .''; + return '' . trans('admin::app.sales.orders.order-status-closed') . ''; } elseif ($value->status == "pending") { - return ''. trans('admin::app.sales.orders.order-status-pending') .''; + return '' . trans('admin::app.sales.orders.order-status-pending') . ''; } elseif ($value->status == "pending_payment") { - return ''. trans('admin::app.sales.orders.order-status-pending-payment') .''; + return '' . trans('admin::app.sales.orders.order-status-pending-payment') . ''; } elseif ($value->status == "fraud") { - return ''. trans('admin::app.sales.orders.order-status-fraud') . ''; + return '' . trans('admin::app.sales.orders.order-status-fraud') . ''; } }, ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ @@ -124,4 +147,4 @@ class CustomerOrderDataGrid extends DataGrid 'icon' => 'icon eye-icon', ]); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php index 29b272abc..469eb154e 100755 --- a/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php @@ -7,10 +7,25 @@ use Webkul\Ui\DataGrid\DataGrid; class CustomerReviewDataGrid extends DataGrid { + /** + * Index. + * + * @var string + */ protected $index = 'product_review_id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('product_reviews as pr') @@ -27,6 +42,11 @@ class CustomerReviewDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -82,8 +102,7 @@ class CustomerReviewDataGrid extends DataGrid 'sortable' => true, 'width' => '100px', 'filterable' => true, - 'closure' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { if ($value->product_review_status == 'approved') { return '' . trans('admin::app.datagrid.approved') . ''; } elseif ($value->product_review_status == "pending") { @@ -104,6 +123,11 @@ class CustomerReviewDataGrid extends DataGrid ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ @@ -121,6 +145,11 @@ class CustomerReviewDataGrid extends DataGrid ]); } + /** + * Prepare mass actions. + * + * @return void + */ public function prepareMassActions() { $this->addMassAction([ @@ -142,4 +171,4 @@ class CustomerReviewDataGrid extends DataGrid ], ]); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Admin/src/DataGrids/CustomersInvoicesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CustomersInvoicesDataGrid.php index 323c870f6..ddccd391b 100644 --- a/packages/Webkul/Admin/src/DataGrids/CustomersInvoicesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CustomersInvoicesDataGrid.php @@ -84,9 +84,8 @@ class CustomersInvoicesDataGrid extends DataGrid 'type' => 'string', 'searchable' => true, 'sortable' => true, - 'closure' => true, 'filterable' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { return '' . $value->order_id . ''; } ]); @@ -106,9 +105,8 @@ class CustomersInvoicesDataGrid extends DataGrid 'type' => 'string', 'sortable' => true, 'searchable' => true, - 'closure' => true, 'filterable' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { if ($value->state == 'paid') { return '' . trans('admin::app.sales.invoices.status-paid') . ''; } elseif ($value->state == 'pending' || $value->state == 'pending_payment') { diff --git a/packages/Webkul/Admin/src/DataGrids/EmailTemplateDataGrid.php b/packages/Webkul/Admin/src/DataGrids/EmailTemplateDataGrid.php index da88abdac..9351f5e0d 100755 --- a/packages/Webkul/Admin/src/DataGrids/EmailTemplateDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/EmailTemplateDataGrid.php @@ -7,10 +7,25 @@ use Webkul\Ui\DataGrid\DataGrid; class EmailTemplateDataGrid extends DataGrid { + /** + * Index. + * + * @var string + */ protected $index = 'id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('marketing_templates')->addSelect('id', 'name', 'status'); @@ -20,6 +35,11 @@ class EmailTemplateDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -47,7 +67,7 @@ class EmailTemplateDataGrid extends DataGrid 'searchable' => true, 'sortable' => true, 'filterable' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { if ($value->status == 'active') { return trans('admin::app.datagrid.active'); } else if ($value->status == 'inactive') { @@ -59,6 +79,11 @@ class EmailTemplateDataGrid extends DataGrid ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ @@ -76,4 +101,4 @@ class EmailTemplateDataGrid extends DataGrid 'icon' => 'icon trash-icon', ]); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php index 54bb1a728..34446e92a 100755 --- a/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php @@ -7,10 +7,25 @@ use Webkul\Ui\DataGrid\DataGrid; class InventorySourcesDataGrid extends DataGrid { + /** + * Index. + * + * @var string + */ protected $index = 'id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('inventory_sources')->addSelect('id', 'code', 'name', 'priority', 'status'); @@ -20,6 +35,11 @@ class InventorySourcesDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -65,7 +85,7 @@ class InventorySourcesDataGrid extends DataGrid 'searchable' => true, 'sortable' => true, 'filterable' => true, - 'wrapper' => function($value) { + 'closure' => function ($value) { if ($value->status == 1) { return trans('admin::app.datagrid.active'); } else { @@ -75,6 +95,11 @@ class InventorySourcesDataGrid extends DataGrid ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ @@ -92,4 +117,4 @@ class InventorySourcesDataGrid extends DataGrid 'icon' => 'icon trash-icon', ]); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Admin/src/DataGrids/LocalesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/LocalesDataGrid.php index 1bd30cf7c..0e54b0929 100755 --- a/packages/Webkul/Admin/src/DataGrids/LocalesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/LocalesDataGrid.php @@ -7,10 +7,25 @@ use Webkul\Ui\DataGrid\DataGrid; class LocalesDataGrid extends DataGrid { + /** + * Index. + * + * @var string + */ protected $index = 'id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('locales')->addSelect('id', 'code', 'name', 'direction'); @@ -18,6 +33,11 @@ class LocalesDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -54,8 +74,7 @@ class LocalesDataGrid extends DataGrid 'searchable' => true, 'sortable' => true, 'filterable' => true, - 'closure' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { if ($value->direction == 'ltr') { return trans('admin::app.datagrid.ltr'); } else { @@ -65,6 +84,11 @@ class LocalesDataGrid extends DataGrid ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ @@ -82,4 +106,4 @@ class LocalesDataGrid extends DataGrid 'icon' => 'icon trash-icon', ]); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php b/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php index def361a01..538a768c1 100755 --- a/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php @@ -7,14 +7,27 @@ use Webkul\Ui\DataGrid\DataGrid; class NewsLetterDataGrid extends DataGrid { + /** + * Index. + * + * @var string + */ protected $index = 'id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { - - $queryBuilder = DB::table('subscribers_list')->select('subscribers_list.id', 'subscribers_list.is_subscribed as status', 'subscribers_list.email'); $this->addFilter('status', 'subscribers_list.is_subscribed'); @@ -22,6 +35,11 @@ class NewsLetterDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -40,7 +58,7 @@ class NewsLetterDataGrid extends DataGrid 'searchable' => true, 'sortable' => true, 'filterable' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { if ($value->status === 1) { return trans('admin::app.datagrid.true'); } else { @@ -59,6 +77,11 @@ class NewsLetterDataGrid extends DataGrid ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ @@ -76,4 +99,4 @@ class NewsLetterDataGrid extends DataGrid 'icon' => 'icon trash-icon', ]); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php b/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php index 252dc67cd..e3c25288b 100755 --- a/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php @@ -11,10 +11,25 @@ class OrderDataGrid extends DataGrid { use ProvideDataGridPlus; + /** + * Index. + * + * @var string + */ protected $index = 'id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('orders') @@ -38,6 +53,11 @@ class OrderDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -91,9 +111,8 @@ class OrderDataGrid extends DataGrid 'type' => 'string', 'sortable' => true, 'searchable' => true, - 'closure' => true, 'filterable' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { if ($value->status == 'processing') { return '' . trans('admin::app.sales.orders.order-status-processing') . ''; } elseif ($value->status == 'completed') { @@ -131,6 +150,11 @@ class OrderDataGrid extends DataGrid ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ diff --git a/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php index 86c27f85a..86a8859f3 100755 --- a/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php @@ -7,10 +7,25 @@ use Webkul\Ui\DataGrid\DataGrid; class OrderInvoicesDataGrid extends DataGrid { + /** + * Index. + * + * @var string + */ protected $index = 'id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $dbPrefix = DB::getTablePrefix(); @@ -28,6 +43,11 @@ class OrderInvoicesDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -72,9 +92,8 @@ class OrderInvoicesDataGrid extends DataGrid 'type' => 'string', 'sortable' => true, 'searchable' => true, - 'closure' => true, 'filterable' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { if ($value->state == 'paid') { return '' . trans('admin::app.sales.invoices.status-paid') . ''; } elseif ($value->state == 'pending' || $value->state == 'pending_payment') { @@ -86,9 +105,13 @@ class OrderInvoicesDataGrid extends DataGrid } }, ]); - } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ @@ -98,4 +121,4 @@ class OrderInvoicesDataGrid extends DataGrid 'icon' => 'icon eye-icon', ]); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php b/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php index 6eb0a77f6..bdbeeceb8 100644 --- a/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/ProductDataGrid.php @@ -222,7 +222,7 @@ class ProductDataGrid extends DataGrid 'sortable' => true, 'searchable' => false, 'filterable' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { if ($value->status == 1) { return trans('admin::app.datagrid.active'); } else { @@ -247,8 +247,7 @@ class ProductDataGrid extends DataGrid 'sortable' => true, 'searchable' => false, 'filterable' => false, - 'closure' => true, - 'wrapper' => function ($row) { + 'closure' => function ($row) { if (is_null($row->quantity)) { return 0; } else { diff --git a/packages/Webkul/Admin/src/DataGrids/TaxRateDataGrid.php b/packages/Webkul/Admin/src/DataGrids/TaxRateDataGrid.php index daac5a7f9..2cbfeae6c 100755 --- a/packages/Webkul/Admin/src/DataGrids/TaxRateDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/TaxRateDataGrid.php @@ -7,10 +7,25 @@ use Webkul\Ui\DataGrid\DataGrid; class TaxRateDataGrid extends DataGrid { + /** + * Index. + * + * @var string + */ protected $index = 'id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('tax_rates')->addSelect('id', 'identifier', 'state', 'country', 'zip_code', 'zip_from', 'zip_to', 'tax_rate'); @@ -18,6 +33,11 @@ class TaxRateDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -45,7 +65,7 @@ class TaxRateDataGrid extends DataGrid 'searchable' => true, 'sortable' => true, 'filterable' => true, - 'wrapper' => function($value) { + 'closure' => function ($value) { if (empty($value->state)) { return '*'; } else { @@ -100,6 +120,11 @@ class TaxRateDataGrid extends DataGrid ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ @@ -116,4 +141,4 @@ class TaxRateDataGrid extends DataGrid 'icon' => 'icon trash-icon', ]); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php b/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php index 59b4f57ff..b138fda91 100755 --- a/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php @@ -7,10 +7,25 @@ use Webkul\Ui\DataGrid\DataGrid; class UserDataGrid extends DataGrid { + /** + * Index. + * + * @var string + */ protected $index = 'user_id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('admins as u') @@ -25,6 +40,11 @@ class UserDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -52,7 +72,7 @@ class UserDataGrid extends DataGrid 'searchable' => true, 'sortable' => true, 'filterable' => true, - 'wrapper' => function($value) { + 'closure' => function ($value) { if ($value->status == 1) { return trans('admin::app.datagrid.active'); } else { @@ -80,6 +100,11 @@ class UserDataGrid extends DataGrid ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ @@ -96,4 +121,4 @@ class UserDataGrid extends DataGrid 'icon' => 'icon trash-icon', ]); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Shop/src/DataGrids/DownloadableProductDataGrid.php b/packages/Webkul/Shop/src/DataGrids/DownloadableProductDataGrid.php index 4fcd54e08..f669025e9 100644 --- a/packages/Webkul/Shop/src/DataGrids/DownloadableProductDataGrid.php +++ b/packages/Webkul/Shop/src/DataGrids/DownloadableProductDataGrid.php @@ -7,10 +7,25 @@ use Webkul\Ui\DataGrid\DataGrid; class DownloadableProductDataGrid extends DataGrid { + /** + * Index. + * + * @var string + */ protected $index = 'id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('downloadable_link_purchased') @@ -28,6 +43,11 @@ class DownloadableProductDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -46,8 +66,7 @@ class DownloadableProductDataGrid extends DataGrid 'searchable' => true, 'sortable' => true, 'filterable' => true, - 'closure' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { if ($value->status == 'pending' || $value->status == 'expired' || $value->invoice_state !== 'paid') { return $value->product_name; } else { @@ -72,8 +91,7 @@ class DownloadableProductDataGrid extends DataGrid 'searchable' => false, 'sortable' => true, 'filterable' => true, - 'closure' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { if ($value->status == 'pending') { return trans('shop::app.customer.account.downloadable_products.pending'); } elseif ($value->status == 'available') { @@ -91,9 +109,8 @@ class DownloadableProductDataGrid extends DataGrid 'searchable' => false, 'sortable' => true, 'filterable' => false, - 'closure' => true, - 'wrapper' => function ($value) { - if (! $value->download_bought) { + 'closure' => function ($value) { + if (!$value->download_bought) { return trans('shop::app.customer.account.downloadable_products.unlimited'); } @@ -101,4 +118,4 @@ class DownloadableProductDataGrid extends DataGrid }, ]); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Shop/src/DataGrids/OrderDataGrid.php b/packages/Webkul/Shop/src/DataGrids/OrderDataGrid.php index f656d9535..fdbd04228 100644 --- a/packages/Webkul/Shop/src/DataGrids/OrderDataGrid.php +++ b/packages/Webkul/Shop/src/DataGrids/OrderDataGrid.php @@ -7,10 +7,25 @@ use Illuminate\Support\Facades\DB; class OrderDataGrid extends DataGrid { + /** + * Index. + * + * @var string + */ protected $index = 'id'; + /** + * Sort order. + * + * @var string + */ protected $sortOrder = 'desc'; + /** + * Prepare query builder. + * + * @return void + */ public function prepareQueryBuilder() { $queryBuilder = DB::table('orders as order') @@ -20,6 +35,11 @@ class OrderDataGrid extends DataGrid $this->setQueryBuilder($queryBuilder); } + /** + * Add columns. + * + * @return void + */ public function addColumns() { $this->addColumn([ @@ -47,7 +67,7 @@ class OrderDataGrid extends DataGrid 'searchable' => true, 'sortable' => true, 'filterable' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { return core()->formatPrice($value->grand_total, $value->order_currency_code); }, ]); @@ -58,8 +78,7 @@ class OrderDataGrid extends DataGrid 'type' => 'string', 'searchable' => false, 'sortable' => true, - 'closure' => true, - 'wrapper' => function ($value) { + 'closure' => function ($value) { if ($value->status == 'processing') { return '' . trans('shop::app.customer.account.order.index.processing') . ''; } elseif ($value->status == 'completed') { @@ -80,6 +99,11 @@ class OrderDataGrid extends DataGrid ]); } + /** + * Prepare actions. + * + * @return void + */ public function prepareActions() { $this->addAction([ diff --git a/packages/Webkul/Ui/src/DataGrid/DataGrid.php b/packages/Webkul/Ui/src/DataGrid/DataGrid.php index 99f98857c..5e74c4308 100644 --- a/packages/Webkul/Ui/src/DataGrid/DataGrid.php +++ b/packages/Webkul/Ui/src/DataGrid/DataGrid.php @@ -15,7 +15,7 @@ abstract class DataGrid /** * Set index columns, ex: id. * - * @var int + * @var string */ protected $index; @@ -232,8 +232,7 @@ abstract class DataGrid /** * Add column. * - * @param string $column - * + * @param array $column * @return void */ public function addColumn($column) @@ -252,8 +251,7 @@ abstract class DataGrid /** * Set complete column details. * - * @param string $column - * + * @param array $column * @return void */ public function setCompleteColumnDetails($column) @@ -264,8 +262,7 @@ abstract class DataGrid /** * Set query builder. * - * @param \Illuminate\Database\Query\Builder $queryBuilder - * + * @param \Illuminate\Database\Query\Builder $queryBuilder * @return void */ public function setQueryBuilder($queryBuilder) diff --git a/packages/Webkul/Ui/src/DataGrid/Traits/ProvideCollection.php b/packages/Webkul/Ui/src/DataGrid/Traits/ProvideCollection.php index 9a3b1d605..fd3a63d6c 100644 --- a/packages/Webkul/Ui/src/DataGrid/Traits/ProvideCollection.php +++ b/packages/Webkul/Ui/src/DataGrid/Traits/ProvideCollection.php @@ -218,17 +218,30 @@ trait ProvideCollection /** * Transform your columns. * - * @parma object $record + * @param object $record * @return void */ private function transformColumns($record) { foreach($this->columns as $column) { - if (isset($column['wrapper'])) { - if (isset($column['closure']) && $column['closure'] == true) { - $record->{$column['index']} = $column['wrapper']($record); - } else { - $record->{$column['index']} = htmlspecialchars($column['wrapper']($record)); + $supportedClosureKey = ['wrapper', 'closure']; + + $isClosure = ! empty(array_intersect($supportedClosureKey, array_keys($column))); + + if ($isClosure) { + /** + * @deprecated $column['wrapper'] + * + * Use $column['closure'] instead. `wrapper` key will get removed in the later version. + */ + if (isset($column['wrapper']) && gettype($column['wrapper']) === 'object' && $column['wrapper'] instanceof \Closure) { + if (isset($column['closure']) && $column['closure'] == true) { + $record->{$column['index']} = $column['wrapper']($record); + } else { + $record->{$column['index']} = htmlspecialchars($column['wrapper']($record)); + } + } else if (isset($column['closure']) && gettype($column['closure']) === 'object' && $column['closure'] instanceof \Closure) { + $record->{$column['index']} = $column['closure']($record); } } else { if ($column['type'] == 'price') { @@ -237,6 +250,8 @@ trait ProvideCollection } else { $record->{$column['index']} = htmlspecialchars(core()->formatBasePrice($record->{$column['index']})); } + } else { + $record->{$column['index']} = htmlspecialchars($record->{$column['index']}); } } } diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/body.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/body.blade.php index 90652ea95..5030db55f 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/body.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/body.blade.php @@ -17,13 +17,26 @@ $columnIndex = explode('.', $column['index']); $columnIndex = end($columnIndex); + + $supportedClosureKey = ['wrapper', 'closure']; + + $isClosure = ! empty(array_intersect($supportedClosureKey, array_keys($column))); @endphp - @if (isset($column['wrapper'])) - @if (isset($column['closure']) && $column['closure'] == true) -