variant fix

This commit is contained in:
merdan 2022-02-11 20:13:21 +05:00
parent ba374025c3
commit 8e19a87165
2 changed files with 13 additions and 4 deletions

View File

@ -2,6 +2,7 @@
namespace Sarga\API\Http\Controllers;
use Illuminate\Support\Facades\Log;
use Sarga\API\Http\Resources\Catalog\ProductVariant;
use Sarga\API\Http\Resources\Catalog\SuperAttribute;
use Sarga\Shop\Repositories\ProductRepository;
@ -93,7 +94,7 @@ class Products extends ProductController
$products = $variants->where($attribute->code,$variant->{$attribute->code})
->map(function ($item,$key) use ($product){
// $option = $last_attribute->options->where('id',$item->{$last_attribute->code})->first();
Log::info($product->super_attributes);
return ProductVariant::make($item,$product->super_attributes);
});

View File

@ -3,6 +3,7 @@
namespace Sarga\API\Http\Resources\Catalog;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Log;
class ProductVariant extends JsonResource
{
@ -61,9 +62,16 @@ class ProductVariant extends JsonResource
}
private function last_attribute_value(){
$last_attribute = is_countable($this->attributes)?$this->attributes->last():$this->attributes;
$option = $last_attribute->options->where('id',$this->{$last_attribute->code})->first();
return $option->admin_name;
$last_attribute = is_countable($this->attributes) ? $this->attributes->last() : $this->attributes;
if(!empty($last_attribute->options))
{
$option = $last_attribute->options->where('id',$this->{$last_attribute->code})->first();
return $option->admin_name;
}
return null;
}
/**
* Get special price information.