diff --git a/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php b/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php index 325e3d904..6551f7ce1 100755 --- a/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php @@ -19,7 +19,9 @@ class OrderDataGrid extends DataGrid public function prepareQueryBuilder() { - $queryBuilder = DB::table('orders')->select('id', 'base_sub_total', 'base_grand_total', 'created_at', 'channel_name', 'status')->addSelect(DB::raw('CONCAT(customer_first_name, " ", customer_last_name) as full_name')); + $queryBuilder = DB::table('orders') + ->select('id', 'base_sub_total', 'base_grand_total', 'created_at', 'channel_name', 'status') + ->addSelect(DB::raw('CONCAT(customer_first_name, " ", customer_last_name) as full_name')); $this->addFilter('full_name', DB::raw('CONCAT(customer_first_name, " ", customer_last_name)')); diff --git a/packages/Webkul/Admin/src/Resources/lang/en/app.php b/packages/Webkul/Admin/src/Resources/lang/en/app.php index 158af5ad2..7d965a97e 100755 --- a/packages/Webkul/Admin/src/Resources/lang/en/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php @@ -761,6 +761,7 @@ return [ 'user-define-error' => 'Can not delete system :name', 'attribute-error' => ':name is used in configurable products.', 'attribute-product-error' => ':name is used in products.', - 'customer-associate' => ':name can not be deleted because customer is associated with this group.' + 'customer-associate' => ':name can not be deleted because customer is associated with this group.', + 'currency-delete-error' => 'This currency is set as channel base currency so it can not be deleted.' ], ]; \ No newline at end of file diff --git a/packages/Webkul/Core/src/Http/Controllers/CurrencyController.php b/packages/Webkul/Core/src/Http/Controllers/CurrencyController.php index 352f9079e..7ebcfc304 100755 --- a/packages/Webkul/Core/src/Http/Controllers/CurrencyController.php +++ b/packages/Webkul/Core/src/Http/Controllers/CurrencyController.php @@ -145,6 +145,8 @@ class CurrencyController extends Controller session()->flash('error', trans('admin::app.response.last-delete-error', ['name' => 'Currency'])); } catch (\Exception $e) { session()->flash('error', $e->getMessage()); + + session()->flash('error', trans('admin::app.response.currency-delete-error', ['name' => 'Currency'])); } return redirect()->back(); diff --git a/packages/Webkul/Product/src/Listeners/ProductFlat.php b/packages/Webkul/Product/src/Listeners/ProductFlat.php index f06fe8bde..c339dede8 100644 --- a/packages/Webkul/Product/src/Listeners/ProductFlat.php +++ b/packages/Webkul/Product/src/Listeners/ProductFlat.php @@ -4,6 +4,7 @@ namespace Webkul\Product\Listeners; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; +use Webkul\Attribute\Repositories\AttributeRepository; use Webkul\Attribute\Repositories\AttributeOptionRepository; use Webkul\Product\Repositories\ProductFlatRepository; use Webkul\Product\Repositories\ProductAttributeValueRepository; @@ -18,6 +19,13 @@ use Webkul\Product\Models\ProductAttributeValue; */ class ProductFlat { + /** + * AttributeRepository Repository Object + * + * @var object + */ + protected $attributeRepository; + /** * AttributeOptionRepository Repository Object * @@ -63,17 +71,21 @@ class ProductFlat /** * Create a new listener instance. * + * @param Webkul\Attribute\Repositories\AttributeRepository $attributeRepository * @param Webkul\Attribute\Repositories\AttributeOptionRepository $attributeOptionRepository * @param Webkul\Product\Repositories\ProductFlatRepository $productFlatRepository * @param Webkul\Product\Repositories\ProductAttributeValueRepository $productAttributeValueRepository * @return void */ public function __construct( + AttributeRepository $attributeRepository, AttributeOptionRepository $attributeOptionRepository, ProductFlatRepository $productFlatRepository, ProductAttributeValueRepository $productAttributeValueRepository ) { + $this->attributeRepository = $attributeRepository; + $this->attributeOptionRepository = $attributeOptionRepository; $this->productAttributeValueRepository = $productAttributeValueRepository; @@ -105,8 +117,10 @@ class ProductFlat } } - public function afterAttributeDeleted($attribute) + public function afterAttributeDeleted($attributeId) { + $attribute = $this->attributeRepository->find($attributeId); + if (Schema::hasTable('product_flat')) { if (Schema::hasColumn('product_flat', strtolower($attribute->code))) { Schema::table('product_flat', function (Blueprint $table) use($attribute) { diff --git a/packages/Webkul/Product/src/Repositories/ProductRepository.php b/packages/Webkul/Product/src/Repositories/ProductRepository.php index 1bcd481a1..fbf544a2a 100755 --- a/packages/Webkul/Product/src/Repositories/ProductRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductRepository.php @@ -156,10 +156,6 @@ class ProductRepository extends Repository $product->update($data); - if (isset($data['categories'])) { - $product->categories()->sync($data['categories']); - } - $attributes = $product->attribute_family->custom_attributes; foreach ($attributes as $attribute) { @@ -189,38 +185,44 @@ class ProductRepository extends Repository } } - $previousVariantIds = $product->variants->pluck('id'); + if (request()->route()->getName() != 'admin.catalog.products.massupdate') { + if (isset($data['categories'])) { + $product->categories()->sync($data['categories']); + } + + $previousVariantIds = $product->variants->pluck('id'); - if (isset($data['variants'])) { - foreach ($data['variants'] as $variantId => $variantData) { - if (str_contains($variantId, 'variant_')) { - $permutation = []; - foreach ($product->super_attributes as $superAttribute) { - $permutation[$superAttribute->id] = $variantData[$superAttribute->code]; + if (isset($data['variants'])) { + foreach ($data['variants'] as $variantId => $variantData) { + if (str_contains($variantId, 'variant_')) { + $permutation = []; + foreach ($product->super_attributes as $superAttribute) { + $permutation[$superAttribute->id] = $variantData[$superAttribute->code]; + } + + $this->createVariant($product, $permutation, $variantData); + } else { + if (is_numeric($index = $previousVariantIds->search($variantId))) { + $previousVariantIds->forget($index); + } + + $variantData['channel'] = $data['channel']; + $variantData['locale'] = $data['locale']; + + $this->updateVariant($variantData, $variantId); } - - $this->createVariant($product, $permutation, $variantData); - } else { - if (is_numeric($index = $previousVariantIds->search($variantId))) { - $previousVariantIds->forget($index); - } - - $variantData['channel'] = $data['channel']; - $variantData['locale'] = $data['locale']; - - $this->updateVariant($variantData, $variantId); } } + + foreach ($previousVariantIds as $variantId) { + $this->delete($variantId); + } + + $this->productInventory->saveInventories($data, $product); + + $this->productImage->uploadImages($data, $product); } - foreach ($previousVariantIds as $variantId) { - $this->delete($variantId); - } - - $this->productInventory->saveInventories($data, $product); - - $this->productImage->uploadImages($data, $product); - Event::fire('catalog.product.update.after', $product); return $product; @@ -385,6 +387,9 @@ class ProductRepository extends Repository $matchCount = 0; foreach ($superAttributeCodes as $attributeCode) { + if (! isset($data[$attributeCode])) + return false; + if ($data[$attributeCode] == $variant->{$attributeCode}) $matchCount++; }