scrap validation sku
This commit is contained in:
parent
092580d960
commit
1fbcd2a6cc
|
|
@ -2,14 +2,19 @@
|
|||
|
||||
namespace Sarga\API\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Sarga\API\Repositories\ProductRepository;
|
||||
use Webkul\API\Http\Controllers\Shop\ProductController;
|
||||
use Sarga\API\Http\Resources\Catalog\Product as ProductResource;
|
||||
use Webkul\Core\Contracts\Validations\Slug;
|
||||
|
||||
|
||||
class Products extends ProductController
|
||||
{
|
||||
|
||||
public function __construct(ProductRepository $productRepository)
|
||||
{
|
||||
parent::__construct($productRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a listing of the resource.
|
||||
*
|
||||
|
|
@ -21,7 +26,6 @@ class Products extends ProductController
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a individual resource.
|
||||
*
|
||||
|
|
@ -35,19 +39,24 @@ class Products extends ProductController
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns product's additional information.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function configurableConfig($id)
|
||||
{
|
||||
public function variants($id){
|
||||
|
||||
$product = $this->productRepository->findOrFail($id);
|
||||
return response()->json([
|
||||
'data' => app('Webkul\Product\Helpers\ConfigurableOption')->getConfigurationConfig($this->productRepository->findOrFail($id)),
|
||||
]);
|
||||
$product = $this->productRepository->with(['super_attributes','variants'=>function($query){
|
||||
// $query->select('id','parent_id');
|
||||
$query->with(['images','product_flats' => function($qf){
|
||||
$channel = core()->getRequestedChannelCode();
|
||||
|
||||
$locale = core()->getRequestedLocaleCode();
|
||||
$qf->where('product_flat.channel', $channel)
|
||||
->where('product_flat.locale', $locale)
|
||||
->whereNotNull('product_flat.url_key')
|
||||
->where('status',1);
|
||||
}]);
|
||||
}])->find($id);
|
||||
return $product;
|
||||
$variants = $this->productRepository->variants($id);
|
||||
return $variants;
|
||||
// return ProductResource::collection($this->productRepository->variants($id));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ Route::group(['prefix' => 'api'], function ($router) {
|
|||
Route::get('products', [Products::class, 'index']);
|
||||
|
||||
Route::get('products/{id}', [Products::class, 'get']);
|
||||
Route::get('products/{id}/variants', [Products::class, 'variants']);
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'scrap','middleware' =>['scrap']], function ($router){
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ class ProductRepository extends WProductRepository
|
|||
}
|
||||
|
||||
if ($product['type'] == 'configurable') {
|
||||
$variant = null;
|
||||
//create variants color
|
||||
if (!empty($data['color_variants'])) {
|
||||
$attribute = $this->attributeRepository->findOneByField('code', 'color');
|
||||
|
|
@ -94,8 +95,6 @@ class ProductRepository extends WProductRepository
|
|||
foreach ($data['color_variants'] as $colorVariant) {
|
||||
$description = implode(array_map(fn($value): string => '<p>' . $value['description'] . '</p>', $colorVariant['descriptions']));
|
||||
if (!empty($colorVariant['size_variants'])) {
|
||||
|
||||
|
||||
foreach ($colorVariant['size_variants'] as $sizeVariant) {
|
||||
$variant = $this->createVariant($parentProduct, $colorVariant['product_number'] . $sizeVariant['size']);
|
||||
|
||||
|
|
@ -157,7 +156,9 @@ class ProductRepository extends WProductRepository
|
|||
$this->assignAttributes($variant, $attributes);
|
||||
}
|
||||
}
|
||||
//todo default_variant_id
|
||||
if($variant){
|
||||
$parentProduct->getTypeInstance()->setDefaultVariantId($variant->id);
|
||||
}
|
||||
}
|
||||
|
||||
// assign attributes
|
||||
|
|
@ -457,4 +458,20 @@ class ProductRepository extends WProductRepository
|
|||
return $grups;
|
||||
|
||||
}
|
||||
|
||||
public function variants($product_id){
|
||||
$channel = core()->getRequestedChannelCode();
|
||||
|
||||
$locale = core()->getRequestedLocaleCode();
|
||||
|
||||
return $this->productFlatRepository->where('product_flat.channel', $channel)
|
||||
->where('product_flat.locale', $locale)
|
||||
// ->whereNotNull('product_flat.url_key')
|
||||
->where('product_flat.status',1)
|
||||
->whereIn('product_flat.product_id',function($query) use($product_id) {
|
||||
$query->select('products.id')->from('products')->where('products.parent_id',$product_id);
|
||||
})
|
||||
->get();
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue