{!! view_render_event('bagisto.admin.catalog.product.edit_form_accordian.' . $attributeGroup->name . '.controls.before', ['product' => $product]) !!}
diff --git a/packages/Webkul/Product/src/Contracts/ProductBundleProduct.php b/packages/Webkul/Product/src/Contracts/ProductBundleOptionProduct.php
similarity index 54%
rename from packages/Webkul/Product/src/Contracts/ProductBundleProduct.php
rename to packages/Webkul/Product/src/Contracts/ProductBundleOptionProduct.php
index 926b091f8..e024ce8cc 100644
--- a/packages/Webkul/Product/src/Contracts/ProductBundleProduct.php
+++ b/packages/Webkul/Product/src/Contracts/ProductBundleOptionProduct.php
@@ -2,6 +2,6 @@
namespace Webkul\Product\Contracts;
-interface ProductBundleProduct
+interface ProductBundleOptionProduct
{
}
\ No newline at end of file
diff --git a/packages/Webkul/Product/src/Database/Migrations/2019_08_20_170528_create_product_bundle_products_table.php b/packages/Webkul/Product/src/Database/Migrations/2019_08_20_170528_create_product_bundle_option_products_table.php
similarity index 76%
rename from packages/Webkul/Product/src/Database/Migrations/2019_08_20_170528_create_product_bundle_products_table.php
rename to packages/Webkul/Product/src/Database/Migrations/2019_08_20_170528_create_product_bundle_option_products_table.php
index 5a38c523e..5cb07480d 100644
--- a/packages/Webkul/Product/src/Database/Migrations/2019_08_20_170528_create_product_bundle_products_table.php
+++ b/packages/Webkul/Product/src/Database/Migrations/2019_08_20_170528_create_product_bundle_option_products_table.php
@@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
-class CreateProductBundleProductsTable extends Migration
+class CreateProductBundleOptionProductsTable extends Migration
{
/**
* Run the migrations.
@@ -13,9 +13,10 @@ class CreateProductBundleProductsTable extends Migration
*/
public function up()
{
- Schema::create('product_bundle_products', function (Blueprint $table) {
+ Schema::create('product_bundle_option_products', function (Blueprint $table) {
$table->increments('id');
$table->integer('qty')->default(0);
+ $table->boolean('is_default')->default(0);
$table->integer('sort_order')->default(0);
$table->integer('product_bundle_option_id')->unsigned();
@@ -33,6 +34,6 @@ class CreateProductBundleProductsTable extends Migration
*/
public function down()
{
- Schema::dropIfExists('product_bundle_products');
+ Schema::dropIfExists('product_bundle_option_products');
}
}
diff --git a/packages/Webkul/Product/src/Http/Controllers/ProductController.php b/packages/Webkul/Product/src/Http/Controllers/ProductController.php
index 574d81b75..b411de872 100755
--- a/packages/Webkul/Product/src/Http/Controllers/ProductController.php
+++ b/packages/Webkul/Product/src/Http/Controllers/ProductController.php
@@ -8,7 +8,6 @@ use Webkul\Category\Repositories\CategoryRepository;
use Webkul\Product\Repositories\ProductRepository;
use Webkul\Product\Repositories\ProductDownloadableLinkRepository;
use Webkul\Product\Repositories\ProductDownloadableSampleRepository;
-use Webkul\Product\Repositories\ProductGroupedProductRepository;
use Webkul\Attribute\Repositories\AttributeFamilyRepository;
use Webkul\Inventory\Repositories\InventorySourceRepository;
use Illuminate\Support\Facades\Storage;
@@ -70,13 +69,6 @@ class ProductController extends Controller
*/
protected $inventorySourceRepository;
- /**
- * ProductGroupedProductRepository object
- *
- * @var Object
- */
- protected $productGroupedProductRepository;
-
/**
* Create a new controller instance.
*
@@ -86,7 +78,6 @@ class ProductController extends Controller
* @param \Webkul\Product\Repositories\ProductDownloadableSampleRepository $productDownloadableSampleRepository
* @param \Webkul\Attribute\Repositories\AttributeFamilyRepository $attributeFamilyRepository
* @param \Webkul\Inventory\Repositories\InventorySourceRepository $inventorySource
- * @param \Webkul\Inventory\Repositories\ProductGroupedProductRepository $productGroupedProductRepository
* @return void
*/
public function __construct(
@@ -95,8 +86,7 @@ class ProductController extends Controller
ProductDownloadableLinkRepository $productDownloadableLinkRepository,
ProductDownloadableSampleRepository $productDownloadableSampleRepository,
AttributeFamilyRepository $attributeFamilyRepository,
- InventorySourceRepository $inventorySourceRepository,
- ProductGroupedProductRepository $productGroupedProductRepository
+ InventorySourceRepository $inventorySourceRepository
)
{
$this->_config = request('_config');
@@ -112,8 +102,6 @@ class ProductController extends Controller
$this->attributeFamilyRepository = $attributeFamilyRepository;
$this->inventorySourceRepository = $inventorySourceRepository;
-
- $this->productGroupedProductRepository = $productGroupedProductRepository;
}
/**
@@ -367,14 +355,14 @@ class ProductController extends Controller
}
/**
- * Search simple products for grouped product association
+ * Search simple products
*
* @return \Illuminate\Http\JsonResponse
*/
- public function searchProductForGroupedAssociation()
+ public function searchSimpleProducts()
{
return response()->json(
- $this->productGroupedProductRepository->searchSimpleProducts(request('id'), request()->input('query'))
+ $this->productRepository->searchSimpleProducts(request()->input('query'))
);
}
}
\ No newline at end of file
diff --git a/packages/Webkul/Product/src/Models/Product.php b/packages/Webkul/Product/src/Models/Product.php
index d98084ae9..6225820c8 100755
--- a/packages/Webkul/Product/src/Models/Product.php
+++ b/packages/Webkul/Product/src/Models/Product.php
@@ -165,6 +165,14 @@ class Product extends Model implements ProductContract
return $this->hasMany(ProductGroupedProductProxy::modelClass());
}
+ /**
+ * Get the bundle options that owns the product.
+ */
+ public function bundle_options()
+ {
+ return $this->hasMany(ProductBundleOptionProxy::modelClass());
+ }
+
/**
* @param integer $qty
*
diff --git a/packages/Webkul/Product/src/Models/ProductBundleOption.php b/packages/Webkul/Product/src/Models/ProductBundleOption.php
index 9a4b96e15..e94524762 100644
--- a/packages/Webkul/Product/src/Models/ProductBundleOption.php
+++ b/packages/Webkul/Product/src/Models/ProductBundleOption.php
@@ -20,4 +20,12 @@ class ProductBundleOption extends TranslatableModel implements ProductBundleOpti
{
return $this->belongsTo(ProductProxy::modelClass());
}
+
+ /**
+ * Get the bundle option products that owns the bundle option.
+ */
+ public function bundle_option_products()
+ {
+ return $this->hasMany(ProductBundleOptionProductProxy::modelClass());
+ }
}
\ No newline at end of file
diff --git a/packages/Webkul/Product/src/Models/ProductBundleOptionProduct.php b/packages/Webkul/Product/src/Models/ProductBundleOptionProduct.php
new file mode 100644
index 000000000..a659105aa
--- /dev/null
+++ b/packages/Webkul/Product/src/Models/ProductBundleOptionProduct.php
@@ -0,0 +1,21 @@
+belongsTo(ProductProxy::modelClass());
+ }
+}
\ No newline at end of file
diff --git a/packages/Webkul/Product/src/Models/ProductBundleProductProxy.php b/packages/Webkul/Product/src/Models/ProductBundleOptionProductProxy.php
similarity index 59%
rename from packages/Webkul/Product/src/Models/ProductBundleProductProxy.php
rename to packages/Webkul/Product/src/Models/ProductBundleOptionProductProxy.php
index 3bcb45512..2968b065a 100644
--- a/packages/Webkul/Product/src/Models/ProductBundleProductProxy.php
+++ b/packages/Webkul/Product/src/Models/ProductBundleOptionProductProxy.php
@@ -4,7 +4,7 @@ namespace Webkul\Product\Models;
use Konekt\Concord\Proxies\ModelProxy;
-class ProductBundleProductProxy extends ModelProxy
+class ProductBundleOptionProductProxy extends ModelProxy
{
}
\ No newline at end of file
diff --git a/packages/Webkul/Product/src/Models/ProductBundleProduct.php b/packages/Webkul/Product/src/Models/ProductBundleProduct.php
deleted file mode 100644
index e398066d4..000000000
--- a/packages/Webkul/Product/src/Models/ProductBundleProduct.php
+++ /dev/null
@@ -1,21 +0,0 @@
-belongsTo(ProductProxy::modelClass());
- }
-}
\ No newline at end of file
diff --git a/packages/Webkul/Product/src/Providers/ModuleServiceProvider.php b/packages/Webkul/Product/src/Providers/ModuleServiceProvider.php
index dc1d0005f..66f6ea312 100644
--- a/packages/Webkul/Product/src/Providers/ModuleServiceProvider.php
+++ b/packages/Webkul/Product/src/Providers/ModuleServiceProvider.php
@@ -20,6 +20,6 @@ class ModuleServiceProvider extends BaseModuleServiceProvider
\Webkul\Product\Models\ProductGroupedProduct::class,
\Webkul\Product\Models\ProductBundleOption::class,
\Webkul\Product\Models\ProductBundleOptionTranslation::class,
- \Webkul\Product\Models\ProductBundleProduct::class,
+ \Webkul\Product\Models\ProductBundleOptionProduct::class,
];
}
\ No newline at end of file
diff --git a/packages/Webkul/Product/src/Repositories/ProductBundleOptionProductRepository.php b/packages/Webkul/Product/src/Repositories/ProductBundleOptionProductRepository.php
new file mode 100644
index 000000000..d57a107e1
--- /dev/null
+++ b/packages/Webkul/Product/src/Repositories/ProductBundleOptionProductRepository.php
@@ -0,0 +1,48 @@
+
+ * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
+ */
+class ProductBundleOptionProductRepository extends Repository
+{
+ public function model()
+ {
+ return 'Webkul\Product\Contracts\ProductBundleOptionProduct';
+ }
+
+ /**
+ * @param array $data
+ * @param ProductBundleOption $productBundleOption
+ * @return void
+ */
+ public function saveBundleOptonProducts($data, $productBundleOption)
+ {
+ $previousBundleOptionProductIds = $productBundleOption->bundle_option_products()->pluck('id');
+
+ if (isset($data['products'])) {
+ foreach ($data['products'] as $bundleOptionProductId => $bundleOptionProductInputs) {
+ if (str_contains($bundleOptionProductId, 'product_')) {
+ $this->create(array_merge([
+ 'product_bundle_option_id' => $productBundleOption->id,
+ ], $bundleOptionProductInputs));
+ } else {
+ if (is_numeric($index = $previousBundleOptionProductIds->search($bundleOptionProductId)))
+ $previousBundleOptionProductIds->forget($index);
+
+ $this->update($bundleOptionProductInputs, $bundleOptionProductId);
+ }
+ }
+ }
+
+ foreach ($previousBundleOptionProductIds as $previousBundleOptionProductId) {
+ $this->delete($previousBundleOptionProductId);
+ }
+ }
+}
\ No newline at end of file
diff --git a/packages/Webkul/Product/src/Repositories/ProductBundleOptionRepository.php b/packages/Webkul/Product/src/Repositories/ProductBundleOptionRepository.php
index 4da76f4b8..6c5208ccf 100644
--- a/packages/Webkul/Product/src/Repositories/ProductBundleOptionRepository.php
+++ b/packages/Webkul/Product/src/Repositories/ProductBundleOptionRepository.php
@@ -2,6 +2,7 @@
namespace Webkul\Product\Repositories;
+use Illuminate\Container\Container as App;
use Webkul\Core\Eloquent\Repository;
/**
@@ -12,8 +13,64 @@ use Webkul\Core\Eloquent\Repository;
*/
class ProductBundleOptionRepository extends Repository
{
+ /**
+ * ProductBundleOptionProductRepository object
+ *
+ * @var ProductBundleOptionProductRepository
+ */
+ protected $productBundleOptionProductRepository;
+
+ /**
+ * Create a new controller instance.
+ *
+ * @param Webkul\Product\Repositories\ProductBundleOptionProductRepository $productBundleOptionProductRepository
+ * @return void
+ */
+ public function __construct(
+ ProductBundleOptionProductRepository $productBundleOptionProductRepository,
+ App $app
+ )
+ {
+ $this->productBundleOptionProductRepository = $productBundleOptionProductRepository;
+
+ parent::__construct($app);
+ }
+
public function model()
{
return 'Webkul\Product\Contracts\ProductBundleOption';
}
+
+ /**
+ * @param array $data
+ * @param Product $product
+ * @return void
+ */
+ public function saveBundleOptons($data, $product)
+ {
+ $previousBundleOptionIds = $product->bundle_options()->pluck('id');
+
+ if (isset($data['bundle_options'])) {
+ foreach ($data['bundle_options'] as $bundleOptionId => $bundleOptionInputs) {
+ if (str_contains($bundleOptionId, 'option_')) {
+ $productBundleOption = $this->create(array_merge([
+ 'product_id' => $product->id,
+ ], $bundleOptionInputs));
+ } else {
+ $productBundleOption = $this->find($bundleOptionId);
+
+ if (is_numeric($index = $previousBundleOptionIds->search($bundleOptionId)))
+ $previousBundleOptionIds->forget($index);
+
+ $this->update($bundleOptionInputs, $bundleOptionId);
+ }
+
+ $this->productBundleOptionProductRepository->saveBundleOptonProducts($bundleOptionInputs, $productBundleOption);
+ }
+ }
+
+ foreach ($previousBundleOptionIds as $previousBundleOptionId) {
+ $this->delete($previousBundleOptionId);
+ }
+ }
}
\ No newline at end of file
diff --git a/packages/Webkul/Product/src/Repositories/ProductBundleProductRepository.php b/packages/Webkul/Product/src/Repositories/ProductBundleProductRepository.php
deleted file mode 100644
index 9fae744a0..000000000
--- a/packages/Webkul/Product/src/Repositories/ProductBundleProductRepository.php
+++ /dev/null
@@ -1,19 +0,0 @@
-
- * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
- */
-class ProductBundleProductRepository extends Repository
-{
- public function model()
- {
- return 'Webkul\Product\Contracts\ProductBundleProduct';
- }
-}
\ No newline at end of file
diff --git a/packages/Webkul/Product/src/Repositories/ProductGroupedProductRepository.php b/packages/Webkul/Product/src/Repositories/ProductGroupedProductRepository.php
index 8920c3ead..8558f9404 100644
--- a/packages/Webkul/Product/src/Repositories/ProductGroupedProductRepository.php
+++ b/packages/Webkul/Product/src/Repositories/ProductGroupedProductRepository.php
@@ -4,7 +4,6 @@ namespace Webkul\Product\Repositories;
use Webkul\Core\Eloquent\Repository;
use Webkul\Product\Repositories\ProductRepository;
-use Webkul\Product\Repositories\ProductFlatRepository;
/**
* Product Grouped Product Repository
@@ -19,39 +18,6 @@ class ProductGroupedProductRepository extends Repository
return 'Webkul\Product\Contracts\ProductGroupedProduct';
}
- /**
- * Search simple products for grouped product association
- *
- * @param integer $productId
- * @param string $term
- * @return \Illuminate\Support\Collection
- */
- public function searchSimpleProducts($productId, $term)
- {
- $product = app(ProductRepository::class)->find($productId);
-
- $groupedProductIds = $product->grouped_products()->pluck('product_id');
-
- $groupedProductIds = $groupedProductIds->concat([$productId]);
-
- return app(ProductFlatRepository::class)->scopeQuery(function($query) use($groupedProductIds, $term) {
- $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
-
- $locale = request()->get('locale') ?: app()->getLocale();
-
- return $query->distinct()
- ->addSelect('product_flat.*')
- ->addSelect('product_flat.product_id as id')
- ->leftJoin('products', 'product_flat.product_id', '=', 'products.id')
- ->where('products.type', 'simple')
- ->where('product_flat.channel', $channel)
- ->where('product_flat.locale', $locale)
- ->whereNotIn('product_flat.product_id', $groupedProductIds)
- ->where('product_flat.name', 'like', '%' . urldecode($term) . '%')
- ->orderBy('product_id', 'desc');
- })->get();
- }
-
/**
* @param array $data
* @param Product $product
diff --git a/packages/Webkul/Product/src/Repositories/ProductRepository.php b/packages/Webkul/Product/src/Repositories/ProductRepository.php
index 8bd57a85b..4ef0147ce 100755
--- a/packages/Webkul/Product/src/Repositories/ProductRepository.php
+++ b/packages/Webkul/Product/src/Repositories/ProductRepository.php
@@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Event;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Core\Eloquent\Repository;
+use Webkul\Product\Repositories\ProductFlatRepository;
/**
* Product Repository
@@ -328,4 +329,29 @@ class ProductRepository extends Repository
return $superAttrbutes;
}
+
+ /**
+ * Search simple products for grouped product association
+ *
+ * @param string $term
+ * @return \Illuminate\Support\Collection
+ */
+ public function searchSimpleProducts($term)
+ {
+ return app(ProductFlatRepository::class)->scopeQuery(function($query) use($term) {
+ $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
+
+ $locale = request()->get('locale') ?: app()->getLocale();
+
+ return $query->distinct()
+ ->addSelect('product_flat.*')
+ ->addSelect('product_flat.product_id as id')
+ ->leftJoin('products', 'product_flat.product_id', '=', 'products.id')
+ ->where('products.type', 'simple')
+ ->where('product_flat.channel', $channel)
+ ->where('product_flat.locale', $locale)
+ ->where('product_flat.name', 'like', '%' . urldecode($term) . '%')
+ ->orderBy('product_id', 'desc');
+ })->get();
+ }
}
\ No newline at end of file
diff --git a/packages/Webkul/Product/src/Type/Bundle.php b/packages/Webkul/Product/src/Type/Bundle.php
index b47b7fd9c..9db8973f0 100644
--- a/packages/Webkul/Product/src/Type/Bundle.php
+++ b/packages/Webkul/Product/src/Type/Bundle.php
@@ -2,6 +2,14 @@
namespace Webkul\Product\Type;
+use Webkul\Attribute\Repositories\AttributeRepository;
+use Webkul\Product\Repositories\ProductRepository;
+use Webkul\Product\Repositories\ProductAttributeValueRepository;
+use Webkul\Product\Repositories\ProductInventoryRepository;
+use Webkul\Product\Repositories\ProductImageRepository;
+use Webkul\Product\Repositories\ProductBundleOptionRepository;
+use Webkul\Product\Helpers\ProductImage;
+
/**
* Class Bundle.
*
@@ -10,6 +18,55 @@ namespace Webkul\Product\Type;
*/
class Bundle extends AbstractType
{
+ /**
+ * AttributeRepository instance
+ *
+ * @var AttributeRepository
+ */
+ protected $attributeRepository;
+
+ /**
+ * ProductRepository instance
+ *
+ * @var ProductRepository
+ */
+ protected $productRepository;
+
+ /**
+ * ProductAttributeValueRepository instance
+ *
+ * @var ProductAttributeValueRepository
+ */
+ protected $attributeValueRepository;
+
+ /**
+ * ProductInventoryRepository instance
+ *
+ * @var ProductInventoryRepository
+ */
+ protected $productInventoryRepository;
+
+ /**
+ * ProductImageRepository instance
+ *
+ * @var ProductImageRepository
+ */
+ protected $productImageRepository;
+
+ /**
+ * ProductBundleOptionRepository instance
+ *
+ * @var ProductBundleOptionRepository
+ */
+ protected $productBundleOptionRepository;
+
+ /**
+ * Product Image helper instance
+ *
+ * @var ProductImage
+ */
+ protected $productImageHelper;
+
/**
* Skip attribute for Bundle product type
*
@@ -28,4 +85,54 @@ class Bundle extends AbstractType
'admin::catalog.products.accordians.bundle-items',
'admin::catalog.products.accordians.product-links'
];
+
+ /**
+ * Create a new product type instance.
+ *
+ * @param Webkul\Attribute\Repositories\AttributeRepository $attributeRepository
+ * @param Webkul\Product\Repositories\ProductRepository $productRepository
+ * @param Webkul\Product\Repositories\ProductAttributeValueRepository $attributeValueRepository
+ * @param Webkul\Product\Repositories\ProductInventoryRepository $productInventoryRepository
+ * @param Webkul\Product\Repositories\ProductImageRepository $productImageRepository
+ * @param Webkul\Product\Repositories\ProductBundleOptionRepository $productBundleOptionRepository
+ * @param Webkul\Product\Helpers\ProductImage $productImageHelper
+ * @return void
+ */
+ public function __construct(
+ AttributeRepository $attributeRepository,
+ ProductRepository $productRepository,
+ ProductAttributeValueRepository $attributeValueRepository,
+ ProductInventoryRepository $productInventoryRepository,
+ productImageRepository $productImageRepository,
+ ProductBundleOptionRepository $productBundleOptionRepository,
+ ProductImage $productImageHelper
+ )
+ {
+ parent::__construct(
+ $attributeRepository,
+ $productRepository,
+ $attributeValueRepository,
+ $productInventoryRepository,
+ $productImageRepository,
+ $productImageHelper
+ );
+
+ $this->productBundleOptionRepository = $productBundleOptionRepository;
+ }
+
+ /**
+ * @param array $data
+ * @param $id
+ * @param string $attribute
+ * @return Product
+ */
+ public function update(array $data, $id, $attribute = "id")
+ {
+ $product = parent::update($data, $id, $attribute);
+
+ if (request()->route()->getName() != 'admin.catalog.products.massupdate')
+ $this->productBundleOptionRepository->saveBundleOptons($data, $product);
+
+ return $product;
+ }
}
\ No newline at end of file
diff --git a/packages/Webkul/Product/src/Type/Downloadable.php b/packages/Webkul/Product/src/Type/Downloadable.php
index 041775492..2094e0733 100644
--- a/packages/Webkul/Product/src/Type/Downloadable.php
+++ b/packages/Webkul/Product/src/Type/Downloadable.php
@@ -9,7 +9,6 @@ use Webkul\Product\Repositories\ProductInventoryRepository;
use Webkul\Product\Repositories\ProductImageRepository;
use Webkul\Product\Repositories\ProductDownloadableLinkRepository;
use Webkul\Product\Repositories\ProductDownloadableSampleRepository;
-use Webkul\Product\Models\ProductAttributeValue;
use Webkul\Product\Helpers\ProductImage;
use Webkul\Checkout\Models\CartItem;