2018-07-27 06:22:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Product\Http\Controllers;
|
|
|
|
|
|
2020-07-30 12:15:54 +00:00
|
|
|
use Exception;
|
2018-12-21 12:48:34 +00:00
|
|
|
use Illuminate\Support\Facades\Event;
|
2020-07-30 12:15:54 +00:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2022-02-07 10:36:38 +00:00
|
|
|
use Webkul\Admin\DataGrids\ProductDataGrid;
|
2019-06-28 14:18:52 +00:00
|
|
|
use Webkul\Attribute\Repositories\AttributeFamilyRepository;
|
2021-09-16 05:13:13 +00:00
|
|
|
use Webkul\Category\Repositories\CategoryRepository;
|
|
|
|
|
use Webkul\Core\Contracts\Validations\Slug;
|
2019-06-28 14:18:52 +00:00
|
|
|
use Webkul\Inventory\Repositories\InventorySourceRepository;
|
2021-09-16 05:13:13 +00:00
|
|
|
use Webkul\Product\Helpers\ProductType;
|
2022-05-09 10:35:21 +00:00
|
|
|
use Webkul\Product\Http\Requests\InventoryRequest;
|
2021-09-16 05:13:13 +00:00
|
|
|
use Webkul\Product\Http\Requests\ProductForm;
|
|
|
|
|
use Webkul\Product\Models\Product;
|
|
|
|
|
use Webkul\Product\Repositories\ProductAttributeValueRepository;
|
2020-07-30 12:15:54 +00:00
|
|
|
use Webkul\Product\Repositories\ProductDownloadableLinkRepository;
|
|
|
|
|
use Webkul\Product\Repositories\ProductDownloadableSampleRepository;
|
2021-09-16 05:13:13 +00:00
|
|
|
use Webkul\Product\Repositories\ProductInventoryRepository;
|
|
|
|
|
use Webkul\Product\Repositories\ProductRepository;
|
2019-01-19 10:05:12 +00:00
|
|
|
|
2018-07-27 06:22:12 +00:00
|
|
|
class ProductController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
2021-09-16 05:13:13 +00:00
|
|
|
* Contains route related configuration.
|
2018-07-27 06:22:12 +00:00
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $_config;
|
2018-08-16 13:39:51 +00:00
|
|
|
|
2021-09-16 05:13:13 +00:00
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
2020-07-30 12:15:54 +00:00
|
|
|
*
|
2022-04-01 14:57:11 +00:00
|
|
|
* @param \Webkul\Category\Repositories\CategoryRepository $categoryRepository
|
|
|
|
|
* @param \Webkul\Product\Repositories\ProductRepository $productRepository
|
|
|
|
|
* @param \Webkul\Product\Repositories\ProductDownloadableLinkRepository $productDownloadableLinkRepository
|
|
|
|
|
* @param \Webkul\Product\Repositories\ProductDownloadableSampleRepository $productDownloadableSampleRepository
|
|
|
|
|
* @param \Webkul\Attribute\Repositories\AttributeFamilyRepository $attributeFamilyRepository
|
|
|
|
|
* @param \Webkul\Inventory\Repositories\InventorySourceRepository $inventorySourceRepository
|
|
|
|
|
* @param \Webkul\Product\Repositories\ProductAttributeValueRepository $productAttributeValueRepository
|
2018-07-27 06:22:12 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2018-08-09 04:35:13 +00:00
|
|
|
public function __construct(
|
2022-04-01 14:57:11 +00:00
|
|
|
protected CategoryRepository $categoryRepository,
|
|
|
|
|
protected ProductRepository $productRepository,
|
|
|
|
|
protected ProductDownloadableLinkRepository $productDownloadableLinkRepository,
|
|
|
|
|
protected ProductDownloadableSampleRepository $productDownloadableSampleRepository,
|
|
|
|
|
protected AttributeFamilyRepository $attributeFamilyRepository,
|
|
|
|
|
protected InventorySourceRepository $inventorySourceRepository,
|
|
|
|
|
protected ProductAttributeValueRepository $productAttributeValueRepository,
|
|
|
|
|
protected ProductInventoryRepository $productInventoryRepository
|
|
|
|
|
)
|
|
|
|
|
{
|
2019-06-28 14:18:52 +00:00
|
|
|
$this->_config = request('_config');
|
2018-07-27 06:22:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
2019-08-19 09:30:24 +00:00
|
|
|
* @return \Illuminate\View\View
|
2018-07-27 06:22:12 +00:00
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2022-02-07 10:36:38 +00:00
|
|
|
if (request()->ajax()) {
|
|
|
|
|
return app(ProductDataGrid::class)->toJson();
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-27 06:22:12 +00:00
|
|
|
return view($this->_config['view']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
|
*
|
2019-08-19 09:30:24 +00:00
|
|
|
* @return \Illuminate\View\View
|
2018-07-27 06:22:12 +00:00
|
|
|
*/
|
|
|
|
|
public function create()
|
|
|
|
|
{
|
2019-06-28 14:18:52 +00:00
|
|
|
$families = $this->attributeFamilyRepository->all();
|
2018-07-31 07:50:54 +00:00
|
|
|
|
2019-01-18 05:30:55 +00:00
|
|
|
$configurableFamily = null;
|
|
|
|
|
|
2019-01-15 11:54:41 +00:00
|
|
|
if ($familyId = request()->get('family')) {
|
2019-06-28 14:18:52 +00:00
|
|
|
$configurableFamily = $this->attributeFamilyRepository->find($familyId);
|
2018-07-31 07:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return view($this->_config['view'], compact('families', 'configurableFamily'));
|
2018-07-27 06:22:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function store()
|
|
|
|
|
{
|
2021-09-16 05:13:13 +00:00
|
|
|
if (
|
|
|
|
|
! request()->get('family')
|
2019-11-21 15:56:21 +00:00
|
|
|
&& ProductType::hasVariants(request()->input('type'))
|
2020-02-28 10:25:53 +00:00
|
|
|
&& request()->input('sku') != ''
|
|
|
|
|
) {
|
2019-06-28 14:18:52 +00:00
|
|
|
return redirect(url()->current() . '?type=' . request()->input('type') . '&family=' . request()->input('attribute_family_id') . '&sku=' . request()->input('sku'));
|
2018-08-01 06:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-16 05:13:13 +00:00
|
|
|
if (
|
|
|
|
|
ProductType::hasVariants(request()->input('type'))
|
2019-06-28 14:18:52 +00:00
|
|
|
&& (! request()->has('super_attributes')
|
2020-07-30 12:15:54 +00:00
|
|
|
|| ! count(request()->get('super_attributes')))
|
2020-02-28 10:25:53 +00:00
|
|
|
) {
|
2019-02-13 12:12:07 +00:00
|
|
|
session()->flash('error', trans('admin::app.catalog.products.configurable-error'));
|
2018-08-01 06:11:33 +00:00
|
|
|
|
|
|
|
|
return back();
|
2018-07-31 07:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-27 06:22:12 +00:00
|
|
|
$this->validate(request(), [
|
2020-02-20 06:12:17 +00:00
|
|
|
'type' => 'required',
|
2018-07-31 07:50:54 +00:00
|
|
|
'attribute_family_id' => 'required',
|
2020-07-30 12:15:54 +00:00
|
|
|
'sku' => ['required', 'unique:products,sku', new Slug],
|
2018-07-27 06:22:12 +00:00
|
|
|
]);
|
|
|
|
|
|
2022-08-08 13:10:37 +00:00
|
|
|
Event::dispatch('catalog.product.create.before');
|
|
|
|
|
|
2019-06-28 14:18:52 +00:00
|
|
|
$product = $this->productRepository->create(request()->all());
|
2018-07-27 06:22:12 +00:00
|
|
|
|
2022-08-08 13:10:37 +00:00
|
|
|
Event::dispatch('catalog.product.create.after', $product);
|
|
|
|
|
|
2019-01-16 08:38:39 +00:00
|
|
|
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'Product']));
|
2018-07-27 06:22:12 +00:00
|
|
|
|
2018-07-31 07:50:54 +00:00
|
|
|
return redirect()->route($this->_config['redirect'], ['id' => $product->id]);
|
2018-07-27 06:22:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
|
*
|
2021-09-16 05:13:13 +00:00
|
|
|
* @param int $id
|
2019-08-19 09:30:24 +00:00
|
|
|
* @return \Illuminate\View\View
|
2018-07-27 06:22:12 +00:00
|
|
|
*/
|
|
|
|
|
public function edit($id)
|
|
|
|
|
{
|
2019-06-28 14:18:52 +00:00
|
|
|
$product = $this->productRepository->with(['variants', 'variants.inventories'])->findOrFail($id);
|
2018-07-27 06:22:12 +00:00
|
|
|
|
2019-06-28 14:18:52 +00:00
|
|
|
$categories = $this->categoryRepository->getCategoryTree();
|
2018-08-09 04:35:13 +00:00
|
|
|
|
2020-06-11 06:06:32 +00:00
|
|
|
$inventorySources = $this->inventorySourceRepository->findWhere(['status' => 1]);
|
2018-08-09 04:35:13 +00:00
|
|
|
|
2019-05-21 14:41:36 +00:00
|
|
|
return view($this->_config['view'], compact('product', 'categories', 'inventorySources'));
|
2018-07-27 06:22:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
|
*
|
2021-09-16 05:13:13 +00:00
|
|
|
* @param \Webkul\Product\Http\Requests\ProductForm $request
|
|
|
|
|
* @param int $id
|
2018-07-27 06:22:12 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2018-08-09 04:35:13 +00:00
|
|
|
public function update(ProductForm $request, $id)
|
2018-07-27 06:22:12 +00:00
|
|
|
{
|
2022-08-19 12:04:26 +00:00
|
|
|
foreach (request()->images['files'] as $fileExists) {
|
2022-08-19 12:09:09 +00:00
|
|
|
|
|
|
|
|
if (! $fileExists) {
|
2022-08-19 12:04:26 +00:00
|
|
|
session()->flash('error', trans('admin::app.admin.system.image-required'));
|
|
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->productRepository->update(request()->all(), $id);
|
|
|
|
|
|
2022-08-08 13:10:37 +00:00
|
|
|
Event::dispatch('catalog.product.update.before', $id);
|
|
|
|
|
|
|
|
|
|
$product = $this->productRepository->update(request()->all(), $id);
|
|
|
|
|
|
|
|
|
|
Event::dispatch('catalog.product.update.after', $product);
|
2018-07-27 06:22:12 +00:00
|
|
|
|
2019-01-16 08:38:39 +00:00
|
|
|
session()->flash('success', trans('admin::app.response.update-success', ['name' => 'Product']));
|
2018-07-27 06:22:12 +00:00
|
|
|
|
|
|
|
|
return redirect()->route($this->_config['redirect']);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-28 14:18:52 +00:00
|
|
|
/**
|
2021-09-16 05:13:13 +00:00
|
|
|
* Update inventories.
|
2019-06-28 14:18:52 +00:00
|
|
|
*
|
2021-09-16 05:13:13 +00:00
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2022-05-09 10:35:21 +00:00
|
|
|
public function updateInventories(InventoryRequest $inventoryRequest, $id)
|
2021-09-16 05:13:13 +00:00
|
|
|
{
|
|
|
|
|
$product = $this->productRepository->findOrFail($id);
|
|
|
|
|
|
|
|
|
|
$this->productInventoryRepository->saveInventories(request()->all(), $product);
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
2022-01-21 09:51:19 +00:00
|
|
|
'message' => __('admin::app.catalog.products.saved-inventory-message'),
|
|
|
|
|
'updatedTotal' => $this->productInventoryRepository->where('product_id', $product->id)->sum('qty'),
|
2021-09-16 05:13:13 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Uploads downloadable file.
|
2020-07-30 12:15:54 +00:00
|
|
|
*
|
2021-09-16 05:13:13 +00:00
|
|
|
* @param int $id
|
2019-06-28 14:18:52 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function uploadLink($id)
|
|
|
|
|
{
|
|
|
|
|
return response()->json(
|
|
|
|
|
$this->productDownloadableLinkRepository->upload(request()->all(), $id)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 12:15:54 +00:00
|
|
|
/**
|
2020-08-05 06:26:01 +00:00
|
|
|
* Copy a given Product.
|
2021-09-16 05:13:13 +00:00
|
|
|
*
|
|
|
|
|
* @param int $productId
|
|
|
|
|
* @return \Illuminate\Http\Response
|
2020-07-30 12:15:54 +00:00
|
|
|
*/
|
|
|
|
|
public function copy(int $productId)
|
|
|
|
|
{
|
2020-08-05 06:26:01 +00:00
|
|
|
$originalProduct = $this->productRepository->findOrFail($productId);
|
|
|
|
|
|
2020-08-10 15:24:36 +00:00
|
|
|
if (! $originalProduct->getTypeInstance()->canBeCopied()) {
|
2021-09-16 05:13:13 +00:00
|
|
|
session()->flash(
|
|
|
|
|
'error',
|
2020-08-11 07:43:03 +00:00
|
|
|
trans('admin::app.response.product-can-not-be-copied', [
|
|
|
|
|
'type' => $originalProduct->type,
|
2021-09-16 05:13:13 +00:00
|
|
|
])
|
|
|
|
|
);
|
2020-08-05 06:26:01 +00:00
|
|
|
|
|
|
|
|
return redirect()->to(route('admin.catalog.products.index'));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 14:53:09 +00:00
|
|
|
if ($originalProduct->parent_id) {
|
2021-09-16 05:13:13 +00:00
|
|
|
session()->flash(
|
|
|
|
|
'error',
|
|
|
|
|
trans('admin::app.catalog.products.variant-already-exist-message')
|
|
|
|
|
);
|
2020-08-11 14:53:09 +00:00
|
|
|
|
|
|
|
|
return redirect()->to(route('admin.catalog.products.index'));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-05 06:26:01 +00:00
|
|
|
$copiedProduct = $this->productRepository->copy($originalProduct);
|
2020-07-30 12:15:54 +00:00
|
|
|
|
2022-07-12 12:04:13 +00:00
|
|
|
if (
|
|
|
|
|
$copiedProduct instanceof Product
|
|
|
|
|
&& $copiedProduct->id
|
|
|
|
|
) {
|
2020-08-05 18:40:19 +00:00
|
|
|
session()->flash('success', trans('admin::app.response.product-copied'));
|
|
|
|
|
} else {
|
|
|
|
|
session()->flash('error', trans('admin::app.response.error-while-copying'));
|
|
|
|
|
}
|
2020-08-03 18:07:49 +00:00
|
|
|
|
2020-07-30 12:15:54 +00:00
|
|
|
return redirect()->to(route('admin.catalog.products.edit', ['id' => $copiedProduct->id]));
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-28 14:18:52 +00:00
|
|
|
/**
|
2021-09-16 05:13:13 +00:00
|
|
|
* Uploads downloadable sample file.
|
2020-07-30 12:15:54 +00:00
|
|
|
*
|
2021-09-16 05:13:13 +00:00
|
|
|
* @param int $id
|
2019-06-28 14:18:52 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function uploadSample($id)
|
|
|
|
|
{
|
|
|
|
|
return response()->json(
|
|
|
|
|
$this->productDownloadableSampleRepository->upload(request()->all(), $id)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-27 06:22:12 +00:00
|
|
|
/**
|
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
|
*
|
2021-09-16 05:13:13 +00:00
|
|
|
* @param int $id
|
2018-07-27 06:22:12 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function destroy($id)
|
|
|
|
|
{
|
2019-06-28 14:18:52 +00:00
|
|
|
$product = $this->productRepository->findOrFail($id);
|
2018-10-17 10:30:31 +00:00
|
|
|
|
2019-04-09 01:01:52 +00:00
|
|
|
try {
|
2022-08-08 13:10:37 +00:00
|
|
|
Event::dispatch('catalog.product.delete.before', $id);
|
|
|
|
|
|
2019-06-28 14:18:52 +00:00
|
|
|
$this->productRepository->delete($id);
|
2018-10-17 10:30:31 +00:00
|
|
|
|
2022-08-08 13:10:37 +00:00
|
|
|
Event::dispatch('catalog.product.delete.after', $id);
|
|
|
|
|
|
2022-02-11 11:35:38 +00:00
|
|
|
return response()->json([
|
|
|
|
|
'message' => trans('admin::app.response.delete-success', ['name' => 'Product']),
|
2022-02-11 12:34:38 +00:00
|
|
|
]);
|
2020-07-30 12:15:54 +00:00
|
|
|
} catch (Exception $e) {
|
2020-01-27 16:06:03 +00:00
|
|
|
report($e);
|
2019-04-09 01:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-11 11:35:38 +00:00
|
|
|
return response()->json([
|
|
|
|
|
'message' => trans('admin::app.response.delete-failed', ['name' => 'Product']),
|
|
|
|
|
], 500);
|
2018-07-27 06:22:12 +00:00
|
|
|
}
|
2018-10-22 13:18:46 +00:00
|
|
|
|
2018-12-07 09:15:31 +00:00
|
|
|
/**
|
2022-02-11 11:35:38 +00:00
|
|
|
* Mass delete the products.
|
2018-12-07 09:15:31 +00:00
|
|
|
*
|
2020-03-05 13:37:08 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
2018-12-07 09:15:31 +00:00
|
|
|
*/
|
2018-12-27 13:27:39 +00:00
|
|
|
public function massDestroy()
|
|
|
|
|
{
|
|
|
|
|
$productIds = explode(',', request()->input('indexes'));
|
2018-12-21 12:48:34 +00:00
|
|
|
|
2018-12-27 13:27:39 +00:00
|
|
|
foreach ($productIds as $productId) {
|
2019-06-28 14:18:52 +00:00
|
|
|
$product = $this->productRepository->find($productId);
|
2019-04-02 07:36:13 +00:00
|
|
|
|
2019-04-08 11:18:43 +00:00
|
|
|
if (isset($product)) {
|
2022-08-08 13:10:37 +00:00
|
|
|
Event::dispatch('catalog.product.delete.before', $productId);
|
|
|
|
|
|
2019-06-28 14:18:52 +00:00
|
|
|
$this->productRepository->delete($productId);
|
2022-08-08 13:10:37 +00:00
|
|
|
|
|
|
|
|
Event::dispatch('catalog.product.delete.after', $productId);
|
2019-04-02 07:36:13 +00:00
|
|
|
}
|
2018-12-07 09:15:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
session()->flash('success', trans('admin::app.catalog.products.mass-delete-success'));
|
|
|
|
|
|
|
|
|
|
return redirect()->route($this->_config['redirect']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-02-11 11:35:38 +00:00
|
|
|
* Mass update the products.
|
2018-12-07 09:15:31 +00:00
|
|
|
*
|
2020-03-05 13:37:08 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
2018-12-07 09:15:31 +00:00
|
|
|
*/
|
2018-12-27 13:27:39 +00:00
|
|
|
public function massUpdate()
|
|
|
|
|
{
|
2018-12-07 09:15:31 +00:00
|
|
|
$data = request()->all();
|
|
|
|
|
|
2019-11-07 09:58:10 +00:00
|
|
|
if (! isset($data['massaction-type'])) {
|
2018-12-07 09:15:31 +00:00
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-11 12:21:33 +00:00
|
|
|
if (! $data['massaction-type'] == 'update') {
|
2019-01-09 11:41:00 +00:00
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-27 13:27:39 +00:00
|
|
|
$productIds = explode(',', $data['indexes']);
|
2018-12-07 09:15:31 +00:00
|
|
|
|
2018-12-27 13:27:39 +00:00
|
|
|
foreach ($productIds as $productId) {
|
2022-08-08 14:51:38 +00:00
|
|
|
Event::dispatch('catalog.product.update.before', $productId);
|
2022-08-08 13:10:37 +00:00
|
|
|
|
|
|
|
|
$product = $this->productRepository->update([
|
2019-01-22 05:05:05 +00:00
|
|
|
'channel' => null,
|
2020-02-20 06:12:17 +00:00
|
|
|
'locale' => null,
|
2020-03-04 06:32:53 +00:00
|
|
|
'status' => $data['update-options'],
|
2019-01-22 05:05:05 +00:00
|
|
|
], $productId);
|
2022-08-08 13:10:37 +00:00
|
|
|
|
|
|
|
|
Event::dispatch('catalog.product.update.after', $product);
|
2018-12-07 09:15:31 +00:00
|
|
|
}
|
|
|
|
|
|
2018-12-22 06:26:26 +00:00
|
|
|
session()->flash('success', trans('admin::app.catalog.products.mass-update-success'));
|
2018-12-07 09:15:31 +00:00
|
|
|
|
|
|
|
|
return redirect()->route($this->_config['redirect']);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-05 13:37:08 +00:00
|
|
|
/**
|
2021-09-16 05:13:13 +00:00
|
|
|
* To be manually invoked when data is seeded into products.
|
2020-06-10 14:37:50 +00:00
|
|
|
*
|
2020-03-05 13:37:08 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
2018-11-27 10:55:23 +00:00
|
|
|
*/
|
2018-12-27 13:27:39 +00:00
|
|
|
public function sync()
|
|
|
|
|
{
|
2019-12-24 14:01:13 +00:00
|
|
|
Event::dispatch('products.datagrid.sync', true);
|
2018-11-28 10:40:48 +00:00
|
|
|
|
|
|
|
|
return redirect()->route('admin.catalog.products.index');
|
2018-10-22 13:18:46 +00:00
|
|
|
}
|
2019-03-12 15:35:10 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Result of search product.
|
|
|
|
|
*
|
2020-03-05 13:37:08 +00:00
|
|
|
* @return \Illuminate\View\View|\Illuminate\Http\Response
|
2019-03-12 15:35:10 +00:00
|
|
|
*/
|
|
|
|
|
public function productLinkSearch()
|
|
|
|
|
{
|
|
|
|
|
if (request()->ajax()) {
|
|
|
|
|
$results = [];
|
|
|
|
|
|
2019-06-28 14:18:52 +00:00
|
|
|
foreach ($this->productRepository->searchProductByAttribute(request()->input('query')) as $row) {
|
2019-03-12 15:35:10 +00:00
|
|
|
$results[] = [
|
2020-02-27 08:03:03 +00:00
|
|
|
'id' => $row->product_id,
|
|
|
|
|
'sku' => $row->sku,
|
|
|
|
|
'name' => $row->name,
|
|
|
|
|
];
|
2019-03-12 15:35:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json($results);
|
|
|
|
|
} else {
|
|
|
|
|
return view($this->_config['view']);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-29 09:53:34 +00:00
|
|
|
|
2020-07-30 12:15:54 +00:00
|
|
|
/**
|
2021-09-16 05:13:13 +00:00
|
|
|
* Download image or file.
|
2020-07-30 12:15:54 +00:00
|
|
|
*
|
2021-09-16 05:13:13 +00:00
|
|
|
* @param int $productId
|
|
|
|
|
* @param int $attributeId
|
2019-06-29 09:53:34 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function download($productId, $attributeId)
|
|
|
|
|
{
|
2020-08-11 13:28:31 +00:00
|
|
|
$productAttribute = $this->productAttributeValueRepository->findOneWhere([
|
2019-06-29 09:53:34 +00:00
|
|
|
'product_id' => $productId,
|
2020-03-04 06:32:53 +00:00
|
|
|
'attribute_id' => $attributeId,
|
2019-06-29 09:53:34 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return Storage::download($productAttribute['text_value']);
|
|
|
|
|
}
|
2019-08-19 09:30:24 +00:00
|
|
|
|
|
|
|
|
/**
|
2021-09-16 05:13:13 +00:00
|
|
|
* Search simple products.
|
2019-08-19 09:30:24 +00:00
|
|
|
*
|
2020-03-05 13:37:08 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
2019-08-19 09:30:24 +00:00
|
|
|
*/
|
2019-08-21 13:54:26 +00:00
|
|
|
public function searchSimpleProducts()
|
2019-08-19 09:30:24 +00:00
|
|
|
{
|
|
|
|
|
return response()->json(
|
2019-08-21 13:54:26 +00:00
|
|
|
$this->productRepository->searchSimpleProducts(request()->input('query'))
|
2019-08-19 09:30:24 +00:00
|
|
|
);
|
|
|
|
|
}
|
2021-09-16 05:13:13 +00:00
|
|
|
}
|