category filters
This commit is contained in:
parent
228b7ad947
commit
3e067df079
|
|
@ -17,8 +17,9 @@ class Products extends ProductController
|
|||
public function __construct(ProductRepository $productRepository,
|
||||
AttributeOptionRepository $attributeOptionRepository)
|
||||
{
|
||||
parent::__construct($productRepository);
|
||||
$this->attributeOptionRepository = $attributeOptionRepository;
|
||||
|
||||
parent::__construct($productRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -40,38 +41,42 @@ class Products extends ProductController
|
|||
*/
|
||||
public function get($id)
|
||||
{
|
||||
return new ProductResource(
|
||||
$this->productRepository->findOrFail($id)
|
||||
);
|
||||
return ($product = $this->productRepository->findl($id))?
|
||||
new ProductResource($product) :
|
||||
response()->json(['error' => 'not found'],404);
|
||||
}
|
||||
|
||||
public function variants($id){
|
||||
|
||||
$product = $this->productRepository->with(['super_attributes:id,code','variants'=>function($query){
|
||||
// $query->select('id','parent_id');
|
||||
$query->with(['images','product_flats' => function($qf){
|
||||
public function variants($id)
|
||||
{
|
||||
$product = $this->productRepository->with(['super_attributes:id,code','variants'=>function($query)
|
||||
{
|
||||
$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; //Attribute::make($product->super_attributes->first());
|
||||
if(!empty($product) && $product->super_attributes->isNotEmpty() && $product->variants->isNotEmpty()){
|
||||
|
||||
if(!empty($product) && $product->super_attributes->isNotEmpty() && $product->variants->isNotEmpty())
|
||||
{
|
||||
$variants = $product->variants->makeHidden(['type','created_at','updated_at','parent_id','attribute_family_id',
|
||||
'additional','new','featured','visible_individually','status','guest_checkout','meta_title','meta_keywords',
|
||||
'product_flats','attribute_family','short_description','sku','brand']);
|
||||
|
||||
$attribute = $product->super_attributes->first();
|
||||
$distinctVariants = $variants->unique($attribute->code);//->only([$attribute_main->code]);
|
||||
|
||||
$distinctVariants = $variants->unique($attribute->code);
|
||||
|
||||
$gr_data = array('attribute' => SuperAttribute::make($attribute),'options' =>[]);
|
||||
|
||||
foreach($distinctVariants as $variant){
|
||||
foreach($distinctVariants as $variant)
|
||||
{
|
||||
$option = $attribute->options->firstWhere('id',$variant->{$attribute->code});
|
||||
|
||||
$item = [
|
||||
|
|
@ -79,7 +84,8 @@ class Products extends ProductController
|
|||
'images' => $variant->images,
|
||||
];
|
||||
|
||||
if($product->super_attributes->count()>1 && $option){
|
||||
if($product->super_attributes->count()>1 && $option)
|
||||
{
|
||||
$last_attribute = $product->super_attributes->last();
|
||||
|
||||
$products = $variants->where($attribute->code,$variant->{$attribute->code})
|
||||
|
|
@ -92,21 +98,16 @@ class Products extends ProductController
|
|||
$item['variants']['attribute'] = SuperAttribute::make($last_attribute);
|
||||
$item['variants']['products'] = $products->values();
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
$item['product'] = ProductVariant::make($variant,$option);
|
||||
}
|
||||
$gr_data['options'][] = $item;
|
||||
}
|
||||
|
||||
return response()->json($gr_data);
|
||||
}
|
||||
else{
|
||||
return response()->json(['message' => 'not found'],404);
|
||||
}
|
||||
|
||||
// $variants = $this->productRepository->variants($id);
|
||||
// return $variants;
|
||||
// return ProductResource::collection($this->productRepository->variants($id));
|
||||
return response()->json(['message' => 'not found'],404);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,6 @@ use Webkul\Product\Repositories\ProductFlatRepository;
|
|||
class Vendors extends Controller
|
||||
{
|
||||
|
||||
protected $vendorRepository;
|
||||
protected $categoryRepository;
|
||||
|
||||
public function __construct(VendorRepository $sellerRepository,
|
||||
CategoryRepository $categoryRepository)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -42,16 +42,14 @@ class ProductVariant extends JsonResource
|
|||
'formatted_price' => core()->currency($productTypeInstance->getMinimalPrice()),
|
||||
'short_description' => $product->short_description,
|
||||
'description' => $product->description,
|
||||
"option_value" => $this->option->admin_name,
|
||||
// "size" => $this->size,
|
||||
// "brand"=>$this->brand,
|
||||
"option_value" => $this->option->admin_name,
|
||||
/* product's checks */
|
||||
'in_stock' => $product->haveSufficientQuantity(1),
|
||||
'is_wishlisted' => $this->wishlistHelper->getWishlistProduct($product) ? true : false,
|
||||
'is_item_in_cart' => \Cart::hasProduct($product),
|
||||
'in_stock' => $product->haveSufficientQuantity(1),
|
||||
'is_wishlisted' => $this->wishlistHelper->getWishlistProduct($product) ? true : false,
|
||||
'is_item_in_cart' => \Cart::hasProduct($product),
|
||||
/* special price cases */
|
||||
$this->merge($this->specialPriceInfo()),
|
||||
|
||||
'images' => ProductImage::collection($product->images),
|
||||
];
|
||||
}
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -371,6 +371,8 @@ class ProductRepository extends WProductRepository
|
|||
'price' => $sizeVariant['price'],
|
||||
'weight' => 0,
|
||||
'status' => 1,
|
||||
'featured'=> 0,
|
||||
'new' => 1,
|
||||
'visible_individually' => 1,
|
||||
'url_key' => $variant->sku,
|
||||
'short_description' => $data['url_key'],
|
||||
|
|
|
|||
Loading…
Reference in New Issue