diff --git a/packages/Webkul/Admin/src/Database/Seeders/DatabaseSeeder.php b/packages/Webkul/Admin/src/Database/Seeders/DatabaseSeeder.php index dbdaed761..74e764713 100755 --- a/packages/Webkul/Admin/src/Database/Seeders/DatabaseSeeder.php +++ b/packages/Webkul/Admin/src/Database/Seeders/DatabaseSeeder.php @@ -10,6 +10,7 @@ use Webkul\User\Database\Seeders\DatabaseSeeder as UserSeeder; use Webkul\Customer\Database\Seeders\DatabaseSeeder as CustomerSeeder; use Webkul\Inventory\Database\Seeders\DatabaseSeeder as InventorySeeder; use Webkul\CMS\Database\Seeders\DatabaseSeeder as CMSSeeder; +use Webkul\SocialLogin\Database\Seeders\DatabaseSeeder as SocialLoginSeeder; class DatabaseSeeder extends Seeder { @@ -27,5 +28,6 @@ class DatabaseSeeder extends Seeder $this->call(UserSeeder::class); $this->call(CustomerSeeder::class); $this->call(CMSSeeder::class); + $this->call(SocialLoginSeeder::class); } -} \ No newline at end of file +} diff --git a/packages/Webkul/BookingProduct/src/Type/Booking.php b/packages/Webkul/BookingProduct/src/Type/Booking.php index 293f65aa0..9e980d9f5 100644 --- a/packages/Webkul/BookingProduct/src/Type/Booking.php +++ b/packages/Webkul/BookingProduct/src/Type/Booking.php @@ -152,6 +152,15 @@ class Booking extends Virtual return app($this->bookingHelper->getTypeHepler($bookingProduct->type))->isItemHaveQuantity($cartItem); } + /** + * @param int $qty + * @return bool + */ + public function haveSufficientQuantity($qty) + { + return true; + } + /** * Add product. Returns error message if can't prepare product. * diff --git a/packages/Webkul/Product/src/Helpers/BundleOption.php b/packages/Webkul/Product/src/Helpers/BundleOption.php index 406a12d63..d1ad05c0a 100644 --- a/packages/Webkul/Product/src/Helpers/BundleOption.php +++ b/packages/Webkul/Product/src/Helpers/BundleOption.php @@ -35,6 +35,9 @@ class BundleOption extends AbstractProduct { $options = []; + # eager load all inventories for bundle options + $this->product->bundle_options->load('bundle_option_products.product.inventories'); + foreach ($this->product->bundle_options as $option) { $data = $this->getOptionItemData($option); @@ -97,6 +100,8 @@ class BundleOption extends AbstractProduct 'product_id' => $bundleOptionProduct->product_id, 'is_default' => $bundleOptionProduct->is_default, 'sort_order' => $bundleOptionProduct->sort_order, + 'in_stock' => $bundleOptionProduct->product->inventories->sum('qty') >= $bundleOptionProduct->qty, + 'inventory' => $bundleOptionProduct->product->inventories->sum('qty'), ]; } diff --git a/packages/Webkul/Product/src/Type/Bundle.php b/packages/Webkul/Product/src/Type/Bundle.php index 9ad09181c..4c5f523cf 100644 --- a/packages/Webkul/Product/src/Type/Bundle.php +++ b/packages/Webkul/Product/src/Type/Bundle.php @@ -173,7 +173,7 @@ class Bundle extends AbstractType if (count($optionProductsPrices)) { $selectionMinPrice = min($optionProductsPrices); - if($option->is_required) { + if ($option->is_required) { $minPrice += $selectionMinPrice; } elseif (! $haveRequiredOptions) { $minPrices[] = $selectionMinPrice; @@ -207,7 +207,7 @@ class Bundle extends AbstractType if (count($optionProductsPrices)) { $selectionMinPrice = min($optionProductsPrices); - if($option->is_required) { + if ($option->is_required) { $minPrice += $selectionMinPrice; } elseif (! $haveRequiredOptions) { $minPrices[] = $selectionMinPrice; @@ -674,4 +674,27 @@ class Bundle extends AbstractType return $options; } + + /** + * @param int $qty + * @return bool + */ + public function haveSufficientQuantity($qty) + { + # to consider a bundle in stock we need to check that at least one product from each required group is available for the given quantity + foreach ($this->product->bundle_options as $option) { + if ($option->is_required) { + foreach ($option->bundle_option_products as $bundleOptionProduct) { + # as long as at least one product in the required group is available we can continue checking other groups + if($bundleOptionProduct->product->haveSufficientQuantity($bundleOptionProduct->qty * $qty)) { + continue 2; + } + } + # if any required option does not have any in-stock product option we will get here. + return false; + } + } + + return true; + } } \ No newline at end of file diff --git a/packages/Webkul/Product/src/Type/Virtual.php b/packages/Webkul/Product/src/Type/Virtual.php index aaa2489a2..6f19a8941 100644 --- a/packages/Webkul/Product/src/Type/Virtual.php +++ b/packages/Webkul/Product/src/Type/Virtual.php @@ -62,6 +62,6 @@ class Virtual extends AbstractType */ public function haveSufficientQuantity($qty) { - return true; + return $qty <= $this->totalQuantity() ? true : false; } } \ No newline at end of file diff --git a/packages/Webkul/SocialLogin/src/Database/Seeders/CustomerSocialAccountTableSeeder.php b/packages/Webkul/SocialLogin/src/Database/Seeders/CustomerSocialAccountTableSeeder.php new file mode 100644 index 000000000..0303898db --- /dev/null +++ b/packages/Webkul/SocialLogin/src/Database/Seeders/CustomerSocialAccountTableSeeder.php @@ -0,0 +1,70 @@ +insert( + [ + 'code' => 'customer.settings.social_login.enable_facebook', + 'value' => '1', + 'channel_code' => 'default', + 'locale_code' => null, + 'created_at' => $now, + 'updated_at' => $now, + ] + ); + + DB::table('core_config')->insert( + [ + 'code' => 'customer.settings.social_login.enable_twitter', + 'value' => '1', + 'channel_code' => 'default', + 'locale_code' => null, + 'created_at' => $now, + 'updated_at' => $now, + ] + ); + + DB::table('core_config')->insert( + [ + 'code' => 'customer.settings.social_login.enable_google', + 'value' => '1', + 'channel_code' => 'default', + 'locale_code' => null, + 'created_at' => $now, + 'updated_at' => $now, + ] + ); + + DB::table('core_config')->insert( + [ + 'code' => 'customer.settings.social_login.enable_linkedin', + 'value' => '1', + 'channel_code' => 'default', + 'locale_code' => null, + 'created_at' => $now, + 'updated_at' => $now, + ] + ); + + DB::table('core_config')->insert( + [ + 'code' => 'customer.settings.social_login.enable_github', + 'value' => '1', + 'channel_code' => 'default', + 'locale_code' => null, + 'created_at' => $now, + 'updated_at' => $now, + ] + ); + } +} diff --git a/packages/Webkul/SocialLogin/src/Database/Seeders/DatabaseSeeder.php b/packages/Webkul/SocialLogin/src/Database/Seeders/DatabaseSeeder.php new file mode 100644 index 000000000..57a79251a --- /dev/null +++ b/packages/Webkul/SocialLogin/src/Database/Seeders/DatabaseSeeder.php @@ -0,0 +1,18 @@ +call(CustomerSocialAccountTableSeeder::class); + } +}