diff --git a/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php index 686a82463..4f666f839 100644 --- a/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php @@ -7,7 +7,7 @@ @section('content')
get('locale') ?: app()->getLocale(); ?> - get('channel') ?: core()->getCurrentChannelCode(); ?> + get('channel') ?: core()->getDefaultChannelCode(); ?>
diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index f6a95a0e1..bf2d7132b 100644 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -237,10 +237,10 @@ class Cart { { $cart = null; - if(session()->has('cart')) { - $cart = $this->cart->find(session()->get('cart')->id); - } else if(auth()->guard('customer')->check()) { + if(auth()->guard('customer')->check()) { $cart = $this->cart->findOneByField('customer_id', auth()->guard('customer')->user()->id); + } elseif(session()->has('cart')) { + $cart = $this->cart->find(session()->get('cart')->id); } return $cart && $cart->is_active ? $cart : null; @@ -460,9 +460,7 @@ class Cart { */ public function removeItem($itemId) { - if(session()->has('cart')) { - $cart = $this->getCart(); - + if($cart = $this->getCart()) { $items = $cart->items; foreach($items as $item) { diff --git a/packages/Webkul/Checkout/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php index 897b98c4a..57c9a8de5 100644 --- a/packages/Webkul/Checkout/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php +++ b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php @@ -48,7 +48,7 @@ class CreateCartItemsTable extends Migration $table->json('additional')->nullable(); $table->integer('product_id')->unsigned(); - $table->foreign('product_id')->references('id')->on('products'); + $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade'); $table->integer('cart_id')->unsigned(); $table->foreign('cart_id')->references('id')->on('cart')->onDelete('cascade'); $table->integer('tax_category_id')->unsigned()->nullable(); diff --git a/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_092845_create_cart_address.php b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_092845_create_cart_address.php index 1e5f9f6c6..b0825103a 100644 --- a/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_092845_create_cart_address.php +++ b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_092845_create_cart_address.php @@ -29,7 +29,7 @@ class CreateCartAddress extends Migration $table->integer('cart_id')->nullable()->unsigned(); $table->foreign('cart_id')->references('id')->on('cart')->onDelete('cascade'); $table->integer('customer_id')->nullable()->unsigned(); - $table->foreign('customer_id')->references('id')->on('customers'); + $table->foreign('customer_id')->references('id')->on('customers')->onDelete('cascade'); $table->timestamps(); }); } diff --git a/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_093453_create_cart_payment.php b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_093453_create_cart_payment.php index 89ab7fd4d..5a175add1 100644 --- a/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_093453_create_cart_payment.php +++ b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_093453_create_cart_payment.php @@ -18,7 +18,7 @@ class CreateCartPayment extends Migration $table->string('method'); $table->string('method_title')->nullable(); $table->integer('cart_id')->nullable()->unsigned(); - $table->foreign('cart_id')->references('id')->on('cart'); + $table->foreign('cart_id')->references('id')->on('cart')->onDelete('cascade'); $table->timestamps(); }); } diff --git a/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_093508_create_cart_shipping_rates_table.php b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_093508_create_cart_shipping_rates_table.php index 2565b846d..9588f961b 100644 --- a/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_093508_create_cart_shipping_rates_table.php +++ b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_093508_create_cart_shipping_rates_table.php @@ -23,7 +23,7 @@ class CreateCartShippingRatesTable extends Migration $table->double('price')->default(0)->nullable(); $table->double('base_price')->default(0)->nullable(); $table->integer('cart_address_id')->nullable()->unsigned(); - $table->foreign('cart_address_id')->references('id')->on('cart_address'); + $table->foreign('cart_address_id')->references('id')->on('cart_address')->onDelete('cascade'); $table->timestamps(); }); } diff --git a/packages/Webkul/Core/src/Core.php b/packages/Webkul/Core/src/Core.php index 716f842df..7d84c73f9 100644 --- a/packages/Webkul/Core/src/Core.php +++ b/packages/Webkul/Core/src/Core.php @@ -84,6 +84,34 @@ class Core return ($channel = $this->getCurrentChannel()) ? $channelCode = $channel->code : ''; } + /** + * Returns default channel models + * + * @return mixed + */ + public function getDefaultChannel() { + static $channel; + + if($channel) + return $channel; + + return $channel = ChannelModel::first(); + } + + /** + * Returns default channel code + * + * @return string + */ + public function getDefaultChannelCode() { + static $channelCode; + + if($channelCode) + return $channelCode; + + return ($channel = $this->getDefaultChannel()) ? $channelCode = $channel->code : ''; + } + /** * Returns all locales * diff --git a/packages/Webkul/Core/src/Http/Controllers/TaxCategoryController.php b/packages/Webkul/Core/src/Http/Controllers/TaxCategoryController.php index 5bc939083..3aff35c82 100644 --- a/packages/Webkul/Core/src/Http/Controllers/TaxCategoryController.php +++ b/packages/Webkul/Core/src/Http/Controllers/TaxCategoryController.php @@ -24,14 +24,6 @@ class TaxCategoryController extends Controller */ protected $_config; - /** - * Contains the current - * channel. - * - * @var string - */ - protected $currentChannelId; - /** * Tax Rule Repository object * @@ -49,8 +41,6 @@ class TaxCategoryController extends Controller { $this->middleware('admin'); - $this->currentChannelId = core()->getCurrentChannel()->id; - $this->taxRule = $taxRule; $this->taxRate = $taxRate; diff --git a/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php b/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php index 306b40d0e..262ee3e9e 100644 --- a/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php @@ -47,7 +47,10 @@ class WishlistController extends Controller * Displays the listing resources if the customer having items in wishlist. */ public function index() { - $wishlists = $this->wishlist->findWhere(['channel_id' => core()->getCurrentChannel()->id,'customer_id' => auth()->guard('customer')->user()->id]); + $wishlists = $this->wishlist->findWhere([ + 'channel_id' => core()->getCurrentChannel()->id, + 'customer_id' => auth()->guard('customer')->user()->id] + ); $wishlistItems = array(); diff --git a/packages/Webkul/Product/src/Models/Product.php b/packages/Webkul/Product/src/Models/Product.php index b6a910fd5..b1d8bd1e4 100644 --- a/packages/Webkul/Product/src/Models/Product.php +++ b/packages/Webkul/Product/src/Models/Product.php @@ -186,7 +186,7 @@ class Product extends Model $attributeModel = $this->attribute_family->custom_attributes()->where('attributes.code', $key)->first(); if($attributeModel) { - $channel = request()->get('channel') ?: core()->getCurrentChannelCode(); + $channel = request()->get('channel') ?: core()->getDefaultChannelCode(); $locale = request()->get('locale') ?: app()->getLocale(); @@ -225,7 +225,7 @@ class Product extends Model $hiddenAttributes = $this->getHidden(); if(isset($this->id)) { - $channel = request()->get('channel') ?: core()->getCurrentChannelCode(); + $channel = request()->get('channel') ?: core()->getDefaultChannelCode(); $locale = request()->get('locale') ?: app()->getLocale(); diff --git a/packages/Webkul/Product/src/Product/Review.php b/packages/Webkul/Product/src/Product/Review.php index a092ec606..dd14117fd 100644 --- a/packages/Webkul/Product/src/Product/Review.php +++ b/packages/Webkul/Product/src/Product/Review.php @@ -37,21 +37,10 @@ class Review extends AbstractProduct return $product->reviews()->where('status', 'approved')->count(); } - /** - * Returns the formated created at date - * - * @param ProductReview $review - * @return integer - */ - public function formatDate($reviewCreatedAt) - { - return core()->formatDate($reviewCreatedAt, 'd, M Y'); - } - /** * Returns the total rating of the product * - * @param Product $product + * @param Product $product * @return integer */ public function getTotalRating($product) diff --git a/packages/Webkul/Product/src/Repositories/ProductRepository.php b/packages/Webkul/Product/src/Repositories/ProductRepository.php index 1a5b92783..553953e37 100644 --- a/packages/Webkul/Product/src/Repositories/ProductRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductRepository.php @@ -423,4 +423,28 @@ class ProductRepository extends Repository get_class($this->model), $slug ); } + + /** + * Return newly added product + * + * @return Collection + */ + public function getNewProducts() + { + $this->pushCriteria(app(AttributeToSelectCriteria::class)->addAttribueToSelect([ + 'name', + 'description', + 'short_description', + 'price', + 'special_price', + 'special_price_from', + 'special_price_to' + ])); + + $params = request()->input(); + + return $this->scopeQuery(function($query){ + return $query->distinct()->addSelect('products.*')->orderBy('id', 'desc'); + })->paginate(4, ['products.id']); + } } \ No newline at end of file diff --git a/packages/Webkul/Shop/src/Http/ViewComposers/Categories/CategoryComposer.php b/packages/Webkul/Shop/src/Http/ViewComposers/CategoryComposer.php similarity index 68% rename from packages/Webkul/Shop/src/Http/ViewComposers/Categories/CategoryComposer.php rename to packages/Webkul/Shop/src/Http/ViewComposers/CategoryComposer.php index 8d6b07511..c4885ea34 100644 --- a/packages/Webkul/Shop/src/Http/ViewComposers/Categories/CategoryComposer.php +++ b/packages/Webkul/Shop/src/Http/ViewComposers/CategoryComposer.php @@ -1,10 +1,9 @@ * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ - class CategoryComposer { /** @@ -36,13 +34,20 @@ class CategoryComposer $this->category = $category; } + /** + * Bind data to the view. + * + * @param View $view + * @return void + */ public function compose(View $view) { - $collected_cat = array(); - $categories = $this->category->getCategoryTree(); - foreach ($categories as $category) { - array_push($collected_cat, collect($category)); + $categories = []; + + foreach ($this->category->getCategoryTree() as $category) { + array_push($categories, collect($category)); } - $view->with('categories', $collected_cat); + + $view->with('categories', $categories); } } diff --git a/packages/Webkul/Shop/src/Http/ViewComposers/NewProductListComposer.php b/packages/Webkul/Shop/src/Http/ViewComposers/NewProductListComposer.php new file mode 100644 index 000000000..b6414a931 --- /dev/null +++ b/packages/Webkul/Shop/src/Http/ViewComposers/NewProductListComposer.php @@ -0,0 +1,48 @@ + + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ +class NewProductListComposer +{ + /** + * ProductRepository object + * + * @var array + */ + protected $product; + + /** + * Bind data to the view. + * + * @param View $view + * @return void + */ + public function __construct(Product $product) + { + $this->product = $product; + } + + /** + * Bind data to the view. + * + * @param View $view + * @return void + */ + public function compose(View $view) + { + // dd($mytime = \Carbon\Carbon::now()); + $products = $this->product->getNewProducts(); + + $view->with('products', $products); + } +} diff --git a/packages/Webkul/Shop/src/Providers/ComposerServiceProvider.php b/packages/Webkul/Shop/src/Providers/ComposerServiceProvider.php index fb5a97bcc..b6d6380bc 100644 --- a/packages/Webkul/Shop/src/Providers/ComposerServiceProvider.php +++ b/packages/Webkul/Shop/src/Providers/ComposerServiceProvider.php @@ -17,17 +17,14 @@ class ComposerServiceProvider extends ServiceProvider */ public function boot() { - //using the class based composers... - View::composer(['shop::layouts.header.index', 'shop::layouts.footer.footer'], 'Webkul\Shop\Http\ViewComposers\Categories\CategoryComposer'); - } + View::composer( + ['shop::layouts.header.index', 'shop::layouts.footer.footer'], + 'Webkul\Shop\Http\ViewComposers\CategoryComposer' + ); - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - // + View::composer( + ['shop::home.new-products'], + 'Webkul\Shop\Http\ViewComposers\NewProductListComposer' + ); } -} +} \ No newline at end of file diff --git a/packages/Webkul/Shop/src/Resources/views/home/new-products.blade.php b/packages/Webkul/Shop/src/Resources/views/home/new-products.blade.php index 84eefb109..47b282aed 100644 --- a/packages/Webkul/Shop/src/Resources/views/home/new-products.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/home/new-products.blade.php @@ -1,4 +1,5 @@
diff --git a/packages/Webkul/Shop/src/Resources/views/products/view/reviews.blade.php b/packages/Webkul/Shop/src/Resources/views/products/view/reviews.blade.php index f877278f7..8fc334b12 100644 --- a/packages/Webkul/Shop/src/Resources/views/products/view/reviews.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/view/reviews.blade.php @@ -60,7 +60,7 @@ - {{ $reviewHelper->formatDate($review->created_at) }} + {{ core()->formatDate($review->created_at) }} diff --git a/packages/Webkul/Ui/src/DataGrid/ProductGrid.php b/packages/Webkul/Ui/src/DataGrid/ProductGrid.php index 47be52540..0a35ee711 100644 --- a/packages/Webkul/Ui/src/DataGrid/ProductGrid.php +++ b/packages/Webkul/Ui/src/DataGrid/ProductGrid.php @@ -200,7 +200,7 @@ class ProductGrid public function __construct(AttributeRepository $attributes) { - $this->channel = request()->get('channel') ?: core()->getCurrentChannelCode(); + $this->channel = request()->get('channel') ?: core()->getDefaultChannelCode(); $this->locale = request()->get('locale') ?: app()->getLocale(); $this->attributes = $attributes;