diff --git a/README.md b/README.md index 25ddd80e2..1db90e246 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Bagisto Logo](https://bagisto.com/wp-content/themes/bagisto/images/logo.png) +![Bagisto Logo](https://bagisto.com/wp-content/themes/bagisto/images/logo.png) 1. #### Introduction @@ -8,15 +8,15 @@ # 1. About Bagisto: - + [Bagisto](https://www.bagisto.com) is a hand tailored E-Commerce framework designed on some of the hottest opensource technologies -such as [Laravel](https://laravel.com) a [PHP](https://secure.php.net/) framework, [Vue.js](https://vuejs.org) +such as [Laravel](https://laravel.com) a [PHP](https://secure.php.net/) framework, [Vue.js](https://vuejs.org) a [Node.js](https://nodejs.org) framework. **Bagisto is viable attempt to cut down your time, cost and workforce for building online stores or migrating from physical stores to the ever demanding online world. Your business whether small or huge it suits all and very simple to set it up.** -It packs in lots of demanding features that allows your business to scale in no time: +It packs in lots of demanding features that allows your business to scale in no time: * Multiple Channels, Locale, Currencies. * Built-in Access Control Layer. @@ -32,7 +32,7 @@ It packs in lots of demanding features that allows your business to scale in no * Simple and Configurable Products. * check out [more....](https://bagisto.com/features/). -**For Developers**: +**For Developers**: Dev guys can take advantage of two of the hottest frameworks used in this project Laravel and Vue.js, both of these frameworks have been used in Bagisto. Bagisto is using power of both of these frameworks and making best out of it out of the box. @@ -51,8 +51,8 @@ Bagisto is using power of both of these frameworks and making best out of it out # 3. Configuration: **Run this Command** to download the project on to your local machine or server: -~~~ -composer create-project bagisto/bagisto +~~~ +composer create-project bagisto/bagisto ~~~ if the above command's process was successful, you will find directory **bagisto** and all of the code will be inside it. @@ -73,12 +73,17 @@ default. # 4.Installation: **Run the Command** -~~~ +~~~ +php artisan migrate +~~~ + +**Run the Command** +~~~ php artisan db:seed ~~~ **Run the Command** -~~~ +~~~ php artisan vendor:publish ~~~ diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 845e050c3..1cda52f16 100644 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -181,6 +181,7 @@ class Cart { * @return void */ public function add($id, $data, $prepared = false, $preparedData = []) { + // dd($id, $data, $prepared, $preparedData); if($prepared == false) { $itemData = $this->prepareItemData($id, $data); } else { @@ -192,15 +193,19 @@ class Cart { } if($cart = $this->getCart()) { - $product = $this->product->find($id); + if($prepared == true) { + $product = $this->product->find($preparedData['parent']['product_id']); + } else { + $product = $this->product->find($id); + } $cartItems = $cart->items; //check the isset conditions as collection empty object will mislead the condition and error handling case. if(isset($cartItems) && $cartItems->count()) { + //for previously added items foreach($cartItems as $cartItem) { if($product->type == "simple") { - if($cartItem->product_id == $id) { $prevQty = $cartItem->quantity; $newQty = $data['quantity']; @@ -224,14 +229,9 @@ class Cart { return true; } } else if($product->type == "configurable") { - if($cartItem->type == "configurable") { + if ($cartItem->type == "configurable") { $temp = $this->cartItem->findOneByField('parent_id', $cartItem->id); - if($prepared == true) { - $data['selected_configurable_option'] = $preparedData['parent']['product_id']; - } - - if($temp->product_id == $data['selected_configurable_option']) { $child = $temp->child; @@ -263,13 +263,29 @@ class Cart { } } + //for new items if($product->type == "configurable") { + $canAdd = $this->canAdd($itemData['child']['product_id'], 1); + + if($canAdd == false) { + session()->flash('warning', trans('shop::app.checkout.cart.quantity.inventory_warning')); + + return false; + } + $parent = $cart->items()->create($itemData['parent']); $itemData['child']['parent_id'] = $parent->id; $cart->items()->create($itemData['child']); - } else if($product->type != "configurable"){ + } else if($product->type != "configurable") { + $canAdd = $this->canAdd($itemData['parent']['product_id'], 1); + + if($canAdd == false) { + session()->flash('warning', trans('shop::app.checkout.cart.quantity.inventory_warning')); + + return false; + } $parent = $cart->items()->create($itemData['parent']); } @@ -277,6 +293,7 @@ class Cart { return $cart; } else { + //rare case of accidents if(isset($cart)) { $this->cart->delete($cart->id); } else { @@ -290,7 +307,6 @@ class Cart { } } } else { - // return $this->createNewCart($id, $data); if($prepared == false) { return $this->createNewCart($id, $data); } @@ -1146,7 +1162,7 @@ class Cart { $moved = $this->add($product->parent_id, $data, true, $result); - if($moved) { + if(isset($moved)) { return true; } else { return false; @@ -1222,14 +1238,43 @@ class Cart { * @param instance cartItem $id */ public function moveToWishlist($itemId) { - $item = $this->cartItem->findOneByField('id', $itemId); - dd($item->cart); - if(!$item) - return false; + $cart = $this->getCart(); + $items = $cart->items; + $wishlist = []; + $wishlist = [ + 'channel_id' => $cart->channel_id, + 'customer_id' => auth()->guard('customer')->user()->id, + ]; - // $wishlist[ - // 'channel_id' => - // ]; + foreach($items as $item) { + if($item->id == $itemId) { + if(is_null($item['parent_id']) && $item['type'] == 'simple') { + $wishlist['product_id'] = $item->product_id; + } else { + $wishlist['product_id'] = $item->child->product_id; + $wishtlist['options'] = $item->addtional; + } + + $shouldBe = $this->wishlist->findWhere(['customer_id' => auth()->guard('customer')->user()->id, 'product_id' => $wishlist['product_id']]); + + if($shouldBe->isEmpty()) { + $wishlist = $this->wishlist->create($wishlist); + } + + $result = $this->cartItem->delete($itemId); + + if($result) { + if($cart->items()->count() == 0) + $this->cart->delete($cart->id); + + session()->flash('success', 'Item Move To Wishlist Successfully'); + + return $result; + } else { + return $result; + } + } + } } /** @@ -1241,11 +1286,13 @@ class Cart { $product = $this->product->findOneByField('id', $id); if($product->type == 'configurable') { - session()->flash('warning', 'Please Select Options Before Buying This Product'); + session()->flash('warning', trans('shop::app.buynow.no-options')); return false; } else { - $this->moveToCart($id); + $result = $this->moveToCart($id); + + return $result; } } } \ No newline at end of file diff --git a/packages/Webkul/Customer/src/Database/migrations/2018_07_24_083025_create_customer_addresses_table.php b/packages/Webkul/Customer/src/Database/migrations/2018_07_24_083025_create_customer_addresses_table.php index dd9676769..d01df94ce 100644 --- a/packages/Webkul/Customer/src/Database/migrations/2018_07_24_083025_create_customer_addresses_table.php +++ b/packages/Webkul/Customer/src/Database/migrations/2018_07_24_083025_create_customer_addresses_table.php @@ -24,6 +24,8 @@ class CreateCustomerAddressesTable extends Migration $table->string('city'); $table->integer('postcode'); $table->string('phone'); + $table->boolean('default_address')->default(0); + $table->string('name')->nullable(); $table->timestamps(); }); } diff --git a/packages/Webkul/Customer/src/Database/migrations/2018_10_27_110337_modify_customer_address_table.php b/packages/Webkul/Customer/src/Database/migrations/2018_10_27_110337_modify_customer_address_table.php deleted file mode 100644 index 01b8b20aa..000000000 --- a/packages/Webkul/Customer/src/Database/migrations/2018_10_27_110337_modify_customer_address_table.php +++ /dev/null @@ -1,37 +0,0 @@ -boolean('default_address')->default(0)->after('phone'); - $table->string('name')->nullable()->after('phone'); - }); - } - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - if (Schema::hasTable('customer_addresses')) { - Schema::table('customer_addresses', function (Blueprint $table) { - $table->dropColumn(['default', 'name']); - }); - } - } -} diff --git a/packages/Webkul/Shop/src/Http/Controllers/CartController.php b/packages/Webkul/Shop/src/Http/Controllers/CartController.php index 682cf0026..796629af8 100644 --- a/packages/Webkul/Shop/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/CartController.php @@ -54,7 +54,7 @@ class CartController extends Controller ProductView $productView ) { - // $this->middleware('customer')->except(['add', 'remove', 'test']); + $this->middleware('customer')->only(['moveToWishlist']); $this->customer = $customer; @@ -138,16 +138,20 @@ class CartController extends Controller * * @return response */ - public function addconfigurable($slug) { + public function addConfigurable($slug) { session()->flash('warning', trans('shop::app.checkout.cart.add-config-warning')); return redirect()->route('shop.products.index', $slug); } - public function test($id) { + public function buyNow($id) { $result = Cart::proceedForBuyNow($id); + Cart::collectTotals(); + if(!$result) { return redirect()->back(); + } else { + return redirect()->route('shop.checkout.onepage.index'); } } @@ -160,6 +164,18 @@ class CartController extends Controller public function moveToWishlist($id) { $result = Cart::moveToWishlist($id); - dd($result); + if($result) { + Cart::collectTotals(); + + session()->flash('success', 'Item Successfully Moved To Wishlist'); + + return redirect()->back(); + } else { + session()->flash('warning', 'Cannot move item to wishlist'); + + return redirect()->back(); + } + + } } \ No newline at end of file diff --git a/packages/Webkul/Shop/src/Http/routes.php b/packages/Webkul/Shop/src/Http/routes.php index c24d57404..78f3998cc 100644 --- a/packages/Webkul/Shop/src/Http/routes.php +++ b/packages/Webkul/Shop/src/Http/routes.php @@ -27,7 +27,7 @@ Route::group(['middleware' => ['web', 'theme', 'locale', 'currency']], function Route::post('checkout/cart/add/{id}', 'Webkul\Shop\Http\Controllers\CartController@add')->name('cart.add'); //Cart Items Add Configurable for more - Route::get('checkout/cart/addconfigurable/{slug}', 'Webkul\Shop\Http\Controllers\CartController@addconfigurable')->name('cart.add.configurable'); + Route::get('checkout/cart/addconfigurable/{slug}', 'Webkul\Shop\Http\Controllers\CartController@addConfigurable')->name('cart.add.configurable'); //Cart Items Remove Route::get('checkout/cart/remove/{id}', 'Webkul\Shop\Http\Controllers\CartController@remove')->name('cart.remove'); @@ -65,10 +65,10 @@ Route::group(['middleware' => ['web', 'theme', 'locale', 'currency']], function ])->name('shop.checkout.success'); //Shop buynow button action - Route::get('buynow/{id}', 'Webkul\Shop\Http\Controllers\CartController@test')->name('shop.product.buynow'); + Route::get('buynow/{id}', 'Webkul\Shop\Http\Controllers\CartController@buyNow')->name('shop.product.buynow'); //Shop buynow button action - Route::get('move/cart/{id}', 'Webkul\Shop\Http\Controllers\CartController@moveToWishlist')->name('shop.movetowishlist'); + Route::get('move/wishlist/{id}', 'Webkul\Shop\Http\Controllers\CartController@moveToWishlist')->name('shop.movetowishlist'); //Show Product Details Page(For individually Viewable Product) Route::get('/products/{slug}', 'Webkul\Shop\Http\Controllers\ProductController@index')->defaults('_config', [ diff --git a/packages/Webkul/Shop/src/Resources/lang/en/app.php b/packages/Webkul/Shop/src/Resources/lang/en/app.php index 4632a9465..e3a6110be 100644 --- a/packages/Webkul/Shop/src/Resources/lang/en/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/en/app.php @@ -261,6 +261,11 @@ return [ 'remove' => 'Item Successfully Removed From Wishlist' ], + 'buynow' => [ + 'no-options' => 'Please Select Options Before Buying This Product' + ], + + 'checkout' => [ 'cart' => [ 'integrity' => [ diff --git a/packages/Webkul/Shop/src/Resources/views/products/buy-now.blade.php b/packages/Webkul/Shop/src/Resources/views/products/buy-now.blade.php index 2bb83c93a..875145341 100644 --- a/packages/Webkul/Shop/src/Resources/views/products/buy-now.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/buy-now.blade.php @@ -1,3 +1,3 @@ -{{-- type != 'configurable' && !$product->haveSufficientQuantity(1) ? 'disabled' : '' }}> +type != 'configurable' && !$product->haveSufficientQuantity(1) ? 'disabled' : '' }}> {{ __('shop::app.products.buy-now') }} - --}} \ No newline at end of file + \ No newline at end of file diff --git a/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php b/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php index 4d99ea31a..41e7444fb 100644 --- a/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php @@ -110,11 +110,12 @@ this.selectedProductId = attribute.options[attribute.selectedIndex].allowedProducts[0]; } + //wishlist anchor href changer with options @auth('customer') - var prevLink = $('#wishlist-changer').attr('href'); + var wishlistLink = $('#wishlist-changer').attr('href'); if(this.selectedProductId != '') { - var splitted = prevLink.split("/"); + var splitted = wishlistLink.split("/"); var lastItem = splitted.pop(); @@ -127,6 +128,23 @@ $('#wishlist-changer').attr('href', newWishlistUrl); } @endauth + + //buy now anchor href changer with options + var buyNowLink = $('#buynow-changer').attr('href'); + + if(this.selectedProductId != '') { + var splitted = buyNowLink.split("/"); + + var lastItem = splitted.pop(); + + lastItem = this.selectedProductId; + + var joined = splitted.join('/'); + + var newBuyNowUrl = joined+'/'+lastItem; + + $('#buynow-changer').attr('href', newBuyNowUrl); + } } else { attribute.selectedIndex = 0;