variants
This commit is contained in:
parent
2412f4ffb9
commit
a45341900a
|
|
@ -90,16 +90,14 @@ class Products extends ProductController
|
|||
|
||||
if($product->super_attributes->count()>1 && $option)
|
||||
{
|
||||
$last_attribute = $product->super_attributes->last();
|
||||
|
||||
$products = $variants->where($attribute->code,$variant->{$attribute->code})
|
||||
->map(function ($item,$key) use ($last_attribute){
|
||||
$option = $last_attribute->options->where('id',$item->{$last_attribute->code})->first();
|
||||
->map(function ($item,$key) use ($product){
|
||||
// $option = $last_attribute->options->where('id',$item->{$last_attribute->code})->first();
|
||||
|
||||
return ProductVariant::make($item,$option);
|
||||
return ProductVariant::make($item,$product->super_attributes);
|
||||
});
|
||||
|
||||
$item['variants']['attribute'] = SuperAttribute::make($last_attribute);
|
||||
$item['variants']['attribute'] = SuperAttribute::make($product->super_attributes->last());
|
||||
$item['variants']['products'] = $products->values();
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -12,13 +12,9 @@ class ProductVariant extends JsonResource
|
|||
* @return void
|
||||
*/
|
||||
|
||||
public function __construct($resource, $opion)
|
||||
public function __construct($resource, $attributes)
|
||||
{
|
||||
// $this->productReviewHelper = app('Webkul\Product\Helpers\Review');
|
||||
|
||||
$this->wishlistHelper = app('Webkul\Customer\Helpers\Wishlist');
|
||||
$this->option = $opion;
|
||||
$this->wishlistHelper = app('Webkul\Customer\Helpers\Wishlist');
|
||||
$this->attributes = $attributes;
|
||||
parent::__construct($resource);
|
||||
}
|
||||
/**
|
||||
|
|
@ -42,7 +38,7 @@ class ProductVariant extends JsonResource
|
|||
'formatted_price' => core()->currency($productTypeInstance->getMinimalPrice()),
|
||||
'short_description' => $product->short_description,
|
||||
'description' => $product->description,
|
||||
"option_value" => $this->option->admin_name,
|
||||
"option_value" => $this->last_attribute_value(),
|
||||
/* product's checks */
|
||||
'in_stock' => $product->haveSufficientQuantity(1),
|
||||
'is_wishlisted' => $this->wishlistHelper->getWishlistProduct($product) ? true : false,
|
||||
|
|
@ -50,8 +46,26 @@ class ProductVariant extends JsonResource
|
|||
/* special price cases */
|
||||
$this->merge($this->specialPriceInfo()),
|
||||
'images' => ProductImage::collection($product->images),
|
||||
'attributes' => $this->super_attributes()->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
private function super_attributes(){
|
||||
return $this->attributes->map(function($item, $key){
|
||||
return [
|
||||
'code' => $item->code,
|
||||
'value' => $this->{$item->code},
|
||||
'name' => $item->name,
|
||||
'label' => $item->options->where('id',$this->{$item->code})->first()->admin_name
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
private function last_attribute_value(){
|
||||
$last_attribute = $this->attributes->last();
|
||||
$option = $last_attribute->options->where('id',$this->{$last_attribute->code})->first();
|
||||
return $option->admin_name;
|
||||
}
|
||||
/**
|
||||
* Get special price information.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue